Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enforce line length and other formatting rules in MDX?

I would love if there was a way to use the VS Code formatter or prettier to enforce rules like max line length for MDX files. It would make writing blog posts in MDX so much nicer. Does anyone have any methods for doing that?

The project I'm currently trying to do this on is a basic gatsby with mdx setup. It has eslint and prettier.

like image 306
itwasmattgregg Avatar asked Sep 18 '25 15:09

itwasmattgregg


1 Answers

You'll need to provide the "Prose Wrap" option to prettier. I hoped it would be enabled by default, however that's not the case because some services use a linebreak-sensitive renderer.

CLI: prettier --prose-wrap always

In config: proseWrap: "always"

https://prettier.io/docs/en/options.html#prose-wrap

like image 122
Rohmer Avatar answered Sep 23 '25 13:09

Rohmer