8000 scan_css in HTML scanner (arguments), change token kind from :inline … · tricknotes/coderay@7ada74c · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ada74c

Browse files
committed
scan_css in HTML scanner (arguments), change token kind from :inline to :string
1 parent 5b0dc0f commit 7ada74c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Changes.textile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ h2. Changes in 1.1
1010
* Diff scanner: Highlight inline changes in multi-line changes [#99]
1111
* JavaScript scanner: Highlight multi-line comments in diff correctly
1212
* Ruby scanner: Accept keywords as Ruby 1.9 hash keys [#126]
13+
* HTML scanner displays style tags and attributes now
1314
* Remove double-click toggle handler from HTML table output
1415
* Fixes to CSS scanner (floats, pseudoclasses)
1516
* CSS scanner uses @:id@ and @:tag@ now [#27]

lib/coderay/scanners/html.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class HTML < Scanner
3333
)
3434

3535
IN_ATTRIBUTE = WordList::CaseIgnoring.new(nil).
36-
add(EVENT_ATTRIBUTES, :script)
36+
add(EVENT_ATTRIBUTES, :script).
37+
add(['style'], :style)
3738

3839
ATTR_NAME = /[\w.:-]+/ # :nodoc:
3940
TAG_END = /\/?>/ # :nodoc:
@@ -79,10 +80,10 @@ def scan_java_script encoder, code
7980
end
8081
end
8182

82-
def scan_css encoder, code
83+
def scan_css encoder, code, state = [:initial]
8384
if code && !code.empty?
8485
@css_scanner ||= Scanners::CSS.new '', :keep_tokens => true
85-
@css_scanner.tokenize code, :tokens => encoder
86+
@css_scanner.tokenize code, :tokens => encoder, :state => state
8687
end
8788
end
8889

@@ -166,17 +167,21 @@ def scan_tokens encoder, options
166167
encoder.text_token match, :attribute_value
167168
state = :attribute
168169
elsif match = scan(/["']/)
169-
if in_attribute == :script
170-
encoder.begin_group :inline
171-
encoder.text_token match, :inline_delimiter
170+
if in_attribute == :script || in_attribute == :style
171+
encoder.begin_group :string
172+
encoder.text_token match, :delimiter
172173
if scan(/javascript:[ \t]*/)
173174
encoder.text_token matched, :comment
174175
end
175176
code = scan_until(match == '"' ? /(?="|\z)/ : /(?='|\z)/)
176-
scan_java_script encoder, code
177+
if in_attribute == :script
178+
scan_java_script encoder, code
179+
else
180+
scan_css encoder, code, [:block]
181+
end
177182
match = scan(/["']/)
178-
encoder.text_token match, :inline_delimiter if match
179-
encoder.end_group :inline
183+
encoder.text_token match, :delimiter if match
184+
encoder.end_group :string
180185
state = :attribute
181186
in_attribute = nil
182187
else

0 commit comments

Comments
 (0)
0