Update MD025/single-title to ignore preceding blank lines and comments when looking for a title (top-level heading) (fixes #1420).

This commit is contained in:
David Anson 2025-03-15 17:52:09 -07:00
parent cb39972d9b
commit 5fc91f6977
6 changed files with 123 additions and 15 deletions

View file

@ -0,0 +1,6 @@
<!-- Comment -->
# Heading 1
# Heading 2 {MD025}

View file

@ -0,0 +1,4 @@
# Heading 1
# Heading 2 {MD025}

View file

@ -0,0 +1,4 @@
<!-- Comment -->
# Heading 1
# Heading 2 {MD025}

View file

@ -15750,6 +15750,92 @@ Generated by [AVA](https://avajs.dev).
`,
}
## heading-multiple-top-level-preceding-blank-and-comment.md
> Snapshot 1
{
errors: [
{
errorContext: 'Heading 2 {MD025}',
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 6,
ruleDescription: 'Multiple top-level headings in the same document',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md025.md',
ruleNames: [
'MD025',
'single-title',
'single-h1',
],
},
],
fixed: `␊
<!-- Comment -->
# Heading 1␊
# Heading 2 {MD025}␊
`,
}
## heading-multiple-top-level-preceding-blank.md
> Snapshot 1
{
errors: [
{
errorContext: 'Heading 2 {MD025}',
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 4,
ruleDescription: 'Multiple top-level headings in the same document',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md025.md',
ruleNames: [
'MD025',
'single-title',
'single-h1',
],
},
],
fixed: `␊
# Heading 1␊
# Heading 2 {MD025}␊
`,
}
## heading-multiple-top-level-preceding-comment.md
> Snapshot 1
{
errors: [
{
errorContext: 'Heading 2 {MD025}',
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 4,
ruleDescription: 'Multiple top-level headings in the same document',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md025.md',
ruleNames: [
'MD025',
'single-title',
'single-h1',
],
},
],
fixed: `<!-- Comment -->
# Heading 1␊
# Heading 2 {MD025}␊
`,
}
## heading_duplicate_content.md
> Snapshot 1