mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD034/no-bare-urls to handle more scenarios, simplify slightly, replace blanket MD034 suppression for https://github.com/mdn/content with specific (valid) issues (refs #607).
This commit is contained in:
parent
2e2937081e
commit
d352d4ece1
6 changed files with 103 additions and 18 deletions
22
lib/md034.js
22
lib/md034.js
|
@ -2,7 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, urlRe, withinAnyRange } = require("../helpers");
|
||||
const { addErrorContext, filterTokens, urlRe, withinAnyRange } =
|
||||
require("../helpers");
|
||||
const { codeBlockAndSpanRanges, htmlElementRanges, referenceLinkImageData } =
|
||||
require("./cache");
|
||||
|
||||
|
@ -18,6 +19,11 @@ module.exports = {
|
|||
...codeBlockAndSpanRanges(),
|
||||
...htmlElementRanges()
|
||||
];
|
||||
filterTokens(params, "html_block", (token) => {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
codeExclusions.push([ i, 0, lines[i].length ]);
|
||||
}
|
||||
});
|
||||
const { definitionLineIndices } = referenceLinkImageData();
|
||||
for (const [ lineIndex, line ] of lines.entries()) {
|
||||
if (definitionLineIndices[0] === lineIndex) {
|
||||
|
@ -35,15 +41,17 @@ module.exports = {
|
|||
const prefix = line.slice(0, matchIndex);
|
||||
const postfix = line.slice(matchIndex + bareUrlLength);
|
||||
if (
|
||||
// Allow ](... to avoid reporting Markdown-style links
|
||||
!(/\]\(\s*$/.test(prefix)) &&
|
||||
// Allow <...> to avoid reporting non-bare links
|
||||
!(prefix.endsWith("<") && /^[#)]?>/.test(postfix)) &&
|
||||
// Allow [...] to avoid MD011/no-reversed-links and nested links
|
||||
!(/\[[^\]]*$/.test(prefix) && /^[^[]*\]/.test(postfix)) &&
|
||||
// Allow "..." and '...' for deliberately including a bare link
|
||||
!(prefix.endsWith("<") && postfix.startsWith(">")) &&
|
||||
// Allow >...</ to avoid reporting <code>...</code>
|
||||
!(prefix.endsWith(">") && postfix.startsWith("</")) &&
|
||||
// Allow "..." and '...' to allow quoting a bare link
|
||||
!(prefix.endsWith("\"") && postfix.startsWith("\"")) &&
|
||||
!(prefix.endsWith("'") && postfix.startsWith("'")) &&
|
||||
// Allow ](... to avoid reporting Markdown-style links
|
||||
!(/\]\(\s*$/.test(prefix)) &&
|
||||
// Allow [...] to avoid MD011/no-reversed-links and nested links
|
||||
!(/\[[^\]]*$/.test(prefix) && /^[^[]*\]/.test(postfix)) &&
|
||||
!withinAnyRange(
|
||||
lineExclusions, lineIndex, matchIndex, bareUrlLength
|
||||
) &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue