Update MD051/link-fragments to support id attributes on non-a elements (fixes #538).

The `name` is only an anchor on `a` elements, but `id` is a universal
attribute on all elements.

Also fix match on id/name to be complete, not just a suffix.
This commit is contained in:
Mark Lodato 2022-07-28 00:42:05 -04:00 committed by GitHub
parent cba2ca0dbd
commit 6c8ef48f94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 102 additions and 18 deletions

View file

@ -20950,7 +20950,7 @@ Generated by [AVA](https://avajs.dev).
31,
],
fixInfo: null,
lineNumber: 132,
lineNumber: 144,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
@ -20966,7 +20966,7 @@ Generated by [AVA](https://avajs.dev).
36,
],
fixInfo: null,
lineNumber: 134,
lineNumber: 146,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
@ -20982,7 +20982,7 @@ Generated by [AVA](https://avajs.dev).
28,
],
fixInfo: null,
lineNumber: 136,
lineNumber: 148,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
@ -20998,7 +20998,7 @@ Generated by [AVA](https://avajs.dev).
18,
],
fixInfo: null,
lineNumber: 138,
lineNumber: 150,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
@ -21014,7 +21014,55 @@ Generated by [AVA](https://avajs.dev).
21,
],
fixInfo: null,
lineNumber: 140,
lineNumber: 152,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
'MD051',
'link-fragments',
],
},
{
errorContext: '[Invalid](#name-for-other-element)',
errorDetail: null,
errorRange: [
1,
34,
],
fixInfo: null,
lineNumber: 154,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
'MD051',
'link-fragments',
],
},
{
errorContext: '[Invalid](#name-should-be-ignored)',
errorDetail: null,
errorRange: [
1,
34,
],
fixInfo: null,
lineNumber: 156,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
'MD051',
'link-fragments',
],
},
{
errorContext: '[Invalid](#not-an-id-should-be-ignored)',
errorDetail: null,
errorRange: [
1,
39,
],
fixInfo: null,
lineNumber: 158,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
@ -21027,7 +21075,7 @@ Generated by [AVA](https://avajs.dev).
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 142,
lineNumber: 160,
ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051',
ruleNames: [
@ -21090,6 +21138,10 @@ Generated by [AVA](https://avajs.dev).
[Valid](#HREFandID)␊
[Valid](#id-for-other-element)␊
[Valid](#id-after-name)␊
[Valid][goodref]␊
### Valid H3 Heading␊
@ -21163,6 +21215,14 @@ Generated by [AVA](https://avajs.dev).
<A href="https://example.com" id="HREFandID">Text</A>
<p id="id-for-other-element"></p>
<p name="name-for-other-element"></p>
<input name="name-should-be-ignored" id="id-after-name">
<a data-id="not-an-id-should-be-ignored">
[goodref]: #namedlink
## Invalid Fragments␊
@ -21177,6 +21237,12 @@ Generated by [AVA](https://avajs.dev).
[Invalid](#hrefandid) {MD051}␊
[Invalid](#name-for-other-element) {MD051}␊
[Invalid](#name-should-be-ignored) {MD051}␊
[Invalid](#not-an-id-should-be-ignored) {MD051}␊
[Invalid][badref] {MD051}␊
[badref]: #missing