summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtienne Massip <etienne.massip@gmail.com>2012-03-29 20:46:07 +0200
committerEtienne Massip <etienne.massip@gmail.com>2012-03-29 20:46:07 +0200
commita2e9acc4dabd2ec2d33ac17d83f92ef370354eb7 (patch)
treeab35ebdc884a848f371e722240229f3f14d007a2
parent0e8008ad88b4f56e35d71c3029d02ffb4e21120f (diff)
downloadcoderay-a2e9acc4dabd2ec2d33ac17d83f92ef370354eb7.tar.gz
Fixed handling of eols inside token content.
-rw-r--r--lib/coderay/encoders/html.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index 14d1307..0d91cdf 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -256,19 +256,23 @@ module Encoders
if text =~ /#{HTML_ESCAPE_PATTERN}/o
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
end
- if @independent_lines && @opened.any? && text.end_with?("\n")
- text.chomp!
- close_eol_reopen = "#{'</span>' * @opened.size}\n"
+
+ style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
+
+ if @independent_lines && (i = text.index("\n")) && (c = @opened.size + (style ? 1 : 0)) > 0
+ close = '</span>' * c
+ reopen = ''
@opened.each_with_index do |k, index|
- close_eol_reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '<span>')
+ reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '<span>')
end
+ text[i .. -1] = text[i .. -1].gsub("\n", "#{close}\n#{reopen}#{style}")
end
- if style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
+
+ if style
@out << style << text << '</span>'
else
@out << text
end
- @out << close_eol_reopen if close_eol_reopen
end
# token groups, eg. strings