Skip to content
Open
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
12 changes: 12 additions & 0 deletions js/src/css/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ Beautifier.prototype.beautify = function() {
} else {
this._output.space_before_token = true;
}
} else if ((this._ch === '>' || this._ch === '<') && parenLevel > 0 && this._input.peek() === '=') {
// Media query range operator: >= or <=
// Ensure a single space before and after the operator
this._output.space_before_token = true;
this.print_string(this._ch);
this._input.next(); // consume '='
this.print_string('=');
this.eatWhitespace();
this._output.space_before_token = true;
if (whitespaceChar.test(this._ch)) {
this._ch = '';
}
} else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
//handle combinator spacing
if (this._options.space_around_combinator) {
Expand Down
15 changes: 15 additions & 0 deletions python/cssbeautifier/css/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,21 @@ def beautify(self):
self._output.add_new_line()
else:
self._output.space_before_token = True
elif (
(self._ch == ">" or self._ch == "<")
and parenLevel > 0
and self._input.peek() == "="
):
# Media query range operator: >= or <=
# Ensure a single space before and after the operator
self._output.space_before_token = True
self.print_string(self._ch)
self._input.next() # consume '='
self.print_string("=")
self.eatWhitespace()
self._output.space_before_token = True
if bool(whitespaceChar.search(self._ch)):
self._ch = ""
elif (
(self._ch == ">" or self._ch == "+" or self._ch == "~")
and not insidePropertyValue
Expand Down
18 changes: 18 additions & 0 deletions test/data/css/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,24 @@ exports.test_data = {
input: '@media print {.tab{}}',
output: '@media print{{curly_separator}}{\n .tab{{curly_separator2}}{}\n}'
},
{
comment: 'Media query range operators should preserve spaces on both sides',
unchanged: '@media (width >= 90rem) {\n .foo {}\n}'
},
{
comment: 'Media query range operators should preserve spaces on both sides',
unchanged: '@media (width <= 90rem) {\n .foo {}\n}'
},
{
comment: 'Media query range operators - minified input should have spaces enforced around operator',
input: '@media (width>=90rem){.foo{}}',
output: '@media (width >= 90rem){{curly_separator}}{\n .foo{{curly_separator2}}{}\n}'
},
{
comment: 'Media query range operators - minified input should have spaces enforced around operator',
input: '@media (width<=90rem){.foo{}}',
output: '@media (width <= 90rem){{curly_separator}}{\n .foo{{curly_separator2}}{}\n}'
},
{
comment: 'This is bug #1489',
input: '@media print {.tab,.bat{}}',
Expand Down
Loading