mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-21 08:20:12 +01:00
Reimplement MD024/no-duplicate-heading using micromark tokens.
This commit is contained in:
parent
b1b16dabec
commit
96354678dc
6 changed files with 77 additions and 49 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue