mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD034/no-bare-urls to ignore "[link]" scenario that conflicts with MD011/no-reversed-links (fixes #268).
This commit is contained in:
parent
29f16bf402
commit
dd66a33d75
8 changed files with 60 additions and 27 deletions
47
lib/md034.js
47
lib/md034.js
|
@ -21,25 +21,34 @@ module.exports = {
|
|||
} else if ((type === "text") && !inLink) {
|
||||
while ((match = bareUrlRe.exec(content)) !== null) {
|
||||
const [ bareUrl ] = match;
|
||||
const index = line.indexOf(content);
|
||||
const range = (index === -1) ? null : [
|
||||
line.indexOf(content) + match.index + 1,
|
||||
bareUrl.length
|
||||
];
|
||||
const fixInfo = range ? {
|
||||
"editColumn": range[0],
|
||||
"deleteCount": range[1],
|
||||
"insertText": `<${bareUrl}>`
|
||||
} : null;
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
bareUrl,
|
||||
null,
|
||||
null,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
const matchIndex = match.index;
|
||||
const bareUrlLength = bareUrl.length;
|
||||
// Allow "[https://example.com]" to avoid conflicts with
|
||||
// MD011/no-reversed-links
|
||||
if (
|
||||
(content[matchIndex - 1] !== "[") ||
|
||||
(content[matchIndex + bareUrlLength] !== "]")
|
||||
) {
|
||||
const index = line.indexOf(content);
|
||||
const range = (index === -1) ? null : [
|
||||
index + matchIndex + 1,
|
||||
bareUrlLength
|
||||
];
|
||||
const fixInfo = range ? {
|
||||
"editColumn": range[0],
|
||||
"deleteCount": range[1],
|
||||
"insertText": `<${bareUrl}>`
|
||||
} : null;
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
bareUrl,
|
||||
null,
|
||||
null,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue