Skip to content

Latest commit

 

History

History
133 lines (96 loc) · 2.36 KB

File metadata and controls

133 lines (96 loc) · 2.36 KB

MD048 - Code fence style

Tags: code
Aliases: code-fence-style

Description

This rule enforces consistent use of code fence symbols (backticks or tildes) throughout a Markdown document.

Rationale

Consistent formatting makes it easier to understand a document. Using a consistent style for code fences improves readability and maintainability.

Configuration

  • style: Code fence style (string, default consistent)
    • consistent: Use a consistent style matching the first code fence in the document
    • backtick: Use only backticks (```)
    • tilde: Use only tildes (~~~)

Examples

Incorrect ❌

Inconsistent style (mixed backticks and tildes):

```python
# First code block with backticks
print("Hello, World!")
// Second code block with tildes - violates consistency
console.log("Hello, World!");

**Backtick style violation:**

```markdown
~~~python
# Tilde fence when backtick style is configured
print("Hello, World!")
~~~

Tilde style violation:

```python
# Backtick fence when tilde style is configured
print("Hello, World!")

### Correct ✅

**Consistent style (all backticks):**

```markdown
```python
# First code block with backticks
print("Hello, World!")
// Second code block also with backticks
console.log("Hello, World!");

**Consistent style (all tildes):**

```markdown
~~~python
# First code block with tildes
print("Hello, World!")
~~~

~~~javascript
// Second code block also with tildes
console.log("Hello, World!");
~~~

Single code block (any style is valid):

```python
# Only one code block - any style is fine
print("Hello, World!")

**Mixed with indented code blocks (indented blocks are ignored):**

```markdown
```python
# Fenced code block
print("Hello, World!")
# Indented code block - ignored by this rule
console.log("Hello, World!");

## Configuration Examples

### Enforce consistent style (default)

```toml
[linters.settings.code-fence-style]
style = 'consistent'

Enforce backtick style only

[linters.settings.code-fence-style]
style = 'backtick'

Enforce tilde style only

[linters.settings.code-fence-style]
style = 'tilde'

Related Rules