commonjs-html-prettyprinter icon indicating copy to clipboard operation
commonjs-html-prettyprinter copied to clipboard

html.prettyPrint does not do any indenting or line-breaking (Node 6.1.0)

Open dannguyen opened this issue 8 years ago • 3 comments

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.

dannguyen avatar Jun 22 '16 02:06 dannguyen

+1 for the command-line example in the README not working as expected.

j-gao avatar Nov 16 '16 19:11 j-gao

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>';

tosbatti avatar Oct 12 '17 07:10 tosbatti

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.

robert8888 avatar Apr 10 '24 11:04 robert8888