UNPKG

1.74 kBMarkdownView Raw
1# html prettyprinter
2
3A node port of beautify-html.js by Nochum Sossonko which is based on jsbeautifier by Einar Lielmanis
4
5## Installation
6
7### from npm (node package manager)
8``` bash
9 npm install html
10```
11
12## Usage (command line)
13
14```
15 echo "<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>" | html
16```
17
18returns:
19
20``` html
21 <h2>
22 <strong>
23 <a href=http://awesome.com>AwesomeCom</a>
24 </strong>
25 <span>
26 is awesome
27 </span>
28 </h2>
29````
30
31`html foo.html` will write the prettified version to `stdout`.
32
33`html *.html` will *update in place* all matching html files with their prettified versions.
34
35## Advanced usage
36
37I find myself constantly using the 'Copy as HTML' feature of the Chrome Inspector:
38
39![Copy as HTML](https://github.com/maxogden/commonjs-html-prettyprinter/raw/master/img/copyashtml.png)
40
41The downside is that that usually the HTML that gets copied is pretty ugly:
42
43![Before pretty printing](https://github.com/maxogden/commonjs-html-prettyprinter/raw/master/img/before.png)
44
45On OS X you can use `pbpaste` and `pbcopy` to stream your clipboard in and out of unix pipes. With the ugly HTML still in your clipboard run this command:
46
47`pbpaste | html | pbcopy`
48
49Now when you paste your clipboard into an editor you will get nice, pretty printed HTML:
50
51![After pretty printing](https://github.com/maxogden/commonjs-html-prettyprinter/raw/master/img/after.png)
52
53## Upgrading
54
55grab the newest `beautify-html.js` from [js-beautifier](https://github.com/einars/js-beautify) and drop it into `lib/` as `html.js`. then add the following code to the bottom of `html.js`:
56
57```javascript
58 module.exports = { prettyPrint: style_html }
59```
60
61BSD LICENSE
\No newline at end of file