linkFragments
Reports link fragments that don't exist in the document.
✅ This rule is included in the md logical presets.
Link fragments (URLs that start with #) should reference valid headings or anchors in the document.
This rule helps prevent broken internal links by ensuring that every fragment link points to an existing heading or HTML anchor.
It uses GitHub’s heading algorithm for generating heading IDs, ensuring compatibility with how GitHub renders Markdown heading anchors.
Examples
Section titled “Examples”[Invalid Link](#non-existent-heading)
# Some Heading# Some Heading
[Case Mismatch](#other-heading)# Introduction
[Invalid Link](#introductions)# Introduction
[Valid Link](#introduction)<h1 id="html-anchor">HTML Anchor</h1>
[Link to HTML anchor](#html-anchor)<a name="named-anchor">Named Anchor</a>
[Link to named anchor](#named-anchor)[Link to top of page](#top)# café
[Link to café](#café)When Not To Use It
Section titled “When Not To Use It”You might consider disabling this rule if:
- You are using a Markdown processor or static site generator that has a significantly different algorithm for generating heading IDs
- You have many dynamically generated links or fragments that cannot be easily validated statically
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
markdown/no-missing-link-fragments - Markdownlint:
link-fragments
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.