Skip to content

MD048 - code-fence-style

Description

This rule enforces that fenced code blocks use a consistent style throughout the document. Code fences can use either backticks (```) or tildes (~~~), but mixing styles within a document is discouraged.

Rationale

Consistent formatting makes it easier to understand a document. Using the same fence style throughout promotes readability and maintains a uniform appearance in the source Markdown.

Configuration

style

Code fence style to enforce.

  • Default: consistent
  • Options:
    • consistent: All fences must match the first one used
    • backtick: All fences must use backticks (```)
    • tilde: All fences must use tildes (~~~)

Examples

Invalid

# Inconsistent Code Fences

First code block uses backticks:

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

Second code block uses tildes:

~~~bash
echo "Hello"
~~~

Valid

# Consistent Code Fences

All code blocks use backticks:

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

```bash
echo "Hello"
```

```json
{"key": "value"}
```