8000 Scan CSS inside of HTML by korny · Pull Request #145 · rubychan/coderay · GitHub
[go: up one dir, main page]

Skip to content

Scan CSS inside of HTML #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
scan_css in HTML scanner (arguments), change token kind from :inline …
…to :string
  • Loading branch information
korny committed Jun 23, 2013
commit 7ada74c8f0f77815393e887db83e1d2c36ce7235
1 change: 1 addition & 0 deletions Changes.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
23 changes: 14 additions & 9 deletions lib/coderay/scanners/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class HTML < Scanner
)

IN_ATTRIBUTE = WordList::CaseIgnoring.new(nil).
add(EVENT_ATTRIBUTES, :script)
add(EVENT_ATTRIBUTES, :script).
add(['style'], :style)

ATTR_NAME = /[\w.:-]+/ # :nodoc:
TAG_END = /\/?>/ # :nodoc:
Expand Down Expand Up @@ -79,10 +80,10 @@ def scan_java_script encoder, code
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

Expand Down Expand Up @@ -166,17 +167,21 @@ def scan_tokens encoder, options
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
Expand Down
0