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

@ -3,15 +3,18 @@
"use strict";
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
const { filterByTypes, tokenIfType } = require("../helpers/micromark.cjs");
const { filterByPredicate, tokenIfType } = require("../helpers/micromark.cjs");
const intrawordRe = /\w/;
const impl =
(params, onError, type, asterisk, underline, style = "consistent") => {
const { lines, parsers } = params;
const emphasisTokens =
filterByTypes(parsers.micromark.tokens, [ type ]);
const emphasisTokens = filterByPredicate(
parsers.micromark.tokens,
(token) => token.type === type,
(token) => ((token.type === "htmlFlow") ? [] : token.children)
);
for (const token of emphasisTokens) {
const { children } = token;
const childType = `${type}Sequence`;