mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 01:40:13 +01:00
Reimplement MD051/link-fragments using micromark tokens, report reference link issues for definition and fix when possible, handle reporting multiple violations on the same line better.
This commit is contained in:
parent
dd73b0ad7f
commit
ef1bd286a9
14 changed files with 458 additions and 346 deletions
|
|
@ -204,6 +204,30 @@ function filterByTypes(tokens, allowed) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of Micromark tokens for HTML tokens.
|
||||
*
|
||||
* @param {Token[]} tokens Micromark tokens.
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all nested child tokens.
|
||||
*
|
||||
|
|
@ -293,6 +317,7 @@ function tokenIfType(token, type) {
|
|||
|
||||
module.exports = {
|
||||
"parse": micromarkParse,
|
||||
filterByHtmlTokens,
|
||||
filterByPredicate,
|
||||
filterByTypes,
|
||||
flattenedChildren,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue