Skip to content

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

Open

Description

@dannguyen

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.

Activity

  1. j-gao commented on Nov 16, 2016

    @j-gao

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

  2. tosbatti commented on Oct 12, 2017

    @tosbatti

    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>';
  3. robert8888 commented on Apr 10, 2024

    @robert8888

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions