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

Warn against dead links within the document #253

Closed
ben-clayton opened this issue Feb 12, 2020 · 5 comments
Closed

Warn against dead links within the document #253

ben-clayton opened this issue Feb 12, 2020 · 5 comments

Comments

@ben-clayton
Copy link

It would be fantastic if bad anchor-style links were detected and warned.
I wouldn't expect bad external URL links to be caught.

@DavidAnson DavidAnson transferred this issue from DavidAnson/vscode-markdownlint Feb 12, 2020
@DavidAnson DavidAnson changed the title Warn against dead links Warn against dead links within the document Feb 12, 2020
@koppor
Copy link
Contributor

koppor commented Apr 29, 2020

Dead external links can be discovered with markdown-link-check:

One file: npx markdown-link-check README.md.

Multiple files outputting the result into a text file:

find . -name \*.md -exec npx markdown-link-check -qq {} \; > bad-links.txt

Note that I used npx to avoid explicit global installation of the markdown-link-check package.

@nichtich
Copy link

nichtich commented Jun 29, 2020

Thanks for the pointer to markdown-link-check, but I'd prefer to have basic support as part of markdownlint instead of having to use yet another tool with different usage and a lot of functionality I don't need anyway. The dead-links use case in this issue is anchor-style links, so implementation would be:

  1. extract all heading titles and create anchor ids
  2. extract all link targets starting with # and check whether a matching id exists.

Note this would not catch link targets within inline HTML but this is discouraged by MD033 anyway.

@DavidAnson
Copy link
Owner

@nichtich Is the anchor ID algorithm part of a specification anywhere, or are you suggesting making this specific to GitHub?

@nichtich
Copy link

Anchor links from header titles have been discussed in CommonMark but it's not part of CommonMark. Popular implementations that create anchor ids from header titles include Pandoc and GitHub. Pandoc also supports GitHub algorithm (see feature gfm_auto_identifiers), so GitHub algorithm seems the best choice:

  • spaces are converted to dashes (-)
  • uppercase characters are converted to lowercase characters
  • punctuation characters other than - and _ are removed
  • if nothing is left, use the identifier section

For a more extensive comparison of algorithms see https://babelmark.github.io/

@DavidAnson
Copy link
Owner

Great info, thank you!

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

No branches or pull requests

4 participants