Aliases: blanks-around-fences
Tags: blank_lines, code
Fixable: Some violations can be fixed by tooling
This rule is triggered when fenced code blocks are either not preceded or not followed by a blank line:
Some text
```
Code block
```
```
Another code block
```
Some more textTo fix this, ensure that all fenced code blocks have a blank line both before and after (except where the block is at the beginning or end of the document):
Some text
```
Code block
```
```
Another code block
```
Some more textThis rule supports one configuration parameter:
Set the list_items parameter to false to disable this rule for list items. Disabling this behavior for lists can be useful if it is necessary to create a tight list containing a code fence.
Example configuration:
[linters.settings.blanks-around-fences]
list_items = falseExample with list_items = true (default):
1. First item
```javascript
const x = 1;
```
2. Second itemThis would trigger MD031 violations (missing blank lines around the code block).
Example with list_items = false:
1. First item
```javascript
const x = 1;
```
2. Second itemThis would NOT trigger MD031 violations, allowing tight lists with code blocks.
Aside from aesthetic reasons, some parsers, including kramdown, will not parse fenced code blocks that don't have blank lines before and after them. Ensuring proper spacing around code blocks improves compatibility across different Markdown parsers and enhances readability.
Some text here.
```javascript
const greeting = "Hello, World!";
console.log(greeting);
```
More text here.# Document start
```bash
echo "This is fine at document start"
```
Some text.
```python
print("This is properly spaced")
```
# Document continuesSome text here.
```javascript
const greeting = "Hello, World!";
console.log(greeting);
```
More text here.Some text here.
```bash
echo "Missing blank line after"
```
More text immediately following.<!-- This triggers violations -->
1. First item
```javascript
const x = 1;
```
2. Second item
<!-- This is correct -->
1. First item
```javascript
const x = 1;
```
2. Second item