commonjs-html-prettyprinter
commonjs-html-prettyprinter copied to clipboard
html.prettyPrint does not do any indenting or line-breaking (Node 6.1.0)
System specs:
- Node: 6.1.0
- OSX: 10.11.5
I haven't had any luck with this:
var html = require('html');
var txt = '<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>';
html.prettyPrint(txt, {indent_size: 2});
// result
'<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>'
So I tried the command-line example in the README but got the same, unformatted text.
+1 for the command-line example in the README not working as expected.
I had the same problem and I went crazy to understand what I was doing wrong...
It works, it's just a wrong example in the readme file.
Try with this input to see it works:
var txt = '<ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul>';
To format example from read.me we need to clear unformated
array
line: https://github.com/max-mapper/commonjs-html-prettyprinter/blob/master/lib/html.js#L54
var html = require('html');
var txt = '<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>';
html.prettyPrint(txt, {unformatted: []});
this will force formatting for all html tags.