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

Fix Issue #339 #354

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 13 additions & 2 deletions python/cssbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ def closeBracket(self):
self.output.append("}")
self.newLine()

def at(self):
self.output.append("@")

def colon(self):
self.output.append(":")
self.singleSpace()

def semicolon(self):
self.output.append(";")
Expand Down Expand Up @@ -208,6 +210,7 @@ def beautify(self):
printer = Printer(self.indentChar, self.indentSize, indentString)

insideRule = False
ignoreOpenBracket = False
while True:
isAfterSpace = self.skipWhitespace()

Expand All @@ -219,7 +222,14 @@ def beautify(self):
header = self.lookBack("")
if header:
printer.push("\n\n")
elif self.ch == "@":
printer.at();
ignoreOpenBracket = True
elif self.ch == '{':
if ignoreOpenBracket:
ignoreOpenBracket = False
else:
insideRule = True
self.eatWhitespace()
if self.peek() == '}':
self.next()
Expand All @@ -234,7 +244,8 @@ def beautify(self):
elif self.ch == ":":
self.eatWhitespace()
printer.colon()
insideRule = True
if insideRule:
printer.singleSpace()
elif self.ch == '"' or self.ch == '\'':
printer.push(self.eatString(self.ch))
elif self.ch == ';':
Expand Down
2 changes: 1 addition & 1 deletion python/cssbeautifier/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.0.1'
6 changes: 6 additions & 0 deletions python/cssbeautifier/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def testSeperateSelectors(self):
t("#bla, #foo{color:red}", "#bla,\n#foo {\n\tcolor: red\n}\n")
t("a, img {padding: 0.2px}", "a,\nimg {\n\tpadding: 0.2px\n}\n")

def testPseudeoselectors(self):
self.resetOptions()
t = self.decodesto

t("a:hover{color:red}", "a:hover {\n\tcolor: red\n}\n")
t(".test:after{content:\"after\"}", ".test:after {\n\tcontent: \"after\"\n}\n")

def testOptions(self):
self.resetOptions()
Expand Down