summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes.textile1
-rw-r--r--lib/coderay/scanners/html.rb23
2 files changed, 15 insertions, 9 deletions
diff --git a/Changes.textile b/Changes.textile
index 930fdbc..9509b15 100644
--- a/Changes.textile
+++ b/Changes.textile
@@ -10,6 +10,7 @@ h2. Changes in 1.1
* Diff scanner: Highlight inline changes in multi-line changes [#99]
* JavaScript scanner: Highlight multi-line comments in diff correctly
* Ruby scanner: Accept keywords as Ruby 1.9 hash keys [#126]
+* HTML scanner displays style tags and attributes now
* Remove double-click toggle handler from HTML table output
* Fixes to CSS scanner (floats, pseudoclasses)
* CSS scanner uses @:id@ and @:tag@ now [#27]
diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb
index 06728e4..f1dfba0 100644
--- a/lib/coderay/scanners/html.rb
+++ b/lib/coderay/scanners/html.rb
@@ -33,7 +33,8 @@ module Scanners
)
IN_ATTRIBUTE = WordList::CaseIgnoring.new(nil).
- add(EVENT_ATTRIBUTES, :script)
+ add(EVENT_ATTRIBUTES, :script).
+ add(['style'], :style)
ATTR_NAME = /[\w.:-]+/ # :nodoc:
TAG_END = /\/?>/ # :nodoc:
@@ -79,10 +80,10 @@ module Scanners
end
end
- def scan_css encoder, code
+ def scan_css encoder, code, state = [:initial]
if code && !code.empty?
@css_scanner ||= Scanners::CSS.new '', :keep_tokens => true
- @css_scanner.tokenize code, :tokens => encoder
+ @css_scanner.tokenize code, :tokens => encoder, :state => state
end
end
@@ -166,17 +167,21 @@ module Scanners
encoder.text_token match, :attribute_value
state = :attribute
elsif match = scan(/["']/)
- if in_attribute == :script
- encoder.begin_group :inline
- encoder.text_token match, :inline_delimiter
+ if in_attribute == :script || in_attribute == :style
+ encoder.begin_group :string
+ encoder.text_token match, :delimiter
if scan(/javascript:[ \t]*/)
encoder.text_token matched, :comment
end
code = scan_until(match == '"' ? /(?="|\z)/ : /(?='|\z)/)
- scan_java_script encoder, code
+ if in_attribute == :script
+ scan_java_script encoder, code
+ else
+ scan_css encoder, code, [:block]
+ end
match = scan(/["']/)
- encoder.text_token match, :inline_delimiter if match
- encoder.end_group :inline
+ encoder.text_token match, :delimiter if match
+ encoder.end_group :string
state = :attribute
in_attribute = nil
else