MDX Formatter
WM-92Paste an MDX document and get Markdown and JSX formatted together. Lists, emphasis and tables are normalized, and import, export and component lines are laid out as JavaScript.
Runs in your browser. Nothing is uploaded.
MDX
Formatted MDX
How to use it
- Paste your MDX, or open an .mdx file or drop it on the input box.
- Choose whether paragraphs are kept, wrapped at a width, or put on one line each.
- Press Format.
- Copy the result or download it as an .mdx file.
What is formatted
Markdown parts follow Prettier's Markdown rules: bullet markers become hyphens, emphasis uses underscores, tables are aligned and blank lines between blocks are normalized. Import and export statements and JSX blocks are formatted as JavaScript, so a self-closing component gets a single space before the slash and props get consistent spacing. Front matter and code fences are kept as they are.
Prose wrapping
By default your line breaks inside paragraphs are left alone, which keeps diffs small. Choose "Wrap at line width" to re-flow text to 80, 100 or 120 columns, or "One line per paragraph" to join each paragraph. Re-flowing changes where lines break, not the words. Pick the default if your team has no wrapping rule.
Limits
Nothing is rendered or compiled, so a component that does not exist is not reported. Expressions in curly braces inside a paragraph are left as typed. MDX that fails to parse gives an error with the line and column where it stopped. Output follows the Prettier version in this page.
Questions people ask
How do I format an MDX file?
Paste the MDX into the box and press Format. Markdown is tidied and the imports, exports and JSX are formatted as code. Copy the output or download it as .mdx.
Does it change my Markdown wording?
No. It changes markers, spacing and blank lines. With prose wrap on, line breaks inside paragraphs move, but the words stay the same. It changes list markers, emphasis marks, spacing and blank lines. With prose wrapping on, line breaks inside paragraphs move, but the words stay the same.
Does it format the JSX inside my MDX?
Yes. JSX blocks are parsed as JavaScript expressions and printed with consistent spacing. Props that are too long are wrapped one per line. JSX blocks are parsed as JavaScript and printed with consistent spacing. Props that are too long for the line width are wrapped one per line.
Will it check that my components exist?
No. It never renders the page or resolves imports. A typo in a component name passes through unchanged. It never renders the page or resolves imports, so a misspelled component name or a missing file passes through unchanged. Run your site build to catch those.
Which prose wrap option should I choose?
Keep as written is the safest. It leaves your paragraph breaks alone, so version control diffs show only real changes. Choose wrap only if your project already wraps prose at a set width.
About this tool
Formats MDX with Prettier. Markdown is tidied (list markers, emphasis, blank lines, tables) and import and export lines and JSX blocks are formatted as JavaScript. The wrap option controls whether paragraphs are re-flowed; the default leaves your line breaks alone. Nothing is compiled or rendered, so a component that does not exist is not reported. Only MDX that fails to parse gives an error with line and column. Expressions in curly braces inside paragraphs are left as written. Output follows the Prettier version in this page.