asciidoctor 1.5.8 → 2.0.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +162 -17
  3. data/LICENSE +1 -1
  4. data/README-de.adoc +12 -13
  5. data/README-fr.adoc +11 -12
  6. data/README-jp.adoc +11 -12
  7. data/README-zh_CN.adoc +12 -13
  8. data/README.adoc +6 -7
  9. data/asciidoctor.gemspec +19 -24
  10. data/bin/asciidoctor +5 -4
  11. data/data/reference/syntax.adoc +283 -0
  12. data/data/stylesheets/asciidoctor-default.css +56 -52
  13. data/data/stylesheets/coderay-asciidoctor.css +7 -9
  14. data/lib/asciidoctor.rb +171 -232
  15. data/lib/asciidoctor/abstract_block.rb +96 -105
  16. data/lib/asciidoctor/abstract_node.rb +118 -139
  17. data/lib/asciidoctor/attribute_list.rb +10 -14
  18. data/lib/asciidoctor/block.rb +20 -19
  19. data/lib/asciidoctor/callouts.rb +4 -2
  20. data/lib/asciidoctor/cli.rb +3 -2
  21. data/lib/asciidoctor/cli/invoker.rb +14 -21
  22. data/lib/asciidoctor/cli/options.rb +64 -54
  23. data/lib/asciidoctor/converter.rb +357 -185
  24. data/lib/asciidoctor/converter/composite.rb +40 -48
  25. data/lib/asciidoctor/converter/docbook5.rb +604 -640
  26. data/lib/asciidoctor/converter/html5.rb +949 -963
  27. data/lib/asciidoctor/converter/manpage.rb +569 -548
  28. data/lib/asciidoctor/converter/template.rb +231 -272
  29. data/lib/asciidoctor/core_ext.rb +5 -18
  30. data/lib/asciidoctor/core_ext/float/truncate.rb +19 -0
  31. data/lib/asciidoctor/core_ext/match_data/names.rb +7 -0
  32. data/lib/asciidoctor/core_ext/nil_or_empty.rb +1 -0
  33. data/lib/asciidoctor/core_ext/regexp/is_match.rb +4 -2
  34. data/lib/asciidoctor/document.rb +399 -377
  35. data/lib/asciidoctor/extensions.rb +72 -140
  36. data/lib/asciidoctor/helpers.rb +122 -83
  37. data/lib/asciidoctor/inline.rb +5 -1
  38. data/lib/asciidoctor/list.rb +13 -11
  39. data/lib/asciidoctor/logging.rb +17 -16
  40. data/lib/asciidoctor/parser.rb +390 -423
  41. data/lib/asciidoctor/path_resolver.rb +10 -5
  42. data/lib/asciidoctor/reader.rb +286 -263
  43. data/lib/asciidoctor/rouge_ext.rb +39 -0
  44. data/lib/asciidoctor/section.rb +9 -8
  45. data/lib/asciidoctor/stylesheets.rb +19 -37
  46. data/lib/asciidoctor/substitutors.rb +364 -509
  47. data/lib/asciidoctor/syntax_highlighter.rb +238 -0
  48. data/lib/asciidoctor/syntax_highlighter/coderay.rb +87 -0
  49. data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +26 -0
  50. data/lib/asciidoctor/syntax_highlighter/html_pipeline.rb +10 -0
  51. data/lib/asciidoctor/syntax_highlighter/prettify.rb +27 -0
  52. data/lib/asciidoctor/syntax_highlighter/pygments.rb +149 -0
  53. data/lib/asciidoctor/syntax_highlighter/rouge.rb +129 -0
  54. data/lib/asciidoctor/table.rb +73 -66
  55. data/lib/asciidoctor/timings.rb +4 -2
  56. data/lib/asciidoctor/version.rb +2 -1
  57. data/lib/asciidoctor/writer.rb +30 -0
  58. data/man/asciidoctor.1 +19 -15
  59. data/man/asciidoctor.adoc +14 -12
  60. metadata +69 -216
  61. data/CONTRIBUTING.adoc +0 -185
  62. data/Gemfile +0 -60
  63. data/Rakefile +0 -129
  64. data/bin/asciidoctor-safe +0 -15
  65. data/features/open_block.feature +0 -92
  66. data/features/pass_block.feature +0 -66
  67. data/features/step_definitions.rb +0 -49
  68. data/features/text_formatting.feature +0 -57
  69. data/features/xref.feature +0 -1039
  70. data/lib/asciidoctor/converter/base.rb +0 -59
  71. data/lib/asciidoctor/converter/docbook45.rb +0 -93
  72. data/lib/asciidoctor/converter/factory.rb +0 -226
  73. data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +0 -6
  74. data/lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb +0 -5
  75. data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +0 -4
  76. data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +0 -6
  77. data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +0 -5
  78. data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +0 -6
  79. data/lib/asciidoctor/core_ext/1.8.7/string/limit_bytesize.rb +0 -29
  80. data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +0 -6
  81. data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +0 -6
  82. data/lib/asciidoctor/core_ext/string/limit_bytesize.rb +0 -10
  83. data/test/api_test.rb +0 -1240
  84. data/test/attribute_list_test.rb +0 -242
  85. data/test/attributes_test.rb +0 -1623
  86. data/test/blocks_test.rb +0 -3870
  87. data/test/converter_test.rb +0 -470
  88. data/test/document_test.rb +0 -1853
  89. data/test/extensions_test.rb +0 -1560
  90. data/test/fixtures/asciidoc_index.txt +0 -521
  91. data/test/fixtures/basic-docinfo-footer.html +0 -6
  92. data/test/fixtures/basic-docinfo-footer.xml +0 -8
  93. data/test/fixtures/basic-docinfo.html +0 -1
  94. data/test/fixtures/basic-docinfo.xml +0 -4
  95. data/test/fixtures/basic.asciidoc +0 -5
  96. data/test/fixtures/chapter-a.adoc +0 -3
  97. data/test/fixtures/child-include.adoc +0 -5
  98. data/test/fixtures/circle.svg +0 -9
  99. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
  100. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
  101. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
  102. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
  103. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
  104. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
  105. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
  106. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
  107. data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
  108. data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
  109. data/test/fixtures/docinfo-footer.html +0 -1
  110. data/test/fixtures/docinfo-footer.xml +0 -9
  111. data/test/fixtures/docinfo.html +0 -1
  112. data/test/fixtures/docinfo.xml +0 -3
  113. data/test/fixtures/doctime-localtime.adoc +0 -2
  114. data/test/fixtures/dot.gif +0 -0
  115. data/test/fixtures/encoding.asciidoc +0 -13
  116. data/test/fixtures/file-with-missing-include.adoc +0 -1
  117. data/test/fixtures/grandchild-include.adoc +0 -3
  118. data/test/fixtures/hello-asciidoctor.pdf +0 -69
  119. data/test/fixtures/include-file.asciidoc +0 -24
  120. data/test/fixtures/include-file.jsx +0 -8
  121. data/test/fixtures/include-file.ml +0 -3
  122. data/test/fixtures/include-file.xml +0 -5
  123. data/test/fixtures/lists.adoc +0 -96
  124. data/test/fixtures/master.adoc +0 -5
  125. data/test/fixtures/mismatched-end-tag.adoc +0 -7
  126. data/test/fixtures/other-chapters.adoc +0 -11
  127. data/test/fixtures/outer-include.adoc +0 -5
  128. data/test/fixtures/parent-include-restricted.adoc +0 -5
  129. data/test/fixtures/parent-include.adoc +0 -5
  130. data/test/fixtures/sample.asciidoc +0 -30
  131. data/test/fixtures/section-a.adoc +0 -4
  132. data/test/fixtures/stylesheets/custom.css +0 -3
  133. data/test/fixtures/subdir/index.adoc +0 -3
  134. data/test/fixtures/subdir/inner-include.adoc +0 -3
  135. data/test/fixtures/subdir/middle-include.adoc +0 -5
  136. data/test/fixtures/subs-docinfo.html +0 -2
  137. data/test/fixtures/subs.adoc +0 -6
  138. data/test/fixtures/tagged-class-enclosed.rb +0 -25
  139. data/test/fixtures/tagged-class.rb +0 -23
  140. data/test/fixtures/tip.gif +0 -0
  141. data/test/fixtures/unclosed-tag.adoc +0 -3
  142. data/test/fixtures/unexpected-end-tag.adoc +0 -4
  143. data/test/invoker_test.rb +0 -745
  144. data/test/links_test.rb +0 -855
  145. data/test/lists_test.rb +0 -5151
  146. data/test/logger_test.rb +0 -211
  147. data/test/manpage_test.rb +0 -660
  148. data/test/options_test.rb +0 -262
  149. data/test/paragraphs_test.rb +0 -562
  150. data/test/parser_test.rb +0 -742
  151. data/test/paths_test.rb +0 -395
  152. data/test/preamble_test.rb +0 -173
  153. data/test/reader_test.rb +0 -2161
  154. data/test/sections_test.rb +0 -3575
  155. data/test/substitutions_test.rb +0 -2066
  156. data/test/tables_test.rb +0 -2036
  157. data/test/test_helper.rb +0 -447
  158. data/test/text_test.rb +0 -309
@@ -1,2036 +0,0 @@
1
- # encoding: UTF-8
2
- unless defined? ASCIIDOCTOR_PROJECT_DIR
3
- $: << File.dirname(__FILE__); $:.uniq!
4
- require 'test_helper'
5
- end
6
-
7
- context 'Tables' do
8
-
9
- context 'PSV' do
10
- test 'converts simple psv table' do
11
- input = <<-EOS
12
- |=======
13
- |A |B |C
14
- |a |b |c
15
- |1 |2 |3
16
- |=======
17
- EOS
18
- cells = [%w(A B C), %w(a b c), %w(1 2 3)]
19
- doc = document_from_string input, :header_footer => false
20
- table = doc.blocks[0]
21
- assert 100, table.columns.map {|col| col.attributes['colpcwidth'] }.reduce(:+)
22
- output = doc.convert
23
- assert_css 'table', output, 1
24
- assert_css 'table.tableblock.frame-all.grid-all.stretch', output, 1
25
- assert_css 'table > colgroup > col[style*="width: 33.3333%"]', output, 2
26
- assert_css 'table > colgroup > col:last-of-type[style*="width: 33.3334%"]', output, 1
27
- assert_css 'table tr', output, 3
28
- assert_css 'table > tbody > tr', output, 3
29
- assert_css 'table td', output, 9
30
- assert_css 'table > tbody > tr > td.tableblock.halign-left.valign-top > p.tableblock', output, 9
31
- cells.each_with_index {|row, rowi|
32
- assert_css "table > tbody > tr:nth-child(#{rowi + 1}) > td", output, row.size
33
- assert_css "table > tbody > tr:nth-child(#{rowi + 1}) > td > p", output, row.size
34
- row.each_with_index {|cell, celli|
35
- assert_xpath "(//tr)[#{rowi + 1}]/td[#{celli + 1}]/p[text()='#{cell}']", output, 1
36
- }
37
- }
38
- end
39
-
40
- test 'should add direction CSS class if float attribute is set on table' do
41
- input = <<-EOS
42
- [float=left]
43
- |=======
44
- |A |B |C
45
- |a |b |c
46
- |1 |2 |3
47
- |=======
48
- EOS
49
-
50
- output = convert_string_to_embedded input
51
- assert_css 'table.left', output, 1
52
- end
53
-
54
- test 'should set stripes class if stripes option is set' do
55
- input = <<-EOS
56
- [stripes=odd]
57
- |=======
58
- |A |B |C
59
- |a |b |c
60
- |1 |2 |3
61
- |=======
62
- EOS
63
-
64
- output = convert_string_to_embedded input
65
- assert_css 'table.stripes-odd', output, 1
66
- end
67
-
68
- test 'outputs a caption on simple psv table' do
69
- input = <<-EOS
70
- .Simple psv table
71
- |=======
72
- |A |B |C
73
- |a |b |c
74
- |1 |2 |3
75
- |=======
76
- EOS
77
- output = convert_string_to_embedded input
78
- assert_xpath '/table/caption[@class="title"][text()="Table 1. Simple psv table"]', output, 1
79
- assert_xpath '/table/caption/following-sibling::colgroup', output, 1
80
- end
81
-
82
- test 'only increments table counter for tables that have a title' do
83
- input = <<-EOS
84
- .First numbered table
85
- |=======
86
- |1 |2 |3
87
- |=======
88
-
89
- |=======
90
- |4 |5 |6
91
- |=======
92
-
93
- .Second numbered table
94
- |=======
95
- |7 |8 |9
96
- |=======
97
- EOS
98
- output = convert_string_to_embedded input
99
- assert_css 'table:root', output, 3
100
- assert_xpath '(/table)[1]/caption', output, 1
101
- assert_xpath '(/table)[1]/caption[text()="Table 1. First numbered table"]', output, 1
102
- assert_xpath '(/table)[2]/caption', output, 0
103
- assert_xpath '(/table)[3]/caption', output, 1
104
- assert_xpath '(/table)[3]/caption[text()="Table 2. Second numbered table"]', output, 1
105
- end
106
-
107
- test 'uses explicit caption in front of title in place of default caption and number' do
108
- input = <<-EOS
109
- [caption="All the Data. "]
110
- .Simple psv table
111
- |=======
112
- |A |B |C
113
- |a |b |c
114
- |1 |2 |3
115
- |=======
116
- EOS
117
- output = convert_string_to_embedded input
118
- assert_xpath '/table/caption[@class="title"][text()="All the Data. Simple psv table"]', output, 1
119
- assert_xpath '/table/caption/following-sibling::colgroup', output, 1
120
- end
121
-
122
- test 'disables caption when caption attribute on table is empty' do
123
- input = <<-EOS
124
- [caption=]
125
- .Simple psv table
126
- |=======
127
- |A |B |C
128
- |a |b |c
129
- |1 |2 |3
130
- |=======
131
- EOS
132
- output = convert_string_to_embedded input
133
- assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1
134
- assert_xpath '/table/caption/following-sibling::colgroup', output, 1
135
- end
136
-
137
- test 'disables caption when caption attribute on table is empty string' do
138
- input = <<-EOS
139
- [caption=""]
140
- .Simple psv table
141
- |=======
142
- |A |B |C
143
- |a |b |c
144
- |1 |2 |3
145
- |=======
146
- EOS
147
- output = convert_string_to_embedded input
148
- assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1
149
- assert_xpath '/table/caption/following-sibling::colgroup', output, 1
150
- end
151
-
152
- test 'disables caption on table when table-caption document attribute is unset' do
153
- input = <<-EOS
154
- :!table-caption:
155
-
156
- .Simple psv table
157
- |=======
158
- |A |B |C
159
- |a |b |c
160
- |1 |2 |3
161
- |=======
162
- EOS
163
- output = convert_string_to_embedded input
164
- assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1
165
- assert_xpath '/table/caption/following-sibling::colgroup', output, 1
166
- end
167
-
168
- test 'ignores escaped separators' do
169
- input = <<-EOS
170
- |===
171
- |A \\| here| a \\| there
172
- |===
173
- EOS
174
- output = convert_string_to_embedded input
175
- assert_css 'table', output, 1
176
- assert_css 'table > colgroup > col', output, 2
177
- assert_css 'table > tbody > tr', output, 1
178
- assert_css 'table > tbody > tr > td', output, 2
179
- assert_xpath '/table/tbody/tr/td[1]/p[text()="A | here"]', output, 1
180
- assert_xpath '/table/tbody/tr/td[2]/p[text()="a | there"]', output, 1
181
- end
182
-
183
- test 'preserves escaped delimiters at the end of the line' do
184
- input = <<-EOS
185
- [%header,cols="1,1"]
186
- |===
187
- |A |B\\|
188
- |A1 |B1\\|
189
- |A2 |B2\\|
190
- |===
191
- EOS
192
- output = convert_string_to_embedded input
193
- assert_css 'table', output, 1
194
- assert_css 'table > colgroup > col', output, 2
195
- assert_css 'table > thead > tr', output, 1
196
- assert_css 'table > thead > tr:nth-child(1) > th', output, 2
197
- assert_xpath '/table/thead/tr[1]/th[2][text()="B|"]', output, 1
198
- assert_css 'table > tbody > tr', output, 2
199
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 2
200
- assert_xpath '/table/tbody/tr[1]/td[2]/p[text()="B1|"]', output, 1
201
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 2
202
- assert_xpath '/table/tbody/tr[2]/td[2]/p[text()="B2|"]', output, 1
203
- end
204
-
205
- test 'should treat trailing pipe as an empty cell' do
206
- input = <<-EOS
207
- |===
208
- |A1 |
209
- |B1 |B2
210
- |C1 |C2
211
- |===
212
- EOS
213
- output = convert_string_to_embedded input
214
- assert_css 'table', output, 1
215
- assert_css 'table > colgroup > col', output, 2
216
- assert_css 'table > tbody > tr', output, 3
217
- assert_xpath '/table/tbody/tr[1]/td', output, 2
218
- assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1
219
- assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0
220
- assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1
221
- end
222
-
223
- test 'should auto recover with warning if missing leading separator on first cell' do
224
- input = <<-EOS
225
- |===
226
- A | here| a | there
227
- | x
228
- | y
229
- | z
230
- | end
231
- |===
232
- EOS
233
- using_memory_logger do |logger|
234
- output = convert_string_to_embedded input
235
- assert_css 'table', output, 1
236
- assert_css 'table > tbody > tr', output, 2
237
- assert_css 'table > tbody > tr > td', output, 8
238
- assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A"]', output, 1
239
- assert_xpath '/table/tbody/tr[1]/td[2]/p[text()="here"]', output, 1
240
- assert_xpath '/table/tbody/tr[1]/td[3]/p[text()="a"]', output, 1
241
- assert_xpath '/table/tbody/tr[1]/td[4]/p[text()="there"]', output, 1
242
- assert_message logger, :ERROR, '<stdin>: line 2: table missing leading separator; recovering automatically', Hash
243
- end
244
- end
245
-
246
- test 'performs normal substitutions on cell content' do
247
- input = <<-EOS
248
- :show_title: Cool new show
249
- |===
250
- |{show_title} |Coming soon...
251
- |===
252
- EOS
253
- output = convert_string_to_embedded input
254
- assert_xpath '//tbody/tr/td[1]/p[text()="Cool new show"]', output, 1
255
- assert_xpath %(//tbody/tr/td[2]/p[text()='Coming soon#{decode_char 8230}#{decode_char 8203}']), output, 1
256
- end
257
-
258
- test 'should only substitute specialchars for literal table cells' do
259
- input = <<-EOS
260
- |===
261
- l|one
262
- *two*
263
- three
264
- <four>
265
- |===
266
- EOS
267
- output = convert_string_to_embedded input
268
- result = xmlnodes_at_xpath('/table//pre', output, 1)
269
- assert_equal %(<pre>one\n*two*\nthree\n&lt;four&gt;</pre>), result.to_s
270
- end
271
-
272
- test 'should preserving leading spaces but not leading endlines or trailing spaces in literal table cells' do
273
- input = <<-EOS
274
- [cols=2*]
275
- |===
276
- l|
277
- one
278
- two
279
- three
280
-
281
- | normal
282
- |===
283
- EOS
284
- output = convert_string_to_embedded input
285
- result = xmlnodes_at_xpath('/table//pre', output, 1)
286
- assert_equal %(<pre> one\n two\nthree</pre>), result.to_s
287
- end
288
-
289
- test 'should preserving leading spaces but not leading endlines or trailing spaces in verse table cells' do
290
- input = <<-EOS
291
- [cols=2*]
292
- |===
293
- v|
294
- one
295
- two
296
- three
297
-
298
- | normal
299
- |===
300
- EOS
301
- output = convert_string_to_embedded input
302
- result = xmlnodes_at_xpath('/table//div[@class="verse"]', output, 1)
303
- assert_equal %(<div class="verse"> one\n two\nthree</div>), result.to_s
304
- end
305
-
306
- test 'table and column width not assigned when autowidth option is specified' do
307
- input = <<-EOS
308
- [options="autowidth"]
309
- |=======
310
- |A |B |C
311
- |a |b |c
312
- |1 |2 |3
313
- |=======
314
- EOS
315
- output = convert_string_to_embedded input
316
- assert_css 'table', output, 1
317
- assert_css 'table.fit-content', output, 1
318
- assert_css 'table[style*="width"]', output, 0
319
- assert_css 'table colgroup col', output, 3
320
- assert_css 'table colgroup col[style*="width"]', output, 0
321
- end
322
-
323
- test 'does not assign column width for autowidth columns in HTML output' do
324
- input = <<-EOS
325
- [cols="15%,3*~"]
326
- |=======
327
- |A |B |C |D
328
- |a |b |c |d
329
- |1 |2 |3 |4
330
- |=======
331
- EOS
332
- doc = document_from_string input
333
- table_row0 = doc.blocks[0].rows.body[0]
334
- assert_equal 15, table_row0[0].attributes['width']
335
- assert_equal 15, table_row0[0].attributes['colpcwidth']
336
- refute_equal '', table_row0[0].attributes['autowidth-option']
337
- expected_pcwidths = { 1 => 28.3333, 2 => 28.3333, 3 => 28.3334 }
338
- (1..3).each do |i|
339
- assert_equal 28.3333, table_row0[i].attributes['width']
340
- assert_equal expected_pcwidths[i], table_row0[i].attributes['colpcwidth']
341
- assert_equal '', table_row0[i].attributes['autowidth-option']
342
- end
343
- output = doc.convert :header_footer => false
344
- assert_css 'table', output, 1
345
- assert_css 'table colgroup col', output, 4
346
- assert_css 'table colgroup col[style]', output, 1
347
- assert_css 'table colgroup col[style*="width: 15%"]', output, 1
348
- end
349
-
350
- test 'can assign autowidth to all columns even when table has a width' do
351
- input = <<-EOS
352
- [cols="4*~",width=50%]
353
- |=======
354
- |A |B |C |D
355
- |a |b |c |d
356
- |1 |2 |3 |4
357
- |=======
358
- EOS
359
- doc = document_from_string input
360
- table_row0 = doc.blocks[0].rows.body[0]
361
- (0..3).each do |i|
362
- assert_equal 25, table_row0[i].attributes['width']
363
- assert_equal 25, table_row0[i].attributes['colpcwidth']
364
- assert_equal '', table_row0[i].attributes['autowidth-option']
365
- end
366
- output = doc.convert :header_footer => false
367
- assert_css 'table', output, 1
368
- assert_css 'table[style*="width: 50%;"]', output, 1
369
- assert_css 'table colgroup col', output, 4
370
- assert_css 'table colgroup col[style]', output, 0
371
- end
372
-
373
- test 'equally distributes remaining column width to autowidth columns in DocBook output' do
374
- input = <<-EOS
375
- [cols="15%,3*~"]
376
- |=======
377
- |A |B |C |D
378
- |a |b |c |d
379
- |1 |2 |3 |4
380
- |=======
381
- EOS
382
- output = convert_string_to_embedded input, :backend => 'docbook5'
383
- assert_css 'tgroup[cols="4"]', output, 1
384
- assert_css 'tgroup colspec', output, 4
385
- assert_css 'tgroup colspec[colwidth]', output, 4
386
- assert_css 'tgroup colspec[colwidth="15*"]', output, 1
387
- assert_css 'tgroup colspec[colwidth="28.3333*"]', output, 2
388
- assert_css 'tgroup colspec[colwidth="28.3334*"]', output, 1
389
- end
390
-
391
- test 'explicit table width is used even when autowidth option is specified' do
392
- input = <<-EOS
393
- [%autowidth,width=75%]
394
- |=======
395
- |A |B |C
396
- |a |b |c
397
- |1 |2 |3
398
- |=======
399
- EOS
400
- output = convert_string_to_embedded input
401
- assert_css 'table', output, 1
402
- assert_css 'table[style*="width"]', output, 1
403
- assert_css 'table colgroup col', output, 3
404
- assert_css 'table colgroup col[style*="width"]', output, 0
405
- end
406
-
407
- test 'first row sets number of columns when not specified' do
408
- input = <<-EOS
409
- |===
410
- |first |second |third |fourth
411
- |1 |2 |3
412
- |4
413
- |===
414
- EOS
415
- output = convert_string_to_embedded input
416
- assert_css 'table', output, 1
417
- assert_css 'table > colgroup > col', output, 4
418
- assert_css 'table > tbody > tr', output, 2
419
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 4
420
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 4
421
- end
422
-
423
- test 'colspec attribute using asterisk syntax sets number of columns' do
424
- input = <<-EOS
425
- [cols="3*"]
426
- |===
427
- |A |B |C |a |b |c |1 |2 |3
428
- |===
429
- EOS
430
- output = convert_string_to_embedded input
431
- assert_css 'table', output, 1
432
- assert_css 'table > tbody > tr', output, 3
433
- end
434
-
435
- test 'table with explicit column count can have multiple rows on a single line' do
436
- input = <<-EOS
437
- [cols="3*"]
438
- |===
439
- |one |two
440
- |1 |2 |a |b
441
- |===
442
- EOS
443
- output = convert_string_to_embedded input
444
- assert_css 'table', output, 1
445
- assert_css 'table > colgroup > col', output, 3
446
- assert_css 'table > tbody > tr', output, 2
447
- end
448
-
449
- test 'table with explicit deprecated colspec syntax can have multiple rows on a single line' do
450
- input = <<-EOS
451
- [cols="3"]
452
- |===
453
- |one |two
454
- |1 |2 |a |b
455
- |===
456
- EOS
457
- output = convert_string_to_embedded input
458
- assert_css 'table', output, 1
459
- assert_css 'table > colgroup > col', output, 3
460
- assert_css 'table > tbody > tr', output, 2
461
- end
462
-
463
- test 'columns are added for empty records in colspec attribute' do
464
- input = <<-EOS
465
- [cols="<,"]
466
- |===
467
- |one |two
468
- |1 |2 |a |b
469
- |===
470
- EOS
471
- output = convert_string_to_embedded input
472
- assert_css 'table', output, 1
473
- assert_css 'table > colgroup > col', output, 2
474
- assert_css 'table > tbody > tr', output, 3
475
- end
476
-
477
- test 'cols may be separated by semi-colon instead of comma' do
478
- input = <<-EOS
479
- [cols="1s;3m"]
480
- |===
481
- | strong
482
- | mono
483
- |===
484
- EOS
485
- output = convert_string_to_embedded input
486
- assert_css 'table', output, 1
487
- assert_css 'table > colgroup > col', output, 2
488
- assert_css 'col[style="width: 25%;"]', output, 1
489
- assert_css 'col[style="width: 75%;"]', output, 1
490
- assert_xpath '(//td)[1]//strong', output, 1
491
- assert_xpath '(//td)[2]//code', output, 1
492
- end
493
-
494
- test 'cols attribute may include spaces' do
495
- input = <<-EOS
496
- [cols=" 1, 1 "]
497
- |===
498
- |one |two |1 |2 |a |b
499
- |===
500
- EOS
501
- output = convert_string_to_embedded input
502
- assert_css 'table', output, 1
503
- assert_css 'table > colgroup > col', output, 2
504
- assert_css 'col[style="width: 50%;"]', output, 2
505
- assert_css 'table > tbody > tr', output, 3
506
- end
507
-
508
- test 'blank cols attribute should be ignored' do
509
- input = <<-EOS
510
- [cols=" "]
511
- |===
512
- |one |two
513
- |1 |2 |a |b
514
- |===
515
- EOS
516
- output = convert_string_to_embedded input
517
- assert_css 'table', output, 1
518
- assert_css 'table > colgroup > col', output, 2
519
- assert_css 'col[style="width: 50%;"]', output, 2
520
- assert_css 'table > tbody > tr', output, 3
521
- end
522
-
523
- test 'empty cols attribute should be ignored' do
524
- input = <<-EOS
525
- [cols=""]
526
- |===
527
- |one |two
528
- |1 |2 |a |b
529
- |===
530
- EOS
531
- output = convert_string_to_embedded input
532
- assert_css 'table', output, 1
533
- assert_css 'table > colgroup > col', output, 2
534
- assert_css 'col[style="width: 50%;"]', output, 2
535
- assert_css 'table > tbody > tr', output, 3
536
- end
537
-
538
- test 'table with header and footer' do
539
- input = <<-EOS
540
- [frame="topbot",options="header,footer"]
541
- |===
542
- |Item |Quantity
543
- |Item 1 |1
544
- |Item 2 |2
545
- |Item 3 |3
546
- |Total |6
547
- |===
548
- EOS
549
- output = convert_string_to_embedded input
550
- assert_css 'table', output, 1
551
- assert_css 'table > colgroup > col', output, 2
552
- assert_css 'table > thead', output, 1
553
- assert_css 'table > thead > tr', output, 1
554
- assert_css 'table > thead > tr > th', output, 2
555
- assert_css 'table > tfoot', output, 1
556
- assert_css 'table > tfoot > tr', output, 1
557
- assert_css 'table > tfoot > tr > td', output, 2
558
- assert_css 'table > tbody', output, 1
559
- assert_css 'table > tbody > tr', output, 3
560
- table_section_names = (xmlnodes_at_css 'table > *', output).map(&:node_name).select {|n| n.start_with? 't' }
561
- assert_equal %w(thead tbody tfoot), table_section_names
562
- end
563
-
564
- test 'table with header and footer docbook' do
565
- input = <<-EOS
566
- .Table with header, body and footer
567
- [frame="topbot",options="header,footer"]
568
- |===
569
- |Item |Quantity
570
- |Item 1 |1
571
- |Item 2 |2
572
- |Item 3 |3
573
- |Total |6
574
- |===
575
- EOS
576
- output = convert_string_to_embedded input, :backend => 'docbook'
577
- assert_css 'table', output, 1
578
- assert_css 'table[frame="topbot"]', output, 1
579
- assert_css 'table > title', output, 1
580
- assert_css 'table > tgroup', output, 1
581
- assert_css 'table > tgroup[cols="2"]', output, 1
582
- assert_css 'table > tgroup[cols="2"] > colspec', output, 2
583
- assert_css 'table > tgroup[cols="2"] > colspec[colwidth="50*"]', output, 2
584
- assert_css 'table > tgroup > thead', output, 1
585
- assert_css 'table > tgroup > thead > row', output, 1
586
- assert_css 'table > tgroup > thead > row > entry', output, 2
587
- assert_css 'table > tgroup > thead > row > entry > simpara', output, 0
588
- assert_css 'table > tgroup > tfoot', output, 1
589
- assert_css 'table > tgroup > tfoot > row', output, 1
590
- assert_css 'table > tgroup > tfoot > row > entry', output, 2
591
- assert_css 'table > tgroup > tfoot > row > entry > simpara', output, 2
592
- assert_css 'table > tgroup > tbody', output, 1
593
- assert_css 'table > tgroup > tbody > row', output, 3
594
- assert_css 'table > tgroup > tbody > row', output, 3
595
- table_section_names = (xmlnodes_at_css 'table > tgroup > *', output).map(&:node_name).select {|n| n.start_with? 't' }
596
- assert_equal %w(thead tbody tfoot), table_section_names
597
- end
598
-
599
- test 'should recognize ends as an alias to topbot for frame when converting to DocBook' do
600
- input = <<-EOS
601
- [frame=ends]
602
- |===
603
- |A |B |C
604
- |===
605
- EOS
606
- output = convert_string_to_embedded input, :backend => 'docbook'
607
- assert_css 'informaltable[frame="topbot"]', output, 1
608
- end
609
-
610
- test 'table with landscape orientation in DocBook' do
611
- ['orientation=landscape', '%rotate'].each do |attrs|
612
- input = <<-EOS
613
- [#{attrs}]
614
- |===
615
- |Column A | Column B | Column C
616
- |===
617
- EOS
618
-
619
- output = convert_string_to_embedded input, :backend => 'docbook'
620
- assert_css 'informaltable', output, 1
621
- assert_css 'informaltable[orient="land"]', output, 1
622
- end
623
- end
624
-
625
- test 'table with implicit header row' do
626
- input = <<-EOS
627
- |===
628
- |Column 1 |Column 2
629
-
630
- |Data A1
631
- |Data B1
632
-
633
- |Data A2
634
- |Data B2
635
- |===
636
- EOS
637
- output = convert_string_to_embedded input
638
- assert_css 'table', output, 1
639
- assert_css 'table > colgroup > col', output, 2
640
- assert_css 'table > thead', output, 1
641
- assert_css 'table > thead > tr', output, 1
642
- assert_css 'table > thead > tr > th', output, 2
643
- assert_css 'table > tbody', output, 1
644
- assert_css 'table > tbody > tr', output, 2
645
- end
646
-
647
- test 'table with implicit header row only' do
648
- input = <<-EOS
649
- |===
650
- |Column 1 |Column 2
651
-
652
- |===
653
- EOS
654
- output = convert_string_to_embedded input
655
- assert_css 'table', output, 1
656
- assert_css 'table > colgroup > col', output, 2
657
- assert_css 'table > thead', output, 1
658
- assert_css 'table > thead > tr', output, 1
659
- assert_css 'table > thead > tr > th', output, 2
660
- assert_css 'table > tbody', output, 0
661
- end
662
-
663
- test 'table with implicit header row when other options set' do
664
- input = <<-EOS
665
- [%autowidth]
666
- |===
667
- |Column 1 |Column 2
668
-
669
- |Data A1
670
- |Data B1
671
- |===
672
- EOS
673
- output = convert_string_to_embedded input
674
- assert_css 'table', output, 1
675
- assert_css 'table[style*="width"]', output, 0
676
- assert_css 'table > colgroup > col', output, 2
677
- assert_css 'table > thead', output, 1
678
- assert_css 'table > thead > tr', output, 1
679
- assert_css 'table > thead > tr > th', output, 2
680
- assert_css 'table > tbody', output, 1
681
- assert_css 'table > tbody > tr', output, 1
682
- end
683
-
684
- test 'no implicit header row if second line not blank' do
685
- input = <<-EOS
686
- |===
687
- |Column 1 |Column 2
688
- |Data A1
689
- |Data B1
690
-
691
- |Data A2
692
- |Data B2
693
- |===
694
- EOS
695
- output = convert_string_to_embedded input
696
- assert_css 'table', output, 1
697
- assert_css 'table > colgroup > col', output, 2
698
- assert_css 'table > thead', output, 0
699
- assert_css 'table > tbody', output, 1
700
- assert_css 'table > tbody > tr', output, 3
701
- end
702
-
703
- test 'no implicit header row if cell in first line spans multiple lines' do
704
- input = <<-EOS
705
- [cols=2*]
706
- |===
707
- |A1
708
-
709
-
710
- A1 continued|B1
711
-
712
- |A2
713
- |B2
714
- |===
715
- EOS
716
- output = convert_string_to_embedded input
717
- assert_css 'table', output, 1
718
- assert_css 'table > colgroup > col', output, 2
719
- assert_css 'table > thead', output, 0
720
- assert_css 'table > tbody', output, 1
721
- assert_css 'table > tbody > tr', output, 2
722
- assert_xpath '(//td)[1]/p', output, 2
723
- end
724
-
725
- test 'no implicit header row if AsciiDoc cell in first line spans multiple lines' do
726
- input = <<-EOS
727
- [cols=2*]
728
- |===
729
- a|contains AsciiDoc content
730
-
731
- * a
732
- * b
733
- * c
734
- a|contains no AsciiDoc content
735
-
736
- just text
737
- |A2
738
- |B2
739
- |===
740
- EOS
741
- output = convert_string_to_embedded input
742
- assert_css 'table', output, 1
743
- assert_css 'table > colgroup > col', output, 2
744
- assert_css 'table > thead', output, 0
745
- assert_css 'table > tbody', output, 1
746
- assert_css 'table > tbody > tr', output, 2
747
- assert_xpath '(//td)[1]//ul', output, 1
748
- end
749
-
750
- test 'no implicit header row if first line blank' do
751
- input = <<-EOS
752
- |===
753
-
754
- |Column 1 |Column 2
755
-
756
- |Data A1
757
- |Data B1
758
-
759
- |Data A2
760
- |Data B2
761
-
762
- |===
763
- EOS
764
- output = convert_string_to_embedded input
765
- assert_css 'table', output, 1
766
- assert_css 'table > colgroup > col', output, 2
767
- assert_css 'table > thead', output, 0
768
- assert_css 'table > tbody', output, 1
769
- assert_css 'table > tbody > tr', output, 3
770
- end
771
-
772
- test 'no implicit header row if noheader option is specified' do
773
- input = <<-EOS
774
- [%noheader]
775
- |===
776
- |Column 1 |Column 2
777
-
778
- |Data A1
779
- |Data B1
780
-
781
- |Data A2
782
- |Data B2
783
- |===
784
- EOS
785
- output = convert_string_to_embedded input
786
- assert_css 'table', output, 1
787
- assert_css 'table > colgroup > col', output, 2
788
- assert_css 'table > thead', output, 0
789
- assert_css 'table > tbody', output, 1
790
- assert_css 'table > tbody > tr', output, 3
791
- end
792
-
793
- test 'styles not applied to header cells' do
794
- input = <<-EOS
795
- [cols="1h,1s,1e",options="header,footer"]
796
- |===
797
- |Name |Occupation| Website
798
- |Octocat |Social coding| https://github.com
799
- |Name |Occupation| Website
800
- |===
801
- EOS
802
- output = convert_string_to_embedded input
803
- assert_css 'table', output, 1
804
- assert_css 'table > thead > tr > th', output, 3
805
- assert_css 'table > thead > tr > th > *', output, 0
806
-
807
- assert_css 'table > tfoot > tr > th', output, 1
808
- assert_css 'table > tfoot > tr > td', output, 2
809
- assert_css 'table > tfoot > tr > td > p > strong', output, 1
810
- assert_css 'table > tfoot > tr > td > p > em', output, 1
811
-
812
- assert_css 'table > tbody > tr > th', output, 1
813
- assert_css 'table > tbody > tr > td', output, 2
814
- assert_css 'table > tbody > tr > td > p.header', output, 0
815
- assert_css 'table > tbody > tr > td > p > strong', output, 1
816
- assert_css 'table > tbody > tr > td > p > em > a', output, 1
817
- end
818
-
819
- test 'vertical table headers use th element instead of header class' do
820
- input = <<-EOS
821
- [cols="1h,1s,1e"]
822
- |===
823
-
824
- |Name |Occupation| Website
825
-
826
- |Octocat |Social coding| https://github.com
827
-
828
- |Name |Occupation| Website
829
-
830
- |===
831
- EOS
832
- output = convert_string_to_embedded input
833
- assert_css 'table', output, 1
834
- assert_css 'table > tbody > tr > th', output, 3
835
- assert_css 'table > tbody > tr > td', output, 6
836
- assert_css 'table > tbody > tr .header', output, 0
837
- assert_css 'table > tbody > tr > td > p > strong', output, 3
838
- assert_css 'table > tbody > tr > td > p > em', output, 3
839
- assert_css 'table > tbody > tr > td > p > em > a', output, 1
840
- end
841
-
842
- test 'supports horizontal and vertical source data with blank lines and table header' do
843
- input = <<-EOS
844
- .Horizontal and vertical source data
845
- [width="80%",cols="3,^2,^2,10",options="header"]
846
- |===
847
- |Date |Duration |Avg HR |Notes
848
-
849
- |22-Aug-08 |10:24 | 157 |
850
- Worked out MSHR (max sustainable heart rate) by going hard
851
- for this interval.
852
-
853
- |22-Aug-08 |23:03 | 152 |
854
- Back-to-back with previous interval.
855
-
856
- |24-Aug-08 |40:00 | 145 |
857
- Moderately hard interspersed with 3x 3min intervals (2 min
858
- hard + 1 min really hard taking the HR up to 160).
859
-
860
- I am getting in shape!
861
-
862
- |===
863
- EOS
864
- output = convert_string_to_embedded input
865
- assert_css 'table', output, 1
866
- assert_css 'table[style*="width: 80%"]', output, 1
867
- assert_xpath '/table/caption[@class="title"][text()="Table 1. Horizontal and vertical source data"]', output, 1
868
- assert_css 'table > colgroup > col', output, 4
869
- assert_css 'table > colgroup > col:nth-child(1)[@style*="width: 17.647%"]', output, 1
870
- assert_css 'table > colgroup > col:nth-child(2)[@style*="width: 11.7647%"]', output, 1
871
- assert_css 'table > colgroup > col:nth-child(3)[@style*="width: 11.7647%"]', output, 1
872
- assert_css 'table > colgroup > col:nth-child(4)[@style*="width: 58.8236%"]', output, 1
873
- assert_css 'table > thead', output, 1
874
- assert_css 'table > thead > tr', output, 1
875
- assert_css 'table > thead > tr > th', output, 4
876
- assert_css 'table > tbody > tr', output, 3
877
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 4
878
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 4
879
- assert_css 'table > tbody > tr:nth-child(3) > td', output, 4
880
- 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
881
- assert_css 'table > tbody > tr:nth-child(3) > td:nth-child(4) > p', output, 2
882
- assert_xpath '/table/tbody/tr[3]/td[4]/p[2][text()="I am getting in shape!"]', output, 1
883
- end
884
-
885
- test 'percentages as column widths' do
886
- input = <<-EOS
887
- [cols="<.^10%,<90%"]
888
- |===
889
- |column A |column B
890
- |===
891
- EOS
892
-
893
- output = convert_string_to_embedded input
894
- assert_xpath '/table/colgroup/col', output, 2
895
- assert_xpath '(/table/colgroup/col)[1][@style="width: 10%;"]', output, 1
896
- assert_xpath '(/table/colgroup/col)[2][@style="width: 90%;"]', output, 1
897
- end
898
-
899
- test 'spans, alignments and styles' do
900
- input = <<-EOS
901
- [cols="e,m,^,>s",width="25%"]
902
- |===
903
- |1 >s|2 |3 |4
904
- ^|5 2.2+^.^|6 .3+<.>m|7
905
- ^|8
906
- d|9 2+>|10
907
- |===
908
- EOS
909
- output = convert_string_to_embedded input
910
- assert_css 'table', output, 1
911
- assert_css 'table > colgroup > col[style*="width: 25%"]', output, 4
912
- assert_css 'table > tbody > tr', output, 4
913
- assert_css 'table > tbody > tr > td', output, 10
914
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 4
915
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
916
- assert_css 'table > tbody > tr:nth-child(3) > td', output, 1
917
- assert_css 'table > tbody > tr:nth-child(4) > td', output, 2
918
-
919
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1).halign-left.valign-top p em', output, 1
920
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2).halign-right.valign-top p strong', output, 1
921
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p', output, 1
922
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p *', output, 0
923
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(4).halign-right.valign-top p strong', output, 1
924
-
925
- assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(1).halign-center.valign-top p em', output, 1
926
- assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(2).halign-center.valign-middle[colspan="2"][rowspan="2"] p code', output, 1
927
- assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(3).halign-left.valign-bottom[rowspan="3"] p code', output, 1
928
-
929
- assert_css 'table > tbody > tr:nth-child(3) > td:nth-child(1).halign-center.valign-top p em', output, 1
930
-
931
- assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p', output, 1
932
- assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p em', output, 0
933
- assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(2).halign-right.valign-top[colspan="2"] p code', output, 1
934
- end
935
-
936
- test 'sets up columns correctly if first row has cell that spans columns' do
937
- input = <<-EOS
938
- |===
939
- 2+^|AAA |CCC
940
- |AAA |BBB |CCC
941
- |AAA |BBB |CCC
942
- |===
943
- EOS
944
- output = convert_string_to_embedded input
945
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 2
946
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1)[colspan="2"]', output, 1
947
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2):not([colspan])', output, 1
948
- assert_css 'table > tbody > tr:nth-child(2) > td:not([colspan])', output, 3
949
- assert_css 'table > tbody > tr:nth-child(3) > td:not([colspan])', output, 3
950
- end
951
-
952
- test 'supports repeating cells' do
953
- input = <<-EOS
954
- |===
955
- 3*|A
956
- |1 3*|2
957
- |b |c
958
- |===
959
- EOS
960
- output = convert_string_to_embedded input
961
- assert_css 'table', output, 1
962
- assert_css 'table > colgroup > col', output, 3
963
- assert_css 'table > tbody > tr', output, 3
964
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
965
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
966
- assert_css 'table > tbody > tr:nth-child(3) > td', output, 3
967
-
968
- assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A"]', output, 1
969
- assert_xpath '/table/tbody/tr[1]/td[2]/p[text()="A"]', output, 1
970
- assert_xpath '/table/tbody/tr[1]/td[3]/p[text()="A"]', output, 1
971
-
972
- assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="1"]', output, 1
973
- assert_xpath '/table/tbody/tr[2]/td[2]/p[text()="2"]', output, 1
974
- assert_xpath '/table/tbody/tr[2]/td[3]/p[text()="2"]', output, 1
975
-
976
- assert_xpath '/table/tbody/tr[3]/td[1]/p[text()="2"]', output, 1
977
- assert_xpath '/table/tbody/tr[3]/td[2]/p[text()="b"]', output, 1
978
- assert_xpath '/table/tbody/tr[3]/td[3]/p[text()="c"]', output, 1
979
- end
980
-
981
- test 'calculates colnames correctly when using implicit column count and single cell with colspan' do
982
- input = <<-EOS
983
- |===
984
- 2+|Two Columns
985
- |One Column |One Column
986
- |===
987
- EOS
988
-
989
- output = convert_string_to_embedded input, :backend => 'docbook'
990
- assert_xpath '//colspec', output, 2
991
- assert_xpath '(//colspec)[1][@colname="col_1"]', output, 1
992
- assert_xpath '(//colspec)[2][@colname="col_2"]', output, 1
993
- assert_xpath '//row', output, 2
994
- assert_xpath '(//row)[1]/entry', output, 1
995
- assert_xpath '(//row)[1]/entry[@namest="col_1"][@nameend="col_2"]', output, 1
996
- end
997
-
998
- test 'calculates colnames correctly when using implicit column count and cells with mixed colspans' do
999
- input = <<-EOS
1000
- |===
1001
- 2+|Two Columns | One Column
1002
- |One Column |One Column |One Column
1003
- |===
1004
- EOS
1005
-
1006
- output = convert_string_to_embedded input, :backend => 'docbook'
1007
- assert_xpath '//colspec', output, 3
1008
- assert_xpath '(//colspec)[1][@colname="col_1"]', output, 1
1009
- assert_xpath '(//colspec)[2][@colname="col_2"]', output, 1
1010
- assert_xpath '(//colspec)[3][@colname="col_3"]', output, 1
1011
- assert_xpath '//row', output, 2
1012
- assert_xpath '(//row)[1]/entry', output, 2
1013
- assert_xpath '(//row)[1]/entry[@namest="col_1"][@nameend="col_2"]', output, 1
1014
- assert_xpath '(//row)[2]/entry[@namest]', output, 0
1015
- assert_xpath '(//row)[2]/entry[@nameend]', output, 0
1016
- end
1017
-
1018
- test 'assigns unique column names for table with implicit column count and colspans in first row' do
1019
- input = <<-EOS
1020
- |===
1021
- | 2+| Node 0 2+| Node 1
1022
-
1023
- | Host processes | Core 0 | Core 1 | Core 4 | Core 5
1024
- | Guest processes | Core 2 | Core 3 | Core 6 | Core 7
1025
- |===
1026
- EOS
1027
-
1028
- output = convert_string_to_embedded input, :backend => 'docbook'
1029
- assert_xpath '//colspec', output, 5
1030
- (1..5).each do |n|
1031
- assert_xpath %((//colspec)[#{n}][@colname="col_#{n}"]), output, 1
1032
- end
1033
- assert_xpath '(//row)[1]/entry', output, 3
1034
- assert_xpath '((//row)[1]/entry)[1][@namest]', output, 0
1035
- assert_xpath '((//row)[1]/entry)[1][@namend]', output, 0
1036
- assert_xpath '((//row)[1]/entry)[2][@namest="col_2"][@nameend="col_3"]', output, 1
1037
- assert_xpath '((//row)[1]/entry)[3][@namest="col_4"][@nameend="col_5"]', output, 1
1038
- end
1039
-
1040
- test 'ignores cell with colspan that exceeds colspec' do
1041
- input = <<-EOS
1042
- [cols=2*]
1043
- |===
1044
- 3+|A
1045
- |B
1046
- a|C
1047
-
1048
- more C
1049
- |===
1050
- EOS
1051
- using_memory_logger do |logger|
1052
- output = convert_string_to_embedded input
1053
- assert_css 'table', output, 1
1054
- assert_css 'table *', output, 0
1055
- assert_message logger, :ERROR, '<stdin>: line 5: dropping cell because it exceeds specified number of columns', Hash
1056
- end
1057
- end
1058
-
1059
- test 'paragraph, verse and literal content' do
1060
- input = <<-EOS
1061
- [cols=",^v,^l",options="header"]
1062
- |===
1063
- |Paragraphs |Verse |Literal
1064
- 3*|The discussion about what is good,
1065
- what is beautiful, what is noble,
1066
- what is pure, and what is true
1067
- could always go on.
1068
-
1069
- Why is that important?
1070
- Why would I like to do that?
1071
-
1072
- Because that's the only conversation worth having.
1073
-
1074
- And whether it goes on or not after I die, I don't know.
1075
- But, I do know that it is the conversation I want to have while I am still alive.
1076
-
1077
- Which means that to me the offer of certainty,
1078
- the offer of complete security,
1079
- the offer of an impermeable faith that can't give way
1080
- is an offer of something not worth having.
1081
-
1082
- I want to live my life taking the risk all the time
1083
- that I don't know anything like enough yet...
1084
- that I haven't understood enough...
1085
- that I can't know enough...
1086
- that I am always hungrily operating on the margins
1087
- of a potentially great harvest of future knowledge and wisdom.
1088
-
1089
- I wouldn't have it any other way.
1090
- |===
1091
- EOS
1092
- output = convert_string_to_embedded input
1093
- assert_css 'table', output, 1
1094
- assert_css 'table > colgroup > col', output, 3
1095
- assert_css 'table > thead', output, 1
1096
- assert_css 'table > thead > tr', output, 1
1097
- assert_css 'table > thead > tr > th', output, 3
1098
- assert_css 'table > tbody', output, 1
1099
- assert_css 'table > tbody > tr', output, 1
1100
- assert_css 'table > tbody > tr > td', output, 3
1101
- assert_css 'table > tbody > tr > td:nth-child(1).halign-left.valign-top > p.tableblock', output, 7
1102
- assert_css 'table > tbody > tr > td:nth-child(2).halign-center.valign-top > div.verse', output, 1
1103
- verse = xmlnodes_at_css 'table > tbody > tr > td:nth-child(2).halign-center.valign-top > div.verse', output, 1
1104
- assert_equal 26, verse.text.lines.entries.size
1105
- assert_css 'table > tbody > tr > td:nth-child(3).halign-center.valign-top > div.literal > pre', output, 1
1106
- literal = xmlnodes_at_css 'table > tbody > tr > td:nth-child(3).halign-center.valign-top > div.literal > pre', output, 1
1107
- assert_equal 26, literal.text.lines.entries.size
1108
- end
1109
-
1110
- test 'should strip trailing endline when splitting paragraphs' do
1111
- input = <<-EOS
1112
- |===
1113
- |first wrapped
1114
- paragraph
1115
-
1116
- second paragraph
1117
-
1118
- third paragraph
1119
- |===
1120
- EOS
1121
-
1122
- result = convert_string_to_embedded input
1123
- assert_xpath %((//p[@class="tableblock"])[1][text()="first wrapped\nparagraph"]), result, 1
1124
- assert_xpath %((//p[@class="tableblock"])[2][text()="second paragraph"]), result, 1
1125
- assert_xpath %((//p[@class="tableblock"])[3][text()="third paragraph"]), result, 1
1126
- end
1127
-
1128
- test 'basic AsciiDoc cell' do
1129
- input = <<-EOS
1130
- |===
1131
- a|--
1132
- NOTE: content
1133
-
1134
- content
1135
- --
1136
- |===
1137
- EOS
1138
-
1139
- result = convert_string_to_embedded input
1140
- assert_css 'table.tableblock', result, 1
1141
- assert_css 'table.tableblock td.tableblock', result, 1
1142
- assert_css 'table.tableblock td.tableblock .openblock', result, 1
1143
- assert_css 'table.tableblock td.tableblock .openblock .admonitionblock', result, 1
1144
- assert_css 'table.tableblock td.tableblock .openblock .paragraph', result, 1
1145
- end
1146
-
1147
- test 'AsciiDoc table cell should be wrapped in div with class "content"' do
1148
- input = <<-EOS
1149
- |===
1150
- a|AsciiDoc table cell
1151
- |===
1152
- EOS
1153
-
1154
- result = convert_string_to_embedded input
1155
- assert_css 'table.tableblock td.tableblock > div.content', result, 1
1156
- assert_css 'table.tableblock td.tableblock > div.content > div.paragraph', result, 1
1157
- end
1158
-
1159
- test 'doctype can be set in AsciiDoc table cell' do
1160
- input = <<-EOS
1161
- |===
1162
- a|
1163
- :doctype: inline
1164
-
1165
- content
1166
- |===
1167
- EOS
1168
-
1169
- result = convert_string_to_embedded input
1170
- assert_css 'table.tableblock', result, 1
1171
- assert_css 'table.tableblock .paragraph', result, 0
1172
- end
1173
-
1174
- test 'should reset doctype to default in AsciiDoc table cell' do
1175
- input = <<-EOS
1176
- = Book Title
1177
- :doctype: book
1178
-
1179
- == Chapter 1
1180
-
1181
- |===
1182
- a|
1183
- = AsciiDoc Table Cell
1184
-
1185
- doctype={doctype}
1186
- {backend-html5-doctype-article}
1187
- {backend-html5-doctype-book}
1188
- |===
1189
- EOS
1190
-
1191
- result = convert_string_to_embedded input, :attributes => { 'attribute-missing' => 'skip' }
1192
- assert_includes result, 'doctype=article'
1193
- refute_includes result, '{backend-html5-doctype-article}'
1194
- assert_includes result, '{backend-html5-doctype-book}'
1195
- end
1196
-
1197
- test 'should update doctype-related attributes in AsciiDoc table cell when doctype is set' do
1198
- input = <<-EOS
1199
- = Document Title
1200
- :doctype: article
1201
-
1202
- == Chapter 1
1203
-
1204
- |===
1205
- a|
1206
- = AsciiDoc Table Cell
1207
- :doctype: book
1208
-
1209
- doctype={doctype}
1210
- {backend-html5-doctype-book}
1211
- {backend-html5-doctype-article}
1212
- |===
1213
- EOS
1214
-
1215
- result = convert_string_to_embedded input, :attributes => { 'attribute-missing' => 'skip' }
1216
- assert_includes result, 'doctype=book'
1217
- refute_includes result, '{backend-html5-doctype-book}'
1218
- assert_includes result, '{backend-html5-doctype-article}'
1219
- end
1220
-
1221
- test 'AsciiDoc content' do
1222
- input = <<-EOS
1223
- [cols="1e,1,5a",frame="topbot",options="header"]
1224
- |===
1225
- |Name |Backends |Description
1226
-
1227
- |badges |xhtml11, html5 |
1228
- Link badges ('XHTML 1.1' and 'CSS') in document footers.
1229
-
1230
- [NOTE]
1231
- ====
1232
- The path names of images, icons and scripts are relative path
1233
- names to the output document not the source document.
1234
- ====
1235
- |[[X97]] docinfo, docinfo1, docinfo2 |All backends |
1236
- These three attributes control which document information
1237
- files will be included in the the header of the output file:
1238
-
1239
- docinfo:: Include `<filename>-docinfo.<ext>`
1240
- docinfo1:: Include `docinfo.<ext>`
1241
- docinfo2:: Include `docinfo.<ext>` and `<filename>-docinfo.<ext>`
1242
-
1243
- Where `<filename>` is the file name (sans extension) of the AsciiDoc
1244
- input file and `<ext>` is `.html` for HTML outputs or `.xml` for
1245
- DocBook outputs. If the input file is the standard input then the
1246
- output file name is used.
1247
- |===
1248
- EOS
1249
- doc = document_from_string input, :sourcemap => true
1250
- table = doc.blocks.first
1251
- refute_nil table
1252
- tbody = table.rows.body
1253
- assert_equal 2, tbody.size
1254
- body_cell_1_2 = tbody[0][1]
1255
- assert_equal 5, body_cell_1_2.lineno
1256
- body_cell_1_3 = tbody[0][2]
1257
- refute_nil body_cell_1_3.inner_document
1258
- assert body_cell_1_3.inner_document.nested?
1259
- assert_equal doc, body_cell_1_3.inner_document.parent_document
1260
- assert_equal doc.converter, body_cell_1_3.inner_document.converter
1261
- assert_equal 5, body_cell_1_3.lineno
1262
- assert_equal 6, body_cell_1_3.inner_document.lineno
1263
- note = (body_cell_1_3.inner_document.find_by :context => :admonition)[0]
1264
- assert_equal 9, note.lineno
1265
- output = doc.convert :header_footer => false
1266
-
1267
- assert_css 'table > tbody > tr', output, 2
1268
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3) div.admonitionblock', output, 1
1269
- assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(3) div.dlist', output, 1
1270
- end
1271
-
1272
- test 'should preserve leading indentation in contents of AsciiDoc table cell if contents starts with newline' do
1273
- input = <<-EOS
1274
- |===
1275
- a|
1276
- $ command
1277
- a| paragraph
1278
- |===
1279
- EOS
1280
- doc = document_from_string input, :sourcemap => true
1281
- table = doc.blocks[0]
1282
- tbody = table.rows.body
1283
- assert_equal 1, table.lineno
1284
- assert_equal 2, tbody[0][0].lineno
1285
- assert_equal 3, tbody[0][0].inner_document.lineno
1286
- assert_equal 4, tbody[1][0].lineno
1287
- output = doc.convert :header_footer => false
1288
- assert_css 'td', output, 2
1289
- assert_xpath '(//td)[1]//*[@class="literalblock"]', output, 1
1290
- assert_xpath '(//td)[2]//*[@class="paragraph"]', output, 1
1291
- assert_xpath '(//pre)[1][text()="$ command"]', output, 1
1292
- assert_xpath '(//p)[1][text()="paragraph"]', output, 1
1293
- end
1294
-
1295
- test 'preprocessor directive on first line of an AsciiDoc table cell should be processed' do
1296
- input = <<-EOS
1297
- |===
1298
- a|include::fixtures/include-file.asciidoc[]
1299
- |===
1300
- EOS
1301
-
1302
- output = convert_string_to_embedded input, :safe => :safe, :base_dir => testdir
1303
- assert_match(/included content/, output)
1304
- end
1305
-
1306
- test 'cross reference link in an AsciiDoc table cell should resolve to reference in main document' do
1307
- input = <<-EOS
1308
- == Some
1309
-
1310
- |===
1311
- a|See <<_more>>
1312
- |===
1313
-
1314
- == More
1315
-
1316
- content
1317
- EOS
1318
-
1319
- result = convert_string input
1320
- assert_xpath '//a[@href="#_more"]', result, 1
1321
- assert_xpath '//a[@href="#_more"][text()="More"]', result, 1
1322
- end
1323
-
1324
- test 'should discover anchor at start of cell and register it as a reference' do
1325
- input = <<-EOS
1326
- The highest peak in the Front Range is <<grays-peak>>, which tops <<mount-evans>> by just a few feet.
1327
-
1328
- [cols="1s,1"]
1329
- |===
1330
- |[[mount-evans,Mount Evans]]Mount Evans
1331
- |14,271 feet
1332
-
1333
- h|[[grays-peak,Grays Peak]]
1334
- Grays Peak
1335
- |14,278 feet
1336
- |===
1337
- EOS
1338
- doc = document_from_string input
1339
- refs = doc.catalog[:refs]
1340
- assert refs.key?('mount-evans')
1341
- assert refs.key?('grays-peak')
1342
- output = doc.convert :header_footer => false
1343
- assert_xpath '(//p)[1]/a[@href="#grays-peak"][text()="Grays Peak"]', output, 1
1344
- assert_xpath '(//p)[1]/a[@href="#mount-evans"][text()="Mount Evans"]', output, 1
1345
- assert_xpath '(//table/tbody/tr)[1]//td//a[@id="mount-evans"]', output, 1
1346
- assert_xpath '(//table/tbody/tr)[2]//th//a[@id="grays-peak"]', output, 1
1347
- end
1348
-
1349
- test 'footnotes should not be shared between an AsciiDoc table cell and the main document' do
1350
- input = <<-EOS
1351
- |===
1352
- a|AsciiDoc footnote:[A lightweight markup language.]
1353
- |===
1354
- EOS
1355
-
1356
- result = convert_string input
1357
- assert_css '#_footnotedef_1', result, 1
1358
- end
1359
-
1360
- test 'callout numbers should be globally unique, including AsciiDoc table cells' do
1361
- input = <<-EOS
1362
- = Document Title
1363
-
1364
- == Section 1
1365
-
1366
- |===
1367
- a|
1368
- [source, yaml]
1369
- ----
1370
- key: value <1>
1371
- ----
1372
- <1> First callout
1373
- |===
1374
-
1375
- == Section 2
1376
-
1377
- |===
1378
- a|
1379
- [source, yaml]
1380
- ----
1381
- key: value <1>
1382
- ----
1383
- <1> Second callout
1384
- |===
1385
-
1386
- == Section 3
1387
-
1388
- [source, yaml]
1389
- ----
1390
- key: value <1>
1391
- ----
1392
- <1> Third callout
1393
- EOS
1394
-
1395
- result = convert_string input, :backend => 'docbook'
1396
- conums = xmlnodes_at_xpath '//co', result
1397
- assert_equal 3, conums.size
1398
- ['CO1-1', 'CO2-1', 'CO3-1'].each_with_index do |conum, idx|
1399
- assert_equal conum, conums[idx].attribute('xml:id').value
1400
- end
1401
- callouts = xmlnodes_at_xpath '//callout', result
1402
- assert_equal 3, callouts.size
1403
- ['CO1-1', 'CO2-1', 'CO3-1'].each_with_index do |callout, idx|
1404
- assert_equal callout, callouts[idx].attribute('arearefs').value
1405
- end
1406
- end
1407
-
1408
- test 'compat mode can be activated in AsciiDoc table cell' do
1409
- input = <<-EOS
1410
- |===
1411
- a|
1412
- :compat-mode:
1413
-
1414
- The word 'italic' is emphasized.
1415
- |===
1416
- EOS
1417
-
1418
- result = convert_string_to_embedded input
1419
- assert_xpath '//em[text()="italic"]', result, 1
1420
- end
1421
-
1422
- test 'compat mode in AsciiDoc table cell inherits from parent document' do
1423
- input = <<-EOS
1424
- :compat-mode:
1425
-
1426
- The word 'italic' is emphasized.
1427
-
1428
- [cols=1*]
1429
- |===
1430
- |The word 'oblique' is emphasized.
1431
- a|
1432
- The word 'slanted' is emphasized.
1433
- |===
1434
-
1435
- The word 'askew' is emphasized.
1436
- EOS
1437
-
1438
- result = convert_string_to_embedded input
1439
- assert_xpath '//em[text()="italic"]', result, 1
1440
- assert_xpath '//em[text()="oblique"]', result, 1
1441
- assert_xpath '//em[text()="slanted"]', result, 1
1442
- assert_xpath '//em[text()="askew"]', result, 1
1443
- end
1444
-
1445
- test 'compat mode in AsciiDoc table cell can be unset if set in parent document' do
1446
- input = <<-EOS
1447
- :compat-mode:
1448
-
1449
- The word 'italic' is emphasized.
1450
-
1451
- [cols=1*]
1452
- |===
1453
- |The word 'oblique' is emphasized.
1454
- a|
1455
- :!compat-mode:
1456
-
1457
- The word 'slanted' is not emphasized.
1458
- |===
1459
-
1460
- The word 'askew' is emphasized.
1461
- EOS
1462
-
1463
- result = convert_string_to_embedded input
1464
- assert_xpath '//em[text()="italic"]', result, 1
1465
- assert_xpath '//em[text()="oblique"]', result, 1
1466
- assert_xpath '//em[text()="slanted"]', result, 0
1467
- assert_xpath '//em[text()="askew"]', result, 1
1468
- end
1469
-
1470
- test 'nested table' do
1471
- input = <<-EOS
1472
- [cols="1,2a"]
1473
- |===
1474
- |Normal cell
1475
- |Cell with nested table
1476
- [cols="2,1"]
1477
- !===
1478
- !Nested table cell 1 !Nested table cell 2
1479
- !===
1480
- |===
1481
- EOS
1482
- output = convert_string_to_embedded input
1483
- assert_css 'table', output, 2
1484
- assert_css 'table table', output, 1
1485
- assert_css 'table > tbody > tr > td:nth-child(2) table', output, 1
1486
- assert_css 'table > tbody > tr > td:nth-child(2) table > tbody > tr > td', output, 2
1487
- end
1488
-
1489
- test 'can set format of nested table to psv' do
1490
- input = <<-EOS
1491
- [cols="2*"]
1492
- |===
1493
- |normal cell
1494
- a|
1495
- [format=psv]
1496
- !===
1497
- !nested cell
1498
- !===
1499
- |===
1500
- EOS
1501
-
1502
- output = convert_string_to_embedded input
1503
- assert_css 'table', output, 2
1504
- assert_css 'table table', output, 1
1505
- assert_css 'table > tbody > tr > td:nth-child(2) table', output, 1
1506
- assert_css 'table > tbody > tr > td:nth-child(2) table > tbody > tr > td', output, 1
1507
- end
1508
-
1509
- test 'toc from parent document should not be included in an AsciiDoc table cell' do
1510
- input = <<-EOS
1511
- = Document Title
1512
- :toc:
1513
-
1514
- == Section A
1515
-
1516
- |===
1517
- a|AsciiDoc content
1518
- |===
1519
- EOS
1520
-
1521
- output = convert_string input
1522
- assert_css '.toc', output, 1
1523
- assert_css 'table .toc', output, 0
1524
- end
1525
-
1526
- test 'should be able to enable toc in an AsciiDoc table cell' do
1527
- input = <<-EOS
1528
- = Document Title
1529
-
1530
- == Section A
1531
-
1532
- |===
1533
- a|
1534
- = Subdocument Title
1535
- :toc:
1536
-
1537
- == Subdocument Section A
1538
-
1539
- content
1540
- |===
1541
- EOS
1542
-
1543
- output = convert_string input
1544
- assert_css '.toc', output, 1
1545
- assert_css 'table .toc', output, 1
1546
- end
1547
-
1548
- test 'should be able to enable toc in both outer document and in an AsciiDoc table cell' do
1549
- input = <<-EOS
1550
- = Document Title
1551
- :toc:
1552
-
1553
- == Section A
1554
-
1555
- |===
1556
- a|
1557
- = Subdocument Title
1558
- :toc: macro
1559
-
1560
- [#table-cell-toc]
1561
- toc::[]
1562
-
1563
- == Subdocument Section A
1564
-
1565
- content
1566
- |===
1567
- EOS
1568
-
1569
- output = convert_string input
1570
- assert_css '.toc', output, 2
1571
- assert_css '#toc', output, 1
1572
- assert_css 'table .toc', output, 1
1573
- assert_css 'table #table-cell-toc', output, 1
1574
- end
1575
-
1576
- test 'document in an AsciiDoc table cell should not see doctitle of parent' do
1577
- input = <<-EOS
1578
- = Document Title
1579
-
1580
- [cols="1a"]
1581
- |===
1582
- |AsciiDoc content
1583
- |===
1584
- EOS
1585
-
1586
- output = convert_string input
1587
- assert_css 'table', output, 1
1588
- assert_css 'table > tbody > tr > td', output, 1
1589
- assert_css 'table > tbody > tr > td #preamble', output, 0
1590
- assert_css 'table > tbody > tr > td .paragraph', output, 1
1591
- end
1592
-
1593
- test 'cell background color' do
1594
- input = <<-EOS
1595
- [cols="1e,1", options="header"]
1596
- |===
1597
- |{set:cellbgcolor:green}green
1598
- |{set:cellbgcolor!}
1599
- plain
1600
- |{set:cellbgcolor:red}red
1601
- |{set:cellbgcolor!}
1602
- plain
1603
- |===
1604
- EOS
1605
-
1606
- output = convert_string_to_embedded input
1607
- assert_xpath '(/table/thead/tr/th)[1][@style="background-color: green;"]', output, 1
1608
- assert_xpath '(/table/thead/tr/th)[2][@style="background-color: green;"]', output, 0
1609
- assert_xpath '(/table/tbody/tr/td)[1][@style="background-color: red;"]', output, 1
1610
- assert_xpath '(/table/tbody/tr/td)[2][@style="background-color: green;"]', output, 0
1611
- end
1612
-
1613
- test 'should warn if table block is not terminated' do
1614
- input = <<-EOS
1615
- outside
1616
-
1617
- |===
1618
- |
1619
- inside
1620
-
1621
- still inside
1622
-
1623
- eof
1624
- EOS
1625
-
1626
- using_memory_logger do |logger|
1627
- output = convert_string_to_embedded input
1628
- assert_xpath '/table', output, 1
1629
- assert_message logger, :WARN, '<stdin>: line 3: unterminated table block', Hash
1630
- end
1631
- end
1632
-
1633
- test 'should show correct line number in warning about unterminated block inside AsciiDoc table cell' do
1634
- input = <<-EOS
1635
- outside
1636
-
1637
- * list item
1638
- +
1639
- |===
1640
- |cell
1641
- a|inside
1642
-
1643
- ====
1644
- unterminated example block
1645
- |===
1646
-
1647
- eof
1648
- EOS
1649
-
1650
- using_memory_logger do |logger|
1651
- output = convert_string_to_embedded input
1652
- assert_xpath '//ul//table', output, 1
1653
- assert_message logger, :WARN, '<stdin>: line 9: unterminated example block', Hash
1654
- end
1655
- end
1656
-
1657
- test 'custom separator for an AsciiDoc table cell' do
1658
- input = <<-EOS
1659
- [cols=2,separator=!]
1660
- |===
1661
- !Pipe output to vim
1662
- a!
1663
- ----
1664
- asciidoctor -o - -s test.adoc | view -
1665
- ----
1666
- |===
1667
- EOS
1668
- output = convert_string_to_embedded input
1669
- assert_css 'table', output, 1
1670
- assert_css 'table > colgroup > col', output, 2
1671
- assert_css 'table > tbody > tr', output, 1
1672
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 2
1673
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1) p', output, 1
1674
- assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2) .listingblock', output, 1
1675
- end
1676
-
1677
- test 'table with breakable option docbook 4.5' do
1678
- input = <<-EOS
1679
- .Table with breakable
1680
- [%breakable]
1681
- |===
1682
- |Item |Quantity
1683
- |Item 1 |1
1684
- |===
1685
- EOS
1686
- output = convert_string_to_embedded input, :backend => 'docbook45'
1687
- assert_includes output, '<?dbfo keep-together="auto"?>'
1688
- end
1689
-
1690
- test 'table with breakable option docbook 5' do
1691
- input = <<-EOS
1692
- .Table with breakable
1693
- [%breakable]
1694
- |===
1695
- |Item |Quantity
1696
- |Item 1 |1
1697
- |===
1698
- EOS
1699
- output = convert_string_to_embedded input, :backend => 'docbook5'
1700
- assert_includes output, '<?dbfo keep-together="auto"?>'
1701
- end
1702
-
1703
- test 'table with unbreakable option docbook 5' do
1704
- input = <<-EOS
1705
- .Table with unbreakable
1706
- [%unbreakable]
1707
- |===
1708
- |Item |Quantity
1709
- |Item 1 |1
1710
- |===
1711
- EOS
1712
- output = convert_string_to_embedded input, :backend => 'docbook5'
1713
- assert_includes output, '<?dbfo keep-together="always"?>'
1714
- end
1715
-
1716
- test 'table with unbreakable option docbook 4.5' do
1717
- input = <<-EOS
1718
- .Table with unbreakable
1719
- [%unbreakable]
1720
- |===
1721
- |Item |Quantity
1722
- |Item 1 |1
1723
- |===
1724
- EOS
1725
- output = convert_string_to_embedded input, :backend => 'docbook45'
1726
- assert_includes output, '<?dbfo keep-together="always"?>'
1727
- end
1728
-
1729
- test 'no implicit header row if cell in first line is quoted and spans multiple lines' do
1730
- input = <<-EOS
1731
- [cols=2*l]
1732
- ,===
1733
- "A1
1734
-
1735
- A1 continued",B1
1736
- A2,B2
1737
- ,===
1738
- EOS
1739
- output = convert_string_to_embedded input
1740
- assert_css 'table', output, 1
1741
- assert_css 'table > colgroup > col', output, 2
1742
- assert_css 'table > thead', output, 0
1743
- assert_css 'table > tbody', output, 1
1744
- assert_css 'table > tbody > tr', output, 2
1745
- assert_xpath %((//td)[1]//pre[text()="A1\n\nA1 continued"]), output, 1
1746
- end
1747
- end
1748
-
1749
- context 'DSV' do
1750
-
1751
- test 'converts simple dsv table' do
1752
- input = <<-EOS
1753
- [width="75%",format="dsv"]
1754
- |===
1755
- root:x:0:0:root:/root:/bin/bash
1756
- bin:x:1:1:bin:/bin:/sbin/nologin
1757
- mysql:x:27:27:MySQL\\:Server:/var/lib/mysql:/bin/bash
1758
- gdm:x:42:42::/var/lib/gdm:/sbin/nologin
1759
- sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
1760
- nobody:x:99:99:Nobody:/:/sbin/nologin
1761
- |===
1762
- EOS
1763
- doc = document_from_string input, :header_footer => false
1764
- table = doc.blocks[0]
1765
- assert 100, table.columns.map {|col| col.attributes['colpcwidth'] }.reduce(:+)
1766
- output = doc.convert
1767
- assert_css 'table', output, 1
1768
- assert_css 'table > colgroup > col[style*="width: 14.2857"]', output, 6
1769
- assert_css 'table > colgroup > col:last-of-type[style*="width: 14.2858%"]', output, 1
1770
- assert_css 'table > tbody > tr', output, 6
1771
- assert_xpath '//tr[4]/td[5]/p/text()', output, 0
1772
- assert_xpath '//tr[3]/td[5]/p[text()="MySQL:Server"]', output, 1
1773
- end
1774
-
1775
- test 'dsv format shorthand' do
1776
- input = <<-EOS
1777
- :===
1778
- a:b:c
1779
- 1:2:3
1780
- :===
1781
- EOS
1782
- output = convert_string_to_embedded input
1783
- assert_css 'table', output, 1
1784
- assert_css 'table > colgroup > col', output, 3
1785
- assert_css 'table > tbody > tr', output, 2
1786
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
1787
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
1788
- end
1789
-
1790
- test 'single cell in DSV table should only produce single row' do
1791
- input = <<-EOS
1792
- :===
1793
- single cell
1794
- :===
1795
- EOS
1796
-
1797
- output = convert_string_to_embedded input
1798
- assert_css 'table td', output, 1
1799
- end
1800
-
1801
- test 'should treat trailing colon as an empty cell' do
1802
- input = <<-EOS
1803
- :===
1804
- A1:
1805
- B1:B2
1806
- C1:C2
1807
- :===
1808
- EOS
1809
- output = convert_string_to_embedded input
1810
- assert_css 'table', output, 1
1811
- assert_css 'table > colgroup > col', output, 2
1812
- assert_css 'table > tbody > tr', output, 3
1813
- assert_xpath '/table/tbody/tr[1]/td', output, 2
1814
- assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1
1815
- assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0
1816
- assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1
1817
- end
1818
- end
1819
-
1820
- context 'CSV' do
1821
-
1822
- test 'should treat trailing comma as an empty cell' do
1823
- input = <<-EOS
1824
- ,===
1825
- A1,
1826
- B1,B2
1827
- C1,C2
1828
- ,===
1829
- EOS
1830
- output = convert_string_to_embedded input
1831
- assert_css 'table', output, 1
1832
- assert_css 'table > colgroup > col', output, 2
1833
- assert_css 'table > tbody > tr', output, 3
1834
- assert_xpath '/table/tbody/tr[1]/td', output, 2
1835
- assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1
1836
- assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0
1837
- assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1
1838
- end
1839
-
1840
- test 'should log error but not crash if cell data has unclosed quote' do
1841
- input = <<-EOS
1842
- ,===
1843
- a,b
1844
- c,"
1845
- ,===
1846
- EOS
1847
- using_memory_logger do |logger|
1848
- output = convert_string_to_embedded input
1849
- assert_css 'table', output, 1
1850
- assert_css 'table td', output, 4
1851
- assert_xpath '(/table/td)[4]/p', output, 0
1852
- assert_message logger, :ERROR, '<stdin>: line 3: unclosed quote in CSV data; setting cell to empty', Hash
1853
- end
1854
- end
1855
-
1856
- test 'should preserve newlines in quoted CSV values' do
1857
- input = <<-EOS
1858
- [cols="1,1,1l"]
1859
- ,===
1860
- "A
1861
- B
1862
- C","one
1863
-
1864
- two
1865
-
1866
- three","do
1867
-
1868
- re
1869
-
1870
- me"
1871
- ,===
1872
- EOS
1873
- output = convert_string_to_embedded input
1874
- assert_css 'table', output, 1
1875
- assert_css 'table > colgroup > col', output, 3
1876
- assert_css 'table > tbody > tr', output, 1
1877
- assert_xpath '/table/tbody/tr[1]/td', output, 3
1878
- assert_xpath %(/table/tbody/tr[1]/td[1]/p[text()="A\nB\nC"]), output, 1
1879
- assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 3
1880
- assert_xpath '/table/tbody/tr[1]/td[2]/p[1][text()="one"]', output, 1
1881
- assert_xpath '/table/tbody/tr[1]/td[2]/p[2][text()="two"]', output, 1
1882
- assert_xpath '/table/tbody/tr[1]/td[2]/p[3][text()="three"]', output, 1
1883
- assert_xpath %(/table/tbody/tr[1]/td[3]//pre[text()="do\n\nre\n\nme"]), output, 1
1884
- end
1885
-
1886
- test 'mixed unquoted records and quoted records with escaped quotes, commas, and wrapped lines' do
1887
- input = <<-EOS
1888
- [format="csv",options="header"]
1889
- |===
1890
- Year,Make,Model,Description,Price
1891
- 1997,Ford,E350,"ac, abs, moon",3000.00
1892
- 1999,Chevy,"Venture ""Extended Edition""","",4900.00
1893
- 1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1894
- 1996,Jeep,Grand Cherokee,"MUST SELL!
1895
- air, moon roof, loaded",4799.00
1896
- 2000,Toyota,Tundra,"""This one's gonna to blow you're socks off,"" per the sticker",10000.00
1897
- 2000,Toyota,Tundra,"Check it, ""this one's gonna to blow you're socks off"", per the sticker",10000.00
1898
- |===
1899
- EOS
1900
- output = convert_string_to_embedded input
1901
- assert_css 'table', output, 1
1902
- assert_css 'table > colgroup > col[style*="width: 20%"]', output, 5
1903
- assert_css 'table > thead > tr', output, 1
1904
- assert_css 'table > tbody > tr', output, 6
1905
- assert_xpath '((//tbody/tr)[1]/td)[4]/p[text()="ac, abs, moon"]', output, 1
1906
- assert_xpath %(((//tbody/tr)[2]/td)[3]/p[text()='Venture "Extended Edition"']), output, 1
1907
- assert_xpath %(((//tbody/tr)[4]/td)[4]/p[text()="MUST SELL!\nair, moon roof, loaded"]), output, 1
1908
- assert_xpath %(((//tbody/tr)[5]/td)[4]/p[text()='"This one#{decode_char 8217}s gonna to blow you#{decode_char 8217}re socks off," per the sticker']), output, 1
1909
- assert_xpath %(((//tbody/tr)[6]/td)[4]/p[text()='Check it, "this one#{decode_char 8217}s gonna to blow you#{decode_char 8217}re socks off", per the sticker']), output, 1
1910
- end
1911
-
1912
- test 'should allow quotes around a CSV value to be on their own lines' do
1913
- input = <<-EOS
1914
- [cols=2*]
1915
- ,===
1916
- "
1917
- A
1918
- ","
1919
- B
1920
- "
1921
- ,===
1922
- EOS
1923
- output = convert_string_to_embedded input
1924
- assert_css 'table', output, 1
1925
- assert_css 'table > colgroup > col', output, 2
1926
- assert_css 'table > tbody > tr', output, 1
1927
- assert_xpath '/table/tbody/tr[1]/td', output, 2
1928
- assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A"]', output, 1
1929
- assert_xpath '/table/tbody/tr[1]/td[2]/p[text()="B"]', output, 1
1930
- end
1931
-
1932
- test 'csv format shorthand' do
1933
- input = <<-EOS
1934
- ,===
1935
- a,b,c
1936
- 1,2,3
1937
- ,===
1938
- EOS
1939
- output = convert_string_to_embedded input
1940
- assert_css 'table', output, 1
1941
- assert_css 'table > colgroup > col', output, 3
1942
- assert_css 'table > tbody > tr', output, 2
1943
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
1944
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
1945
- end
1946
-
1947
- test 'tsv as format' do
1948
- input = <<-EOS
1949
- [format=tsv]
1950
- ,===
1951
- a\tb\tc
1952
- 1\t2\t3
1953
- ,===
1954
- EOS
1955
- output = convert_string_to_embedded input
1956
- assert_css 'table', output, 1
1957
- assert_css 'table > colgroup > col', output, 3
1958
- assert_css 'table > tbody > tr', output, 2
1959
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
1960
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
1961
- end
1962
-
1963
- test 'custom csv separator' do
1964
- input = <<-EOS
1965
- [format=csv,separator=;]
1966
- |===
1967
- a;b;c
1968
- 1;2;3
1969
- |===
1970
- EOS
1971
- output = convert_string_to_embedded input
1972
- assert_css 'table', output, 1
1973
- assert_css 'table > colgroup > col', output, 3
1974
- assert_css 'table > tbody > tr', output, 2
1975
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
1976
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
1977
- end
1978
-
1979
- test 'tab as separator' do
1980
- input = <<-EOS
1981
- [separator=\\t]
1982
- ,===
1983
- a\tb\tc
1984
- 1\t2\t3
1985
- ,===
1986
- EOS
1987
- output = convert_string_to_embedded input
1988
- assert_css 'table', output, 1
1989
- assert_css 'table > colgroup > col', output, 3
1990
- assert_css 'table > tbody > tr', output, 2
1991
- assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
1992
- assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
1993
- end
1994
-
1995
- test 'single cell in CSV table should only produce single row' do
1996
- input = <<-EOS
1997
- ,===
1998
- single cell
1999
- ,===
2000
- EOS
2001
-
2002
- output = convert_string_to_embedded input
2003
- assert_css 'table td', output, 1
2004
- end
2005
-
2006
- test 'cell formatted with AsciiDoc style' do
2007
- input = <<-EOS
2008
- [cols="1,1,1a",separator=;]
2009
- ,===
2010
- element;description;example
2011
-
2012
- thematic break,a visible break; also known as a horizontal rule;---
2013
- ,===
2014
- EOS
2015
-
2016
- output = convert_string_to_embedded input
2017
- assert_css 'table tbody hr', output, 1
2018
- end
2019
-
2020
- test 'should strip whitespace around contents of AsciiDoc cell' do
2021
- input = <<-EOS
2022
- [cols="1,1,1a",separator=;]
2023
- ,===
2024
- element;description;example
2025
-
2026
- paragraph;contiguous lines of words and phrases;"
2027
- one sentence, one line
2028
- "
2029
- ,===
2030
- EOS
2031
-
2032
- output = convert_string_to_embedded input
2033
- assert_xpath '/table/tbody//*[@class="paragraph"]/p[text()="one sentence, one line"]', output, 1
2034
- end
2035
- end
2036
- end