mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Reimplement MD042/no-empty-links using micromark tokens.
This commit is contained in:
parent
7377b75383
commit
964e4c80ab
6 changed files with 219 additions and 97 deletions
|
|
@ -304,6 +304,21 @@ function filterByTypes(tokens, types, htmlFlow) {
|
|||
return filterByPredicate(tokens, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of nested Micromark token descendants by type path.
|
||||
*
|
||||
* @param {Token|Token[]} parent Micromark token parent or parents.
|
||||
* @param {TokenType[]} typePath Micromark token type path.
|
||||
* @returns {Token[]} Micromark token descendants.
|
||||
*/
|
||||
function getDescendantsByType(parent, typePath) {
|
||||
let tokens = Array.isArray(parent) ? parent : [ parent ];
|
||||
for (const type of typePath) {
|
||||
tokens = tokens.flatMap((t) => t.children).filter((t) => t.type === type);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the heading level of a Micromark heading tokan.
|
||||
*
|
||||
|
|
@ -472,6 +487,7 @@ module.exports = {
|
|||
"parse": micromarkParse,
|
||||
filterByPredicate,
|
||||
filterByTypes,
|
||||
getDescendantsByType,
|
||||
getHeadingLevel,
|
||||
getHeadingStyle,
|
||||
getHeadingText,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue