[GH-ISSUE #527] MD031: Make rule configurable with lines above/after like MD022 #2278

Open
opened 2026-03-07 20:06:15 +03:00 by kerem · 1 comment
Owner

Originally created by @cjcarpen on GitHub (May 20, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/527

MD031 - Fenced code blocks should be surrounded by blank lines notes in the rationale:

Rationale: Aside from aesthetic reasons, some parsers, including kramdown, will not parse fenced code blocks that don't have blank lines before and after them.

However, we use a Markdown parser with Kramdown-style attributes, which for block-level elements are applied on the line immediately after the block. For example, to apply an ID:

```
this is my code block
```
{: #my-code-block}

Because of this, we'd like to be able to configure MD031 with lines_above and lines_below much like you can for MD022, Headings should be surrounded by blank lines. This would allow us to enable the MD031 rule to enforce an empty line above code blocks while still supporting Kramdown-style attributes on code blocks.

Originally created by @cjcarpen on GitHub (May 20, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/527 _MD031 - Fenced code blocks should be surrounded by blank lines_ notes in the rationale: > Rationale: Aside from aesthetic reasons, some parsers, including kramdown, will not parse fenced code blocks that don't have blank lines before and after them. However, we use a Markdown parser with [Kramdown-style attributes](https://kramdown.gettalong.org/quickref.html#block-attributes), which for block-level elements are applied on the line immediately after the block. For example, to apply an ID: ```` ``` this is my code block ``` {: #my-code-block} ```` Because of this, we'd like to be able to configure MD031 with `lines_above` and `lines_below` much like you can for _MD022, Headings should be surrounded by blank lines_. This would allow us to enable the MD031 rule to enforce an empty line above code blocks while still supporting Kramdown-style attributes on code blocks.
Author
Owner

@fulldecent commented on GitHub (Sep 10, 2024):

This also affects:

MD058/blanks-around-tables

And FYI, kramdown supports these attributes before or after the content:

{: .lead}
Hi

Try it yourself at:

https://kramdown.electricbook.works/

<!-- gh-comment-id:2341860174 --> @fulldecent commented on GitHub (Sep 10, 2024): This also affects: MD058/blanks-around-tables And FYI, kramdown supports these attributes **before** or after the content: ```md {: .lead} Hi ``` Try it yourself at: https://kramdown.electricbook.works/
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#2278
No description provided.