gjtorikian / html-proofer

Test your rendered HTML files to make sure they're accurate.
MIT License
1.57k stars 196 forks source link

Link checker triggered on <a name="..."> and <a id="..."> #819

Open franke-biosaxs opened 4 months ago

franke-biosaxs commented 4 months ago

I'm new to web page building and am using Jekyll to build static .html from Markdown. This project seems to be the perfect match to check the links in the resulting files. And it found ... way too many (v5.0.8, installed via gem).

In particular, consider the generated HTML:

Lorem <a id="ipsum">Ipsum</a>. Etc pp.

Here html-proofer tells me:

'a' tag is missing a reference

The same is true for \<a name="ipsum">Ipsum\</a>.

Although the W3C validator sees no issue with this usage. The mdn web docs state on name/id attributes:

name: Was required to define a possible target location in a page. In HTML 4.01, id and name could both be used on \<a>, as long as they had identical values. Note: Use the global attribute id instead.

In Issue #746 it was stated that one should rather err on the cautious side with empty href="" tags, and I can see that. However, there is a valid use for \<a> without href attribute altogether -- if and only if at least one of the name or id attributes are present.

gjtorikian commented 4 months ago

Curiously, name is listed under Deprecated attributes; this project has only ever really attempted to target HTML 5.

The single id rather than href is interesting, I never knew that. Would the suggestion of setting allow_missing_href = true work for you though?

franke-biosaxs commented 4 months ago

Thanks for the quick reply.

I only quoted the name attribute as it included a description of what it was meant for, i.e. what id is being used for here. Don't know if this is a common thing to do nowadays, though. I just changed the name with id when preparing my texts, out of habit of old when <a name="..."> was the only way to define anchors (that I knew of).

The single id rather than href is interesting, I never knew that. Would the suggestion of setting allow_missing_href = true work for you though?

In the sense of not showing the warning for <a id="..."> yes, it will not show the message. However, I would also not be notified in the rare cases where I might actually have missed to fill in the href, unfortunately.

To provide context: running html-proofer on my project as-is results in about 2000 failures, by far the most are "'a' tag is missing a reference" messages - I'd guess that at most five of those are actually missing hrefs and all others are of the <a id="..."> kind. I would have to verify each and every one to find them, though.

jimklimov commented 4 months ago

Cheers, I've hit this issue as well, with asciidoc generated HTML pages which also use <a id="token"></a> anchors and elsewhere the <a href="#token">Some text</a> references.

Per https://www.w3schools.com/tags/tag_a.asp this is valid, the a tag accepts "Global Attributes" which include an id : https://www.w3schools.com/tags/ref_standardattributes.asp

It seems that the <a name=...> syntax is obsolete (not documented in the page above); Q&A like https://stackoverflow.com/questions/16974480/if-a-name-is-obsolete-what-is-preferred confirm that. The name attribute is known for some other tags/elements: https://www.w3schools.com/tags/att_name.asp

jimklimov commented 4 months ago

To answer the additional question above, at least with htmlproofer 3.14.1 (as available in the Ubuntu 22 that I have under hand), and command-line tool usage, the option did not help:

Ran on 1 file!

A variant of the page is available at https://networkupstools.org/protocols/apcsmart.html and links like https://networkupstools.org/protocols/apcsmart.html#R do work in a browser to jump to referred parts of the table etc.

jimklimov commented 4 months ago

Curiously, I haven't seen complaints about 'a' tag is missing a reference on the systems I've tried (also checked htmlproofer 3.19.2 on Debian 12).

But given that the current release is 5.0.9, maybe that complaint just appeared "too recently" :)

jimklimov commented 4 months ago

UPDATE: With a custom-built 5.0.9, it seems to mostly like the existing file (at least, WRT the internal hash links).