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
Fenced (Recommended)
```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"
| Value | Description |
|---|---|
fenced | Use triple backticks |
indented | Use 4-space indentation |
consistent | Match 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
Why Fenced is Recommended
- Supports language specification for syntax highlighting
- Clearer visual boundaries
- Easier to copy and paste
- Works better with nested content