diff options
Diffstat (limited to 'lib/coderay')
-rw-r--r-- | lib/coderay/duo.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoder.rb | 17 | ||||
-rw-r--r-- | lib/coderay/encoders/debug.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/html.rb | 6 | ||||
-rw-r--r-- | lib/coderay/encoders/text.rb | 6 | ||||
-rw-r--r-- | lib/coderay/helpers/gzip_simple.rb | 5 | ||||
-rw-r--r-- | lib/coderay/scanners/c.rb | 2 | ||||
-rw-r--r-- | lib/coderay/tokens.rb | 6 |
8 files changed, 26 insertions, 20 deletions
diff --git a/lib/coderay/duo.rb b/lib/coderay/duo.rb index e2d6888..9d11c0e 100644 --- a/lib/coderay/duo.rb +++ b/lib/coderay/duo.rb @@ -35,7 +35,7 @@ module CodeRay # CodeRay::Duo[:ruby => :statistic].encode 'class << self; end' # # alternative syntax with options: - # CodeRay::Duo[(:ruby => :statistic), :do => :something].encode 'abc' + # CodeRay::Duo[{ :ruby => :statistic }, :do => :something].encode 'abc' # # The options are forwarded to scanner and encoder # (see CodeRay.get_scanner_options). diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb index ce65832..8e67172 100644 --- a/lib/coderay/encoder.rb +++ b/lib/coderay/encoder.rb @@ -42,7 +42,7 @@ module CodeRay # downcase class name instead. def const_missing sym if sym == :FILE_EXTENSION - sym.to_s.downcase + plugin_id else super end @@ -132,13 +132,14 @@ module CodeRay # By default, it calls text_token or block_token, depending on # whether +text+ is a String. def token text, kind - out = if text.instance_of? ::String # Ruby 1.9: :open.is_a? String - text_token text, kind - elsif text.is_a? ::Symbol - block_token text, kind - else - raise 'Unknown token text type: %p' % text - end + out = + if text.is_a? ::String # Ruby 1.9: :open.is_a? String + text_token text, kind + elsif text.is_a? ::Symbol + block_token text, kind + else + raise 'Unknown token text type: %p' % text + end @out << out if @out end diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb index 21d4710..8e1c0f0 100644 --- a/lib/coderay/encoders/debug.rb +++ b/lib/coderay/encoders/debug.rb @@ -22,7 +22,7 @@ module Encoders if kind == :space text else - text = text.gsub(/[)\\]/, '\\\\\0') + text = text.gsub(/[)\\]/, '\\\\\0') # escape ) and \ "#{kind}(#{text})" end end diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 32e35f8..0c66f68 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -167,7 +167,11 @@ module Encoders else '' end - h[k.dup] = '<span%s class="%s">' % [title, c] + if c == :NO_HIGHLIGHT + h[k.dup] = '<span%s>' % [title] + else + h[k.dup] = '<span%s class="%s">' % [title, c] + end end end diff --git a/lib/coderay/encoders/text.rb b/lib/coderay/encoders/text.rb index 7493280..14282ac 100644 --- a/lib/coderay/encoders/text.rb +++ b/lib/coderay/encoders/text.rb @@ -14,12 +14,12 @@ module Encoders protected def setup options - super + @out = '' @sep = options[:separator] end - def text_token text, kind - text + @sep + def token text, kind + @out << text + @sep if text.is_a? ::String end def finish options diff --git a/lib/coderay/helpers/gzip_simple.rb b/lib/coderay/helpers/gzip_simple.rb index 4d44711..76aeb22 100644 --- a/lib/coderay/helpers/gzip_simple.rb +++ b/lib/coderay/helpers/gzip_simple.rb @@ -1,5 +1,3 @@ -module CodeRay - # =GZip Simple # # A simplified interface to the gzip library +zlib+ (from the Ruby Standard Library.) @@ -48,6 +46,7 @@ module GZip end end + # String extensions to use the GZip module. # # The methods gzip and gunzip provide an even more simple @@ -93,8 +92,6 @@ if $0 == __FILE__ eval DATA.read, nil, $0, __LINE__+4 end -end - __END__ #CODE diff --git a/lib/coderay/scanners/c.rb b/lib/coderay/scanners/c.rb index 2b63a81..f6d71ad 100644 --- a/lib/coderay/scanners/c.rb +++ b/lib/coderay/scanners/c.rb @@ -44,7 +44,7 @@ module Scanners kind = nil match = nil - + case state when :initial diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb index d05177a..26c923f 100644 --- a/lib/coderay/tokens.rb +++ b/lib/coderay/tokens.rb @@ -267,7 +267,11 @@ module CodeRay # Should be equal to the input size before # scanning. def text_size - inject(0) { |size, (t, k)| t.is_a?(::String) ? size : size + t.size } + size = 0 + each_text_token do |t, k| + size + t.size + end + size end # The total size of the tokens. |