mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Edit description of MD051/link-fragments to clarify that it implements the GitHub algorithm for creating section links (which converts to lowercase) (refs #591).
This commit is contained in:
parent
38ae54a27f
commit
30353cc733
3 changed files with 69 additions and 30 deletions
|
|
@ -1,5 +1,5 @@
|
|||
This rule is triggered when a link fragment does not correspond to a heading
|
||||
in the document:
|
||||
This rule is triggered when a link fragment does not match any of the fragments
|
||||
that are automatically generated for headings in a document:
|
||||
|
||||
```markdown
|
||||
# Title
|
||||
|
|
@ -7,23 +7,36 @@ in the document:
|
|||
[Link](#fragment)
|
||||
```
|
||||
|
||||
To fix the issue, change the fragment to reference an existing heading:
|
||||
To fix this issue, change the link fragment to reference an existing heading:
|
||||
|
||||
```markdown
|
||||
# Title
|
||||
|
||||
[Link](#title)
|
||||
```
|
||||
|
||||
Alternatively, an HTML `a` tag with an `id` (or a `name`) attribute defines a
|
||||
valid anchor:
|
||||
Alternatively, an HTML `a` tag with an `id` or a `name` attribute can be used to
|
||||
define a fragment:
|
||||
|
||||
```markdown
|
||||
<a id="fragment"></a>
|
||||
<a id="bookmark"></a>
|
||||
|
||||
[Link](#bookmark)
|
||||
```
|
||||
|
||||
Some platforms (e.g., [GitHub][github-section-links]) automatically create HTML
|
||||
anchors for every heading. This makes it easy to link to different sections in
|
||||
a document. These internal links can break over time as headings are renamed.
|
||||
An `a` tag can be useful in scenarios where a heading is not appropriate or for
|
||||
control over the text of the fragment identifier.
|
||||
|
||||
Note: Creating anchors for headings is not part of the CommonMark specification.
|
||||
Rationale: [GitHub section links][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. However, section
|
||||
links change if headings are renamed or removed. This rule helps identify broken
|
||||
section links within a document.
|
||||
|
||||
Section links are **not** part of the CommonMark specification. This rule
|
||||
enforces the [GitHub heading algorithm][github-heading-algorithm] which is:
|
||||
convert heading to lowercase, remove punctuation, convert spaces to dashes, append
|
||||
an incrementing integer as needed for uniqueness.
|
||||
|
||||
[github-section-links]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links
|
||||
[github-heading-algorithm]: https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb
|
||||
|
|
|
|||
33
doc/Rules.md
33
doc/Rules.md
|
|
@ -2077,8 +2077,8 @@ Tags: `links`
|
|||
|
||||
Aliases: `link-fragments`
|
||||
|
||||
This rule is triggered when a link fragment does not correspond to a heading
|
||||
in the document:
|
||||
This rule is triggered when a link fragment does not match any of the fragments
|
||||
that are automatically generated for headings in a document:
|
||||
|
||||
```markdown
|
||||
# Title
|
||||
|
|
@ -2086,26 +2086,39 @@ in the document:
|
|||
[Link](#fragment)
|
||||
```
|
||||
|
||||
To fix the issue, change the fragment to reference an existing heading:
|
||||
To fix this issue, change the link fragment to reference an existing heading:
|
||||
|
||||
```markdown
|
||||
# Title
|
||||
|
||||
[Link](#title)
|
||||
```
|
||||
|
||||
Alternatively, an HTML `a` tag with an `id` (or a `name`) attribute defines a
|
||||
valid anchor:
|
||||
Alternatively, an HTML `a` tag with an `id` or a `name` attribute can be used to
|
||||
define a fragment:
|
||||
|
||||
```markdown
|
||||
<a id="fragment"></a>
|
||||
<a id="bookmark"></a>
|
||||
|
||||
[Link](#bookmark)
|
||||
```
|
||||
|
||||
Some platforms (e.g., [GitHub][github-section-links]) automatically create HTML
|
||||
anchors for every heading. This makes it easy to link to different sections in
|
||||
a document. These internal links can break over time as headings are renamed.
|
||||
An `a` tag can be useful in scenarios where a heading is not appropriate or for
|
||||
control over the text of the fragment identifier.
|
||||
|
||||
Note: Creating anchors for headings is not part of the CommonMark specification.
|
||||
Rationale: [GitHub section links][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. However, section
|
||||
links change if headings are renamed or removed. This rule helps identify broken
|
||||
section links within a document.
|
||||
|
||||
Section links are **not** part of the CommonMark specification. This rule
|
||||
enforces the [GitHub heading algorithm][github-heading-algorithm] which is:
|
||||
convert heading to lowercase, remove punctuation, convert spaces to dashes, append
|
||||
an incrementing integer as needed for uniqueness.
|
||||
|
||||
[github-section-links]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links
|
||||
[github-heading-algorithm]: https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb
|
||||
|
||||
<a name="md052"></a>
|
||||
|
||||
|
|
|
|||
33
doc/md051.md
33
doc/md051.md
|
|
@ -4,8 +4,8 @@ Tags: `links`
|
|||
|
||||
Aliases: `link-fragments`
|
||||
|
||||
This rule is triggered when a link fragment does not correspond to a heading
|
||||
in the document:
|
||||
This rule is triggered when a link fragment does not match any of the fragments
|
||||
that are automatically generated for headings in a document:
|
||||
|
||||
```markdown
|
||||
# Title
|
||||
|
|
@ -13,23 +13,36 @@ in the document:
|
|||
[Link](#fragment)
|
||||
```
|
||||
|
||||
To fix the issue, change the fragment to reference an existing heading:
|
||||
To fix this issue, change the link fragment to reference an existing heading:
|
||||
|
||||
```markdown
|
||||
# Title
|
||||
|
||||
[Link](#title)
|
||||
```
|
||||
|
||||
Alternatively, an HTML `a` tag with an `id` (or a `name`) attribute defines a
|
||||
valid anchor:
|
||||
Alternatively, an HTML `a` tag with an `id` or a `name` attribute can be used to
|
||||
define a fragment:
|
||||
|
||||
```markdown
|
||||
<a id="fragment"></a>
|
||||
<a id="bookmark"></a>
|
||||
|
||||
[Link](#bookmark)
|
||||
```
|
||||
|
||||
Some platforms (e.g., [GitHub][github-section-links]) automatically create HTML
|
||||
anchors for every heading. This makes it easy to link to different sections in
|
||||
a document. These internal links can break over time as headings are renamed.
|
||||
An `a` tag can be useful in scenarios where a heading is not appropriate or for
|
||||
control over the text of the fragment identifier.
|
||||
|
||||
Note: Creating anchors for headings is not part of the CommonMark specification.
|
||||
Rationale: [GitHub section links][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. However, section
|
||||
links change if headings are renamed or removed. This rule helps identify broken
|
||||
section links within a document.
|
||||
|
||||
Section links are **not** part of the CommonMark specification. This rule
|
||||
enforces the [GitHub heading algorithm][github-heading-algorithm] which is:
|
||||
convert heading to lowercase, remove punctuation, convert spaces to dashes, append
|
||||
an incrementing integer as needed for uniqueness.
|
||||
|
||||
[github-section-links]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links
|
||||
[github-heading-algorithm]: https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue