Search code examples
prettiermdxjs

Formatting MDX programmatically using prettier


I would like to format MDX using prettier.

It's working on the playground, but I'm having trouble to get it running programmatically. In my code i get an unchanged result (no error, but not formatted)

Here is what i am doing:

import prettier from "prettier/esm/standalone.mjs";
const markdownParser = require("prettier/parser-markdown");

var formatted = prettier.format(content, {
  parser: "mdx",
  plugins: [markdownParser],
});

The following works on the playground, but NOT with my current code.

# Hello World

<div    class="test" >
  Hello
  </div>

Solution

  • The problem was that i also had to add the parser for babel.

    prettier/parser-babel