diff options
author | murphy <murphy@rubychan.de> | 2008-12-25 01:22:30 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2008-12-25 01:22:30 +0000 |
commit | 79a313948f2277cf0f2e238d5765a71fee03e089 (patch) | |
tree | 7f6c2de879231f1b7a30d9ba481984e79fede9c1 /lib/coderay/encoders | |
parent | bca06f1ec361537c4c7f1368ca8838be2940dafe (diff) | |
download | coderay-79a313948f2277cf0f2e238d5765a71fee03e089.tar.gz |
Fixes for Ruby 1.9.
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r-- | lib/coderay/encoders/html.rb | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 8d13cf5..035ee65 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -220,8 +220,13 @@ module Encoders super end - def token text, type - if text.is_a? ::String + def token text, type = :plain + case text + + when nil + # raise 'Token with nil as text was given: %p' % [[text, type]] + + when String if text =~ /#{HTML_ESCAPE_PATTERN}/o text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] } end @@ -231,53 +236,49 @@ module Encoders else @out << text end - else - - case text - - # token groups, eg. strings - when :open - @opened[0] = type - @out << (@css_style[@opened] || '<span>') - @opened << type - when :close - if @opened.empty? - # nothing to close - else - if $DEBUG and (@opened.size == 1 or @opened.last != type) - raise 'Malformed token stream: Trying to close a token (%p) \ - that is not open. Open are: %p.' % [type, @opened[1..-1]] - end - @out << '</span>' - @opened.pop - end - # whole lines to be highlighted, eg. a deleted line in a diff - when :begin_line - @opened[0] = type - if style = @css_style[@opened] - @out << style.sub('<span', '<div') - else - @out << '<div>' - end - @opened << type - when :end_line - if @opened.empty? - # nothing to close - else - if $DEBUG and (@opened.size == 1 or @opened.last != type) - raise 'Malformed token stream: Trying to close a line (%p) \ - that is not open. Open are: %p.' % [type, @opened[1..-1]] - end - @out << '</div>' - @opened.pop + + # token groups, eg. strings + when :open + @opened[0] = type + @out << (@css_style[@opened] || '<span>') + @opened << type + when :close + if @opened.empty? + # nothing to close + else + if $DEBUG and (@opened.size == 1 or @opened.last != type) + raise 'Malformed token stream: Trying to close a token (%p) \ + that is not open. Open are: %p.' % [type, @opened[1..-1]] end - - when nil - raise 'Token with nil as text was given: %p' % [[text, type]] + @out << '</span>' + @opened.pop + end + + # whole lines to be highlighted, eg. a deleted line in a diff + when :begin_line + @opened[0] = type + if style = @css_style[@opened] + @out << style.sub('<span', '<div') else - raise 'unknown token kind: %p' % text + @out << '<div>' end + @opened << type + when :end_line + if @opened.empty? + # nothing to close + else + if $DEBUG and (@opened.size == 1 or @opened.last != type) + raise 'Malformed token stream: Trying to close a line (%p) \ + that is not open. Open are: %p.' % [type, @opened[1..-1]] + end + @out << '</div>' + @opened.pop + end + + else + raise 'unknown token kind: %p' % [text] + end end |