Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MD031 - Blanks Around Fences

Fenced code blocks should be surrounded by blank lines.

Why This Rule Exists

Blank lines around code blocks improve readability and ensure consistent rendering. Some parsers may not correctly identify code blocks without surrounding blank lines.

Examples

Incorrect

Some text here.
```code
let x = 1;

More text here.


### Correct

```markdown
Some text here.

```code
let x = 1;

More text here.


## Configuration

```toml
[MD031]
list_items = true  # Apply rule inside list items (default: true)

When to Disable

  • Documents with compact formatting requirements
  • Content where code blocks intentionally flow with text

Rule Details

  • Rule ID: MD031
  • Aliases: blanks-around-fences
  • Category: Formatting
  • Severity: Warning
  • Auto-fix: Yes
  • MD022 - Blanks around headings
  • MD032 - Blanks around lists
  • MD040 - Fenced code blocks language
  • MD046 - Code block style