Reimplement MD028/no-blanks-blockquote using micromark tokens.

This commit is contained in:
David Anson 2024-02-18 16:46:13 -08:00
parent 89eef68dbd
commit f5b5773b50
4 changed files with 94 additions and 30 deletions

View file

@ -295,6 +295,28 @@ function filterByTypes(tokens, types) {
return filterByPredicate(tokens, predicate);
}
/**
* Gets all sibling token groups for a list of Micromark tokens.
*
* @param {Token[]} tokens Micromark tokens.
* @returns {Token[][]} Sibling token groups.
*/
function getSiblingTokens(tokens) {
const result = [];
const queue = [ tokens ];
// eslint-disable-next-line init-declarations
let current;
while ((current = queue.shift())) {
result.push(current);
for (const token of current) {
if (token.children.length > 0) {
queue.push(token.children);
}
}
}
return result;
}
/**
* Gets the heading level of a Micromark heading tokan.
*
@ -419,6 +441,7 @@ module.exports = {
getHeadingLevel,
getHtmlTagInfo,
getMicromarkEvents,
getSiblingLists: getSiblingTokens,
getTokenParentOfType,
getTokenTextByType,
inHtmlFlow,