Reimplement MD024/no-duplicate-heading using micromark tokens.

This commit is contained in:
David Anson 2024-06-19 21:05:31 -07:00
parent b1b16dabec
commit 96354678dc
6 changed files with 77 additions and 49 deletions

View file

@ -345,6 +345,20 @@ function getHeadingStyle(heading) {
return "atx_closed";
}
/**
* Gets the heading text of a Micromark heading token.
*
* @param {Token} heading Micromark heading token.
* @returns {string} Heading text.
*/
function getHeadingText(heading) {
const headingTexts = filterByTypes(
heading.children,
[ "atxHeadingText", "setextHeadingText" ]
);
return headingTexts[0]?.text.replace(/[\r\n]+/g, " ") || "";
}
/**
* HTML tag information.
*
@ -460,6 +474,7 @@ module.exports = {
filterByTypes,
getHeadingLevel,
getHeadingStyle,
getHeadingText,
getHtmlTagInfo,
getMicromarkEvents,
getTokenParentOfType,