Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
franke-biosaxs opened this issue May 6, 2024 · 6 comments
Open

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

franke-biosaxs opened this issue May 6, 2024 · 6 comments

Comments

@franke-biosaxs
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link

jimklimov commented May 9, 2024

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
Copy link

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:

  • In full form - "needless":
:; htmlproofer --allow_missing_href=true protocols/apcsmart.html
/usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary/program.rb:31:in `go': needless argument: --allow_missing_href=true (OptionParser::NeedlessArgument)
        from /usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
        from /usr/bin/htmlproofer:11:in `<main>'
  • In short form - no effect:
:; htmlproofer --allow_missing_href --disable-external protocols/apcsmart.html
Running ["ImageCheck", "LinkCheck", "ScriptCheck"] on protocols/apcsmart.html on *.html...


Ran on 1 file!


- protocols/apcsmart.html
  *  linking to internal hash #@ that does not exist (line 729)
     <a href="#@"><strong></strong></a>
  *  linking to internal hash #B that does not exist (line 508)
     <a href="#B">actual voltage</a>
  *  linking to internal hash #B that does not exist (line 515)
     <a href="#B">current battery voltage</a>
...
  *  linking to internal hash #x that does not exist (line 708)
     <a href="#x">battery change date</a>
htmlproofer 3.14.1 | Error:  HTML-Proofer found 23 failures!
/usr/lib/ruby/vendor_ruby/html-proofer/runner.rb:172:in `print_failed_tests': \e[31mHTML-Proofer found 23 failures!\e[0m (RuntimeError)
        from /usr/lib/ruby/vendor_ruby/html-proofer/runner.rb:50:in `run'
        from /usr/bin/htmlproofer:105:in `block (2 levels) in <main>'
        from /usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
        from /usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
        from /usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
        from /usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
        from /usr/share/rubygems-integration/all/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
        from /usr/bin/htmlproofer:11:in `<main>'

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
Copy link

jimklimov commented May 9, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants