Refactor micromark helper getTokenTextByType to be more efficient, remove tokenIfType helper for being redundant.

This commit is contained in:
David Anson 2024-09-16 20:50:54 -07:00
parent b749d9fbb4
commit 2ea3f95fd1
6 changed files with 82 additions and 120 deletions

View file

@ -3,7 +3,7 @@
"use strict";
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
const { filterByPredicate, tokenIfType } = require("../helpers/micromark.cjs");
const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark.cjs");
const intrawordRe = /^\w$/;
@ -25,9 +25,9 @@ const impl =
(token) => ((token.type === "htmlFlow") ? [] : token.children)
);
for (const token of emphasisTokens) {
const { children } = token;
const startSequence = tokenIfType(children[0], typeSequence);
const endSequence = tokenIfType(children[children.length - 1], typeSequence);
const sequences = getDescendantsByType(token, [ typeSequence ]);
const startSequence = sequences[0];
const endSequence = sequences[sequences.length - 1];
if (startSequence && endSequence) {
const markupStyle = emphasisOrStrongStyleFor(startSequence.text);
if (style === "consistent") {