mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +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.
|
* @returns {Token[]} Filtered tokens.
|
||||||
*/
|
*/
|
||||||
function filterByHtmlTokens(tokens) {
|
function filterByHtmlTokens(tokens) {
|
||||||
var result = [];
|
return filterByPredicate(tokens, function (token) {
|
||||||
var pending = [tokens];
|
return token.type === "htmlText";
|
||||||
var current = null;
|
}, function (token) {
|
||||||
while (current = pending.shift()) {
|
return token.htmlFlowChildren || token.children;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -218,21 +218,11 @@ function filterByTypes(tokens, allowed) {
|
||||||
* @returns {Token[]} Filtered tokens.
|
* @returns {Token[]} Filtered tokens.
|
||||||
*/
|
*/
|
||||||
function filterByHtmlTokens(tokens) {
|
function filterByHtmlTokens(tokens) {
|
||||||
const result = [];
|
return filterByPredicate(
|
||||||
const pending = [ tokens ];
|
tokens,
|
||||||
let current = null;
|
(token) => token.type === "htmlText",
|
||||||
while ((current = pending.shift())) {
|
(token) => token.htmlFlowChildren || token.children
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue