Update MD022/blanks-around-headings to allow specifying a different number of blank lines for each heading level (fixes #504).

This commit is contained in:
David Anson 2023-08-08 22:56:47 -07:00
parent bdc9d357f3
commit d9de1dd22f
13 changed files with 690 additions and 64 deletions

View file

@ -245,6 +245,27 @@ function flattenedChildren(parent) {
return result;
}
/**
* Gets the heading level of a Micromark heading tokan.
*
* @param {Token} heading Micromark heading token.
* @returns {number} Heading level.
*/
function getHeadingLevel(heading) {
const headingSequence = filterByTypes(
heading.children,
[ "atxHeadingSequence", "setextHeadingLineSequence" ]
);
let level = 1;
const { text } = headingSequence[0];
if (text[0] === "#") {
level = Math.min(text.length, 6);
} else if (text[0] === "-") {
level = 2;
}
return level;
}
/**
* Gets information about the tag in an HTML token.
*
@ -321,6 +342,7 @@ module.exports = {
filterByPredicate,
filterByTypes,
flattenedChildren,
getHeadingLevel,
getHtmlTagInfo,
getMicromarkEvents,
getTokenTextByType,