mdx-formatter

Type to search...

to open search from anywhere

You are viewing documentation for an older version. View the latest version

Code Blocks

How the formatter handles fenced code blocks

Code blocks are preserved exactly as written. The formatter does not modify content, language identifiers, or meta strings inside code blocks.

Rules

  • Fenced code blocks (```) are preserved as-is
  • Language identifiers are preserved
  • Content inside code blocks is never modified
  • Meta strings (e.g., title="example.js") are preserved

Examples

JSX content inside code blocks is not formatted

Code blocks containing JSX are left as-is — the JSX formatting rules do not apply inside fences:

Before:

```jsx
<Component prop1="value1" prop2="value2" prop3="value3" />
```

After (unchanged):

```jsx
<Component prop1="value1" prop2="value2" prop3="value3" />
```

Code block with title (MDX)

Before:

```js title="example.js"
function hello() {
  console.log('world');
}
```

After (unchanged — content and meta string preserved):

```js title="example.js"
function hello() {
  console.log('world');
}
```

Revision History