Skip to content

Commit

Permalink
Merge pull request #2064 from bitwiseman/issue/2051
Browse files Browse the repository at this point in the history
Fix two spacing issue in CSS
  • Loading branch information
bitwiseman committed Jun 20, 2022
2 parents ba2236a + 19e9521 commit 145ffa0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 3 additions & 2 deletions js/src/css/beautifier.js
Expand Up @@ -400,7 +400,8 @@ Beautifier.prototype.beautify = function() {
}
}
} else if (this._ch === '"' || this._ch === '\'') {
this.preserveSingleSpace(isAfterSpace);
var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
this.print_string(this._ch + this.eatString(this._ch));
this.eatWhitespace(true);
} else if (this._ch === ';') {
Expand Down Expand Up @@ -507,7 +508,7 @@ Beautifier.prototype.beautify = function() {
this._ch = '';
}
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
this.print_string(' ');
this._output.space_before_token = true;
this.print_string(this._ch);
} else {
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
Expand Down
5 changes: 3 additions & 2 deletions python/cssbeautifier/css/beautifier.py
Expand Up @@ -422,7 +422,8 @@ def beautify(self):
# pseudo-element
self.print_string(":")
elif self._ch == '"' or self._ch == "'":
self.preserveSingleSpace(isAfterSpace)
preserveQuoteSpace = previous_ch == '"' or previous_ch == "'"
self.preserveSingleSpace(preserveQuoteSpace or isAfterSpace)
self.print_string(self._ch + self.eatString(self._ch))
self.eatWhitespace(True)
elif self._ch == ";":
Expand Down Expand Up @@ -537,7 +538,7 @@ def beautify(self):
self._ch = ""
elif self._ch == "!" and not (self._input.lookBack("\\")):
# !important
self.print_string(" ")
self._output.space_before_token = True
self.print_string(self._ch)
else:
preserveAfterSpace = previous_ch == '"' or previous_ch == "'"
Expand Down
25 changes: 25 additions & 0 deletions test/data/css/tests.js
Expand Up @@ -1502,6 +1502,31 @@ exports.test_data = {
' filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);',
'}'
]
}, {
comment: "#2056 - Extra space before !important added",
unchanged: [
'.x {',
' $d: a !default;',
'}'
]
}, {
unchanged: [
'.x {',
' $d: a !default;',
' @if $x !=0 {',
' color: $var !important;',
' }',
'}'
]
}, {
comment: "#2051 - css format removes space after quoted value",
unchanged: [
'q {',
' quotes: \\\'"\\\' \\\'"\\\' "\\\'" "\\\'";',
' quotes: "some" \\\'thing\\\' "different";',
' quotes: \\\'some\\\' "thing" \\\'different\\\';',
'}'
]
}]
}, {
name: "Regression tests - with default options",
Expand Down

0 comments on commit 145ffa0

Please sign in to comment.