mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-23 17:30:12 +01:00
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:
parent
bdc9d357f3
commit
d9de1dd22f
13 changed files with 690 additions and 64 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue