review 3.1.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-win.yml +45 -0
  3. data/.github/workflows/ruby.yml +27 -0
  4. data/.rubocop.yml +161 -34
  5. data/.travis.yml +16 -15
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +394 -0
  8. data/NEWS.md +395 -1
  9. data/README.md +10 -7
  10. data/appveyor.yml +1 -3
  11. data/bin/review-catalog-converter +5 -5
  12. data/bin/review-check +10 -12
  13. data/bin/review-checkdep +2 -2
  14. data/bin/review-compile +17 -23
  15. data/bin/review-epubmaker +3 -35
  16. data/bin/review-idgxmlmaker +16 -0
  17. data/bin/review-index +2 -89
  18. data/bin/review-preproc +13 -13
  19. data/bin/review-validate +4 -4
  20. data/bin/review-vol +4 -78
  21. data/doc/config.yml.sample +47 -12
  22. data/doc/config.yml.sample-simple +3 -2
  23. data/doc/format.ja.md +120 -17
  24. data/doc/format.md +119 -27
  25. data/doc/makeindex.ja.md +2 -2
  26. data/doc/pdfmaker.ja.md +43 -1
  27. data/doc/pdfmaker.md +42 -1
  28. data/doc/quickstart.ja.md +45 -25
  29. data/doc/quickstart.md +37 -16
  30. data/lib/epubmaker/content.rb +3 -2
  31. data/lib/epubmaker/epubcommon.rb +34 -27
  32. data/lib/epubmaker/epubv2.rb +5 -6
  33. data/lib/epubmaker/epubv3.rb +21 -18
  34. data/lib/epubmaker/producer.rb +2 -1
  35. data/lib/review/book.rb +2 -2
  36. data/lib/review/book/base.rb +91 -96
  37. data/lib/review/book/bib.rb +21 -0
  38. data/lib/review/book/book_unit.rb +155 -0
  39. data/lib/review/book/chapter.rb +48 -29
  40. data/lib/review/book/index.rb +46 -240
  41. data/lib/review/book/index/item.rb +46 -0
  42. data/lib/review/book/page_metric.rb +7 -7
  43. data/lib/review/book/part.rb +45 -10
  44. data/lib/review/book/volume.rb +4 -5
  45. data/lib/review/builder.rb +172 -56
  46. data/lib/review/catalog.rb +14 -17
  47. data/lib/review/compiler.rb +219 -121
  48. data/lib/review/configure.rb +39 -7
  49. data/lib/review/converter.rb +1 -1
  50. data/lib/review/epub2html.rb +43 -5
  51. data/lib/review/epubmaker.rb +69 -27
  52. data/lib/review/extentions/string.rb +0 -4
  53. data/lib/review/htmlbuilder.rb +112 -101
  54. data/lib/review/htmlutils.rb +9 -13
  55. data/lib/review/i18n.rb +3 -3
  56. data/lib/review/idgxmlbuilder.rb +202 -78
  57. data/lib/review/idgxmlmaker.rb +186 -0
  58. data/lib/review/index_builder.rb +653 -0
  59. data/lib/review/init-web/finish.html +10 -0
  60. data/lib/review/init-web/index.html +190 -0
  61. data/lib/review/init-web/review-layout-design.js +691 -0
  62. data/lib/review/init.rb +129 -46
  63. data/lib/review/latexbuilder.rb +255 -92
  64. data/lib/review/lineinput.rb +1 -1
  65. data/lib/review/location.rb +32 -0
  66. data/lib/review/logger.rb +4 -8
  67. data/lib/review/makerhelper.rb +35 -5
  68. data/lib/review/markdownbuilder.rb +50 -38
  69. data/lib/review/md2inaobuilder.rb +3 -5
  70. data/lib/review/pdfmaker.rb +60 -57
  71. data/lib/review/plaintextbuilder.rb +154 -87
  72. data/lib/review/preprocessor.rb +20 -42
  73. data/lib/review/rstbuilder.rb +57 -38
  74. data/lib/review/sec_counter.rb +13 -0
  75. data/lib/review/textmaker.rb +23 -15
  76. data/lib/review/textutils.rb +76 -2
  77. data/lib/review/tocprinter.rb +230 -102
  78. data/lib/review/topbuilder.rb +139 -60
  79. data/lib/review/update.rb +24 -24
  80. data/lib/review/version.rb +1 -1
  81. data/lib/review/volumeprinter.rb +98 -0
  82. data/lib/review/webmaker.rb +20 -24
  83. data/lib/review/webtocprinter.rb +38 -35
  84. data/lib/review/yamlloader.rb +26 -16
  85. data/review.gemspec +6 -4
  86. data/samples/sample-book/README.md +7 -2
  87. data/samples/sample-book/src/.gitignore +154 -0
  88. data/samples/sample-book/src/config-ebook.yml +4 -0
  89. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  90. data/samples/sample-book/src/config-jlreq.yml +6 -0
  91. data/samples/sample-book/src/config.yml +2 -2
  92. data/samples/sample-book/src/lib/tasks/review.rake +29 -14
  93. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  94. data/samples/syntax-book/Gemfile +1 -1
  95. data/samples/syntax-book/ch01.re +4 -2
  96. data/samples/syntax-book/ch02.re +8 -16
  97. data/samples/syntax-book/ch03.re +3 -6
  98. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  99. data/samples/syntax-book/config-jlreq.yml +5 -0
  100. data/samples/syntax-book/config-print.yml +3 -0
  101. data/samples/syntax-book/config.yml +1 -1
  102. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  103. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  104. data/templates/latex/config.erb +39 -25
  105. data/templates/latex/layout.tex.erb +1 -0
  106. data/templates/latex/review-jlreq/README.md +3 -1
  107. data/templates/latex/review-jlreq/review-base.sty +161 -50
  108. data/templates/latex/review-jlreq/review-jlreq.cls +21 -22
  109. data/templates/latex/review-jlreq/review-style.sty +4 -1
  110. data/templates/latex/review-jsbook/README.md +46 -5
  111. data/templates/latex/review-jsbook/review-base.sty +123 -35
  112. data/templates/latex/review-jsbook/review-jsbook.cls +10 -4
  113. data/templates/latex/review-jsbook/review-style.sty +5 -2
  114. data/templates/opf/epubv3.opf.erb +1 -0
  115. data/templates/web/html/layout-html5.html.erb +3 -3
  116. data/test/assets/test_template.tex +19 -7
  117. data/test/assets/test_template_backmatter.tex +19 -7
  118. data/test/book_test_helper.rb +11 -5
  119. data/test/test_book.rb +124 -79
  120. data/test/test_book_chapter.rb +97 -54
  121. data/test/test_book_part.rb +3 -3
  122. data/test/test_builder.rb +38 -13
  123. data/test/test_catalog.rb +24 -42
  124. data/test/test_catalog_converter_cmd.rb +1 -1
  125. data/test/test_converter.rb +1 -0
  126. data/test/test_epub3maker.rb +2 -2
  127. data/test/test_epubmaker.rb +8 -0
  128. data/test/test_epubmaker_cmd.rb +14 -7
  129. data/test/test_helper.rb +18 -7
  130. data/test/test_htmlbuilder.rb +1491 -205
  131. data/test/test_htmlutils.rb +0 -12
  132. data/test/test_i18n.rb +37 -37
  133. data/test/test_idgxmlbuilder.rb +744 -42
  134. data/test/test_idgxmlmaker_cmd.rb +46 -0
  135. data/test/test_image_finder.rb +52 -70
  136. data/test/test_index.rb +94 -44
  137. data/test/test_indexbuilder.rb +52 -0
  138. data/test/test_latexbuilder.rb +1784 -161
  139. data/test/test_latexbuilder_v2.rb +671 -102
  140. data/test/test_logger.rb +17 -4
  141. data/test/test_makerhelper.rb +2 -14
  142. data/test/test_markdownbuilder.rb +137 -16
  143. data/test/test_md2inaobuilder.rb +32 -9
  144. data/test/test_pdfmaker.rb +30 -12
  145. data/test/test_pdfmaker_cmd.rb +100 -6
  146. data/test/test_plaintextbuilder.rb +791 -30
  147. data/test/test_preprocessor.rb +2 -16
  148. data/test/test_review_ext.rb +2 -1
  149. data/test/test_rstbuilder.rb +274 -27
  150. data/test/test_sec_counter.rb +156 -0
  151. data/test/test_textmaker_cmd.rb +54 -0
  152. data/test/test_textutils.rb +109 -2
  153. data/test/test_topbuilder.rb +724 -34
  154. data/test/test_update.rb +20 -11
  155. data/test/test_webtocprinter.rb +75 -43
  156. data/test/test_yamlloader.rb +13 -0
  157. data/vendor/gentombow/LICENSE +1 -1
  158. data/vendor/gentombow/Makefile +0 -1
  159. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  160. data/vendor/gentombow/bounddvi-en.tex +1 -0
  161. data/vendor/gentombow/bounddvi.pdf +0 -0
  162. data/vendor/gentombow/bounddvi.sty +30 -7
  163. data/vendor/gentombow/bounddvi.tex +1 -0
  164. data/vendor/gentombow/create_archive.sh +1 -0
  165. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  166. data/vendor/gentombow/gentombow-ja.tex +9 -0
  167. data/vendor/gentombow/gentombow.pdf +0 -0
  168. data/vendor/gentombow/gentombow.sty +32 -10
  169. data/vendor/gentombow/gentombow.tex +8 -0
  170. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  171. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  172. data/vendor/jsclasses/LICENSE +1 -1
  173. data/vendor/jsclasses/Makefile +3 -2
  174. data/vendor/jsclasses/create_archive.sh +5 -5
  175. data/vendor/jsclasses/jis/Makefile +3 -2
  176. data/vendor/jsclasses/jis/jsarticle.cls +74 -31
  177. data/vendor/jsclasses/jis/jsbook.cls +74 -31
  178. data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
  179. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  180. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  181. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  182. data/vendor/jsclasses/jis/jslogo.sty +4 -16
  183. data/vendor/jsclasses/jis/jspf.cls +73 -30
  184. data/vendor/jsclasses/jis/jsreport.cls +74 -31
  185. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  186. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  187. data/vendor/jsclasses/jis/kiyou.cls +74 -31
  188. data/vendor/jsclasses/jis/minijs.sty +65 -22
  189. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  190. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  191. data/vendor/jsclasses/jis/okumacro.sty +4 -17
  192. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  193. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  194. data/vendor/jsclasses/jis/winjis.sty +23 -19
  195. data/vendor/jsclasses/jsarticle.cls +74 -31
  196. data/vendor/jsclasses/jsbook.cls +74 -31
  197. data/vendor/jsclasses/jsclasses.dtx +176 -36
  198. data/vendor/jsclasses/jsclasses.ins +15 -5
  199. data/vendor/jsclasses/jsclasses.pdf +0 -0
  200. data/vendor/jsclasses/jslogo.dtx +4 -4
  201. data/vendor/jsclasses/jslogo.ins +9 -0
  202. data/vendor/jsclasses/jslogo.pdf +0 -0
  203. data/vendor/jsclasses/jslogo.sty +4 -16
  204. data/vendor/jsclasses/jspf.cls +73 -30
  205. data/vendor/jsclasses/jsreport.cls +74 -31
  206. data/vendor/jsclasses/jsverb.ins +9 -0
  207. data/vendor/jsclasses/jsverb.pdf +0 -0
  208. data/vendor/jsclasses/jsverb.sty +1 -13
  209. data/vendor/jsclasses/kiyou.cls +74 -31
  210. data/vendor/jsclasses/minijs.sty +68 -22
  211. data/vendor/jsclasses/okumacro.dtx +4 -5
  212. data/vendor/jsclasses/okumacro.ins +9 -0
  213. data/vendor/jsclasses/okumacro.pdf +0 -0
  214. data/vendor/jsclasses/okumacro.sty +4 -17
  215. data/vendor/jsclasses/okuverb.ins +9 -0
  216. data/vendor/jsclasses/okuverb.pdf +0 -0
  217. data/vendor/jsclasses/okuverb.sty +1 -13
  218. data/vendor/jsclasses/tests/relfont.tex +10 -0
  219. data/vendor/jsclasses/winjis.sty +23 -19
  220. metadata +65 -12
  221. data/.rubocop_todo.yml +0 -7
  222. data/lib/review/book/compilable.rb +0 -173
  223. data/lib/review/tocparser.rb +0 -271
  224. data/samples/syntax-book/review-ext.rb +0 -14
  225. data/test/test_tocparser.rb +0 -25
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  require 'yaml'
5
5
  require 'rbconfig'
6
6
 
7
- load File.expand_path('../bin/review-catalog-converter', File.dirname(__FILE__))
7
+ load(File.expand_path('../bin/review-catalog-converter', File.dirname(__FILE__)))
8
8
 
9
9
  class CatalogConverterCmdTest < Test::Unit::TestCase
10
10
  def test_parse_chaps
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'book_test_helper'
3
3
  require 'review/converter'
4
+ require 'review/latexbuilder'
4
5
 
5
6
  class ConverterTest < Test::Unit::TestCase
6
7
  include BookTestHelper
@@ -631,7 +631,7 @@ EOT
631
631
  </body>
632
632
  </html>
633
633
  EOT
634
- File.open(path, 'w') { |f| f.write(html) }
634
+ File.write(path, html)
635
635
  assert_equal ['mathml'], epubmaker.detect_properties(path)
636
636
  end
637
637
  end
@@ -656,7 +656,7 @@ EOT
656
656
  </body>
657
657
  </html>
658
658
  EOT
659
- File.open(path, 'w') { |f| f.write(html) }
659
+ File.write(path, html)
660
660
  assert_equal ['mathml'], epubmaker.detect_properties(path)
661
661
  end
662
662
  end
@@ -1,5 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'epubmaker'
3
+ require 'review/epubmaker'
3
4
 
4
5
  class EPUBMakerTest < Test::Unit::TestCase
5
6
  include EPUBMaker
@@ -818,4 +819,11 @@ EOT
818
819
  EOT
819
820
  assert_equal expect, @output.string
820
821
  end
822
+
823
+ def test_epub_unsafe_id
824
+ content = Content.new({ 'file' => 'sample.png' })
825
+ assert_equal 'sample-png', content.id
826
+ content = Content.new({ 'file' => 'sample-&()-=+@:,漢字.png' })
827
+ assert_equal 'sample-_25_26_25_28_25_29-_25_3D_25_2B_25_40_25_3A_25_2C_25_E6_25_BC_25_A2_25_E5_25_AD_25_97-png', content.id
828
+ end
821
829
  end
@@ -16,23 +16,30 @@ class EPUBMakerCmdTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def teardown
19
- FileUtils.rm_rf @tmpdir1
20
- FileUtils.rm_rf @tmpdir2
19
+ FileUtils.rm_rf(@tmpdir1)
20
+ FileUtils.rm_rf(@tmpdir2)
21
21
  ENV['RUBYLIB'] = @old_rubylib
22
22
  end
23
23
 
24
- def test_epubmaker_cmd
24
+ def common_buildepub(bookdir, configfile, targetepubfile)
25
25
  if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM
26
- config = prepare_samplebook(@tmpdir1)
26
+ config = prepare_samplebook(@tmpdir1, bookdir, nil, configfile)
27
27
  builddir = File.join(@tmpdir1, config['bookname'] + '-epub')
28
28
  assert !File.exist?(builddir)
29
29
 
30
30
  ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + RbConfig::CONFIG['EXEEXT']
31
31
  Dir.chdir(@tmpdir1) do
32
- system("#{ruby_cmd} -S #{REVIEW_EPUBMAKER} config.yml 1>/dev/null 2>/dev/null")
32
+ system("#{ruby_cmd} -S #{REVIEW_EPUBMAKER} #{configfile} 1>/dev/null 2>/dev/null")
33
33
  end
34
-
35
- assert File.exist?(builddir)
34
+ assert File.exist?(File.join(@tmpdir1, targetepubfile))
36
35
  end
37
36
  end
37
+
38
+ def test_epubmaker_cmd_samplebook
39
+ common_buildepub('sample-book/src', 'config.yml', 'book.epub')
40
+ end
41
+
42
+ def test_epubmaker_cmd_syntaxbook
43
+ common_buildepub('syntax-book', 'config.yml', 'syntax-book.epub')
44
+ end
38
45
  end
@@ -1,6 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
2
2
  require 'test/unit'
3
3
  require 'fileutils'
4
+ require 'review/yamlloader'
5
+ require 'review/extentions'
4
6
 
5
7
  def touch_file(path)
6
8
  FileUtils.touch(path)
@@ -10,13 +12,19 @@ def assets_dir
10
12
  File.join(File.dirname(__FILE__), 'assets')
11
13
  end
12
14
 
13
- def prepare_samplebook(srcdir)
14
- samplebook_dir = File.expand_path('../samples/sample-book/src/', File.dirname(__FILE__))
15
- FileUtils.cp_r(Dir.glob(File.join(samplebook_dir, '*')), srcdir)
16
- # copy from review-jsbook
17
- template_dir = File.expand_path('../templates/latex/review-jsbook/', File.dirname(__FILE__))
18
- FileUtils.cp(Dir.glob(File.join(template_dir, '*')), File.join(srcdir, 'sty'))
19
- YAML.load(File.open(File.join(srcdir, 'config.yml')))
15
+ def prepare_samplebook(srcdir, bookdir, latextemplatedir, configfile)
16
+ samplebook_dir = File.expand_path("../samples/#{bookdir}/", File.dirname(__FILE__))
17
+ files = Dir.glob(File.join(samplebook_dir, '*'))
18
+ # ignore temporary built files
19
+ files.delete_if { |file| file =~ /.*-(pdf|epub|text)/ || file == 'webroot' }
20
+ FileUtils.cp_r(files, srcdir)
21
+ if latextemplatedir
22
+ # copy from review-jsbook or review-jlreq
23
+ template_dir = File.expand_path("../templates/latex/#{latextemplatedir}/", File.dirname(__FILE__))
24
+ FileUtils.cp(Dir.glob(File.join(template_dir, '*')), File.join(srcdir, 'sty'))
25
+ end
26
+ loader = ReVIEW::YAMLLoader.new
27
+ loader.load_file(File.open(File.join(srcdir, configfile)))
20
28
  end
21
29
 
22
30
  def compile_inline(text)
@@ -31,11 +39,13 @@ end
31
39
 
32
40
  def compile_block_default(text)
33
41
  @chapter.content = text
42
+ @chapter.execute_indexer(force: true)
34
43
  @compiler.compile(@chapter)
35
44
  end
36
45
 
37
46
  def compile_block_html(text)
38
47
  @chapter.content = text
48
+ @chapter.execute_indexer(force: true)
39
49
  matched = @compiler.compile(@chapter).match(Regexp.new(%Q(<body>\n(.+)</body>), Regexp::MULTILINE))
40
50
  if matched && matched.size > 1
41
51
  matched[1]
@@ -46,5 +56,6 @@ end
46
56
 
47
57
  def compile_block_idgxml(text)
48
58
  @chapter.content = text
59
+ @chapter.execute_indexer(force: true)
49
60
  @compiler.compile(@chapter).gsub(Regexp.new(%Q(.*<doc xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">), Regexp::MULTILINE), '').gsub("</doc>\n", '')
50
61
  end
@@ -61,7 +61,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
61
61
  Dir.mktmpdir do |dir|
62
62
  Dir.chdir(dir) do
63
63
  file = File.join(dir, 'locale.yml')
64
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") }
64
+ File.write(file, "locale: ja\nappendix: 付録%pR")
65
65
  I18n.setup('ja')
66
66
  @chapter.instance_eval do
67
67
  def on_appendix?
@@ -82,7 +82,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
82
82
  Dir.mktmpdir do |dir|
83
83
  Dir.chdir(dir) do
84
84
  file = File.join(dir, 'locale.yml')
85
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") }
85
+ File.write(file, "locale: ja\nappendix: 付録%pA")
86
86
  I18n.setup('ja')
87
87
  @chapter.instance_eval do
88
88
  def on_appendix?
@@ -106,8 +106,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
106
106
  end
107
107
 
108
108
  def test_headline_level1_with_tricky_id
109
- actual = compile_block("={123 あ_;} this is test.\n")
110
- assert_equal %Q(<h1 id="id_123-_E3_81_82___3B"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n), actual
109
+ actual = compile_block("={123あ_} this is test.\n")
110
+ 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
111
111
  end
112
112
 
113
113
  def test_headline_level1_with_inlinetag
@@ -137,8 +137,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
137
137
  end
138
138
 
139
139
  def test_label_with_tricky_id
140
- actual = compile_block("//label[123 あ_;]\n")
141
- assert_equal %Q(<a id="id_123-_E3_81_82___3B"></a>\n), actual
140
+ actual = compile_block("//label[123あ_]\n")
141
+ assert_equal %Q(<a id="id_123_E3_81_82__"></a>\n), actual
142
142
  end
143
143
 
144
144
  def test_href
@@ -191,7 +191,15 @@ class HTMLBuidlerTest < Test::Unit::TestCase
191
191
 
192
192
  def test_inline_in_table
193
193
  actual = compile_block("//table{\n@<b>{1}\t@<i>{2}\n------------\n@<b>{3}\t@<i>{4}<>&\n//}\n")
194
- assert_equal %Q(<div class="table">\n<table>\n<tr><th><b>1</b></th><th><i>2</i></th></tr>\n<tr><td><b>3</b></td><td><i>4</i>&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n), actual
194
+ expected = <<-EOS
195
+ <div class="table">
196
+ <table>
197
+ <tr><th><b>1</b></th><th><i>2</i></th></tr>
198
+ <tr><td><b>3</b></td><td><i>4</i>&lt;&gt;&amp;</td></tr>
199
+ </table>
200
+ </div>
201
+ EOS
202
+ assert_equal expected, actual
195
203
  end
196
204
 
197
205
  def test_inline_br
@@ -236,10 +244,21 @@ class HTMLBuidlerTest < Test::Unit::TestCase
236
244
 
237
245
  def test_inline_hd_chap
238
246
  def @chapter.headline_index
239
- items = [Book::HeadlineIndex::Item.new('chap1|test', [1, 1], 'te_st')]
240
- Book::HeadlineIndex.new(items, self)
247
+ item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
248
+ idx = Book::HeadlineIndex.new(self)
249
+ idx.add_item(item)
250
+ idx
241
251
  end
242
252
 
253
+ @config['secnolevel'] = 2
254
+ actual = compile_inline('test @<hd>{chap1|test} test2')
255
+ assert_equal 'test <a href="-.html#h1-1-1">「te_st」</a> test2', actual
256
+
257
+ @config['secnolevel'] = 3
258
+ actual = compile_inline('test @<hd>{chap1|test} test2')
259
+ assert_equal 'test <a href="-.html#h1-1-1">「1.1.1 te_st」</a> test2', actual
260
+
261
+ @config['chapterlink'] = nil
243
262
  @config['secnolevel'] = 2
244
263
  actual = compile_inline('test @<hd>{chap1|test} test2')
245
264
  assert_equal 'test 「te_st」 test2', actual
@@ -253,7 +272,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
253
272
  Dir.mktmpdir do |dir|
254
273
  Dir.chdir(dir) do
255
274
  file = File.join(dir, 'locale.yml')
256
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") }
275
+ File.write(file, "locale: ja\nappendix: 付録%pR")
257
276
  I18n.setup('ja')
258
277
  @chapter.instance_eval do
259
278
  def on_appendix?
@@ -262,10 +281,16 @@ class HTMLBuidlerTest < Test::Unit::TestCase
262
281
  end
263
282
 
264
283
  def @chapter.headline_index
265
- items = [Book::HeadlineIndex::Item.new('test', [1], 'te_st')]
266
- Book::HeadlineIndex.new(items, self)
284
+ item = Book::Index::Item.new('test', [1], 'te_st')
285
+ idx = Book::HeadlineIndex.new(self)
286
+ idx.add_item(item)
287
+ idx
267
288
  end
268
289
 
290
+ actual = compile_inline('test @<hd>{test} test2')
291
+ assert_equal 'test <a href="-.html#hI-1">「I.1 te_st」</a> test2', actual
292
+
293
+ @config['chapterlink'] = nil
269
294
  actual = compile_inline('test @<hd>{test} test2')
270
295
  assert_equal 'test 「I.1 te_st」 test2', actual
271
296
  end
@@ -276,7 +301,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
276
301
  Dir.mktmpdir do |dir|
277
302
  Dir.chdir(dir) do
278
303
  file = File.join(dir, 'locale.yml')
279
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") }
304
+ File.write(file, "locale: ja\nappendix: 付録%pA")
280
305
  I18n.setup('ja')
281
306
  @chapter.instance_eval do
282
307
  def on_appendix?
@@ -285,10 +310,16 @@ class HTMLBuidlerTest < Test::Unit::TestCase
285
310
  end
286
311
 
287
312
  def @chapter.headline_index
288
- items = [Book::HeadlineIndex::Item.new('test', [1], 'te_st')]
289
- Book::HeadlineIndex.new(items, self)
313
+ item = Book::Index::Item.new('test', [1], 'te_st')
314
+ idx = Book::HeadlineIndex.new(self)
315
+ idx.add_item(item)
316
+ idx
290
317
  end
291
318
 
319
+ actual = compile_inline('test @<hd>{test} test2')
320
+ assert_equal 'test <a href="-.html#hA-1">「A.1 te_st」</a> test2', actual
321
+
322
+ @config['chapterlink'] = nil
292
323
  actual = compile_inline('test @<hd>{test} test2')
293
324
  assert_equal 'test 「A.1 te_st」 test2', actual
294
325
  end
@@ -335,36 +366,51 @@ class HTMLBuidlerTest < Test::Unit::TestCase
335
366
 
336
367
  def test_inline_img
337
368
  def @chapter.image(_id)
338
- item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
369
+ item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
339
370
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
340
371
  item
341
372
  end
342
373
 
343
- actual = compile_block "@<img>{sampleimg}\n"
374
+ actual = compile_block("@<img>{sampleimg}\n")
375
+ expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n)
376
+ assert_equal expected, actual
377
+
378
+ @config['chapterlink'] = nil
379
+ actual = compile_block("@<img>{sampleimg}\n")
344
380
  expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
345
381
  assert_equal expected, actual
346
382
  end
347
383
 
348
384
  def test_inline_imgref
349
385
  def @chapter.image(_id)
350
- item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
386
+ item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
351
387
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
352
388
  item
353
389
  end
354
390
 
355
- actual = compile_block "@<imgref>{sampleimg}\n"
391
+ actual = compile_block("@<imgref>{sampleimg}\n")
392
+ expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span>「sample photo」</p>\n)
393
+ assert_equal expected, actual
394
+
395
+ @config['chapterlink'] = nil
396
+ actual = compile_block("@<imgref>{sampleimg}\n")
356
397
  expected = %Q(<p><span class="imgref">図1.1</span>「sample photo」</p>\n)
357
398
  assert_equal expected, actual
358
399
  end
359
400
 
360
401
  def test_inline_imgref2
361
402
  def @chapter.image(_id)
362
- item = Book::NumberlessImageIndex::Item.new('sampleimg', 1)
403
+ item = Book::Index::Item.new('sampleimg', 1)
363
404
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
364
405
  item
365
406
  end
366
407
 
367
- actual = compile_block "@<imgref>{sampleimg}\n"
408
+ actual = compile_block("@<imgref>{sampleimg}\n")
409
+ expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n)
410
+ assert_equal expected, actual
411
+
412
+ @config['chapterlink'] = nil
413
+ actual = compile_block("@<imgref>{sampleimg}\n")
368
414
  expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
369
415
  assert_equal expected, actual
370
416
  end
@@ -375,20 +421,24 @@ class HTMLBuidlerTest < Test::Unit::TestCase
375
421
  file1 = File.join(dir, 'images', 'img1.png')
376
422
  filet1 = File.join(dir, 'images', 'tbl1.png')
377
423
  file2 = File.join(dir, 'images', 'img2.png')
424
+ file3 = File.join(dir, 'images', 'icon3.png')
378
425
  re1 = File.join(dir, 'sample1.re')
379
426
  cat = File.join(dir, 'catalog.yml')
380
427
  FileUtils.mkdir_p(File.join(dir, 'images'))
381
- File.open(file1, 'w') { |f| f.write('') }
382
- File.open(filet1, 'w') { |f| f.write('') }
383
- File.open(file2, 'w') { |f| f.write('') }
384
- File.open(cat, 'w') { |f| f.write("CHAPS:\n - sample1.re\n") }
385
- File.open(re1, 'w') { |f| f.write(<<EOF) }
428
+ File.write(file1, '')
429
+ File.write(filet1, '')
430
+ File.write(file2, '')
431
+ File.write(file3, '')
432
+ File.write(cat, "CHAPS:\n - sample1.re\n")
433
+ File.write(re1, <<-EOF)
386
434
  = test
387
435
 
388
436
  tbl1 is @<table>{tbl1}.
389
437
 
390
438
  img2 is @<img>{img2}.
391
439
 
440
+ icon3 is @<icon>{icon3}.
441
+
392
442
  //image[img1][image 1]{
393
443
  //}
394
444
 
@@ -403,8 +453,37 @@ EOF
403
453
 
404
454
  expected = <<-EOS
405
455
  <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
456
+ <p>tbl1 is <span class="tableref"><a href="./-.html#tbl1">表1.1</a></span>.</p>
457
+ <p>img2 is <span class="imgref"><a href="./-.html#img2">図1.2</a></span>.</p>
458
+ <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
459
+ <div id="img1" class="image">
460
+ <img src="images/img1.png" alt="image 1" />
461
+ <p class="caption">
462
+ 図1.1: image 1
463
+ </p>
464
+ </div>
465
+ <div id="tbl1" class="imgtable image">
466
+ <p class="caption">表1.1: table 1</p>
467
+ <img src="images/tbl1.png" alt="table 1" />
468
+ </div>
469
+ <div id="img2" class="image">
470
+ <img src="images/img2.png" alt="image 2" />
471
+ <p class="caption">
472
+ 図1.2: image 2
473
+ </p>
474
+ </div>
475
+ EOS
476
+
477
+ assert_equal expected, actual
478
+
479
+ @config['chapterlink'] = nil
480
+ actual = compile_block(content)
481
+
482
+ expected = <<-EOS
483
+ <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
406
484
  <p>tbl1 is <span class="tableref">表1.1</span>.</p>
407
485
  <p>img2 is <span class="imgref">図1.2</span>.</p>
486
+ <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
408
487
  <div id="img1" class="image">
409
488
  <img src="images/img1.png" alt="image 1" />
410
489
  <p class="caption">
@@ -430,189 +509,443 @@ EOS
430
509
 
431
510
  def test_quote
432
511
  actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
433
- assert_equal %Q(<blockquote><p>foobar</p>\n<p>buz</p></blockquote>\n), actual
512
+ expected = <<-EOS
513
+ <blockquote><p>foobar</p>
514
+ <p>buz</p></blockquote>
515
+ EOS
516
+ assert_equal expected, actual
517
+
518
+ @book.config['join_lines_by_lang'] = true
519
+ actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
520
+ expected = <<-EOS
521
+ <blockquote><p>foo bar</p>
522
+ <p>buz</p></blockquote>
523
+ EOS
524
+ assert_equal expected, actual
434
525
  end
435
526
 
436
527
  def test_memo
437
528
  actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
438
- assert_equal %Q(<div class="memo">\n<p class="caption">this is <b>test</b>&lt;&amp;&gt;_</p>\n<p>test1</p>\n<p>test<i>2</i></p>\n</div>\n), actual
529
+ expected = <<-EOS
530
+ <div class="memo">
531
+ <p class="caption">this is <b>test</b>&lt;&amp;&gt;_</p>
532
+ <p>test1</p>
533
+ <p>test<i>2</i></p>
534
+ </div>
535
+ EOS
536
+ assert_equal expected, actual
439
537
  end
440
538
 
441
539
  def test_blankline
442
540
  actual = compile_block("//blankline\nfoo\n")
443
- assert_equal %Q(<p><br /></p>\n<p>foo</p>\n), actual
541
+ expected = <<-EOS
542
+ <p><br /></p>
543
+ <p>foo</p>
544
+ EOS
545
+ assert_equal expected, actual
444
546
  end
445
547
 
446
548
  def test_noindent
447
549
  actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
448
- assert_equal %Q(<p class="noindent">foobar</p>\n<p>foo2bar2</p>\n), actual
550
+ expected = <<-EOS
551
+ <p class="noindent">foobar</p>
552
+ <p>foo2bar2</p>
553
+ EOS
554
+ assert_equal expected, actual
555
+
556
+ @book.config['join_lines_by_lang'] = true
557
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
558
+ expected = <<-EOS
559
+ <p class="noindent">foo bar</p>
560
+ <p>foo2 bar2</p>
561
+ EOS
562
+ assert_equal expected, actual
449
563
  end
450
564
 
451
565
  def test_flushright
452
566
  actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
453
- assert_equal %Q(<p class="flushright">foobar</p>\n<p class="flushright">buz</p>\n), actual
567
+ expected = <<-EOS
568
+ <p class="flushright">foobar</p>
569
+ <p class="flushright">buz</p>
570
+ EOS
571
+ assert_equal expected, actual
572
+
573
+ @book.config['join_lines_by_lang'] = true
574
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
575
+ expected = <<-EOS
576
+ <p class="flushright">foo bar</p>
577
+ <p class="flushright">buz</p>
578
+ EOS
579
+ assert_equal expected, actual
454
580
  end
455
581
 
456
582
  def test_centering
457
583
  actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
458
- assert_equal %Q(<p class="center">foobar</p>\n<p class="center">buz</p>\n), actual
584
+ expected = <<-EOS
585
+ <p class="center">foobar</p>
586
+ <p class="center">buz</p>
587
+ EOS
588
+ assert_equal expected, actual
589
+
590
+ @book.config['join_lines_by_lang'] = true
591
+ actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
592
+ expected = <<-EOS
593
+ <p class="center">foo bar</p>
594
+ <p class="center">buz</p>
595
+ EOS
596
+ assert_equal expected, actual
459
597
  end
460
598
 
461
599
  def test_image
462
600
  def @chapter.image(_id)
463
- item = Book::ImageIndex::Item.new('sampleimg', 1)
601
+ item = Book::Index::Item.new('sampleimg', 1)
464
602
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
465
603
  item
466
604
  end
467
605
 
468
606
  actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
469
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
607
+ expected = <<-EOS
608
+ <div id="sampleimg" class="image">
609
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
610
+ <p class="caption">
611
+ 図1.1: sample photo
612
+ </p>
613
+ </div>
614
+ EOS
615
+ assert_equal expected, actual
616
+
617
+ @config['caption_position']['image'] = 'top'
618
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
619
+ expected = <<-EOS
620
+ <div id="sampleimg" class="image">
621
+ <p class="caption">
622
+ 図1.1: sample photo
623
+ </p>
624
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
625
+ </div>
626
+ EOS
627
+ assert_equal expected, actual
470
628
  end
471
629
 
472
630
  def test_image_with_metric
473
631
  def @chapter.image(_id)
474
- item = Book::ImageIndex::Item.new('sampleimg', 1)
632
+ item = Book::Index::Item.new('sampleimg', 1)
475
633
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
476
634
  item
477
635
  end
478
636
 
479
637
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
480
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
638
+ expected = <<-EOS
639
+ <div id="sampleimg" class="image">
640
+ <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />
641
+ <p class="caption">
642
+ 図1.1: sample photo
643
+ </p>
644
+ </div>
645
+ EOS
646
+ assert_equal expected, actual
481
647
  end
482
648
 
483
649
  def test_image_with_metric2
484
650
  def @chapter.image(_id)
485
- item = Book::ImageIndex::Item.new('sampleimg', 1)
651
+ item = Book::Index::Item.new('sampleimg', 1)
486
652
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
487
653
  item
488
654
  end
489
655
 
490
656
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
491
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
657
+ expected = <<-EOS
658
+ <div id="sampleimg" class="image">
659
+ <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />
660
+ <p class="caption">
661
+ 図1.1: sample photo
662
+ </p>
663
+ </div>
664
+ EOS
665
+ assert_equal expected, actual
492
666
  end
493
667
 
494
- def test_image_with_tricky_id
668
+ def test_image_with_tricky_id_kana
495
669
  def @chapter.image(_id)
496
- item = Book::ImageIndex::Item.new('123 あ_;', 1)
497
- item.instance_eval { @path = './images/chap1-123 あ_;.png' }
670
+ item = Book::Index::Item.new('123あいう', 1)
671
+ item.instance_eval { @path = './images/123あいう.png' }
498
672
  item
499
673
  end
500
-
501
- actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
502
- assert_equal %Q(<div id="id_123-_E3_81_82___3B" class="image">\n<img src="images/chap1-123 あ_;.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
674
+ @chapter.instance_eval { @name = 'ch01' }
675
+ actual = compile_block("//image[123あいう][sample photo]{\n//}\nimg: @<img>{123あいう}\n")
676
+ expected = <<-EOS
677
+ <div id="id_123_E3_81_82_E3_81_84_E3_81_86" class="image">
678
+ <img src="images/123あいう.png" alt="sample photo" />
679
+ <p class="caption">
680
+ 図1.1: sample photo
681
+ </p>
682
+ </div>
683
+ <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>
684
+ EOS
685
+ assert_equal expected, actual
503
686
  end
504
687
 
505
688
  def test_indepimage
506
689
  def @chapter.image(_id)
507
- item = Book::ImageIndex::Item.new('sampleimg', 1)
690
+ item = Book::Index::Item.new('sampleimg', 1)
508
691
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
509
692
  item
510
693
  end
511
694
 
512
695
  actual = compile_block("//indepimage[sampleimg][sample photo]\n")
513
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n), actual
696
+ expected = <<-EOS
697
+ <div id="sampleimg" class="image">
698
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
699
+ <p class="caption">
700
+ 図: sample photo
701
+ </p>
702
+ </div>
703
+ EOS
704
+ assert_equal expected, actual
705
+
706
+ @config['caption_position']['image'] = 'top'
707
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
708
+ expected = <<-EOS
709
+ <div id="sampleimg" class="image">
710
+ <p class="caption">
711
+ 図: sample photo
712
+ </p>
713
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
714
+ </div>
715
+ EOS
716
+ assert_equal expected, actual
514
717
  end
515
718
 
516
719
  def test_indepimage_without_caption
517
720
  def @chapter.image(_id)
518
- item = Book::ImageIndex::Item.new('sampleimg', 1)
721
+ item = Book::Index::Item.new('sampleimg', 1)
519
722
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
520
723
  item
521
724
  end
522
725
 
523
726
  actual = compile_block("//indepimage[sampleimg]\n")
524
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="" />\n</div>\n), actual
727
+ expected = <<-EOS
728
+ <div id="sampleimg" class="image">
729
+ <img src="images/chap1-sampleimg.png" alt="" />
730
+ </div>
731
+ EOS
732
+ assert_equal expected, actual
525
733
  end
526
734
 
527
735
  def test_indepimage_with_metric
528
736
  def @chapter.image(_id)
529
- item = Book::ImageIndex::Item.new('sampleimg', 1)
737
+ item = Book::Index::Item.new('sampleimg', 1)
530
738
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
531
739
  item
532
740
  end
533
741
 
534
742
  actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
535
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n), actual
743
+ expected = <<-EOS
744
+ <div id="sampleimg" class="image">
745
+ <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />
746
+ <p class="caption">
747
+ 図: sample photo
748
+ </p>
749
+ </div>
750
+ EOS
751
+ assert_equal expected, actual
536
752
  end
537
753
 
538
754
  def test_indepimage_with_metric2
539
755
  def @chapter.image(_id)
540
- item = Book::ImageIndex::Item.new('sampleimg', 1)
756
+ item = Book::Index::Item.new('sampleimg', 1)
541
757
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
542
758
  item
543
759
  end
544
760
 
545
761
  actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
546
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n), actual
762
+ expected = <<-EOS
763
+ <div id="sampleimg" class="image">
764
+ <img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />
765
+ <p class="caption">
766
+ 図: sample photo
767
+ </p>
768
+ </div>
769
+ EOS
770
+ assert_equal expected, actual
547
771
  end
548
772
 
549
773
  def test_indepimage_without_caption_but_with_metric
550
774
  def @chapter.image(_id)
551
- item = Book::ImageIndex::Item.new('sampleimg', 1)
775
+ item = Book::Index::Item.new('sampleimg', 1)
552
776
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
553
777
  item
554
778
  end
555
779
 
556
780
  actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
557
- assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="" class="width-120per" />\n</div>\n), actual
781
+ expected = <<-EOS
782
+ <div id="sampleimg" class="image">
783
+ <img src="images/chap1-sampleimg.png" alt="" class="width-120per" />
784
+ </div>
785
+ EOS
786
+ assert_equal expected, actual
558
787
  end
559
788
 
560
789
  def test_dlist
561
- actual = compile_block(": foo\n foo.\n bar.\n")
562
- assert_equal %Q(<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n), actual
790
+ actual = compile_block(" : foo\n foo.\n bar.\n")
791
+ expected = <<-EOS
792
+ <dl>
793
+ <dt>foo</dt>
794
+ <dd>foo.bar.</dd>
795
+ </dl>
796
+ EOS
797
+ assert_equal expected, actual
798
+
799
+ @book.config['join_lines_by_lang'] = true
800
+ actual = compile_block(" : foo\n foo.\n bar.\n")
801
+ expected = <<-EOS
802
+ <dl>
803
+ <dt>foo</dt>
804
+ <dd>foo. bar.</dd>
805
+ </dl>
806
+ EOS
807
+ assert_equal expected, actual
563
808
  end
564
809
 
565
810
  def test_dlist_with_bracket
566
- actual = compile_block(": foo[bar]\n foo.\n bar.\n")
567
- assert_equal %Q(<dl>\n<dt>foo[bar]</dt>\n<dd>foo.bar.</dd>\n</dl>\n), actual
811
+ actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
812
+ expected = <<-EOS
813
+ <dl>
814
+ <dt>foo[bar]</dt>
815
+ <dd>foo.bar.</dd>
816
+ </dl>
817
+ EOS
818
+ assert_equal expected, actual
819
+
820
+ @book.config['join_lines_by_lang'] = true
821
+ actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
822
+ expected = <<-EOS
823
+ <dl>
824
+ <dt>foo[bar]</dt>
825
+ <dd>foo. bar.</dd>
826
+ </dl>
827
+ EOS
828
+ assert_equal expected, actual
568
829
  end
569
830
 
570
831
  def test_dlist_with_comment
571
- source = ": title\n body\n\#@ comment\n\#@ comment\n: title2\n body2\n"
832
+ source = " : title\n body\n\#@ comment\n\#@ comment\n : title2\n body2\n"
572
833
  actual = compile_block(source)
573
- assert_equal %Q(<dl>\n<dt>title</dt>\n<dd>body</dd>\n<dt>title2</dt>\n<dd>body2</dd>\n</dl>\n), actual
834
+ expected = <<-EOS
835
+ <dl>
836
+ <dt>title</dt>
837
+ <dd>body</dd>
838
+ <dt>title2</dt>
839
+ <dd>body2</dd>
840
+ </dl>
841
+ EOS
842
+ assert_equal expected, actual
574
843
  end
575
844
 
576
845
  def test_dlist_beforeulol
577
846
  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")
578
- assert_equal %Q(<dl>\n<dt>foo</dt>\n<dd>foo.</dd>\n</dl>\n<p>para</p>\n<dl>\n<dt>foo</dt>\n<dd>foo.</dd>\n</dl>\n<ol>\n<li>bar</li>\n</ol>\n<dl>\n<dt>foo</dt>\n<dd>foo.</dd>\n</dl>\n<ul>\n<li>bar</li>\n</ul>\n), actual
847
+ expected = <<-EOS
848
+ <dl>
849
+ <dt>foo</dt>
850
+ <dd>foo.</dd>
851
+ </dl>
852
+ <p>para</p>
853
+ <dl>
854
+ <dt>foo</dt>
855
+ <dd>foo.</dd>
856
+ </dl>
857
+ <ol>
858
+ <li>bar</li>
859
+ </ol>
860
+ <dl>
861
+ <dt>foo</dt>
862
+ <dd>foo.</dd>
863
+ </dl>
864
+ <ul>
865
+ <li>bar</li>
866
+ </ul>
867
+ EOS
868
+ assert_equal expected, actual
869
+ end
870
+
871
+ def test_dt_inline
872
+ actual = compile_block("//footnote[bar][bar]\n\n : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
873
+
874
+ expected = <<-EOS
875
+ <div class="footnote" epub:type="footnote" id="fn-bar"><p class="footnote">[*1] bar</p></div>
876
+ <dl>
877
+ <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>
878
+ <dd></dd>
879
+ </dl>
880
+ EOS
881
+ assert_equal expected, actual
579
882
  end
580
883
 
581
884
  def test_list
582
885
  def @chapter.list(_id)
583
- Book::ListIndex::Item.new('samplelist', 1)
886
+ Book::Index::Item.new('samplelist', 1)
584
887
  end
585
888
  actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
586
- assert_equal %Q(<div id="samplelist" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n), actual
889
+ expected = <<-EOS
890
+ <div id="samplelist" class="caption-code">
891
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
892
+ <pre class="list">test1
893
+ test1.5
894
+
895
+ test<i>2</i>
896
+ </pre>
897
+ </div>
898
+ EOS
899
+ assert_equal expected, actual
900
+
901
+ @config['caption_position']['list'] = 'bottom'
902
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
903
+ expected = <<-EOS
904
+ <div id="samplelist" class="caption-code">
905
+ <pre class="list">test1
906
+ test1.5
907
+
908
+ test<i>2</i>
909
+ </pre>
910
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
911
+ </div>
912
+ EOS
913
+ assert_equal expected, actual
587
914
  end
588
915
 
589
916
  def test_inline_list
590
917
  def @chapter.list(_id)
591
- Book::ListIndex::Item.new('samplelist', 1)
918
+ Book::Index::Item.new('samplelist', 1)
592
919
  end
593
- actual = compile_block("@<list>{sampletest}\n")
920
+ actual = compile_block("@<list>{samplelist}\n")
921
+ assert_equal %Q(<p><span class="listref"><a href="./-.html#samplelist">リスト1.1</a></span></p>\n), actual
922
+
923
+ @config['chapterlink'] = nil
924
+ actual = compile_block("@<list>{samplelist}\n")
594
925
  assert_equal %Q(<p><span class="listref">リスト1.1</span></p>\n), actual
595
926
  end
596
927
 
597
928
  def test_inline_list_href
598
- book = ReVIEW::Book::Base.load
929
+ book = ReVIEW::Book::Base.new
599
930
  book.config['chapterlink'] = true
600
931
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
601
- io1 = StringIO.new("//list[sampletest]{\nfoo\n//}\n")
932
+ io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n")
602
933
  io2 = StringIO.new("= BAR\n")
603
934
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
604
935
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
605
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
936
+ book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
606
937
  builder = ReVIEW::HTMLBuilder.new
607
938
  comp = ReVIEW::Compiler.new(builder)
608
939
  builder.bind(comp, chap2, nil)
940
+
941
+ chap1.generate_indexes
609
942
  actual = builder.inline_list('ch1|sampletest')
610
943
  assert_equal %Q(<span class="listref"><a href="./ch1.html#sampletest">リスト1.1</a></span>), actual
611
944
  end
612
945
 
613
946
  def test_list_pygments
614
947
  def @chapter.list(_id)
615
- Book::ListIndex::Item.new('samplelist', 1)
948
+ Book::Index::Item.new('samplelist', 1)
616
949
  end
617
950
  begin
618
951
  require 'pygments'
@@ -639,7 +972,7 @@ test&lt;i&gt;2&lt;/i&gt;
639
972
 
640
973
  def test_list_pygments_lang
641
974
  def @chapter.list(_id)
642
- Book::ListIndex::Item.new('samplelist', 1)
975
+ Book::Index::Item.new('samplelist', 1)
643
976
  end
644
977
  begin
645
978
  require 'pygments'
@@ -667,7 +1000,7 @@ EOS
667
1000
 
668
1001
  def test_list_pygments_nulllang
669
1002
  def @chapter.list(_id)
670
- Book::ListIndex::Item.new('samplelist', 1)
1003
+ Book::Index::Item.new('samplelist', 1)
671
1004
  end
672
1005
  begin
673
1006
  require 'pygments'
@@ -700,13 +1033,23 @@ end
700
1033
  return true
701
1034
  end
702
1035
  def @chapter.list(_id)
703
- Book::ListIndex::Item.new('samplelist', 1)
1036
+ Book::Index::Item.new('samplelist', 1)
704
1037
  end
705
1038
  @book.config['highlight'] = {}
706
1039
  @book.config['highlight']['html'] = 'rouge'
707
1040
  actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
708
1041
 
709
- assert_equal %Q(<div id="samplelist" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list highlight">test1\ntest1.5\n\ntest&lt;i&gt;2&lt;/i&gt;\n</pre>\n</div>\n), actual
1042
+ expected = <<-EOS
1043
+ <div id="samplelist" class="caption-code">
1044
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1045
+ <pre class="list highlight">test1
1046
+ test1.5
1047
+
1048
+ test&lt;i&gt;2&lt;/i&gt;
1049
+ </pre>
1050
+ </div>
1051
+ EOS
1052
+ assert_equal expected, actual
710
1053
  end
711
1054
 
712
1055
  def test_list_rouge_lang
@@ -717,7 +1060,7 @@ end
717
1060
  return true
718
1061
  end
719
1062
  def @chapter.list(_id)
720
- Book::ListIndex::Item.new('samplelist', 1)
1063
+ Book::Index::Item.new('samplelist', 1)
721
1064
  end
722
1065
  @book.config['highlight'] = {}
723
1066
  @book.config['highlight']['html'] = 'rouge'
@@ -745,18 +1088,29 @@ EOS
745
1088
  return true
746
1089
  end
747
1090
  def @chapter.list(_id)
748
- Book::ListIndex::Item.new('samplelist', 1)
1091
+ Book::Index::Item.new('samplelist', 1)
749
1092
  end
750
1093
  @book.config['highlight'] = {}
751
1094
  @book.config['highlight']['html'] = 'rouge'
752
1095
  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")
753
1096
 
754
- assert_equal %Q(<div id="samplelist" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list highlight">def foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n</pre>\n</div>\n), actual
1097
+ expected = <<-EOS
1098
+ <div id="samplelist" class="caption-code">
1099
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1100
+ <pre class="list highlight">def foo(a1, a2=:test)
1101
+ (1..3).times{|i| a.include?(:foo)}
1102
+ return true
1103
+ end
1104
+
1105
+ </pre>
1106
+ </div>
1107
+ EOS
1108
+ assert_equal expected, actual
755
1109
  end
756
1110
 
757
1111
  def test_listnum
758
1112
  def @chapter.list(_id)
759
- Book::ListIndex::Item.new('samplelist', 1)
1113
+ Book::Index::Item.new('samplelist', 1)
760
1114
  end
761
1115
 
762
1116
  @book.config['highlight'] = false
@@ -778,6 +1132,29 @@ EOS
778
1132
  4: end
779
1133
  </pre>
780
1134
  </div>
1135
+ EOS
1136
+
1137
+ assert_equal expected, actual
1138
+
1139
+ @config['caption_position']['list'] = 'bottom'
1140
+ actual = compile_block(<<-EOS)
1141
+ //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
1142
+ def foo(a1, a2=:test)
1143
+ (1..3).times{|i| a.include?(:foo)}
1144
+ return true
1145
+ end
1146
+ //}
1147
+ EOS
1148
+
1149
+ expected = <<-EOS
1150
+ <div id="samplelist" class="code">
1151
+ <pre class="list language-ruby"> 1: def foo(a1, a2=:test)
1152
+ 2: (1..3).times{|i| a.include?(:foo)}
1153
+ 3: return true
1154
+ 4: end
1155
+ </pre>
1156
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1157
+ </div>
781
1158
  EOS
782
1159
 
783
1160
  assert_equal expected, actual
@@ -785,7 +1162,7 @@ EOS
785
1162
 
786
1163
  def test_listnum_linenum
787
1164
  def @chapter.list(_id)
788
- Book::ListIndex::Item.new('samplelist', 1)
1165
+ Book::Index::Item.new('samplelist', 1)
789
1166
  end
790
1167
 
791
1168
  @book.config['highlight'] = false
@@ -815,7 +1192,7 @@ EOS
815
1192
 
816
1193
  def test_listnum_pygments_lang
817
1194
  def @chapter.list(_id)
818
- Book::ListIndex::Item.new('samplelist', 1)
1195
+ Book::Index::Item.new('samplelist', 1)
819
1196
  end
820
1197
  begin
821
1198
  require 'pygments'
@@ -842,7 +1219,7 @@ EOS
842
1219
 
843
1220
  def test_listnum_pygments_lang_linenum
844
1221
  def @chapter.list(_id)
845
- Book::ListIndex::Item.new('samplelist', 1)
1222
+ Book::Index::Item.new('samplelist', 1)
846
1223
  end
847
1224
  begin
848
1225
  require 'pygments'
@@ -870,7 +1247,7 @@ EOS
870
1247
 
871
1248
  def test_listnum_pygments_lang_without_lang
872
1249
  def @chapter.list(_id)
873
- Book::ListIndex::Item.new('samplelist', 1)
1250
+ Book::Index::Item.new('samplelist', 1)
874
1251
  end
875
1252
  begin
876
1253
  require 'pygments'
@@ -904,7 +1281,7 @@ EOS
904
1281
  return true
905
1282
  end
906
1283
  def @chapter.list(_id)
907
- Book::ListIndex::Item.new('samplelist', 1)
1284
+ Book::Index::Item.new('samplelist', 1)
908
1285
  end
909
1286
  @book.config['highlight'] = {}
910
1287
  @book.config['highlight']['html'] = 'rouge'
@@ -938,7 +1315,7 @@ EOS
938
1315
  return true
939
1316
  end
940
1317
  def @chapter.list(_id)
941
- Book::ListIndex::Item.new('samplelist', 1)
1318
+ Book::Index::Item.new('samplelist', 1)
942
1319
  end
943
1320
  @book.config['highlight'] = {}
944
1321
  @book.config['highlight']['html'] = 'rouge'
@@ -964,15 +1341,100 @@ EOB
964
1341
  assert_equal expected, actual
965
1342
  end
966
1343
 
967
- def test_emlist
968
- actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
969
- assert_equal %Q(<div class="emlist-code">\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n), actual
970
- end
1344
+ def test_source
1345
+ actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
1346
+ expected = <<-EOS
1347
+ <div class="source-code">
1348
+ <p class="caption">foo/bar/test.rb</p>
1349
+ <pre class="source">foo
1350
+ bar
971
1351
 
972
- def test_emlist_pygments_lang
973
- begin
974
- require 'pygments'
975
- rescue LoadError
1352
+ buz
1353
+ </pre>
1354
+ </div>
1355
+ EOS
1356
+ assert_equal expected, actual
1357
+
1358
+ @config['caption_position']['list'] = 'bottom'
1359
+ actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
1360
+ expected = <<-EOS
1361
+ <div class="source-code">
1362
+ <pre class="source">foo
1363
+ bar
1364
+
1365
+ buz
1366
+ </pre>
1367
+ <p class="caption">foo/bar/test.rb</p>
1368
+ </div>
1369
+ EOS
1370
+ assert_equal expected, actual
1371
+ end
1372
+
1373
+ def test_source_empty_caption
1374
+ actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n")
1375
+ expected = <<-EOS
1376
+ <div class="source-code">
1377
+ <pre class="source">foo
1378
+ bar
1379
+
1380
+ buz
1381
+ </pre>
1382
+ </div>
1383
+ EOS
1384
+ assert_equal expected, actual
1385
+ end
1386
+
1387
+ def test_box
1388
+ actual = compile_block("//box{\nfoo\nbar\n//}\n")
1389
+ expected = <<-EOS
1390
+ <div class="syntax">
1391
+ <pre class="syntax">foo
1392
+ bar
1393
+ </pre>
1394
+ </div>
1395
+ EOS
1396
+ assert_equal expected, actual
1397
+
1398
+ actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
1399
+ expected = <<-EOS
1400
+ <div class="syntax">
1401
+ <p class="caption">FOO</p>
1402
+ <pre class="syntax">foo
1403
+ bar
1404
+ </pre>
1405
+ </div>
1406
+ EOS
1407
+ assert_equal expected, actual
1408
+
1409
+ @config['caption_position']['list'] = 'bottom'
1410
+ actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
1411
+ expected = <<-EOS
1412
+ <div class="syntax">
1413
+ <pre class="syntax">foo
1414
+ bar
1415
+ </pre>
1416
+ <p class="caption">FOO</p>
1417
+ </div>
1418
+ EOS
1419
+ assert_equal expected, actual
1420
+ end
1421
+
1422
+ def test_emlist
1423
+ actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
1424
+ expected = <<-EOS
1425
+ <div class="emlist-code">
1426
+ <pre class="emlist">lineA
1427
+ lineB
1428
+ </pre>
1429
+ </div>
1430
+ EOS
1431
+ assert_equal expected, actual
1432
+ end
1433
+
1434
+ def test_emlist_pygments_lang
1435
+ begin
1436
+ require 'pygments'
1437
+ rescue LoadError
976
1438
  $stderr.puts 'skip test_emlist_pygments_lang (cannot find pygments.rb)'
977
1439
  return true
978
1440
  end
@@ -990,12 +1452,40 @@ EOB
990
1452
 
991
1453
  def test_emlist_caption
992
1454
  actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
993
- assert_equal %Q(<div class="emlist-code">\n<p class="caption">cap1</p>\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n), actual
1455
+ expected = <<-EOS
1456
+ <div class="emlist-code">
1457
+ <p class="caption">cap1</p>
1458
+ <pre class="emlist">lineA
1459
+ lineB
1460
+ </pre>
1461
+ </div>
1462
+ EOS
1463
+ assert_equal expected, actual
1464
+
1465
+ @config['caption_position']['list'] = 'bottom'
1466
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
1467
+ expected = <<-EOS
1468
+ <div class="emlist-code">
1469
+ <pre class="emlist">lineA
1470
+ lineB
1471
+ </pre>
1472
+ <p class="caption">cap1</p>
1473
+ </div>
1474
+ EOS
1475
+ assert_equal expected, actual
994
1476
  end
995
1477
 
996
1478
  def test_emlist_with_tab
997
1479
  actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
998
- assert_equal %Q(<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n), actual
1480
+ expected = <<-EOS
1481
+ <div class="emlist-code">
1482
+ <pre class="emlist"> lineA
1483
+ lineB
1484
+ lineC
1485
+ </pre>
1486
+ </div>
1487
+ EOS
1488
+ assert_equal expected, actual
999
1489
  end
1000
1490
 
1001
1491
  def test_emlistnum
@@ -1021,6 +1511,18 @@ EOS
1021
1511
  2: lineB
1022
1512
  </pre>
1023
1513
  </div>
1514
+ EOS
1515
+ assert_equal expected, actual
1516
+
1517
+ @config['caption_position']['list'] = 'bottom'
1518
+ actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
1519
+ expected = <<-EOS
1520
+ <div class="emlistnum-code">
1521
+ <pre class="emlist language-text"> 1: lineA
1522
+ 2: lineB
1523
+ </pre>
1524
+ <p class="caption">cap</p>
1525
+ </div>
1024
1526
  EOS
1025
1527
  assert_equal expected, actual
1026
1528
  end
@@ -1042,12 +1544,27 @@ EOS
1042
1544
  def test_emlist_with_4tab
1043
1545
  @config['tabwidth'] = 4
1044
1546
  actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
1045
- assert_equal %Q(<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n), actual
1547
+ expected = <<-EOS
1548
+ <div class="emlist-code">
1549
+ <pre class="emlist"> lineA
1550
+ lineB
1551
+ lineC
1552
+ </pre>
1553
+ </div>
1554
+ EOS
1555
+ assert_equal expected, actual
1046
1556
  end
1047
1557
 
1048
1558
  def test_cmd
1049
1559
  actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
1050
- assert_equal %Q(<div class="cmd-code">\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n), actual
1560
+ expected = <<-EOS
1561
+ <div class="cmd-code">
1562
+ <pre class="cmd">lineA
1563
+ lineB
1564
+ </pre>
1565
+ </div>
1566
+ EOS
1567
+ assert_equal expected, actual
1051
1568
  end
1052
1569
 
1053
1570
  def test_cmd_pygments
@@ -1059,12 +1576,39 @@ EOS
1059
1576
  @book.config['highlight'] = {}
1060
1577
  @book.config['highlight']['html'] = 'pygments'
1061
1578
  actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
1062
- assert_equal %Q(<div class="cmd-code">\n<pre class="cmd"><span style="color: #888888">lineA</span>\n<span style="color: #888888">lineB</span>\n</pre>\n</div>\n), actual
1579
+ expected = <<-EOS
1580
+ <div class="cmd-code">
1581
+ <pre class="cmd"><span style="color: #888888">lineA</span>
1582
+ <span style="color: #888888">lineB</span>
1583
+ </pre>
1584
+ </div>
1585
+ EOS
1586
+ assert_equal expected, actual
1063
1587
  end
1064
1588
 
1065
1589
  def test_cmd_caption
1066
1590
  actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
1067
- assert_equal %Q(<div class="cmd-code">\n<p class="caption">cap1</p>\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n), actual
1591
+ expected = <<-EOS
1592
+ <div class="cmd-code">
1593
+ <p class="caption">cap1</p>
1594
+ <pre class="cmd">lineA
1595
+ lineB
1596
+ </pre>
1597
+ </div>
1598
+ EOS
1599
+ assert_equal expected, actual
1600
+
1601
+ @config['caption_position']['list'] = 'bottom'
1602
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
1603
+ expected = <<-EOS
1604
+ <div class="cmd-code">
1605
+ <pre class="cmd">lineA
1606
+ lineB
1607
+ </pre>
1608
+ <p class="caption">cap1</p>
1609
+ </div>
1610
+ EOS
1611
+ assert_equal expected, actual
1068
1612
  end
1069
1613
 
1070
1614
  def test_texequation
@@ -1124,7 +1668,7 @@ EOS
1124
1668
 
1125
1669
  def test_bib
1126
1670
  def @chapter.bibpaper(_id)
1127
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1671
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1128
1672
  end
1129
1673
 
1130
1674
  assert_equal %Q(<a href="bib.html#bib-samplebib">[1]</a>), compile_inline('@<bib>{samplebib}')
@@ -1132,7 +1676,7 @@ EOS
1132
1676
 
1133
1677
  def test_bib_noramlized
1134
1678
  def @chapter.bibpaper(_id)
1135
- Book::BibpaperIndex::Item.new('sampleb=ib', 1, 'sample bib')
1679
+ Book::Index::Item.new('sampleb=ib', 1, 'sample bib')
1136
1680
  end
1137
1681
 
1138
1682
  assert_equal %Q(<a href="bib.html#bib-id_sample_3Dbib">[1]</a>), compile_inline('@<bib>{sample=bib}')
@@ -1140,7 +1684,7 @@ EOS
1140
1684
 
1141
1685
  def test_bib_htmlext
1142
1686
  def @chapter.bibpaper(_id)
1143
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1687
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1144
1688
  end
1145
1689
 
1146
1690
  @config['htmlext'] = 'xhtml'
@@ -1149,29 +1693,71 @@ EOS
1149
1693
 
1150
1694
  def test_bibpaper
1151
1695
  def @chapter.bibpaper(_id)
1152
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1696
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1153
1697
  end
1154
1698
 
1155
1699
  actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1156
- assert_equal %Q(<div class="bibpaper">\n<a id="bib-samplebib">[1]</a> sample bib <b>bold</b>\n<p>ab</p></div>\n), actual
1700
+ expected = <<-EOS
1701
+ <div class="bibpaper">
1702
+ <a id="bib-samplebib">[1]</a> sample bib <b>bold</b>
1703
+ <p>ab</p></div>
1704
+ EOS
1705
+ assert_equal expected, actual
1706
+
1707
+ @book.config['join_lines_by_lang'] = true
1708
+ actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1709
+ expected = <<-EOS
1710
+ <div class="bibpaper">
1711
+ <a id="bib-samplebib">[1]</a> sample bib <b>bold</b>
1712
+ <p>a b</p></div>
1713
+ EOS
1714
+ assert_equal expected, actual
1157
1715
  end
1158
1716
 
1159
1717
  def test_bibpaper_normalized
1160
1718
  def @chapter.bibpaper(_id)
1161
- Book::BibpaperIndex::Item.new('sample=bib', 1, 'sample bib')
1719
+ Book::Index::Item.new('sample=bib', 1, 'sample bib')
1162
1720
  end
1163
1721
 
1164
1722
  actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1165
- assert_equal %Q(<div class="bibpaper">\n<a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>\n<p>ab</p></div>\n), actual
1723
+ expected = <<-EOS
1724
+ <div class="bibpaper">
1725
+ <a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>
1726
+ <p>ab</p></div>
1727
+ EOS
1728
+ assert_equal expected, actual
1729
+
1730
+ @book.config['join_lines_by_lang'] = true
1731
+ actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1732
+ expected = <<-EOS
1733
+ <div class="bibpaper">
1734
+ <a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>
1735
+ <p>a b</p></div>
1736
+ EOS
1737
+ assert_equal expected, actual
1166
1738
  end
1167
1739
 
1168
1740
  def test_bibpaper_with_anchor
1169
1741
  def @chapter.bibpaper(_id)
1170
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1742
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1171
1743
  end
1172
1744
 
1173
1745
  actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
1174
- assert_equal %Q(<div class="bibpaper">\n<a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>\n<p>ab</p></div>\n), actual
1746
+ expected = <<-EOS
1747
+ <div class="bibpaper">
1748
+ <a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>
1749
+ <p>ab</p></div>
1750
+ EOS
1751
+ assert_equal expected, actual
1752
+
1753
+ @book.config['join_lines_by_lang'] = true
1754
+ actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
1755
+ expected = <<-EOS
1756
+ <div class="bibpaper">
1757
+ <a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>
1758
+ <p>a b</p></div>
1759
+ EOS
1760
+ assert_equal expected, actual
1175
1761
  end
1176
1762
 
1177
1763
  def column_helper(review)
@@ -1256,6 +1842,20 @@ EOS
1256
1842
  <p>inside column</p>
1257
1843
  </div>
1258
1844
 
1845
+ <h3><a id="h1-0-1"></a>next level</h3>
1846
+ <p>this is <a href="-.html#column-1" class="columnref">コラム「test」</a>.</p>
1847
+ EOS
1848
+
1849
+ assert_equal expected, column_helper(review)
1850
+
1851
+ @config['chapterlink'] = nil
1852
+ expected = <<-EOS
1853
+ <div class="column">
1854
+
1855
+ <h3 id="foo"><a id="column-1"></a>test</h3>
1856
+ <p>inside column</p>
1857
+ </div>
1858
+
1259
1859
  <h3><a id="h1-0-1"></a>next level</h3>
1260
1860
  <p>this is コラム「test」.</p>
1261
1861
  EOS
@@ -1265,10 +1865,17 @@ EOS
1265
1865
 
1266
1866
  def test_column_in_aother_chapter_ref
1267
1867
  def @chapter.column_index
1268
- items = [Book::ColumnIndex::Item.new('chap1|column', 1, 'column_cap')]
1269
- Book::ColumnIndex.new(items)
1868
+ item = Book::Index::Item.new('chap1|column', 1, 'column_cap')
1869
+ idx = Book::ColumnIndex.new
1870
+ idx.add_item(item)
1871
+ idx
1270
1872
  end
1271
1873
 
1874
+ actual = compile_inline('test @<column>{chap1|column} test2')
1875
+ expected = 'test <a href="-.html#column-1" class="columnref">コラム「column_cap」</a> test2'
1876
+ assert_equal expected, actual
1877
+
1878
+ @config['chapterlink'] = nil
1272
1879
  actual = compile_inline('test @<column>{chap1|column} test2')
1273
1880
  expected = 'test コラム「column_cap」 test2'
1274
1881
  assert_equal expected, actual
@@ -1279,7 +1886,12 @@ EOS
1279
1886
  * AAA
1280
1887
  * BBB
1281
1888
  EOS
1282
- expected = "<ul>\n<li>AAA</li>\n<li>BBB</li>\n</ul>\n"
1889
+ expected = <<-EOS
1890
+ <ul>
1891
+ <li>AAA</li>
1892
+ <li>BBB</li>
1893
+ </ul>
1894
+ EOS
1283
1895
  actual = compile_block(src)
1284
1896
  assert_equal expected, actual
1285
1897
  end
@@ -1291,7 +1903,22 @@ EOS
1291
1903
  * BBB
1292
1904
  -BB
1293
1905
  EOS
1294
- expected = "<ul>\n<li>AAA-AA</li>\n<li>BBB-BB</li>\n</ul>\n"
1906
+ expected = <<-EOS
1907
+ <ul>
1908
+ <li>AAA-AA</li>
1909
+ <li>BBB-BB</li>
1910
+ </ul>
1911
+ EOS
1912
+ actual = compile_block(src)
1913
+ assert_equal expected, actual
1914
+
1915
+ @book.config['join_lines_by_lang'] = true
1916
+ expected = <<-EOS
1917
+ <ul>
1918
+ <li>AAA -AA</li>
1919
+ <li>BBB -BB</li>
1920
+ </ul>
1921
+ EOS
1295
1922
  actual = compile_block(src)
1296
1923
  assert_equal expected, actual
1297
1924
  end
@@ -1342,25 +1969,10 @@ EOS
1342
1969
  src = <<-EOS
1343
1970
  ** AAA
1344
1971
  * AA
1345
- * BBB
1346
- ** BB
1347
1972
  EOS
1348
1973
 
1349
- expected = <<-EOS
1350
- <ul>
1351
- <li><ul>
1352
- <li>AAA</li>
1353
- </ul>
1354
- </li>
1355
- <li>AA</li>
1356
- <li>BBB<ul>
1357
- <li>BB</li>
1358
- </ul>
1359
- </li>
1360
- </ul>
1361
- EOS
1362
- actual = compile_block(src)
1363
- assert_equal expected, actual
1974
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1975
+ assert_equal ':1: error: too many *.', e.message
1364
1976
  end
1365
1977
 
1366
1978
  def test_ul_nest4
@@ -1391,37 +2003,6 @@ EOS
1391
2003
  assert_equal expected, actual
1392
2004
  end
1393
2005
 
1394
- def test_ul_nest5
1395
- src = <<-EOS
1396
- * A
1397
- ** AA
1398
- **** AAAA
1399
- * B
1400
- ** BB
1401
- EOS
1402
-
1403
- expected = <<-EOS
1404
- <ul>
1405
- <li>A<ul>
1406
- <li>AA<ul>
1407
- <li><ul>
1408
- <li>AAAA</li>
1409
- </ul>
1410
- </li>
1411
- </ul>
1412
- </li>
1413
- </ul>
1414
- </li>
1415
- <li>B<ul>
1416
- <li>BB</li>
1417
- </ul>
1418
- </li>
1419
- </ul>
1420
- EOS
1421
- actual = compile_block(src)
1422
- assert_equal expected, actual
1423
- end
1424
-
1425
2006
  def test_ol
1426
2007
  src = <<-EOS
1427
2008
  3. AAA
@@ -1592,8 +2173,6 @@ EOS
1592
2173
  end
1593
2174
 
1594
2175
  def test_footnote
1595
- fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
1596
- @chapter.instance_eval { @footnote_index = fn }
1597
2176
  actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
1598
2177
  expected = <<-'EOS'
1599
2178
  <div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote">[*1] bar\a\$buz</p></div>
@@ -1618,58 +2197,69 @@ EOS
1618
2197
  end
1619
2198
 
1620
2199
  def test_footnote_with_tricky_id
1621
- fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
1622
- @chapter.instance_eval { @footnote_index = fn }
1623
- actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
2200
+ actual = compile_block("//footnote[123あ_;][bar\\a\\$buz]\n")
1624
2201
  expected = <<-'EOS'
1625
- <div class="footnote" epub:type="footnote" id="fn-id_123-_E3_81_82___3B"><p class="footnote">[*1] bar\a\$buz</p></div>
2202
+ <div class="footnote" epub:type="footnote" id="fn-id_123_E3_81_82___3B"><p class="footnote">[*1] bar\a\$buz</p></div>
1626
2203
  EOS
1627
2204
  assert_equal expected, actual
1628
2205
  end
1629
2206
 
1630
2207
  def test_inline_fn
1631
- book = ReVIEW::Book::Base.load
1632
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re])
1633
- io1 = StringIO.new("//footnote[foo][bar]\n")
1634
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1635
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1])]
1636
- builder = ReVIEW::HTMLBuilder.new
1637
- comp = ReVIEW::Compiler.new(builder)
1638
- builder.bind(comp, chap1, nil)
1639
- fn = builder.inline_fn('foo')
1640
- assert_equal '<a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">*1</a>', fn
2208
+ fn = compile_block("//footnote[foo][bar]\n\n@<fn>{foo}\n")
2209
+ expected = <<-EOS
2210
+ <div class=\"footnote\" epub:type=\"footnote\" id=\"fn-foo\"><p class=\"footnote\">[*1] bar</p></div>
2211
+ <p><a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">*1</a></p>
2212
+ EOS
2213
+ assert_equal expected, fn
1641
2214
  I18n.set('html_footnote_refmark', '+%s')
1642
- fn = builder.inline_fn('foo')
1643
- assert_equal '<a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">+1</a>', fn
2215
+ fn = compile_block("//footnote[foo][bar]\n\n@<fn>{foo}\n")
2216
+ expected = <<-EOS
2217
+ <div class=\"footnote\" epub:type=\"footnote\" id=\"fn-foo\"><p class=\"footnote\">[*1] bar</p></div>
2218
+ <p><a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">+1</a></p>
2219
+ EOS
2220
+ assert_equal expected, fn
1644
2221
  end
1645
2222
 
1646
2223
  def test_inline_hd
1647
- book = ReVIEW::Book::Base.load
2224
+ book = ReVIEW::Book::Base.new
1648
2225
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
1649
2226
  io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
1650
2227
  io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
1651
2228
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1652
2229
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
1653
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
2230
+ book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
1654
2231
  builder = ReVIEW::HTMLBuilder.new
1655
2232
  comp = ReVIEW::Compiler.new(builder)
1656
2233
  builder.bind(comp, chap2, nil)
2234
+
2235
+ chap1.generate_indexes
2236
+ chap2.generate_indexes
2237
+ hd = builder.inline_hd('ch1|test1-1')
2238
+ assert_equal '<a href="ch1.html#h1-1">「1.1 test1-1」</a>', hd
2239
+
2240
+ builder.instance_eval { @book.config['chapterlink'] = nil }
1657
2241
  hd = builder.inline_hd('ch1|test1-1')
1658
2242
  assert_equal '「1.1 test1-1」', hd
1659
2243
  end
1660
2244
 
1661
2245
  def test_inline_hd_for_part
1662
- book = ReVIEW::Book::Base.load
2246
+ book = ReVIEW::Book::Base.new
1663
2247
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
1664
2248
  io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
1665
2249
  io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
1666
2250
  io_p1 = StringIO.new("= part1\n\nfoo\n\n== part1-1\n\nbar\n\n== part1-2\n\nbar\n\n")
1667
2251
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1668
2252
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
1669
- book.parts = [ReVIEW::Book::Part.new(self, 1, [chap1, chap2], 'part1.re', io_p1)]
2253
+ book.parts = [ReVIEW::Book::Part.new(book, 1, [chap1, chap2], 'part1.re', io_p1)]
1670
2254
  builder = ReVIEW::HTMLBuilder.new
1671
2255
  comp = ReVIEW::Compiler.new(builder)
1672
2256
  builder.bind(comp, chap2, nil)
2257
+ book.generate_indexes
2258
+
2259
+ hd = builder.inline_hd('part1|part1-1')
2260
+ assert_equal '<a href="part1.html#h1-1">「1.1 part1-1」</a>', hd
2261
+
2262
+ builder.instance_eval { @book.config['chapterlink'] = nil }
1673
2263
  hd = builder.inline_hd('part1|part1-1')
1674
2264
  assert_equal '「1.1 part1-1」', hd
1675
2265
  end
@@ -1680,77 +2270,453 @@ EOS
1680
2270
  location = Location.new(nil, nil)
1681
2271
  @builder.bind(@compiler, chap1, location)
1682
2272
  hd = @builder.inline_hd('foo')
2273
+ assert_equal '<a href="-.html#h1-1">「1.1 foo」</a>', hd
2274
+
2275
+ @config['chapterlink'] = nil
2276
+ hd = @builder.inline_hd('foo')
1683
2277
  assert_equal '「1.1 foo」', hd
2278
+
1684
2279
  hd = @builder.inline_hd('bar')
1685
2280
  assert_equal '「1.2 bar」', hd
1686
2281
  end
1687
2282
 
1688
2283
  def test_table
1689
2284
  actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1690
- assert_equal %Q(<div class="table">\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n),
1691
- actual
2285
+ expected = <<-EOS
2286
+ <div class="table">
2287
+ <table>
2288
+ <tr><th>aaa</th><th>bbb</th></tr>
2289
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2290
+ </table>
2291
+ </div>
2292
+ EOS
2293
+ assert_equal expected, actual
2294
+
2295
+ actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2296
+ expected = <<-EOS
2297
+ <div id="foo" class="table">
2298
+ <p class="caption">表1.1: FOO</p>
2299
+ <table>
2300
+ <tr><th>aaa</th><th>bbb</th></tr>
2301
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2302
+ </table>
2303
+ </div>
2304
+ EOS
2305
+ assert_equal expected, actual
2306
+
2307
+ @config['caption_position']['table'] = 'bottom'
2308
+ actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2309
+ expected = <<-EOS
2310
+ <div id="foo" class="table">
2311
+ <table>
2312
+ <tr><th>aaa</th><th>bbb</th></tr>
2313
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2314
+ </table>
2315
+ <p class="caption">表1.1: FOO</p>
2316
+ </div>
2317
+ EOS
2318
+ assert_equal expected, actual
2319
+ end
2320
+
2321
+ def test_empty_table
2322
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
2323
+ assert_equal ':2: error: no rows in the table', e.message
2324
+
2325
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
2326
+ assert_equal ':3: error: no rows in the table', e.message
1692
2327
  end
1693
2328
 
1694
2329
  def test_inline_table
1695
2330
  def @chapter.table(_id)
1696
- Book::TableIndex::Item.new('sampletable', 1)
2331
+ Book::Index::Item.new('sampletable', 1)
1697
2332
  end
1698
2333
  actual = compile_block("@<table>{sampletest}\n")
2334
+ assert_equal %Q(<p><span class="tableref"><a href="./-.html#sampletest">表1.1</a></span></p>\n), actual
2335
+
2336
+ @config['chapterlink'] = nil
2337
+ actual = compile_block("@<table>{sampletest}\n")
1699
2338
  assert_equal %Q(<p><span class="tableref">表1.1</span></p>\n), actual
1700
2339
  end
1701
2340
 
1702
2341
  def test_emtable
1703
2342
  actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1704
- assert_equal %Q(<div class="table">\n<p class="caption">foo</p>\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n<div class="table">\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n),
1705
- actual
1706
- end
2343
+ expected = <<-EOS
2344
+ <div class="table">
2345
+ <p class="caption">foo</p>
2346
+ <table>
2347
+ <tr><th>aaa</th><th>bbb</th></tr>
2348
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2349
+ </table>
2350
+ </div>
2351
+ <div class="table">
2352
+ <table>
2353
+ <tr><th>aaa</th><th>bbb</th></tr>
2354
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2355
+ </table>
2356
+ </div>
2357
+ EOS
2358
+ assert_equal expected, actual
1707
2359
 
1708
- def test_imgtable
1709
- def @chapter.image(_id)
1710
- item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample img')
1711
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
2360
+ @config['caption_position']['table'] = 'bottom'
2361
+ actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2362
+ expected = <<-EOS
2363
+ <div class="table">
2364
+ <table>
2365
+ <tr><th>aaa</th><th>bbb</th></tr>
2366
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2367
+ </table>
2368
+ <p class="caption">foo</p>
2369
+ </div>
2370
+ <div class="table">
2371
+ <table>
2372
+ <tr><th>aaa</th><th>bbb</th></tr>
2373
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2374
+ </table>
2375
+ </div>
2376
+ EOS
2377
+ assert_equal expected, actual
2378
+ end
2379
+
2380
+ def test_imgtable
2381
+ def @chapter.image(_id)
2382
+ item = Book::Index::Item.new('sampleimg', 1, 'sample img')
2383
+ item.instance_eval { @path = './images/chap1-sampleimg.png' }
1712
2384
  item
1713
2385
  end
1714
2386
 
1715
2387
  actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
1716
- expected = %Q(<div id="sampleimg" class="imgtable image">\n<p class="caption">表1.1: test for imgtable</p>\n<img src="images/chap1-sampleimg.png" alt="test for imgtable" />\n</div>\n)
2388
+ expected = <<-EOS
2389
+ <div id="sampleimg" class="imgtable image">
2390
+ <p class="caption">表1.1: test for imgtable</p>
2391
+ <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2392
+ </div>
2393
+ EOS
2394
+ assert_equal expected, actual
2395
+
2396
+ @config['caption_position']['table'] = 'bottom'
2397
+ actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
2398
+ expected = <<-EOS
2399
+ <div id="sampleimg" class="imgtable image">
2400
+ <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2401
+ <p class="caption">表1.1: test for imgtable</p>
2402
+ </div>
2403
+ EOS
2404
+ assert_equal expected, actual
2405
+ end
2406
+
2407
+ def test_table_row_separator
2408
+ src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n"
2409
+ expected = <<-EOS
2410
+ <div class="table">
2411
+ <table>
2412
+ <tr><th>1</th><th>2</th><th>3 4| 5</th></tr>
2413
+ <tr><td>a b</td><td>c d |e</td><td></td></tr>
2414
+ </table>
2415
+ </div>
2416
+ EOS
2417
+ actual = compile_block(src)
2418
+ assert_equal expected, actual
2419
+
2420
+ @config['table_row_separator'] = 'singletab'
2421
+ actual = compile_block(src)
2422
+ expected = <<-EOS
2423
+ <div class="table">
2424
+ <table>
2425
+ <tr><th>1</th><th>2</th><th></th><th>3 4| 5</th></tr>
2426
+ <tr><td>a b</td><td>c d |e</td><td></td><td></td></tr>
2427
+ </table>
2428
+ </div>
2429
+ EOS
2430
+ assert_equal expected, actual
2431
+
2432
+ @config['table_row_separator'] = 'spaces'
2433
+ actual = compile_block(src)
2434
+ expected = <<-EOS
2435
+ <div class="table">
2436
+ <table>
2437
+ <tr><th>1</th><th>2</th><th>3</th><th>4|</th><th>5</th></tr>
2438
+ <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>|e</td></tr>
2439
+ </table>
2440
+ </div>
2441
+ EOS
2442
+ assert_equal expected, actual
2443
+
2444
+ @config['table_row_separator'] = 'verticalbar'
2445
+ actual = compile_block(src)
2446
+ expected = <<-EOS
2447
+ <div class="table">
2448
+ <table>
2449
+ <tr><th>1 2 3 4</th><th>5</th></tr>
2450
+ <tr><td>a b c d</td><td>e</td></tr>
2451
+ </table>
2452
+ </div>
2453
+ EOS
1717
2454
  assert_equal expected, actual
1718
2455
  end
1719
2456
 
1720
2457
  def test_major_blocks
1721
2458
  actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
1722
- expected = %Q(<div class="note">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="note">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2459
+ expected = <<-EOS
2460
+ <div class="note">
2461
+ <p>A</p>
2462
+ <p>B</p>
2463
+ </div>
2464
+ <div class="note">
2465
+ <p class="caption">caption</p>
2466
+ <p>A</p>
2467
+ </div>
2468
+ EOS
1723
2469
  assert_equal expected, actual
1724
2470
 
1725
2471
  actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
1726
- expected = %Q(<div class="memo">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="memo">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2472
+ expected = <<-EOS
2473
+ <div class="memo">
2474
+ <p>A</p>
2475
+ <p>B</p>
2476
+ </div>
2477
+ <div class="memo">
2478
+ <p class="caption">caption</p>
2479
+ <p>A</p>
2480
+ </div>
2481
+ EOS
1727
2482
  assert_equal expected, actual
1728
2483
 
1729
2484
  actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
1730
- expected = %Q(<div class="info">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="info">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2485
+ expected = <<-EOS
2486
+ <div class="info">
2487
+ <p>A</p>
2488
+ <p>B</p>
2489
+ </div>
2490
+ <div class="info">
2491
+ <p class="caption">caption</p>
2492
+ <p>A</p>
2493
+ </div>
2494
+ EOS
1731
2495
  assert_equal expected, actual
1732
2496
 
1733
2497
  actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
1734
- expected = %Q(<div class="important">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="important">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2498
+ expected = <<-EOS
2499
+ <div class="important">
2500
+ <p>A</p>
2501
+ <p>B</p>
2502
+ </div>
2503
+ <div class="important">
2504
+ <p class="caption">caption</p>
2505
+ <p>A</p>
2506
+ </div>
2507
+ EOS
1735
2508
  assert_equal expected, actual
1736
2509
 
1737
2510
  actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
1738
- expected = %Q(<div class="caution">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="caution">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2511
+ expected = <<-EOS
2512
+ <div class="caution">
2513
+ <p>A</p>
2514
+ <p>B</p>
2515
+ </div>
2516
+ <div class="caution">
2517
+ <p class="caption">caption</p>
2518
+ <p>A</p>
2519
+ </div>
2520
+ EOS
1739
2521
  assert_equal expected, actual
1740
2522
 
1741
2523
  actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
1742
- expected = %Q(<div class="notice">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="notice">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2524
+ expected = <<-EOS
2525
+ <div class="notice">
2526
+ <p>A</p>
2527
+ <p>B</p>
2528
+ </div>
2529
+ <div class="notice">
2530
+ <p class="caption">caption</p>
2531
+ <p>A</p>
2532
+ </div>
2533
+ EOS
1743
2534
  assert_equal expected, actual
1744
2535
 
1745
2536
  actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
1746
- expected = %Q(<div class="warning">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="warning">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2537
+ expected = <<-EOS
2538
+ <div class="warning">
2539
+ <p>A</p>
2540
+ <p>B</p>
2541
+ </div>
2542
+ <div class="warning">
2543
+ <p class="caption">caption</p>
2544
+ <p>A</p>
2545
+ </div>
2546
+ EOS
1747
2547
  assert_equal expected, actual
1748
2548
 
1749
2549
  actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
1750
- expected = %Q(<div class="tip">\n<p>A</p>\n<p>B</p>\n</div>\n<div class="tip">\n<p class="caption">caption</p>\n<p>A</p>\n</div>\n)
2550
+ expected = <<-EOS
2551
+ <div class="tip">
2552
+ <p>A</p>
2553
+ <p>B</p>
2554
+ </div>
2555
+ <div class="tip">
2556
+ <p class="caption">caption</p>
2557
+ <p>A</p>
2558
+ </div>
2559
+ EOS
1751
2560
  assert_equal expected, actual
1752
2561
  end
1753
2562
 
2563
+ def test_minicolumn_blocks
2564
+ %w[note memo tip info warning important caution notice].each do |type|
2565
+ src = <<-EOS
2566
+ //#{type}[#{type}1]{
2567
+
2568
+ //}
2569
+
2570
+ //#{type}[#{type}2]{
2571
+ //}
2572
+ EOS
2573
+
2574
+ expected = <<-EOS
2575
+ <div class="#{type}">
2576
+ <p class="caption">#{type}1</p>
2577
+ </div>
2578
+ <div class="#{type}">
2579
+ <p class="caption">#{type}2</p>
2580
+ </div>
2581
+ EOS
2582
+ assert_equal expected, compile_block(src)
2583
+
2584
+ src = <<-EOS
2585
+ //#{type}[#{type}2]{
2586
+
2587
+ //}
2588
+
2589
+ //#{type}[#{type}3]{
2590
+
2591
+ //}
2592
+
2593
+ //#{type}[#{type}4]{
2594
+
2595
+ //}
2596
+
2597
+ //#{type}[#{type}5]{
2598
+
2599
+ //}
2600
+
2601
+ //#{type}[#{type}6]{
2602
+
2603
+ //}
2604
+ EOS
2605
+
2606
+ expected = <<-EOS
2607
+ <div class="#{type}">
2608
+ <p class="caption">#{type}2</p>
2609
+ </div>
2610
+ <div class="#{type}">
2611
+ <p class="caption">#{type}3</p>
2612
+ </div>
2613
+ <div class="#{type}">
2614
+ <p class="caption">#{type}4</p>
2615
+ </div>
2616
+ <div class="#{type}">
2617
+ <p class="caption">#{type}5</p>
2618
+ </div>
2619
+ <div class="#{type}">
2620
+ <p class="caption">#{type}6</p>
2621
+ </div>
2622
+ EOS
2623
+ assert_equal expected, compile_block(src)
2624
+
2625
+ src = <<-EOS
2626
+ //#{type}{
2627
+
2628
+ * A
2629
+
2630
+ 1. B
2631
+
2632
+ //}
2633
+
2634
+ //#{type}[OMITEND1]{
2635
+
2636
+ //emlist{
2637
+ LIST
2638
+ //}
2639
+
2640
+ //}
2641
+
2642
+ //#{type}[OMITEND2]{
2643
+ //}
2644
+ EOS
2645
+
2646
+ expected = <<-EOS
2647
+ <div class="#{type}">
2648
+ <ul>
2649
+ <li>A</li>
2650
+ </ul>
2651
+ <ol>
2652
+ <li>B</li>
2653
+ </ol>
2654
+ </div>
2655
+ <div class="#{type}">
2656
+ <p class="caption">OMITEND1</p>
2657
+ <div class="emlist-code">
2658
+ <pre class="emlist">LIST
2659
+ </pre>
2660
+ </div>
2661
+ </div>
2662
+ <div class="#{type}">
2663
+ <p class="caption">OMITEND2</p>
2664
+ </div>
2665
+ EOS
2666
+ assert_equal expected, compile_block(src)
2667
+ end
2668
+ end
2669
+
2670
+ def test_minicolumn_blocks_nest_error1
2671
+ %w[note memo tip info warning important caution notice].each do |type|
2672
+ @builder.doc_status.clear
2673
+ src = <<-EOS
2674
+ //#{type}{
2675
+
2676
+ //#{type}{
2677
+ //}
2678
+
2679
+ //}
2680
+ EOS
2681
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2682
+ assert_match(/minicolumn cannot be nested:/, e.message)
2683
+ end
2684
+ end
2685
+
2686
+ def test_minicolumn_blocks_nest_error2
2687
+ %w[note memo tip info warning important caution notice].each do |type|
2688
+ @builder.doc_status.clear
2689
+ src = <<-EOS
2690
+ //#{type}{
2691
+
2692
+ //#{type}{
2693
+
2694
+ //}
2695
+
2696
+ //}
2697
+ EOS
2698
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2699
+ assert_match(/minicolumn cannot be nested:/, e.message)
2700
+ end
2701
+ end
2702
+
2703
+ def test_minicolumn_blocks_nest_error3
2704
+ %w[memo tip info warning important caution notice].each do |type|
2705
+ @builder.doc_status.clear
2706
+ src = <<-EOS
2707
+ //#{type}{
2708
+
2709
+ //note{
2710
+
2711
+ //}
2712
+
2713
+ //}
2714
+ EOS
2715
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2716
+ assert_match(/minicolumn cannot be nested:/, e.message)
2717
+ end
2718
+ end
2719
+
1754
2720
  def test_comment
1755
2721
  actual = compile_block('//comment[コメント]')
1756
2722
  assert_equal '', actual
@@ -1793,23 +2759,23 @@ EOB
1793
2759
  @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) }
1794
2760
  actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
1795
2761
  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
1796
- assert_match(/WARN -- : :1: word not bound: N/, io.string)
2762
+ assert_match(/WARN --: :1: word not bound: N/, io.string)
1797
2763
  end
1798
2764
  end
1799
2765
 
1800
2766
  def test_inline_unknown
1801
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
2767
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1802
2768
  assert_equal ':1: error: unknown image: n', e.message
1803
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" }
2769
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1804
2770
  assert_equal ':1: error: unknown footnote: n', e.message
1805
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" }
2771
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1806
2772
  assert_equal ':1: error: unknown headline: n', e.message
1807
2773
  %w[list table column].each do |name|
1808
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
2774
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1809
2775
  assert_equal ":1: error: unknown #{name}: n", e.message
1810
2776
  end
1811
2777
  %w[chap chapref title].each do |name|
1812
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
2778
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1813
2779
  assert_equal ':1: error: key not found: "n"', e.message
1814
2780
  end
1815
2781
  end
@@ -1839,6 +2805,20 @@ e=mc^2
1839
2805
  //}
1840
2806
  EOS
1841
2807
  expected = <<-EOS
2808
+ <p><span class="eqref"><a href="./-.html#emc2">式1.1</a></span></p>
2809
+ <div id="emc2" class="caption-equation">
2810
+ <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2811
+ <div class="equation">
2812
+ <pre>e=mc^2
2813
+ </pre>
2814
+ </div>
2815
+ </div>
2816
+ EOS
2817
+ actual = compile_block(src)
2818
+ assert_equal expected, actual
2819
+
2820
+ @config['chapterlink'] = nil
2821
+ expected = <<-EOS
1842
2822
  <p><span class="eqref">式1.1</span></p>
1843
2823
  <div id="emc2" class="caption-equation">
1844
2824
  <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
@@ -1850,5 +2830,311 @@ EOS
1850
2830
  EOS
1851
2831
  actual = compile_block(src)
1852
2832
  assert_equal expected, actual
2833
+
2834
+ @config['caption_position']['equation'] = 'bottom'
2835
+ expected = <<-EOS
2836
+ <p><span class="eqref">式1.1</span></p>
2837
+ <div id="emc2" class="caption-equation">
2838
+ <div class="equation">
2839
+ <pre>e=mc^2
2840
+ </pre>
2841
+ </div>
2842
+ <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2843
+ </div>
2844
+ EOS
2845
+ actual = compile_block(src)
2846
+ assert_equal expected, actual
2847
+ end
2848
+
2849
+ def test_nest_error_close1
2850
+ src = <<-EOS
2851
+ //beginchild
2852
+ EOS
2853
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2854
+ assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2855
+ end
2856
+
2857
+ def test_nest_error_close2
2858
+ src = <<-EOS
2859
+ * foo
2860
+
2861
+ //beginchild
2862
+
2863
+ 1. foo
2864
+
2865
+ //beginchild
2866
+
2867
+ : foo
2868
+
2869
+ //beginchild
2870
+ EOS
2871
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2872
+ assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
2873
+ end
2874
+
2875
+ def test_nest_error_close3
2876
+ src = <<-EOS
2877
+ * foo
2878
+
2879
+ //beginchild
2880
+
2881
+ 1. foo
2882
+
2883
+ //beginchild
2884
+
2885
+ : foo
2886
+
2887
+ //beginchild
2888
+
2889
+ //endchild
2890
+ EOS
2891
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2892
+ assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
2893
+ end
2894
+
2895
+ def test_nest_ul
2896
+ src = <<-EOS
2897
+ * UL1
2898
+
2899
+ //beginchild
2900
+
2901
+ 1. UL1-OL1
2902
+ 2. UL1-OL2
2903
+
2904
+ * UL1-UL1
2905
+ * UL1-UL2
2906
+
2907
+ : UL1-DL1
2908
+ UL1-DD1
2909
+ : UL1-DL2
2910
+ UL1-DD2
2911
+
2912
+ //endchild
2913
+
2914
+ * UL2
2915
+
2916
+ //beginchild
2917
+
2918
+ UL2-PARA
2919
+
2920
+ //endchild
2921
+ EOS
2922
+
2923
+ expected = <<-EOS
2924
+ <ul>
2925
+ <li>UL1
2926
+ <ol>
2927
+ <li>UL1-OL1</li>
2928
+ <li>UL1-OL2</li>
2929
+ </ol>
2930
+ <ul>
2931
+ <li>UL1-UL1</li>
2932
+ <li>UL1-UL2</li>
2933
+ </ul>
2934
+ <dl>
2935
+ <dt>UL1-DL1</dt>
2936
+ <dd>UL1-DD1</dd>
2937
+ <dt>UL1-DL2</dt>
2938
+ <dd>UL1-DD2</dd>
2939
+ </dl>
2940
+ </li>
2941
+
2942
+ <li>UL2
2943
+ <p>UL2-PARA</p>
2944
+ </li>
2945
+ </ul>
2946
+ EOS
2947
+
2948
+ actual = compile_block(src)
2949
+ assert_equal expected, actual
2950
+ end
2951
+
2952
+ def test_nest_ol
2953
+ src = <<-EOS
2954
+ 1. OL1
2955
+
2956
+ //beginchild
2957
+
2958
+ 1. OL1-OL1
2959
+ 2. OL1-OL2
2960
+
2961
+ * OL1-UL1
2962
+ * OL1-UL2
2963
+
2964
+ : OL1-DL1
2965
+ OL1-DD1
2966
+ : OL1-DL2
2967
+ OL1-DD2
2968
+
2969
+ //endchild
2970
+
2971
+ 2. OL2
2972
+
2973
+ //beginchild
2974
+
2975
+ OL2-PARA
2976
+
2977
+ //endchild
2978
+ EOS
2979
+
2980
+ expected = <<-EOS
2981
+ <ol>
2982
+ <li>OL1
2983
+ <ol>
2984
+ <li>OL1-OL1</li>
2985
+ <li>OL1-OL2</li>
2986
+ </ol>
2987
+ <ul>
2988
+ <li>OL1-UL1</li>
2989
+ <li>OL1-UL2</li>
2990
+ </ul>
2991
+ <dl>
2992
+ <dt>OL1-DL1</dt>
2993
+ <dd>OL1-DD1</dd>
2994
+ <dt>OL1-DL2</dt>
2995
+ <dd>OL1-DD2</dd>
2996
+ </dl>
2997
+ </li>
2998
+
2999
+ <li>OL2
3000
+ <p>OL2-PARA</p>
3001
+ </li>
3002
+ </ol>
3003
+ EOS
3004
+
3005
+ actual = compile_block(src)
3006
+ assert_equal expected, actual
3007
+ end
3008
+
3009
+ def test_nest_dl
3010
+ src = <<-EOS
3011
+ : DL1
3012
+
3013
+ //beginchild
3014
+
3015
+ 1. DL1-OL1
3016
+ 2. DL1-OL2
3017
+
3018
+ * DL1-UL1
3019
+ * DL1-UL2
3020
+
3021
+ : DL1-DL1
3022
+ DL1-DD1
3023
+ : DL1-DL2
3024
+ DL1-DD2
3025
+
3026
+ //endchild
3027
+
3028
+ : DL2
3029
+ DD2
3030
+
3031
+ //beginchild
3032
+
3033
+ * DD2-UL1
3034
+ * DD2-UL2
3035
+
3036
+ DD2-PARA
3037
+
3038
+ //endchild
3039
+ EOS
3040
+
3041
+ expected = <<-EOS
3042
+ <dl>
3043
+ <dt>DL1</dt>
3044
+ <dd>
3045
+ <ol>
3046
+ <li>DL1-OL1</li>
3047
+ <li>DL1-OL2</li>
3048
+ </ol>
3049
+ <ul>
3050
+ <li>DL1-UL1</li>
3051
+ <li>DL1-UL2</li>
3052
+ </ul>
3053
+ <dl>
3054
+ <dt>DL1-DL1</dt>
3055
+ <dd>DL1-DD1</dd>
3056
+ <dt>DL1-DL2</dt>
3057
+ <dd>DL1-DD2</dd>
3058
+ </dl>
3059
+ </dd>
3060
+
3061
+ <dt>DL2</dt>
3062
+ <dd>DD2
3063
+ <ul>
3064
+ <li>DD2-UL1</li>
3065
+ <li>DD2-UL2</li>
3066
+ </ul>
3067
+ <p>DD2-PARA</p>
3068
+ </dd>
3069
+ </dl>
3070
+ EOS
3071
+
3072
+ actual = compile_block(src)
3073
+ assert_equal expected, actual
3074
+ end
3075
+
3076
+ def test_nest_multi
3077
+ src = <<-EOS
3078
+ 1. OL1
3079
+
3080
+ //beginchild
3081
+
3082
+ 1. OL1-OL1
3083
+
3084
+ //beginchild
3085
+
3086
+ * OL1-OL1-UL1
3087
+
3088
+ OL1-OL1-PARA
3089
+
3090
+ //endchild
3091
+
3092
+ 2. OL1-OL2
3093
+
3094
+ * OL1-UL1
3095
+
3096
+ //beginchild
3097
+
3098
+ : OL1-UL1-DL1
3099
+ OL1-UL1-DD1
3100
+
3101
+ OL1-UL1-PARA
3102
+
3103
+ //endchild
3104
+
3105
+ * OL1-UL2
3106
+
3107
+ //endchild
3108
+ EOS
3109
+ expected = <<-EOS
3110
+ <ol>
3111
+ <li>OL1
3112
+ <ol>
3113
+ <li>OL1-OL1
3114
+ <ul>
3115
+ <li>OL1-OL1-UL1</li>
3116
+ </ul>
3117
+ <p>OL1-OL1-PARA</p>
3118
+ </li>
3119
+
3120
+ <li>OL1-OL2</li>
3121
+ </ol>
3122
+ <ul>
3123
+ <li>OL1-UL1
3124
+ <dl>
3125
+ <dt>OL1-UL1-DL1</dt>
3126
+ <dd>OL1-UL1-DD1</dd>
3127
+ </dl>
3128
+ <p>OL1-UL1-PARA</p>
3129
+ </li>
3130
+
3131
+ <li>OL1-UL2</li>
3132
+ </ul>
3133
+ </li>
3134
+ </ol>
3135
+ EOS
3136
+
3137
+ actual = compile_block(src)
3138
+ assert_equal expected, actual
1853
3139
  end
1854
3140
  end