summaryrefslogtreecommitdiff
path: root/lib/coderay/tokens.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/coderay/tokens.rb')
-rw-r--r--lib/coderay/tokens.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb
index b0ce70e..d05177a 100644
--- a/lib/coderay/tokens.rb
+++ b/lib/coderay/tokens.rb
@@ -115,7 +115,7 @@ module CodeRay
# tokens.each_text_token { |text, kind| text.replace html_escape(text) }
def each_text_token
each do |text, kind|
- next unless text.respond_to? :to_str
+ next unless text.is_a? ::String
yield text, kind
end
end
@@ -252,7 +252,7 @@ module CodeRay
#
# You can configure the level of compression,
# but the default value 7 should be what you want
- # in most cases as it is a good comprimise between
+ # in most cases as it is a good compromise between
# speed and compression rate.
#
# See GZip module.
@@ -267,7 +267,14 @@ module CodeRay
# Should be equal to the input size before
# scanning.
def text_size
- map { |t, k| t }.join.size
+ inject(0) { |size, (t, k)| t.is_a?(::String) ? size : size + t.size }
+ end
+
+ # The total size of the tokens.
+ # Should be equal to the input size before
+ # scanning.
+ def text
+ map { |t, k| t if t.is_a? ::String }.join
end
# Include this module to give an object an #undump
@@ -365,4 +372,8 @@ module CodeRay
end
+
+ # Token name abbreviations
+ require 'coderay/token_classes'
+
end