diff --git a/js/src/css/beautifier.js b/js/src/css/beautifier.js index 7c2b4e81..04a33008 100644 --- a/js/src/css/beautifier.js +++ b/js/src/css/beautifier.js @@ -392,22 +392,31 @@ Beautifier.prototype.beautify = function() { if (this._input.lookBack("url")) { this.print_string(this._ch); this.eatWhitespace(); + parenLevel++; + this.indent(); this._ch = this._input.next(); if (this._ch === ')' || this._ch === '"' || this._ch === '\'') { this._input.back(); - parenLevel++; } else if (this._ch) { this.print_string(this._ch + this.eatString(')')); + if (parenLevel) { + parenLevel--; + this.outdent(); + } } } else { - parenLevel++; this.preserveSingleSpace(isAfterSpace); this.print_string(this._ch); this.eatWhitespace(); + parenLevel++; + this.indent(); } } else if (this._ch === ')') { + if (parenLevel) { + parenLevel--; + this.outdent(); + } this.print_string(this._ch); - parenLevel = Math.max(parenLevel - 1, 0); } else if (this._ch === ',') { this.print_string(this._ch); this.eatWhitespace(true); diff --git a/js/test/generated/beautify-css-tests.js b/js/test/generated/beautify-css-tests.js index 8a71463b..a4f7e8df 100644 --- a/js/test/generated/beautify-css-tests.js +++ b/js/test/generated/beautify-css-tests.js @@ -10494,8 +10494,8 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea '}\n' + '.set {\n' + ' each(@set, {\n' + - ' @{key}-@{index}: @value;\n' + - ' }\n' + + ' @{key}-@{index}: @value;\n' + + ' }\n' + ' );\n' + '}'); t('@light-blue: @nice-blue + #111;'); diff --git a/python/cssbeautifier/css/beautifier.py b/python/cssbeautifier/css/beautifier.py index d4955d8e..8a27317c 100644 --- a/python/cssbeautifier/css/beautifier.py +++ b/python/cssbeautifier/css/beautifier.py @@ -413,20 +413,27 @@ class Beautifier: if self._input.lookBack("url"): self.print_string(self._ch) self.eatWhitespace() + parenLevel += 1 + self.indent() self._ch = self._input.next() if self._ch in {')', '"', '\''}: self._input.back() - parenLevel += 1 elif self._ch is not None: self.print_string(self._ch + self.eatString(')')) + if parenLevel: + parenLevel -= 1 + self.outdent() else: - parenLevel += 1 self.preserveSingleSpace(isAfterSpace) self.print_string(self._ch) self.eatWhitespace() + parenLevel += 1 + self.indent() elif self._ch == ')': + if parenLevel: + parenLevel -= 1 + self.outdent() self.print_string(self._ch) - parenLevel = max(parenLevel - 1, 0) elif self._ch == ',': self.print_string(self._ch) self.eatWhitespace(True) diff --git a/python/cssbeautifier/tests/generated/tests.py b/python/cssbeautifier/tests/generated/tests.py index 792ba8d5..918b03b2 100644 --- a/python/cssbeautifier/tests/generated/tests.py +++ b/python/cssbeautifier/tests/generated/tests.py @@ -10379,8 +10379,8 @@ class CSSBeautifierTest(unittest.TestCase): '}\n' + '.set {\n' + ' each(@set, {\n' + - ' @{key}-@{index}: @value;\n' + - ' }\n' + + ' @{key}-@{index}: @value;\n' + + ' }\n' + ' );\n' + '}') t('@light-blue: @nice-blue + #111;') diff --git a/test/data/css/tests.js b/test/data/css/tests.js index f7d1802a..57f3cb72 100644 --- a/test/data/css/tests.js +++ b/test/data/css/tests.js @@ -1297,9 +1297,8 @@ exports.test_data = { '}', '.set {', ' each(@set, {', - ' @{key}-@{index}: @value;', - ' }', - // This is not optimal formatting, included to document current behavior. + ' @{key}-@{index}: @value;', + ' }', ' );', '}' ]