mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD051/link-fragments to allow HTML's implicit "#top" fragment (fixes #1488).
This commit is contained in:
parent
5749c8dcf7
commit
50300fa7af
7 changed files with 58 additions and 1 deletions
|
@ -52,6 +52,13 @@ 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.
|
||||
|
||||
[HTML links to `#top` scroll to the top of a document][html-top-fragment]. This
|
||||
rule allows that syntax (using lower-case for consistency):
|
||||
|
||||
```markdown
|
||||
[Link](#top)
|
||||
```
|
||||
|
||||
This rule also recognizes the custom fragment syntax used by GitHub to highlight
|
||||
[specific content in a document][github-linking-to-content].
|
||||
|
||||
|
@ -81,3 +88,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-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
|
||||
[html-top-fragment]: https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
|
||||
|
|
|
@ -2198,6 +2198,13 @@ 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.
|
||||
|
||||
[HTML links to `#top` scroll to the top of a document][html-top-fragment]. This
|
||||
rule allows that syntax (using lower-case for consistency):
|
||||
|
||||
```markdown
|
||||
[Link](#top)
|
||||
```
|
||||
|
||||
This rule also recognizes the custom fragment syntax used by GitHub to highlight
|
||||
[specific content in a document][github-linking-to-content].
|
||||
|
||||
|
@ -2227,6 +2234,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-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
|
||||
[html-top-fragment]: https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
|
||||
|
||||
<a name="md052"></a>
|
||||
|
||||
|
|
|
@ -64,6 +64,13 @@ 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.
|
||||
|
||||
[HTML links to `#top` scroll to the top of a document][html-top-fragment]. This
|
||||
rule allows that syntax (using lower-case for consistency):
|
||||
|
||||
```markdown
|
||||
[Link](#top)
|
||||
```
|
||||
|
||||
This rule also recognizes the custom fragment syntax used by GitHub to highlight
|
||||
[specific content in a document][github-linking-to-content].
|
||||
|
||||
|
@ -93,3 +100,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-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
|
||||
[html-top-fragment]: https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
|
||||
|
|
|
@ -66,7 +66,8 @@ export default {
|
|||
"parser": "micromark",
|
||||
"function": function MD051(params, onError) {
|
||||
const ignoreCase = params.config.ignore_case || false;
|
||||
const fragments = new Map();
|
||||
/** @type {Map<string, number>} */
|
||||
const fragments = new Map([ [ "#top", 0 ] ]);
|
||||
|
||||
// Process headings
|
||||
const headingTexts = filterByTypesCached([ "atxHeadingText", "setextHeadingText" ]);
|
||||
|
|
|
@ -332,6 +332,12 @@ Valid Setext Heading with Named Fragment {#setext}
|
|||
|
||||
[Invalid](#C11-L4C31) {MD051}
|
||||
|
||||
## Implicit Fragments
|
||||
|
||||
[Valid](#top)
|
||||
|
||||
[Invalid](#ToP) {MD051}
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"emphasis-style": false,
|
||||
"heading-style": false,
|
||||
|
|
|
@ -25749,6 +25749,26 @@ Generated by [AVA](https://avajs.dev).
|
|||
'link-fragments',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '[Invalid](#ToP)',
|
||||
errorDetail: 'Expected: #top; Actual: #ToP',
|
||||
errorRange: [
|
||||
1,
|
||||
15,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 4,
|
||||
editColumn: 11,
|
||||
insertText: '#top',
|
||||
},
|
||||
lineNumber: 339,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
'MD051',
|
||||
'link-fragments',
|
||||
],
|
||||
},
|
||||
],
|
||||
fixed: `# Valid/Invalid Link Fragments␊
|
||||
␊
|
||||
|
@ -26084,6 +26104,12 @@ Generated by [AVA](https://avajs.dev).
|
|||
␊
|
||||
[Invalid](#C11-L4C31) {MD051}␊
|
||||
␊
|
||||
## Implicit Fragments␊
|
||||
␊
|
||||
[Valid](#top)␊
|
||||
␊
|
||||
[Invalid](#top) {MD051}␊
|
||||
␊
|
||||
<!-- markdownlint-configure-file {␊
|
||||
"emphasis-style": false,␊
|
||||
"heading-style": false,␊
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue