Skip to content

MD040 - fenced-code-language

Description

This rule enforces that fenced code blocks include a language identifier after the opening fence. The language identifier enables proper syntax highlighting in documentation viewers and code editors.

Rationale

Specifying a language identifier improves content rendering by using the correct syntax highlighting for code. This helps readers quickly identify the code type and allows tools to apply appropriate formatting. For plain text blocks, use text as the language identifier.

Configuration

allowed_languages

List of allowed language identifiers. Empty list allows any.

  • Default: [] (empty)
language_only

When True, only the language identifier is allowed (no metadata such as python hl_lines="3-5").

  • Default: false

Examples

Invalid

# Invalid Code Blocks

Code block without language:

```
def hello():
    print("Hello, World!")
```

Valid

# Valid Code Blocks

Code blocks with language specified:

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

```bash
echo "Hello"
```

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