posthtml-tidy

0.8.0 • Public • Published

HTML Tidy for PostHTML

HTML Tidy corrects and cleans up HTML and XML documents by fixing markup errors and upgrading legacy code to modern standards.

Install

(sudo) npm i -D posthtml-tidy

Usage

Options

log [Boolean]

Boolean option which logs tidied html to the console. By default no output is logged.

rules [Object]

If no rules set, tidy will use it's default setup. For rules take a look at the Quick Reference. Multi-word rules separated with a hyphen should be used with camelCase.

const tidy = require('posthtml-tidy')({
  log: true,
  rules: {
    doctype: 'omit',
    hideComments: true,
    dropEmptyElements: true
    // more options...
  }
})

Input

<!DOCTYPE html>
<html>
 
<head>
  <meta charset="utf-8">
  <title>PostHTML Tidy</title>
</head>
 
<body>
  <!-- Bad format -->
  <h1>Well formatted</h1>
  <h1>Bad formatted</h4>
  <h6>Even worse formatted</h1
 
  <div></div>
</body>
 
</html>

Output

<html>
<head>
 
<meta charset="utf-8">
<title>PostHTML Tidy</title>
 
</head>
 
<body>
 
<h1>Well formatted</h1>
<h1>Bad formatted</h1>
<h6>Even worse formatted</h6>
 
</body>
</html>

Example using Node API

For general usage and build process integration see PostHTML Docs

const fs = require('fs')
 
const posthtml = require('posthtml')
 
const tidy = require('posthtml-tidy')(/* options */)
 
let html = fs.readFileSync('./index.html', 'utf8')
 
posthtml([ tidy ])
  .process(html)
  .then(result => console.log(result.html))

Input

<h1>Well formatted</h1>
<h1>Bad formatted</h4>
<h6>Even worser formatted</h1

Output

<h1>Well formatted</h1>
<h1>Bad formatted</h1>
<h6>Even worser formatted</h6>

Readme

Keywords

none

Package Sidebar

Install

npm i posthtml-tidy

Weekly Downloads

177

Version

0.8.0

License

MIT

Last publish

Collaborators

  • cossssmin
  • scrum
  • voischev
  • michael-ciniawsky