diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/coderay.rb | 24 | ||||
-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 |
9 files changed, 36 insertions, 34 deletions
diff --git a/lib/coderay.rb b/lib/coderay.rb index 9d1dbd7..2f8e4dd 100644 --- a/lib/coderay.rb +++ b/lib/coderay.rb @@ -24,8 +24,8 @@ # # == Usage # -# Remember you need RubyGems to use CodeRay. Run Ruby with -rubygems option -# if required. +# Remember you need RubyGems to use CodeRay, unless you have it in your load path. Run Ruby with +# -rubygems option if required. # # === Highlight Ruby code in a string as html # @@ -44,19 +44,15 @@ # # You can include this div in your page. The used CSS styles can be printed with # -# % ruby -rcoderay -e "print CodeRay::Encoders[:html]::CSS" +# % coderay_stylesheet # # === Highlight without typing too much -# +# # If you are one of the hasty (or lazy, or extremely curious) people, just run this file: -# -# % ruby -rubygems coderay.rb # -# If the output was to fast for you, try +# % ruby -rubygems /path/to/coderay/coderay.rb > example.html # -# % ruby -rubygems coderay.rb > example.html -# -# and look at the file it created. +# and look at the file it created in your browser. # # = CodeRay Module # @@ -121,11 +117,11 @@ # for this Encoder must only be done once. # # CodeRay.encoder:: Create an Encoder instance with format and options. +# CodeRay.scanner:: Create an Scanner instance for lang, with '' as default code. # -# There is no CodeRay.scanner method because Scanners are bound to an input string -# on creation; you can't re-use them with another string. +# To make use of CodeRay.scanner, use CodeRay::Scanner::code=. # -# The scanning methods provide more flexibility; we recommend to use these. +# The scanning methods provide more flexibility; we recommend to use these. # # == Reusing Scanners and Encoders # @@ -319,6 +315,6 @@ end # Run a test script. if $0 == __FILE__ $stderr.print 'Press key to print demo.'; gets - code = File.read($0)[/module CodeRay.*/m] + code = File.read(__FILE__)[/module CodeRay.*/m] print CodeRay.scan(code, :ruby).html end 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. |