mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-15 21:40:13 +01:00
Update getHeadingText helper to exclude HTML comments from returned heading text (fixes #1411).
This commit is contained in:
parent
d36a57d680
commit
d5cb5c8546
4 changed files with 33 additions and 2 deletions
|
|
@ -7,6 +7,8 @@ const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");
|
|||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
|
||||
/** @typedef {import("../lib/exports.mjs").MicromarkToken} Token */
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
|
||||
|
||||
/**
|
||||
* Determines if a Micromark token is within an htmlFlow type.
|
||||
|
|
@ -214,8 +216,12 @@ function getHeadingStyle(heading) {
|
|||
* @returns {string} Heading text.
|
||||
*/
|
||||
function getHeadingText(heading) {
|
||||
const headingTexts = getDescendantsByType(heading, [ [ "atxHeadingText", "setextHeadingText" ] ]);
|
||||
return headingTexts[0]?.text.replace(/[\r\n]+/g, " ") || "";
|
||||
const headingText = getDescendantsByType(heading, [ [ "atxHeadingText", "setextHeadingText" ] ])
|
||||
.flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
|
||||
.map((data) => data.text)
|
||||
.join("")
|
||||
.replace(/[\r\n]+/g, " ");
|
||||
return headingText || "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -95,6 +95,12 @@ BB
|
|||
|
||||
{MD024:94}
|
||||
|
||||
## Headings <!-- that differ -->
|
||||
|
||||
## Headings <!-- in comments -->
|
||||
|
||||
{MD024:-2}
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"heading-style": false,
|
||||
"no-duplicate-heading": {
|
||||
|
|
|
|||
|
|
@ -15554,6 +15554,19 @@ Generated by [AVA](https://avajs.dev).
|
|||
'no-duplicate-heading',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: 'Headings',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: null,
|
||||
lineNumber: 100,
|
||||
ruleDescription: 'Multiple headings with the same content',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md024.md',
|
||||
ruleNames: [
|
||||
'MD024',
|
||||
'no-duplicate-heading',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: 'A',
|
||||
errorDetail: null,
|
||||
|
|
@ -15722,6 +15735,12 @@ Generated by [AVA](https://avajs.dev).
|
|||
␊
|
||||
{MD024:94}␊
|
||||
␊
|
||||
## Headings <!-- that differ -->␊
|
||||
␊
|
||||
## Headings <!-- in comments -->␊
|
||||
␊
|
||||
{MD024:-2}␊
|
||||
␊
|
||||
<!-- markdownlint-configure-file {␊
|
||||
"heading-style": false,␊
|
||||
"no-duplicate-heading": {␊
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue