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

MD046 - Code Block Style

Code block style should be consistent.

Why This Rule Exists

Markdown supports both fenced code blocks (triple backticks) and indented code blocks (4 spaces). Consistent style improves readability.

Styles

```rust
fn main() {
    println!("Hello");
}
```

Indented

    fn main() {
        println!("Hello");
    }

Examples

Incorrect (Mixed)

```python
print("Hello")
```

    # Indented code block
    echo "World"

Correct (Consistent Fenced)

```python
print("Hello")
```

```bash
echo "World"
```

Configuration

[MD046]
style = "fenced"  # Options: "fenced", "indented", "consistent"
ValueDescription
fencedUse triple backticks
indentedUse 4-space indentation
consistentMatch first code block's style

When to Disable

  • Documents mixing styles intentionally
  • Legacy content with established patterns

Rule Details

  • Rule ID: MD046
  • Aliases: code-block-style
  • Category: Formatting
  • Severity: Warning
  • Auto-fix: Yes
  • Supports language specification for syntax highlighting
  • Clearer visual boundaries
  • Easier to copy and paste
  • Works better with nested content
  • MD031 - Blanks around fences
  • MD040 - Fenced code blocks language
  • MD048 - Code fence style