mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Refactor micromark token handling to remove optional Token.htmlFlowChildren property and make related code more efficient for a ~6% elapsed time reduction.
This commit is contained in:
parent
e282874fe3
commit
24c97a54fb
16 changed files with 274 additions and 283 deletions
21
lib/md044.js
21
lib/md044.js
|
|
@ -29,27 +29,22 @@ module.exports = {
|
|||
const htmlElements = params.config.html_elements;
|
||||
const includeHtmlElements =
|
||||
(htmlElements === undefined) ? true : !!htmlElements;
|
||||
const scannedTypes = new Set([ "data", "htmlFlowData" ]);
|
||||
const scannedTypes = new Set([ "data" ]);
|
||||
if (includeCodeBlocks) {
|
||||
scannedTypes.add("codeFlowValue");
|
||||
scannedTypes.add("codeTextData");
|
||||
}
|
||||
if (includeHtmlElements) {
|
||||
scannedTypes.add("htmlFlowData");
|
||||
scannedTypes.add("htmlTextData");
|
||||
}
|
||||
const contentTokens =
|
||||
filterByPredicate(
|
||||
params.parsers.micromark.tokens,
|
||||
(token) => scannedTypes.has(token.type),
|
||||
(token) => {
|
||||
let { children } = token;
|
||||
const { htmlFlowChildren, text, type } = token;
|
||||
if (!includeHtmlElements && (type === "htmlFlow")) {
|
||||
children = text.startsWith("<!--") ?
|
||||
// Remove comment content
|
||||
[] :
|
||||
// Examine htmlText content
|
||||
htmlFlowChildren;
|
||||
}
|
||||
return children.filter((t) => !ignoredChildTypes.has(t.type));
|
||||
}
|
||||
(token) => (
|
||||
token.children.filter((t) => !ignoredChildTypes.has(t.type))
|
||||
)
|
||||
);
|
||||
const exclusions = [];
|
||||
const autoLinked = new Set();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue