Skip to content

Commit df4e2bc

Browse files
committed
here come the white-space nazis
1 parent d68749d commit df4e2bc

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

lib/coderay/encoders/html.rb

+12-11
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Encoders
4848
# Default: 'CodeRay output'
4949
#
5050
# === :independent_lines
51-
# Split multilines blocks into line-wide blocks.
51+
# Split multiline blocks at line breaks.
5252
# Forced to true if :line_numbers option is set to :inline.
5353
#
5454
# Default: false
@@ -105,8 +105,9 @@ class HTML < Encoder
105105
:style => :alpha,
106106
:wrap => nil,
107107
:title => 'CodeRay output',
108-
109-
:independent_lines => false,
108+
109+
:independent_lines => false,
110+
110111
:line_numbers => nil,
111112
:line_number_anchors => 'n',
112113
:line_number_start => 1,
@@ -174,11 +175,11 @@ def setup options
174175
@real_out = @out
175176
@out = ''
176177
end
177-
178+
178179
options[:independent_lines] = true if options[:line_numbers] == :inline
179-
180+
180181
@independent_lines = (options[:independent_lines] == true)
181-
182+
182183
@HTML_ESCAPE = HTML_ESCAPE.dup
183184
@HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
184185

@@ -256,9 +257,9 @@ def text_token text, kind
256257
if text =~ /#{HTML_ESCAPE_PATTERN}/o
257258
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
258259
end
259-
260+
260261
style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
261-
262+
262263
if @independent_lines && (i = text.index("\n")) && (c = @opened.size + (style ? 1 : 0)) > 0
263264
close = '</span>' * c
264265
reopen = ''
@@ -267,14 +268,14 @@ def text_token text, kind
267268
end
268269
text[i .. -1] = text[i .. -1].gsub("\n", "#{close}\n#{reopen}#{style}")
269270
end
270-
271+
271272
if style
272273
@out << style << text << '</span>'
273274
else
274275
@out << text
275276
end
276277
end
277-
278+
278279
# token groups, eg. strings
279280
def begin_group kind
280281
@out << (@span_for_kind[@last_opened ? [kind, *@opened] : kind] || '<span>')
@@ -322,4 +323,4 @@ def end_line kind
322323
end
323324

324325
end
325-
end
326+
end

lib/coderay/encoders/html/numbering.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ def self.number! output, mode = :table, options = {}
100100
end
101101

102102
end
103-
end
103+
end

test/unit/html.rb

+19-20
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,35 @@
22
require 'coderay'
33

44
class HtmlTest < Test::Unit::TestCase
5-
5+
66
def test_independent_lines_option
7-
87
snippets = {}
9-
8+
109
snippets[:ruby] = {}
11-
10+
1211
snippets[:ruby][:in] = <<-RUBY
1312
ruby_inside = <<-RUBY_INSIDE
1413
This is tricky,
1514
isn't it?
1615
RUBY_INSIDE
17-
RUBY
18-
16+
RUBY
17+
1918
snippets[:ruby][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF
2019
ruby_inside = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\">
2120
This is tricky,
2221
isn't it?</span><span class=\"delimiter\">
2322
RUBY_INSIDE</span></span>
24-
HTML_OPT_INDEPENDENT_LINES_OFF
25-
23+
HTML_OPT_INDEPENDENT_LINES_OFF
24+
2625
snippets[:ruby][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
2726
ruby_inside = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\"></span></span>
2827
<span class=\"string\"><span class=\"content\">This is tricky,</span></span>
2928
<span class=\"string\"><span class=\"content\">isn't it?</span><span class=\"delimiter\"></span></span>
3029
<span class=\"string\"><span class=\"delimiter\">RUBY_INSIDE</span></span>
31-
HTML_OPT_INDEPENDENT_LINES_ON
32-
30+
HTML_OPT_INDEPENDENT_LINES_ON
31+
3332
snippets[:java] = {}
34-
33+
3534
snippets[:java][:in] = <<-JAVA
3635
import java.lang.*;
3736
@@ -51,8 +50,8 @@ def test_independent_lines_option
5150
System.out.println(MESSAGE);
5251
}
5352
}
54-
JAVA
55-
53+
JAVA
54+
5655
snippets[:java][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF
5756
<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;
5857
@@ -71,8 +70,8 @@ def test_independent_lines_option
7170
<span class=\"predefined-type\">System</span>.out.println(MESSAGE);
7271
}
7372
}
74-
HTML_OPT_INDEPENDENT_LINES_OFF
75-
73+
HTML_OPT_INDEPENDENT_LINES_OFF
74+
7675
snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
7776
<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;
7877
@@ -91,14 +90,14 @@ def test_independent_lines_option
9190
<span class=\"predefined-type\">System</span>.out.println(MESSAGE);
9291
}
9392
}
94-
HTML_OPT_INDEPENDENT_LINES_ON
95-
96-
snippets.entries().each do |lang, code|
93+
HTML_OPT_INDEPENDENT_LINES_ON
94+
95+
for lang, code in snippets
9796
tokens = CodeRay.scan code[:in], lang
98-
97+
9998
assert_equal code[:expected_with_option_off], tokens.html
10099
assert_equal code[:expected_with_option_off], tokens.html(:independent_lines => false)
101100
assert_equal code[:expected_with_option_on], tokens.html(:independent_lines => true)
102101
end
103102
end
104-
end
103+
end

0 commit comments

Comments
 (0)