summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders
diff options
context:
space:
mode:
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r--lib/coderay/encoders/debug_lint.rb3
-rw-r--r--lib/coderay/encoders/html.rb24
-rw-r--r--lib/coderay/encoders/lint.rb4
3 files changed, 20 insertions, 11 deletions
diff --git a/lib/coderay/encoders/debug_lint.rb b/lib/coderay/encoders/debug_lint.rb
index 2c14186..a4eba2c 100644
--- a/lib/coderay/encoders/debug_lint.rb
+++ b/lib/coderay/encoders/debug_lint.rb
@@ -18,7 +18,8 @@ module Encoders
register_for :debug_lint
def text_token text, kind
- raise Lint::EmptyToken, 'empty token' if text.empty?
+ raise Lint::EmptyToken, 'empty token for %p' % [kind] if text.empty?
+ raise Lint::UnknownTokenKind, 'unknown token kind %p (text was %p)' % [kind, text] unless TokenKinds.has_key? kind
super
end
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index 1040d20..b6db051 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -25,7 +25,8 @@ module Encoders
# == Options
#
# === :tab_width
- # Convert \t characters to +n+ spaces (a number.)
+ # Convert \t characters to +n+ spaces (a number or false.)
+ # false will keep tab characters untouched.
#
# Default: 8
#
@@ -180,7 +181,7 @@ module Encoders
@break_lines = (options[:break_lines] == true)
- @HTML_ESCAPE = HTML_ESCAPE.merge("\t" => ' ' * options[:tab_width])
+ @HTML_ESCAPE = HTML_ESCAPE.merge("\t" => options[:tab_width] ? ' ' * options[:tab_width] : "\t")
@opened = []
@last_opened = nil
@@ -197,11 +198,13 @@ module Encoders
@last_opened = nil
end
- if options[:line_numbers]
- Numbering.number! @out, options[:line_numbers], options
+ if @out.respond_to? :to_str
+ if options[:line_numbers]
+ Numbering.number! @out, options[:line_numbers], options
+ end
+ @out = Output.wrap_string_in @out, options[:wrap], @css if options[:wrap]
+ @out = @out.sub(/(<title>)(<\/title>)/) { $1 + options[:title] + $2 } if options[:title]
end
- @out = Output.wrap_string_in @out, options[:wrap], @css if options[:wrap]
- @out = @out.sub(/(<title>)(<\/title>)/) { $1 + options[:title] + $2 } if options[:title]
if defined?(@real_out) && @real_out
@real_out << @out
@@ -287,7 +290,7 @@ module Encoders
def make_span_for_kinds method, hint
Hash.new do |h, kinds|
- h[kinds.is_a?(Symbol) ? kinds : kinds.dup] = begin
+ begin
css_class = css_class_for_kinds(kinds)
title = HTML.token_path_to_hint hint, kinds if hint
@@ -299,6 +302,9 @@ module Encoders
"<span#{title}#{" class=\"#{css_class}\"" if css_class}>"
end
end
+ end.tap do |span|
+ h.clear if h.size >= 100
+ h[kinds] = span
end
end
end
@@ -311,8 +317,8 @@ module Encoders
def break_lines text, style
reopen = ''
- @opened.each_with_index do |k, index|
- reopen << (@span_for_kinds[index > 0 ? [k, *@opened[0...index]] : k] || '<span>')
+ @opened.each_with_index do |kind, index|
+ reopen << (@span_for_kinds[index > 0 ? [kind, *@opened[0...index]] : kind] || '<span>')
end
text.gsub("\n", "#{'</span>' * @opened.size}#{'</span>' if style}\n#{reopen}#{style}")
end
diff --git a/lib/coderay/encoders/lint.rb b/lib/coderay/encoders/lint.rb
index 4601e90..88c8bd1 100644
--- a/lib/coderay/encoders/lint.rb
+++ b/lib/coderay/encoders/lint.rb
@@ -17,10 +17,12 @@ module Encoders
InvalidTokenStream = Class.new StandardError
EmptyToken = Class.new InvalidTokenStream
+ UnknownTokenKind = Class.new InvalidTokenStream
IncorrectTokenGroupNesting = Class.new InvalidTokenStream
def text_token text, kind
- raise EmptyToken, 'empty token' if text.empty?
+ raise EmptyToken, 'empty token for %p' % [kind] if text.empty?
+ raise UnknownTokenKind, 'unknown token kind %p (text was %p)' % [kind, text] unless TokenKinds.has_key? kind
end
def begin_group kind