Skip to content

Commit

Permalink
Move whitespace preserving split to `RuleSet#split_value_preserving_w…
Browse files Browse the repository at this point in the history
…hitespace`
  • Loading branch information
dark-panda committed Jul 26, 2021
1 parent 720eb34 commit 7fe280f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/css_parser/rule_set.rb
Expand Up @@ -359,9 +359,8 @@ def expand_dimensions_shorthand! # :nodoc:
#
# TODO: rgba, hsl, hsla
value.gsub!(RE_COLOUR) { |c| c.gsub(/(\s*,\s*)/, ',') }
value.gsub!(RE_FUNCTIONS) { |c| c.gsub(/\s+/, WHITESPACE_REPLACEMENT) }

matches = value.strip.split(/\s+/)
matches = split_value_preserving_whitespace(value)

case matches.length
when 1
Expand Down Expand Up @@ -640,6 +639,21 @@ def parse_selectors!(selectors) # :nodoc:
s
end
end

def split_value_preserving_whitespace(value)
split_value = value.gsub(RE_FUNCTIONS) do |c|
c.gsub!(/\s+/, WHITESPACE_REPLACEMENT)
c
end

matches = split_value.strip.split(/\s+/)

matches.each do |c|
c.gsub!(WHITESPACE_REPLACEMENT, ' ')
end

matches
end
end

class OffsetAwareRuleSet < RuleSet
Expand Down

0 comments on commit 7fe280f

Please sign in to comment.