mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +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
16
lib/md037.js
16
lib/md037.js
|
|
@ -3,6 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { filterByPredicate } = require("../helpers/micromark.cjs");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD037", "no-space-in-emphasis" ],
|
||||
|
|
@ -16,16 +17,11 @@ module.exports = {
|
|||
for (const marker of [ "_", "__", "___", "*", "**", "***" ]) {
|
||||
emphasisTokensByMarker.set(marker, []);
|
||||
}
|
||||
const pending = [ ...parsers.micromark.tokens ];
|
||||
let token = null;
|
||||
while ((token = pending.shift())) {
|
||||
|
||||
// Use reparsed children of htmlFlow tokens
|
||||
if (token.type === "htmlFlow") {
|
||||
pending.unshift(...token.htmlFlowChildren);
|
||||
continue;
|
||||
}
|
||||
pending.push(...token.children);
|
||||
const tokens = filterByPredicate(
|
||||
parsers.micromark.tokens,
|
||||
(token) => token.children.some((child) => child.type === "data")
|
||||
);
|
||||
for (const token of tokens) {
|
||||
|
||||
// Build lists of bare tokens for each emphasis marker type
|
||||
for (const emphasisTokens of emphasisTokensByMarker.values()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue