From 70dcba4428281407ff0b92a417c3d6d6939390a4 Mon Sep 17 00:00:00 2001 From: murphy Date: Thu, 22 Jan 2009 14:13:43 +0000 Subject: New feature: HTML encode option :highlight_lines. See documentation. * The scanner test suite uses it and highlights the lines that differ after a failed complete test in *.actual.html. --- lib/coderay/encoders/html.rb | 11 +++++++++++ lib/coderay/encoders/html/numerization.rb | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'lib/coderay/encoders') diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 035ee65..f7f99f7 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -56,6 +56,16 @@ module Encoders # # Default: 10 # + # === :highlight_lines + # + # Highlights certain line numbers now by using the :highlight_lines option. + # Can be any Enumerable, typically just an Array or Range, of numbers. + # + # Bolding is deactivated when :highlight_lines is set. It only makes sense + # in combination with :line_numbers. + # + # Default: nil + # # === :hint # Include some information into the output using the title attribute. # Can be :info (show token type on mouse-over), :info_long (with full path) @@ -82,6 +92,7 @@ module Encoders :line_numbers => nil, :line_number_start => 1, :bold_every => 10, + :highlight_lines => nil, :hint => false, } diff --git a/lib/coderay/encoders/html/numerization.rb b/lib/coderay/encoders/html/numerization.rb index 9f1667f..0b6cf7a 100644 --- a/lib/coderay/encoders/html/numerization.rb +++ b/lib/coderay/encoders/html/numerization.rb @@ -32,9 +32,19 @@ module Encoders #end bold_every = options[:bold_every] + highlight_lines = options[:highlight_lines] bolding = - if bold_every == false + if bold_every == false && highlight_lines == nil proc { |line| line.to_s } + elsif highlight_lines.is_a? Enumerable + highlight_lines = highlight_lines.to_set + proc do |line| + if highlight_lines.include? line + "#{line}" # highlighted line numbers in bold + else + line.to_s + end + end elsif bold_every.is_a? Integer raise ArgumentError, ":bolding can't be 0." if bold_every == 0 proc do |line| -- cgit v1.2.1