Js-beautify: Add an option to strip empty lines

Created on 12 Jul 2013  ·  6Comments  ·  Source: beautify-web/js-beautify

It would be useful if JS Beautify had an option to strip empty lines.

Includes, partials and other serverside code can create blank lines in the HTML. The HTML would be more beautiful without these blank lines.

This used to be the behaviour in version 1.3.1 but I think it was changed for https://github.com/einars/js-beautify/issues/285.

Input:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Demo</title>
</head>
<body>
    <p>P1</p>

    <p>P2</p>

</body>
</html>

_(Note: the line after P1 should contain some spaces and tabs but GitHub Flavored Markdown is removing them. This line should still be removed by JS Beautify.)_

Configuration:

js-beautify input.html -o output.html --remove-empty-lines

Expected output:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Demo</title>
</head>
<body>
    <p>P1</p>
    <p>P2</p>
</body>
</html>

Actual output:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>Demo</title>
</head>

<body>
    <p>P1</p>

    <p>P2</p>

</body>

</html>


html bug

Most helpful comment

Hi, can you add same option for css?

All 6 comments

Excellent report, thank you. Have you tried using the option --no-preserve-newlines? I know that isn't the same, but it might be close enough for a work-around in the short-term.

:+1: @keeganstreet's point. Most changes in 1.4.0 were great, but it would be nice to have any option to strip all blank lines. IMO, it would make the most sense for max_preserve_newline to respect 0 as a value, but it doesn't seem to.

Yeah, I see your point. Until we get to fixing this, have you tried 1 instead of 0?
Does that exhibit the behavior you want?

Hi, can you add same option for css?

Please add the same functionality to css :-)

@Migacz85 Have you tried this? I think it is already there. You'll also need to set "newline-between-rules": false. Please open a new issue for css if this doesn't work.

Was this page helpful?
0 / 5 - 0 ratings