Update MD051/link-fragments to also look for a fragment matching the URI-encoded link definition (implicit behavior in previous version via markdown-it) (fixes #954, fixes #955).

This commit is contained in:
David Anson 2023-09-06 20:50:56 -07:00
parent b7ef571401
commit 1ddee6b195
5 changed files with 62 additions and 37 deletions

View file

@ -6328,7 +6328,10 @@ module.exports = {
try { try {
var _loop = function _loop() { var _loop = function _loop() {
var definition = _step4.value; var definition = _step4.value;
if (definition.text.length > 1 && definition.text.startsWith("#") && !fragments.has(definition.text)) { var endColumn = definition.endColumn,
startColumn = definition.startColumn,
text = definition.text;
if (text.length > 1 && text.startsWith("#") && !fragments.has(text) && !fragments.has("#".concat(encodeURIComponent(text.slice(1))))) {
// eslint-disable-next-line no-undef-init // eslint-disable-next-line no-undef-init
var context = undefined; var context = undefined;
// eslint-disable-next-line no-undef-init // eslint-disable-next-line no-undef-init
@ -6339,18 +6342,18 @@ module.exports = {
context = link.text; context = link.text;
range = [link.startColumn, link.endColumn - link.startColumn]; range = [link.startColumn, link.endColumn - link.startColumn];
fixInfo = { fixInfo = {
"editColumn": definition.startColumn, "editColumn": startColumn,
"deleteCount": definition.endColumn - definition.startColumn "deleteCount": endColumn - startColumn
}; };
} }
var definitionTextLower = definition.text.toLowerCase(); var textLower = text.toLowerCase();
var mixedCaseKey = _toConsumableArray(fragments.keys()).find(function (key) { var mixedCaseKey = _toConsumableArray(fragments.keys()).find(function (key) {
return definitionTextLower === key.toLowerCase(); return textLower === key.toLowerCase();
}); });
if (mixedCaseKey) { if (mixedCaseKey) {
// @ts-ignore // @ts-ignore
(fixInfo || {}).insertText = mixedCaseKey; (fixInfo || {}).insertText = mixedCaseKey;
addErrorDetailIf(onError, link.startLine, mixedCaseKey, definition.text, undefined, context, range, fixInfo); addErrorDetailIf(onError, link.startLine, mixedCaseKey, text, undefined, context, range, fixInfo);
} else { } else {
addError(onError, link.startLine, undefined, context, range); addError(onError, link.startLine, undefined, context, range);
} }

View file

@ -99,10 +99,12 @@ module.exports = {
for (const link of links) { for (const link of links) {
const definitions = filterByTypes(link.children, [ definitionType ]); const definitions = filterByTypes(link.children, [ definitionType ]);
for (const definition of definitions) { for (const definition of definitions) {
const { endColumn, startColumn, text } = definition;
if ( if (
(definition.text.length > 1) && (text.length > 1) &&
definition.text.startsWith("#") && text.startsWith("#") &&
!fragments.has(definition.text) !fragments.has(text) &&
!fragments.has(`#${encodeURIComponent(text.slice(1))}`)
) { ) {
// eslint-disable-next-line no-undef-init // eslint-disable-next-line no-undef-init
let context = undefined; let context = undefined;
@ -114,13 +116,13 @@ module.exports = {
context = link.text; context = link.text;
range = [ link.startColumn, link.endColumn - link.startColumn ]; range = [ link.startColumn, link.endColumn - link.startColumn ];
fixInfo = { fixInfo = {
"editColumn": definition.startColumn, "editColumn": startColumn,
"deleteCount": definition.endColumn - definition.startColumn "deleteCount": endColumn - startColumn
}; };
} }
const definitionTextLower = definition.text.toLowerCase(); const textLower = text.toLowerCase();
const mixedCaseKey = [ ...fragments.keys() ] const mixedCaseKey = [ ...fragments.keys() ]
.find((key) => definitionTextLower === key.toLowerCase()); .find((key) => textLower === key.toLowerCase());
if (mixedCaseKey) { if (mixedCaseKey) {
// @ts-ignore // @ts-ignore
(fixInfo || {}).insertText = mixedCaseKey; (fixInfo || {}).insertText = mixedCaseKey;
@ -128,7 +130,7 @@ module.exports = {
onError, onError,
link.startLine, link.startLine,
mixedCaseKey, mixedCaseKey,
definition.text, text,
undefined, undefined,
context, context,
range, range,

View file

@ -44,8 +44,16 @@
[Valid](#valid-heading-about-lh%C3%B4pitals-rule) [Valid](#valid-heading-about-lh%C3%B4pitals-rule)
[Valid](#valid-heading-about-lhôpitals-rule)
[Valid](#en-t%C3%AAte-valide-dans-fran%C3%A7ais-pour-v%C3%A9rification) [Valid](#en-t%C3%AAte-valide-dans-fran%C3%A7ais-pour-v%C3%A9rification)
[Valid](#en-tête-valide-dans-français-pour-vérification)
[Valid](#%E6%A0%87%E9%A2%98)
[Valid](#标题)
[Valid](#valid-heading-is-a-link) [Valid](#valid-heading-is-a-link)
[Valid](#valid-heading-has-a-link) [Valid](#valid-heading-has-a-link)
@ -137,6 +145,8 @@ Text
### En-tête Valide Dans Français Pour Vérification ### En-tête Valide Dans Français Pour Vérification
### 标题
### [Valid Heading Is a Link](https://example.com) ### [Valid Heading Is a Link](https://example.com)
### Valid Heading [Has a Link](https://example.com) ### Valid Heading [Has a Link](https://example.com)

View file

@ -23969,7 +23969,7 @@ Generated by [AVA](https://avajs.dev).
37, 37,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 172, lineNumber: 182,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -23985,7 +23985,7 @@ Generated by [AVA](https://avajs.dev).
31, 31,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 174, lineNumber: 184,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24001,7 +24001,7 @@ Generated by [AVA](https://avajs.dev).
36, 36,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 176, lineNumber: 186,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24017,7 +24017,7 @@ Generated by [AVA](https://avajs.dev).
28, 28,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 178, lineNumber: 188,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24033,7 +24033,7 @@ Generated by [AVA](https://avajs.dev).
18, 18,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 180, lineNumber: 190,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24053,7 +24053,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 11, editColumn: 11,
insertText: '#HREFandID', insertText: '#HREFandID',
}, },
lineNumber: 182, lineNumber: 192,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24069,7 +24069,7 @@ Generated by [AVA](https://avajs.dev).
34, 34,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 184, lineNumber: 194,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24085,7 +24085,7 @@ Generated by [AVA](https://avajs.dev).
34, 34,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 186, lineNumber: 196,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24101,7 +24101,7 @@ Generated by [AVA](https://avajs.dev).
39, 39,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 188, lineNumber: 198,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24114,7 +24114,7 @@ Generated by [AVA](https://avajs.dev).
errorDetail: null, errorDetail: null,
errorRange: null, errorRange: null,
fixInfo: null, fixInfo: null,
lineNumber: 190, lineNumber: 200,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24130,7 +24130,7 @@ Generated by [AVA](https://avajs.dev).
28, 28,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 195, lineNumber: 205,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24150,7 +24150,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 9, editColumn: 9,
insertText: '#valid-fragments', insertText: '#valid-fragments',
}, },
lineNumber: 199, lineNumber: 209,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24170,7 +24170,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 12, editColumn: 12,
insertText: '#namedlink', insertText: '#namedlink',
}, },
lineNumber: 201, lineNumber: 211,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24183,7 +24183,7 @@ Generated by [AVA](https://avajs.dev).
errorDetail: 'Expected: #namedlink; Actual: #NAMEDLINK', errorDetail: 'Expected: #namedlink; Actual: #NAMEDLINK',
errorRange: null, errorRange: null,
fixInfo: null, fixInfo: null,
lineNumber: 203, lineNumber: 213,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24203,7 +24203,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 13, editColumn: 13,
insertText: '#idlink', insertText: '#idlink',
}, },
lineNumber: 208, lineNumber: 218,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24219,7 +24219,7 @@ Generated by [AVA](https://avajs.dev).
26, 26,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 243, lineNumber: 253,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24235,7 +24235,7 @@ Generated by [AVA](https://avajs.dev).
26, 26,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 245, lineNumber: 255,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24251,7 +24251,7 @@ Generated by [AVA](https://avajs.dev).
20, 20,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 247, lineNumber: 257,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24267,7 +24267,7 @@ Generated by [AVA](https://avajs.dev).
23, 23,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 249, lineNumber: 259,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24283,7 +24283,7 @@ Generated by [AVA](https://avajs.dev).
22, 22,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 251, lineNumber: 261,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24299,7 +24299,7 @@ Generated by [AVA](https://avajs.dev).
42, 42,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 253, lineNumber: 263,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24315,7 +24315,7 @@ Generated by [AVA](https://avajs.dev).
21, 21,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 255, lineNumber: 265,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24331,7 +24331,7 @@ Generated by [AVA](https://avajs.dev).
21, 21,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 257, lineNumber: 267,
ruleDescription: 'Link fragments should be valid', ruleDescription: 'Link fragments should be valid',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
ruleNames: [ ruleNames: [
@ -24386,8 +24386,16 @@ Generated by [AVA](https://avajs.dev).
[Valid](#valid-heading-about-lh%C3%B4pitals-rule)␊ [Valid](#valid-heading-about-lh%C3%B4pitals-rule)␊
[Valid](#valid-heading-about-lhôpitals-rule)␊
[Valid](#en-t%C3%AAte-valide-dans-fran%C3%A7ais-pour-v%C3%A9rification)␊ [Valid](#en-t%C3%AAte-valide-dans-fran%C3%A7ais-pour-v%C3%A9rification)␊
[Valid](#en-tête-valide-dans-français-pour-vérification)␊
[Valid](#%E6%A0%87%E9%A2%98)␊
[Valid](#标题)␊
[Valid](#valid-heading-is-a-link)␊ [Valid](#valid-heading-is-a-link)␊
[Valid](#valid-heading-has-a-link)␊ [Valid](#valid-heading-has-a-link)␊
@ -24479,6 +24487,8 @@ Generated by [AVA](https://avajs.dev).
### En-tête Valide Dans Français Pour Vérification␊ ### En-tête Valide Dans Français Pour Vérification␊
### 标题␊
### [Valid Heading Is a Link](https://example.com)␊ ### [Valid Heading Is a Link](https://example.com)␊
### Valid Heading [Has a Link](https://example.com)␊ ### Valid Heading [Has a Link](https://example.com)␊