posthtml-spaceless
Version:
A posthtml plugin remove whitespace between HTML tags
70 lines (54 loc) • 2.67 kB
Markdown
# posthtml-spaceless
> A [posthtml](https://github.com/posthtml) plugin remove whitespace between HTML tags
[](https://travis-ci.org/GitScrum/posthtml-spaceless)[](https://ci.appveyor.com/project/GitScrum/posthtml-spaceless)[]()[](https://www.npmjs.com/package/posthtml-spaceless)[](https://david-dm.org/GitScrum/posthtml-spaceless)[](https://github.com/sindresorhus/xo)[](https://coveralls.io/r/GitScrum/posthtml-spaceless)
[](https://www.npmjs.com/package/posthtml-spaceless)[](https://www.npmjs.com/package/posthtml-spaceless)
## Why?
This tag is based on and compatible with the [Twig `spaceless` tag](http://twig.sensiolabs.org/doc/tags/spaceless.html), [Swig `spaceless` tag](https://voorhoede.github.io/swig/docs/tags/#spaceless) and [Django `spaceless` tag](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#spaceless).
## Install
```bash
npm i -D posthtml posthtml-spaceless
```
> **Note:** This project is compatible with node v4+
## Usage
```js
import {readFileSync, writeFileSync} from 'fs';
import posthtml from 'posthtml';
import spaceless from 'posthtml-spaceless';
const html = readFileSync('input.html', 'utf8');
posthtml()
.use(spaceless())
.process(html)
.then(result => {
writeFileSync('output.html', result.html);
});
```
*Returns the html without whitespace between tags*
## Example
#### input.html
```html
<!DOCTYPE html>
<html>
<head></head>
<body>
<h2>Header</h2>
<spaceless>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</spaceless>
</body>
</html>
```
#### output.html
```html
<!DOCTYPE html>
<html>
<head></head>
<body>
<h2>Header</h2>
<ul><li>one</li><li>two</li><li>three</li></ul>
</body>
</html>
```