Reimplement inlineCodeSpanRanges as codeBlockAndSpanRanges to fix an issue with unterminated code spans (and for flexibility).

This commit is contained in:
David Anson 2021-11-23 04:40:05 +00:00 committed by GitHub
parent 9c60343692
commit 1e82f76596
12 changed files with 178 additions and 71 deletions

View file

@ -2,6 +2,14 @@
"use strict";
let codeBlockAndSpanRanges = null;
module.exports.codeBlockAndSpanRanges = (value) => {
if (value) {
codeBlockAndSpanRanges = value;
}
return codeBlockAndSpanRanges;
};
let flattenedLists = null;
module.exports.flattenedLists = (value) => {
if (value) {
@ -10,14 +18,6 @@ module.exports.flattenedLists = (value) => {
return flattenedLists;
};
let inlineCodeSpanRanges = null;
module.exports.inlineCodeSpanRanges = (value) => {
if (value) {
inlineCodeSpanRanges = value;
}
return inlineCodeSpanRanges;
};
let lineMetadata = null;
module.exports.lineMetadata = (value) => {
if (value) {
@ -27,7 +27,7 @@ module.exports.lineMetadata = (value) => {
};
module.exports.clear = () => {
codeBlockAndSpanRanges = null;
flattenedLists = null;
inlineCodeSpanRanges = null;
lineMetadata = null;
};

View file

@ -515,7 +515,9 @@ function lintContent(
};
cache.lineMetadata(helpers.getLineMetadata(params));
cache.flattenedLists(helpers.flattenLists(params.tokens));
cache.inlineCodeSpanRanges(helpers.inlineCodeSpanRanges(params.lines));
cache.codeBlockAndSpanRanges(
helpers.codeBlockAndSpanRanges(params, cache.lineMetadata())
);
// Function to run for each rule
const result = (resultVersion === 0) ? {} : [];
// eslint-disable-next-line jsdoc/require-jsdoc

View file

@ -3,7 +3,7 @@
"use strict";
const { addError, forEachLine, overlapsAnyRange } = require("../helpers");
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
const { codeBlockAndSpanRanges, lineMetadata } = require("./cache");
const reversedLinkRe =
/(^|[^\\])\(([^)]+)\)\[([^\]^][^\]]*)](?!\()/g;
@ -13,7 +13,7 @@ module.exports = {
"description": "Reversed link syntax",
"tags": [ "links" ],
"function": function MD011(params, onError) {
const exclusions = inlineCodeSpanRanges();
const exclusions = codeBlockAndSpanRanges();
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => {
if (!inCode && !onFence) {
let match = null;

View file

@ -5,7 +5,7 @@
const {
addError, forEachLine, overlapsAnyRange, unescapeMarkdown
} = require("../helpers");
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
const { codeBlockAndSpanRanges, lineMetadata } = require("./cache");
const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g;
const linkDestinationRe = /]\(\s*$/;
@ -22,7 +22,7 @@ module.exports = {
let allowedElements = params.config.allowed_elements;
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
allowedElements = allowedElements.map((element) => element.toLowerCase());
const exclusions = inlineCodeSpanRanges();
const exclusions = codeBlockAndSpanRanges();
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
let match = null;
// eslint-disable-next-line no-unmodified-loop-condition

View file

@ -4,7 +4,7 @@
const { addErrorDetailIf, bareUrlRe, escapeForRegExp, forEachLine,
overlapsAnyRange, linkRe, linkReferenceRe } = require("../helpers");
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
const { codeBlockAndSpanRanges, lineMetadata } = require("./cache");
module.exports = {
"names": [ "MD044", "proper-names" ],
@ -36,7 +36,7 @@ module.exports = {
}
});
if (!includeCodeBlocks) {
exclusions.push(...inlineCodeSpanRanges());
exclusions.push(...codeBlockAndSpanRanges());
}
for (const name of names) {
const escapedName = escapeForRegExp(name);