mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
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:
parent
b7ef571401
commit
1ddee6b195
5 changed files with 62 additions and 37 deletions
|
|
@ -6328,7 +6328,10 @@ module.exports = {
|
|||
try {
|
||||
var _loop = function _loop() {
|
||||
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
|
||||
var context = undefined;
|
||||
// eslint-disable-next-line no-undef-init
|
||||
|
|
@ -6339,18 +6342,18 @@ module.exports = {
|
|||
context = link.text;
|
||||
range = [link.startColumn, link.endColumn - link.startColumn];
|
||||
fixInfo = {
|
||||
"editColumn": definition.startColumn,
|
||||
"deleteCount": definition.endColumn - definition.startColumn
|
||||
"editColumn": startColumn,
|
||||
"deleteCount": endColumn - startColumn
|
||||
};
|
||||
}
|
||||
var definitionTextLower = definition.text.toLowerCase();
|
||||
var textLower = text.toLowerCase();
|
||||
var mixedCaseKey = _toConsumableArray(fragments.keys()).find(function (key) {
|
||||
return definitionTextLower === key.toLowerCase();
|
||||
return textLower === key.toLowerCase();
|
||||
});
|
||||
if (mixedCaseKey) {
|
||||
// @ts-ignore
|
||||
(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 {
|
||||
addError(onError, link.startLine, undefined, context, range);
|
||||
}
|
||||
|
|
|
|||
18
lib/md051.js
18
lib/md051.js
|
|
@ -99,10 +99,12 @@ module.exports = {
|
|||
for (const link of links) {
|
||||
const definitions = filterByTypes(link.children, [ definitionType ]);
|
||||
for (const definition of definitions) {
|
||||
const { endColumn, startColumn, text } = definition;
|
||||
if (
|
||||
(definition.text.length > 1) &&
|
||||
definition.text.startsWith("#") &&
|
||||
!fragments.has(definition.text)
|
||||
(text.length > 1) &&
|
||||
text.startsWith("#") &&
|
||||
!fragments.has(text) &&
|
||||
!fragments.has(`#${encodeURIComponent(text.slice(1))}`)
|
||||
) {
|
||||
// eslint-disable-next-line no-undef-init
|
||||
let context = undefined;
|
||||
|
|
@ -114,13 +116,13 @@ module.exports = {
|
|||
context = link.text;
|
||||
range = [ link.startColumn, link.endColumn - link.startColumn ];
|
||||
fixInfo = {
|
||||
"editColumn": definition.startColumn,
|
||||
"deleteCount": definition.endColumn - definition.startColumn
|
||||
"editColumn": startColumn,
|
||||
"deleteCount": endColumn - startColumn
|
||||
};
|
||||
}
|
||||
const definitionTextLower = definition.text.toLowerCase();
|
||||
const textLower = text.toLowerCase();
|
||||
const mixedCaseKey = [ ...fragments.keys() ]
|
||||
.find((key) => definitionTextLower === key.toLowerCase());
|
||||
.find((key) => textLower === key.toLowerCase());
|
||||
if (mixedCaseKey) {
|
||||
// @ts-ignore
|
||||
(fixInfo || {}).insertText = mixedCaseKey;
|
||||
|
|
@ -128,7 +130,7 @@ module.exports = {
|
|||
onError,
|
||||
link.startLine,
|
||||
mixedCaseKey,
|
||||
definition.text,
|
||||
text,
|
||||
undefined,
|
||||
context,
|
||||
range,
|
||||
|
|
|
|||
|
|
@ -44,8 +44,16 @@
|
|||
|
||||
[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ê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-has-a-link)
|
||||
|
|
@ -137,6 +145,8 @@ Text
|
|||
|
||||
### En-tête Valide Dans Français Pour Vérification
|
||||
|
||||
### 标题
|
||||
|
||||
### [Valid Heading Is a Link](https://example.com)
|
||||
|
||||
### Valid Heading [Has a Link](https://example.com)
|
||||
|
|
|
|||
|
|
@ -23969,7 +23969,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
37,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 172,
|
||||
lineNumber: 182,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -23985,7 +23985,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
31,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 174,
|
||||
lineNumber: 184,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24001,7 +24001,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
36,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 176,
|
||||
lineNumber: 186,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24017,7 +24017,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
28,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 178,
|
||||
lineNumber: 188,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24033,7 +24033,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
18,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 180,
|
||||
lineNumber: 190,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24053,7 +24053,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
editColumn: 11,
|
||||
insertText: '#HREFandID',
|
||||
},
|
||||
lineNumber: 182,
|
||||
lineNumber: 192,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24069,7 +24069,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
34,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 184,
|
||||
lineNumber: 194,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24085,7 +24085,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
34,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 186,
|
||||
lineNumber: 196,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24101,7 +24101,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
39,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 188,
|
||||
lineNumber: 198,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24114,7 +24114,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: null,
|
||||
lineNumber: 190,
|
||||
lineNumber: 200,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24130,7 +24130,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
28,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 195,
|
||||
lineNumber: 205,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24150,7 +24150,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
editColumn: 9,
|
||||
insertText: '#valid-fragments',
|
||||
},
|
||||
lineNumber: 199,
|
||||
lineNumber: 209,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24170,7 +24170,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
editColumn: 12,
|
||||
insertText: '#namedlink',
|
||||
},
|
||||
lineNumber: 201,
|
||||
lineNumber: 211,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24183,7 +24183,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
errorDetail: 'Expected: #namedlink; Actual: #NAMEDLINK',
|
||||
errorRange: null,
|
||||
fixInfo: null,
|
||||
lineNumber: 203,
|
||||
lineNumber: 213,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24203,7 +24203,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
editColumn: 13,
|
||||
insertText: '#idlink',
|
||||
},
|
||||
lineNumber: 208,
|
||||
lineNumber: 218,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24219,7 +24219,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
26,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 243,
|
||||
lineNumber: 253,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24235,7 +24235,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
26,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 245,
|
||||
lineNumber: 255,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24251,7 +24251,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
20,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 247,
|
||||
lineNumber: 257,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24267,7 +24267,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
23,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 249,
|
||||
lineNumber: 259,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24283,7 +24283,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
22,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 251,
|
||||
lineNumber: 261,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24299,7 +24299,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
42,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 253,
|
||||
lineNumber: 263,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24315,7 +24315,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
21,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 255,
|
||||
lineNumber: 265,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24331,7 +24331,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
21,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 257,
|
||||
lineNumber: 267,
|
||||
ruleDescription: 'Link fragments should be valid',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md051.md',
|
||||
ruleNames: [
|
||||
|
|
@ -24386,8 +24386,16 @@ Generated by [AVA](https://avajs.dev).
|
|||
␊
|
||||
[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ê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-has-a-link)␊
|
||||
|
|
@ -24479,6 +24487,8 @@ Generated by [AVA](https://avajs.dev).
|
|||
␊
|
||||
### En-tête Valide Dans Français Pour Vérification␊
|
||||
␊
|
||||
### 标题␊
|
||||
␊
|
||||
### [Valid Heading Is a Link](https://example.com)␊
|
||||
␊
|
||||
### Valid Heading [Has a Link](https://example.com)␊
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue