lib/css_parser/parser.rb in css_parser-1.15.0 vs lib/css_parser/parser.rb in css_parser-1.16.0

- old
+ new

@@ -327,11 +327,11 @@ # once we are in a rule, we will use this to store where we started if we are capturing offsets rule_start = nil offset = nil - block.scan(/\s+|\\{2,}|\\?[{}\s"]|.[^\s"{}\\]*/) do |token| + block.scan(/\s+|\\{2,}|\\?[{}\s"]|[()]|.[^\s"{}()\\]*/) do |token| # save the regex offset so that we know where in the file we are offset = Regexp.last_match.offset(0) if options[:capture_offsets] if token.start_with?('"') # found un-escaped double quote in_string = !in_string @@ -389,10 +389,19 @@ current_media_query << token << ' ' current_media_queries << CssParser.sanitize_media_query(current_media_query) current_media_query = String.new else token.strip! - current_media_query << token << ' ' + # special-case the ( and ) tokens to remove inner-whitespace + # (eg we'd prefer '(width: 500px)' to '( width: 500px )' ) + case token + when '(' + current_media_query << token + when ')' + current_media_query.sub!(/ ?$/, token) + else + current_media_query << token << ' ' + end end elsif in_charset or token =~ /@charset/i # iterate until we are out of the charset declaration in_charset = !token.include?(';') elsif !in_string && token.include?('}')