-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added option max_preserve_newlines in CSS beautifier #1867
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing.
Take a look at my suggestion and see if they seem right to you.
js/src/css/beautifier.js
Outdated
@@ -92,11 +92,15 @@ Beautifier.prototype.eatString = function(endChars) { | |||
Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) { | |||
var result = whitespaceChar.test(this._input.peek()); | |||
var isFirstNewLine = true; | |||
|
|||
var newlines = this._options.max_preserve_newlines; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete var isFirstNewLine = true;
and then
var newlines = this._options.max_preserve_newlines; | |
var newline_count = 0; |
js/src/css/beautifier.js
Outdated
if ((this._options.preserve_newlines || isFirstNewLine) && (this._options.max_preserve_newlines === 32786 || this._options.max_preserve_newlines === 0)) { | ||
isFirstNewLine = false; | ||
this._output.add_new_line(true); | ||
} else if ((this._options.preserve_newlines || isFirstNewLine) && newlines > 0) { | ||
newlines--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_preserve_newlines is already sanitized by the options object:
if ((this._options.preserve_newlines || isFirstNewLine) && (this._options.max_preserve_newlines === 32786 || this._options.max_preserve_newlines === 0)) { | |
isFirstNewLine = false; | |
this._output.add_new_line(true); | |
} else if ((this._options.preserve_newlines || isFirstNewLine) && newlines > 0) { | |
newlines--; | |
if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) { | |
newline_count++; |
Also delete isFirstNewLine = false;
below.
And implement same in python, of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I liked this way better, is way cleaner, thank you!
dbc7542
to
fba76bd
Compare
I think I already fix it, although I don't know how I can erase the commits at the top, but I could also close this and open a new one. |
Description
Added option max_preserve_newlines to CSS beautifier, as well tests with more lines, less lines and the same as the ones requested in the option.
master
)Fixes #1863:
Before Merge Checklist
These items can be completed after PR is created.
(Check any items that are not applicable (NA) for this PR)