mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10: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
|
|
@ -18,10 +18,6 @@ const inlineCommentStartRe =
|
|||
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
|
||||
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
||||
|
||||
// Regular expression for matching HTML elements
|
||||
const htmlElementRe = /<(([A-Za-z][A-Za-z\d-]*)(?:\s[^`>]*)?)\/?>/g;
|
||||
module.exports.htmlElementRe = htmlElementRe;
|
||||
|
||||
// Regular expressions for range matching
|
||||
module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
|
||||
module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
|
||||
|
|
@ -444,23 +440,6 @@ module.exports.flattenLists = function flattenLists(tokens) {
|
|||
return flattenedLists;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calls the provided function for each specified inline child token.
|
||||
*
|
||||
* @param {Object} params RuleParams instance.
|
||||
* @param {string} type Token type identifier.
|
||||
* @param {Function} handler Callback function.
|
||||
* @returns {void}
|
||||
*/
|
||||
function forEachInlineChild(params, type, handler) {
|
||||
filterTokens(params, "inline", (token) => {
|
||||
for (const child of token.children.filter((c) => c.type === type)) {
|
||||
handler(child, token);
|
||||
}
|
||||
});
|
||||
}
|
||||
module.exports.forEachInlineChild = forEachInlineChild;
|
||||
|
||||
// Calls the provided function for each heading's content
|
||||
module.exports.forEachHeading = function forEachHeading(params, handler) {
|
||||
let heading = null;
|
||||
|
|
|
|||
|
|
@ -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