2.0.1 • Published 10 months ago

unified-prettier v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

unified-prettier

github actions npm version npm downloads codecov

A unified plugin to format output using Prettier.

Table of Contents

Installation

npm install unified-prettier

Usage

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:

{
  "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.

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.

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)

API

The default export is a unified plugin.

Options

This plugin accepts Prettier options. By default it uses the options from the Prettier configuration file.

Related projects

Compatibility

This project is compatible with Node.js 16 or greater, Prettier 3, and unified 11.

Acknowledgements

Thanks to @JounQin for giving me the npm package name.

License

MIT © Remco Haszing