Socket
Socket
Sign inDemoInstall

rehype-format

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-format

Format HTML with rehype


Version published
Weekly downloads
96K
increased by5.69%
Maintainers
1
Weekly downloads
 
Created
Source

rehype-format Build Status Coverage Status

Format HTML with rehype.

Installation

npm:

npm install rehype-format

Usage

Say we have the following file, index.html:

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

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

var vfile = require('to-vfile');
var report = require('vfile-reporter');
var rehype = require('rehype');
var format = require('rehype-format');

rehype().use(format).process(vfile.readSync('index.html'), function (err, file) {
  console.error(report(err || file));
  console.log(String(file));
});

Now, running node example yields:

index.html: no issues found
<!DOCTYPE html>
<html>
  <head>
    <title>Hello!</title>
    <meta charset="utf8">
  </head>
  <body>
    <section>
      <p>hi there</p>
    </section>
  </body>
</html>

API

rehype().use(format[, options])

Format white-space in the processed tree.

  • Collapse all white-space (to a single space or newline);
  • Remove unneeded white-space;
  • Inject needed newlines and indentation;
  • Indent previously collapsed newlines properly.

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

options
  • indent (number, string, default: 2) — Indentation per level. When number, uses that amount of spaces. When string, uses that per indentation level.
  • indentInitial (boolean, default: true) — Whether to indent the first level (usually, in the html element, thus not indenting head and body).
  • blanks (Array.<string>, default: []) — List of tag-names, which, 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.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 22 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc