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
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue