From a2e9acc4dabd2ec2d33ac17d83f92ef370354eb7 Mon Sep 17 00:00:00 2001 From: Etienne Massip Date: Thu, 29 Mar 2012 20:46:07 +0200 Subject: Fixed handling of eols inside token content. --- lib/coderay/encoders/html.rb | 16 ++++++++++------ 1 file 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 = "#{'' * @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 = '' * c + reopen = '' @opened.each_with_index do |k, index| - close_eol_reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '') + reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '') 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 << '' else @out << text end - @out << close_eol_reopen if close_eol_reopen end # token groups, eg. strings -- cgit v1.2.1