Skip to content

anchor link checking is broken #225

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

Open
OmarTawfik opened this issue Dec 8, 2022 · 5 comments
Open

anchor link checking is broken #225

OmarTawfik opened this issue Dec 8, 2022 · 5 comments

Comments

@OmarTawfik
Copy link

OmarTawfik commented Dec 8, 2022

Thanks for the awesome linter. Long time user, first time contributor.
I have a bunch of files that define HTML code blocks, with id attributes:

<code id="foo"> .... </code>
<code id="bar"> .... </code>

Then I have some links that reference them:

<a href="#foo"> ... </a>
<a href="../other-file/#bar"> ... </a>

After upgrading to the latest version 3.10.3, it broke CI because of new errors everywhere. I traced it down to the following issues:

  1. The linter doesn't collect links from id attributes. So any links pointing to it (like href="#foo") produce errors.
  2. The linter doesn't lint href attributes that have a file path AND a header.
    1. href=".#id" for the same markdown file.
    2. href="../relative/path#id" for a markdown file at ../relative/path.md or ../relative/path/index.md.

Any feedback/pointers are greatly appreciated. I imagine it is not too hard to fix, given that the linter has partial support for it already.

Although my plate is currently full, I welcome any code pointers/green light on how to fix it, and I can take a stab at it at some point in the future.

@OmarTawfik
Copy link
Author

cc @tcort any thoughts about how involving the fix is? I imagine it is a simple change, but probably involves a few different packages.

@MikeMcC399
Copy link
Contributor

@MikeMcC399

This comment was marked as outdated.

Copy link

This issue has been marked as stale because it has been open 60 days with no activity. It will be closed in 30 days unless the stale label is removed or someone adds a comment.

@github-actions github-actions bot added the Stale label Apr 11, 2025
@per1234
Copy link

per1234 commented Apr 11, 2025

This has been fixed (I assume by 0348390 / #331, but can't precisely bisect due to #368).

$ printf '[link to HTML anchor](#html-anchor)\n\n<code id="html-anchor"> .... </code>\n' > /tmp/foo.md

$ npx github:tcort/markdown-link-check#29694c8 /tmp/foo.md  # Last usable bad commit.

FILE: C:/Users/per/AppData/Local/Temp/foo.md
  [✖] #html-anchor

  1 links checked.

  ERROR: 1 dead links found!
  [✖] #html-anchor → Status: 404

$ npx github:tcort/markdown-link-check#834a4e2 /tmp/foo.md  # First usable good commit.

FILE: C:/Users/per/AppData/Local/Temp/foo.md
  [✓] #html-anchor

  1 links checked.

@github-actions github-actions bot removed the Stale label Apr 18, 2025
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