An open API service indexing awesome lists of open source software.

https://github.com/posthtml/posthtml-tidy

Tidy Plugin
https://github.com/posthtml/posthtml-tidy

Last synced: 10 months ago
JSON representation

Tidy Plugin

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

```