Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to strip empty lines #307

Closed
keeganstreet opened this issue Jul 12, 2013 · 6 comments
Closed

Add an option to strip empty lines #307

keeganstreet opened this issue Jul 12, 2013 · 6 comments

Comments

@keeganstreet
Copy link

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 #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>
@bitwiseman
Copy link
Member

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.

@jonschlinkert
Copy link
Contributor

👍 @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.

@bitwiseman
Copy link
Member

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?

johvik added a commit to johvik/js-beautify that referenced this issue Dec 30, 2013
For preserve_newlines and max_preserve_newlines false or 0 isn't accepted as configuration. This PR allows both those scenarios.
@bitwiseman bitwiseman added this to the v1.5.0 milestone Apr 25, 2014
@maciej-zuk
Copy link

Hi, can you add same option for css?

@Migacz85
Copy link

Please add the same functionality to css :-)

@bitwiseman
Copy link
Member

@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.

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

No branches or pull requests

5 participants