diff --git a/lib/md011.mjs b/lib/md011.mjs index 32df13d6..f9cce643 100644 --- a/lib/md011.mjs +++ b/lib/md011.mjs @@ -4,6 +4,8 @@ import { addError, hasOverlap } from "../helpers/helpers.cjs"; import { addRangeToSet } from "../helpers/micromark-helpers.cjs"; import { filterByTypesCached } from "./cache.mjs"; +/** @typedef {import("micromark-extension-math")} */ + const reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g; /** @type {import("markdownlint").Rule} */ @@ -13,14 +15,14 @@ export default { "tags": [ "links" ], "parser": "micromark", "function": function MD011(params, onError) { - const codeBlockLineNumbers = new Set(); - for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) { - addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine); + const ignoreBlockLineNumbers = new Set(); + for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "mathFlow" ])) { + addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine); } - const codeTexts = filterByTypesCached([ "codeText" ]); + const ignoreTexts = filterByTypesCached([ "codeText", "mathText" ]); for (const [ lineIndex, line ] of params.lines.entries()) { const lineNumber = lineIndex + 1; - if (!codeBlockLineNumbers.has(lineNumber)) { + if (!ignoreBlockLineNumbers.has(lineNumber)) { let match = null; while ((match = reversedLinkRe.exec(line)) !== null) { const [ reversedLink, preChar, linkText, linkDestination ] = match; @@ -32,7 +34,7 @@ export default { const length = match[0].length - preChar.length; /** @type {import("../helpers/helpers.cjs").FileRange} */ const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 }; - if (!codeTexts.some((codeText) => hasOverlap(codeText, range))) { + if (!ignoreTexts.some((ignoreText) => hasOverlap(ignoreText, range))) { addError( onError, lineNumber, diff --git a/test/markdownlint-test.mjs b/test/markdownlint-test.mjs index a10497a9..f53bf9a0 100644 --- a/test/markdownlint-test.mjs +++ b/test/markdownlint-test.mjs @@ -1101,7 +1101,7 @@ test("readme", async(t) => { }); test("validateJsonUsingConfigSchemaStrict", async(t) => { - t.plan(218); + t.plan(219); // @ts-ignore const ajv = new Ajv(ajvOptions); const validateSchemaStrict = ajv.compile(configSchemaStrict); diff --git a/test/snapshots/markdownlint-test-scenarios.mjs.md b/test/snapshots/markdownlint-test-scenarios.mjs.md index dc7c2f22..da599a58 100644 --- a/test/snapshots/markdownlint-test-scenarios.mjs.md +++ b/test/snapshots/markdownlint-test-scenarios.mjs.md @@ -75717,6 +75717,36 @@ Generated by [AVA](https://avajs.dev). $$␊ x * y = x * y␊ $$␊ + ␊ + ## Content␊ + ␊ + $$␊ + ␊ + Text (reversed)[link] text␊ + ␊ + Text [invalid](#link) text␊ + ␊ + Text [link](not-descriptive-link-text) text␊ + ␊ + Text javascript text␊ + ␊ + $$␊ + ␊ + Text $ (reversed)[link] $ text␊ + ␊ + Text $ [invalid](#link) $ text␊ + ␊ + Text $ [link](not-descriptive-link-text) $ text␊ + ␊ + Text $ javascript $ text␊ + ␊ + ␊ `, } diff --git a/test/snapshots/markdownlint-test-scenarios.mjs.snap b/test/snapshots/markdownlint-test-scenarios.mjs.snap index 1a3c8359..38d5fd73 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.mjs.snap and b/test/snapshots/markdownlint-test-scenarios.mjs.snap differ diff --git a/test/texmath-content.md b/test/texmath-content.md index 715a35c1..e27a360c 100644 --- a/test/texmath-content.md +++ b/test/texmath-content.md @@ -17,3 +17,33 @@ text $$ x * y = x * y $$ + +## Content + +$$ + +Text (reversed)[link] text + +Text [invalid](#link) text + +Text [link](not-descriptive-link-text) text + +Text javascript text + +$$ + +Text $ (reversed)[link] $ text + +Text $ [invalid](#link) $ text + +Text $ [link](not-descriptive-link-text) $ text + +Text $ javascript $ text + +