remark-prettier v2.0.0
Remark Prettier
Check and format markdown using Prettier as a remark plugin
Installation
remark-prettier has a peer dependency on prettier
npm install prettier remark-prettierUsage
By default this plugin does 2 things:
- Report differences from the Prettier formatting.
- Format the document using Prettier.
It has support for Prettier configuration files: .editorconfig, .prettierrc*, and
.prettierignore.
For example, running remark --use remark-prettier . may yield:
README.md
18:30-19:1 warning Replace `⏎` with `·` replace prettier
38:1 warning Insert `⏎` insert prettier
40:32-41:1 warning Delete `⏎` delete prettierThis can also be spcified in a .remarkrc file:
{
"plugins": ["remark-prettier"]
}This plugin can also be used with programmatically:
import remark from 'remark';
import remarkPrettier from 'remark-prettier';
import { readSync } from 'to-vfile';
remark()
.use(remarkPrettier)
.process(readSync('README.md'))
.then(({ messages, value }) => {
// Formatted content
console.log(value);
// Prettier formatting violations
console.dir(messages);
});remark-prettier registers a unified compiler. This means this plugin is used for formatting the
document. Usually this is done by remark-stringify. When building a custom unified processor,
remark-stringify can be omitted. If multiple compilers are registered, the last one registered is
used.
import remarkParse from 'remark-parse';
import remarkPrettier from 'remark-prettier';
import { readSync } from 'to-vfile';
import unified from 'unified';
unified()
.use(remarkParse)
.use(remarkPrettier)
.process(readSync('README.md'))
.then(({ messages, value }) => {
// Formatted content
console.log(value);
// Prettier formatting violations
console.dir(messages);
});Options
The first argument may contain the options below. A second argument may specify overrides for the Prettier configuration, although this isn’t recommended.
format
By default remark-prettier registers a unified compiler, which formats the document using
Prettier. This behaviour can be disabled by setting this option to false. (Default true)
report
By default remark-prettier reports differences from document as Prettier would format it. This
behaviour can be disabled by setting this option to false. (Default true)