summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2012-04-01 00:28:15 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2012-04-01 00:28:15 +0200
commitdf4e2bc7f7d8238f56e2d823aea707bfd860ad8f (patch)
tree30a7b7ef3f7ce47aeac0d8e0318525d52fb7bf15
parentd68749d4473e3bafb88365cb27728cb61d28ca1d (diff)
downloadcoderay-df4e2bc7f7d8238f56e2d823aea707bfd860ad8f.tar.gz
here come the white-space nazis
-rw-r--r--lib/coderay/encoders/html.rb23
-rw-r--r--lib/coderay/encoders/html/numbering.rb2
-rw-r--r--test/unit/html.rb39
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 = '</span>' * 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 << '</span>'
else
@out << text
end
end
-
+
# token groups, eg. strings
def begin_group kind
@out << (@span_for_kind[@last_opened ? [kind, *@opened] : kind] || '<span>')
@@ -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 = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\">
This is tricky,
isn't it?</span><span class=\"delimiter\">
RUBY_INSIDE</span></span>
- HTML_OPT_INDEPENDENT_LINES_OFF
-
+ HTML_OPT_INDEPENDENT_LINES_OFF
+
snippets[:ruby][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
ruby_inside = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\"></span></span>
<span class=\"string\"><span class=\"content\">This is tricky,</span></span>
<span class=\"string\"><span class=\"content\">isn't it?</span><span class=\"delimiter\"></span></span>
<span class=\"string\"><span class=\"delimiter\">RUBY_INSIDE</span></span>
- 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
<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;
@@ -71,8 +70,8 @@ public class Test {
<span class=\"predefined-type\">System</span>.out.println(MESSAGE);
}
}
- HTML_OPT_INDEPENDENT_LINES_OFF
-
+ HTML_OPT_INDEPENDENT_LINES_OFF
+
snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;
@@ -91,14 +90,14 @@ public class Test {
<span class=\"predefined-type\">System</span>.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