10000 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
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
Next Next commit
scan_css in HTML scanner (tags)
  • Loading branch information
korny committed Jun 23, 2013
commit 5b0dc0f35090949d7512a85dadc8cf2871b91aac
21 changes: 15 additions & 6 deletions lib/coderay/scanners/html.rb
5A07
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ def setup
def scan_java_script encoder, code
if code && !code.empty?
@java_script_scanner ||= Scanners::JavaScript.new '', :keep_tokens => true
# encoder.begin_group :inline
@java_script_scanner.tokenize code, :tokens => encoder
# encoder.end_group :inline
end
end

def scan_css encoder, code
if code && !code.empty?
@css_scanner ||= Scanners::CSS.new '', :keep_tokens => true
@css_scanner.tokenize code, :tokens => encoder
end
end

Expand Down Expand Up @@ -110,7 +115,7 @@ def scan_tokens encoder, options
elsif match = scan(/<\/[-\w.:]*>?/m)
in_tag = nil
encoder.text_token match, :tag
elsif match = scan(/<(?:(script)|[-\w.:]+)(>)?/m)
elsif match = scan(/<(?:(script|style)|[-\w.:]+)(>)?/m)
encoder.text_token match, :tag
in_tag = self[1]
if self[2]
Expand Down Expand Up @@ -206,19 +211,23 @@ def scan_tokens encoder, options

when :in_special_tag
case in_tag
when 'script'
when 'script', 'style'
encoder.text_token match, :space if match = scan(/[ \t]*\n/)
if scan(/(\s*<!--)(?:(.*?)(-->)|(.*))/m)
code = self[2] || self[4]
closing = self[3]
encoder.text_token self[1], :comment
else
code = scan_until(/(?=(?:\n\s*)?<\/script>)|\z/)
code = scan_until(/(?=(?:\n\s*)?<\/#{in_tag}>)|\z/)
closing = false
end
unless code.empty?
encoder.begin_group :inline
scan_java_script encoder, code
if in_tag == 'script'
scan_java_script encoder, code
else
scan_css encoder, code
end
encoder.end_group :inline
end
encoder.text_token closing, :comment if closing
Expand Down
0