From df4e2bc7f7d8238f56e2d823aea707bfd860ad8f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 1 Apr 2012 00:28:15 +0200 Subject: here come the white-space nazis --- lib/coderay/encoders/html.rb | 23 ++++++++++---------- lib/coderay/encoders/html/numbering.rb | 2 +- test/unit/html.rb | 39 +++++++++++++++++----------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 0d91cdf..2ec0f37 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -48,7 +48,7 @@ module Encoders # Default: 'CodeRay output' # # === :independent_lines - # Split multilines blocks into line-wide blocks. + # Split multiline blocks at line breaks. # Forced to true if :line_numbers option is set to :inline. # # Default: false @@ -105,8 +105,9 @@ module Encoders :style => :alpha, :wrap => nil, :title => 'CodeRay output', - - :independent_lines => false, + + :independent_lines => false, + :line_numbers => nil, :line_number_anchors => 'n', :line_number_start => 1, @@ -174,11 +175,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] @@ -256,9 +257,9 @@ module Encoders if text =~ /#{HTML_ESCAPE_PATTERN}/o text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] } end - + 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 = '' @@ -267,14 +268,14 @@ module Encoders end text[i .. -1] = text[i .. -1].gsub("\n", "#{close}\n#{reopen}#{style}") end - + if style @out << style << text << '' else @out << text end end - + # token groups, eg. strings def begin_group kind @out << (@span_for_kind[@last_opened ? [kind, *@opened] : kind] || '') @@ -322,4 +323,4 @@ module Encoders end end -end \ No newline at end of file +end diff --git a/lib/coderay/encoders/html/numbering.rb b/lib/coderay/encoders/html/numbering.rb index 904a64f..8bc6259 100644 --- a/lib/coderay/encoders/html/numbering.rb +++ b/lib/coderay/encoders/html/numbering.rb @@ -100,4 +100,4 @@ module Encoders end end -end \ No newline at end of file +end diff --git a/test/unit/html.rb b/test/unit/html.rb index f6e3d7e..cc4a0c6 100644 --- a/test/unit/html.rb +++ b/test/unit/html.rb @@ -2,36 +2,35 @@ require 'test/unit' require 'coderay' class HtmlTest < Test::Unit::TestCase - + def test_independent_lines_option - snippets = {} - + snippets[:ruby] = {} - + snippets[:ruby][:in] = <<-RUBY ruby_inside = <<-RUBY_INSIDE This is tricky, isn't it? RUBY_INSIDE - RUBY - + RUBY + snippets[:ruby][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF ruby_inside = <<-RUBY_INSIDE This is tricky, isn't it? RUBY_INSIDE - HTML_OPT_INDEPENDENT_LINES_OFF - + HTML_OPT_INDEPENDENT_LINES_OFF + snippets[:ruby][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON ruby_inside = <<-RUBY_INSIDE This is tricky, isn't it? RUBY_INSIDE - HTML_OPT_INDEPENDENT_LINES_ON - + HTML_OPT_INDEPENDENT_LINES_ON + snippets[:java] = {} - + snippets[:java][:in] = <<-JAVA import java.lang.*; @@ -51,8 +50,8 @@ public class Test { System.out.println(MESSAGE); } } - JAVA - + JAVA + snippets[:java][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF import java.lang.*; @@ -71,8 +70,8 @@ public class Test { System.out.println(MESSAGE); } } - HTML_OPT_INDEPENDENT_LINES_OFF - + HTML_OPT_INDEPENDENT_LINES_OFF + snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON import java.lang.*; @@ -91,14 +90,14 @@ public class Test { System.out.println(MESSAGE); } } - HTML_OPT_INDEPENDENT_LINES_ON - - snippets.entries().each do |lang, code| + HTML_OPT_INDEPENDENT_LINES_ON + + for lang, code in snippets tokens = CodeRay.scan code[:in], lang - + assert_equal code[:expected_with_option_off], tokens.html assert_equal code[:expected_with_option_off], tokens.html(:independent_lines => false) assert_equal code[:expected_with_option_on], tokens.html(:independent_lines => true) end end -end \ No newline at end of file +end -- cgit v1.2.1