mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
MD044/proper-names should ignore text of automatic hyperlinks (fixes #329).
This commit is contained in:
parent
6061cce169
commit
2605d56c62
3 changed files with 39 additions and 3 deletions
23
lib/md044.js
23
lib/md044.js
|
@ -17,6 +17,22 @@ module.exports = {
|
||||||
names = Array.isArray(names) ? names : [];
|
names = Array.isArray(names) ? names : [];
|
||||||
const codeBlocks = params.config.code_blocks;
|
const codeBlocks = params.config.code_blocks;
|
||||||
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||||
|
// Text of automatic hyperlinks is implicitly a URL
|
||||||
|
const autolinkText = new Set();
|
||||||
|
filterTokens(params, "inline", (token) => {
|
||||||
|
let inAutoLink = false;
|
||||||
|
token.children.forEach((child) => {
|
||||||
|
const { info, type } = child;
|
||||||
|
if ((type === "link_open") && (info === "auto")) {
|
||||||
|
inAutoLink = true;
|
||||||
|
} else if (type === "link_close") {
|
||||||
|
inAutoLink = false;
|
||||||
|
} else if ((type === "text") && inAutoLink) {
|
||||||
|
autolinkText.add(child);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// For each proper name...
|
||||||
names.forEach((name) => {
|
names.forEach((name) => {
|
||||||
const escapedName = escapeForRegExp(name);
|
const escapedName = escapeForRegExp(name);
|
||||||
const startNamePattern = startNonWordRe.test(name) ? "" : "\\S*\\b";
|
const startNamePattern = startNonWordRe.test(name) ? "" : "\\S*\\b";
|
||||||
|
@ -26,9 +42,9 @@ module.exports = {
|
||||||
const anyNameRe = new RegExp(namePattern, "gi");
|
const anyNameRe = new RegExp(namePattern, "gi");
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function forToken(token) {
|
function forToken(token) {
|
||||||
const fenceOffset = (token.type === "fence") ? 1 : 0;
|
if (!autolinkText.has(token)) {
|
||||||
token.content.split(newLineRe)
|
const fenceOffset = (token.type === "fence") ? 1 : 0;
|
||||||
.forEach((line, index) => {
|
token.content.split(newLineRe).forEach((line, index) => {
|
||||||
let match = null;
|
let match = null;
|
||||||
while ((match = anyNameRe.exec(line)) !== null) {
|
while ((match = anyNameRe.exec(line)) !== null) {
|
||||||
const [ fullMatch, leftMatch, nameMatch, rightMatch ] = match;
|
const [ fullMatch, leftMatch, nameMatch, rightMatch ] = match;
|
||||||
|
@ -65,6 +81,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
forEachInlineChild(params, "text", forToken);
|
forEachInlineChild(params, "text", forToken);
|
||||||
if (includeCodeBlocks) {
|
if (includeCodeBlocks) {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"FILE"
|
"FILE"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"line-length": false,
|
||||||
"no-bare-urls": false,
|
"no-bare-urls": false,
|
||||||
"code-block-style": false
|
"code-block-style": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,3 +31,21 @@ Text https://example.com/directory/file text
|
||||||
|
|
||||||
Text https://example.com/directory/file text
|
Text https://example.com/directory/file text
|
||||||
Text https://example.com/directory/file text
|
Text https://example.com/directory/file text
|
||||||
|
|
||||||
|
Text https://example.com/directory/text.file text
|
||||||
|
Text https://example.com/directory/text.file text
|
||||||
|
|
||||||
|
Text https://example.com/directory/text%20text.file text
|
||||||
|
Text https://example.com/directory/text%20text.file text
|
||||||
|
|
||||||
|
Text <https://example.com/directory/text.file> text
|
||||||
|
Text <https://example.com/directory/text.file> text
|
||||||
|
|
||||||
|
Text <https://example.com/directory/text%20text.file> text
|
||||||
|
Text <https://example.com/directory/text%20text.file> text
|
||||||
|
|
||||||
|
Text [https://example.com/directory/text.file](https://example.com/directory/text.file) text
|
||||||
|
Text [https://example.com/directory/text.file](https://example.com/directory/text.file) text
|
||||||
|
|
||||||
|
Text [https://example.com/directory/text%20text.file](https://example.com/directory/text%20text.file) text
|
||||||
|
Text [https://example.com/directory/text%20text.file](https://example.com/directory/text%20text.file) text
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue