Reimplement micromark helper filterByHtmlTokens using filterByPredicate to simplify.

This commit is contained in:
David Anson 2023-08-29 22:52:08 -07:00
parent 96a36de713
commit b13d6a49ee
2 changed files with 10 additions and 39 deletions

View file

@ -218,21 +218,11 @@ function filterByTypes(tokens, allowed) {
* @returns {Token[]} Filtered tokens.
*/
function filterByHtmlTokens(tokens) {
const result = [];
const pending = [ tokens ];
let current = null;
while ((current = pending.shift())) {
for (const token of filterByTypes(current, [ "htmlFlow", "htmlText" ])) {
if (token.type === "htmlText") {
result.push(token);
} else {
// token.type === "htmlFlow"
// @ts-ignore
pending.push(token.htmlFlowChildren);
}
}
}
return result;
return filterByPredicate(
tokens,
(token) => token.type === "htmlText",
(token) => token.htmlFlowChildren || token.children
);
}
/**