MD031 - blanks-around-fences¶
Description¶
This rule enforces blank lines around fenced code blocks. It triggers when code fences are not preceded or followed by blank lines. The first code fence in a document does not require a blank line above, and a code fence at the end of a document does not require a blank line below. Set list_items to false to disable this rule for code fences inside list items. This can be useful when creating tight lists containing code fences.
Rationale¶
Some parsers require a blank line before fenced code blocks when they follow a paragraph, or the fence may be treated as literal text. Consistent spacing around code blocks also improves readability.
Configuration¶
list_items-
Whether to check code fences inside list items.
- Default:
true
- Default:
Examples¶
Invalid¶
Some text here.
```python
def hello():
print("Hello!")
```
Some more text here.
Valid¶
Some text here.
```python
def hello():
print("Hello!")
```
Some more text here.