diff --git a/lib/coderay/encoders/html/numbering.rb b/lib/coderay/encoders/html/numbering.rb index a1b9c04a..589ca186 100644 --- a/lib/coderay/encoders/html/numbering.rb +++ b/lib/coderay/encoders/html/numbering.rb @@ -1,20 +1,20 @@ module CodeRay module Encoders - + class HTML - + module Numbering # :nodoc: - + def self.number! output, mode = :table, options = {} return self unless mode - + options = DEFAULT_OPTIONS.merge options - + start = options[:line_number_start] unless start.is_a? Integer raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start end - + anchor_prefix = options[:line_number_anchors] anchor_prefix = 'line' if anchor_prefix == true anchor_prefix = anchor_prefix.to_s[/[\w-]+/] if anchor_prefix @@ -28,7 +28,7 @@ def self.number! output, mode = :table, options = {} else :to_s.to_proc end - + bold_every = options[:bold_every] highlight_lines = options[:highlight_lines] bolding = @@ -55,11 +55,11 @@ def self.number! output, mode = :table, options = {} else raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every end - + if position_of_last_newline = output.rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n) after_last_newline = output[position_of_last_newline + 1 .. -1] ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/] - + if ends_with_newline line_count = output.count("\n") else @@ -68,7 +68,7 @@ def self.number! output, mode = :table, options = {} else line_count = 1 end - + case mode when :inline max_width = (start + line_count).to_s.size @@ -77,32 +77,44 @@ def self.number! output, mode = :table, options = {} line_number_text = bolding.call line_number indent = ' ' * (max_width - line_number.to_s.size) line_number += 1 - "#{indent}#{line_number_text}#{line}" + numbered_line = "#{indent}#{line_number_text}#{line}" + if options.wrap_lines + numbered_line = "