mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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
|
@ -26,17 +26,28 @@ test("getMicromarkEvents/filterByPredicate", async(t) => {
|
|||
t.plan(1);
|
||||
const content = await testContent;
|
||||
const events = getMicromarkEvents(content);
|
||||
let inHtmlFlow = false;
|
||||
const eventTypes = events
|
||||
.filter((event) => event[0] === "enter")
|
||||
.filter((event) => {
|
||||
const result = !inHtmlFlow && (event[0] === "enter");
|
||||
if (event[1].type === "htmlFlow") {
|
||||
inHtmlFlow = !inHtmlFlow;
|
||||
}
|
||||
return result;
|
||||
})
|
||||
.map((event) => event[1].type);
|
||||
const tokens = parse(content);
|
||||
const filtered = filterByPredicate(tokens, () => true);
|
||||
const filtered = filterByPredicate(
|
||||
tokens,
|
||||
() => true,
|
||||
(token) => ((token.type === "htmlFlow") ? [] : token.children)
|
||||
);
|
||||
const tokenTypes = filtered.map((token) => token.type);
|
||||
t.deepEqual(tokenTypes, eventTypes);
|
||||
});
|
||||
|
||||
test("filterByTypes", async(t) => {
|
||||
t.plan(6);
|
||||
t.plan(8);
|
||||
const filtered = filterByTypes(
|
||||
await testTokens,
|
||||
[ "atxHeadingText", "codeText", "htmlText", "setextHeadingText" ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue