mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01: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
|
|
@ -1334,30 +1334,11 @@ function filterByTypes(tokens, allowed) {
|
|||
* @returns {Token[]} Filtered tokens.
|
||||
*/
|
||||
function filterByHtmlTokens(tokens) {
|
||||
var result = [];
|
||||
var pending = [tokens];
|
||||
var current = null;
|
||||
while (current = pending.shift()) {
|
||||
var _iterator2 = _createForOfIteratorHelper(filterByTypes(current, ["htmlFlow", "htmlText"])),
|
||||
_step2;
|
||||
try {
|
||||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||
var token = _step2.value;
|
||||
if (token.type === "htmlText") {
|
||||
result.push(token);
|
||||
} else {
|
||||
// token.type === "htmlFlow"
|
||||
// @ts-ignore
|
||||
pending.push(token.htmlFlowChildren);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator2.e(err);
|
||||
} finally {
|
||||
_iterator2.f();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return filterByPredicate(tokens, function (token) {
|
||||
return token.type === "htmlText";
|
||||
}, function (token) {
|
||||
return token.htmlFlowChildren || token.children;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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