MD031 - Code blocks need blank lines around them¶
Aliases: blanks-around-fences
What this rule does¶
Ensures code blocks (```) have blank lines before and after them for proper spacing.
Why this matters¶
- Readability: Blank lines visually separate code from surrounding text
- Rendering: Some Markdown processors require blank lines for proper code block display
- Consistency: Uniform spacing makes documents look professional
Examples¶
✅ Correct¶
Here's some text explaining the code.
```python
def hello():
print("Hello, world!")
```
And here's more text after the code.
❌ Incorrect¶
Here's some text explaining the code.
```python
def hello():
print("Hello, world!")
```
And here's more text after the code.
🔧 Fixed¶
Here's some text explaining the code.
```python
def hello():
print("Hello, world!")
```
And here's more text after the code.
Configuration¶
Example with list-items¶
When list-items is true (default):
When list-items is false:
Automatic fixes¶
This rule automatically adds blank lines:
- Before code blocks that don't have one
- After code blocks that don't have one
Azure DevOps / Colon Fences¶
Under the azure_devops flavor, MD031 also enforces blank lines before and
after colon-style fences (... :::), which Azure DevOps wikis use for
Mermaid diagrams and other block content.
❌ Incorrect¶
✅ Correct¶
Under any other flavor, colon fences are not recognized and MD031 ignores them.
See Azure DevOps Flavor for the full colon fence specification.
Learn more¶
- CommonMark code blocks - Technical specification
- Markdown Guide - Code - Code block best practices