mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Refactor to remove micromark helper getSiblingTokens for simpler code and better performance.
This commit is contained in:
parent
4436d84b55
commit
996d88a9b4
4 changed files with 88 additions and 140 deletions
|
|
@ -295,28 +295,6 @@ 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.
|
||||
*
|
||||
|
|
@ -441,7 +419,6 @@ module.exports = {
|
|||
getHeadingLevel,
|
||||
getHtmlTagInfo,
|
||||
getMicromarkEvents,
|
||||
getSiblingTokens,
|
||||
getTokenParentOfType,
|
||||
getTokenTextByType,
|
||||
inHtmlFlow,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue