asciidoctor 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of asciidoctor might be problematic. Click here for more details.
- data/Gemfile +2 -0
- data/README.asciidoc +35 -26
- data/Rakefile +9 -6
- data/asciidoctor.gemspec +27 -8
- data/bin/asciidoctor +1 -1
- data/lib/asciidoctor.rb +351 -63
- data/lib/asciidoctor/abstract_block.rb +218 -0
- data/lib/asciidoctor/abstract_node.rb +249 -0
- data/lib/asciidoctor/attribute_list.rb +211 -0
- data/lib/asciidoctor/backends/base_template.rb +99 -0
- data/lib/asciidoctor/backends/docbook45.rb +510 -0
- data/lib/asciidoctor/backends/html5.rb +585 -0
- data/lib/asciidoctor/block.rb +27 -254
- data/lib/asciidoctor/callouts.rb +117 -0
- data/lib/asciidoctor/debug.rb +7 -4
- data/lib/asciidoctor/document.rb +229 -77
- data/lib/asciidoctor/inline.rb +29 -0
- data/lib/asciidoctor/lexer.rb +1330 -502
- data/lib/asciidoctor/list_item.rb +33 -34
- data/lib/asciidoctor/reader.rb +305 -142
- data/lib/asciidoctor/renderer.rb +115 -19
- data/lib/asciidoctor/section.rb +100 -189
- data/lib/asciidoctor/substituters.rb +468 -0
- data/lib/asciidoctor/table.rb +499 -0
- data/lib/asciidoctor/version.rb +1 -1
- data/test/attributes_test.rb +301 -87
- data/test/blocks_test.rb +568 -0
- data/test/document_test.rb +221 -24
- data/test/fixtures/dot.gif +0 -0
- data/test/fixtures/encoding.asciidoc +1 -0
- data/test/fixtures/include-file.asciidoc +1 -0
- data/test/fixtures/tip.gif +0 -0
- data/test/headers_test.rb +411 -43
- data/test/lexer_test.rb +265 -45
- data/test/links_test.rb +144 -3
- data/test/lists_test.rb +2252 -74
- data/test/paragraphs_test.rb +21 -30
- data/test/preamble_test.rb +24 -0
- data/test/reader_test.rb +248 -12
- data/test/renderer_test.rb +22 -0
- data/test/substitutions_test.rb +414 -0
- data/test/tables_test.rb +484 -0
- data/test/test_helper.rb +70 -6
- data/test/text_test.rb +30 -6
- metadata +64 -10
- data/lib/asciidoctor/render_templates.rb +0 -317
- data/lib/asciidoctor/string.rb +0 -12
data/test/tables_test.rb
ADDED
@@ -0,0 +1,484 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context 'Tables' do
|
4
|
+
|
5
|
+
context 'PSV' do
|
6
|
+
test 'renders simple psv table' do
|
7
|
+
input = <<-EOS
|
8
|
+
|=======
|
9
|
+
|A |B |C
|
10
|
+
|a |b |c
|
11
|
+
|1 |2 |3
|
12
|
+
|=======
|
13
|
+
EOS
|
14
|
+
cells = [%w(A B C), %w(a b c), %w(1 2 3)]
|
15
|
+
output = render_embedded_string input
|
16
|
+
assert_css 'table', output, 1
|
17
|
+
assert_css 'table.tableblock.frame-all.grid-all[style~="width: 100%;"]', output, 1
|
18
|
+
assert_css 'table > colgroup > col[style~="width: 33%;"]', output, 3
|
19
|
+
assert_css 'table tr', output, 3
|
20
|
+
assert_css 'table > tbody > tr', output, 3
|
21
|
+
assert_css 'table td', output, 9
|
22
|
+
assert_css 'table > tbody > tr > td.tableblock.halign-left.valign-top > p.tableblock', output, 9
|
23
|
+
cells.each_with_index {|row, rowi|
|
24
|
+
assert_css "table tr:nth-child(#{rowi + 1}) > td", output, row.size
|
25
|
+
assert_css "table tr:nth-child(#{rowi + 1}) > td > p", output, row.size
|
26
|
+
row.each_with_index {|cell, celli|
|
27
|
+
assert_xpath "(//tr)[#{rowi + 1}]/td[#{celli + 1}]/p[text()='#{cell}']", output, 1
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'renders caption on simple psv table' do
|
33
|
+
input = <<-EOS
|
34
|
+
.Simple psv table
|
35
|
+
|=======
|
36
|
+
|A |B |C
|
37
|
+
|a |b |c
|
38
|
+
|1 |2 |3
|
39
|
+
|=======
|
40
|
+
EOS
|
41
|
+
output = render_embedded_string input
|
42
|
+
assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1
|
43
|
+
assert_xpath '/table/caption/following-sibling::colgroup', output, 1
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'ignores escaped separators' do
|
47
|
+
input = <<-EOS
|
48
|
+
|===
|
49
|
+
|A \\| here| a \\| there
|
50
|
+
|===
|
51
|
+
EOS
|
52
|
+
output = render_embedded_string input
|
53
|
+
assert_css 'table', output, 1
|
54
|
+
assert_css 'table > colgroup > col', output, 2
|
55
|
+
assert_css 'table > tbody > tr', output, 1
|
56
|
+
assert_css 'table > tbody > tr > td', output, 2
|
57
|
+
assert_xpath '/table/tbody/tr/td[1]/p[text()="A | here"]', output, 1
|
58
|
+
assert_xpath '/table/tbody/tr/td[2]/p[text()="a | there"]', output, 1
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'performs normal substitutions on cell content' do
|
62
|
+
input = <<-EOS
|
63
|
+
:show_title: Cool new show
|
64
|
+
|===
|
65
|
+
|{show_title} |Coming soon...
|
66
|
+
|===
|
67
|
+
EOS
|
68
|
+
output = render_embedded_string input
|
69
|
+
assert_xpath '//tbody/tr/td[1]/p[text()="Cool new show"]', output, 1
|
70
|
+
assert_xpath %(//tbody/tr/td[2]/p[text()='Coming soon#{[8230].pack('U*')}']), output, 1
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'table and col width not assigned when autowidth option is specified' do
|
74
|
+
input = <<-EOS
|
75
|
+
[options="autowidth"]
|
76
|
+
|=======
|
77
|
+
|A |B |C
|
78
|
+
|a |b |c
|
79
|
+
|1 |2 |3
|
80
|
+
|=======
|
81
|
+
EOS
|
82
|
+
output = render_embedded_string input
|
83
|
+
assert_css 'table', output, 1
|
84
|
+
assert_css 'table[style*="width"]', output, 0
|
85
|
+
assert_css 'table colgroup col', output, 3
|
86
|
+
assert_css 'table colgroup col[width]', output, 0
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'first row sets number of columns when not specified' do
|
90
|
+
input = <<-EOS
|
91
|
+
|====
|
92
|
+
|first |second |third |fourth
|
93
|
+
|
94
|
+
|1 |2 |3
|
95
|
+
|4
|
96
|
+
|====
|
97
|
+
EOS
|
98
|
+
output = render_embedded_string input
|
99
|
+
assert_css 'table', output, 1
|
100
|
+
assert_css 'table > colgroup > col', output, 4
|
101
|
+
assert_css 'table > tbody > tr', output, 2
|
102
|
+
assert_css 'table > tbody > tr:nth-child(1) > td', output, 4
|
103
|
+
assert_css 'table > tbody > tr:nth-child(2) > td', output, 4
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'colspec attribute sets number of columns' do
|
107
|
+
input = <<-EOS
|
108
|
+
[cols="3*"]
|
109
|
+
|===
|
110
|
+
|A |B |C |a |b |c |1 |2 |3
|
111
|
+
|===
|
112
|
+
EOS
|
113
|
+
output = render_embedded_string input
|
114
|
+
assert_css 'table', output, 1
|
115
|
+
assert_css 'table > tbody > tr', output, 3
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'table with explicit column count can have multiple rows on a single line' do
|
119
|
+
input = <<-EOS
|
120
|
+
[cols="3*"]
|
121
|
+
|===
|
122
|
+
|one |two
|
123
|
+
|1 |2 |a |b
|
124
|
+
|===
|
125
|
+
EOS
|
126
|
+
output = render_embedded_string input
|
127
|
+
assert_css 'table', output, 1
|
128
|
+
assert_css 'table > colgroup > col', output, 3
|
129
|
+
assert_css 'table > tbody > tr', output, 2
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'table with explicit deprecated syntax column count can have multiple rows on a single line' do
|
133
|
+
input = <<-EOS
|
134
|
+
[cols="3"]
|
135
|
+
|===
|
136
|
+
|one |two
|
137
|
+
|1 |2 |a |b
|
138
|
+
|===
|
139
|
+
EOS
|
140
|
+
output = render_embedded_string input
|
141
|
+
assert_css 'table', output, 1
|
142
|
+
assert_css 'table > colgroup > col', output, 3
|
143
|
+
assert_css 'table > tbody > tr', output, 2
|
144
|
+
end
|
145
|
+
|
146
|
+
test 'table with header and footer' do
|
147
|
+
input = <<-EOS
|
148
|
+
[frame="topbot",options="header,footer"]
|
149
|
+
|===
|
150
|
+
|Item |Quantity
|
151
|
+
|Item 1 |1
|
152
|
+
|Item 2 |2
|
153
|
+
|Item 3 |3
|
154
|
+
|Total |6
|
155
|
+
|===
|
156
|
+
EOS
|
157
|
+
output = render_embedded_string input
|
158
|
+
assert_css 'table', output, 1
|
159
|
+
assert_css 'table > colgroup > col', output, 2
|
160
|
+
assert_css 'table > thead', output, 1
|
161
|
+
assert_css 'table > thead > tr', output, 1
|
162
|
+
assert_css 'table > thead > tr > th', output, 2
|
163
|
+
assert_css 'table > tfoot', output, 1
|
164
|
+
assert_css 'table > tfoot > tr', output, 1
|
165
|
+
assert_css 'table > tfoot > tr > td', output, 2
|
166
|
+
assert_css 'table > tbody', output, 1
|
167
|
+
assert_css 'table > tbody > tr', output, 3
|
168
|
+
end
|
169
|
+
|
170
|
+
test 'styles not applied to header cells' do
|
171
|
+
input = <<-EOS
|
172
|
+
[cols="1h,1s,1e",options="header,footer"]
|
173
|
+
|====
|
174
|
+
|Name |Occupation| Website
|
175
|
+
|Octocat |Social coding| http://github.com
|
176
|
+
|Name |Occupation| Website
|
177
|
+
|====
|
178
|
+
EOS
|
179
|
+
output = render_embedded_string input
|
180
|
+
assert_css 'table', output, 1
|
181
|
+
assert_css 'table > thead > tr > th', output, 3
|
182
|
+
assert_css 'table > thead > tr > th > *', output, 0
|
183
|
+
|
184
|
+
assert_css 'table > tfoot > tr > td', output, 3
|
185
|
+
assert_css 'table > tfoot > tr > td > p.header', output, 1
|
186
|
+
assert_css 'table > tfoot > tr > td > p > strong', output, 1
|
187
|
+
assert_css 'table > tfoot > tr > td > p > em', output, 1
|
188
|
+
|
189
|
+
assert_css 'table > tbody > tr > td', output, 3
|
190
|
+
assert_css 'table > tbody > tr > td > p.header', output, 1
|
191
|
+
assert_css 'table > tbody > tr > td > p > strong', output, 1
|
192
|
+
assert_css 'table > tbody > tr > td > p > em > a', output, 1
|
193
|
+
end
|
194
|
+
|
195
|
+
test 'supports horizontal and vertical source data with blank lines and table header' do
|
196
|
+
input = <<-EOS
|
197
|
+
.Horizontal and vertical source data
|
198
|
+
[width="80%",cols="3,^2,^2,10",options="header"]
|
199
|
+
|===
|
200
|
+
|Date |Duration |Avg HR |Notes
|
201
|
+
|
202
|
+
|22-Aug-08 |10:24 | 157 |
|
203
|
+
Worked out MSHR (max sustainable heart rate) by going hard
|
204
|
+
for this interval.
|
205
|
+
|
206
|
+
|22-Aug-08 |23:03 | 152 |
|
207
|
+
Back-to-back with previous interval.
|
208
|
+
|
209
|
+
|24-Aug-08 |40:00 | 145 |
|
210
|
+
Moderately hard interspersed with 3x 3min intervals (2 min
|
211
|
+
hard + 1 min really hard taking the HR up to 160).
|
212
|
+
|
213
|
+
I am getting in shape!
|
214
|
+
|
215
|
+
|===
|
216
|
+
EOS
|
217
|
+
output = render_embedded_string input
|
218
|
+
assert_css 'table', output, 1
|
219
|
+
assert_css 'table[style~="width: 80%;"]', output, 1
|
220
|
+
assert_xpath '/table/caption[@class="title"][text()="Horizontal and vertical source data"]', output, 1
|
221
|
+
assert_css 'table > colgroup > col', output, 4
|
222
|
+
assert_css 'table > colgroup > col:nth-child(1)[@style~="width: 17%;"]', output, 1
|
223
|
+
assert_css 'table > colgroup > col:nth-child(2)[@style~="width: 11%;"]', output, 1
|
224
|
+
assert_css 'table > colgroup > col:nth-child(3)[@style~="width: 11%;"]', output, 1
|
225
|
+
assert_css 'table > colgroup > col:nth-child(4)[@style~="width: 58%;"]', output, 1
|
226
|
+
assert_css 'table > thead', output, 1
|
227
|
+
assert_css 'table > thead > tr', output, 1
|
228
|
+
assert_css 'table > thead > tr > th', output, 4
|
229
|
+
assert_css 'table > tbody > tr', output, 3
|
230
|
+
assert_css 'table > tbody > tr:nth-child(1) > td', output, 4
|
231
|
+
assert_css 'table > tbody > tr:nth-child(2) > td', output, 4
|
232
|
+
assert_css 'table > tbody > tr:nth-child(3) > td', output, 4
|
233
|
+
assert_xpath "/table/tbody/tr[1]/td[4]/p[text()='Worked out MSHR (max sustainable heart rate) by going hard\nfor this interval.']", output, 1
|
234
|
+
assert_css 'table > tbody > tr:nth-child(3) > td:nth-child(4) > p', output, 2
|
235
|
+
assert_xpath '/table/tbody/tr[3]/td[4]/p[2][text()="I am getting in shape!"]', output, 1
|
236
|
+
end
|
237
|
+
|
238
|
+
test 'spans, alignments and styles' do
|
239
|
+
input = <<-EOS
|
240
|
+
[cols="e,m,^,>s",width="25%"]
|
241
|
+
|===
|
242
|
+
|1 >s|2 |3 |4
|
243
|
+
^|5 2.2+^.^|6 .3+<.>m|7
|
244
|
+
^|8
|
245
|
+
|9 2+>|10
|
246
|
+
|===
|
247
|
+
EOS
|
248
|
+
output = render_embedded_string input
|
249
|
+
assert_css 'table', output, 1
|
250
|
+
assert_css 'table > colgroup > col[style~="width: 25%;"]', output, 4
|
251
|
+
assert_css 'table > tbody > tr', output, 4
|
252
|
+
assert_css 'table > tbody > tr > td', output, 10
|
253
|
+
assert_css 'table > tbody > tr:nth-child(1) > td', output, 4
|
254
|
+
assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
|
255
|
+
assert_css 'table > tbody > tr:nth-child(3) > td', output, 1
|
256
|
+
assert_css 'table > tbody > tr:nth-child(4) > td', output, 2
|
257
|
+
|
258
|
+
assert_css 'table tr:nth-child(1) > td:nth-child(1).halign-left.valign-top p em', output, 1
|
259
|
+
assert_css 'table tr:nth-child(1) > td:nth-child(2).halign-right.valign-top p strong', output, 1
|
260
|
+
assert_css 'table tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p', output, 1
|
261
|
+
assert_css 'table tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p *', output, 0
|
262
|
+
assert_css 'table tr:nth-child(1) > td:nth-child(4).halign-right.valign-top p strong', output, 1
|
263
|
+
|
264
|
+
assert_css 'table tr:nth-child(2) > td:nth-child(1).halign-center.valign-top p em', output, 1
|
265
|
+
assert_css 'table tr:nth-child(2) > td:nth-child(2).halign-center.valign-middle[colspan="2"][rowspan="2"] p tt', output, 1
|
266
|
+
assert_css 'table tr:nth-child(2) > td:nth-child(3).halign-left.valign-bottom[rowspan="3"] p tt', output, 1
|
267
|
+
|
268
|
+
assert_css 'table tr:nth-child(3) > td:nth-child(1).halign-center.valign-top p em', output, 1
|
269
|
+
|
270
|
+
assert_css 'table tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p em', output, 1
|
271
|
+
assert_css 'table tr:nth-child(4) > td:nth-child(2).halign-right.valign-top[colspan="2"] p tt', output, 1
|
272
|
+
end
|
273
|
+
|
274
|
+
test 'supports repeating cells' do
|
275
|
+
input = <<-EOS
|
276
|
+
|===
|
277
|
+
3*|A
|
278
|
+
|1 3*|2
|
279
|
+
|b |c
|
280
|
+
|===
|
281
|
+
EOS
|
282
|
+
output = render_embedded_string input
|
283
|
+
assert_css 'table', output, 1
|
284
|
+
assert_css 'table > colgroup > col', output, 3
|
285
|
+
assert_css 'table > tbody > tr', output, 3
|
286
|
+
assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
|
287
|
+
assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
|
288
|
+
assert_css 'table > tbody > tr:nth-child(3) > td', output, 3
|
289
|
+
|
290
|
+
assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A"]', output, 1
|
291
|
+
assert_xpath '/table/tbody/tr[1]/td[2]/p[text()="A"]', output, 1
|
292
|
+
assert_xpath '/table/tbody/tr[1]/td[3]/p[text()="A"]', output, 1
|
293
|
+
|
294
|
+
assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="1"]', output, 1
|
295
|
+
assert_xpath '/table/tbody/tr[2]/td[2]/p[text()="2"]', output, 1
|
296
|
+
assert_xpath '/table/tbody/tr[2]/td[3]/p[text()="2"]', output, 1
|
297
|
+
|
298
|
+
assert_xpath '/table/tbody/tr[3]/td[1]/p[text()="2"]', output, 1
|
299
|
+
assert_xpath '/table/tbody/tr[3]/td[2]/p[text()="b"]', output, 1
|
300
|
+
assert_xpath '/table/tbody/tr[3]/td[3]/p[text()="c"]', output, 1
|
301
|
+
end
|
302
|
+
|
303
|
+
test 'paragraph, verse and literal content' do
|
304
|
+
input = <<-EOS
|
305
|
+
[cols=",^v,^l",options="header"]
|
306
|
+
|===
|
307
|
+
|Paragraphs |Verse |Literal
|
308
|
+
3*|The discussion about what is good,
|
309
|
+
what is beautiful, what is noble,
|
310
|
+
what is pure, and what is true
|
311
|
+
could always go on.
|
312
|
+
|
313
|
+
Why is that important?
|
314
|
+
Why would I like to do that?
|
315
|
+
|
316
|
+
Because that's the only conversation worth having.
|
317
|
+
|
318
|
+
And whether it goes on or not after I die, I don't know.
|
319
|
+
But, I do know that it is the conversation I want to have while I am still alive.
|
320
|
+
|
321
|
+
Which means that to me the offer of certainty,
|
322
|
+
the offer of complete security,
|
323
|
+
the offer of an impermeable faith that can't give way
|
324
|
+
is an offer of something not worth having.
|
325
|
+
|
326
|
+
I want to live my life taking the risk all the time
|
327
|
+
that I don't know anything like enough yet...
|
328
|
+
that I haven't understood enough...
|
329
|
+
that I can't know enough...
|
330
|
+
that I am always hungrily operating on the margins
|
331
|
+
of a potentially great harvest of future knowledge and wisdom.
|
332
|
+
|
333
|
+
I wouldn't have it any other way.
|
334
|
+
|===
|
335
|
+
EOS
|
336
|
+
output = render_embedded_string input
|
337
|
+
assert_css 'table', output, 1
|
338
|
+
assert_css 'table > colgroup > col', output, 3
|
339
|
+
assert_css 'table > thead', output, 1
|
340
|
+
assert_css 'table > thead > tr', output, 1
|
341
|
+
assert_css 'table > thead > tr > th', output, 3
|
342
|
+
assert_css 'table > tbody', output, 1
|
343
|
+
assert_css 'table > tbody > tr', output, 1
|
344
|
+
assert_css 'table > tbody > tr > td', output, 3
|
345
|
+
assert_css 'table > tbody > tr > td:nth-child(1).halign-left.valign-top > p.tableblock', output, 7
|
346
|
+
assert_css 'table > tbody > tr > td:nth-child(2).halign-center.valign-top > div.verse', output, 1
|
347
|
+
verse = xmlnodes_at_css 'table > tbody > tr > td:nth-child(2).halign-center.valign-top > div.verse', output, 1
|
348
|
+
assert_equal 26, verse.text.lines.entries.size
|
349
|
+
assert_css 'table > tbody > tr > td:nth-child(3).halign-center.valign-top > div.literal > pre', output, 1
|
350
|
+
literal = xmlnodes_at_css 'table > tbody > tr > td:nth-child(3).halign-center.valign-top > div.literal > pre', output, 1
|
351
|
+
assert_equal 26, literal.text.lines.entries.size
|
352
|
+
end
|
353
|
+
|
354
|
+
test 'asciidoc content' do
|
355
|
+
input = <<-EOS
|
356
|
+
[cols="1e,1,5a",frame="topbot",options="header"]
|
357
|
+
|===
|
358
|
+
|Name |Backends |Description
|
359
|
+
|
360
|
+
|badges |xhtml11, html5 |
|
361
|
+
Link badges ('XHTML 1.1' and 'CSS') in document footers.
|
362
|
+
|
363
|
+
NOTE: The path names of images, icons and scripts are relative path
|
364
|
+
names to the output document not the source document.
|
365
|
+
|
366
|
+
|[[X97]] docinfo, docinfo1, docinfo2 |All backends |
|
367
|
+
These three attributes control which document information
|
368
|
+
files will be included in the the header of the output file:
|
369
|
+
|
370
|
+
docinfo:: Include `<filename>-docinfo.<ext>`
|
371
|
+
docinfo1:: Include `docinfo.<ext>`
|
372
|
+
docinfo2:: Include `docinfo.<ext>` and `<filename>-docinfo.<ext>`
|
373
|
+
|
374
|
+
Where `<filename>` is the file name (sans extension) of the AsciiDoc
|
375
|
+
input file and `<ext>` is `.html` for HTML outputs or `.xml` for
|
376
|
+
DocBook outputs. If the input file is the standard input then the
|
377
|
+
output file name is used.
|
378
|
+
|===
|
379
|
+
EOS
|
380
|
+
doc = document_from_string input
|
381
|
+
table = doc.blocks.first
|
382
|
+
assert !table.nil?
|
383
|
+
tbody = table.rows.body
|
384
|
+
assert_equal 2, tbody.size
|
385
|
+
body_cell_1_3 = tbody[0][2]
|
386
|
+
assert !body_cell_1_3.inner_document.nil?
|
387
|
+
assert body_cell_1_3.inner_document.nested?
|
388
|
+
assert_equal doc, body_cell_1_3.inner_document.parent_document
|
389
|
+
assert_equal doc.renderer, body_cell_1_3.inner_document.renderer
|
390
|
+
output = doc.render
|
391
|
+
|
392
|
+
assert_css 'table > tbody > tr', output, 2
|
393
|
+
assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3) div.admonitionblock', output, 1
|
394
|
+
assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(3) div.dlist', output, 1
|
395
|
+
end
|
396
|
+
|
397
|
+
test 'nested table' do
|
398
|
+
input = <<-EOS
|
399
|
+
[cols="1,2a"]
|
400
|
+
|===
|
401
|
+
|Normal cell
|
402
|
+
|
403
|
+
|Cell with nested table
|
404
|
+
|
405
|
+
[cols="2,1"]
|
406
|
+
!===
|
407
|
+
!Nested table cell 1 !Nested table cell 2
|
408
|
+
!===
|
409
|
+
|
410
|
+
|===
|
411
|
+
EOS
|
412
|
+
output = render_embedded_string input
|
413
|
+
assert_css 'table', output, 2
|
414
|
+
assert_css 'table table', output, 1
|
415
|
+
assert_css 'table table', output, 1
|
416
|
+
assert_css 'table > tbody > tr > td:nth-child(2) table', output, 1
|
417
|
+
assert_css 'table > tbody > tr > td:nth-child(2) table > tbody > tr > td', output, 2
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
context 'DSV' do
|
422
|
+
|
423
|
+
test 'renders simple dsv table' do
|
424
|
+
input = <<-EOS
|
425
|
+
[width="75%",format="dsv"]
|
426
|
+
|===
|
427
|
+
root:x:0:0:root:/root:/bin/bash
|
428
|
+
bin:x:1:1:bin:/bin:/sbin/nologin
|
429
|
+
mysql:x:27:27:MySQL\\:Server:/var/lib/mysql:/bin/bash
|
430
|
+
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
|
431
|
+
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
|
432
|
+
nobody:x:99:99:Nobody:/:/sbin/nologin
|
433
|
+
|===
|
434
|
+
EOS
|
435
|
+
output = render_embedded_string input
|
436
|
+
assert_css 'table', output, 1
|
437
|
+
assert_css 'table > colgroup > col[style~="width: 14%;"]', output, 7
|
438
|
+
assert_css 'table > tbody > tr', output, 6
|
439
|
+
assert_xpath '//tr[4]/td[5]/p/text()', output, 0
|
440
|
+
assert_xpath '//tr[3]/td[5]/p[text()="MySQL:Server"]', output, 1
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
context 'CSV' do
|
445
|
+
|
446
|
+
test 'mixed unquoted records and quoted records with escaped quotes, commas and wrapped lines' do
|
447
|
+
input = <<-EOS
|
448
|
+
[format="csv",options="header"]
|
449
|
+
|===
|
450
|
+
Year,Make,Model,Description,Price
|
451
|
+
1997,Ford,E350,"ac, abs, moon",3000.00
|
452
|
+
1999,Chevy,"Venture ""Extended Edition""","",4900.00
|
453
|
+
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
|
454
|
+
1996,Jeep,Grand Cherokee,"MUST SELL!
|
455
|
+
air, moon roof, loaded",4799.00
|
456
|
+
|===
|
457
|
+
EOS
|
458
|
+
output = render_embedded_string input
|
459
|
+
assert_css 'table', output, 1
|
460
|
+
assert_css 'table > colgroup > col[style~="width: 20%;"]', output, 5
|
461
|
+
assert_css 'table > thead > tr', output, 1
|
462
|
+
assert_css 'table > tbody > tr', output, 4
|
463
|
+
assert_xpath '((//tbody/tr)[1]/td)[4]/p[text()="ac, abs, moon"]', output, 1
|
464
|
+
assert_xpath %(((//tbody/tr)[2]/td)[3]/p[text()='Venture "Extended Edition"']), output, 1
|
465
|
+
assert_xpath '((//tbody/tr)[4]/td)[4]/p[text()="MUST SELL! air, moon roof, loaded"]', output, 1
|
466
|
+
end
|
467
|
+
|
468
|
+
test 'custom separator' do
|
469
|
+
input = <<-EOS
|
470
|
+
[format="csv", separator=";"]
|
471
|
+
|===
|
472
|
+
a;b;c
|
473
|
+
1;2;3
|
474
|
+
|===
|
475
|
+
EOS
|
476
|
+
output = render_embedded_string input
|
477
|
+
assert_css 'table', output, 1
|
478
|
+
assert_css 'table > colgroup > col', output, 3
|
479
|
+
assert_css 'table > tbody > tr', output, 2
|
480
|
+
assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
|
481
|
+
assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|