-
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
Add expand brace-style option to css beautifier #1796
Conversation
1d2f12d
to
f682354
Compare
} | ||
if (this._options.newline_between_rules && insideRule) { | ||
if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') { | ||
this._output.ensure_empty_line_above('/', ','); | ||
} | ||
} | ||
|
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.
moved this section below to prevent ( when using newline_between_rules
)
.a{} .b{}
-->
.a
/* there shouldn't be an empty line here */
{}
.b
/* there shouldn't be an empty line here */
{}
On the other hand the branching is to indent the {
correctly
README.md
Outdated
@@ -323,6 +323,7 @@ CSS Beautifier Options: | |||
-e, --eol Character(s) to use as line terminators. (default newline - "\\n") | |||
-n, --end-with-newline End output with newline | |||
-L, --selector-separator-newline Add a newline between multiple selectors | |||
-C, --curly-start-newline Add a newline before the opening { bracket of selector(s) |
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.
What do you think of reusing the brace-style
setting instead of create a new field specific to the css beautifier?
I ask because the formatting curly-start-newline
creates is the same as brace-style=expand
. The default behavior matches brace-style=collapse
(or end-expand
but these are the same in css.)
Don't change anything yet, I'd like to discuss and see if what I'm thinking makes sense to you.
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 looking at this!
Think it would be more consistent to use brace-style
as well (I missed it out before).
Perhaps a trimmed set of options like [collapse|expand|none]
, since as you mentioned end-expand
dosen't make sense in css. I'm not too sure if preserve-inline
makes sense though. (adding css to a minified file while preserving the minified styles maybe?)
I could expand the scope of this to include support for these if needed, or in separate PRs. Let me know what you think!
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.
@ang-zeyu
I think it would be fine to start with support for just collapse
and expand
(and treat end-expand
and none
the same as collapse
). Then you could open an issue to add support for preserve-inline
and none
and someone (or you) can do that at a later date in another PR.
That will get this cool new feature out for people to use with minimal added work for you now. Sound good?
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.
Yup! will update this with brace-style=[collapse|expand]
as a start then
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.
This is a great start!
34f2dcc
to
ed044c4
Compare
ready for another look @bitwiseman I noticed |
@ang-zeyu |
input: 'a:first-child,a:first-child{color:red;div:first-child,div:hover{color:black;}}\na:first-child,a:first-child{color:red;div:first-child,div:hover{color:black;}}', | ||
output: 'a:first-child,{{separator}}a:first-child {\n color: red;{{new_rule}}\n div:first-child,{{separator1}}div:hover {\n color: black;\n }\n}\n{{new_rule}}a:first-child,{{separator}}a:first-child {\n color: red;{{new_rule}}\n div:first-child,{{separator1}}div:hover {\n color: black;\n }\n}' |
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.
Excellent, thanks for cleaning up this formatting.
js/src/css/options.js
Outdated
@@ -38,6 +38,11 @@ function Options(options) { | |||
var space_around_selector_separator = this._get_boolean('space_around_selector_separator'); | |||
this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator; | |||
|
|||
var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand']); |
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.
You'll need to accept the other values that are allowed by the javascript options, otherwise you'll get an error if someone passes them (via inheriting the option). You can ignore or convert them loop below.
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.
👍 done. Linked two more related issues as well
the below commit reverts the jsbeautifyrc
override
ed044c4
to
de50dc9
Compare
de50dc9
to
5cb5390
Compare
this.brace_style = 'collapse'; | ||
for (var bs = 0; bs < brace_style_split.length; bs++) { | ||
if (brace_style_split[bs] !== 'expand') { | ||
// default to collapse, as only collapse|expand is implemented for now |
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.
Perfect.
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.
Sorry about the wait. Looks good.
Description
master
)Fixes Issue: #1776 ( adding a newline before the opening curly brace of selector(s) )
#1353
#1259 (partially, till the other options are implemented)
Name of the new option:curly-start-newline
Shorthand:-R
for thecur
incurly
Added
brace-style=expand
to the css beautifierBefore Merge Checklist
These items can be completed after PR is created.
(Check any items that are not applicable (NA) for this PR)