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:
David Anson 2023-09-02 12:07:14 -07:00
parent e282874fe3
commit 24c97a54fb
16 changed files with 274 additions and 283 deletions

View file

@ -19,3 +19,11 @@ also` __bad__ {MD050}
This `is
also
very` __bad__ {MD050}
<p>HTML __should__ *be* ignored</p>
<p>
HTML __should__ *be* ignored
</p>
<!-- markdownlint-configure-file { "no-inline-html": false } -->

View file

@ -74,7 +74,22 @@ code
text
<p>
1. Not a
2. list
</p>
<p>1. Not a list</p>
<p>
* Not a
* list
</p>
<p>* Not a list</p>
<!-- markdownlint-configure-file {
"no-inline-html": false,
"ul-style": false,
"ol-prefix": false,
"fenced-code-language": false

View file

@ -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" ]

View file

@ -912,7 +912,7 @@ test("readme", async(t) => {
});
test("validateJsonUsingConfigSchemaStrict", (t) => {
t.plan(159);
t.plan(160);
const configRe =
/^[\s\S]*<!-- markdownlint-configure-file ([\s\S]*) -->[\s\S]*$/;
const ignoreFiles = new Set([

View file

@ -2574,57 +2574,6 @@ Generated by [AVA](https://avajs.dev).
},
{
children: [
{
children: [],
endColumn: 4,
endLine: 43,
startColumn: 1,
startLine: 43,
text: '<p>',
type: 'htmlFlowData',
},
{
children: [],
endColumn: 1,
endLine: 44,
startColumn: 4,
startLine: 43,
text: `␊
`,
type: 'lineEnding',
},
{
children: [],
endColumn: 11,
endLine: 44,
startColumn: 1,
startLine: 44,
text: 'HTML block',
type: 'htmlFlowData',
},
{
children: [],
endColumn: 1,
endLine: 45,
startColumn: 11,
startLine: 44,
text: `␊
`,
type: 'lineEnding',
},
{
children: [],
endColumn: 5,
endLine: 45,
startColumn: 1,
startLine: 45,
text: '</p>',
type: 'htmlFlowData',
},
],
endColumn: 5,
endLine: 45,
htmlFlowChildren: [
{
children: [
{
@ -2717,6 +2666,8 @@ Generated by [AVA](https://avajs.dev).
type: 'content',
},
],
endColumn: 5,
endLine: 45,
startColumn: 1,
startLine: 43,
text: `<p>
@ -3224,47 +3175,6 @@ Generated by [AVA](https://avajs.dev).
],
endColumn: 35,
endLine: 51,
htmlFlowChildren: [
{
children: [
{
children: [
{
children: [
{
children: [],
endColumn: 35,
endLine: 51,
startColumn: 1,
startLine: 51,
text: '<!-- markdownlint-disable-file -->',
type: 'htmlTextData',
},
],
endColumn: 35,
endLine: 51,
startColumn: 1,
startLine: 51,
text: '<!-- markdownlint-disable-file -->',
type: 'htmlText',
},
],
endColumn: 35,
endLine: 51,
startColumn: 1,
startLine: 51,
text: '<!-- markdownlint-disable-file -->',
type: 'paragraph',
},
],
endColumn: 35,
endLine: 51,
startColumn: 1,
startLine: 51,
text: '<!-- markdownlint-disable-file -->',
type: 'content',
},
],
startColumn: 1,
startLine: 51,
text: '<!-- markdownlint-disable-file -->',

View file

@ -10917,6 +10917,14 @@ Generated by [AVA](https://avajs.dev).
This \`is␊
also␊
very\` **bad** {MD050}␊
<p>HTML __should__ *be* ignored</p>
<p>
HTML __should__ *be* ignored␊
</p>
<!-- markdownlint-configure-file { "no-inline-html": false } -->
`,
}
@ -30582,7 +30590,7 @@ Generated by [AVA](https://avajs.dev).
insertText: `␊
`,
},
lineNumber: 83,
lineNumber: 98,
ruleDescription: 'Files should end with a single newline character',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md047.md',
ruleNames: [
@ -30679,7 +30687,22 @@ Generated by [AVA](https://avajs.dev).
text␊
<p>
1. Not a␊
2. list␊
</p>
<p>1. Not a list</p>
<p>
* Not a␊
* list␊
</p>
<p>* Not a list</p>
<!-- markdownlint-configure-file {␊
"no-inline-html": false,␊
"ul-style": false,␊
"ol-prefix": false,␊
"fenced-code-language": false␊