lychee icon indicating copy to clipboard operation
lychee copied to clipboard

feature request: check text fragments

Open SKalt opened this issue 1 year ago • 6 comments

Text fragments are a standardized way to link to webpage text without relying on HTML ID attributes. They are supported by all modern browsers. I'd like to use lychee to make sure my text fragment links are valid!

Example:

<!-- file.html -->
<html>
  <body>
    <div>
      <a href="https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:~:text=without%20relying%20on%20the%20presence%20of%20IDs">
        valid
      </a>
      <a href="https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:~:text=asdfawefaweafa">
        invalid
      </a>
    </div>
  </body>
</html>
; lychee --version
# lychee 0.16.1
; lychee -vv --include-fragments ./file.html
#     [200] https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:~:text=without%20relying%20on%20the%20presence%20of%20IDs
#     [200] https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:~:text=asdfawefaweafa

Desired behavior: if lychee is configured to check fragments and is passed a #:~:text=... fragment, lychee should throw an error if the text is not found within the linked document.

SKalt avatar Oct 26 '24 12:10 SKalt

@HU90m, this one has your name on it. 😆

mre avatar Oct 26 '24 23:10 mre

My (first attempt) implementation of the Text Fragment feature - i had the audacity to include a new flag "include-text-fragments" to explicitly support the fragment directive (aka text fragment) feature.

Contributing Guidelines instruction is followed and cargo clippy & test run were successful.

I've forked the code into my repository since I didn't have permission to create feature branch in the main repository. I am ready to execute a pull-request for review - please let me know!

thiru-appitap avatar Dec 25 '24 07:12 thiru-appitap

Just took a gander at your changes. The branch definitely looks ready for a PR. I'll have a proper peruse and ask my questions once you have.

Thanks for going through the effort of adding good number of tests!

HU90m avatar Dec 25 '24 08:12 HU90m

Ah, you already have! Sorry I missed this.

HU90m avatar Dec 25 '24 08:12 HU90m

I have fixed few lint and clippy issues (missed it in the first couple of commits :-() - do review at your available time and let me know your comments!

thiru-appitap avatar Dec 25 '24 09:12 thiru-appitap

Related PR: https://github.com/lycheeverse/lychee/pull/1600

mre avatar Feb 05 '25 09:02 mre