A unified plugin to format output using Prettier
npm install unified-prettier



A unified plugin to format output using Prettier.
- Installation
- Usage
- API
- Options
- Related projects
- Compatibility
- Acknowledgements
- License
``sh`
npm install unified-prettier
This unified plugin takes content from another compiler, and reformats the output using Prettier.
It’s intended to work with
unified-engine implementations,
such as remark-cli and
rehype-cli.
In your
configuration file, add
unified-prettier to the plugins:
`json`
{
"plugins": ["unified-prettier"]
}
It can also be used programmatically. Although you’re probably better off passing the output value
to Prettier directly.
The following example formats the readme using Prettier.
`js
import { remark } from 'remark'
import { read } from 'to-vfile'
import unifiedPrettier from 'unified-prettier'
const processor = remark.use(unifiedPrettier)
const file = await read('README.md')
const { value } = await processor.process(file)
console.log(value)
`
The following package formats the readme using Prettier after updating the table of contents.
`js
import { remark } from 'remark'
import remarkToc from 'remark-toc'
import { read } from 'to-vfile'
import unifiedPrettier from 'unified-prettier'
const processor = remark.use(remarkToc).use(unifiedPrettier)
const file = await read('README.md')
const { value } = await processor.process(file)
console.log(value)
`
The default export is a unified plugin.
This plugin accepts Prettier options. By default it uses
the options from the Prettier configuration file.
- prettier is an opiniated code formatter.
- unified is a tool that transforms content with plugins.
- unified-consistency` can be used to report
output inconsistencies.
This project is compatible with Node.js 16 or greater, Prettier 3, and unified 11.
Thanks to @JounQin for giving me the npm package name.