From e46b6cbe74db250d743e7f194bfc7514529a82cc Mon Sep 17 00:00:00 2001 From: murphy Date: Tue, 16 Sep 2008 22:07:44 +0000 Subject: New: *JavaScript Scanner* (closes #23). * It's quite good and fast, but still a beta. * I included Prototype and script.aculo.us as example code for testing. More changes: * Added two new token classes, :keyword and :key, along with CSS styles. ** Actually, we should use :keyword for most scanners that now use :reserved. * HTML Encoder: The CSS parser understands multiple selectors separated by commas. --- lib/coderay/encoders/html/css.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/coderay/encoders') diff --git a/lib/coderay/encoders/html/css.rb b/lib/coderay/encoders/html/css.rb index d577602..90d8cb1 100644 --- a/lib/coderay/encoders/html/css.rb +++ b/lib/coderay/encoders/html/css.rb @@ -34,9 +34,12 @@ module Encoders private CSS_CLASS_PATTERN = / - ( (?: # $1 = classes - \s* \. [-\w]+ - )+ ) + ( # $1 = selectors + (?: + (?: \s* \. [-\w]+ )+ + \s* ,? + )+ + ) \s* \{ \s* ( [^\}]+ )? # $2 = style \s* \} \s* @@ -44,12 +47,14 @@ module Encoders ( . ) # $3 = error /mx def parse stylesheet - stylesheet.scan CSS_CLASS_PATTERN do |classes, style, error| + stylesheet.scan CSS_CLASS_PATTERN do |selectors, style, error| raise "CSS parse error: '#{error.inspect}' not recognized" if error - styles = classes.scan(/[-\w]+/) - cl = styles.pop - @classes[cl] ||= Hash.new - @classes[cl][styles] = style.to_s.strip + for selector in selectors.split(',') + classes = selector.scan(/[-\w]+/) + cl = classes.pop + @classes[cl] ||= Hash.new + @classes[cl][classes] = style.to_s.strip + end end end -- cgit v1.2.1