Refine previous commit for MD051/link-fragments to tweak behavior, tests, and documentation.

This commit is contained in:
David Anson 2024-02-10 15:36:12 -08:00
parent 242b35f98f
commit 45c8766eda
8 changed files with 259 additions and 148 deletions

View file

@ -2100,9 +2100,9 @@ generated name (see below):
[Link](#heading-name)
```
Furthermore, this rule mandates the use of lowercase for link fragments.
Thus, even though the link points to the correct fragment, the following example
will still trigger this rule:
Link fragments may be handled case-sensitively, so this rule requires fragments
to exactly match the [GitHub heading algorithm][github-heading-algorithm].
Therefore, the following example is reported as a violation:
```markdown
# Heading Name
@ -2132,28 +2132,21 @@ attribute can be used to define a fragment:
An `a` tag can be useful in scenarios where a heading is not appropriate or for
control over the text of the fragment identifier.
GitHub supports links to [specific lines][github-lines-links].
This rule also recognizes the custom fragment syntax used by GitHub to highlight
[specific content in a document][github-linking-to-content].
For example, to link to line 12 of current Markdown file:
For example, this link to line 20:
```markdown
[Go to line 12](#L12)
[Link](#L20)
```
GitHub also allows to specify a column number:
And this link to content starting within line 19 running into line 21:
```markdown
[Go to line 12, column 34](#L12-L34)
[Link](#L19C5-L21C11)
```
Or a range of lines/columns:
```markdown
[Go to lines 12-34](#L12-L34)
```
So this rule will not report violations when this syntax is used.
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.
@ -2167,7 +2160,7 @@ 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/f13a1534cb650ba17af400d1acd3a22c28004c09/lib/html/pipeline/toc_filter.rb
[github-lines-links]: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-a-permanent-link-to-a-code-snippet#linking-to-markdown#linking-to-markdown
[github-linking-to-content]: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-a-permanent-link-to-a-code-snippet#linking-to-markdown#linking-to-markdown
<a name="md052"></a>

View file

@ -24,9 +24,9 @@ generated name (see below):
[Link](#heading-name)
```
Furthermore, this rule mandates the use of lowercase for link fragments.
Thus, even though the link points to the correct fragment, the following example
will still trigger this rule:
Link fragments may be handled case-sensitively, so this rule requires fragments
to exactly match the [GitHub heading algorithm][github-heading-algorithm].
Therefore, the following example is reported as a violation:
```markdown
# Heading Name
@ -56,28 +56,21 @@ attribute can be used to define a fragment:
An `a` tag can be useful in scenarios where a heading is not appropriate or for
control over the text of the fragment identifier.
GitHub supports links to [specific lines][github-lines-links].
This rule also recognizes the custom fragment syntax used by GitHub to highlight
[specific content in a document][github-linking-to-content].
For example, to link to line 12 of current Markdown file:
For example, this link to line 20:
```markdown
[Go to line 12](#L12)
[Link](#L20)
```
GitHub also allows to specify a column number:
And this link to content starting within line 19 running into line 21:
```markdown
[Go to line 12, column 34](#L12-L34)
[Link](#L19C5-L21C11)
```
Or a range of lines/columns:
```markdown
[Go to lines 12-34](#L12-L34)
```
So this rule will not report violations when this syntax is used.
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.
@ -91,4 +84,4 @@ 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/f13a1534cb650ba17af400d1acd3a22c28004c09/lib/html/pipeline/toc_filter.rb
[github-lines-links]: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-a-permanent-link-to-a-code-snippet#linking-to-markdown#linking-to-markdown
[github-linking-to-content]: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-a-permanent-link-to-a-code-snippet#linking-to-markdown#linking-to-markdown