diff options
author | Etienne Massip <etienne.massip@gmail.com> | 2012-01-26 21:14:59 +0100 |
---|---|---|
committer | Etienne Massip <etienne.massip@gmail.com> | 2012-01-26 21:14:59 +0100 |
commit | 0e8008ad88b4f56e35d71c3029d02ffb4e21120f (patch) | |
tree | 92da233c37df252a7e1ba0781528053c0583237f /lib/coderay/encoders/html.rb | |
parent | 185c4222c4be23cec40b3a91bb8ae481aff398bc (diff) | |
download | coderay-0e8008ad88b4f56e35d71c3029d02ffb4e21120f.tar.gz |
Extracted code making HTML lines independent from numbering code to a specific option in encoder.
Diffstat (limited to 'lib/coderay/encoders/html.rb')
-rw-r--r-- | lib/coderay/encoders/html.rb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index c32dbd1..14d1307 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -47,6 +47,12 @@ module Encoders # # Default: 'CodeRay output' # + # === :independent_lines + # Split multilines blocks into line-wide blocks. + # Forced to true if :line_numbers option is set to :inline. + # + # Default: false + # # === :line_numbers # Include line numbers in :table, :inline, or nil (no line numbers) # @@ -99,7 +105,8 @@ module Encoders :style => :alpha, :wrap => nil, :title => 'CodeRay output', - + + :independent_lines => false, :line_numbers => nil, :line_number_anchors => 'n', :line_number_start => 1, @@ -167,7 +174,11 @@ module Encoders @real_out = @out @out = '' end - + + options[:independent_lines] = true if options[:line_numbers] == :inline + + @independent_lines = (options[:independent_lines] == true) + @HTML_ESCAPE = HTML_ESCAPE.dup @HTML_ESCAPE["\t"] = ' ' * options[:tab_width] @@ -245,13 +256,21 @@ 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" + @opened.each_with_index do |k, index| + close_eol_reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '<span>') + end + end if style = @span_for_kind[@last_opened ? [kind, *@opened] : kind] @out << style << text << '</span>' else @out << text end + @out << close_eol_reopen if close_eol_reopen end - + # token groups, eg. strings def begin_group kind @out << (@span_for_kind[@last_opened ? [kind, *@opened] : kind] || '<span>') @@ -299,4 +318,4 @@ module Encoders end end -end +end
\ No newline at end of file |