MD044/proper-names should ignore text of automatic hyperlinks (fixes #329).

This commit is contained in:
David Anson 2020-09-18 20:30:46 -07:00
parent 6061cce169
commit 2605d56c62
3 changed files with 39 additions and 3 deletions

View file

@ -17,6 +17,22 @@ module.exports = {
names = Array.isArray(names) ? names : [];
const codeBlocks = params.config.code_blocks;
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) => {
const escapedName = escapeForRegExp(name);
const startNamePattern = startNonWordRe.test(name) ? "" : "\\S*\\b";
@ -26,9 +42,9 @@ module.exports = {
const anyNameRe = new RegExp(namePattern, "gi");
// eslint-disable-next-line jsdoc/require-jsdoc
function forToken(token) {
if (!autolinkText.has(token)) {
const fenceOffset = (token.type === "fence") ? 1 : 0;
token.content.split(newLineRe)
.forEach((line, index) => {
token.content.split(newLineRe).forEach((line, index) => {
let match = null;
while ((match = anyNameRe.exec(line)) !== null) {
const [ fullMatch, leftMatch, nameMatch, rightMatch ] = match;
@ -66,6 +82,7 @@ module.exports = {
}
});
}
}
forEachInlineChild(params, "text", forToken);
if (includeCodeBlocks) {
forEachInlineChild(params, "code_inline", forToken);

View file

@ -9,6 +9,7 @@
"FILE"
]
},
"line-length": false,
"no-bare-urls": false,
"code-block-style": false
}

View file

@ -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/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