mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Refactor use of micromark so token stream is authentic by shimming undefined link reference handling, remove no-longer-necessary parse operation in MD034.
This commit is contained in:
parent
1d9bd4725d
commit
38b4ec0c2f
6 changed files with 369 additions and 122 deletions
|
|
@ -499,7 +499,7 @@ function lintContent(
|
|||
// Parse content into parser tokens
|
||||
const micromarkTokens = micromark.parse(
|
||||
content,
|
||||
{ "freezeTokens": customRulesPresent, "shimReferences": true }
|
||||
{ "freezeTokens": customRulesPresent }
|
||||
);
|
||||
// Hide the content of HTML comments from rules
|
||||
const preClearedContent = content;
|
||||
|
|
|
|||
47
lib/md034.js
47
lib/md034.js
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
const { addErrorContext } = require("../helpers");
|
||||
const { filterByPredicate, getHtmlTagInfo, inHtmlFlow } = require("../helpers/micromark-helpers.cjs");
|
||||
const { parse } = require("../helpers/micromark-parse.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
|
|
@ -39,6 +37,7 @@ module.exports = {
|
|||
return false;
|
||||
},
|
||||
(token) => {
|
||||
// Ignore content of inline HTML tags
|
||||
const { children } = token;
|
||||
const result = [];
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
|
|
@ -69,31 +68,25 @@ module.exports = {
|
|||
}
|
||||
)
|
||||
);
|
||||
const autoLinks = filterByTypesCached([ "literalAutolink" ]);
|
||||
if (autoLinks.length > 0) {
|
||||
// Re-parse with correct link/image reference definition handling
|
||||
const document = params.lines.join("\n");
|
||||
const tokens = parse(document);
|
||||
for (const token of literalAutolinks(tokens)) {
|
||||
const range = [
|
||||
token.startColumn,
|
||||
token.endColumn - token.startColumn
|
||||
];
|
||||
const fixInfo = {
|
||||
"editColumn": range[0],
|
||||
"deleteCount": range[1],
|
||||
"insertText": `<${token.text}>`
|
||||
};
|
||||
addErrorContext(
|
||||
onError,
|
||||
token.startLine,
|
||||
token.text,
|
||||
undefined,
|
||||
undefined,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
}
|
||||
for (const token of literalAutolinks(params.parsers.micromark.tokens)) {
|
||||
const range = [
|
||||
token.startColumn,
|
||||
token.endColumn - token.startColumn
|
||||
];
|
||||
const fixInfo = {
|
||||
"editColumn": range[0],
|
||||
"deleteCount": range[1],
|
||||
"insertText": `<${token.text}>`
|
||||
};
|
||||
addErrorContext(
|
||||
onError,
|
||||
token.startLine,
|
||||
token.text,
|
||||
undefined,
|
||||
undefined,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue