Refactor to freeze parser tokens only when custom rules are present (negligable performance improvement).

This commit is contained in:
David Anson 2024-10-11 22:18:51 -07:00
parent a63972a666
commit 5e1b269fa5
4 changed files with 110 additions and 92 deletions

View file

@ -495,8 +495,12 @@ function lintContent(
const needMarkdownItTokens = enabledRuleList.some(
(rule) => (rule.parser === "markdownit") || (rule.parser === undefined)
);
const customRulesPresent = (ruleList.length !== rules.length);
// Parse content into parser tokens
const micromarkTokens = micromark.parse(content);
const micromarkTokens = micromark.parse(
content,
{ "freezeTokens": customRulesPresent, "shimReferences": true }
);
// Hide the content of HTML comments from rules
const preClearedContent = content;
content = helpers.clearHtmlCommentText(content);

View file

@ -73,7 +73,7 @@ module.exports = {
if (autoLinks.length > 0) {
// Re-parse with correct link/image reference definition handling
const document = params.lines.join("\n");
const tokens = parse(document, undefined, false);
const tokens = parse(document);
for (const token of literalAutolinks(tokens)) {
const range = [
token.startColumn,