Skip to content

MD040 - Code blocks should have a language specified

Aliases: fenced-code-language

What this rule does

Ensures code blocks (```) specify what programming language they contain.

Why this matters

  • Syntax highlighting: Editors and renderers can color-code the syntax correctly
  • Clarity: Readers immediately know what language they're looking at
  • Tools: Some tools use language hints for processing or validation

Examples

✅ Correct

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

```javascript
console.log("Hello, world!");
```

```bash
echo "Hello, world!"
```

❌ Incorrect

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

```
console.log("Hello, world!");
```

🔧 Fixed

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

```text
console.log("Hello, world!");
```

Note: The fix adds text as a default language hint when none is specified.

Configuration

This rule has no configuration options.

Automatic fixes

This rule automatically adds text as the language specifier for code blocks without one.

Learn more

  • MD046 - Code block style should be consistent
  • MD048 - Code fence style should be consistent
  • MD031 - Code blocks should be surrounded by blank lines