summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/coderay.rb6
-rw-r--r--lib/coderay/encoders/html.rb13
-rw-r--r--lib/coderay/tokens.rb9
3 files changed, 16 insertions, 12 deletions
diff --git a/lib/coderay.rb b/lib/coderay.rb
index 23901ed..e1dbcd2 100644
--- a/lib/coderay.rb
+++ b/lib/coderay.rb
@@ -69,10 +69,10 @@
# * Input and language are always sorted in this order: +code+, +lang+.
# (This is in alphabetical order, if you need a mnemonic ;)
#
-# You should be able to highlight everything you want just using this methods;
+# You should be able to highlight everything you want just using these methods;
# so there is no need to dive into CodeRay's deep class hierarchy.
#
-# The exmaples in the demo/ directory demonstrate common cases using this interface.
+# The examples in the demo directory demonstrate common cases using this interface.
#
# = Basic Access Ways
#
@@ -84,7 +84,7 @@
# Each Token knows about what type it is: string, comment, class name, etc.
#
# Each +lang+ (language) has its own Scanner; for example, <tt>:ruby</tt> code is
-# handled by CodeRay::Scanners::RubyScanner.
+# handled by CodeRay::Scanners::Ruby.
#
# CodeRay.scan:: Scan a string in a given language into Tokens.
# This is the most common method to use.
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index 65a7874..02a718b 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -109,7 +109,7 @@ module Encoders
# \x9 (\t) and \xA (\n) not included
HTML_ESCAPE_PATTERN = /[\t&"><\xB-\x1f\x7f-\xff\0-\x8]/
- TOKEN_KIND_TO_INFO = Hash.new do |h, kind|
+ TOKEN_KIND_TO_INFO = Hash.new { |h, kind|
h[kind] =
case kind
when :pre_constant
@@ -117,8 +117,11 @@ module Encoders
else
kind.to_s.gsub(/_/, ' ').gsub(/\b\w/) { $&.capitalize }
end
- end
+ }
+ # Generate a hint about the given +classes+ in a +hint+ style.
+ #
+ # +hint+ may be :info, :info_long or :debug.
def self.token_path_to_hint hint, classes
return '' unless hint
title =
@@ -126,7 +129,7 @@ module Encoders
when :info
TOKEN_KIND_TO_INFO[classes.first]
when :info_long
- classes.map { |kind| TOKEN_KIND_TO_INFO[kind] }.join('/')
+ classes.reverse.map { |kind| TOKEN_KIND_TO_INFO[kind] }.join('/')
when :debug
classes.inspect
end
@@ -145,7 +148,7 @@ module Encoders
@css = CSS.new options[:style]
hint = options[:hint]
- if hint and not [:debug, :info].include? hint
+ if hint and not [:debug, :info, :info_long].include? hint
raise ArgumentError, "Unknown value %p for :hint; expected :info, :debug, false or nil." % hint
end
@@ -179,7 +182,9 @@ module Encoders
if classes.first == :NO_HIGHLIGHT and not hint
h[k] = false
else
+ styles.shift if [:delimiter, :modifier, :content, :escape].include? styles.first
title = HTML.token_path_to_hint hint, styles
+ classes.delete 'il'
style = @css[*classes]
h[k] =
if style
diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb
index e3b3305..c7ca356 100644
--- a/lib/coderay/tokens.rb
+++ b/lib/coderay/tokens.rb
@@ -161,12 +161,11 @@ module CodeRay
# This can not be undone, but should yield the same output
# in most Encoders. It basically makes the output smaller.
#
- # Combined with dump, it saves space for the cost
- # calculating time.
+ # Combined with dump, it saves space for the cost of time.
#
# If the scanner is written carefully, this is not required -
- # for example, consecutive //-comment lines can already be
- # joined in one token by the Scanner.
+ # for example, consecutive //-comment lines could already be
+ # joined in one comment token by the Scanner.
def optimize
print ' Tokens#optimize: before: %d - ' % size if $DEBUG
last_kind = last_text = nil
@@ -219,7 +218,7 @@ module CodeRay
dump.extend Undumping
end
- # The total size of the tokens;
+ # The total size of the tokens.
# Should be equal to the input size before
# scanning.
def text_size