[GH-ISSUE #143] MD022 - Headings should be surrounded by blank lines #1971

Closed
opened 2026-03-07 20:03:15 +03:00 by kerem · 7 comments
Owner

Originally created by @walles on GitHub (Aug 31, 2018).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/143

I'd like to configure this warning to:

  • Require a preceding empty line (as it already does)
  • Not requiring a following empty line

So this should be OK:

something

# Heading
more text

But this should not be OK:

something
# Heading
more text

The docs explain why you must have an empty line before the heading (kramdown), but only cites aesthetics for why you should have an empty line after the heading.

And as a lot of our markdown has no empty line after headings, and I actually like it this way, I'd like to be able to inform Markdownlint about this.

Regards /Johan

Originally created by @walles on GitHub (Aug 31, 2018). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/143 I'd like to configure this warning to: * Require a preceding empty line (as it already does) * Not requiring a following empty line So this should be OK: ``` markdown something # Heading more text ``` But this should not be OK: ``` markdown something # Heading more text ``` [The docs](https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md022) explain why you must have an empty line before the heading (kramdown), but only cites aesthetics for why you should have an empty line after the heading. And as a lot of our markdown has no empty line after headings, and I actually like it this way, I'd like to be able to inform Markdownlint about this. Regards /Johan
kerem 2026-03-07 20:03:15 +03:00
Author
Owner

@DavidAnson commented on GitHub (Aug 31, 2018):

I feel like I have seen parsers have problems with this, so I won’t default it on - but it seems okay to add as an option. Thanks!

<!-- gh-comment-id:417711495 --> @DavidAnson commented on GitHub (Aug 31, 2018): I feel like I have seen parsers have problems with this, so I won’t default it on - but it seems okay to add as an option. Thanks!
Author
Owner

@vukanac commented on GitHub (Dec 20, 2018):

Is it possible to configure markdownlinter to force usage of 2 empty lines before headings and 1 after?

<!-- gh-comment-id:448909428 --> @vukanac commented on GitHub (Dec 20, 2018): Is it possible to configure markdownlinter to force usage of 2 empty lines before headings and 1 after?
Author
Owner

@DavidAnson commented on GitHub (Dec 20, 2018):

Not currently, but that seems like a reasonable thing to enable as part of addressing this issue.

<!-- gh-comment-id:449067539 --> @DavidAnson commented on GitHub (Dec 20, 2018): Not currently, but that seems like a reasonable thing to enable as part of addressing this issue.
Author
Owner

@vukanac commented on GitHub (Mar 31, 2019):

Thank you for new feature!
But new problem show up. Applying this new rule will force to change other rule (multiple empty lines), and that will allow breaking its desired default value 1. As in .markdownlint.json:

{
  "no-multiple-blanks": {
    "maximum": 2         <------ We_need_to_keep_this_to_default:_1.
  },
  "blanks-around-headings": {
    "line-above": 2,
    "line-below": 1
  }
}

Desired would be only to override multiple-empty-line validation on validating heading lines.
Any way, thank you for the work on this feature.

<!-- gh-comment-id:478334254 --> @vukanac commented on GitHub (Mar 31, 2019): Thank you for new feature! But new problem show up. Applying this new rule will force to change other rule (multiple empty lines), and that will allow breaking its desired default value 1. As in `.markdownlint.json`: ```json { "no-multiple-blanks": { "maximum": 2 <------ We_need_to_keep_this_to_default:_1. }, "blanks-around-headings": { "line-above": 2, "line-below": 1 } } ``` Desired would be only to override multiple-empty-line validation on validating heading lines. Any way, thank you for the work on this feature.
Author
Owner

@DavidAnson commented on GitHub (Mar 31, 2019):

Yes, I mention that consequence here: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md022

Because rules are independent, I don’t see a good way to avoid this.

<!-- gh-comment-id:478360249 --> @DavidAnson commented on GitHub (Mar 31, 2019): Yes, I mention that consequence here: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md022 Because rules are independent, I don’t see a good way to avoid this.
Author
Owner

@merqrial commented on GitHub (Mar 12, 2023):

Related question, can we have heading-level rules for this? Probably makes sense to have a blank line after the H1, not necessarily headings lower than H4.

<!-- gh-comment-id:1465090077 --> @merqrial commented on GitHub (Mar 12, 2023): Related question, can we have heading-level rules for this? Probably makes sense to have a blank line after the H1, not necessarily headings lower than H4.
Author
Owner

@DavidAnson commented on GitHub (Mar 12, 2023):

See #504

<!-- gh-comment-id:1465092715 --> @DavidAnson commented on GitHub (Mar 12, 2023): See #504
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#1971
No description provided.