fix(md012): do not flag blank lines adjacent to headings (fixes #990).

Blank lines immediately above or below a heading are now excluded from
MD012's consecutive-blank-line count. Those blank lines are governed by
MD022 (blanks-around-headings), so MD012 defers to it. This means users
can set MD022's lines_above/lines_below > 1 without triggering spurious
MD012 violations.
This commit is contained in:
Ruben J. Jongejan 2026-02-21 13:05:05 +01:00
parent 0213a0274d
commit ccd26cef7f
No known key found for this signature in database
7 changed files with 106 additions and 4 deletions

View file

@ -0,0 +1,23 @@
# Heading
## Two blank lines above
Content.
## Two blank lines above again
More content.
Text
Text {MD012:15}
Text
## Three blank lines above
Text

View file

@ -46267,6 +46267,54 @@ Generated by [AVA](https://avajs.dev).
`,
}
## no-multiple-blanks-headings.md
> Snapshot 1
{
errors: [
{
errorContext: null,
errorDetail: 'Expected: 1; Actual: 2',
errorRange: null,
fixInfo: {
deleteCount: -1,
},
lineNumber: 15,
ruleDescription: 'Multiple consecutive blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md012.md',
ruleNames: [
'MD012',
'no-multiple-blanks',
],
severity: 'error',
},
],
fixed: `# Heading␊
## Two blank lines above␊
Content.␊
## Two blank lines above again␊
More content.␊
Text␊
Text {MD012:15}␊
Text␊
## Three blank lines above␊
Text␊
`,
}
## no-multiple-blanks-maximum.md
> Snapshot 1