Reimplement MD003/heading-style using micromark tokens.

This commit is contained in:
David Anson 2024-06-08 14:44:49 -07:00
parent e447db33c9
commit 6daaa43410
10 changed files with 132 additions and 148 deletions

View file

@ -309,6 +309,26 @@ function getHeadingLevel(heading) {
return level;
}
/**
* Gets the heading style of a Micromark heading tokan.
*
* @param {Token} heading Micromark heading token.
* @returns {"atx" | "atx_closed" | "setext"} Heading style.
*/
function getHeadingStyle(heading) {
if (heading.type === "setextHeading") {
return "setext";
}
const atxHeadingSequenceLength = filterByTypes(
heading.children,
[ "atxHeadingSequence" ]
).length;
if (atxHeadingSequenceLength === 1) {
return "atx";
}
return "atx_closed";
}
/**
* HTML tag information.
*
@ -433,6 +453,7 @@ module.exports = {
filterByPredicate,
filterByTypes,
getHeadingLevel,
getHeadingStyle,
getHtmlTagInfo,
getMicromarkEvents,
getTokenParentOfType,