Skip to content

Commit

Permalink
Port 2fe8c3d (Issue beautifier#339) to JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
bthorben committed Nov 10, 2013
1 parent 2fe8c3d commit 93fd82b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions js/lib/beautify-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
/*_____________________--------------------_____________________*/

var insideRule = false;
var ignoreOpenBracket = false;
while (true) {
var isAfterSpace = skipWhitespace();

Expand All @@ -207,7 +208,15 @@
if (header) {
print.newLine();
}
} else if (ch === "@") {
output.push("@");
ignoreOpenBracket = true;
} else if (ch === '{') {
if (ignoreOpenBracket) {
ignoreOpenBracket = false;
} else {
insideRule = true;
}
eatWhitespace();
if (peek() == '}') {
next();
Expand All @@ -222,8 +231,10 @@
insideRule = false;
} else if (ch === ":") {
eatWhitespace();
output.push(ch, " ");
insideRule = true;
output.push(ch);
if (insideRule) {
print.singleSpace();
}
} else if (ch === '"' || ch === '\'') {
output.push(eatString(ch));
} else if (ch === ';') {
Expand Down
5 changes: 5 additions & 0 deletions js/test/beautify-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,11 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
btc("#bla, #foo{color:red}", "#bla,\n#foo {\n\tcolor: red\n}\n");
btc("a, img {padding: 0.2px}", "a,\nimg {\n\tpadding: 0.2px\n}\n");

// pseudoselectors
btc("a:hover{color:red}", "a:hover {\n\tcolor: red\n}\n");
btc(".test:after{content:\"after\"}", ".test:after {\n\tcontent: \"after\"\n}\n");


// test options
opts.indent_size = 2;
opts.indent_char = ' ';
Expand Down

0 comments on commit 93fd82b

Please sign in to comment.