mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Reimplement micromark helper filterByHtmlTokens using filterByPredicate to simplify.
This commit is contained in:
parent
96a36de713
commit
b13d6a49ee
2 changed files with 10 additions and 39 deletions
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue