MDX Formatter

Format and beautify MDX code.

Local Your input is processed locally in your browser. The first run loads the open-source Prettier library from this site; your input is not sent anywhere. Found a problem? Report an issue

What the MDX Formatter does

The MDX Formatter formats MDX (Markdown with JSX) with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports MDX documents that mix Markdown with JSX and imports.

MDX Formatter examples

The built-in sample

Input

import {Chart} from './chart'

# Sales
*  north
*  south

<Chart data={[1,2,3]}   color="red"/>

Output

import { Chart } from "./chart";

# Sales

- north
- south

<Chart data={[1, 2, 3]} color="red" />

This is the input that the Load sample button fills in.

Exports and expressions

Input

export const meta={title:'x'}

# Hi {props.name}

Total: {1+2}

Output

export const meta = { title: "x" };

# Hi {props.name}

Total: {1+2}

The export statement is formatted as JavaScript. Expressions in braces inside text are left exactly as written.

Each output was produced by running this tool on the input above it.

How it works

The code is parsed with Prettier's mdx parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.

Details and limits

  • import and export statements and JSX elements on their own lines are formatted as JavaScript: double quotes, spacing in braces, a space before />.
  • The Markdown parts follow the same rules as the Markdown Formatter.
  • Prettier's MDX support was written for the first version of MDX. Markdown placed inside a JSX element may be joined onto one line, which newer MDX versions can interpret differently, so review such blocks after formatting.

Questions

Is my data uploaded when I use MDX Formatter?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does MDX Formatter do?

The MDX Formatter formats MDX (Markdown with JSX) with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports MDX documents that mix Markdown with JSX and imports.

How does MDX Formatter work?

The code is parsed with Prettier's mdx parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.

Are there any limits I should know about?

import and export statements and JSX elements on their own lines are formatted as JavaScript: double quotes, spacing in braces, a space before />. The Markdown parts follow the same rules as the Markdown Formatter.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.