MD048 - Code fence style should be consistent¶
Aliases: code-fence-style
What this rule does¶
Ensures all code blocks use the same fence markers - either ``` or ~ consistently.
Why this matters¶
- Consistency: Mixed fence styles look unprofessional
- Readability: Consistent markers make code blocks easier to spot
- Tool compatibility: Some tools may expect one style over another
Examples¶
✅ Correct (using ``` throughout)¶
```javascript
function hello() {
console.log("Hello, world!");
}
```
```python
def hello():
print("Hello, world!")
```
✅ Correct (using ~ throughout)¶
~~~javascript
function hello() {
console.log("Hello, world!");
}
~~~
~~~python
def hello():
print("Hello, world!")
~~~
❌ Incorrect (mixed styles)¶
```javascript
function hello() {
console.log("Hello, world!");
}
```
~~~python
def hello():
print("Hello, world!")
~~~
🔧 Fixed¶
```javascript
function hello() {
console.log("Hello, world!");
}
```
```python
def hello():
print("Hello, world!")
```
Configuration¶
Style options¶
"consistent"(default): Use the most prevalent style in your document (in case of a tie, backtick ``` is preferred as it's more widely supported)"backtick": Always use ``` markers"tilde": Always use ~ markers
Automatic fixes¶
This rule automatically converts all code fence markers to match your configured style or the most prevalent style in the document.
Azure DevOps / Colon Fences¶
Under the azure_devops flavor, colon-style fences (... :::) are
skipped during fence style detection. They do not count as backtick or tilde
fences and are never flagged as style violations. This means you can freely use
colon fences for Mermaid diagrams alongside backtick or tilde fences for code,
without affecting which style is considered dominant:
In this example, only the backtick fence is counted. The colon fence is treated as opaque block content and ignored by MD048.
Under any other flavor, colon fences are not recognized and do not affect fence style detection.
See Azure DevOps Flavor for the full colon fence specification.
Markdown with Gherkin¶
Under the mdg flavor, MD048 always uses backtick. A Gherkin Doc String is
only ever a backtick fence, so a tilde fence can never be one: consistent
resolves to backtick rather than by prevalence, and a configured
style = "tilde" is not adopted — the rule enforces backtick anyway and prints
one [config warning] line on stderr when the rule reaches relevant content.
The fence-length arithmetic that keeps a converted outer fence from being closed by an interior one is unaffected.
See Markdown with Gherkin Flavor for the full flavor specification.
Learn more¶
- CommonMark code fences - Technical specification
- GitHub Flavored Markdown - Code block syntax