https://github.com/posthtml/posthtml-tidy
Tidy Plugin
https://github.com/posthtml/posthtml-tidy
Last synced: 10 months ago
JSON representation
Tidy Plugin
- Host: GitHub
- URL: https://github.com/posthtml/posthtml-tidy
- Owner: posthtml
- License: mit
- Created: 2016-02-27T04:37:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-10T17:41:52.000Z (about 9 years ago)
- Last Synced: 2024-10-29T21:06:08.250Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 9
- Watchers: 5
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTML Tidy for PostHTML
[HTML Tidy](http://html-tidy.org) corrects and cleans up HTML and XML documents by fixing markup errors and upgrading legacy code to modern standards.
## Install
```bash
(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](http://api.html-tidy.org/tidy/quickref_5.1.25.html).
Multi-word rules separated with a hyphen should be used with camelCase.
```js
const tidy = require('posthtml-tidy')({
log: true,
rules: {
doctype: 'omit',
hideComments: true,
dropEmptyElements: true
// more options...
}
})
```
#### Input
```html
PostHTML Tidy
Well formatted
Bad formatted
Even worse formatted
```
#### Output
```html
PostHTML Tidy
Well formatted
Bad formatted
Even worse formatted
```
### Example using Node API
For general usage and build process integration see [PostHTML Docs](https://github.com/posthtml/posthtml#usage)
```js
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
```html
Well formatted
Bad formatted
Even worser formatted
Well formatted
Bad formatted
Even worser formatted
```