diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 3c12f285..bc8f8ac3 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -303,14 +303,14 @@ module.exports.forEachLine = function forEachLine(lineMetadata, handler) { }); }; // Returns (nested) lists as a flat array (in order) -module.exports.flattenLists = function flattenLists(params) { +module.exports.flattenLists = function flattenLists(tokens) { var flattenedLists = []; var stack = []; var current = null; var nesting = 0; var nestingStack = []; var lastWithMap = { "map": [0, 1] }; - params.tokens.forEach(function (token) { + tokens.forEach(function (token) { if (isMathBlock(token) && token.map[1]) { // markdown-it-texmath plugin does not account for math_block_end token.map[1]++; @@ -760,13 +760,6 @@ module.exports.applyFixes = function applyFixes(input, errors) { "use strict"; // @ts-check -var lineMetadata = null; -module.exports.lineMetadata = function (value) { - if (value) { - lineMetadata = value; - } - return lineMetadata; -}; var flattenedLists = null; module.exports.flattenedLists = function (value) { if (value) { @@ -774,9 +767,24 @@ module.exports.flattenedLists = function (value) { } return flattenedLists; }; +var inlineCodeSpanRanges = null; +module.exports.inlineCodeSpanRanges = function (value) { + if (value) { + inlineCodeSpanRanges = value; + } + return inlineCodeSpanRanges; +}; +var lineMetadata = null; +module.exports.lineMetadata = function (value) { + if (value) { + lineMetadata = value; + } + return lineMetadata; +}; module.exports.clear = function () { - lineMetadata = null; flattenedLists = null; + inlineCodeSpanRanges = null; + lineMetadata = null; }; @@ -1268,7 +1276,8 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul frontMatterLines: frontMatterLines }; cache.lineMetadata(helpers.getLineMetadata(params)); - cache.flattenedLists(helpers.flattenLists(params)); + cache.flattenedLists(helpers.flattenLists(params.tokens)); + cache.inlineCodeSpanRanges(helpers.inlineCodeSpanRanges(params.lines)); // Function to run for each rule var result = (resultVersion === 0) ? {} : []; // eslint-disable-next-line jsdoc/require-jsdoc @@ -2207,15 +2216,15 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, forEachLine = _a.forEachLine, inlineCodeSpanRanges = _a.inlineCodeSpanRanges, overlapsAnyRange = _a.overlapsAnyRange; -var lineMetadata = __webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata; +var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, forEachLine = _a.forEachLine, overlapsAnyRange = _a.overlapsAnyRange; +var _b = __webpack_require__(/*! ./cache */ "../lib/cache.js"), inlineCodeSpanRanges = _b.inlineCodeSpanRanges, lineMetadata = _b.lineMetadata; var reversedLinkRe = /(? { + tokens.forEach((token) => { if (isMathBlock(token) && token.map[1]) { // markdown-it-texmath plugin does not account for math_block_end token.map[1]++; diff --git a/lib/cache.js b/lib/cache.js index bd5ebe8a..a2ad39af 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -2,14 +2,6 @@ "use strict"; -let lineMetadata = null; -module.exports.lineMetadata = (value) => { - if (value) { - lineMetadata = value; - } - return lineMetadata; -}; - let flattenedLists = null; module.exports.flattenedLists = (value) => { if (value) { @@ -18,7 +10,24 @@ module.exports.flattenedLists = (value) => { return flattenedLists; }; -module.exports.clear = () => { - lineMetadata = null; - flattenedLists = null; +let inlineCodeSpanRanges = null; +module.exports.inlineCodeSpanRanges = (value) => { + if (value) { + inlineCodeSpanRanges = value; + } + return inlineCodeSpanRanges; +}; + +let lineMetadata = null; +module.exports.lineMetadata = (value) => { + if (value) { + lineMetadata = value; + } + return lineMetadata; +}; + +module.exports.clear = () => { + flattenedLists = null; + inlineCodeSpanRanges = null; + lineMetadata = null; }; diff --git a/lib/markdownlint.js b/lib/markdownlint.js index ebc86282..a94e4c51 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -516,7 +516,8 @@ function lintContent( frontMatterLines }; cache.lineMetadata(helpers.getLineMetadata(params)); - cache.flattenedLists(helpers.flattenLists(params)); + cache.flattenedLists(helpers.flattenLists(params.tokens)); + cache.inlineCodeSpanRanges(helpers.inlineCodeSpanRanges(params.lines)); // Function to run for each rule const result = (resultVersion === 0) ? {} : []; // eslint-disable-next-line jsdoc/require-jsdoc diff --git a/lib/md011.js b/lib/md011.js index ff794e74..94bd87ca 100644 --- a/lib/md011.js +++ b/lib/md011.js @@ -2,9 +2,8 @@ "use strict"; -const { addError, forEachLine, inlineCodeSpanRanges, overlapsAnyRange } = - require("../helpers"); -const { lineMetadata } = require("./cache"); +const { addError, forEachLine, overlapsAnyRange } = require("../helpers"); +const { inlineCodeSpanRanges, lineMetadata } = require("./cache"); const reversedLinkRe = /(? { if (!inCode && !onFence) { let match = null; diff --git a/lib/md044.js b/lib/md044.js index 365b4aeb..2d8da0e4 100644 --- a/lib/md044.js +++ b/lib/md044.js @@ -3,9 +3,8 @@ "use strict"; const { addErrorDetailIf, bareUrlRe, escapeForRegExp, forEachLine, - inlineCodeSpanRanges, overlapsAnyRange, linkRe, linkReferenceRe } = - require("../helpers"); -const { lineMetadata } = require("./cache"); + overlapsAnyRange, linkRe, linkReferenceRe } = require("../helpers"); +const { inlineCodeSpanRanges, lineMetadata } = require("./cache"); module.exports = { "names": [ "MD044", "proper-names" ], @@ -37,7 +36,7 @@ module.exports = { } }); if (!includeCodeBlocks) { - exclusions.push(...inlineCodeSpanRanges(params.lines)); + exclusions.push(...inlineCodeSpanRanges()); } for (const name of names) { const escapedName = escapeForRegExp(name);