Update MD036/no-emphasis-as-heading to ignore HTML comments at the beginning or ending of the emphasised heading (fixes #1267).

This commit is contained in:
David Anson 2025-03-30 17:30:12 -07:00
parent b4204f197e
commit a9417fdf67
4 changed files with 62 additions and 2 deletions

View file

@ -11,6 +11,11 @@ const emphasisTypes = [
[ "strong", "strongText" ]
];
const isParagraphChildMeaningful = (token) => !(
(token.type === "htmlText") ||
((token.type === "data") && (token.text.trim().length === 0))
);
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD036", "no-emphasis-as-heading" ],
@ -22,9 +27,14 @@ export default {
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
const punctuationRe = new RegExp("[" + punctuation + "]$");
const paragraphTokens =
filterByTypesCached([ "paragraph" ])
filterByTypesCached([ "paragraph" ], true)
.filter((token) =>
(token.parent?.type === "content") && !token.parent?.parent && (token.children.length === 1)
(token.parent?.type === "content") &&
(
!token.parent?.parent ||
((token.parent?.parent?.type === "htmlFlow") && !token.parent?.parent?.parent)
) &&
(token.children.filter(isParagraphChildMeaningful).length === 1)
);
for (const emphasisType of emphasisTypes) {
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);