Keeping New lines #96

wisec opened this Issue Feb 14, 2012 · 13 comments


None yet

7 participants


Would it be possible to keep original newlines by simply adding:
to beautify options?

By modifying n_newlines condition it's "probably" easy to preserve the nl.
What do you think?

--- beautify.js 2012-02-14 15:37:23.000000000 +0100
+++ beautify.js 2012-02-14 15:55:37.000000000 +0100
@@ -345,7 +345,7 @@ function js_beautify(js_source_text, opt

             if (opt_preserve_newlines) {
-                if (n_newlines > 1) {
+                if (n_newlines > 0) {
                     for (i = 0; i < n_newlines; i += 1) {
                         print_newline(i === 0);
                         just_added_newline = true;

Of course if the patch is wrong i'd like to understand why.



Hmm, what would be achieved by keeping the newlines? This would effectively forbid the beautifier to make any meaningful changes, as e.g

var a =

would not be restored to any beautiful form. The preserve_newlines options were implemented to keep the blank lines between the blocks of code intact, but I don't see the use in preserving all existing nl's, but please correct me if i'm wrong, maybe I misunderstood something.


broadly speaking I'd agree, but if you consider unfixed issues like:

which become:

or similar, I'd say this feature is worth exposing..unless it breaks something else of course :)

That way you wouldn't break original newlines (and original js) but you would still beautify it.

Looking forward to your reply


I mean, newlines are definitely metachars as well, so unless there's the chance to be perfect in js sintax, I'd prefer to have the option to be conservative on newlines.
I'm not saying to be always like that, just to have an option to be like that :)


+1 on this

usually while typing i have newlines the way i want but some spaces are missing
it would be nice if editor could do this

var a=1

var a = 1
if (a == 1)
    b += x

Yes, now I see the point in that.


Is this already implemented in the python version? It would be cool if


wouldnt be converted to

if(true) bar();

Some of my colleagues dislike it when I use jsbeautifier, for the above reason. :(


@hickop +1 :)


This is at least partially addressed by my recent changes to newline preservation.

But I see where you're headed with this - having an option where there would still be some formatting but newlines always kept.


I'm going to close this. If the new behavior is insufficient, please reopen.

@bitwiseman bitwiseman closed this May 26, 2013

I know this issue was created with js in mind, but it would be great to have a fix for HTML as well.


Please file a new issue.

@bitwiseman bitwiseman reopened this Jun 5, 2013
@bitwiseman bitwiseman closed this Jun 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment