package
HTML Tidy for PostHTML
npm install posthtml-tidyGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Registry package owners.
HTML Tidy corrects and cleans up HTML and XML documents by fixing markup errors and upgrading legacy code to modern standards.
(sudo) npm i -D posthtml-tidyBoolean option which logs tidied html to the console. By default no output is logged.
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...
}
})<!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>
<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>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))<h1>Well formatted</h1>
<h1>Bad formatted</h4>
<h6>Even worser formatted</h1<h1>Well formatted</h1>
<h1>Bad formatted</h1>
<h6>Even worser formatted</h6>Estimated unpacked size across 5 packages.
3.9 MB
Includes dependencies.
3 direct · 3 outdated