Skip to content

Formatting MDX Blog Posts with Oxfmt

Have you ever written a blog post and ended up with a handful of very long, hard-to-read lines? If you write Markdown or MDX in Neovim, this guide walks you through a complete setup that automatically wraps your prose to a readable width as you save.

By the end you will have:

  • oxfmt installed globally so it works in any project
  • A tiny repo-level config file
  • Neovim’s conform.nvim formatting .md and .mdx files on save
  • Long lines broken automatically — without splitting your paragraphs in the rendered post

Markdown has a subtle rule: a single newline in your source is just folded into a space when rendered. You only get a visible line break with a blank line (new paragraph) or by ending a line with two spaces (a hard break).

That means you can safely wrap your source lines to, say, 100 characters — your editor stays readable, and the published post still shows one continuous paragraph.

There is a fast formatter called oxfmt (from the Oxc/JS Oxidation Compiler project). It supports Markdown and MDX, but here is the crucial detail:

Only the npm package of oxfmt can format Markdown/MDX. The standalone binary (e.g. the one Mason installs) skips those file types entirely.

So the whole trick is installing the right build of oxfmt.

Terminal window
npm install -g oxfmt@latest

Verify it’s on your PATH:

Terminal window
oxfmt --version
# e.g. Version: 0.63.0

Installing globally means it works in every project on your machine, not just this one.

Create .oxfmtrc.json in your project root (anywhere oxfmt will start from when it walks up your file tree):

{ "proseWrap": "always" }

That one option is everything. Everything else stays at oxfmt’s defaults:

  • printWidth: 100 (lines wrap at 100 characters)
  • default quoting, semicolons, indentation

If you prefer Prettier-style 80-character lines, you can add "printWidth": 80 explicitly.

Step 3 — Wire up Neovim with conform.nvim

Section titled “Step 3 — Wire up Neovim with conform.nvim”

If you use conform.nvim, register oxfmt for Markdown and MDX. Make sure .mdx files are treated as markdown:

vim.filetype.add { extension = { mdx = "markdown" } }
require("conform").setup({
formatters_by_ft = {
markdown = { "oxfmt" },
},
})

conform.nvim ships a built-in oxfmt formatter definition that:

  1. Looks for node_modules/.bin/oxfmt first, then falls back to the global one on PATH
  2. Uses stdin for fast formatting
  3. Roots its working directory at wherever it finds .oxfmtrc.json

Add format_on_save if you want automatic formatting when you save:

require("conform").setup({
format_on_save = {
timeout_ms = 2000,
lsp_fallback = true,
},
})

Step 4 — Format your existing files once

Section titled “Step 4 — Format your existing files once”

For files you’ve already written, run oxfmt once:

Terminal window
oxfmt --write "content/blog/*.{md,mdx}"

Adjust the glob to wherever your posts live — e.g. src/content/docs/blog/*.{md,mdx}.

Open a post, write a long sentence, and save. The line should break automatically at 100 characters.

Check that your rendered content is unchanged — since oxfmt wraps with plain single newlines (never trailing double-spaces), paragraphs stay intact in the browser.

“Formatting doesn’t do anything on save.”

Confirm which oxfmt binary is being used. Only the npm build supports Markdown/MDX. Remove any override that points conform at the standalone binary (e.g. a Mason path like stdpath("data")/mason/bin/oxfmt).

“It formats JS/TS files, but not markdown.”

Same root cause — check your formatter setup isn’t mapping markdown/mdx to a binary that can’t handle those file types.

“Long lines still don’t wrap.”

You almost certainly have proseWrap unset (its default is "preserve", which leaves lines untouched). Set "always" in .oxfmtrc.json.

Thing What it does
npm install -g oxfmt Global, MDX-capable formatter on your PATH
.oxfmtrc.json proseWrap: "always" so long lines wrap
conform.nvim config Formats .md/.mdx on save, local binary preferred
oxfmt --write One-off reformat of existing files

Fifteen minutes of setup gets you a blog you actually enjoy writing in.