summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders
diff options
context:
space:
mode:
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r--lib/coderay/encoders/debug.rb8
-rw-r--r--lib/coderay/encoders/html.rb27
-rw-r--r--lib/coderay/encoders/html/numerization.rb4
-rw-r--r--lib/coderay/encoders/html/output.rb4
4 files changed, 40 insertions, 3 deletions
diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb
index 8e1c0f0..a4b0648 100644
--- a/lib/coderay/encoders/debug.rb
+++ b/lib/coderay/encoders/debug.rb
@@ -35,6 +35,14 @@ module Encoders
">"
end
+ def begin_line kind
+ "#{kind}["
+ end
+
+ def end_line kind
+ "]"
+ end
+
end
end
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index 2edcf1d..8d13cf5 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -226,13 +226,16 @@ module Encoders
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
end
@opened[0] = type
- if style = @css_style[@opened]
+ if text != "\n" && style = @css_style[@opened]
@out << style << text << '</span>'
else
@out << text
end
else
+
case text
+
+ # token groups, eg. strings
when :open
@opened[0] = type
@out << (@css_style[@opened] || '<span>')
@@ -248,6 +251,28 @@ module Encoders
@out << '</span>'
@opened.pop
end
+
+ # whole lines to be highlighted, eg. a deleted line in a diff
+ when :begin_line
+ @opened[0] = type
+ if style = @css_style[@opened]
+ @out << style.sub('<span', '<div')
+ else
+ @out << '<div>'
+ end
+ @opened << type
+ when :end_line
+ if @opened.empty?
+ # nothing to close
+ else
+ if $DEBUG and (@opened.size == 1 or @opened.last != type)
+ raise 'Malformed token stream: Trying to close a line (%p) \
+ that is not open. Open are: %p.' % [type, @opened[1..-1]]
+ end
+ @out << '</div>'
+ @opened.pop
+ end
+
when nil
raise 'Token with nil as text was given: %p' % [[text, type]]
else
diff --git a/lib/coderay/encoders/html/numerization.rb b/lib/coderay/encoders/html/numerization.rb
index d784bbe..9f1667f 100644
--- a/lib/coderay/encoders/html/numerization.rb
+++ b/lib/coderay/encoders/html/numerization.rb
@@ -71,6 +71,7 @@ module Encoders
line_numbers.gsub!(/\n/) { "<tt>\n</tt>" }
line_numbers_table_tpl = TABLE.apply('LINE_NUMBERS', line_numbers)
+ gsub!(/<\/div>\n/) { '</div>' }
gsub!(/\n/) { "<tt>\n</tt>" }
wrap_in! line_numbers_table_tpl
@wrapped_in = :div
@@ -90,8 +91,9 @@ module Encoders
end
close = '</span>' * opened_tags.size
- "<li>#{open}#{line}#{close}</li>"
+ "<li>#{open}#{line}#{close}</li>\n"
end
+ chomp!("\n")
wrap_in! LIST
@wrapped_in = :div
diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb
index e74e55e..8def95e 100644
--- a/lib/coderay/encoders/html/output.rb
+++ b/lib/coderay/encoders/html/output.rb
@@ -166,7 +166,9 @@ module Encoders
# title="double click to expand"
LIST = <<-`LIST`
-<ol class="CodeRay"><%CONTENT%></ol>
+<ol class="CodeRay">
+<%CONTENT%>
+</ol>
LIST
PAGE = <<-`PAGE`