You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Paweł Romanowski, Frederick Henderson, Brennan Kinney, Derek Croote, Martin, Martin Winandy, Roman Vasylenko, Steven DeMartini, Santiago Fraire Willemoes, Johnathan and 3 more
This is a bit of a tricky one. Anchors are really the properties of the document contents, not really being integral parts of the URLs.
What I really mean by that is this:
You can't tell if an anchor is valid by merely making a request (you can only check the URL path without the anchor)
To verify anchors, you'd have to parse the retrieved HTML and check they're there (but we already do it for link extraction using html5ever, a browser grade parser)
So this might not be very straightforward, but should be perfectly doable. I'd welcome such a feature 😃
To verify anchors, you'd have to parse the retrieved HTML and check they're there (but we already do it for link extraction using html5ever, a browser grade parser)
HTMLs are parsed for link extraction on the input HTML documents, but not for the target HTML documents. So it would required to first check whether the target is actually an HTML document, then download it fully (currently it is only partially downloaded or not at all when using -X head) and then parse the target HTML for a matching id attribute.
When support for internal links via file existence check is added (#21), then it could be at least cheaply added for those:
If the link/URL is an internal one, check only if the target file exists, relative to the input HTML file location or relative to the base path, when given and it is an absolute internal link.
Then, if the target is an HTML file, or a directory that contains an index.htm/index.html, check for a contained matching id attribute.
In other cases, I think it's difficult if one does not want to imply much overhead for checking the URLs document type and downloading it completely. But nevertheless, the idea/feature itself would be awesome of course 🙂.
Another case where the difficulties with target downloads etc do not apply, and probably this is what you had in mind anyway, is to check for scroll links within the input HTMLs. so if there is an <a href="#heading">, to check whether there is an id="heading" as well. If such is wanted, it's good to create a generic method/function for it, so that URL fragments can be generally detected and HTMLs generally scanned for matching IDs, but at first implemented for such same-page scroll links, then depending on #21 for locally stored target HTML files, and gradually for online HTML documents, when this is found to be important enough to fully download the target, based on content-type: text/html or so. But I'm not sure if the content type header is reliable enough of if there is a risk that a large archive or video file is unintentionally downloaded 😄.
But I'm not sure if the content type header is reliable enough of if there is a risk that a large archive or video file is unintentionally downloaded
Response headers should provide info about content size, completing a request in full (eg downloading a large resource) shouldn't be necessary and could be terminated early AFAIK?
completing a request in full (eg downloading a large resource) shouldn't be necessary and could be terminated early AFAIK?
If you want to check whether an URL fragment is valid or not, you need to download the whole document of course, which is the whole issue I see here, as long as it's not about same-page links or local files. Currently the download is terminated early, reasonably, so currently it is impossible to apply this feature for remote HTML documents without changing the download behaviour based on such things like HTTP headers, which is why I think one needs to evaluate carefully if the effort is worth it or not 😉.
you need to download the whole document of course, which is the whole issue I see here
Downloading a complete HTML document to operate on isn't much of a concern vs larger files which I thought was being raised as the concern but could be avoided.
You make a good point though, especially with some HTML documents that are dependent on JS to populate the real content, such as React pages without any pre-rendering process involved. That'd require actually loading and running the JS..
I haven't used lychee myself yet, so I'm not sure if it supports that well (anchor tag feature aside).
If other attributes of 'a' tag is provided, you can use that to help you determine whether to download that webpage, or whether it links to webpage, etc. But it gets complicated.
Sometimes anchors aren’t even in the HTML itself, like for static websites! Another approach could be to make the request with and without the anchor and compare the scroll location if that’s possible, it means making two requests though
Sorry, I don't quite get it. If we find a fragment link in a document, we have to check if that fragment exists. Say we find "#helloworld" and there is a headline named "Hello World", for which a fragment was generated automatically by the hoster (GitHub, GitLab, Swagger (?)). Now the question is if that headline gets converted into "#helloworld" or "#hello-world" or something else. How can we design the header format in such a case? Don't we have to generate the same fragment link as the hoster?
Don't we have to generate the same fragment link as the hoster
yes thats what i mean, the exact implementation would need a balance between verbosity and conciseness but for example something like
[ { " ": "-" } ]
this would replace in the content with - in the header, transforming hello world to hello-world, we'd likely need more configuration like escaping, casing, handling duplicates and so on
Ah, I understand now. Not sure how to find the right balance between simplicity and flexibility here. Open for suggestions for the configuration format.
we could use toml, i believe it supports arbitrary keys as string ("abc" = "xyz") which could be used for replacing characters
we could take an "enum" (not sure toml supports them) for casing, options i can think of are camel case, snake case, kebab case, pascal case and macro case
for escaping i think we already do percent encoding so not sure if theres additional configuration necessary
lastly duplicates are a little tricky, we could have them provide a format template such as {anchor}-{n} where n is the index of the occurrence, we'd have to also let them set if its 0 indexed or 1 indexed and whether the first occurrence still needs this formatting (whether to use {anchor} or {anchor}-{0} for the first occurrence)
or we could take an entirely different approach and direct users to use the crate for configuration, maybe having them pass a closure like |element| -> anchor, which is infinitely extensible but may be a dealbreaker for non-rust users or people that dont want to spend the time on that
should we provide a way for the user to configure this (probably the same way we pre-configure these websites)?
I'm personally not keen on this idea.
In an ideal world, fragment generation would be specified in the common mark spec, but it isn't and there are a few different common methods. I don't want to encourage xkcd № 927, especially if it involves adding significant complexity to the tool and configuration.
I think hard coding the common generation methods in lychee (or in a separate crate) would help clearly document existing generation methods and hopefully help reduce, stop or even reverse their proliferation.
Here's our current architecture after the changes:
Supporting fragments in URLs (e.g. https://foo/bar.html#frag as in option 3 in the link types) won't be a small change, I guess.
We'd probably have to make few changes to the architecture, because right now there's no way for the check step to "ask" for all links of a given input or even just ask if a link occurs in a given input (e.g. "is https://foo/bar.html#frag valid?").
One way to go about it might be to fully decouple input handling from link checking (where inputs can be files or websites).
The fragment cache is a basic version of that, but it's limited to fragments. I think we need a bigger cache for all inputs we encounter and a central entity, which manages this cache. We can think of it as an abstraction on top of the network and the file system, purpose-built for our use-case.
It could lazy-load resources on demand and store the parsed information from inputs, which would be used by the rest of the system; so our parsed representation would be the ground-truth for the rest of the link checking. For each input, it would contain a big map of the URI of the input (i.e. the path or URL) and its parsed links/fragments.
It should be fully async, and we will need read/write access throughout the program's runtime.
Maybe this is even a graph problem, but I don't feel comfortable going down that route.
In any case, we will need a lot of discussions to come up with a solid design.
However we model it, a check to see if an input contains a link or fragment should be trivial from other parts of the program. We should not deal with ad-hoc resource-fetching within the checking code.
@HU90m, any thoughts on this? Maybe I'm overcomplicating things.
A simplified view of the current flow could be illustrated as:
I think an elegant implementation of this idea would be to remove the collector and move the extractors into the Client. The inputs are converted directly to Requests, with the only transformation being the de-globbing of globs. These initial requests will be given a depth of 0, depth being a new member of Request:
pubstructRequest{/// A valid Uniform Resource Identifier of a given endpoint, which can be/// checked with lycheepuburi:Uri,/// The resource which contained the given URIpubsource:InputSource,// .../// Depth of the link,/// where a depth of 0 is a link provided in the user input.pubdepth:u32,}
When the client handles a request it will fetch the file (form the file system or network). If successfully fetched, It will then parse the file extracting links and optionally fragments, if the file isn't in it's cache. After which, the file will be added to a cache in the client along with it's links and fragments. The extracted links will be converted to Requests with a depth of their origin file plus one, and be put back into the request channel to be handled later.
There will be max_depth option that defaults to 1. If a request's depth is greater or equal to max_depth, it's extracted links won't be put back into the request channel.
This gives us recursive checks for free, when max_depth >= 1! Another advantage is the possibility of combining the fragment and link extractors so that files are only parsed once.
A simplistic illustration of the above:
As it is possible for Client to produce more requests than it consumes, we should probably use mpsc::unbounded_channel.
Anchor support has landed now.
Future improvements can be discussed in new issues and the architecture discussion at #1252.
Big thanks to @HU90m, who single-handedly pulled this off.
Activity
pawroman commentedon Mar 16, 2021
At this point, they're not supported.
This is a bit of a tricky one. Anchors are really the properties of the document contents, not really being integral parts of the URLs.
What I really mean by that is this:
So this might not be very straightforward, but should be perfectly doable. I'd welcome such a feature 😃
[-]Are anchors supported?[/-][+]Add support for anchor tags[/+]MichaIng commentedon Jun 11, 2021
HTMLs are parsed for link extraction on the input HTML documents, but not for the target HTML documents. So it would required to first check whether the target is actually an HTML document, then download it fully (currently it is only partially downloaded or not at all when using
-X head) and then parse the target HTML for a matchingidattribute.When support for internal links via file existence check is added (#21), then it could be at least cheaply added for those:
index.htm/index.html, check for a contained matchingidattribute.In other cases, I think it's difficult if one does not want to imply much overhead for checking the URLs document type and downloading it completely. But nevertheless, the idea/feature itself would be awesome of course 🙂.
MichaIng commentedon Jun 12, 2021
For reference the hint by @polarathene: #21 (comment)
Another case where the difficulties with target downloads etc do not apply, and probably this is what you had in mind anyway, is to check for scroll links within the input HTMLs. so if there is an
<a href="#heading">, to check whether there is anid="heading"as well. If such is wanted, it's good to create a generic method/function for it, so that URL fragments can be generally detected and HTMLs generally scanned for matching IDs, but at first implemented for such same-page scroll links, then depending on #21 for locally stored target HTML files, and gradually for online HTML documents, when this is found to be important enough to fully download the target, based oncontent-type: text/htmlor so. But I'm not sure if the content type header is reliable enough of if there is a risk that a large archive or video file is unintentionally downloaded 😄.polarathene commentedon Jun 12, 2021
Response headers should provide info about content size, completing a request in full (eg downloading a large resource) shouldn't be necessary and could be terminated early AFAIK?
MichaIng commentedon Jun 12, 2021
If you want to check whether an URL fragment is valid or not, you need to download the whole document of course, which is the whole issue I see here, as long as it's not about same-page links or local files. Currently the download is terminated early, reasonably, so currently it is impossible to apply this feature for remote HTML documents without changing the download behaviour based on such things like HTTP headers, which is why I think one needs to evaluate carefully if the effort is worth it or not 😉.
polarathene commentedon Jun 12, 2021
Downloading a complete HTML document to operate on isn't much of a concern vs larger files which I thought was being raised as the concern but could be avoided.
You make a good point though, especially with some HTML documents that are dependent on JS to populate the real content, such as React pages without any pre-rendering process involved. That'd require actually loading and running the JS..
I haven't used lychee myself yet, so I'm not sure if it supports that well (anchor tag feature aside).
lebensterben commentedon Jun 12, 2021
If other attributes of 'a' tag is provided, you can use that to help you determine whether to download that webpage, or whether it links to webpage, etc. But it gets complicated.
https://html.spec.whatwg.org/multipage/links.html#links
mre commentedon Mar 28, 2022
Anchor tags are supported by https://github.com/killercup/link-checker and the implementation is done with a
HashSetof anchor links per page. https://github.com/killercup/link-checker/blob/master/src/links.rs. Something to look into if we get around to adding it to lychee.lara-rium commentedon Sep 26, 2022
Sometimes anchors aren’t even in the HTML itself, like for static websites! Another approach could be to make the request with and without the anchor and compare the scroll location if that’s possible, it means making two requests though
lebensterben commentedon Sep 26, 2022
that requires emulation of webpage rendering and is outside the scope of this project.
15 remaining items
lara-rium commentedon Jul 28, 2023
thats fair enough but another major use case would be linking to documentation, for example swagger
i think we should design the header format used in an independent way so that in the future we can let others set it easier
mre commentedon Jul 28, 2023
Sorry, I don't quite get it. If we find a fragment link in a document, we have to check if that fragment exists. Say we find "#helloworld" and there is a headline named "Hello World", for which a fragment was generated automatically by the hoster (GitHub, GitLab, Swagger (?)). Now the question is if that headline gets converted into "#helloworld" or "#hello-world" or something else. How can we design the header format in such a case? Don't we have to generate the same fragment link as the hoster?
It's likely I might be missing something here.
lara-rium commentedon Jul 28, 2023
yes thats what i mean, the exact implementation would need a balance between verbosity and conciseness but for example something like
[ { " ": "-" } ]this would replace
in the content with-in the header, transforminghello worldtohello-world, we'd likely need more configuration like escaping, casing, handling duplicates and so onmre commentedon Jul 29, 2023
Ah, I understand now. Not sure how to find the right balance between simplicity and flexibility here. Open for suggestions for the configuration format.
lara-rium commentedon Jul 29, 2023
we could use toml, i believe it supports arbitrary keys as string (
"abc" = "xyz") which could be used for replacing characterswe could take an "enum" (not sure toml supports them) for casing, options i can think of are camel case, snake case, kebab case, pascal case and macro case
for escaping i think we already do percent encoding so not sure if theres additional configuration necessary
lastly duplicates are a little tricky, we could have them provide a format template such as
{anchor}-{n}wherenis the index of the occurrence, we'd have to also let them set if its 0 indexed or 1 indexed and whether the first occurrence still needs this formatting (whether to use{anchor}or{anchor}-{0}for the first occurrence)or we could take an entirely different approach and direct users to use the crate for configuration, maybe having them pass a closure like
|element| -> anchor, which is infinitely extensible but may be a dealbreaker for non-rust users or people that dont want to spend the time on thatHU90m commentedon Jul 31, 2023
I'm personally not keen on this idea.
In an ideal world, fragment generation would be specified in the common mark spec, but it isn't and there are a few different common methods. I don't want to encourage xkcd № 927, especially if it involves adding significant complexity to the tool and configuration.
I think hard coding the common generation methods in lychee (or in a separate crate) would help clearly document existing generation methods and hopefully help reduce, stop or even reverse their proliferation.
HU90m commentedon Aug 23, 2023
#1198 has been merged, so of the link types laid out in #185 (comment) Lychee now supports types 1 and 2.
mre commentedon Aug 27, 2023
Awesome progress! 🚀
Here's our current architecture after the changes:

Supporting fragments in URLs (e.g.
https://foo/bar.html#fragas in option 3 in the link types) won't be a small change, I guess.We'd probably have to make few changes to the architecture, because right now there's no way for the
checkstep to "ask" for all links of a given input or even just ask if a link occurs in a given input (e.g. "ishttps://foo/bar.html#fragvalid?").One way to go about it might be to fully decouple input handling from link checking (where inputs can be files or websites).
The fragment cache is a basic version of that, but it's limited to fragments. I think we need a bigger cache for all inputs we encounter and a central entity, which manages this cache. We can think of it as an abstraction on top of the network and the file system, purpose-built for our use-case.
It could lazy-load resources on demand and store the parsed information from inputs, which would be used by the rest of the system; so our parsed representation would be the ground-truth for the rest of the link checking. For each input, it would contain a big map of the URI of the input (i.e. the path or URL) and its parsed links/fragments.
It should be fully async, and we will need read/write access throughout the program's runtime.
Maybe this is even a graph problem, but I don't feel comfortable going down that route.
In any case, we will need a lot of discussions to come up with a solid design.
However we model it, a check to see if an input contains a link or fragment should be trivial from other parts of the program. We should not deal with ad-hoc resource-fetching within the checking code.
@HU90m, any thoughts on this? Maybe I'm overcomplicating things.
HU90m commentedon Sep 3, 2023
That sounds like a splendid plan.
A simplified view of the current flow could be illustrated as:
I think an elegant implementation of this idea would be to remove the collector and move the extractors into the
Client. The inputs are converted directly toRequests, with the only transformation being the de-globbing of globs. These initial requests will be given a depth of 0, depth being a new member ofRequest:When the client handles a request it will fetch the file (form the file system or network). If successfully fetched, It will then parse the file extracting links and optionally fragments, if the file isn't in it's cache. After which, the file will be added to a cache in the client along with it's links and fragments. The extracted links will be converted to
Requests with a depth of their origin file plus one, and be put back into the request channel to be handled later.There will be
max_depthoption that defaults to 1. If a request's depth is greater or equal tomax_depth, it's extracted links won't be put back into the request channel.This gives us recursive checks for free, when
max_depth >= 1! Another advantage is the possibility of combining the fragment and link extractors so that files are only parsed once.A simplistic illustration of the above:
As it is possible for
Clientto produce more requests than it consumes, we should probably usempsc::unbounded_channel.HU90m commentedon Sep 3, 2023
Also I enjoyed the lychee talk, props!
mre commentedon Sep 4, 2023
Thanks for watching and glad you liked it.
Should we move the architecture discussion into a separate issue?
HU90m commentedon Sep 4, 2023
Let's!
mre commentedon Sep 7, 2023
Done. ✌️
mre commentedon Jan 28, 2024
Anchor support has landed now.
Future improvements can be discussed in new issues and the architecture discussion at #1252.
Big thanks to @HU90m, who single-handedly pulled this off.