Skip to content

MD046 - code-block-style

Description

This rule ensures that code blocks throughout a document follow a consistent style. It validates that code blocks use either fenced style (triple backticks) or indented style (4 spaces) according to the configured preference.

Rationale

Consistent formatting makes it easier to understand a document. Uniform code block styling improves the readability of code examples.

Configuration

style

Required code block style.

  • Default: fenced
  • Options:
    • consistent: All code blocks must match the first one used
    • fenced: All code blocks must use fenced style (triple backticks)
    • indented: All code blocks must use indented style (4 spaces)

Examples

Invalid

# Mixed Code Block Styles

Fenced code block:

```python
def hello():
    print("Hello!")
```

Indented code block:

    echo "This is indented"
    ls -la

Valid

# Valid Code Blocks

All code blocks use fenced style:

```python
def hello():
    print("Hello, world!")
```

More text here.

```bash
echo "Fenced code block"
```