Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 1.37 KB

File metadata and controls

51 lines (34 loc) · 1.37 KB

MD051 - Link Fragments Should Be Valid

Description

This rule ensures that link fragments in Markdown documents match existing headings or predefined anchors according to GitHub's heading algorithm.

Supported Options

  • ignore_case: Ignore case when comparing fragments (default: false)
  • ignored_pattern: Regular expression to ignore specific fragment patterns (default: "")

Examples

Valid:

# Heading Name

[Link](#heading-name)

Invalid:

# Heading Name

[Link](#Heading-Name)  # Case mismatch

Additional Fragment Types Supported

  • Custom named anchors: # Heading {#custom-name}
  • HTML anchors: <a id="bookmark"></a>
  • Special GitHub fragments: [Link](#L20), [Link](#L19C5-L21C11)

Rationale

"GitHub section links are created automatically for every heading when Markdown content is displayed on GitHub. This makes it easy to link directly to different sections within a document."

Fixing Violations

Update link fragments to match:

  • Lowercase heading text
  • Replace spaces with dashes
  • Remove punctuation
  • Append incrementing integer if needed for uniqueness

Notes

  • Not part of CommonMark specification
  • Follows GitHub's heading algorithm for fragment generation
  • Uses GitHub's official specification as source of truth for special fragments
  • May be more strict than some other implementations for better accuracy