mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
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:
parent
b4204f197e
commit
a9417fdf67
4 changed files with 62 additions and 2 deletions
|
|
@ -11,6 +11,11 @@ const emphasisTypes = [
|
||||||
[ "strong", "strongText" ]
|
[ "strong", "strongText" ]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const isParagraphChildMeaningful = (token) => !(
|
||||||
|
(token.type === "htmlText") ||
|
||||||
|
((token.type === "data") && (token.text.trim().length === 0))
|
||||||
|
);
|
||||||
|
|
||||||
/** @type {import("markdownlint").Rule} */
|
/** @type {import("markdownlint").Rule} */
|
||||||
export default {
|
export default {
|
||||||
"names": [ "MD036", "no-emphasis-as-heading" ],
|
"names": [ "MD036", "no-emphasis-as-heading" ],
|
||||||
|
|
@ -22,9 +27,14 @@ export default {
|
||||||
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
|
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
|
||||||
const punctuationRe = new RegExp("[" + punctuation + "]$");
|
const punctuationRe = new RegExp("[" + punctuation + "]$");
|
||||||
const paragraphTokens =
|
const paragraphTokens =
|
||||||
filterByTypesCached([ "paragraph" ])
|
filterByTypesCached([ "paragraph" ], true)
|
||||||
.filter((token) =>
|
.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) {
|
for (const emphasisType of emphasisTypes) {
|
||||||
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
|
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
|
||||||
|
|
|
||||||
|
|
@ -44,3 +44,15 @@ detected as a heading because it's on multiple lines**
|
||||||
**This shouldn't be detected as a heading as it ends in full-width punctuation。**
|
**This shouldn't be detected as a heading as it ends in full-width punctuation。**
|
||||||
|
|
||||||
**[This as well since it is a link](https://example.com)**
|
**[This as well since it is a link](https://example.com)**
|
||||||
|
|
||||||
|
*Section 4: emphasis as heading {MD036}* <!-- comment -->
|
||||||
|
|
||||||
|
Emphasis as heading followed by an HTML comment
|
||||||
|
|
||||||
|
<!-- comment --> __Section 5: emphasis as heading {MD036}__
|
||||||
|
|
||||||
|
Emphasis as heading following an HTML comment
|
||||||
|
|
||||||
|
*Section 6: emphasis <!-- comment --> as non-heading*
|
||||||
|
|
||||||
|
Embedded HTML comments are unusual and cause the emphasis to be ignored/allowed
|
||||||
|
|
|
||||||
|
|
@ -11850,6 +11850,32 @@ Generated by [AVA](https://avajs.dev).
|
||||||
'no-emphasis-as-heading',
|
'no-emphasis-as-heading',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
errorContext: 'Section 4: emphasis as heading...',
|
||||||
|
errorDetail: null,
|
||||||
|
errorRange: null,
|
||||||
|
fixInfo: null,
|
||||||
|
lineNumber: 48,
|
||||||
|
ruleDescription: 'Emphasis used instead of a heading',
|
||||||
|
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md036.md',
|
||||||
|
ruleNames: [
|
||||||
|
'MD036',
|
||||||
|
'no-emphasis-as-heading',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
errorContext: 'Section 5: emphasis as heading...',
|
||||||
|
errorDetail: null,
|
||||||
|
errorRange: null,
|
||||||
|
fixInfo: null,
|
||||||
|
lineNumber: 52,
|
||||||
|
ruleDescription: 'Emphasis used instead of a heading',
|
||||||
|
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md036.md',
|
||||||
|
ruleNames: [
|
||||||
|
'MD036',
|
||||||
|
'no-emphasis-as-heading',
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
errorContext: null,
|
errorContext: null,
|
||||||
errorDetail: 'Expected: asterisk; Actual: underscore',
|
errorDetail: 'Expected: asterisk; Actual: underscore',
|
||||||
|
|
@ -11977,6 +12003,18 @@ Generated by [AVA](https://avajs.dev).
|
||||||
**This shouldn't be detected as a heading as it ends in full-width punctuation。**␊
|
**This shouldn't be detected as a heading as it ends in full-width punctuation。**␊
|
||||||
␊
|
␊
|
||||||
**[This as well since it is a link](https://example.com)**␊
|
**[This as well since it is a link](https://example.com)**␊
|
||||||
|
␊
|
||||||
|
*Section 4: emphasis as heading {MD036}* <!-- comment -->␊
|
||||||
|
␊
|
||||||
|
Emphasis as heading followed by an HTML comment␊
|
||||||
|
␊
|
||||||
|
<!-- comment --> __Section 5: emphasis as heading {MD036}__␊
|
||||||
|
␊
|
||||||
|
Emphasis as heading following an HTML comment␊
|
||||||
|
␊
|
||||||
|
*Section 6: emphasis <!-- comment --> as non-heading*␊
|
||||||
|
␊
|
||||||
|
Embedded HTML comments are unusual and cause the emphasis to be ignored/allowed␊
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue