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
|
@ -3756,7 +3756,7 @@ module.exports = {
|
|||
"use strict";
|
||||
// @ts-check
|
||||
|
||||
const { addErrorContext, urlRe, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const { addErrorContext, filterTokens, urlRe, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const { codeBlockAndSpanRanges, htmlElementRanges, referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||
const htmlLinkRe = /<a(?:|\s[^>]+)>[^<>]*<\/a\s*>/ig;
|
||||
module.exports = {
|
||||
|
@ -3769,6 +3769,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) {
|
||||
|
@ -3787,15 +3792,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
|
||||
// Allow <...> to avoid reporting non-bare links
|
||||
!(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) &&
|
||||
!withinAnyRange(codeExclusions, lineIndex, matchIndex, bareUrlLength)) {
|
||||
const range = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue