review 5.5.0 → 5.7.0

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +31 -0
  3. data/.github/workflows/ruby-tex.yml +1 -1
  4. data/.github/workflows/ruby-win.yml +1 -1
  5. data/.github/workflows/ruby.yml +2 -2
  6. data/.rubocop.yml +13 -2
  7. data/NEWS.ja.md +40 -0
  8. data/NEWS.md +39 -0
  9. data/README.md +1 -1
  10. data/doc/format.ja.md +70 -33
  11. data/doc/format.md +69 -34
  12. data/doc/quickstart.ja.md +7 -1
  13. data/doc/quickstart.md +7 -1
  14. data/lib/review/book/base.rb +1 -1
  15. data/lib/review/builder.rb +6 -10
  16. data/lib/review/epubmaker/epubcommon.rb +13 -7
  17. data/lib/review/epubmaker/epubv2.rb +0 -5
  18. data/lib/review/epubmaker/epubv3.rb +9 -1
  19. data/lib/review/epubmaker/producer.rb +2 -3
  20. data/lib/review/epubmaker.rb +2 -4
  21. data/lib/review/htmlbuilder.rb +2 -2
  22. data/lib/review/i18n.yml +24 -2
  23. data/lib/review/idgxmlbuilder.rb +29 -10
  24. data/lib/review/idgxmlmaker.rb +11 -1
  25. data/lib/review/img_math.rb +9 -2
  26. data/lib/review/init.rb +10 -5
  27. data/lib/review/latexbuilder.rb +2 -2
  28. data/lib/review/lineinput.rb +2 -2
  29. data/lib/review/makerhelper.rb +2 -2
  30. data/lib/review/pdfmaker.rb +3 -5
  31. data/lib/review/update.rb +3 -7
  32. data/lib/review/version.rb +1 -1
  33. data/lib/review/yamlloader.rb +0 -3
  34. data/review.gemspec +3 -3
  35. data/samples/syntax-book/Gemfile +1 -1
  36. data/templates/latex/config.erb +6 -1
  37. data/templates/latex/review-jlreq/review-base.sty +11 -8
  38. data/templates/latex/review-jsbook/review-base.sty +15 -11
  39. data/templates/opf/epubv2.opf.erb +2 -0
  40. data/templates/opf/epubv3.opf.erb +2 -0
  41. data/templates/opf/opf_manifest_epubv2.opf.erb +2 -0
  42. data/templates/opf/opf_manifest_epubv3.opf.erb +2 -0
  43. data/templates/opf/opf_tocx_epubv3.opf.erb +2 -0
  44. metadata +24 -139
  45. data/test/assets/black.eps +0 -280
  46. data/test/assets/fit.png +0 -0
  47. data/test/assets/header_listener.html +0 -35
  48. data/test/assets/img_math/img1.png +0 -0
  49. data/test/assets/img_math/img2.png +0 -0
  50. data/test/assets/img_math/img3.png +0 -0
  51. data/test/assets/large.gif +0 -0
  52. data/test/assets/large.jpg +0 -0
  53. data/test/assets/large.png +0 -0
  54. data/test/assets/large.svg +0 -65
  55. data/test/assets/syntax_book_index_detail.txt +0 -60
  56. data/test/assets/test.xml.erb +0 -3
  57. data/test/assets/test_template.tex +0 -179
  58. data/test/assets/test_template_backmatter.tex +0 -190
  59. data/test/book_test_helper.rb +0 -44
  60. data/test/run_test.rb +0 -12
  61. data/test/test_book.rb +0 -588
  62. data/test/test_book_chapter.rb +0 -329
  63. data/test/test_book_part.rb +0 -53
  64. data/test/test_builder.rb +0 -126
  65. data/test/test_catalog.rb +0 -174
  66. data/test/test_catalog_converter_cmd.rb +0 -73
  67. data/test/test_compiler.rb +0 -52
  68. data/test/test_configure.rb +0 -91
  69. data/test/test_converter.rb +0 -21
  70. data/test/test_epub3maker.rb +0 -733
  71. data/test/test_epubmaker.rb +0 -931
  72. data/test/test_epubmaker_cmd.rb +0 -56
  73. data/test/test_extentions_hash.rb +0 -66
  74. data/test/test_helper.rb +0 -62
  75. data/test/test_htmlbuilder.rb +0 -3312
  76. data/test/test_htmltoc.rb +0 -29
  77. data/test/test_htmlutils.rb +0 -43
  78. data/test/test_i18n.rb +0 -300
  79. data/test/test_idgxmlbuilder.rb +0 -1487
  80. data/test/test_idgxmlmaker_cmd.rb +0 -50
  81. data/test/test_image_finder.rb +0 -81
  82. data/test/test_img_math.rb +0 -120
  83. data/test/test_index.rb +0 -287
  84. data/test/test_indexbuilder.rb +0 -52
  85. data/test/test_latexbuilder.rb +0 -2964
  86. data/test/test_latexbuilder_v2.rb +0 -1654
  87. data/test/test_lineinput.rb +0 -104
  88. data/test/test_location.rb +0 -30
  89. data/test/test_logger.rb +0 -33
  90. data/test/test_makerhelper.rb +0 -44
  91. data/test/test_markdownbuilder.rb +0 -371
  92. data/test/test_md2inaobuilder.rb +0 -90
  93. data/test/test_pdfmaker.rb +0 -354
  94. data/test/test_pdfmaker_cmd.rb +0 -130
  95. data/test/test_plaintextbuilder.rb +0 -1211
  96. data/test/test_preprocessor.rb +0 -196
  97. data/test/test_review_ext.rb +0 -30
  98. data/test/test_reviewheaderlistener.rb +0 -49
  99. data/test/test_rstbuilder.rb +0 -616
  100. data/test/test_sec_counter.rb +0 -156
  101. data/test/test_template.rb +0 -33
  102. data/test/test_textmaker_cmd.rb +0 -58
  103. data/test/test_textutils.rb +0 -187
  104. data/test/test_tocprinter.rb +0 -46
  105. data/test/test_topbuilder.rb +0 -1298
  106. data/test/test_update.rb +0 -473
  107. data/test/test_webtocprinter.rb +0 -195
  108. data/test/test_yamlloader.rb +0 -186
  109. data/test/test_zip_exporter.rb +0 -106
@@ -1,3312 +0,0 @@
1
- require 'test_helper'
2
- require 'book_test_helper'
3
- require 'review'
4
-
5
- class HTMLBuidlerTest < Test::Unit::TestCase
6
- include ReVIEW
7
- include BookTestHelper
8
-
9
- def setup
10
- ReVIEW::I18n.setup
11
- @config = ReVIEW::Configure.values
12
- @config['secnolevel'] = 2
13
- @config['stylesheet'] = nil
14
- @config['htmlext'] = 'html'
15
- @config['epubmaker'] = {}
16
- @book = Book::Base.new('.')
17
- @book.config = @config
18
- img_math = ReVIEW::ImgMath.new(@config)
19
- @log_io = StringIO.new
20
- ReVIEW.logger = ReVIEW::Logger.new(@log_io)
21
- @builder = HTMLBuilder.new(img_math: img_math)
22
- @compiler = ReVIEW::Compiler.new(@builder)
23
- @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
24
- location = Location.new(nil, nil)
25
- @builder.bind(@compiler, @chapter, location)
26
- I18n.setup('ja')
27
- @skip_pygments = true # temporary suppress pygments test
28
- end
29
-
30
- def test_xmlns_ops_prefix_epub3
31
- assert_equal 'epub', @builder.xmlns_ops_prefix
32
- end
33
-
34
- def test_xmlns_ops_prefix_epub2
35
- @book.config['epubversion'] = 2
36
- assert_equal 'ops', @builder.xmlns_ops_prefix
37
- end
38
-
39
- def test_headline_level1
40
- actual = compile_block("={test} this is test.\n")
41
- assert_equal %Q(<h1 id="test"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n), actual
42
- end
43
-
44
- def test_headline_level1_postdef
45
- @chapter.instance_eval do
46
- def on_appendix?
47
- true
48
- end
49
- end
50
- actual = compile_block("={test} this is test.\n")
51
- assert_equal %Q(<h1 id="test"><a id="hA"></a><span class="secno">付録A </span>this is test.</h1>\n), actual
52
- end
53
-
54
- def test_headline_level2_postdef
55
- @chapter.instance_eval do
56
- def on_appendix?
57
- true
58
- end
59
- end
60
- actual = compile_block("=={test} this is test.\n")
61
- assert_equal %Q(\n<h2 id="test"><a id="hA-1"></a><span class="secno">A.1 </span>this is test.</h2>\n), actual
62
- end
63
-
64
- def test_headline_postdef_roman
65
- Dir.mktmpdir do |dir|
66
- Dir.chdir(dir) do
67
- file = File.join(dir, 'locale.yml')
68
- File.write(file, "locale: ja\nappendix: 付録%pR")
69
- I18n.setup('ja')
70
- @chapter.instance_eval do
71
- def on_appendix?
72
- true
73
- end
74
- end
75
-
76
- actual = compile_block("={test} this is test.\n")
77
- assert_equal %Q(<h1 id="test"><a id="hI"></a><span class="secno">付録I </span>this is test.</h1>\n), actual
78
-
79
- actual = compile_block("=={test} this is test.\n")
80
- assert_equal %Q(\n<h2 id="test"><a id="hI-1"></a><span class="secno">I.1 </span>this is test.</h2>\n), actual
81
- end
82
- end
83
- end
84
-
85
- def test_headline_postdef_alpha
86
- Dir.mktmpdir do |dir|
87
- Dir.chdir(dir) do
88
- file = File.join(dir, 'locale.yml')
89
- File.write(file, "locale: ja\nappendix: 付録%pA")
90
- I18n.setup('ja')
91
- @chapter.instance_eval do
92
- def on_appendix?
93
- true
94
- end
95
- end
96
-
97
- actual = compile_block("={test} this is test.\n")
98
- assert_equal %Q(<h1 id="test"><a id="hA"></a><span class="secno">付録A </span>this is test.</h1>\n), actual
99
-
100
- actual = compile_block("=={test} this is test.\n")
101
- assert_equal %Q(\n<h2 id="test"><a id="hA-1"></a><span class="secno">A.1 </span>this is test.</h2>\n), actual
102
- end
103
- end
104
- end
105
-
106
- def test_headline_level1_without_secno
107
- @book.config['secnolevel'] = 0
108
- actual = compile_block("={test} this is test.\n")
109
- assert_equal %Q(<h1 id="test"><a id="h1"></a>this is test.</h1>\n), actual
110
- end
111
-
112
- def test_headline_level1_with_tricky_id
113
- actual = compile_block("={123あ_} this is test.\n")
114
- assert_equal %Q(<h1 id="id_123_E3_81_82__"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n), actual
115
- end
116
-
117
- def test_headline_level1_with_inlinetag
118
- actual = compile_block(%Q(={test} this @<b>{is} test.<&">\n))
119
- assert_equal %Q(<h1 id="test"><a id="h1"></a><span class="secno">第1章 </span>this <b>is</b> test.&lt;&amp;&quot;&gt;</h1>\n), actual
120
- end
121
-
122
- def test_headline_level2
123
- actual = compile_block("=={test} this is test.\n")
124
- assert_equal %Q(\n<h2 id="test"><a id="h1-1"></a><span class="secno">1.1 </span>this is test.</h2>\n), actual
125
- end
126
-
127
- def test_headline_level3
128
- actual = compile_block("==={test} this is test.\n")
129
- assert_equal %Q(\n<h3 id="test"><a id="h1-0-1"></a>this is test.</h3>\n), actual
130
- end
131
-
132
- def test_headline_level3_with_secno
133
- @book.config['secnolevel'] = 3
134
- actual = compile_block("==={test} this is test.\n")
135
- assert_equal %Q(\n<h3 id="test"><a id="h1-0-1"></a><span class="secno">1.0.1 </span>this is test.</h3>\n), actual
136
- end
137
-
138
- def test_headline_sections
139
- @book.config['epubmaker']['use_section'] = true
140
- actual = compile_block("= H1\n== H2\n== H2-2\n")
141
- expected = <<-EOS
142
- <section class="level1"><h1><a id="h1"></a><span class="secno">第1章 </span>H1</h1>
143
- <section class="level2">
144
- <h2><a id="h1-1"></a><span class="secno">1.1 </span>H2</h2>
145
- </section>
146
- <section class="level2">
147
- <h2><a id="h1-2"></a><span class="secno">1.2 </span>H2-2</h2>
148
- </section>
149
- </section>
150
- EOS
151
- assert_equal expected, actual
152
-
153
- actual = compile_block("= H1\n== H2\n==== H4\n== H2-2\n")
154
- expected = <<-EOS
155
- <section class="level1"><h1><a id="h1"></a><span class="secno">第1章 </span>H1</h1>
156
- <section class="level2">
157
- <h2><a id="h1-1"></a><span class="secno">1.1 </span>H2</h2>
158
- <section class="level4">
159
- <h4><a id="h1-1-0-1"></a>H4</h4>
160
- </section>
161
- </section>
162
- <section class="level2">
163
- <h2><a id="h1-2"></a><span class="secno">1.2 </span>H2-2</h2>
164
- </section>
165
- </section>
166
- EOS
167
- assert_equal expected, actual
168
-
169
- actual = compile_block("===== H5\n= H1\n")
170
- expected = <<-EOS
171
- <section class="level5">
172
- <h5><a id="h1-0-0-0-1"></a>H5</h5>
173
- </section>
174
- <section class="level1"><h1><a id="h1"></a><span class="secno">第1章 </span>H1</h1>
175
- </section>
176
- EOS
177
- assert_equal expected, actual
178
- end
179
-
180
- def test_label
181
- actual = compile_block("//label[label_test]\n")
182
- assert_equal %Q(<a id="label_test"></a>\n), actual
183
- end
184
-
185
- def test_label_with_tricky_id
186
- actual = compile_block("//label[123あ_]\n")
187
- assert_equal %Q(<a id="id_123_E3_81_82__"></a>\n), actual
188
- end
189
-
190
- def test_href
191
- actual = compile_inline('@<href>{http://github.com,GitHub}')
192
- assert_equal %Q(<a href="http://github.com" class="link">GitHub</a>), actual
193
- end
194
-
195
- def test_href_without_label
196
- actual = compile_inline('@<href>{http://github.com}')
197
- assert_equal %Q(<a href="http://github.com" class="link">http://github.com</a>), actual
198
- end
199
-
200
- def test_inline_href
201
- actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
202
- assert_equal %Q(<a href="http://github.com" class="link">Git,Hub</a>), actual
203
-
204
- @book.config['epubmaker'] ||= {}
205
- @book.config['epubmaker']['externallink'] = false
206
- actual = compile_inline('@<href>{http://github.com&q=1,Git\\,Hub}')
207
- assert_equal %Q(<a href="http://github.com&amp;q=1" class="link">Git,Hub</a>), actual
208
-
209
- actual = compile_inline('@<href>{http://github.com&q=1}')
210
- assert_equal %Q(<a href="http://github.com&amp;q=1" class="link">http://github.com&amp;q=1</a>), actual
211
- end
212
-
213
- def test_inline_href_epubmaker
214
- @book.config.maker = 'epubmaker'
215
- actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
216
- assert_equal %Q(<a href="http://github.com" class="link">Git,Hub</a>), actual
217
-
218
- @book.config['epubmaker'] ||= {}
219
- @book.config['epubmaker']['externallink'] = false
220
- actual = compile_inline('@<href>{http://github.com&q=1,Git\\,Hub}')
221
- assert_equal 'Git,Hub(http://github.com&amp;q=1)', actual
222
-
223
- actual = compile_inline('@<href>{http://github.com&q=1}')
224
- assert_equal 'http://github.com&amp;q=1', actual
225
-
226
- @book.config['epubmaker']['externallink'] = true
227
- actual = compile_inline('@<href>{http://github.com&q=1,Git\\,Hub}')
228
- assert_equal %Q(<a href="http://github.com&amp;q=1" class="link">Git,Hub</a>), actual
229
- actual = compile_inline('@<href>{http://github.com&q=1}')
230
- assert_equal %Q(<a href="http://github.com&amp;q=1" class="link">http://github.com&amp;q=1</a>), actual
231
- end
232
-
233
- def test_inline_raw
234
- actual = compile_inline('@<raw>{@<tt>{inline\\}}')
235
- assert_equal '@<tt>{inline}', actual
236
- end
237
-
238
- def test_inline_in_table
239
- actual = compile_block("//table{\n@<b>{1}\t@<i>{2}\n------------\n@<b>{3}\t@<i>{4}<>&\n//}\n")
240
- expected = <<-EOS
241
- <div class="table">
242
- <table>
243
- <tr><th><b>1</b></th><th><i>2</i></th></tr>
244
- <tr><td><b>3</b></td><td><i>4</i>&lt;&gt;&amp;</td></tr>
245
- </table>
246
- </div>
247
- EOS
248
- assert_equal expected, actual
249
- end
250
-
251
- def test_inline_br
252
- actual = compile_inline('@<br>{}')
253
- assert_equal '<br />', actual
254
- end
255
-
256
- def test_inline_i
257
- actual = compile_inline('test @<i>{inline test} test2')
258
- assert_equal 'test <i>inline test</i> test2', actual
259
- end
260
-
261
- def test_inline_i_and_escape
262
- actual = compile_inline('test @<i>{inline<&;\\ test} test2')
263
- assert_equal 'test <i>inline&lt;&amp;;\\ test</i> test2', actual
264
- end
265
-
266
- def test_inline_b
267
- actual = compile_inline('test @<b>{inline test} test2')
268
- assert_equal 'test <b>inline test</b> test2', actual
269
- end
270
-
271
- def test_inline_b_and_escape
272
- actual = compile_inline('test @<b>{inline<&;\\ test} test2')
273
- assert_equal 'test <b>inline&lt;&amp;;\\ test</b> test2', actual
274
- end
275
-
276
- def test_inline_tt
277
- actual = compile_inline('test @<tt>{inline test} test2')
278
- assert_equal %Q(test <code class="tt">inline test</code> test2), actual
279
- end
280
-
281
- def test_inline_tti
282
- actual = compile_inline('test @<tti>{inline test} test2')
283
- assert_equal %Q(test <code class="tt"><i>inline test</i></code> test2), actual
284
- end
285
-
286
- def test_inline_ttb
287
- actual = compile_inline('test @<ttb>{inline test} test2')
288
- assert_equal %Q(test <code class="tt"><b>inline test</b></code> test2), actual
289
- end
290
-
291
- def test_inline_hd_chap
292
- def @chapter.headline_index
293
- item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
294
- idx = Book::HeadlineIndex.new(self)
295
- idx.add_item(item)
296
- idx
297
- end
298
-
299
- @config['secnolevel'] = 2
300
- actual = compile_inline('test @<hd>{chap1|test} test2')
301
- assert_equal 'test <a href="-.html#h1-1-1">「te_st」</a> test2', actual
302
-
303
- @config['secnolevel'] = 3
304
- actual = compile_inline('test @<hd>{chap1|test} test2')
305
- assert_equal 'test <a href="-.html#h1-1-1">「1.1.1 te_st」</a> test2', actual
306
-
307
- @config['chapterlink'] = nil
308
- @config['secnolevel'] = 2
309
- actual = compile_inline('test @<hd>{chap1|test} test2')
310
- assert_equal 'test 「te_st」 test2', actual
311
-
312
- @config['secnolevel'] = 3
313
- actual = compile_inline('test @<hd>{chap1|test} test2')
314
- assert_equal 'test 「1.1.1 te_st」 test2', actual
315
- end
316
-
317
- def test_inline_hd_chap_postdef_roman
318
- Dir.mktmpdir do |dir|
319
- Dir.chdir(dir) do
320
- file = File.join(dir, 'locale.yml')
321
- File.write(file, "locale: ja\nappendix: 付録%pR")
322
- I18n.setup('ja')
323
- @chapter.instance_eval do
324
- def on_appendix?
325
- true
326
- end
327
- end
328
-
329
- def @chapter.headline_index
330
- item = Book::Index::Item.new('test', [1], 'te_st')
331
- idx = Book::HeadlineIndex.new(self)
332
- idx.add_item(item)
333
- idx
334
- end
335
-
336
- actual = compile_inline('test @<hd>{test} test2')
337
- assert_equal 'test <a href="-.html#hI-1">「I.1 te_st」</a> test2', actual
338
-
339
- @config['chapterlink'] = nil
340
- actual = compile_inline('test @<hd>{test} test2')
341
- assert_equal 'test 「I.1 te_st」 test2', actual
342
- end
343
- end
344
- end
345
-
346
- def test_inline_hd_chap_postdef_alpha
347
- Dir.mktmpdir do |dir|
348
- Dir.chdir(dir) do
349
- file = File.join(dir, 'locale.yml')
350
- File.write(file, "locale: ja\nappendix: 付録%pA")
351
- I18n.setup('ja')
352
- @chapter.instance_eval do
353
- def on_appendix?
354
- true
355
- end
356
- end
357
-
358
- def @chapter.headline_index
359
- item = Book::Index::Item.new('test', [1], 'te_st')
360
- idx = Book::HeadlineIndex.new(self)
361
- idx.add_item(item)
362
- idx
363
- end
364
-
365
- actual = compile_inline('test @<hd>{test} test2')
366
- assert_equal 'test <a href="-.html#hA-1">「A.1 te_st」</a> test2', actual
367
-
368
- @config['chapterlink'] = nil
369
- actual = compile_inline('test @<hd>{test} test2')
370
- assert_equal 'test 「A.1 te_st」 test2', actual
371
- end
372
- end
373
- end
374
-
375
- def test_inline_sec
376
- def @chapter.headline_index
377
- item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st<>')
378
- idx = Book::HeadlineIndex.new(self)
379
- idx.add_item(item)
380
- idx
381
- end
382
-
383
- @config['secnolevel'] = 3
384
- actual = compile_inline('test @<secref>{test}')
385
- assert_equal 'test <a href="-.html#h1-1-1">「1.1.1 te_st&lt;&gt;」</a>', actual
386
- actual = compile_inline('test @<sectitle>{test}')
387
- assert_equal 'test <a href="-.html#h1-1-1">te_st&lt;&gt;</a>', actual
388
- actual = compile_inline('test @<sec>{test}')
389
- assert_equal 'test <a href="-.html#h1-1-1">1.1.1</a>', actual
390
-
391
- @config['secnolevel'] = 2
392
- actual = compile_inline('test @<secref>{test}')
393
- assert_equal 'test <a href="-.html#h1-1-1">「te_st&lt;&gt;」</a>', actual
394
- actual = compile_inline('test @<sectitle>{test}')
395
- assert_equal 'test <a href="-.html#h1-1-1">te_st&lt;&gt;</a>', actual
396
- assert_raises(ReVIEW::ApplicationError) { compile_block('test @<sec>{test}') }
397
- assert_match(/the target headline doesn't have a number/, @log_io.string)
398
-
399
- @config['chapterlink'] = nil
400
- @config['secnolevel'] = 3
401
- actual = compile_inline('test @<secref>{test}')
402
- assert_equal 'test 「1.1.1 te_st&lt;&gt;」', actual
403
- actual = compile_inline('test @<sectitle>{test}')
404
- assert_equal 'test te_st&lt;&gt;', actual
405
- actual = compile_inline('test @<sec>{test}')
406
- assert_equal 'test 1.1.1', actual
407
- end
408
-
409
- def test_inline_uchar
410
- actual = compile_inline('test @<uchar>{2460} test2')
411
- assert_equal 'test &#x2460; test2', actual
412
- end
413
-
414
- def test_inline_balloon
415
- actual = compile_inline('test @<balloon>{①}')
416
- assert_equal %Q(test <span class="balloon">①</span>), actual
417
- end
418
-
419
- def test_inline_ruby
420
- actual = compile_inline('@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。')
421
- assert_equal '<ruby>粗雑<rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby>繊細<rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。', actual
422
- end
423
-
424
- def test_inline_ruby_comma
425
- actual = compile_inline('@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}')
426
- assert_equal '<ruby>foo, bar, buz<rp>(</rp><rt>フー・バー・バズ</rt><rp>)</rp></ruby>', actual
427
- end
428
-
429
- def test_inline_ref
430
- actual = compile_inline('@<ref>{外部参照<>&}')
431
- assert_equal %Q(<a target='外部参照&lt;&gt;&amp;'>「●● 外部参照&lt;&gt;&amp;」</a>), actual
432
- end
433
-
434
- def test_inline_mathml
435
- begin
436
- require 'math_ml'
437
- require 'math_ml/symbol/character_reference'
438
- rescue LoadError
439
- return true
440
- end
441
- @config['math_format'] = 'mathml'
442
- actual = compile_inline('@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}')
443
- assert_equal %Q(<span class="equation"><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mfrac><mrow><mo stretchy='false'>-</mo><mi>b</mi><mo stretchy='false'>&#xb1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo stretchy='false'>-</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math></span>), actual
444
- end
445
-
446
- def test_inline_mathjax
447
- @config['math_format'] = 'mathjax'
448
- actual = compile_inline('@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}')
449
- assert_equal %Q(<span class="equation">\\( \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a} \\)</span>), actual
450
-
451
- content = <<-EOF
452
- //texequation{
453
- \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}
454
- //}
455
- EOF
456
- actual = compile_block(content)
457
- expected = %Q(<div class="equation">\n$$\\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$\n</div>\n)
458
- assert_equal expected, actual
459
- end
460
-
461
- def test_inline_img
462
- def @chapter.image(_id)
463
- item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
464
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
465
- item
466
- end
467
-
468
- actual = compile_block("@<img>{sampleimg}\n")
469
- expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n)
470
- assert_equal expected, actual
471
-
472
- @config['chapterlink'] = nil
473
- actual = compile_block("@<img>{sampleimg}\n")
474
- expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
475
- assert_equal expected, actual
476
- end
477
-
478
- def test_inline_imgref
479
- def @chapter.image(_id)
480
- item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
481
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
482
- item
483
- end
484
-
485
- actual = compile_block("@<imgref>{sampleimg}\n")
486
- expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span>「sample photo」</p>\n)
487
- assert_equal expected, actual
488
-
489
- @config['chapterlink'] = nil
490
- actual = compile_block("@<imgref>{sampleimg}\n")
491
- expected = %Q(<p><span class="imgref">図1.1</span>「sample photo」</p>\n)
492
- assert_equal expected, actual
493
- end
494
-
495
- def test_inline_imgref2
496
- def @chapter.image(_id)
497
- item = Book::Index::Item.new('sampleimg', 1)
498
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
499
- item
500
- end
501
-
502
- actual = compile_block("@<imgref>{sampleimg}\n")
503
- expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n)
504
- assert_equal expected, actual
505
-
506
- @config['chapterlink'] = nil
507
- actual = compile_block("@<imgref>{sampleimg}\n")
508
- expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
509
- assert_equal expected, actual
510
- end
511
-
512
- def test_inline_imgref3
513
- Dir.mktmpdir do |dir|
514
- Dir.chdir(dir) do
515
- file1 = File.join(dir, 'images', 'img1.png')
516
- filet1 = File.join(dir, 'images', 'tbl1.png')
517
- file2 = File.join(dir, 'images', 'img2.png')
518
- file3 = File.join(dir, 'images', 'icon3.png')
519
- re1 = File.join(dir, 'sample1.re')
520
- cat = File.join(dir, 'catalog.yml')
521
- FileUtils.mkdir_p(File.join(dir, 'images'))
522
- File.write(file1, '')
523
- File.write(filet1, '')
524
- File.write(file2, '')
525
- File.write(file3, '')
526
- File.write(cat, "CHAPS:\n - sample1.re\n")
527
- File.write(re1, <<-EOF)
528
- = test
529
-
530
- tbl1 is @<table>{tbl1}.
531
-
532
- img2 is @<img>{img2}.
533
-
534
- icon3 is @<icon>{icon3}.
535
-
536
- //image[img1][image 1]{
537
- //}
538
-
539
- //imgtable[tbl1][table 1]{
540
- //}
541
-
542
- //image[img2][image 2]{
543
- //}
544
- EOF
545
- content = File.read(re1)
546
- actual = compile_block(content)
547
-
548
- expected = <<-EOS
549
- <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
550
- <p>tbl1 is <span class="tableref"><a href="./-.html#tbl1">表1.1</a></span>.</p>
551
- <p>img2 is <span class="imgref"><a href="./-.html#img2">図1.2</a></span>.</p>
552
- <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
553
- <div id="img1" class="image">
554
- <img src="images/img1.png" alt="image 1" />
555
- <p class="caption">
556
- 図1.1: image 1
557
- </p>
558
- </div>
559
- <div id="tbl1" class="imgtable image">
560
- <p class="caption">表1.1: table 1</p>
561
- <img src="images/tbl1.png" alt="table 1" />
562
- </div>
563
- <div id="img2" class="image">
564
- <img src="images/img2.png" alt="image 2" />
565
- <p class="caption">
566
- 図1.2: image 2
567
- </p>
568
- </div>
569
- EOS
570
-
571
- assert_equal expected, actual
572
-
573
- @config['chapterlink'] = nil
574
- actual = compile_block(content)
575
-
576
- expected = <<-EOS
577
- <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
578
- <p>tbl1 is <span class="tableref">表1.1</span>.</p>
579
- <p>img2 is <span class="imgref">図1.2</span>.</p>
580
- <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
581
- <div id="img1" class="image">
582
- <img src="images/img1.png" alt="image 1" />
583
- <p class="caption">
584
- 図1.1: image 1
585
- </p>
586
- </div>
587
- <div id="tbl1" class="imgtable image">
588
- <p class="caption">表1.1: table 1</p>
589
- <img src="images/tbl1.png" alt="table 1" />
590
- </div>
591
- <div id="img2" class="image">
592
- <img src="images/img2.png" alt="image 2" />
593
- <p class="caption">
594
- 図1.2: image 2
595
- </p>
596
- </div>
597
- EOS
598
-
599
- assert_equal expected, actual
600
- end
601
- end
602
- end
603
-
604
- def test_quote
605
- actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
606
- expected = <<-EOS
607
- <blockquote><p>foobar</p>
608
- <p>buz</p></blockquote>
609
- EOS
610
- assert_equal expected, actual
611
-
612
- @book.config['join_lines_by_lang'] = true
613
- actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
614
- expected = <<-EOS
615
- <blockquote><p>foo bar</p>
616
- <p>buz</p></blockquote>
617
- EOS
618
- assert_equal expected, actual
619
- end
620
-
621
- def test_memo
622
- actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
623
- expected = <<-EOS
624
- <div class="memo">
625
- <p class="caption">this is <b>test</b>&lt;&amp;&gt;_</p>
626
- <p>test1</p>
627
- <p>test<i>2</i></p>
628
- </div>
629
- EOS
630
- assert_equal expected, actual
631
- end
632
-
633
- def test_blankline
634
- actual = compile_block("//blankline\nfoo\n")
635
- expected = <<-EOS
636
- <p><br /></p>
637
- <p>foo</p>
638
- EOS
639
- assert_equal expected, actual
640
- end
641
-
642
- def test_noindent
643
- actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
644
- expected = <<-EOS
645
- <p class="noindent">foobar</p>
646
- <p>foo2bar2</p>
647
- EOS
648
- assert_equal expected, actual
649
-
650
- @book.config['join_lines_by_lang'] = true
651
- actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
652
- expected = <<-EOS
653
- <p class="noindent">foo bar</p>
654
- <p>foo2 bar2</p>
655
- EOS
656
- assert_equal expected, actual
657
- end
658
-
659
- def test_flushright
660
- actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
661
- expected = <<-EOS
662
- <p class="flushright">foobar</p>
663
- <p class="flushright">buz</p>
664
- EOS
665
- assert_equal expected, actual
666
-
667
- @book.config['join_lines_by_lang'] = true
668
- actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
669
- expected = <<-EOS
670
- <p class="flushright">foo bar</p>
671
- <p class="flushright">buz</p>
672
- EOS
673
- assert_equal expected, actual
674
- end
675
-
676
- def test_centering
677
- actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
678
- expected = <<-EOS
679
- <p class="center">foobar</p>
680
- <p class="center">buz</p>
681
- EOS
682
- assert_equal expected, actual
683
-
684
- @book.config['join_lines_by_lang'] = true
685
- actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
686
- expected = <<-EOS
687
- <p class="center">foo bar</p>
688
- <p class="center">buz</p>
689
- EOS
690
- assert_equal expected, actual
691
- end
692
-
693
- def test_image
694
- def @chapter.image(_id)
695
- item = Book::Index::Item.new('sampleimg', 1)
696
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
697
- item
698
- end
699
-
700
- actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
701
- expected = <<-EOS
702
- <div id="sampleimg" class="image">
703
- <img src="images/chap1-sampleimg.png" alt="sample photo" />
704
- <p class="caption">
705
- 図1.1: sample photo
706
- </p>
707
- </div>
708
- EOS
709
- assert_equal expected, actual
710
-
711
- actual = compile_block("//image[sampleimg][]{\n//}\n")
712
- expected = <<-EOS
713
- <div id="sampleimg" class="image">
714
- <img src="images/chap1-sampleimg.png" alt="" />
715
- <p class="caption">
716
- 図1.1:
717
- </p>
718
- </div>
719
- EOS
720
- assert_equal expected, actual
721
-
722
- actual = compile_block("//image[sampleimg][][]{\n//}\n")
723
- assert_equal expected, actual
724
-
725
- @config['caption_position']['image'] = 'top'
726
- actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
727
- expected = <<-EOS
728
- <div id="sampleimg" class="image">
729
- <p class="caption">
730
- 図1.1: sample photo
731
- </p>
732
- <img src="images/chap1-sampleimg.png" alt="sample photo" />
733
- </div>
734
- EOS
735
- assert_equal expected, actual
736
- end
737
-
738
- def test_image_with_metric
739
- def @chapter.image(_id)
740
- item = Book::Index::Item.new('sampleimg', 1)
741
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
742
- item
743
- end
744
-
745
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
746
- expected = <<-EOS
747
- <div id="sampleimg" class="image">
748
- <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />
749
- <p class="caption">
750
- 図1.1: sample photo
751
- </p>
752
- </div>
753
- EOS
754
- assert_equal expected, actual
755
- end
756
-
757
- def test_image_with_metric2
758
- def @chapter.image(_id)
759
- item = Book::Index::Item.new('sampleimg', 1)
760
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
761
- item
762
- end
763
-
764
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
765
- expected = <<-EOS
766
- <div id="sampleimg" class="image">
767
- <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />
768
- <p class="caption">
769
- 図1.1: sample photo
770
- </p>
771
- </div>
772
- EOS
773
- assert_equal expected, actual
774
- end
775
-
776
- def test_image_with_tricky_id_kana
777
- def @chapter.image(_id)
778
- item = Book::Index::Item.new('123あいう', 1)
779
- item.instance_eval { @path = './images/123あいう.png' }
780
- item
781
- end
782
- @chapter.instance_eval { @name = 'ch01' }
783
- actual = compile_block("//image[123あいう][sample photo]{\n//}\nimg: @<img>{123あいう}\n")
784
- expected = <<-EOS
785
- <div id="id_123_E3_81_82_E3_81_84_E3_81_86" class="image">
786
- <img src="images/123あいう.png" alt="sample photo" />
787
- <p class="caption">
788
- 図1.1: sample photo
789
- </p>
790
- </div>
791
- <p>img: <span class="imgref"><a href="./ch01.html#id_123_E3_81_82_E3_81_84_E3_81_86">図1.1</a></span></p>
792
- EOS
793
- assert_equal expected, actual
794
- end
795
-
796
- def test_indepimage
797
- def @chapter.image(_id)
798
- item = Book::Index::Item.new('sampleimg', 1)
799
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
800
- item
801
- end
802
-
803
- actual = compile_block("//indepimage[sampleimg][sample photo]\n")
804
- expected = <<-EOS
805
- <div id="sampleimg" class="image">
806
- <img src="images/chap1-sampleimg.png" alt="sample photo" />
807
- <p class="caption">
808
- 図: sample photo
809
- </p>
810
- </div>
811
- EOS
812
- assert_equal expected, actual
813
-
814
- @config['caption_position']['image'] = 'top'
815
- actual = compile_block("//indepimage[sampleimg][sample photo]\n")
816
- expected = <<-EOS
817
- <div id="sampleimg" class="image">
818
- <p class="caption">
819
- 図: sample photo
820
- </p>
821
- <img src="images/chap1-sampleimg.png" alt="sample photo" />
822
- </div>
823
- EOS
824
- assert_equal expected, actual
825
- end
826
-
827
- def test_indepimage_without_caption
828
- def @chapter.image(_id)
829
- item = Book::Index::Item.new('sampleimg', 1)
830
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
831
- item
832
- end
833
-
834
- actual = compile_block("//indepimage[sampleimg]\n")
835
- expected = <<-EOS
836
- <div id="sampleimg" class="image">
837
- <img src="images/chap1-sampleimg.png" alt="" />
838
- </div>
839
- EOS
840
- assert_equal expected, actual
841
-
842
- actual = compile_block("//indepimage[sampleimg][]\n")
843
- assert_equal expected, actual
844
-
845
- actual = compile_block("//indepimage[sampleimg][][]\n")
846
- assert_equal expected, actual
847
- end
848
-
849
- def test_indepimage_with_metric
850
- def @chapter.image(_id)
851
- item = Book::Index::Item.new('sampleimg', 1)
852
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
853
- item
854
- end
855
-
856
- actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
857
- expected = <<-EOS
858
- <div id="sampleimg" class="image">
859
- <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />
860
- <p class="caption">
861
- 図: sample photo
862
- </p>
863
- </div>
864
- EOS
865
- assert_equal expected, actual
866
- end
867
-
868
- def test_indepimage_with_metric2
869
- def @chapter.image(_id)
870
- item = Book::Index::Item.new('sampleimg', 1)
871
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
872
- item
873
- end
874
-
875
- actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
876
- expected = <<-EOS
877
- <div id="sampleimg" class="image">
878
- <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />
879
- <p class="caption">
880
- 図: sample photo
881
- </p>
882
- </div>
883
- EOS
884
- assert_equal expected, actual
885
- end
886
-
887
- def test_indepimage_without_caption_but_with_metric
888
- def @chapter.image(_id)
889
- item = Book::Index::Item.new('sampleimg', 1)
890
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
891
- item
892
- end
893
-
894
- actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
895
- expected = <<-EOS
896
- <div id="sampleimg" class="image">
897
- <img src="images/chap1-sampleimg.png" alt="" class="width-120per" />
898
- </div>
899
- EOS
900
- assert_equal expected, actual
901
- end
902
-
903
- def test_dlist
904
- actual = compile_block(" : foo\n foo.\n bar.\n")
905
- expected = <<-EOS
906
- <dl>
907
- <dt>foo</dt>
908
- <dd>foo.bar.</dd>
909
- </dl>
910
- EOS
911
- assert_equal expected, actual
912
-
913
- @book.config['join_lines_by_lang'] = true
914
- actual = compile_block(" : foo\n foo.\n bar.\n")
915
- expected = <<-EOS
916
- <dl>
917
- <dt>foo</dt>
918
- <dd>foo. bar.</dd>
919
- </dl>
920
- EOS
921
- assert_equal expected, actual
922
- end
923
-
924
- def test_dlist_with_bracket
925
- actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
926
- expected = <<-EOS
927
- <dl>
928
- <dt>foo[bar]</dt>
929
- <dd>foo.bar.</dd>
930
- </dl>
931
- EOS
932
- assert_equal expected, actual
933
-
934
- @book.config['join_lines_by_lang'] = true
935
- actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
936
- expected = <<-EOS
937
- <dl>
938
- <dt>foo[bar]</dt>
939
- <dd>foo. bar.</dd>
940
- </dl>
941
- EOS
942
- assert_equal expected, actual
943
- end
944
-
945
- def test_dlist_with_comment
946
- source = " : title\n body\n\#@ comment\n\#@ comment\n : title2\n body2\n"
947
- actual = compile_block(source)
948
- expected = <<-EOS
949
- <dl>
950
- <dt>title</dt>
951
- <dd>body</dd>
952
- <dt>title2</dt>
953
- <dd>body2</dd>
954
- </dl>
955
- EOS
956
- assert_equal expected, actual
957
- end
958
-
959
- def test_dlist_beforeulol
960
- actual = compile_block(" : foo\n foo.\n\npara\n\n : foo\n foo.\n\n 1. bar\n\n : foo\n foo.\n\n * bar\n")
961
- expected = <<-EOS
962
- <dl>
963
- <dt>foo</dt>
964
- <dd>foo.</dd>
965
- </dl>
966
- <p>para</p>
967
- <dl>
968
- <dt>foo</dt>
969
- <dd>foo.</dd>
970
- </dl>
971
- <ol>
972
- <li>bar</li>
973
- </ol>
974
- <dl>
975
- <dt>foo</dt>
976
- <dd>foo.</dd>
977
- </dl>
978
- <ul>
979
- <li>bar</li>
980
- </ul>
981
- EOS
982
- assert_equal expected, actual
983
- end
984
-
985
- def test_dt_inline
986
- actual = compile_block("//footnote[bar][bar]\n\n : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
987
-
988
- expected = <<-EOS
989
- <div class="footnote" epub:type="footnote" id="fn-bar"><p class="footnote">[*1] bar</p></div>
990
- <dl>
991
- <dt>foo<a id="fnb-bar" href="#fn-bar" class="noteref" epub:type="noteref">*1</a>[]&lt;&gt;&amp;<span class="equation">\\alpha[]</span></dt>
992
- <dd></dd>
993
- </dl>
994
- EOS
995
- assert_equal expected, actual
996
- end
997
-
998
- def test_list
999
- def @chapter.list(_id)
1000
- Book::Index::Item.new('samplelist', 1)
1001
- end
1002
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
1003
- expected = <<-EOS
1004
- <div id="samplelist" class="caption-code">
1005
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1006
- <pre class="list">test1
1007
- test1.5
1008
-
1009
- test<i>2</i>
1010
- </pre>
1011
- </div>
1012
- EOS
1013
- assert_equal expected, actual
1014
-
1015
- @config['caption_position']['list'] = 'bottom'
1016
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
1017
- expected = <<-EOS
1018
- <div id="samplelist" class="caption-code">
1019
- <pre class="list">test1
1020
- test1.5
1021
-
1022
- test<i>2</i>
1023
- </pre>
1024
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1025
- </div>
1026
- EOS
1027
- assert_equal expected, actual
1028
- end
1029
-
1030
- def test_inline_list
1031
- def @chapter.list(_id)
1032
- Book::Index::Item.new('samplelist', 1)
1033
- end
1034
- actual = compile_block("@<list>{samplelist}\n")
1035
- assert_equal %Q(<p><span class="listref"><a href="./-.html#samplelist">リスト1.1</a></span></p>\n), actual
1036
-
1037
- @config['chapterlink'] = nil
1038
- actual = compile_block("@<list>{samplelist}\n")
1039
- assert_equal %Q(<p><span class="listref">リスト1.1</span></p>\n), actual
1040
- end
1041
-
1042
- def test_inline_list_href
1043
- book = ReVIEW::Book::Base.new
1044
- book.config['chapterlink'] = true
1045
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
1046
- io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n")
1047
- io2 = StringIO.new("= BAR\n")
1048
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1049
- chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
1050
- book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
1051
- builder = ReVIEW::HTMLBuilder.new
1052
- comp = ReVIEW::Compiler.new(builder)
1053
- builder.bind(comp, chap2, nil)
1054
-
1055
- chap1.generate_indexes
1056
- actual = builder.inline_list('ch1|sampletest')
1057
- assert_equal %Q(<span class="listref"><a href="./ch1.html#sampletest">リスト1.1</a></span>), actual
1058
- end
1059
-
1060
- def test_list_pygments
1061
- return true if @skip_pygments
1062
-
1063
- def @chapter.list(_id)
1064
- Book::Index::Item.new('samplelist', 1)
1065
- end
1066
- begin
1067
- require 'pygments'
1068
- rescue LoadError
1069
- $stderr.puts 'skip test_list_pygments_lang (cannot find pygments.rb)'
1070
- return true
1071
- end
1072
- @book.config['highlight'] = {}
1073
- @book.config['highlight']['html'] = 'pygments'
1074
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
1075
-
1076
- expected = <<-EOS
1077
- <div id="samplelist" class="caption-code">
1078
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1079
- <pre class="list highlight">test1
1080
- test1.5
1081
-
1082
- test&lt;i&gt;2&lt;/i&gt;
1083
- </pre>
1084
- </div>
1085
- EOS
1086
- assert_equal expected, actual
1087
- end
1088
-
1089
- def test_list_pygments_lang
1090
- return true if @skip_pygments
1091
-
1092
- def @chapter.list(_id)
1093
- Book::Index::Item.new('samplelist', 1)
1094
- end
1095
- begin
1096
- require 'pygments'
1097
- rescue LoadError
1098
- $stderr.puts 'skip test_list_pygments_lang (cannot find pygments.rb)'
1099
- return true
1100
- end
1101
- @book.config['highlight'] = {}
1102
- @book.config['highlight']['html'] = 'pygments'
1103
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1104
-
1105
- expected = <<-EOS
1106
- <div id="samplelist" class="caption-code">
1107
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1108
- <pre class="list language-ruby highlight"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">foo</span>(a1, a2<span style="color: #666666">=</span><span style="color: #19177C">:test</span>)
1109
- (<span style="color: #666666">1..3</span>)<span style="color: #666666">.</span>times{<span style="color: #666666">\|</span>i<span style="color: #666666">|</span> a<span style="color: #666666">.</span>include?(<span style="color: #19177C">:foo</span>)}
1110
- <span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">true</span>
1111
- <span style="color: #008000; font-weight: bold">end</span>
1112
- </pre>
1113
- </div>
1114
- EOS
1115
-
1116
- assert_equal expected, actual
1117
- end
1118
-
1119
- def test_list_pygments_nulllang
1120
- return true if @skip_pygments
1121
-
1122
- def @chapter.list(_id)
1123
- Book::Index::Item.new('samplelist', 1)
1124
- end
1125
- begin
1126
- require 'pygments'
1127
- rescue LoadError
1128
- $stderr.puts 'skip test_list_pygments_nulllang (cannot find pygments.rb)'
1129
- return true
1130
- end
1131
- @book.config['highlight'] = {}
1132
- @book.config['highlight']['html'] = 'pygments'
1133
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1134
-
1135
- expected = <<-EOS
1136
- <div id="samplelist" class="caption-code">
1137
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1138
- <pre class="list highlight">def foo(a1, a2=:test)
1139
- (1..3).times{|i| a.include?(:foo)}
1140
- return true
1141
- end
1142
- </pre>
1143
- </div>
1144
- EOS
1145
- assert_equal expected, actual
1146
- end
1147
-
1148
- def test_list_rouge
1149
- begin
1150
- require 'rouge'
1151
- rescue LoadError
1152
- $stderr.puts 'skip test_list_rouge (cannot find Rouge)'
1153
- return true
1154
- end
1155
- def @chapter.list(_id)
1156
- Book::Index::Item.new('samplelist', 1)
1157
- end
1158
- @book.config['highlight'] = {}
1159
- @book.config['highlight']['html'] = 'rouge'
1160
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
1161
-
1162
- expected = <<-EOS
1163
- <div id="samplelist" class="caption-code">
1164
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1165
- <pre class="list highlight">test1
1166
- test1.5
1167
-
1168
- test&lt;i&gt;2&lt;/i&gt;
1169
- </pre>
1170
- </div>
1171
- EOS
1172
- assert_equal expected, actual
1173
- end
1174
-
1175
- def test_list_rouge_lang
1176
- begin
1177
- require 'rouge'
1178
- rescue LoadError
1179
- $stderr.puts 'skip test_list_rouge_lang (cannot find Rouge)'
1180
- return true
1181
- end
1182
- def @chapter.list(_id)
1183
- Book::Index::Item.new('samplelist', 1)
1184
- end
1185
- @book.config['highlight'] = {}
1186
- @book.config['highlight']['html'] = 'rouge'
1187
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1188
-
1189
- expected = <<-EOS
1190
- <div id="samplelist" class="caption-code">
1191
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1192
- <pre class="list language-ruby highlight"><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="ss">:test</span><span class="p">)</span>
1193
- <span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">3</span><span class="p">).</span><span class="nf">times</span><span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">a</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="ss">:foo</span><span class="p">)}</span>
1194
- <span class="k">return</span> <span class="kp">true</span>
1195
- <span class="k">end</span>
1196
-
1197
- </pre>
1198
- </div>
1199
- EOS
1200
- assert_equal expected, actual
1201
- end
1202
-
1203
- def test_list_rouge_nulllang
1204
- begin
1205
- require 'rouge'
1206
- rescue LoadError
1207
- $stderr.puts 'skip test_list_rouge_nulllang (cannot find Rouge)'
1208
- return true
1209
- end
1210
- def @chapter.list(_id)
1211
- Book::Index::Item.new('samplelist', 1)
1212
- end
1213
- @book.config['highlight'] = {}
1214
- @book.config['highlight']['html'] = 'rouge'
1215
- actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1216
-
1217
- expected = <<-EOS
1218
- <div id="samplelist" class="caption-code">
1219
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1220
- <pre class="list highlight">def foo(a1, a2=:test)
1221
- (1..3).times{|i| a.include?(:foo)}
1222
- return true
1223
- end
1224
-
1225
- </pre>
1226
- </div>
1227
- EOS
1228
- assert_equal expected, actual
1229
- end
1230
-
1231
- def test_listnum
1232
- def @chapter.list(_id)
1233
- Book::Index::Item.new('samplelist', 1)
1234
- end
1235
-
1236
- @book.config['highlight'] = false
1237
- actual = compile_block(<<-EOS)
1238
- //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
1239
- def foo(a1, a2=:test)
1240
- (1..3).times{|i| a.include?(:foo)}
1241
- return true
1242
- end
1243
- //}
1244
- EOS
1245
-
1246
- expected = <<-EOS
1247
- <div id="samplelist" class="code">
1248
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1249
- <pre class="list language-ruby"> 1: def foo(a1, a2=:test)
1250
- 2: (1..3).times{|i| a.include?(:foo)}
1251
- 3: return true
1252
- 4: end
1253
- </pre>
1254
- </div>
1255
- EOS
1256
-
1257
- assert_equal expected, actual
1258
-
1259
- @config['caption_position']['list'] = 'bottom'
1260
- actual = compile_block(<<-EOS)
1261
- //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
1262
- def foo(a1, a2=:test)
1263
- (1..3).times{|i| a.include?(:foo)}
1264
- return true
1265
- end
1266
- //}
1267
- EOS
1268
-
1269
- expected = <<-EOS
1270
- <div id="samplelist" class="code">
1271
- <pre class="list language-ruby"> 1: def foo(a1, a2=:test)
1272
- 2: (1..3).times{|i| a.include?(:foo)}
1273
- 3: return true
1274
- 4: end
1275
- </pre>
1276
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1277
- </div>
1278
- EOS
1279
-
1280
- assert_equal expected, actual
1281
- end
1282
-
1283
- def test_listnum_linenum
1284
- def @chapter.list(_id)
1285
- Book::Index::Item.new('samplelist', 1)
1286
- end
1287
-
1288
- @book.config['highlight'] = false
1289
- actual = compile_block(<<-EOS)
1290
- //firstlinenum[100]
1291
- //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
1292
- def foo(a1, a2=:test)
1293
- (1..3).times{|i| a.include?(:foo)}
1294
- return true
1295
- end
1296
- //}
1297
- EOS
1298
-
1299
- expected = <<-EOS
1300
- <div id="samplelist" class="code">
1301
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1302
- <pre class="list language-ruby">100: def foo(a1, a2=:test)
1303
- 101: (1..3).times{|i| a.include?(:foo)}
1304
- 102: return true
1305
- 103: end
1306
- </pre>
1307
- </div>
1308
- EOS
1309
-
1310
- assert_equal expected, actual
1311
- end
1312
-
1313
- def test_listnum_pygments_lang
1314
- return true if @skip_pygments
1315
-
1316
- def @chapter.list(_id)
1317
- Book::Index::Item.new('samplelist', 1)
1318
- end
1319
- begin
1320
- require 'pygments'
1321
- rescue LoadError
1322
- $stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)'
1323
- return true
1324
- end
1325
- @book.config['highlight'] = {}
1326
- @book.config['highlight']['html'] = 'pygments'
1327
- actual = compile_block("//listnum[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1328
-
1329
- expected = <<-EOS
1330
- <div id="samplelist" class="code">
1331
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1332
- <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="background-color: #f0f0f0; padding: 0 5px 0 5px">1 </span><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">foo</span>(a1, a2<span style="color: #666666">=</span><span style="color: #19177C">:test</span>)
1333
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">2 </span> (<span style="color: #666666">1..3</span>)<span style="color: #666666">.</span>times{<span style="color: #666666">|</span>i<span style="color: #666666">|</span> a<span style="color: #666666">.</span>include?(<span style="color: #19177C">:foo</span>)}
1334
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">3 </span> <span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">true</span>
1335
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">4 </span><span style="color: #008000; font-weight: bold">end</span>
1336
- </pre></div>
1337
- </div>
1338
- EOS
1339
- assert_equal expected, actual
1340
- end
1341
-
1342
- def test_listnum_pygments_lang_linenum
1343
- return true if @skip_pygments
1344
-
1345
- def @chapter.list(_id)
1346
- Book::Index::Item.new('samplelist', 1)
1347
- end
1348
- begin
1349
- require 'pygments'
1350
- rescue LoadError
1351
- $stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)'
1352
- return true
1353
- end
1354
- @book.config['highlight'] = {}
1355
- @book.config['highlight']['html'] = 'pygments'
1356
- actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1357
-
1358
- expected = <<-EOS
1359
- <div id="samplelist" class="code">
1360
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1361
- <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="background-color: #f0f0f0; padding: 0 5px 0 5px">100 </span><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">foo</span>(a1, a2<span style="color: #666666">=</span><span style="color: #19177C">:test</span>)
1362
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">101 </span> (<span style="color: #666666">1..3</span>)<span style="color: #666666">.</span>times{<span style="color: #666666">|</span>i<span style="color: #666666">|</span> a<span style="color: #666666">.</span>include?(<span style="color: #19177C">:foo</span>)}
1363
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">102 </span> <span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">true</span>
1364
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">103 </span><span style="color: #008000; font-weight: bold">end</span>
1365
- </pre></div>
1366
- </div>
1367
- EOS
1368
-
1369
- assert_equal expected, actual
1370
- end
1371
-
1372
- def test_listnum_pygments_lang_without_lang
1373
- return true if @skip_pygments
1374
-
1375
- def @chapter.list(_id)
1376
- Book::Index::Item.new('samplelist', 1)
1377
- end
1378
- begin
1379
- require 'pygments'
1380
- rescue LoadError
1381
- $stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)'
1382
- return true
1383
- end
1384
- @book.config['highlight'] = {}
1385
- @book.config['highlight']['html'] = 'pygments'
1386
- @book.config['highlight']['lang'] = 'ruby'
1387
- actual = compile_block("//listnum[samplelist][this is @<b>{test}<&>_]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1388
-
1389
- expected = <<-EOS
1390
- <div id="samplelist" class="code">
1391
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1392
- <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="background-color: #f0f0f0; padding: 0 5px 0 5px">1 </span><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">foo</span>(a1, a2<span style="color: #666666">=</span><span style="color: #19177C">:test</span>)
1393
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">2 </span> (<span style="color: #666666">1..3</span>)<span style="color: #666666">.</span>times{<span style="color: #666666">|</span>i<span style="color: #666666">|</span> a<span style="color: #666666">.</span>include?(<span style="color: #19177C">:foo</span>)}
1394
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">3 </span> <span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">true</span>
1395
- <span style="background-color: #f0f0f0; padding: 0 5px 0 5px">4 </span><span style="color: #008000; font-weight: bold">end</span>
1396
- </pre></div>
1397
- </div>
1398
- EOS
1399
- assert_equal expected, actual
1400
- end
1401
-
1402
- def test_listnum_rouge_lang
1403
- begin
1404
- require 'rouge'
1405
- rescue LoadError
1406
- $stderr.puts 'skip test_listnum_rouge_lang (cannot find Rouge)'
1407
- return true
1408
- end
1409
- def @chapter.list(_id)
1410
- Book::Index::Item.new('samplelist', 1)
1411
- end
1412
- @book.config['highlight'] = {}
1413
- @book.config['highlight']['html'] = 'rouge'
1414
- actual = compile_block("//listnum[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1415
-
1416
- expected = <<-EOS
1417
- <div id="samplelist" class="code">
1418
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1419
- <table class="highlight rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
1420
- 2
1421
- 3
1422
- 4
1423
- 5
1424
- </pre></td><td class="rouge-code"><pre><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="ss">:test</span><span class="p">)</span>
1425
- <span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">3</span><span class="p">).</span><span class="nf">times</span><span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">a</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="ss">:foo</span><span class="p">)}</span>
1426
- <span class="k">return</span> <span class="kp">true</span>
1427
- <span class="k">end</span>
1428
-
1429
- </pre></td></tr></tbody></table>
1430
- </div>
1431
- EOS
1432
-
1433
- assert_equal expected, actual
1434
- end
1435
-
1436
- def test_listnum_rouge_lang_linenum
1437
- begin
1438
- require 'rouge'
1439
- rescue LoadError
1440
- $stderr.puts 'skip test_listnum_rouge_lang_linenum (cannot find Rouge)'
1441
- return true
1442
- end
1443
- def @chapter.list(_id)
1444
- Book::Index::Item.new('samplelist', 1)
1445
- end
1446
- @book.config['highlight'] = {}
1447
- @book.config['highlight']['html'] = 'rouge'
1448
- actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
1449
-
1450
- expected = <<-EOB
1451
- <div id="samplelist" class="code">
1452
- <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1453
- <table class="highlight rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">100
1454
- 101
1455
- 102
1456
- 103
1457
- 104
1458
- </pre></td><td class="rouge-code"><pre><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="ss">:test</span><span class="p">)</span>
1459
- <span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">3</span><span class="p">).</span><span class="nf">times</span><span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">a</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="ss">:foo</span><span class="p">)}</span>
1460
- <span class="k">return</span> <span class="kp">true</span>
1461
- <span class="k">end</span>
1462
-
1463
- </pre></td></tr></tbody></table>
1464
- </div>
1465
- EOB
1466
-
1467
- assert_equal expected, actual
1468
- end
1469
-
1470
- def test_source
1471
- actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
1472
- expected = <<-EOS
1473
- <div class="source-code">
1474
- <p class="caption">foo/bar/test.rb</p>
1475
- <pre class="source">foo
1476
- bar
1477
-
1478
- buz
1479
- </pre>
1480
- </div>
1481
- EOS
1482
- assert_equal expected, actual
1483
-
1484
- @config['caption_position']['list'] = 'bottom'
1485
- actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
1486
- expected = <<-EOS
1487
- <div class="source-code">
1488
- <pre class="source">foo
1489
- bar
1490
-
1491
- buz
1492
- </pre>
1493
- <p class="caption">foo/bar/test.rb</p>
1494
- </div>
1495
- EOS
1496
- assert_equal expected, actual
1497
- end
1498
-
1499
- def test_source_empty_caption
1500
- actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n")
1501
- expected = <<-EOS
1502
- <div class="source-code">
1503
- <pre class="source">foo
1504
- bar
1505
-
1506
- buz
1507
- </pre>
1508
- </div>
1509
- EOS
1510
- assert_equal expected, actual
1511
- end
1512
-
1513
- def test_box
1514
- actual = compile_block("//box{\nfoo\nbar\n//}\n")
1515
- expected = <<-EOS
1516
- <div class="syntax">
1517
- <pre class="syntax">foo
1518
- bar
1519
- </pre>
1520
- </div>
1521
- EOS
1522
- assert_equal expected, actual
1523
-
1524
- actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
1525
- expected = <<-EOS
1526
- <div class="syntax">
1527
- <p class="caption">FOO</p>
1528
- <pre class="syntax">foo
1529
- bar
1530
- </pre>
1531
- </div>
1532
- EOS
1533
- assert_equal expected, actual
1534
-
1535
- @config['caption_position']['list'] = 'bottom'
1536
- actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
1537
- expected = <<-EOS
1538
- <div class="syntax">
1539
- <pre class="syntax">foo
1540
- bar
1541
- </pre>
1542
- <p class="caption">FOO</p>
1543
- </div>
1544
- EOS
1545
- assert_equal expected, actual
1546
- end
1547
-
1548
- def test_emlist
1549
- actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
1550
- expected = <<-EOS
1551
- <div class="emlist-code">
1552
- <pre class="emlist">lineA
1553
- lineB
1554
- </pre>
1555
- </div>
1556
- EOS
1557
- assert_equal expected, actual
1558
- end
1559
-
1560
- def test_emlist_pygments_lang
1561
- return true if @skip_pygments
1562
-
1563
- begin
1564
- require 'pygments'
1565
- rescue LoadError
1566
- $stderr.puts 'skip test_emlist_pygments_lang (cannot find pygments.rb)'
1567
- return true
1568
- end
1569
- @book.config['highlight'] = {}
1570
- @book.config['highlight']['html'] = 'pygments'
1571
- actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
1572
- expected = <<-EOS
1573
- <div class="emlist-code">
1574
- <pre class="emlist language-sql highlight"><span style="color: #008000; font-weight: bold">SELECT</span> <span style="color: #008000; font-weight: bold">COUNT</span>(<span style="color: #666666">*</span>) <span style="color: #008000; font-weight: bold">FROM</span> tests <span style="color: #008000; font-weight: bold">WHERE</span> tests.<span style="color: #008000; font-weight: bold">no</span> <span style="color: #666666">&gt;</span> <span style="color: #666666">10</span> <span style="color: #008000; font-weight: bold">AND</span> test.name <span style="color: #008000; font-weight: bold">LIKE</span> <span style="color: #BA2121">&#39;ABC%&#39;</span>
1575
- </pre>
1576
- </div>
1577
- EOS
1578
- assert_equal expected, actual
1579
- end
1580
-
1581
- def test_emlist_caption
1582
- actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
1583
- expected = <<-EOS
1584
- <div class="emlist-code">
1585
- <p class="caption">cap1</p>
1586
- <pre class="emlist">lineA
1587
- lineB
1588
- </pre>
1589
- </div>
1590
- EOS
1591
- assert_equal expected, actual
1592
-
1593
- @config['caption_position']['list'] = 'bottom'
1594
- actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
1595
- expected = <<-EOS
1596
- <div class="emlist-code">
1597
- <pre class="emlist">lineA
1598
- lineB
1599
- </pre>
1600
- <p class="caption">cap1</p>
1601
- </div>
1602
- EOS
1603
- assert_equal expected, actual
1604
- end
1605
-
1606
- def test_emlist_with_tab
1607
- actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
1608
- expected = <<-EOS
1609
- <div class="emlist-code">
1610
- <pre class="emlist"> lineA
1611
- lineB
1612
- lineC
1613
- </pre>
1614
- </div>
1615
- EOS
1616
- assert_equal expected, actual
1617
- end
1618
-
1619
- def test_emlistnum
1620
- @book.config['highlight'] = false
1621
- actual = compile_block("//emlistnum{\nlineA\nlineB\n//}\n")
1622
- expected = <<-EOS
1623
- <div class="emlistnum-code">
1624
- <pre class="emlist"> 1: lineA
1625
- 2: lineB
1626
- </pre>
1627
- </div>
1628
- EOS
1629
- assert_equal expected, actual
1630
- end
1631
-
1632
- def test_emlistnum_lang
1633
- @book.config['highlight'] = false
1634
- actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
1635
- expected = <<-EOS
1636
- <div class="emlistnum-code">
1637
- <p class="caption">cap</p>
1638
- <pre class="emlist language-text"> 1: lineA
1639
- 2: lineB
1640
- </pre>
1641
- </div>
1642
- EOS
1643
- assert_equal expected, actual
1644
-
1645
- @config['caption_position']['list'] = 'bottom'
1646
- actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
1647
- expected = <<-EOS
1648
- <div class="emlistnum-code">
1649
- <pre class="emlist language-text"> 1: lineA
1650
- 2: lineB
1651
- </pre>
1652
- <p class="caption">cap</p>
1653
- </div>
1654
- EOS
1655
- assert_equal expected, actual
1656
- end
1657
-
1658
- def test_emlistnum_lang_linenum
1659
- @book.config['highlight'] = false
1660
- actual = compile_block("//firstlinenum[1000]\n//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
1661
- expected = <<-EOS
1662
- <div class="emlistnum-code">
1663
- <p class="caption">cap</p>
1664
- <pre class="emlist language-text">1000: lineA
1665
- 1001: lineB
1666
- </pre>
1667
- </div>
1668
- EOS
1669
- assert_equal expected, actual
1670
- end
1671
-
1672
- def test_emlist_with_4tab
1673
- @config['tabwidth'] = 4
1674
- actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
1675
- expected = <<-EOS
1676
- <div class="emlist-code">
1677
- <pre class="emlist"> lineA
1678
- lineB
1679
- lineC
1680
- </pre>
1681
- </div>
1682
- EOS
1683
- assert_equal expected, actual
1684
- end
1685
-
1686
- def test_cmd
1687
- actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
1688
- expected = <<-EOS
1689
- <div class="cmd-code">
1690
- <pre class="cmd">lineA
1691
- lineB
1692
- </pre>
1693
- </div>
1694
- EOS
1695
- assert_equal expected, actual
1696
- end
1697
-
1698
- def test_cmd_pygments
1699
- return true if @skip_pygments
1700
-
1701
- begin
1702
- require 'pygments'
1703
- rescue LoadError
1704
- return true
1705
- end
1706
- @book.config['highlight'] = {}
1707
- @book.config['highlight']['html'] = 'pygments'
1708
- actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
1709
- expected = <<-EOS
1710
- <div class="cmd-code">
1711
- <pre class="cmd"><span style="color: #888888">lineA</span>
1712
- <span style="color: #888888">lineB</span>
1713
- </pre>
1714
- </div>
1715
- EOS
1716
- assert_equal expected, actual
1717
- end
1718
-
1719
- def test_cmd_caption
1720
- actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
1721
- expected = <<-EOS
1722
- <div class="cmd-code">
1723
- <p class="caption">cap1</p>
1724
- <pre class="cmd">lineA
1725
- lineB
1726
- </pre>
1727
- </div>
1728
- EOS
1729
- assert_equal expected, actual
1730
-
1731
- @config['caption_position']['list'] = 'bottom'
1732
- actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
1733
- expected = <<-EOS
1734
- <div class="cmd-code">
1735
- <pre class="cmd">lineA
1736
- lineB
1737
- </pre>
1738
- <p class="caption">cap1</p>
1739
- </div>
1740
- EOS
1741
- assert_equal expected, actual
1742
- end
1743
-
1744
- def test_texequation
1745
- return true if /mswin|mingw|cygwin/.match?(RUBY_PLATFORM)
1746
- return true unless system('latex -version 1>/dev/null 2>/dev/null')
1747
-
1748
- mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
1749
- 'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P} q\n//}\n") do |dir, book, _files|
1750
- @book = book
1751
- @book.config = @config
1752
- @config['math_format'] = 'imgmath'
1753
- @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
1754
- location = Location.new(nil, nil)
1755
- img_math = ReVIEW::ImgMath.new(@config)
1756
- @builder = HTMLBuilder.new(img_math: img_math)
1757
- @builder.bind(@compiler, @chapter, location)
1758
- FileUtils.mkdir_p(File.join(dir, 'images'))
1759
- expected = <<-EOB
1760
- <div class=\"equation\">
1761
- <img src=\"images/_review_math/_gen_XXX.png\" class=\"math_gen_84291054a12d278ea05694c20fbbc8e974ec66fc13be801c01dca764faeecccb\" alt="p \\land \\bm{P} q" />
1762
- </div>
1763
- EOB
1764
- tmpio = $stderr
1765
- $stderr = StringIO.new
1766
- begin
1767
- result = compile_block("//texequation{\np \\land \\bm{P} q\n//}\n")
1768
- ensure
1769
- $stderr = tmpio
1770
- end
1771
- actual = result.gsub(/_gen_[0-9a-f]+\.png/, '_gen_XXX.png')
1772
- assert_equal expected, actual
1773
- end
1774
- end
1775
-
1776
- def test_texequation_fail
1777
- # Re:VIEW 3 never fail on defer mode. This test is only for Re:VIEW 2.
1778
- return true if /mswin|mingw|cygwin/.match?(RUBY_PLATFORM)
1779
- return true unless system('latex -version 1>/dev/null 2>/dev/null')
1780
-
1781
- mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
1782
- 'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P}} q\n//}\n") do |dir, book, _files|
1783
- @book = book
1784
- @book.config = @config
1785
- @config['review_version'] = 2
1786
- @config['math_format'] = 'imgmath'
1787
- @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
1788
- location = Location.new(nil, nil)
1789
- img_math = ReVIEW::ImgMath.new(@config)
1790
- @builder = HTMLBuilder.new(img_math: img_math)
1791
- @builder.bind(@compiler, @chapter, location)
1792
- FileUtils.mkdir_p(File.join(dir, 'images'))
1793
- tmpio = $stderr
1794
- $stderr = StringIO.new
1795
- begin
1796
- assert_raise(ReVIEW::ApplicationError) do
1797
- _result = compile_block("//texequation{\np \\land \\bm{P}} q\n//}\n")
1798
- end
1799
- ensure
1800
- $stderr = tmpio
1801
- end
1802
- end
1803
- end
1804
-
1805
- def test_bib
1806
- def @chapter.bibpaper(_id)
1807
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1808
- end
1809
-
1810
- assert_equal %Q(<a href="bib.html#bib-samplebib">[1]</a>), compile_inline('@<bib>{samplebib}')
1811
- end
1812
-
1813
- def test_bib_noramlized
1814
- def @chapter.bibpaper(_id)
1815
- Book::Index::Item.new('sampleb=ib', 1, 'sample bib')
1816
- end
1817
-
1818
- assert_equal %Q(<a href="bib.html#bib-id_sample_3Dbib">[1]</a>), compile_inline('@<bib>{sample=bib}')
1819
- end
1820
-
1821
- def test_bib_htmlext
1822
- def @chapter.bibpaper(_id)
1823
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1824
- end
1825
-
1826
- @config['htmlext'] = 'xhtml'
1827
- assert_equal %Q(<a href="bib.xhtml#bib-samplebib">[1]</a>), compile_inline('@<bib>{samplebib}')
1828
- end
1829
-
1830
- def test_bibpaper
1831
- def @chapter.bibpaper(_id)
1832
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1833
- end
1834
-
1835
- actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1836
- expected = <<-EOS
1837
- <div class="bibpaper">
1838
- <a id="bib-samplebib">[1]</a> sample bib <b>bold</b>
1839
- <p>ab</p></div>
1840
- EOS
1841
- assert_equal expected, actual
1842
-
1843
- @book.config['join_lines_by_lang'] = true
1844
- actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1845
- expected = <<-EOS
1846
- <div class="bibpaper">
1847
- <a id="bib-samplebib">[1]</a> sample bib <b>bold</b>
1848
- <p>a b</p></div>
1849
- EOS
1850
- assert_equal expected, actual
1851
- end
1852
-
1853
- def test_bibpaper_normalized
1854
- def @chapter.bibpaper(_id)
1855
- Book::Index::Item.new('sample=bib', 1, 'sample bib')
1856
- end
1857
-
1858
- actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1859
- expected = <<-EOS
1860
- <div class="bibpaper">
1861
- <a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>
1862
- <p>ab</p></div>
1863
- EOS
1864
- assert_equal expected, actual
1865
-
1866
- @book.config['join_lines_by_lang'] = true
1867
- actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1868
- expected = <<-EOS
1869
- <div class="bibpaper">
1870
- <a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>
1871
- <p>a b</p></div>
1872
- EOS
1873
- assert_equal expected, actual
1874
- end
1875
-
1876
- def test_bibpaper_with_anchor
1877
- def @chapter.bibpaper(_id)
1878
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1879
- end
1880
-
1881
- actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
1882
- expected = <<-EOS
1883
- <div class="bibpaper">
1884
- <a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>
1885
- <p>ab</p></div>
1886
- EOS
1887
- assert_equal expected, actual
1888
-
1889
- @book.config['join_lines_by_lang'] = true
1890
- actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
1891
- expected = <<-EOS
1892
- <div class="bibpaper">
1893
- <a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>
1894
- <p>a b</p></div>
1895
- EOS
1896
- assert_equal expected, actual
1897
- end
1898
-
1899
- def column_helper(review)
1900
- compile_block(review)
1901
- end
1902
-
1903
- def test_column_1
1904
- review = <<-EOS
1905
- ===[column] prev column
1906
-
1907
- inside prev column
1908
-
1909
- ===[column] test
1910
-
1911
- inside column
1912
-
1913
- ===[/column]
1914
- EOS
1915
- expected = <<-EOS
1916
- <div class="column">
1917
-
1918
- <h3><a id="column-1"></a>prev column</h3>
1919
- <p>inside prev column</p>
1920
- </div>
1921
- <div class="column">
1922
-
1923
- <h3><a id="column-2"></a>test</h3>
1924
- <p>inside column</p>
1925
- </div>
1926
- EOS
1927
- assert_equal expected, column_helper(review)
1928
- end
1929
-
1930
- def test_column_2
1931
- review = <<-EOS
1932
- ===[column] test
1933
-
1934
- inside column
1935
-
1936
- === next level
1937
- EOS
1938
- expected = <<-EOS
1939
- <div class="column">
1940
-
1941
- <h3><a id="column-1"></a>test</h3>
1942
- <p>inside column</p>
1943
- </div>
1944
-
1945
- <h3><a id="h1-0-1"></a>next level</h3>
1946
- EOS
1947
-
1948
- assert_equal expected, column_helper(review)
1949
- end
1950
-
1951
- def test_column_3
1952
- review = <<-EOS
1953
- ===[column] test
1954
-
1955
- inside column
1956
-
1957
- ===[/column_dummy]
1958
- EOS
1959
- assert_raise(ReVIEW::ApplicationError) do
1960
- column_helper(review)
1961
- end
1962
- end
1963
-
1964
- def test_column_ref
1965
- review = <<-EOS
1966
- ===[column]{foo} test
1967
-
1968
- inside column
1969
-
1970
- === next level
1971
-
1972
- this is @<column>{foo}.
1973
- EOS
1974
- expected = <<-EOS
1975
- <div class="column">
1976
-
1977
- <h3 id="foo"><a id="column-1"></a>test</h3>
1978
- <p>inside column</p>
1979
- </div>
1980
-
1981
- <h3><a id="h1-0-1"></a>next level</h3>
1982
- <p>this is <a href="-.html#column-1" class="columnref">コラム「test」</a>.</p>
1983
- EOS
1984
-
1985
- assert_equal expected, column_helper(review)
1986
-
1987
- @config['chapterlink'] = nil
1988
- expected = <<-EOS
1989
- <div class="column">
1990
-
1991
- <h3 id="foo"><a id="column-1"></a>test</h3>
1992
- <p>inside column</p>
1993
- </div>
1994
-
1995
- <h3><a id="h1-0-1"></a>next level</h3>
1996
- <p>this is コラム「test」.</p>
1997
- EOS
1998
-
1999
- assert_equal expected, column_helper(review)
2000
- end
2001
-
2002
- def test_column_in_aother_chapter_ref
2003
- def @chapter.column_index
2004
- item = Book::Index::Item.new('chap1|column', 1, 'column_cap')
2005
- idx = Book::ColumnIndex.new
2006
- idx.add_item(item)
2007
- idx
2008
- end
2009
-
2010
- actual = compile_inline('test @<column>{chap1|column} test2')
2011
- expected = 'test <a href="-.html#column-1" class="columnref">コラム「column_cap」</a> test2'
2012
- assert_equal expected, actual
2013
-
2014
- @config['chapterlink'] = nil
2015
- actual = compile_inline('test @<column>{chap1|column} test2')
2016
- expected = 'test コラム「column_cap」 test2'
2017
- assert_equal expected, actual
2018
- end
2019
-
2020
- def test_ul
2021
- src = <<-EOS
2022
- * AAA
2023
- * BBB
2024
- EOS
2025
- expected = <<-EOS
2026
- <ul>
2027
- <li>AAA</li>
2028
- <li>BBB</li>
2029
- </ul>
2030
- EOS
2031
- actual = compile_block(src)
2032
- assert_equal expected, actual
2033
- end
2034
-
2035
- def test_ul_cont
2036
- src = <<-EOS
2037
- * AAA
2038
- -AA
2039
- * BBB
2040
- -BB
2041
- EOS
2042
- expected = <<-EOS
2043
- <ul>
2044
- <li>AAA-AA</li>
2045
- <li>BBB-BB</li>
2046
- </ul>
2047
- EOS
2048
- actual = compile_block(src)
2049
- assert_equal expected, actual
2050
-
2051
- @book.config['join_lines_by_lang'] = true
2052
- expected = <<-EOS
2053
- <ul>
2054
- <li>AAA -AA</li>
2055
- <li>BBB -BB</li>
2056
- </ul>
2057
- EOS
2058
- actual = compile_block(src)
2059
- assert_equal expected, actual
2060
- end
2061
-
2062
- def test_ul_nest1
2063
- src = <<-EOS
2064
- * AAA
2065
- ** AA
2066
- EOS
2067
-
2068
- expected = <<-EOS
2069
- <ul>
2070
- <li>AAA<ul>
2071
- <li>AA</li>
2072
- </ul>
2073
- </li>
2074
- </ul>
2075
- EOS
2076
- actual = compile_block(src)
2077
- assert_equal expected, actual
2078
- end
2079
-
2080
- def test_ul_nest2
2081
- src = <<-EOS
2082
- * AAA
2083
- ** AA
2084
- * BBB
2085
- ** BB
2086
- EOS
2087
-
2088
- expected = <<-EOS
2089
- <ul>
2090
- <li>AAA<ul>
2091
- <li>AA</li>
2092
- </ul>
2093
- </li>
2094
- <li>BBB<ul>
2095
- <li>BB</li>
2096
- </ul>
2097
- </li>
2098
- </ul>
2099
- EOS
2100
- actual = compile_block(src)
2101
- assert_equal expected, actual
2102
- end
2103
-
2104
- def test_ul_nest3
2105
- src = <<-EOS
2106
- ** AAA
2107
- * AA
2108
- EOS
2109
-
2110
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2111
- assert_match(/too many \*\./, @log_io.string)
2112
- end
2113
-
2114
- def test_ul_nest4
2115
- src = <<-EOS
2116
- * A
2117
- ** AA
2118
- *** AAA
2119
- * B
2120
- ** BB
2121
- EOS
2122
-
2123
- expected = <<-EOS
2124
- <ul>
2125
- <li>A<ul>
2126
- <li>AA<ul>
2127
- <li>AAA</li>
2128
- </ul>
2129
- </li>
2130
- </ul>
2131
- </li>
2132
- <li>B<ul>
2133
- <li>BB</li>
2134
- </ul>
2135
- </li>
2136
- </ul>
2137
- EOS
2138
- actual = compile_block(src)
2139
- assert_equal expected, actual
2140
- end
2141
-
2142
- def test_ol
2143
- src = <<-EOS
2144
- 3. AAA
2145
- 3. BBB
2146
- EOS
2147
-
2148
- expected = <<-EOS
2149
- <ol>
2150
- <li>AAA</li>
2151
- <li>BBB</li>
2152
- </ol>
2153
- EOS
2154
- actual = compile_block(src)
2155
- assert_equal expected, actual
2156
- end
2157
-
2158
- def test_inline_raw0
2159
- assert_equal 'normal', compile_inline('@<raw>{normal}')
2160
- end
2161
-
2162
- def test_inline_raw1
2163
- assert_equal 'body', compile_inline('@<raw>{|html|body}')
2164
- end
2165
-
2166
- def test_inline_raw2
2167
- assert_equal 'body', compile_inline('@<raw>{|html, latex|body}')
2168
- end
2169
-
2170
- def test_inline_raw3
2171
- assert_equal '', compile_inline('@<raw>{|idgxml, latex|body}')
2172
- end
2173
-
2174
- def test_inline_raw4
2175
- assert_equal '|html body', compile_inline('@<raw>{|html body}')
2176
- end
2177
-
2178
- def test_inline_raw5
2179
- assert_equal "nor\nmal", compile_inline('@<raw>{|html|nor\\nmal}')
2180
- end
2181
-
2182
- def test_inline_embed0
2183
- assert_equal 'normal', compile_inline('@<embed>{normal}')
2184
- end
2185
-
2186
- def test_inline_embed1
2187
- assert_equal 'body', compile_inline('@<embed>{|html|body}')
2188
- end
2189
-
2190
- def test_inline_embed3
2191
- assert_equal '', compile_inline('@<embed>{|idgxml, latex|body}')
2192
- end
2193
-
2194
- def test_inline_embed5
2195
- assert_equal 'nor\\nmal', compile_inline('@<embed>{|html|nor\\nmal}')
2196
- end
2197
-
2198
- def test_inline_embed_math1
2199
- assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@<embed>{\[ \frac{\partial f\}{\partial x\} =x^2+xy \]}')
2200
- end
2201
-
2202
- def test_inline_embed_math1a
2203
- assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@<embed>{\\[ \\frac{\\partial f\}{\\partial x\} =x^2+xy \\]}')
2204
- end
2205
-
2206
- def test_inline_embed_math1b
2207
- assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@<embed>{\\\\[ \\\\frac{\\\\partial f\}{\\\\partial x\} =x^2+xy \\\\]}')
2208
- end
2209
-
2210
- def test_inline_embed_math1c
2211
- assert_equal '\\[ \\frac{}{} \\]',
2212
- compile_inline('@<embed>{\[ \\frac{\}{\} \\]}')
2213
- end
2214
-
2215
- def test_inline_embed_n1
2216
- assert_equal '\\n', compile_inline('@<embed>{\\n}')
2217
- end
2218
-
2219
- def test_inline_embed_n2
2220
- assert_equal '\\n', compile_inline('@<embed>{\\\\n}')
2221
- end
2222
-
2223
- def test_inline_embed_brace_right0
2224
- assert_equal '}', compile_inline('@<embed>{\\}}')
2225
- end
2226
-
2227
- def test_inline_embed_brace_right1
2228
- assert_equal '\\}', compile_inline('@<embed>{\\\\}}')
2229
- end
2230
-
2231
- def test_inline_embed_brace_right2
2232
- assert_equal '\\}', compile_inline('@<embed>{\\\\\\}}')
2233
- end
2234
-
2235
- def test_inline_embed_brace_right3
2236
- assert_equal '\\\\}', compile_inline('@<embed>{\\\\\\\\}}')
2237
- end
2238
-
2239
- def test_block_raw0
2240
- actual = compile_block(%Q(//raw[<>!"\\n& ]\n))
2241
- expected = %Q(<>!"\n& )
2242
- assert_equal expected, actual
2243
- end
2244
-
2245
- def test_block_raw1
2246
- actual = compile_block(%Q(//raw[|html|<>!"\\n& ]\n))
2247
- expected = %Q(<>!"\n& )
2248
- assert_equal expected, actual
2249
- end
2250
-
2251
- def test_block_raw2
2252
- actual = compile_block(%Q(//raw[|html, latex|<>!"\\n& ]\n))
2253
- expected = %Q(<>!"\n& )
2254
- assert_equal expected, actual
2255
- end
2256
-
2257
- def test_block_raw3
2258
- actual = compile_block(%Q(//raw[|latex, idgxml|<>!"\\n& ]\n))
2259
- expected = ''
2260
- assert_equal expected, actual
2261
- end
2262
-
2263
- def test_block_raw4
2264
- actual = compile_block(%Q(//raw[|html <>!"\\n& ]\n))
2265
- expected = %Q(|html <>!"\n& )
2266
- assert_equal expected, actual
2267
- end
2268
-
2269
- def test_embed0
2270
- lines = '//embed{' + "\n" +
2271
- %Q( <>!"\\\\n& ) + "\n" +
2272
- '//}' + "\n"
2273
- actual = compile_block(lines)
2274
- expected = %Q( <>!"\\\\n& ) + "\n"
2275
- assert_equal expected, actual
2276
- end
2277
-
2278
- def test_embed1
2279
- actual = compile_block("//embed[|html|]{\n" +
2280
- %Q(<>!"\\\\n& \n) +
2281
- "//}\n")
2282
- expected = %Q(<>!"\\\\n& \n)
2283
- assert_equal expected, actual
2284
- end
2285
-
2286
- def test_embed2
2287
- actual = compile_block("//embed[html, latex]{\n" +
2288
- %Q(<>!"\\\\n& \n) +
2289
- "//}\n")
2290
- expected = %Q(<>!"\\\\n& \n)
2291
- assert_equal expected, actual
2292
- end
2293
-
2294
- def test_embed2a
2295
- actual = compile_block("//embed[|html, latex|]{\n" +
2296
- %Q(<>!"\\\\n& \n) +
2297
- "//}\n")
2298
- expected = %Q(<>!"\\\\n& \n)
2299
- assert_equal expected, actual
2300
- end
2301
-
2302
- def test_embed2b
2303
- actual = compile_block("//embed[html, latex]{\n" +
2304
- '#@# comments are not ignored in //embed block' + "\n" +
2305
- %Q(<>!"\\\\n& \n) +
2306
- "//}\n")
2307
- expected = '#@# comments are not ignored in //embed block' + "\n" + %Q(<>!"\\\\n& \n)
2308
- assert_equal expected, actual
2309
- end
2310
-
2311
- def test_footnote
2312
- actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
2313
- expected = <<-'EOS'
2314
- <div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote">[*1] bar\a\$buz</p></div>
2315
- EOS
2316
- assert_equal expected, actual
2317
-
2318
- @book.config['epubmaker'] ||= {}
2319
- @book.config['epubmaker']['back_footnote'] = true
2320
- actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
2321
- expected = <<-'EOS'
2322
- <div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote"><a href="#fnb-foo">⏎</a>[*1] bar\a\$buz</p></div>
2323
- EOS
2324
- assert_equal expected, actual
2325
-
2326
- I18n.set('html_footnote_textmark', '+%s:')
2327
- I18n.set('html_footnote_backmark', '←')
2328
- actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
2329
- expected = <<-'EOS'
2330
- <div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote"><a href="#fnb-foo">←</a>+1:bar\a\$buz</p></div>
2331
- EOS
2332
- assert_equal expected, actual
2333
- end
2334
-
2335
- def test_footnote_with_tricky_id
2336
- actual = compile_block("//footnote[123あ_;][bar\\a\\$buz]\n")
2337
- expected = <<-'EOS'
2338
- <div class="footnote" epub:type="footnote" id="fn-id_123_E3_81_82___3B"><p class="footnote">[*1] bar\a\$buz</p></div>
2339
- EOS
2340
- assert_equal expected, actual
2341
- end
2342
-
2343
- def test_inline_fn
2344
- fn = compile_block("//footnote[foo][bar]\n\n@<fn>{foo}\n")
2345
- expected = <<-EOS
2346
- <div class=\"footnote\" epub:type=\"footnote\" id=\"fn-foo\"><p class=\"footnote\">[*1] bar</p></div>
2347
- <p><a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">*1</a></p>
2348
- EOS
2349
- assert_equal expected, fn
2350
- I18n.set('html_footnote_refmark', '+%s')
2351
- fn = compile_block("//footnote[foo][bar]\n\n@<fn>{foo}\n")
2352
- expected = <<-EOS
2353
- <div class=\"footnote\" epub:type=\"footnote\" id=\"fn-foo\"><p class=\"footnote\">[*1] bar</p></div>
2354
- <p><a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">+1</a></p>
2355
- EOS
2356
- assert_equal expected, fn
2357
- end
2358
-
2359
- def test_endnote
2360
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@<endnote>{foo}\n") }
2361
- assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message
2362
-
2363
- actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
2364
- expected = <<-'EOS'
2365
- <p><a id="endnoteb-foo" href="#endnote-foo" class="noteref" epub:type="noteref">(1)</a></p>
2366
- <div class="endnotes">
2367
- <div class="endnote" id="endnote-foo"><p class="endnote">(1) bar</p></div>
2368
- </div>
2369
- EOS
2370
- assert_equal expected, actual
2371
-
2372
- @book.config['epubmaker'] ||= {}
2373
- @book.config['epubmaker']['back_footnote'] = true
2374
- actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
2375
- expected = <<-'EOS'
2376
- <p><a id="endnoteb-foo" href="#endnote-foo" class="noteref" epub:type="noteref">(1)</a></p>
2377
- <div class="endnotes">
2378
- <div class="endnote" id="endnote-foo"><p class="endnote"><a href="#endnoteb-foo">⏎</a>(1) bar</p></div>
2379
- </div>
2380
- EOS
2381
- assert_equal expected, actual
2382
-
2383
- I18n.set('html_endnote_textmark', '+%s:')
2384
- I18n.set('html_endnote_refmark', '+%s:')
2385
- I18n.set('html_footnote_backmark', '←')
2386
- actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
2387
- expected = <<-'EOS'
2388
- <p><a id="endnoteb-foo" href="#endnote-foo" class="noteref" epub:type="noteref">+1:</a></p>
2389
- <div class="endnotes">
2390
- <div class="endnote" id="endnote-foo"><p class="endnote"><a href="#endnoteb-foo">←</a>+1:bar</p></div>
2391
- </div>
2392
- EOS
2393
- assert_equal expected, actual
2394
- end
2395
-
2396
- def test_inline_hd
2397
- book = ReVIEW::Book::Base.new
2398
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
2399
- io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
2400
- io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
2401
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
2402
- chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
2403
- book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
2404
- builder = ReVIEW::HTMLBuilder.new
2405
- comp = ReVIEW::Compiler.new(builder)
2406
- builder.bind(comp, chap2, nil)
2407
-
2408
- chap1.generate_indexes
2409
- chap2.generate_indexes
2410
- hd = builder.inline_hd('ch1|test1-1')
2411
- assert_equal '<a href="ch1.html#h1-1">「1.1 test1-1」</a>', hd
2412
-
2413
- builder.instance_eval { @book.config['chapterlink'] = nil }
2414
- hd = builder.inline_hd('ch1|test1-1')
2415
- assert_equal '「1.1 test1-1」', hd
2416
- end
2417
-
2418
- def test_inline_hd_for_part
2419
- book = ReVIEW::Book::Base.new
2420
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
2421
- io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
2422
- io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
2423
- io_p1 = StringIO.new("= part1\n\nfoo\n\n== part1-1\n\nbar\n\n== part1-2\n\nbar\n\n")
2424
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
2425
- chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
2426
- book.parts = [ReVIEW::Book::Part.new(book, 1, [chap1, chap2], 'part1.re', io_p1)]
2427
- builder = ReVIEW::HTMLBuilder.new
2428
- comp = ReVIEW::Compiler.new(builder)
2429
- builder.bind(comp, chap2, nil)
2430
- book.generate_indexes
2431
-
2432
- hd = builder.inline_hd('part1|part1-1')
2433
- assert_equal '<a href="part1.html#h1-1">「1.1 part1-1」</a>', hd
2434
-
2435
- builder.instance_eval { @book.config['chapterlink'] = nil }
2436
- hd = builder.inline_hd('part1|part1-1')
2437
- assert_equal '「1.1 part1-1」', hd
2438
- end
2439
-
2440
- def test_inline_hd_with_block
2441
- io1 = StringIO.new("= test1\n=={foo} foo\n//emlist{\n======\nbar\n======\n}\n//}\n=={bar} bar")
2442
- chap1 = Book::Chapter.new(@book, 1, '-', nil, io1)
2443
- location = Location.new(nil, nil)
2444
- @builder.bind(@compiler, chap1, location)
2445
- hd = @builder.inline_hd('foo')
2446
- assert_equal '<a href="-.html#h1-1">「1.1 foo」</a>', hd
2447
-
2448
- @config['chapterlink'] = nil
2449
- hd = @builder.inline_hd('foo')
2450
- assert_equal '「1.1 foo」', hd
2451
-
2452
- hd = @builder.inline_hd('bar')
2453
- assert_equal '「1.2 bar」', hd
2454
- end
2455
-
2456
- def test_table
2457
- actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2458
- expected = <<-EOS
2459
- <div class="table">
2460
- <table>
2461
- <tr><th>aaa</th><th>bbb</th></tr>
2462
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2463
- </table>
2464
- </div>
2465
- EOS
2466
- assert_equal expected, actual
2467
-
2468
- actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2469
- expected = <<-EOS
2470
- <div id="foo" class="table">
2471
- <p class="caption">表1.1: FOO</p>
2472
- <table>
2473
- <tr><th>aaa</th><th>bbb</th></tr>
2474
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2475
- </table>
2476
- </div>
2477
- EOS
2478
- assert_equal expected, actual
2479
-
2480
- @config['caption_position']['table'] = 'bottom'
2481
- actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2482
- expected = <<-EOS
2483
- <div id="foo" class="table">
2484
- <table>
2485
- <tr><th>aaa</th><th>bbb</th></tr>
2486
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2487
- </table>
2488
- <p class="caption">表1.1: FOO</p>
2489
- </div>
2490
- EOS
2491
- assert_equal expected, actual
2492
- end
2493
-
2494
- def test_empty_table
2495
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
2496
- assert_equal 'no rows in the table', e.message
2497
-
2498
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
2499
- assert_equal 'no rows in the table', e.message
2500
- end
2501
-
2502
- def test_inline_table
2503
- def @chapter.table(_id)
2504
- Book::Index::Item.new('sampletable', 1)
2505
- end
2506
- actual = compile_block("@<table>{sampletest}\n")
2507
- assert_equal %Q(<p><span class="tableref"><a href="./-.html#sampletest">表1.1</a></span></p>\n), actual
2508
-
2509
- @config['chapterlink'] = nil
2510
- actual = compile_block("@<table>{sampletest}\n")
2511
- assert_equal %Q(<p><span class="tableref">表1.1</span></p>\n), actual
2512
- end
2513
-
2514
- def test_emtable
2515
- actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2516
- expected = <<-EOS
2517
- <div class="table">
2518
- <p class="caption">foo</p>
2519
- <table>
2520
- <tr><th>aaa</th><th>bbb</th></tr>
2521
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2522
- </table>
2523
- </div>
2524
- <div class="table">
2525
- <table>
2526
- <tr><th>aaa</th><th>bbb</th></tr>
2527
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2528
- </table>
2529
- </div>
2530
- EOS
2531
- assert_equal expected, actual
2532
-
2533
- @config['caption_position']['table'] = 'bottom'
2534
- actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2535
- expected = <<-EOS
2536
- <div class="table">
2537
- <table>
2538
- <tr><th>aaa</th><th>bbb</th></tr>
2539
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2540
- </table>
2541
- <p class="caption">foo</p>
2542
- </div>
2543
- <div class="table">
2544
- <table>
2545
- <tr><th>aaa</th><th>bbb</th></tr>
2546
- <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2547
- </table>
2548
- </div>
2549
- EOS
2550
- assert_equal expected, actual
2551
- end
2552
-
2553
- def test_imgtable
2554
- def @chapter.image(_id)
2555
- item = Book::Index::Item.new('sampleimg', 1, 'sample img')
2556
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
2557
- item
2558
- end
2559
-
2560
- actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
2561
- expected = <<-EOS
2562
- <div id="sampleimg" class="imgtable image">
2563
- <p class="caption">表1.1: test for imgtable</p>
2564
- <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2565
- </div>
2566
- EOS
2567
- assert_equal expected, actual
2568
-
2569
- @config['caption_position']['table'] = 'bottom'
2570
- actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
2571
- expected = <<-EOS
2572
- <div id="sampleimg" class="imgtable image">
2573
- <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2574
- <p class="caption">表1.1: test for imgtable</p>
2575
- </div>
2576
- EOS
2577
- assert_equal expected, actual
2578
- end
2579
-
2580
- def test_table_row_separator
2581
- src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n"
2582
- expected = <<-EOS
2583
- <div class="table">
2584
- <table>
2585
- <tr><th>1</th><th>2</th><th>3 4| 5</th></tr>
2586
- <tr><td>a b</td><td>c d |e</td><td></td></tr>
2587
- </table>
2588
- </div>
2589
- EOS
2590
- actual = compile_block(src)
2591
- assert_equal expected, actual
2592
-
2593
- @config['table_row_separator'] = 'singletab'
2594
- actual = compile_block(src)
2595
- expected = <<-EOS
2596
- <div class="table">
2597
- <table>
2598
- <tr><th>1</th><th>2</th><th></th><th>3 4| 5</th></tr>
2599
- <tr><td>a b</td><td>c d |e</td><td></td><td></td></tr>
2600
- </table>
2601
- </div>
2602
- EOS
2603
- assert_equal expected, actual
2604
-
2605
- @config['table_row_separator'] = 'spaces'
2606
- actual = compile_block(src)
2607
- expected = <<-EOS
2608
- <div class="table">
2609
- <table>
2610
- <tr><th>1</th><th>2</th><th>3</th><th>4|</th><th>5</th></tr>
2611
- <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>|e</td></tr>
2612
- </table>
2613
- </div>
2614
- EOS
2615
- assert_equal expected, actual
2616
-
2617
- @config['table_row_separator'] = 'verticalbar'
2618
- actual = compile_block(src)
2619
- expected = <<-EOS
2620
- <div class="table">
2621
- <table>
2622
- <tr><th>1 2 3 4</th><th>5</th></tr>
2623
- <tr><td>a b c d</td><td>e</td></tr>
2624
- </table>
2625
- </div>
2626
- EOS
2627
- assert_equal expected, actual
2628
- end
2629
-
2630
- def test_major_blocks
2631
- actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
2632
- expected = <<-EOS
2633
- <div class="note">
2634
- <p>A</p>
2635
- <p>B</p>
2636
- </div>
2637
- <div class="note">
2638
- <p class="caption">caption</p>
2639
- <p>A</p>
2640
- </div>
2641
- EOS
2642
- assert_equal expected, actual
2643
-
2644
- actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
2645
- expected = <<-EOS
2646
- <div class="memo">
2647
- <p>A</p>
2648
- <p>B</p>
2649
- </div>
2650
- <div class="memo">
2651
- <p class="caption">caption</p>
2652
- <p>A</p>
2653
- </div>
2654
- EOS
2655
- assert_equal expected, actual
2656
-
2657
- actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
2658
- expected = <<-EOS
2659
- <div class="info">
2660
- <p>A</p>
2661
- <p>B</p>
2662
- </div>
2663
- <div class="info">
2664
- <p class="caption">caption</p>
2665
- <p>A</p>
2666
- </div>
2667
- EOS
2668
- assert_equal expected, actual
2669
-
2670
- actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
2671
- expected = <<-EOS
2672
- <div class="important">
2673
- <p>A</p>
2674
- <p>B</p>
2675
- </div>
2676
- <div class="important">
2677
- <p class="caption">caption</p>
2678
- <p>A</p>
2679
- </div>
2680
- EOS
2681
- assert_equal expected, actual
2682
-
2683
- actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
2684
- expected = <<-EOS
2685
- <div class="caution">
2686
- <p>A</p>
2687
- <p>B</p>
2688
- </div>
2689
- <div class="caution">
2690
- <p class="caption">caption</p>
2691
- <p>A</p>
2692
- </div>
2693
- EOS
2694
- assert_equal expected, actual
2695
-
2696
- actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
2697
- expected = <<-EOS
2698
- <div class="notice">
2699
- <p>A</p>
2700
- <p>B</p>
2701
- </div>
2702
- <div class="notice">
2703
- <p class="caption">caption</p>
2704
- <p>A</p>
2705
- </div>
2706
- EOS
2707
- assert_equal expected, actual
2708
-
2709
- actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
2710
- expected = <<-EOS
2711
- <div class="warning">
2712
- <p>A</p>
2713
- <p>B</p>
2714
- </div>
2715
- <div class="warning">
2716
- <p class="caption">caption</p>
2717
- <p>A</p>
2718
- </div>
2719
- EOS
2720
- assert_equal expected, actual
2721
-
2722
- actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
2723
- expected = <<-EOS
2724
- <div class="tip">
2725
- <p>A</p>
2726
- <p>B</p>
2727
- </div>
2728
- <div class="tip">
2729
- <p class="caption">caption</p>
2730
- <p>A</p>
2731
- </div>
2732
- EOS
2733
- assert_equal expected, actual
2734
- end
2735
-
2736
- def test_minicolumn_blocks
2737
- %w[note memo tip info warning important caution notice].each do |type|
2738
- src = <<-EOS
2739
- //#{type}[#{type}1]{
2740
-
2741
- //}
2742
-
2743
- //#{type}[#{type}2]{
2744
- //}
2745
- EOS
2746
-
2747
- expected = <<-EOS
2748
- <div class="#{type}">
2749
- <p class="caption">#{type}1</p>
2750
- </div>
2751
- <div class="#{type}">
2752
- <p class="caption">#{type}2</p>
2753
- </div>
2754
- EOS
2755
- assert_equal expected, compile_block(src)
2756
-
2757
- src = <<-EOS
2758
- //#{type}[#{type}2]{
2759
-
2760
- //}
2761
-
2762
- //#{type}[#{type}3]{
2763
-
2764
- //}
2765
-
2766
- //#{type}[#{type}4]{
2767
-
2768
- //}
2769
-
2770
- //#{type}[#{type}5]{
2771
-
2772
- //}
2773
-
2774
- //#{type}[#{type}6]{
2775
-
2776
- //}
2777
- EOS
2778
-
2779
- expected = <<-EOS
2780
- <div class="#{type}">
2781
- <p class="caption">#{type}2</p>
2782
- </div>
2783
- <div class="#{type}">
2784
- <p class="caption">#{type}3</p>
2785
- </div>
2786
- <div class="#{type}">
2787
- <p class="caption">#{type}4</p>
2788
- </div>
2789
- <div class="#{type}">
2790
- <p class="caption">#{type}5</p>
2791
- </div>
2792
- <div class="#{type}">
2793
- <p class="caption">#{type}6</p>
2794
- </div>
2795
- EOS
2796
- assert_equal expected, compile_block(src)
2797
-
2798
- src = <<-EOS
2799
- //#{type}{
2800
-
2801
- * A
2802
-
2803
- 1. B
2804
-
2805
- //}
2806
-
2807
- //#{type}[OMITEND1]{
2808
-
2809
- //emlist{
2810
- LIST
2811
- //}
2812
-
2813
- //}
2814
-
2815
- //#{type}[OMITEND2]{
2816
- //}
2817
- EOS
2818
-
2819
- expected = <<-EOS
2820
- <div class="#{type}">
2821
- <ul>
2822
- <li>A</li>
2823
- </ul>
2824
- <ol>
2825
- <li>B</li>
2826
- </ol>
2827
- </div>
2828
- <div class="#{type}">
2829
- <p class="caption">OMITEND1</p>
2830
- <div class="emlist-code">
2831
- <pre class="emlist">LIST
2832
- </pre>
2833
- </div>
2834
- </div>
2835
- <div class="#{type}">
2836
- <p class="caption">OMITEND2</p>
2837
- </div>
2838
- EOS
2839
- assert_equal expected, compile_block(src)
2840
- end
2841
- end
2842
-
2843
- def test_minicolumn_blocks_nest_error1
2844
- %w[note memo tip info warning important caution notice].each do |type|
2845
- @builder.doc_status.clear
2846
- src = <<-EOS
2847
- //#{type}{
2848
-
2849
- //#{type}{
2850
- //}
2851
-
2852
- //}
2853
- EOS
2854
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2855
- assert_match(/minicolumn cannot be nested:/, @log_io.string)
2856
- end
2857
- end
2858
-
2859
- def test_minicolumn_blocks_nest_error2
2860
- %w[note memo tip info warning important caution notice].each do |type|
2861
- @builder.doc_status.clear
2862
- src = <<-EOS
2863
- //#{type}{
2864
-
2865
- //#{type}{
2866
-
2867
- //}
2868
-
2869
- //}
2870
- EOS
2871
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2872
- assert_match(/minicolumn cannot be nested:/, @log_io.string)
2873
- end
2874
- end
2875
-
2876
- def test_minicolumn_blocks_nest_error3
2877
- %w[memo tip info warning important caution notice].each do |type|
2878
- @builder.doc_status.clear
2879
- src = <<-EOS
2880
- //#{type}{
2881
-
2882
- //note{
2883
-
2884
- //}
2885
-
2886
- //}
2887
- EOS
2888
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2889
- assert_match(/minicolumn cannot be nested:/, @log_io.string)
2890
- end
2891
- end
2892
-
2893
- def test_comment
2894
- actual = compile_block('//comment[コメント]')
2895
- assert_equal '', actual
2896
- end
2897
-
2898
- def test_comment_for_draft
2899
- @config['draft'] = true
2900
- actual = compile_block('//comment[コメント<]')
2901
- assert_equal %Q(<div class="draft-comment">コメント&lt;</div>\n), actual
2902
- actual = compile_block("//comment{\nA<>\nB&\n//}")
2903
- assert_equal %Q(<div class="draft-comment">A&lt;&gt;<br />B&amp;</div>\n), actual
2904
- end
2905
-
2906
- def test_inline_comment
2907
- actual = compile_inline('test @<comment>{コメント} test2')
2908
- assert_equal 'test test2', actual
2909
- end
2910
-
2911
- def test_inline_comment_for_draft
2912
- @config['draft'] = true
2913
- actual = compile_inline('test @<comment>{コメント} test2')
2914
- assert_equal %Q(test <span class="draft-comment">コメント</span> test2), actual
2915
- end
2916
-
2917
- def test_inline_fence
2918
- actual = compile_inline('test @<code>|@<code>{$サンプル$}|')
2919
- assert_equal 'test <code class="inline-code tt">@&lt;code&gt;{$サンプル$}</code>', actual
2920
- end
2921
-
2922
- def test_inline_w
2923
- Dir.mktmpdir do |dir|
2924
- File.write(File.join(dir, 'words.csv'), <<EOB
2925
- "F","foo"
2926
- "B","bar""\\<>_@<b>{BAZ}"
2927
- EOB
2928
- )
2929
- @book.config['words_file'] = File.join(dir, 'words.csv')
2930
- actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
2931
- assert_equal %Q(<p>foo bar&quot;\\&lt;&gt;_@&lt;b&gt;{BAZ} <b>bar&quot;\\&lt;&gt;_@&lt;b&gt;{BAZ}</b> [missing word: N]</p>\n), actual
2932
- assert_match(/WARN --: :1: word not bound: N/, @log_io.string)
2933
- end
2934
- end
2935
-
2936
- def test_inline_unknown
2937
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2938
- assert_match(/unknown image: n/, @log_io.string)
2939
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2940
- assert_match(/unknown footnote: n/, @log_io.string)
2941
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<endnote>{n}\n") }
2942
- assert_match(/unknown endnote: n/, @log_io.string)
2943
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2944
- assert_match(/unknown headline: n/, @log_io.string)
2945
- %w[list table column].each do |name|
2946
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2947
- assert_match(/unknown #{name}: n/, @log_io.string)
2948
- end
2949
- %w[chap chapref title].each do |name|
2950
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2951
- assert_match(/key not found: "n"/, @log_io.string)
2952
- end
2953
- end
2954
-
2955
- def test_texequation_plain
2956
- src = <<-EOS
2957
- //texequation{
2958
- e=mc^2
2959
- //}
2960
- EOS
2961
- expected = <<-EOS
2962
- <div class="equation">
2963
- <pre>e=mc^2
2964
- </pre>
2965
- </div>
2966
- EOS
2967
- actual = compile_block(src)
2968
- assert_equal expected, actual
2969
- end
2970
-
2971
- def test_texequation_with_caption
2972
- src = <<-EOS
2973
- @<eq>{emc2}
2974
-
2975
- //texequation[emc2][The Equivalence of Mass @<i>{and} Energy]{
2976
- e=mc^2
2977
- //}
2978
- EOS
2979
- expected = <<-EOS
2980
- <p><span class="eqref"><a href="./-.html#emc2">式1.1</a></span></p>
2981
- <div id="emc2" class="caption-equation">
2982
- <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2983
- <div class="equation">
2984
- <pre>e=mc^2
2985
- </pre>
2986
- </div>
2987
- </div>
2988
- EOS
2989
- actual = compile_block(src)
2990
- assert_equal expected, actual
2991
-
2992
- @config['chapterlink'] = nil
2993
- expected = <<-EOS
2994
- <p><span class="eqref">式1.1</span></p>
2995
- <div id="emc2" class="caption-equation">
2996
- <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2997
- <div class="equation">
2998
- <pre>e=mc^2
2999
- </pre>
3000
- </div>
3001
- </div>
3002
- EOS
3003
- actual = compile_block(src)
3004
- assert_equal expected, actual
3005
-
3006
- @config['caption_position']['equation'] = 'bottom'
3007
- expected = <<-EOS
3008
- <p><span class="eqref">式1.1</span></p>
3009
- <div id="emc2" class="caption-equation">
3010
- <div class="equation">
3011
- <pre>e=mc^2
3012
- </pre>
3013
- </div>
3014
- <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
3015
- </div>
3016
- EOS
3017
- actual = compile_block(src)
3018
- assert_equal expected, actual
3019
- end
3020
-
3021
- def test_nest_error_close1
3022
- src = <<-EOS
3023
- //beginchild
3024
- EOS
3025
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
3026
- assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
3027
- end
3028
-
3029
- def test_nest_error_close2
3030
- src = <<-EOS
3031
- * foo
3032
-
3033
- //beginchild
3034
-
3035
- 1. foo
3036
-
3037
- //beginchild
3038
-
3039
- : foo
3040
-
3041
- //beginchild
3042
- EOS
3043
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
3044
- assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message
3045
- end
3046
-
3047
- def test_nest_error_close3
3048
- src = <<-EOS
3049
- * foo
3050
-
3051
- //beginchild
3052
-
3053
- 1. foo
3054
-
3055
- //beginchild
3056
-
3057
- : foo
3058
-
3059
- //beginchild
3060
-
3061
- //endchild
3062
- EOS
3063
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
3064
- assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message
3065
- end
3066
-
3067
- def test_nest_ul
3068
- src = <<-EOS
3069
- * UL1
3070
-
3071
- //beginchild
3072
-
3073
- 1. UL1-OL1
3074
- 2. UL1-OL2
3075
-
3076
- * UL1-UL1
3077
- * UL1-UL2
3078
-
3079
- : UL1-DL1
3080
- UL1-DD1
3081
- : UL1-DL2
3082
- UL1-DD2
3083
-
3084
- //endchild
3085
-
3086
- * UL2
3087
-
3088
- //beginchild
3089
-
3090
- UL2-PARA
3091
-
3092
- //endchild
3093
- EOS
3094
-
3095
- expected = <<-EOS
3096
- <ul>
3097
- <li>UL1
3098
- <ol>
3099
- <li>UL1-OL1</li>
3100
- <li>UL1-OL2</li>
3101
- </ol>
3102
- <ul>
3103
- <li>UL1-UL1</li>
3104
- <li>UL1-UL2</li>
3105
- </ul>
3106
- <dl>
3107
- <dt>UL1-DL1</dt>
3108
- <dd>UL1-DD1</dd>
3109
- <dt>UL1-DL2</dt>
3110
- <dd>UL1-DD2</dd>
3111
- </dl>
3112
- </li>
3113
-
3114
- <li>UL2
3115
- <p>UL2-PARA</p>
3116
- </li>
3117
- </ul>
3118
- EOS
3119
-
3120
- actual = compile_block(src)
3121
- assert_equal expected, actual
3122
- end
3123
-
3124
- def test_nest_ol
3125
- src = <<-EOS
3126
- 1. OL1
3127
-
3128
- //beginchild
3129
-
3130
- 1. OL1-OL1
3131
- 2. OL1-OL2
3132
-
3133
- * OL1-UL1
3134
- * OL1-UL2
3135
-
3136
- : OL1-DL1
3137
- OL1-DD1
3138
- : OL1-DL2
3139
- OL1-DD2
3140
-
3141
- //endchild
3142
-
3143
- 2. OL2
3144
-
3145
- //beginchild
3146
-
3147
- OL2-PARA
3148
-
3149
- //endchild
3150
- EOS
3151
-
3152
- expected = <<-EOS
3153
- <ol>
3154
- <li>OL1
3155
- <ol>
3156
- <li>OL1-OL1</li>
3157
- <li>OL1-OL2</li>
3158
- </ol>
3159
- <ul>
3160
- <li>OL1-UL1</li>
3161
- <li>OL1-UL2</li>
3162
- </ul>
3163
- <dl>
3164
- <dt>OL1-DL1</dt>
3165
- <dd>OL1-DD1</dd>
3166
- <dt>OL1-DL2</dt>
3167
- <dd>OL1-DD2</dd>
3168
- </dl>
3169
- </li>
3170
-
3171
- <li>OL2
3172
- <p>OL2-PARA</p>
3173
- </li>
3174
- </ol>
3175
- EOS
3176
-
3177
- actual = compile_block(src)
3178
- assert_equal expected, actual
3179
- end
3180
-
3181
- def test_nest_dl
3182
- src = <<-EOS
3183
- : DL1
3184
-
3185
- //beginchild
3186
-
3187
- 1. DL1-OL1
3188
- 2. DL1-OL2
3189
-
3190
- * DL1-UL1
3191
- * DL1-UL2
3192
-
3193
- : DL1-DL1
3194
- DL1-DD1
3195
- : DL1-DL2
3196
- DL1-DD2
3197
-
3198
- //endchild
3199
-
3200
- : DL2
3201
- DD2
3202
-
3203
- //beginchild
3204
-
3205
- * DD2-UL1
3206
- * DD2-UL2
3207
-
3208
- DD2-PARA
3209
-
3210
- //endchild
3211
- EOS
3212
-
3213
- expected = <<-EOS
3214
- <dl>
3215
- <dt>DL1</dt>
3216
- <dd>
3217
- <ol>
3218
- <li>DL1-OL1</li>
3219
- <li>DL1-OL2</li>
3220
- </ol>
3221
- <ul>
3222
- <li>DL1-UL1</li>
3223
- <li>DL1-UL2</li>
3224
- </ul>
3225
- <dl>
3226
- <dt>DL1-DL1</dt>
3227
- <dd>DL1-DD1</dd>
3228
- <dt>DL1-DL2</dt>
3229
- <dd>DL1-DD2</dd>
3230
- </dl>
3231
- </dd>
3232
-
3233
- <dt>DL2</dt>
3234
- <dd>DD2
3235
- <ul>
3236
- <li>DD2-UL1</li>
3237
- <li>DD2-UL2</li>
3238
- </ul>
3239
- <p>DD2-PARA</p>
3240
- </dd>
3241
- </dl>
3242
- EOS
3243
-
3244
- actual = compile_block(src)
3245
- assert_equal expected, actual
3246
- end
3247
-
3248
- def test_nest_multi
3249
- src = <<-EOS
3250
- 1. OL1
3251
-
3252
- //beginchild
3253
-
3254
- 1. OL1-OL1
3255
-
3256
- //beginchild
3257
-
3258
- * OL1-OL1-UL1
3259
-
3260
- OL1-OL1-PARA
3261
-
3262
- //endchild
3263
-
3264
- 2. OL1-OL2
3265
-
3266
- * OL1-UL1
3267
-
3268
- //beginchild
3269
-
3270
- : OL1-UL1-DL1
3271
- OL1-UL1-DD1
3272
-
3273
- OL1-UL1-PARA
3274
-
3275
- //endchild
3276
-
3277
- * OL1-UL2
3278
-
3279
- //endchild
3280
- EOS
3281
- expected = <<-EOS
3282
- <ol>
3283
- <li>OL1
3284
- <ol>
3285
- <li>OL1-OL1
3286
- <ul>
3287
- <li>OL1-OL1-UL1</li>
3288
- </ul>
3289
- <p>OL1-OL1-PARA</p>
3290
- </li>
3291
-
3292
- <li>OL1-OL2</li>
3293
- </ol>
3294
- <ul>
3295
- <li>OL1-UL1
3296
- <dl>
3297
- <dt>OL1-UL1-DL1</dt>
3298
- <dd>OL1-UL1-DD1</dd>
3299
- </dl>
3300
- <p>OL1-UL1-PARA</p>
3301
- </li>
3302
-
3303
- <li>OL1-UL2</li>
3304
- </ul>
3305
- </li>
3306
- </ol>
3307
- EOS
3308
-
3309
- actual = compile_block(src)
3310
- assert_equal expected, actual
3311
- end
3312
- end