Project: rehypejs/rehype-format

Package: rehype-format@4.0.0

  1. Dependents: 51
  2. rehype plugin to format HTML
  1. unified 173
  2. plugin 137
  3. html 122
  4. rehype 87
  5. rehype-plugin 61
  6. format 3


Build Coverage Downloads Size Sponsors Backers Chat

rehype plugin to format HTML.


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install rehype-format


Say we have the following file, index.html:

<!doCTYPE HTML><html>
<meta charset=utf8>
  <body><section>    <p>hi there</p>

And our module, example.js, looks as follows:

import {readSync} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {rehype} from 'rehype'
import rehypeFormat from 'rehype-format'

const file = readSync('index.html')

  .then((file) => {

Now, running node example yields:

index.html: no issues found
<!doctype html>
    <meta charset="utf8">
      <p>hi there</p>


This package exports no identifiers. The default export is rehypeFormat.

unified().use(rehypeFormat[, options])

Format whitespace in the processed tree.

All superfluous white space is removed. However, as newlines are kept (and later properly indented), your code will still line-wrap as expected.


Indentation per level (number, string, default: 2). When number, uses that amount of spaces. When string, uses that per indentation level.


Whether to indent the first level (boolean, default: true). This is usually the <html>, thus not indenting head and body.


List of tag names to join with a blank line (Array.<string>, default: []). These tags, when next to each other, are joined by a blank line (\n\n). For example, when ['head', 'body'] is given, a blank line is added between these two.


Use of rehype-format changes white space in the syntax tree. White space in <script>, <style>, <pre>, or <textarea> is not modified. If the tree is already safe, use of this plugin does not open you up for a cross-site scripting (XSS) attack. When in doubt, use rehype-sanitize.


See contributing.md in rehypejs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer