review 3.2.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +31 -0
  3. data/.github/workflows/ruby-win.yml +45 -0
  4. data/.github/workflows/ruby.yml +27 -0
  5. data/.rubocop.yml +167 -42
  6. data/.travis.yml +1 -1
  7. data/Dockerfile +21 -5
  8. data/NEWS.ja.md +428 -1
  9. data/NEWS.md +429 -2
  10. data/README.md +11 -7
  11. data/Rakefile +7 -2
  12. data/appveyor.yml +0 -20
  13. data/bin/review +2 -4
  14. data/bin/review-catalog-converter +5 -5
  15. data/bin/review-check +13 -17
  16. data/bin/review-checkdep +3 -6
  17. data/bin/review-compile +13 -22
  18. data/bin/review-epub2html +1 -4
  19. data/bin/review-epubmaker +3 -4
  20. data/bin/review-idgxmlmaker +14 -0
  21. data/bin/review-index +5 -86
  22. data/bin/review-init +1 -4
  23. data/bin/review-pdfmaker +1 -3
  24. data/bin/review-preproc +11 -13
  25. data/bin/review-textmaker +1 -3
  26. data/bin/review-update +1 -4
  27. data/bin/review-validate +7 -7
  28. data/bin/review-vol +5 -82
  29. data/bin/review-webmaker +1 -3
  30. data/doc/config.yml.sample +67 -16
  31. data/doc/config.yml.sample-simple +4 -3
  32. data/doc/format.ja.md +133 -21
  33. data/doc/format.md +135 -34
  34. data/doc/makeindex.ja.md +2 -2
  35. data/doc/pdfmaker.ja.md +43 -1
  36. data/doc/pdfmaker.md +42 -1
  37. data/doc/quickstart.ja.md +55 -25
  38. data/doc/quickstart.md +47 -17
  39. data/lib/review.rb +1 -1
  40. data/lib/review/book.rb +2 -2
  41. data/lib/review/book/base.rb +89 -90
  42. data/lib/review/book/bib.rb +21 -0
  43. data/lib/review/book/book_unit.rb +158 -0
  44. data/lib/review/book/chapter.rb +51 -29
  45. data/lib/review/book/index.rb +42 -248
  46. data/lib/review/book/index/item.rb +46 -0
  47. data/lib/review/book/page_metric.rb +7 -7
  48. data/lib/review/book/part.rb +45 -10
  49. data/lib/review/book/volume.rb +5 -5
  50. data/lib/review/builder.rb +171 -54
  51. data/lib/review/call_hook.rb +20 -0
  52. data/lib/review/catalog.rb +15 -17
  53. data/lib/review/compiler.rb +240 -102
  54. data/lib/review/configure.rb +101 -12
  55. data/lib/review/converter.rb +1 -1
  56. data/lib/review/epub2html.rb +6 -1
  57. data/lib/review/epubmaker.rb +120 -118
  58. data/lib/review/epubmaker/content.rb +113 -0
  59. data/lib/review/epubmaker/epubcommon.rb +372 -0
  60. data/lib/review/epubmaker/epubv2.rb +178 -0
  61. data/lib/review/epubmaker/epubv3.rb +231 -0
  62. data/lib/review/epubmaker/producer.rb +168 -0
  63. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  64. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  65. data/lib/review/exception.rb +6 -0
  66. data/lib/review/extentions/string.rb +0 -4
  67. data/lib/review/htmlbuilder.rb +147 -149
  68. data/lib/review/htmlutils.rb +10 -14
  69. data/lib/review/i18n.rb +4 -3
  70. data/lib/review/idgxmlbuilder.rb +229 -103
  71. data/lib/review/idgxmlmaker.rb +188 -0
  72. data/lib/review/img_math.rb +245 -0
  73. data/lib/review/index_builder.rb +654 -0
  74. data/lib/review/init-web/finish.html +10 -0
  75. data/lib/review/init-web/index.html +190 -0
  76. data/lib/review/init-web/review-layout-design.js +691 -0
  77. data/lib/review/init.rb +124 -41
  78. data/lib/review/latexbox.rb +58 -0
  79. data/lib/review/latexbuilder.rb +249 -97
  80. data/lib/review/latexutils.rb +9 -1
  81. data/lib/review/lineinput.rb +113 -3
  82. data/lib/review/logger.rb +43 -8
  83. data/lib/review/makerhelper.rb +13 -186
  84. data/lib/review/markdownbuilder.rb +75 -39
  85. data/lib/review/md2inaobuilder.rb +3 -5
  86. data/lib/review/pdfmaker.rb +88 -83
  87. data/lib/review/plaintextbuilder.rb +158 -83
  88. data/lib/review/preprocessor.rb +30 -24
  89. data/lib/review/rstbuilder.rb +58 -39
  90. data/lib/review/sec_counter.rb +14 -0
  91. data/lib/review/template.rb +6 -0
  92. data/lib/review/textmaker.rb +29 -17
  93. data/lib/review/textutils.rb +68 -2
  94. data/lib/review/tocprinter.rb +242 -97
  95. data/lib/review/topbuilder.rb +147 -61
  96. data/lib/review/update.rb +27 -28
  97. data/lib/review/version.rb +1 -1
  98. data/lib/review/volumeprinter.rb +97 -0
  99. data/lib/review/webmaker.rb +36 -35
  100. data/lib/review/webtocprinter.rb +39 -35
  101. data/lib/review/yamlloader.rb +4 -0
  102. data/review.gemspec +8 -5
  103. data/samples/sample-book/README.md +7 -2
  104. data/samples/sample-book/src/.gitignore +154 -0
  105. data/samples/sample-book/src/config-ebook.yml +4 -0
  106. data/samples/sample-book/src/config-epub2.yml +1 -1
  107. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  108. data/samples/sample-book/src/config-jlreq.yml +6 -0
  109. data/samples/sample-book/src/config.yml +3 -3
  110. data/samples/sample-book/src/lib/tasks/review.rake +45 -14
  111. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  112. data/samples/syntax-book/Gemfile +1 -1
  113. data/samples/syntax-book/ch01.re +3 -1
  114. data/samples/syntax-book/ch02.re +28 -21
  115. data/samples/syntax-book/ch03.re +4 -7
  116. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  117. data/samples/syntax-book/config-jlreq.yml +5 -0
  118. data/samples/syntax-book/config-print.yml +3 -0
  119. data/samples/syntax-book/config.yml +1 -1
  120. data/samples/syntax-book/images/img3-2.png +0 -0
  121. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  122. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  123. data/templates/html/_colophon.html.erb +23 -0
  124. data/templates/html/_colophon_history.html.erb +9 -0
  125. data/templates/html/_cover.html.erb +10 -0
  126. data/templates/html/_part_body.html.erb +6 -0
  127. data/templates/html/_titlepage.html.erb +20 -0
  128. data/templates/html/layout-html5.html.erb +6 -0
  129. data/templates/html/layout-xhtml1.html.erb +6 -0
  130. data/templates/latex/config.erb +45 -27
  131. data/templates/latex/layout.tex.erb +1 -0
  132. data/templates/latex/review-jlreq/README.md +3 -1
  133. data/templates/latex/review-jlreq/review-base.sty +124 -37
  134. data/templates/latex/review-jlreq/review-jlreq.cls +29 -22
  135. data/templates/latex/review-jlreq/review-style.sty +9 -1
  136. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  137. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  138. data/templates/latex/review-jsbook/README.md +46 -5
  139. data/templates/latex/review-jsbook/review-base.sty +111 -30
  140. data/templates/latex/review-jsbook/review-jsbook.cls +16 -2
  141. data/templates/latex/review-jsbook/review-style.sty +10 -2
  142. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  143. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  144. data/templates/opf/epubv2.opf.erb +7 -7
  145. data/templates/opf/epubv3.opf.erb +7 -7
  146. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  147. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  148. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  149. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  150. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  151. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  152. data/templates/web/html/layout-html5.html.erb +9 -8
  153. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  154. data/test/assets/header_listener.html +35 -0
  155. data/test/assets/img_math/img1.png +0 -0
  156. data/test/assets/img_math/img2.png +0 -0
  157. data/test/assets/img_math/img3.png +0 -0
  158. data/test/assets/syntax_book_index_detail.txt +58 -0
  159. data/test/assets/test_template.tex +20 -9
  160. data/test/assets/test_template_backmatter.tex +20 -9
  161. data/test/book_test_helper.rb +11 -5
  162. data/test/run_test.rb +1 -1
  163. data/test/test_book.rb +123 -78
  164. data/test/test_book_chapter.rb +99 -56
  165. data/test/test_book_part.rb +3 -3
  166. data/test/test_builder.rb +24 -15
  167. data/test/test_catalog.rb +19 -42
  168. data/test/test_catalog_converter_cmd.rb +1 -1
  169. data/test/test_converter.rb +1 -0
  170. data/test/test_epub3maker.rb +170 -126
  171. data/test/test_epubmaker.rb +249 -129
  172. data/test/test_epubmaker_cmd.rb +16 -9
  173. data/test/test_helper.rb +23 -11
  174. data/test/test_htmlbuilder.rb +1083 -114
  175. data/test/test_htmlutils.rb +0 -12
  176. data/test/test_i18n.rb +37 -37
  177. data/test/test_idgxmlbuilder.rb +627 -27
  178. data/test/test_idgxmlmaker_cmd.rb +50 -0
  179. data/test/test_image_finder.rb +52 -70
  180. data/test/test_img_math.rb +111 -0
  181. data/test/test_index.rb +62 -52
  182. data/test/test_indexbuilder.rb +52 -0
  183. data/test/test_latexbuilder.rb +1189 -59
  184. data/test/test_latexbuilder_v2.rb +74 -34
  185. data/test/test_lineinput.rb +20 -93
  186. data/test/test_logger.rb +17 -4
  187. data/test/test_makerhelper.rb +2 -14
  188. data/test/test_markdownbuilder.rb +77 -4
  189. data/test/test_md2inaobuilder.rb +12 -2
  190. data/test/test_pdfmaker.rb +101 -12
  191. data/test/test_pdfmaker_cmd.rb +102 -8
  192. data/test/test_plaintextbuilder.rb +562 -31
  193. data/test/test_review_ext.rb +2 -1
  194. data/test/test_reviewheaderlistener.rb +49 -0
  195. data/test/test_rstbuilder.rb +58 -5
  196. data/test/test_sec_counter.rb +156 -0
  197. data/test/test_template.rb +12 -2
  198. data/test/test_textmaker_cmd.rb +58 -0
  199. data/test/test_textutils.rb +109 -2
  200. data/test/test_tocprinter.rb +46 -0
  201. data/test/test_topbuilder.rb +400 -17
  202. data/test/test_update.rb +53 -44
  203. data/test/test_webtocprinter.rb +75 -43
  204. data/test/test_yamlloader.rb +13 -0
  205. data/test/test_zip_exporter.rb +5 -6
  206. data/vendor/gentombow/LICENSE +1 -1
  207. data/vendor/gentombow/Makefile +0 -1
  208. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  209. data/vendor/gentombow/bounddvi-en.tex +1 -0
  210. data/vendor/gentombow/bounddvi.pdf +0 -0
  211. data/vendor/gentombow/bounddvi.sty +30 -7
  212. data/vendor/gentombow/bounddvi.tex +1 -0
  213. data/vendor/gentombow/create_archive.sh +1 -0
  214. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  215. data/vendor/gentombow/gentombow-ja.tex +9 -0
  216. data/vendor/gentombow/gentombow.pdf +0 -0
  217. data/vendor/gentombow/gentombow.sty +32 -10
  218. data/vendor/gentombow/gentombow.tex +8 -0
  219. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  220. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  221. data/vendor/jsclasses/LICENSE +1 -1
  222. data/vendor/jsclasses/Makefile +3 -2
  223. data/vendor/jsclasses/create_archive.sh +5 -5
  224. data/vendor/jsclasses/jis/Makefile +3 -2
  225. data/vendor/jsclasses/jis/jsarticle.cls +74 -31
  226. data/vendor/jsclasses/jis/jsbook.cls +74 -31
  227. data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
  228. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  229. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  230. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  231. data/vendor/jsclasses/jis/jslogo.sty +4 -16
  232. data/vendor/jsclasses/jis/jspf.cls +73 -30
  233. data/vendor/jsclasses/jis/jsreport.cls +74 -31
  234. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  235. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  236. data/vendor/jsclasses/jis/kiyou.cls +74 -31
  237. data/vendor/jsclasses/jis/minijs.sty +65 -22
  238. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  239. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  240. data/vendor/jsclasses/jis/okumacro.sty +4 -17
  241. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  242. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  243. data/vendor/jsclasses/jis/winjis.sty +23 -19
  244. data/vendor/jsclasses/jsarticle.cls +74 -31
  245. data/vendor/jsclasses/jsbook.cls +74 -31
  246. data/vendor/jsclasses/jsclasses.dtx +176 -36
  247. data/vendor/jsclasses/jsclasses.ins +15 -5
  248. data/vendor/jsclasses/jsclasses.pdf +0 -0
  249. data/vendor/jsclasses/jslogo.dtx +4 -4
  250. data/vendor/jsclasses/jslogo.ins +9 -0
  251. data/vendor/jsclasses/jslogo.pdf +0 -0
  252. data/vendor/jsclasses/jslogo.sty +4 -16
  253. data/vendor/jsclasses/jspf.cls +73 -30
  254. data/vendor/jsclasses/jsreport.cls +74 -31
  255. data/vendor/jsclasses/jsverb.ins +9 -0
  256. data/vendor/jsclasses/jsverb.pdf +0 -0
  257. data/vendor/jsclasses/jsverb.sty +1 -13
  258. data/vendor/jsclasses/kiyou.cls +74 -31
  259. data/vendor/jsclasses/minijs.sty +68 -22
  260. data/vendor/jsclasses/okumacro.dtx +4 -5
  261. data/vendor/jsclasses/okumacro.ins +9 -0
  262. data/vendor/jsclasses/okumacro.pdf +0 -0
  263. data/vendor/jsclasses/okumacro.sty +4 -17
  264. data/vendor/jsclasses/okuverb.ins +9 -0
  265. data/vendor/jsclasses/okuverb.pdf +0 -0
  266. data/vendor/jsclasses/okuverb.sty +1 -13
  267. data/vendor/jsclasses/tests/relfont.tex +10 -0
  268. data/vendor/jsclasses/winjis.sty +23 -19
  269. metadata +136 -23
  270. data/.rubocop_todo.yml +0 -7
  271. data/lib/epubmaker.rb +0 -23
  272. data/lib/epubmaker/content.rb +0 -110
  273. data/lib/epubmaker/epubcommon.rb +0 -441
  274. data/lib/epubmaker/epubv2.rb +0 -143
  275. data/lib/epubmaker/epubv3.rb +0 -233
  276. data/lib/epubmaker/producer.rb +0 -375
  277. data/lib/epubmaker/zip_exporter.rb +0 -81
  278. data/lib/lineinput.rb +0 -155
  279. data/lib/review/book/compilable.rb +0 -173
  280. data/lib/review/tocparser.rb +0 -271
  281. data/samples/syntax-book/review-ext.rb +0 -14
  282. data/test/test_tocparser.rb +0 -25
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  require 'yaml'
5
5
  require 'rbconfig'
6
6
 
7
- REVIEW_EPUBMAKER = File.expand_path('../bin/review-epubmaker', File.dirname(__FILE__))
7
+ REVIEW_EPUBMAKER = File.expand_path('../bin/review-epubmaker', __dir__)
8
8
 
9
9
  class EPUBMakerCmdTest < Test::Unit::TestCase
10
10
  def setup
@@ -12,27 +12,34 @@ class EPUBMakerCmdTest < Test::Unit::TestCase
12
12
  @tmpdir2 = Dir.mktmpdir
13
13
 
14
14
  @old_rubylib = ENV['RUBYLIB']
15
- ENV['RUBYLIB'] = File.expand_path('../lib', File.dirname(__FILE__))
15
+ ENV['RUBYLIB'] = File.expand_path('lib', __dir__)
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
data/test/test_helper.rb CHANGED
@@ -1,22 +1,31 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
1
+ $LOAD_PATH.unshift(File.realpath('../lib', __dir__))
2
+
2
3
  require 'test/unit'
3
4
  require 'fileutils'
5
+ require 'review/yamlloader'
6
+ require 'review/extentions'
4
7
 
5
8
  def touch_file(path)
6
9
  FileUtils.touch(path)
7
10
  end
8
11
 
9
12
  def assets_dir
10
- File.join(File.dirname(__FILE__), 'assets')
11
- end
12
-
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')))
13
+ File.join(__dir__, 'assets')
14
+ end
15
+
16
+ def prepare_samplebook(srcdir, bookdir, latextemplatedir, configfile)
17
+ samplebook_dir = File.expand_path("../samples/#{bookdir}/", __dir__)
18
+ files = Dir.glob(File.join(samplebook_dir, '*'))
19
+ # ignore temporary built files
20
+ files.delete_if { |file| file =~ /.*-(pdf|epub|text)/ || file == 'webroot' }
21
+ FileUtils.cp_r(files, srcdir)
22
+ if latextemplatedir
23
+ # copy from review-jsbook or review-jlreq
24
+ template_dir = File.expand_path("../templates/latex/#{latextemplatedir}/", __dir__)
25
+ FileUtils.cp(Dir.glob(File.join(template_dir, '*')), File.join(srcdir, 'sty'))
26
+ end
27
+ loader = ReVIEW::YAMLLoader.new
28
+ loader.load_file(File.open(File.join(srcdir, configfile)))
20
29
  end
21
30
 
22
31
  def compile_inline(text)
@@ -31,11 +40,13 @@ end
31
40
 
32
41
  def compile_block_default(text)
33
42
  @chapter.content = text
43
+ @chapter.execute_indexer(force: true)
34
44
  @compiler.compile(@chapter)
35
45
  end
36
46
 
37
47
  def compile_block_html(text)
38
48
  @chapter.content = text
49
+ @chapter.execute_indexer(force: true)
39
50
  matched = @compiler.compile(@chapter).match(Regexp.new(%Q(<body>\n(.+)</body>), Regexp::MULTILINE))
40
51
  if matched && matched.size > 1
41
52
  matched[1]
@@ -46,5 +57,6 @@ end
46
57
 
47
58
  def compile_block_idgxml(text)
48
59
  @chapter.content = text
60
+ @chapter.execute_indexer(force: true)
49
61
  @compiler.compile(@chapter).gsub(Regexp.new(%Q(.*<doc xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">), Regexp::MULTILINE), '').gsub("</doc>\n", '')
50
62
  end
@@ -8,7 +8,6 @@ class HTMLBuidlerTest < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
10
  ReVIEW::I18n.setup
11
- @builder = HTMLBuilder.new
12
11
  @config = ReVIEW::Configure.values
13
12
  @config['secnolevel'] = 2
14
13
  @config['stylesheet'] = nil
@@ -16,11 +15,14 @@ class HTMLBuidlerTest < Test::Unit::TestCase
16
15
  @config['epubmaker'] = {}
17
16
  @book = Book::Base.new('.')
18
17
  @book.config = @config
18
+ img_math = ReVIEW::ImgMath.new(@config)
19
+ @builder = HTMLBuilder.new(img_math: img_math)
19
20
  @compiler = ReVIEW::Compiler.new(@builder)
20
21
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
21
22
  location = Location.new(nil, nil)
22
23
  @builder.bind(@compiler, @chapter, location)
23
24
  I18n.setup('ja')
25
+ @skip_pygments = true # temporary suppress pygments test
24
26
  end
25
27
 
26
28
  def test_xmlns_ops_prefix_epub3
@@ -61,7 +63,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
61
63
  Dir.mktmpdir do |dir|
62
64
  Dir.chdir(dir) do
63
65
  file = File.join(dir, 'locale.yml')
64
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") }
66
+ File.write(file, "locale: ja\nappendix: 付録%pR")
65
67
  I18n.setup('ja')
66
68
  @chapter.instance_eval do
67
69
  def on_appendix?
@@ -82,7 +84,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
82
84
  Dir.mktmpdir do |dir|
83
85
  Dir.chdir(dir) do
84
86
  file = File.join(dir, 'locale.yml')
85
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") }
87
+ File.write(file, "locale: ja\nappendix: 付録%pA")
86
88
  I18n.setup('ja')
87
89
  @chapter.instance_eval do
88
90
  def on_appendix?
@@ -106,8 +108,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
106
108
  end
107
109
 
108
110
  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
111
+ actual = compile_block("={123あ_} this is test.\n")
112
+ 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
113
  end
112
114
 
113
115
  def test_headline_level1_with_inlinetag
@@ -137,8 +139,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
137
139
  end
138
140
 
139
141
  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
142
+ actual = compile_block("//label[123あ_]\n")
143
+ assert_equal %Q(<a id="id_123_E3_81_82__"></a>\n), actual
142
144
  end
143
145
 
144
146
  def test_href
@@ -244,10 +246,21 @@ EOS
244
246
 
245
247
  def test_inline_hd_chap
246
248
  def @chapter.headline_index
247
- items = [Book::HeadlineIndex::Item.new('chap1|test', [1, 1], 'te_st')]
248
- Book::HeadlineIndex.new(items, self)
249
+ item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
250
+ idx = Book::HeadlineIndex.new(self)
251
+ idx.add_item(item)
252
+ idx
249
253
  end
250
254
 
255
+ @config['secnolevel'] = 2
256
+ actual = compile_inline('test @<hd>{chap1|test} test2')
257
+ assert_equal 'test <a href="-.html#h1-1-1">「te_st」</a> test2', actual
258
+
259
+ @config['secnolevel'] = 3
260
+ actual = compile_inline('test @<hd>{chap1|test} test2')
261
+ assert_equal 'test <a href="-.html#h1-1-1">「1.1.1 te_st」</a> test2', actual
262
+
263
+ @config['chapterlink'] = nil
251
264
  @config['secnolevel'] = 2
252
265
  actual = compile_inline('test @<hd>{chap1|test} test2')
253
266
  assert_equal 'test 「te_st」 test2', actual
@@ -261,7 +274,7 @@ EOS
261
274
  Dir.mktmpdir do |dir|
262
275
  Dir.chdir(dir) do
263
276
  file = File.join(dir, 'locale.yml')
264
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") }
277
+ File.write(file, "locale: ja\nappendix: 付録%pR")
265
278
  I18n.setup('ja')
266
279
  @chapter.instance_eval do
267
280
  def on_appendix?
@@ -270,10 +283,16 @@ EOS
270
283
  end
271
284
 
272
285
  def @chapter.headline_index
273
- items = [Book::HeadlineIndex::Item.new('test', [1], 'te_st')]
274
- Book::HeadlineIndex.new(items, self)
286
+ item = Book::Index::Item.new('test', [1], 'te_st')
287
+ idx = Book::HeadlineIndex.new(self)
288
+ idx.add_item(item)
289
+ idx
275
290
  end
276
291
 
292
+ actual = compile_inline('test @<hd>{test} test2')
293
+ assert_equal 'test <a href="-.html#hI-1">「I.1 te_st」</a> test2', actual
294
+
295
+ @config['chapterlink'] = nil
277
296
  actual = compile_inline('test @<hd>{test} test2')
278
297
  assert_equal 'test 「I.1 te_st」 test2', actual
279
298
  end
@@ -284,7 +303,7 @@ EOS
284
303
  Dir.mktmpdir do |dir|
285
304
  Dir.chdir(dir) do
286
305
  file = File.join(dir, 'locale.yml')
287
- File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") }
306
+ File.write(file, "locale: ja\nappendix: 付録%pA")
288
307
  I18n.setup('ja')
289
308
  @chapter.instance_eval do
290
309
  def on_appendix?
@@ -293,10 +312,16 @@ EOS
293
312
  end
294
313
 
295
314
  def @chapter.headline_index
296
- items = [Book::HeadlineIndex::Item.new('test', [1], 'te_st')]
297
- Book::HeadlineIndex.new(items, self)
315
+ item = Book::Index::Item.new('test', [1], 'te_st')
316
+ idx = Book::HeadlineIndex.new(self)
317
+ idx.add_item(item)
318
+ idx
298
319
  end
299
320
 
321
+ actual = compile_inline('test @<hd>{test} test2')
322
+ assert_equal 'test <a href="-.html#hA-1">「A.1 te_st」</a> test2', actual
323
+
324
+ @config['chapterlink'] = nil
300
325
  actual = compile_inline('test @<hd>{test} test2')
301
326
  assert_equal 'test 「A.1 te_st」 test2', actual
302
327
  end
@@ -335,44 +360,73 @@ EOS
335
360
  rescue LoadError
336
361
  return true
337
362
  end
338
- @config['mathml'] = true
363
+ @config['math_format'] = 'mathml'
339
364
  actual = compile_inline('@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}')
340
- @config['mathml'] = nil
341
365
  assert_equal %Q(<span class="equation"><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mfrac><mrow><mo stretchy='false'>-</mo><mi>b</mi><mo stretchy='false'>&#xb1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo stretchy='false'>-</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math></span>), actual
342
366
  end
343
367
 
368
+ def test_inline_mathjax
369
+ @config['math_format'] = 'mathjax'
370
+ actual = compile_inline('@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}')
371
+ assert_equal %Q(<span class="equation">\\( \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a} \\)</span>), actual
372
+
373
+ content = <<-EOF
374
+ //texequation{
375
+ \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}
376
+ //}
377
+ EOF
378
+ actual = compile_block(content)
379
+ expected = %Q(<div class="equation">\n$$\\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$\n</div>\n)
380
+ assert_equal expected, actual
381
+ end
382
+
344
383
  def test_inline_img
345
384
  def @chapter.image(_id)
346
- item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
385
+ item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
347
386
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
348
387
  item
349
388
  end
350
389
 
351
- actual = compile_block "@<img>{sampleimg}\n"
390
+ actual = compile_block("@<img>{sampleimg}\n")
391
+ expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n)
392
+ assert_equal expected, actual
393
+
394
+ @config['chapterlink'] = nil
395
+ actual = compile_block("@<img>{sampleimg}\n")
352
396
  expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
353
397
  assert_equal expected, actual
354
398
  end
355
399
 
356
400
  def test_inline_imgref
357
401
  def @chapter.image(_id)
358
- item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
402
+ item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
359
403
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
360
404
  item
361
405
  end
362
406
 
363
- actual = compile_block "@<imgref>{sampleimg}\n"
407
+ actual = compile_block("@<imgref>{sampleimg}\n")
408
+ expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span>「sample photo」</p>\n)
409
+ assert_equal expected, actual
410
+
411
+ @config['chapterlink'] = nil
412
+ actual = compile_block("@<imgref>{sampleimg}\n")
364
413
  expected = %Q(<p><span class="imgref">図1.1</span>「sample photo」</p>\n)
365
414
  assert_equal expected, actual
366
415
  end
367
416
 
368
417
  def test_inline_imgref2
369
418
  def @chapter.image(_id)
370
- item = Book::NumberlessImageIndex::Item.new('sampleimg', 1)
419
+ item = Book::Index::Item.new('sampleimg', 1)
371
420
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
372
421
  item
373
422
  end
374
423
 
375
- actual = compile_block "@<imgref>{sampleimg}\n"
424
+ actual = compile_block("@<imgref>{sampleimg}\n")
425
+ expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n)
426
+ assert_equal expected, actual
427
+
428
+ @config['chapterlink'] = nil
429
+ actual = compile_block("@<imgref>{sampleimg}\n")
376
430
  expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
377
431
  assert_equal expected, actual
378
432
  end
@@ -383,20 +437,24 @@ EOS
383
437
  file1 = File.join(dir, 'images', 'img1.png')
384
438
  filet1 = File.join(dir, 'images', 'tbl1.png')
385
439
  file2 = File.join(dir, 'images', 'img2.png')
440
+ file3 = File.join(dir, 'images', 'icon3.png')
386
441
  re1 = File.join(dir, 'sample1.re')
387
442
  cat = File.join(dir, 'catalog.yml')
388
443
  FileUtils.mkdir_p(File.join(dir, 'images'))
389
- File.open(file1, 'w') { |f| f.write('') }
390
- File.open(filet1, 'w') { |f| f.write('') }
391
- File.open(file2, 'w') { |f| f.write('') }
392
- File.open(cat, 'w') { |f| f.write("CHAPS:\n - sample1.re\n") }
393
- File.open(re1, 'w') { |f| f.write(<<EOF) }
444
+ File.write(file1, '')
445
+ File.write(filet1, '')
446
+ File.write(file2, '')
447
+ File.write(file3, '')
448
+ File.write(cat, "CHAPS:\n - sample1.re\n")
449
+ File.write(re1, <<-EOF)
394
450
  = test
395
451
 
396
452
  tbl1 is @<table>{tbl1}.
397
453
 
398
454
  img2 is @<img>{img2}.
399
455
 
456
+ icon3 is @<icon>{icon3}.
457
+
400
458
  //image[img1][image 1]{
401
459
  //}
402
460
 
@@ -411,8 +469,37 @@ EOF
411
469
 
412
470
  expected = <<-EOS
413
471
  <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
472
+ <p>tbl1 is <span class="tableref"><a href="./-.html#tbl1">表1.1</a></span>.</p>
473
+ <p>img2 is <span class="imgref"><a href="./-.html#img2">図1.2</a></span>.</p>
474
+ <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
475
+ <div id="img1" class="image">
476
+ <img src="images/img1.png" alt="image 1" />
477
+ <p class="caption">
478
+ 図1.1: image 1
479
+ </p>
480
+ </div>
481
+ <div id="tbl1" class="imgtable image">
482
+ <p class="caption">表1.1: table 1</p>
483
+ <img src="images/tbl1.png" alt="table 1" />
484
+ </div>
485
+ <div id="img2" class="image">
486
+ <img src="images/img2.png" alt="image 2" />
487
+ <p class="caption">
488
+ 図1.2: image 2
489
+ </p>
490
+ </div>
491
+ EOS
492
+
493
+ assert_equal expected, actual
494
+
495
+ @config['chapterlink'] = nil
496
+ actual = compile_block(content)
497
+
498
+ expected = <<-EOS
499
+ <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
414
500
  <p>tbl1 is <span class="tableref">表1.1</span>.</p>
415
501
  <p>img2 is <span class="imgref">図1.2</span>.</p>
502
+ <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
416
503
  <div id="img1" class="image">
417
504
  <img src="images/img1.png" alt="image 1" />
418
505
  <p class="caption">
@@ -441,6 +528,14 @@ EOS
441
528
  expected = <<-EOS
442
529
  <blockquote><p>foobar</p>
443
530
  <p>buz</p></blockquote>
531
+ EOS
532
+ assert_equal expected, actual
533
+
534
+ @book.config['join_lines_by_lang'] = true
535
+ actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
536
+ expected = <<-EOS
537
+ <blockquote><p>foo bar</p>
538
+ <p>buz</p></blockquote>
444
539
  EOS
445
540
  assert_equal expected, actual
446
541
  end
@@ -471,6 +566,14 @@ EOS
471
566
  expected = <<-EOS
472
567
  <p class="noindent">foobar</p>
473
568
  <p>foo2bar2</p>
569
+ EOS
570
+ assert_equal expected, actual
571
+
572
+ @book.config['join_lines_by_lang'] = true
573
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
574
+ expected = <<-EOS
575
+ <p class="noindent">foo bar</p>
576
+ <p>foo2 bar2</p>
474
577
  EOS
475
578
  assert_equal expected, actual
476
579
  end
@@ -480,6 +583,14 @@ EOS
480
583
  expected = <<-EOS
481
584
  <p class="flushright">foobar</p>
482
585
  <p class="flushright">buz</p>
586
+ EOS
587
+ assert_equal expected, actual
588
+
589
+ @book.config['join_lines_by_lang'] = true
590
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
591
+ expected = <<-EOS
592
+ <p class="flushright">foo bar</p>
593
+ <p class="flushright">buz</p>
483
594
  EOS
484
595
  assert_equal expected, actual
485
596
  end
@@ -489,13 +600,21 @@ EOS
489
600
  expected = <<-EOS
490
601
  <p class="center">foobar</p>
491
602
  <p class="center">buz</p>
603
+ EOS
604
+ assert_equal expected, actual
605
+
606
+ @book.config['join_lines_by_lang'] = true
607
+ actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
608
+ expected = <<-EOS
609
+ <p class="center">foo bar</p>
610
+ <p class="center">buz</p>
492
611
  EOS
493
612
  assert_equal expected, actual
494
613
  end
495
614
 
496
615
  def test_image
497
616
  def @chapter.image(_id)
498
- item = Book::ImageIndex::Item.new('sampleimg', 1)
617
+ item = Book::Index::Item.new('sampleimg', 1)
499
618
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
500
619
  item
501
620
  end
@@ -508,13 +627,39 @@ EOS
508
627
  図1.1: sample photo
509
628
  </p>
510
629
  </div>
630
+ EOS
631
+ assert_equal expected, actual
632
+
633
+ actual = compile_block("//image[sampleimg][]{\n//}\n")
634
+ expected = <<-EOS
635
+ <div id="sampleimg" class="image">
636
+ <img src="images/chap1-sampleimg.png" alt="" />
637
+ <p class="caption">
638
+ 図1.1:
639
+ </p>
640
+ </div>
641
+ EOS
642
+ assert_equal expected, actual
643
+
644
+ actual = compile_block("//image[sampleimg][][]{\n//}\n")
645
+ assert_equal expected, actual
646
+
647
+ @config['caption_position']['image'] = 'top'
648
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
649
+ expected = <<-EOS
650
+ <div id="sampleimg" class="image">
651
+ <p class="caption">
652
+ 図1.1: sample photo
653
+ </p>
654
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
655
+ </div>
511
656
  EOS
512
657
  assert_equal expected, actual
513
658
  end
514
659
 
515
660
  def test_image_with_metric
516
661
  def @chapter.image(_id)
517
- item = Book::ImageIndex::Item.new('sampleimg', 1)
662
+ item = Book::Index::Item.new('sampleimg', 1)
518
663
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
519
664
  item
520
665
  end
@@ -533,7 +678,7 @@ EOS
533
678
 
534
679
  def test_image_with_metric2
535
680
  def @chapter.image(_id)
536
- item = Book::ImageIndex::Item.new('sampleimg', 1)
681
+ item = Book::Index::Item.new('sampleimg', 1)
537
682
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
538
683
  item
539
684
  end
@@ -550,28 +695,29 @@ EOS
550
695
  assert_equal expected, actual
551
696
  end
552
697
 
553
- def test_image_with_tricky_id
698
+ def test_image_with_tricky_id_kana
554
699
  def @chapter.image(_id)
555
- item = Book::ImageIndex::Item.new('123 あ_;', 1)
556
- item.instance_eval { @path = './images/chap1-123 あ_;.png' }
700
+ item = Book::Index::Item.new('123あいう', 1)
701
+ item.instance_eval { @path = './images/123あいう.png' }
557
702
  item
558
703
  end
559
-
560
- actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
704
+ @chapter.instance_eval { @name = 'ch01' }
705
+ actual = compile_block("//image[123あいう][sample photo]{\n//}\nimg: @<img>{123あいう}\n")
561
706
  expected = <<-EOS
562
- <div id="id_123-_E3_81_82___3B" class="image">
563
- <img src="images/chap1-123 あ_;.png" alt="sample photo" />
707
+ <div id="id_123_E3_81_82_E3_81_84_E3_81_86" class="image">
708
+ <img src="images/123あいう.png" alt="sample photo" />
564
709
  <p class="caption">
565
710
  図1.1: sample photo
566
711
  </p>
567
712
  </div>
713
+ <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>
568
714
  EOS
569
715
  assert_equal expected, actual
570
716
  end
571
717
 
572
718
  def test_indepimage
573
719
  def @chapter.image(_id)
574
- item = Book::ImageIndex::Item.new('sampleimg', 1)
720
+ item = Book::Index::Item.new('sampleimg', 1)
575
721
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
576
722
  item
577
723
  end
@@ -584,13 +730,25 @@ EOS
584
730
  図: sample photo
585
731
  </p>
586
732
  </div>
733
+ EOS
734
+ assert_equal expected, actual
735
+
736
+ @config['caption_position']['image'] = 'top'
737
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
738
+ expected = <<-EOS
739
+ <div id="sampleimg" class="image">
740
+ <p class="caption">
741
+ 図: sample photo
742
+ </p>
743
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
744
+ </div>
587
745
  EOS
588
746
  assert_equal expected, actual
589
747
  end
590
748
 
591
749
  def test_indepimage_without_caption
592
750
  def @chapter.image(_id)
593
- item = Book::ImageIndex::Item.new('sampleimg', 1)
751
+ item = Book::Index::Item.new('sampleimg', 1)
594
752
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
595
753
  item
596
754
  end
@@ -602,11 +760,17 @@ EOS
602
760
  </div>
603
761
  EOS
604
762
  assert_equal expected, actual
763
+
764
+ actual = compile_block("//indepimage[sampleimg][]\n")
765
+ assert_equal expected, actual
766
+
767
+ actual = compile_block("//indepimage[sampleimg][][]\n")
768
+ assert_equal expected, actual
605
769
  end
606
770
 
607
771
  def test_indepimage_with_metric
608
772
  def @chapter.image(_id)
609
- item = Book::ImageIndex::Item.new('sampleimg', 1)
773
+ item = Book::Index::Item.new('sampleimg', 1)
610
774
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
611
775
  item
612
776
  end
@@ -625,7 +789,7 @@ EOS
625
789
 
626
790
  def test_indepimage_with_metric2
627
791
  def @chapter.image(_id)
628
- item = Book::ImageIndex::Item.new('sampleimg', 1)
792
+ item = Book::Index::Item.new('sampleimg', 1)
629
793
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
630
794
  item
631
795
  end
@@ -644,7 +808,7 @@ EOS
644
808
 
645
809
  def test_indepimage_without_caption_but_with_metric
646
810
  def @chapter.image(_id)
647
- item = Book::ImageIndex::Item.new('sampleimg', 1)
811
+ item = Book::Index::Item.new('sampleimg', 1)
648
812
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
649
813
  item
650
814
  end
@@ -659,29 +823,49 @@ EOS
659
823
  end
660
824
 
661
825
  def test_dlist
662
- actual = compile_block(": foo\n foo.\n bar.\n")
826
+ actual = compile_block(" : foo\n foo.\n bar.\n")
663
827
  expected = <<-EOS
664
828
  <dl>
665
829
  <dt>foo</dt>
666
830
  <dd>foo.bar.</dd>
667
831
  </dl>
832
+ EOS
833
+ assert_equal expected, actual
834
+
835
+ @book.config['join_lines_by_lang'] = true
836
+ actual = compile_block(" : foo\n foo.\n bar.\n")
837
+ expected = <<-EOS
838
+ <dl>
839
+ <dt>foo</dt>
840
+ <dd>foo. bar.</dd>
841
+ </dl>
668
842
  EOS
669
843
  assert_equal expected, actual
670
844
  end
671
845
 
672
846
  def test_dlist_with_bracket
673
- actual = compile_block(": foo[bar]\n foo.\n bar.\n")
847
+ actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
674
848
  expected = <<-EOS
675
849
  <dl>
676
850
  <dt>foo[bar]</dt>
677
851
  <dd>foo.bar.</dd>
678
852
  </dl>
853
+ EOS
854
+ assert_equal expected, actual
855
+
856
+ @book.config['join_lines_by_lang'] = true
857
+ actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
858
+ expected = <<-EOS
859
+ <dl>
860
+ <dt>foo[bar]</dt>
861
+ <dd>foo. bar.</dd>
862
+ </dl>
679
863
  EOS
680
864
  assert_equal expected, actual
681
865
  end
682
866
 
683
867
  def test_dlist_with_comment
684
- source = ": title\n body\n\#@ comment\n\#@ comment\n: title2\n body2\n"
868
+ source = " : title\n body\n\#@ comment\n\#@ comment\n : title2\n body2\n"
685
869
  actual = compile_block(source)
686
870
  expected = <<-EOS
687
871
  <dl>
@@ -720,9 +904,22 @@ EOS
720
904
  assert_equal expected, actual
721
905
  end
722
906
 
907
+ def test_dt_inline
908
+ actual = compile_block("//footnote[bar][bar]\n\n : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
909
+
910
+ expected = <<-EOS
911
+ <div class="footnote" epub:type="footnote" id="fn-bar"><p class="footnote">[*1] bar</p></div>
912
+ <dl>
913
+ <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>
914
+ <dd></dd>
915
+ </dl>
916
+ EOS
917
+ assert_equal expected, actual
918
+ end
919
+
723
920
  def test_list
724
921
  def @chapter.list(_id)
725
- Book::ListIndex::Item.new('samplelist', 1)
922
+ Book::Index::Item.new('samplelist', 1)
726
923
  end
727
924
  actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
728
925
  expected = <<-EOS
@@ -734,37 +931,59 @@ test1.5
734
931
  test<i>2</i>
735
932
  </pre>
736
933
  </div>
934
+ EOS
935
+ assert_equal expected, actual
936
+
937
+ @config['caption_position']['list'] = 'bottom'
938
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
939
+ expected = <<-EOS
940
+ <div id="samplelist" class="caption-code">
941
+ <pre class="list">test1
942
+ test1.5
943
+
944
+ test<i>2</i>
945
+ </pre>
946
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
947
+ </div>
737
948
  EOS
738
949
  assert_equal expected, actual
739
950
  end
740
951
 
741
952
  def test_inline_list
742
953
  def @chapter.list(_id)
743
- Book::ListIndex::Item.new('samplelist', 1)
954
+ Book::Index::Item.new('samplelist', 1)
744
955
  end
745
- actual = compile_block("@<list>{sampletest}\n")
956
+ actual = compile_block("@<list>{samplelist}\n")
957
+ assert_equal %Q(<p><span class="listref"><a href="./-.html#samplelist">リスト1.1</a></span></p>\n), actual
958
+
959
+ @config['chapterlink'] = nil
960
+ actual = compile_block("@<list>{samplelist}\n")
746
961
  assert_equal %Q(<p><span class="listref">リスト1.1</span></p>\n), actual
747
962
  end
748
963
 
749
964
  def test_inline_list_href
750
- book = ReVIEW::Book::Base.load
965
+ book = ReVIEW::Book::Base.new
751
966
  book.config['chapterlink'] = true
752
967
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
753
- io1 = StringIO.new("//list[sampletest]{\nfoo\n//}\n")
968
+ io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n")
754
969
  io2 = StringIO.new("= BAR\n")
755
970
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
756
971
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
757
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
972
+ book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
758
973
  builder = ReVIEW::HTMLBuilder.new
759
974
  comp = ReVIEW::Compiler.new(builder)
760
975
  builder.bind(comp, chap2, nil)
976
+
977
+ chap1.generate_indexes
761
978
  actual = builder.inline_list('ch1|sampletest')
762
979
  assert_equal %Q(<span class="listref"><a href="./ch1.html#sampletest">リスト1.1</a></span>), actual
763
980
  end
764
981
 
765
982
  def test_list_pygments
983
+ return true if @skip_pygments
984
+
766
985
  def @chapter.list(_id)
767
- Book::ListIndex::Item.new('samplelist', 1)
986
+ Book::Index::Item.new('samplelist', 1)
768
987
  end
769
988
  begin
770
989
  require 'pygments'
@@ -790,8 +1009,10 @@ test&lt;i&gt;2&lt;/i&gt;
790
1009
  end
791
1010
 
792
1011
  def test_list_pygments_lang
1012
+ return true if @skip_pygments
1013
+
793
1014
  def @chapter.list(_id)
794
- Book::ListIndex::Item.new('samplelist', 1)
1015
+ Book::Index::Item.new('samplelist', 1)
795
1016
  end
796
1017
  begin
797
1018
  require 'pygments'
@@ -818,8 +1039,10 @@ EOS
818
1039
  end
819
1040
 
820
1041
  def test_list_pygments_nulllang
1042
+ return true if @skip_pygments
1043
+
821
1044
  def @chapter.list(_id)
822
- Book::ListIndex::Item.new('samplelist', 1)
1045
+ Book::Index::Item.new('samplelist', 1)
823
1046
  end
824
1047
  begin
825
1048
  require 'pygments'
@@ -852,7 +1075,7 @@ end
852
1075
  return true
853
1076
  end
854
1077
  def @chapter.list(_id)
855
- Book::ListIndex::Item.new('samplelist', 1)
1078
+ Book::Index::Item.new('samplelist', 1)
856
1079
  end
857
1080
  @book.config['highlight'] = {}
858
1081
  @book.config['highlight']['html'] = 'rouge'
@@ -879,7 +1102,7 @@ EOS
879
1102
  return true
880
1103
  end
881
1104
  def @chapter.list(_id)
882
- Book::ListIndex::Item.new('samplelist', 1)
1105
+ Book::Index::Item.new('samplelist', 1)
883
1106
  end
884
1107
  @book.config['highlight'] = {}
885
1108
  @book.config['highlight']['html'] = 'rouge'
@@ -907,7 +1130,7 @@ EOS
907
1130
  return true
908
1131
  end
909
1132
  def @chapter.list(_id)
910
- Book::ListIndex::Item.new('samplelist', 1)
1133
+ Book::Index::Item.new('samplelist', 1)
911
1134
  end
912
1135
  @book.config['highlight'] = {}
913
1136
  @book.config['highlight']['html'] = 'rouge'
@@ -929,7 +1152,7 @@ EOS
929
1152
 
930
1153
  def test_listnum
931
1154
  def @chapter.list(_id)
932
- Book::ListIndex::Item.new('samplelist', 1)
1155
+ Book::Index::Item.new('samplelist', 1)
933
1156
  end
934
1157
 
935
1158
  @book.config['highlight'] = false
@@ -951,6 +1174,29 @@ EOS
951
1174
  4: end
952
1175
  </pre>
953
1176
  </div>
1177
+ EOS
1178
+
1179
+ assert_equal expected, actual
1180
+
1181
+ @config['caption_position']['list'] = 'bottom'
1182
+ actual = compile_block(<<-EOS)
1183
+ //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
1184
+ def foo(a1, a2=:test)
1185
+ (1..3).times{|i| a.include?(:foo)}
1186
+ return true
1187
+ end
1188
+ //}
1189
+ EOS
1190
+
1191
+ expected = <<-EOS
1192
+ <div id="samplelist" class="code">
1193
+ <pre class="list language-ruby"> 1: def foo(a1, a2=:test)
1194
+ 2: (1..3).times{|i| a.include?(:foo)}
1195
+ 3: return true
1196
+ 4: end
1197
+ </pre>
1198
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1199
+ </div>
954
1200
  EOS
955
1201
 
956
1202
  assert_equal expected, actual
@@ -958,7 +1204,7 @@ EOS
958
1204
 
959
1205
  def test_listnum_linenum
960
1206
  def @chapter.list(_id)
961
- Book::ListIndex::Item.new('samplelist', 1)
1207
+ Book::Index::Item.new('samplelist', 1)
962
1208
  end
963
1209
 
964
1210
  @book.config['highlight'] = false
@@ -987,8 +1233,10 @@ EOS
987
1233
  end
988
1234
 
989
1235
  def test_listnum_pygments_lang
1236
+ return true if @skip_pygments
1237
+
990
1238
  def @chapter.list(_id)
991
- Book::ListIndex::Item.new('samplelist', 1)
1239
+ Book::Index::Item.new('samplelist', 1)
992
1240
  end
993
1241
  begin
994
1242
  require 'pygments'
@@ -1014,8 +1262,10 @@ EOS
1014
1262
  end
1015
1263
 
1016
1264
  def test_listnum_pygments_lang_linenum
1265
+ return true if @skip_pygments
1266
+
1017
1267
  def @chapter.list(_id)
1018
- Book::ListIndex::Item.new('samplelist', 1)
1268
+ Book::Index::Item.new('samplelist', 1)
1019
1269
  end
1020
1270
  begin
1021
1271
  require 'pygments'
@@ -1042,8 +1292,10 @@ EOS
1042
1292
  end
1043
1293
 
1044
1294
  def test_listnum_pygments_lang_without_lang
1295
+ return true if @skip_pygments
1296
+
1045
1297
  def @chapter.list(_id)
1046
- Book::ListIndex::Item.new('samplelist', 1)
1298
+ Book::Index::Item.new('samplelist', 1)
1047
1299
  end
1048
1300
  begin
1049
1301
  require 'pygments'
@@ -1077,7 +1329,7 @@ EOS
1077
1329
  return true
1078
1330
  end
1079
1331
  def @chapter.list(_id)
1080
- Book::ListIndex::Item.new('samplelist', 1)
1332
+ Book::Index::Item.new('samplelist', 1)
1081
1333
  end
1082
1334
  @book.config['highlight'] = {}
1083
1335
  @book.config['highlight']['html'] = 'rouge'
@@ -1111,7 +1363,7 @@ EOS
1111
1363
  return true
1112
1364
  end
1113
1365
  def @chapter.list(_id)
1114
- Book::ListIndex::Item.new('samplelist', 1)
1366
+ Book::Index::Item.new('samplelist', 1)
1115
1367
  end
1116
1368
  @book.config['highlight'] = {}
1117
1369
  @book.config['highlight']['html'] = 'rouge'
@@ -1148,6 +1400,20 @@ bar
1148
1400
  buz
1149
1401
  </pre>
1150
1402
  </div>
1403
+ EOS
1404
+ assert_equal expected, actual
1405
+
1406
+ @config['caption_position']['list'] = 'bottom'
1407
+ actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
1408
+ expected = <<-EOS
1409
+ <div class="source-code">
1410
+ <pre class="source">foo
1411
+ bar
1412
+
1413
+ buz
1414
+ </pre>
1415
+ <p class="caption">foo/bar/test.rb</p>
1416
+ </div>
1151
1417
  EOS
1152
1418
  assert_equal expected, actual
1153
1419
  end
@@ -1185,6 +1451,18 @@ EOS
1185
1451
  bar
1186
1452
  </pre>
1187
1453
  </div>
1454
+ EOS
1455
+ assert_equal expected, actual
1456
+
1457
+ @config['caption_position']['list'] = 'bottom'
1458
+ actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
1459
+ expected = <<-EOS
1460
+ <div class="syntax">
1461
+ <pre class="syntax">foo
1462
+ bar
1463
+ </pre>
1464
+ <p class="caption">FOO</p>
1465
+ </div>
1188
1466
  EOS
1189
1467
  assert_equal expected, actual
1190
1468
  end
@@ -1202,6 +1480,8 @@ EOS
1202
1480
  end
1203
1481
 
1204
1482
  def test_emlist_pygments_lang
1483
+ return true if @skip_pygments
1484
+
1205
1485
  begin
1206
1486
  require 'pygments'
1207
1487
  rescue LoadError
@@ -1229,6 +1509,18 @@ EOS
1229
1509
  lineB
1230
1510
  </pre>
1231
1511
  </div>
1512
+ EOS
1513
+ assert_equal expected, actual
1514
+
1515
+ @config['caption_position']['list'] = 'bottom'
1516
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
1517
+ expected = <<-EOS
1518
+ <div class="emlist-code">
1519
+ <pre class="emlist">lineA
1520
+ lineB
1521
+ </pre>
1522
+ <p class="caption">cap1</p>
1523
+ </div>
1232
1524
  EOS
1233
1525
  assert_equal expected, actual
1234
1526
  end
@@ -1269,6 +1561,18 @@ EOS
1269
1561
  2: lineB
1270
1562
  </pre>
1271
1563
  </div>
1564
+ EOS
1565
+ assert_equal expected, actual
1566
+
1567
+ @config['caption_position']['list'] = 'bottom'
1568
+ actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
1569
+ expected = <<-EOS
1570
+ <div class="emlistnum-code">
1571
+ <pre class="emlist language-text"> 1: lineA
1572
+ 2: lineB
1573
+ </pre>
1574
+ <p class="caption">cap</p>
1575
+ </div>
1272
1576
  EOS
1273
1577
  assert_equal expected, actual
1274
1578
  end
@@ -1314,6 +1618,8 @@ EOS
1314
1618
  end
1315
1619
 
1316
1620
  def test_cmd_pygments
1621
+ return true if @skip_pygments
1622
+
1317
1623
  begin
1318
1624
  require 'pygments'
1319
1625
  rescue LoadError
@@ -1341,6 +1647,18 @@ EOS
1341
1647
  lineB
1342
1648
  </pre>
1343
1649
  </div>
1650
+ EOS
1651
+ assert_equal expected, actual
1652
+
1653
+ @config['caption_position']['list'] = 'bottom'
1654
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
1655
+ expected = <<-EOS
1656
+ <div class="cmd-code">
1657
+ <pre class="cmd">lineA
1658
+ lineB
1659
+ </pre>
1660
+ <p class="caption">cap1</p>
1661
+ </div>
1344
1662
  EOS
1345
1663
  assert_equal expected, actual
1346
1664
  end
@@ -1348,13 +1666,16 @@ EOS
1348
1666
  def test_texequation
1349
1667
  return true if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
1350
1668
  return true unless system('latex -version 1>/dev/null 2>/dev/null')
1669
+
1351
1670
  mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
1352
1671
  'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P} q\n//}\n") do |dir, book, _files|
1353
1672
  @book = book
1354
1673
  @book.config = @config
1355
- @config['imgmath'] = true
1674
+ @config['math_format'] = 'imgmath'
1356
1675
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
1357
1676
  location = Location.new(nil, nil)
1677
+ img_math = ReVIEW::ImgMath.new(@config)
1678
+ @builder = HTMLBuilder.new(img_math: img_math)
1358
1679
  @builder.bind(@compiler, @chapter, location)
1359
1680
  FileUtils.mkdir_p(File.join(dir, 'images'))
1360
1681
  expected = <<-EOB
@@ -1378,14 +1699,17 @@ EOS
1378
1699
  # Re:VIEW 3 never fail on defer mode. This test is only for Re:VIEW 2.
1379
1700
  return true if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
1380
1701
  return true unless system('latex -version 1>/dev/null 2>/dev/null')
1702
+
1381
1703
  mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
1382
1704
  'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P}} q\n//}\n") do |dir, book, _files|
1383
1705
  @book = book
1384
1706
  @book.config = @config
1385
1707
  @config['review_version'] = 2
1386
- @config['imgmath'] = true
1708
+ @config['math_format'] = 'imgmath'
1387
1709
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
1388
1710
  location = Location.new(nil, nil)
1711
+ img_math = ReVIEW::ImgMath.new(@config)
1712
+ @builder = HTMLBuilder.new(img_math: img_math)
1389
1713
  @builder.bind(@compiler, @chapter, location)
1390
1714
  FileUtils.mkdir_p(File.join(dir, 'images'))
1391
1715
  tmpio = $stderr
@@ -1402,7 +1726,7 @@ EOS
1402
1726
 
1403
1727
  def test_bib
1404
1728
  def @chapter.bibpaper(_id)
1405
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1729
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1406
1730
  end
1407
1731
 
1408
1732
  assert_equal %Q(<a href="bib.html#bib-samplebib">[1]</a>), compile_inline('@<bib>{samplebib}')
@@ -1410,7 +1734,7 @@ EOS
1410
1734
 
1411
1735
  def test_bib_noramlized
1412
1736
  def @chapter.bibpaper(_id)
1413
- Book::BibpaperIndex::Item.new('sampleb=ib', 1, 'sample bib')
1737
+ Book::Index::Item.new('sampleb=ib', 1, 'sample bib')
1414
1738
  end
1415
1739
 
1416
1740
  assert_equal %Q(<a href="bib.html#bib-id_sample_3Dbib">[1]</a>), compile_inline('@<bib>{sample=bib}')
@@ -1418,7 +1742,7 @@ EOS
1418
1742
 
1419
1743
  def test_bib_htmlext
1420
1744
  def @chapter.bibpaper(_id)
1421
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1745
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1422
1746
  end
1423
1747
 
1424
1748
  @config['htmlext'] = 'xhtml'
@@ -1427,7 +1751,7 @@ EOS
1427
1751
 
1428
1752
  def test_bibpaper
1429
1753
  def @chapter.bibpaper(_id)
1430
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1754
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1431
1755
  end
1432
1756
 
1433
1757
  actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
@@ -1435,13 +1759,22 @@ EOS
1435
1759
  <div class="bibpaper">
1436
1760
  <a id="bib-samplebib">[1]</a> sample bib <b>bold</b>
1437
1761
  <p>ab</p></div>
1762
+ EOS
1763
+ assert_equal expected, actual
1764
+
1765
+ @book.config['join_lines_by_lang'] = true
1766
+ actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1767
+ expected = <<-EOS
1768
+ <div class="bibpaper">
1769
+ <a id="bib-samplebib">[1]</a> sample bib <b>bold</b>
1770
+ <p>a b</p></div>
1438
1771
  EOS
1439
1772
  assert_equal expected, actual
1440
1773
  end
1441
1774
 
1442
1775
  def test_bibpaper_normalized
1443
1776
  def @chapter.bibpaper(_id)
1444
- Book::BibpaperIndex::Item.new('sample=bib', 1, 'sample bib')
1777
+ Book::Index::Item.new('sample=bib', 1, 'sample bib')
1445
1778
  end
1446
1779
 
1447
1780
  actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
@@ -1449,13 +1782,22 @@ EOS
1449
1782
  <div class="bibpaper">
1450
1783
  <a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>
1451
1784
  <p>ab</p></div>
1785
+ EOS
1786
+ assert_equal expected, actual
1787
+
1788
+ @book.config['join_lines_by_lang'] = true
1789
+ actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1790
+ expected = <<-EOS
1791
+ <div class="bibpaper">
1792
+ <a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>
1793
+ <p>a b</p></div>
1452
1794
  EOS
1453
1795
  assert_equal expected, actual
1454
1796
  end
1455
1797
 
1456
1798
  def test_bibpaper_with_anchor
1457
1799
  def @chapter.bibpaper(_id)
1458
- Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
1800
+ Book::Index::Item.new('samplebib', 1, 'sample bib')
1459
1801
  end
1460
1802
 
1461
1803
  actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
@@ -1465,13 +1807,22 @@ EOS
1465
1807
  <p>ab</p></div>
1466
1808
  EOS
1467
1809
  assert_equal expected, actual
1468
- end
1469
-
1470
- def column_helper(review)
1471
- compile_block(review)
1472
- end
1473
1810
 
1474
- def test_column_1
1811
+ @book.config['join_lines_by_lang'] = true
1812
+ actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
1813
+ expected = <<-EOS
1814
+ <div class="bibpaper">
1815
+ <a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>
1816
+ <p>a b</p></div>
1817
+ EOS
1818
+ assert_equal expected, actual
1819
+ end
1820
+
1821
+ def column_helper(review)
1822
+ compile_block(review)
1823
+ end
1824
+
1825
+ def test_column_1
1475
1826
  review = <<-EOS
1476
1827
  ===[column] prev column
1477
1828
 
@@ -1549,6 +1900,20 @@ EOS
1549
1900
  <p>inside column</p>
1550
1901
  </div>
1551
1902
 
1903
+ <h3><a id="h1-0-1"></a>next level</h3>
1904
+ <p>this is <a href="-.html#column-1" class="columnref">コラム「test」</a>.</p>
1905
+ EOS
1906
+
1907
+ assert_equal expected, column_helper(review)
1908
+
1909
+ @config['chapterlink'] = nil
1910
+ expected = <<-EOS
1911
+ <div class="column">
1912
+
1913
+ <h3 id="foo"><a id="column-1"></a>test</h3>
1914
+ <p>inside column</p>
1915
+ </div>
1916
+
1552
1917
  <h3><a id="h1-0-1"></a>next level</h3>
1553
1918
  <p>this is コラム「test」.</p>
1554
1919
  EOS
@@ -1558,10 +1923,17 @@ EOS
1558
1923
 
1559
1924
  def test_column_in_aother_chapter_ref
1560
1925
  def @chapter.column_index
1561
- items = [Book::ColumnIndex::Item.new('chap1|column', 1, 'column_cap')]
1562
- Book::ColumnIndex.new(items)
1926
+ item = Book::Index::Item.new('chap1|column', 1, 'column_cap')
1927
+ idx = Book::ColumnIndex.new
1928
+ idx.add_item(item)
1929
+ idx
1563
1930
  end
1564
1931
 
1932
+ actual = compile_inline('test @<column>{chap1|column} test2')
1933
+ expected = 'test <a href="-.html#column-1" class="columnref">コラム「column_cap」</a> test2'
1934
+ assert_equal expected, actual
1935
+
1936
+ @config['chapterlink'] = nil
1565
1937
  actual = compile_inline('test @<column>{chap1|column} test2')
1566
1938
  expected = 'test コラム「column_cap」 test2'
1567
1939
  assert_equal expected, actual
@@ -1594,6 +1966,16 @@ EOS
1594
1966
  <li>AAA-AA</li>
1595
1967
  <li>BBB-BB</li>
1596
1968
  </ul>
1969
+ EOS
1970
+ actual = compile_block(src)
1971
+ assert_equal expected, actual
1972
+
1973
+ @book.config['join_lines_by_lang'] = true
1974
+ expected = <<-EOS
1975
+ <ul>
1976
+ <li>AAA -AA</li>
1977
+ <li>BBB -BB</li>
1978
+ </ul>
1597
1979
  EOS
1598
1980
  actual = compile_block(src)
1599
1981
  assert_equal expected, actual
@@ -1849,8 +2231,6 @@ EOS
1849
2231
  end
1850
2232
 
1851
2233
  def test_footnote
1852
- fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
1853
- @chapter.instance_eval { @footnote_index = fn }
1854
2234
  actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
1855
2235
  expected = <<-'EOS'
1856
2236
  <div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote">[*1] bar\a\$buz</p></div>
@@ -1875,58 +2255,69 @@ EOS
1875
2255
  end
1876
2256
 
1877
2257
  def test_footnote_with_tricky_id
1878
- fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
1879
- @chapter.instance_eval { @footnote_index = fn }
1880
- actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
2258
+ actual = compile_block("//footnote[123あ_;][bar\\a\\$buz]\n")
1881
2259
  expected = <<-'EOS'
1882
- <div class="footnote" epub:type="footnote" id="fn-id_123-_E3_81_82___3B"><p class="footnote">[*1] bar\a\$buz</p></div>
2260
+ <div class="footnote" epub:type="footnote" id="fn-id_123_E3_81_82___3B"><p class="footnote">[*1] bar\a\$buz</p></div>
1883
2261
  EOS
1884
2262
  assert_equal expected, actual
1885
2263
  end
1886
2264
 
1887
2265
  def test_inline_fn
1888
- book = ReVIEW::Book::Base.load
1889
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re])
1890
- io1 = StringIO.new("//footnote[foo][bar]\n")
1891
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1892
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1])]
1893
- builder = ReVIEW::HTMLBuilder.new
1894
- comp = ReVIEW::Compiler.new(builder)
1895
- builder.bind(comp, chap1, nil)
1896
- fn = builder.inline_fn('foo')
1897
- assert_equal '<a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">*1</a>', fn
2266
+ fn = compile_block("//footnote[foo][bar]\n\n@<fn>{foo}\n")
2267
+ expected = <<-EOS
2268
+ <div class=\"footnote\" epub:type=\"footnote\" id=\"fn-foo\"><p class=\"footnote\">[*1] bar</p></div>
2269
+ <p><a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">*1</a></p>
2270
+ EOS
2271
+ assert_equal expected, fn
1898
2272
  I18n.set('html_footnote_refmark', '+%s')
1899
- fn = builder.inline_fn('foo')
1900
- assert_equal '<a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">+1</a>', fn
2273
+ fn = compile_block("//footnote[foo][bar]\n\n@<fn>{foo}\n")
2274
+ expected = <<-EOS
2275
+ <div class=\"footnote\" epub:type=\"footnote\" id=\"fn-foo\"><p class=\"footnote\">[*1] bar</p></div>
2276
+ <p><a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">+1</a></p>
2277
+ EOS
2278
+ assert_equal expected, fn
1901
2279
  end
1902
2280
 
1903
2281
  def test_inline_hd
1904
- book = ReVIEW::Book::Base.load
2282
+ book = ReVIEW::Book::Base.new
1905
2283
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
1906
2284
  io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
1907
2285
  io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
1908
2286
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1909
2287
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
1910
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
2288
+ book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
1911
2289
  builder = ReVIEW::HTMLBuilder.new
1912
2290
  comp = ReVIEW::Compiler.new(builder)
1913
2291
  builder.bind(comp, chap2, nil)
2292
+
2293
+ chap1.generate_indexes
2294
+ chap2.generate_indexes
2295
+ hd = builder.inline_hd('ch1|test1-1')
2296
+ assert_equal '<a href="ch1.html#h1-1">「1.1 test1-1」</a>', hd
2297
+
2298
+ builder.instance_eval { @book.config['chapterlink'] = nil }
1914
2299
  hd = builder.inline_hd('ch1|test1-1')
1915
2300
  assert_equal '「1.1 test1-1」', hd
1916
2301
  end
1917
2302
 
1918
2303
  def test_inline_hd_for_part
1919
- book = ReVIEW::Book::Base.load
2304
+ book = ReVIEW::Book::Base.new
1920
2305
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
1921
2306
  io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
1922
2307
  io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
1923
2308
  io_p1 = StringIO.new("= part1\n\nfoo\n\n== part1-1\n\nbar\n\n== part1-2\n\nbar\n\n")
1924
2309
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
1925
2310
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
1926
- book.parts = [ReVIEW::Book::Part.new(self, 1, [chap1, chap2], 'part1.re', io_p1)]
2311
+ book.parts = [ReVIEW::Book::Part.new(book, 1, [chap1, chap2], 'part1.re', io_p1)]
1927
2312
  builder = ReVIEW::HTMLBuilder.new
1928
2313
  comp = ReVIEW::Compiler.new(builder)
1929
2314
  builder.bind(comp, chap2, nil)
2315
+ book.generate_indexes
2316
+
2317
+ hd = builder.inline_hd('part1|part1-1')
2318
+ assert_equal '<a href="part1.html#h1-1">「1.1 part1-1」</a>', hd
2319
+
2320
+ builder.instance_eval { @book.config['chapterlink'] = nil }
1930
2321
  hd = builder.inline_hd('part1|part1-1')
1931
2322
  assert_equal '「1.1 part1-1」', hd
1932
2323
  end
@@ -1937,7 +2328,12 @@ EOS
1937
2328
  location = Location.new(nil, nil)
1938
2329
  @builder.bind(@compiler, chap1, location)
1939
2330
  hd = @builder.inline_hd('foo')
2331
+ assert_equal '<a href="-.html#h1-1">「1.1 foo」</a>', hd
2332
+
2333
+ @config['chapterlink'] = nil
2334
+ hd = @builder.inline_hd('foo')
1940
2335
  assert_equal '「1.1 foo」', hd
2336
+
1941
2337
  hd = @builder.inline_hd('bar')
1942
2338
  assert_equal '「1.2 bar」', hd
1943
2339
  end
@@ -1963,23 +2359,40 @@ EOS
1963
2359
  <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
1964
2360
  </table>
1965
2361
  </div>
2362
+ EOS
2363
+ assert_equal expected, actual
2364
+
2365
+ @config['caption_position']['table'] = 'bottom'
2366
+ actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2367
+ expected = <<-EOS
2368
+ <div id="foo" class="table">
2369
+ <table>
2370
+ <tr><th>aaa</th><th>bbb</th></tr>
2371
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2372
+ </table>
2373
+ <p class="caption">表1.1: FOO</p>
2374
+ </div>
1966
2375
  EOS
1967
2376
  assert_equal expected, actual
1968
2377
  end
1969
2378
 
1970
2379
  def test_empty_table
1971
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "//table{\n//}\n" }
2380
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
1972
2381
  assert_equal ':2: error: no rows in the table', e.message
1973
2382
 
1974
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "//table{\n------------\n//}\n" }
2383
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
1975
2384
  assert_equal ':3: error: no rows in the table', e.message
1976
2385
  end
1977
2386
 
1978
2387
  def test_inline_table
1979
2388
  def @chapter.table(_id)
1980
- Book::TableIndex::Item.new('sampletable', 1)
2389
+ Book::Index::Item.new('sampletable', 1)
1981
2390
  end
1982
2391
  actual = compile_block("@<table>{sampletest}\n")
2392
+ assert_equal %Q(<p><span class="tableref"><a href="./-.html#sampletest">表1.1</a></span></p>\n), actual
2393
+
2394
+ @config['chapterlink'] = nil
2395
+ actual = compile_block("@<table>{sampletest}\n")
1983
2396
  assert_equal %Q(<p><span class="tableref">表1.1</span></p>\n), actual
1984
2397
  end
1985
2398
 
@@ -1999,13 +2412,32 @@ EOS
1999
2412
  <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2000
2413
  </table>
2001
2414
  </div>
2415
+ EOS
2416
+ assert_equal expected, actual
2417
+
2418
+ @config['caption_position']['table'] = 'bottom'
2419
+ actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2420
+ expected = <<-EOS
2421
+ <div class="table">
2422
+ <table>
2423
+ <tr><th>aaa</th><th>bbb</th></tr>
2424
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2425
+ </table>
2426
+ <p class="caption">foo</p>
2427
+ </div>
2428
+ <div class="table">
2429
+ <table>
2430
+ <tr><th>aaa</th><th>bbb</th></tr>
2431
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2432
+ </table>
2433
+ </div>
2002
2434
  EOS
2003
2435
  assert_equal expected, actual
2004
2436
  end
2005
2437
 
2006
2438
  def test_imgtable
2007
2439
  def @chapter.image(_id)
2008
- item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample img')
2440
+ item = Book::Index::Item.new('sampleimg', 1, 'sample img')
2009
2441
  item.instance_eval { @path = './images/chap1-sampleimg.png' }
2010
2442
  item
2011
2443
  end
@@ -2016,6 +2448,66 @@ EOS
2016
2448
  <p class="caption">表1.1: test for imgtable</p>
2017
2449
  <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2018
2450
  </div>
2451
+ EOS
2452
+ assert_equal expected, actual
2453
+
2454
+ @config['caption_position']['table'] = 'bottom'
2455
+ actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
2456
+ expected = <<-EOS
2457
+ <div id="sampleimg" class="imgtable image">
2458
+ <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2459
+ <p class="caption">表1.1: test for imgtable</p>
2460
+ </div>
2461
+ EOS
2462
+ assert_equal expected, actual
2463
+ end
2464
+
2465
+ def test_table_row_separator
2466
+ src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n"
2467
+ expected = <<-EOS
2468
+ <div class="table">
2469
+ <table>
2470
+ <tr><th>1</th><th>2</th><th>3 4| 5</th></tr>
2471
+ <tr><td>a b</td><td>c d |e</td><td></td></tr>
2472
+ </table>
2473
+ </div>
2474
+ EOS
2475
+ actual = compile_block(src)
2476
+ assert_equal expected, actual
2477
+
2478
+ @config['table_row_separator'] = 'singletab'
2479
+ actual = compile_block(src)
2480
+ expected = <<-EOS
2481
+ <div class="table">
2482
+ <table>
2483
+ <tr><th>1</th><th>2</th><th></th><th>3 4| 5</th></tr>
2484
+ <tr><td>a b</td><td>c d |e</td><td></td><td></td></tr>
2485
+ </table>
2486
+ </div>
2487
+ EOS
2488
+ assert_equal expected, actual
2489
+
2490
+ @config['table_row_separator'] = 'spaces'
2491
+ actual = compile_block(src)
2492
+ expected = <<-EOS
2493
+ <div class="table">
2494
+ <table>
2495
+ <tr><th>1</th><th>2</th><th>3</th><th>4|</th><th>5</th></tr>
2496
+ <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>|e</td></tr>
2497
+ </table>
2498
+ </div>
2499
+ EOS
2500
+ assert_equal expected, actual
2501
+
2502
+ @config['table_row_separator'] = 'verticalbar'
2503
+ actual = compile_block(src)
2504
+ expected = <<-EOS
2505
+ <div class="table">
2506
+ <table>
2507
+ <tr><th>1 2 3 4</th><th>5</th></tr>
2508
+ <tr><td>a b c d</td><td>e</td></tr>
2509
+ </table>
2510
+ </div>
2019
2511
  EOS
2020
2512
  assert_equal expected, actual
2021
2513
  end
@@ -2126,6 +2618,163 @@ EOS
2126
2618
  assert_equal expected, actual
2127
2619
  end
2128
2620
 
2621
+ def test_minicolumn_blocks
2622
+ %w[note memo tip info warning important caution notice].each do |type|
2623
+ src = <<-EOS
2624
+ //#{type}[#{type}1]{
2625
+
2626
+ //}
2627
+
2628
+ //#{type}[#{type}2]{
2629
+ //}
2630
+ EOS
2631
+
2632
+ expected = <<-EOS
2633
+ <div class="#{type}">
2634
+ <p class="caption">#{type}1</p>
2635
+ </div>
2636
+ <div class="#{type}">
2637
+ <p class="caption">#{type}2</p>
2638
+ </div>
2639
+ EOS
2640
+ assert_equal expected, compile_block(src)
2641
+
2642
+ src = <<-EOS
2643
+ //#{type}[#{type}2]{
2644
+
2645
+ //}
2646
+
2647
+ //#{type}[#{type}3]{
2648
+
2649
+ //}
2650
+
2651
+ //#{type}[#{type}4]{
2652
+
2653
+ //}
2654
+
2655
+ //#{type}[#{type}5]{
2656
+
2657
+ //}
2658
+
2659
+ //#{type}[#{type}6]{
2660
+
2661
+ //}
2662
+ EOS
2663
+
2664
+ expected = <<-EOS
2665
+ <div class="#{type}">
2666
+ <p class="caption">#{type}2</p>
2667
+ </div>
2668
+ <div class="#{type}">
2669
+ <p class="caption">#{type}3</p>
2670
+ </div>
2671
+ <div class="#{type}">
2672
+ <p class="caption">#{type}4</p>
2673
+ </div>
2674
+ <div class="#{type}">
2675
+ <p class="caption">#{type}5</p>
2676
+ </div>
2677
+ <div class="#{type}">
2678
+ <p class="caption">#{type}6</p>
2679
+ </div>
2680
+ EOS
2681
+ assert_equal expected, compile_block(src)
2682
+
2683
+ src = <<-EOS
2684
+ //#{type}{
2685
+
2686
+ * A
2687
+
2688
+ 1. B
2689
+
2690
+ //}
2691
+
2692
+ //#{type}[OMITEND1]{
2693
+
2694
+ //emlist{
2695
+ LIST
2696
+ //}
2697
+
2698
+ //}
2699
+
2700
+ //#{type}[OMITEND2]{
2701
+ //}
2702
+ EOS
2703
+
2704
+ expected = <<-EOS
2705
+ <div class="#{type}">
2706
+ <ul>
2707
+ <li>A</li>
2708
+ </ul>
2709
+ <ol>
2710
+ <li>B</li>
2711
+ </ol>
2712
+ </div>
2713
+ <div class="#{type}">
2714
+ <p class="caption">OMITEND1</p>
2715
+ <div class="emlist-code">
2716
+ <pre class="emlist">LIST
2717
+ </pre>
2718
+ </div>
2719
+ </div>
2720
+ <div class="#{type}">
2721
+ <p class="caption">OMITEND2</p>
2722
+ </div>
2723
+ EOS
2724
+ assert_equal expected, compile_block(src)
2725
+ end
2726
+ end
2727
+
2728
+ def test_minicolumn_blocks_nest_error1
2729
+ %w[note memo tip info warning important caution notice].each do |type|
2730
+ @builder.doc_status.clear
2731
+ src = <<-EOS
2732
+ //#{type}{
2733
+
2734
+ //#{type}{
2735
+ //}
2736
+
2737
+ //}
2738
+ EOS
2739
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2740
+ assert_match(/minicolumn cannot be nested:/, e.message)
2741
+ end
2742
+ end
2743
+
2744
+ def test_minicolumn_blocks_nest_error2
2745
+ %w[note memo tip info warning important caution notice].each do |type|
2746
+ @builder.doc_status.clear
2747
+ src = <<-EOS
2748
+ //#{type}{
2749
+
2750
+ //#{type}{
2751
+
2752
+ //}
2753
+
2754
+ //}
2755
+ EOS
2756
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2757
+ assert_match(/minicolumn cannot be nested:/, e.message)
2758
+ end
2759
+ end
2760
+
2761
+ def test_minicolumn_blocks_nest_error3
2762
+ %w[memo tip info warning important caution notice].each do |type|
2763
+ @builder.doc_status.clear
2764
+ src = <<-EOS
2765
+ //#{type}{
2766
+
2767
+ //note{
2768
+
2769
+ //}
2770
+
2771
+ //}
2772
+ EOS
2773
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2774
+ assert_match(/minicolumn cannot be nested:/, e.message)
2775
+ end
2776
+ end
2777
+
2129
2778
  def test_comment
2130
2779
  actual = compile_block('//comment[コメント]')
2131
2780
  assert_equal '', actual
@@ -2165,26 +2814,26 @@ EOB
2165
2814
  end
2166
2815
  @book.config['words_file'] = File.join(dir, 'words.csv')
2167
2816
  io = StringIO.new
2168
- @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) }
2817
+ @builder.instance_eval { @logger = ReVIEW::Logger.new(io) }
2169
2818
  actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
2170
2819
  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
2171
- assert_match(/WARN -- : :1: word not bound: N/, io.string)
2820
+ assert_match(/WARN --: :1: word not bound: N/, io.string)
2172
2821
  end
2173
2822
  end
2174
2823
 
2175
2824
  def test_inline_unknown
2176
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
2825
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2177
2826
  assert_equal ':1: error: unknown image: n', e.message
2178
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" }
2827
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2179
2828
  assert_equal ':1: error: unknown footnote: n', e.message
2180
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" }
2829
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2181
2830
  assert_equal ':1: error: unknown headline: n', e.message
2182
2831
  %w[list table column].each do |name|
2183
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
2832
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2184
2833
  assert_equal ":1: error: unknown #{name}: n", e.message
2185
2834
  end
2186
2835
  %w[chap chapref title].each do |name|
2187
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
2836
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2188
2837
  assert_equal ':1: error: key not found: "n"', e.message
2189
2838
  end
2190
2839
  end
@@ -2214,6 +2863,20 @@ e=mc^2
2214
2863
  //}
2215
2864
  EOS
2216
2865
  expected = <<-EOS
2866
+ <p><span class="eqref"><a href="./-.html#emc2">式1.1</a></span></p>
2867
+ <div id="emc2" class="caption-equation">
2868
+ <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2869
+ <div class="equation">
2870
+ <pre>e=mc^2
2871
+ </pre>
2872
+ </div>
2873
+ </div>
2874
+ EOS
2875
+ actual = compile_block(src)
2876
+ assert_equal expected, actual
2877
+
2878
+ @config['chapterlink'] = nil
2879
+ expected = <<-EOS
2217
2880
  <p><span class="eqref">式1.1</span></p>
2218
2881
  <div id="emc2" class="caption-equation">
2219
2882
  <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
@@ -2225,5 +2888,311 @@ EOS
2225
2888
  EOS
2226
2889
  actual = compile_block(src)
2227
2890
  assert_equal expected, actual
2891
+
2892
+ @config['caption_position']['equation'] = 'bottom'
2893
+ expected = <<-EOS
2894
+ <p><span class="eqref">式1.1</span></p>
2895
+ <div id="emc2" class="caption-equation">
2896
+ <div class="equation">
2897
+ <pre>e=mc^2
2898
+ </pre>
2899
+ </div>
2900
+ <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2901
+ </div>
2902
+ EOS
2903
+ actual = compile_block(src)
2904
+ assert_equal expected, actual
2905
+ end
2906
+
2907
+ def test_nest_error_close1
2908
+ src = <<-EOS
2909
+ //beginchild
2910
+ EOS
2911
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2912
+ assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2913
+ end
2914
+
2915
+ def test_nest_error_close2
2916
+ src = <<-EOS
2917
+ * foo
2918
+
2919
+ //beginchild
2920
+
2921
+ 1. foo
2922
+
2923
+ //beginchild
2924
+
2925
+ : foo
2926
+
2927
+ //beginchild
2928
+ EOS
2929
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2930
+ assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
2931
+ end
2932
+
2933
+ def test_nest_error_close3
2934
+ src = <<-EOS
2935
+ * foo
2936
+
2937
+ //beginchild
2938
+
2939
+ 1. foo
2940
+
2941
+ //beginchild
2942
+
2943
+ : foo
2944
+
2945
+ //beginchild
2946
+
2947
+ //endchild
2948
+ EOS
2949
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2950
+ assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
2951
+ end
2952
+
2953
+ def test_nest_ul
2954
+ src = <<-EOS
2955
+ * UL1
2956
+
2957
+ //beginchild
2958
+
2959
+ 1. UL1-OL1
2960
+ 2. UL1-OL2
2961
+
2962
+ * UL1-UL1
2963
+ * UL1-UL2
2964
+
2965
+ : UL1-DL1
2966
+ UL1-DD1
2967
+ : UL1-DL2
2968
+ UL1-DD2
2969
+
2970
+ //endchild
2971
+
2972
+ * UL2
2973
+
2974
+ //beginchild
2975
+
2976
+ UL2-PARA
2977
+
2978
+ //endchild
2979
+ EOS
2980
+
2981
+ expected = <<-EOS
2982
+ <ul>
2983
+ <li>UL1
2984
+ <ol>
2985
+ <li>UL1-OL1</li>
2986
+ <li>UL1-OL2</li>
2987
+ </ol>
2988
+ <ul>
2989
+ <li>UL1-UL1</li>
2990
+ <li>UL1-UL2</li>
2991
+ </ul>
2992
+ <dl>
2993
+ <dt>UL1-DL1</dt>
2994
+ <dd>UL1-DD1</dd>
2995
+ <dt>UL1-DL2</dt>
2996
+ <dd>UL1-DD2</dd>
2997
+ </dl>
2998
+ </li>
2999
+
3000
+ <li>UL2
3001
+ <p>UL2-PARA</p>
3002
+ </li>
3003
+ </ul>
3004
+ EOS
3005
+
3006
+ actual = compile_block(src)
3007
+ assert_equal expected, actual
3008
+ end
3009
+
3010
+ def test_nest_ol
3011
+ src = <<-EOS
3012
+ 1. OL1
3013
+
3014
+ //beginchild
3015
+
3016
+ 1. OL1-OL1
3017
+ 2. OL1-OL2
3018
+
3019
+ * OL1-UL1
3020
+ * OL1-UL2
3021
+
3022
+ : OL1-DL1
3023
+ OL1-DD1
3024
+ : OL1-DL2
3025
+ OL1-DD2
3026
+
3027
+ //endchild
3028
+
3029
+ 2. OL2
3030
+
3031
+ //beginchild
3032
+
3033
+ OL2-PARA
3034
+
3035
+ //endchild
3036
+ EOS
3037
+
3038
+ expected = <<-EOS
3039
+ <ol>
3040
+ <li>OL1
3041
+ <ol>
3042
+ <li>OL1-OL1</li>
3043
+ <li>OL1-OL2</li>
3044
+ </ol>
3045
+ <ul>
3046
+ <li>OL1-UL1</li>
3047
+ <li>OL1-UL2</li>
3048
+ </ul>
3049
+ <dl>
3050
+ <dt>OL1-DL1</dt>
3051
+ <dd>OL1-DD1</dd>
3052
+ <dt>OL1-DL2</dt>
3053
+ <dd>OL1-DD2</dd>
3054
+ </dl>
3055
+ </li>
3056
+
3057
+ <li>OL2
3058
+ <p>OL2-PARA</p>
3059
+ </li>
3060
+ </ol>
3061
+ EOS
3062
+
3063
+ actual = compile_block(src)
3064
+ assert_equal expected, actual
3065
+ end
3066
+
3067
+ def test_nest_dl
3068
+ src = <<-EOS
3069
+ : DL1
3070
+
3071
+ //beginchild
3072
+
3073
+ 1. DL1-OL1
3074
+ 2. DL1-OL2
3075
+
3076
+ * DL1-UL1
3077
+ * DL1-UL2
3078
+
3079
+ : DL1-DL1
3080
+ DL1-DD1
3081
+ : DL1-DL2
3082
+ DL1-DD2
3083
+
3084
+ //endchild
3085
+
3086
+ : DL2
3087
+ DD2
3088
+
3089
+ //beginchild
3090
+
3091
+ * DD2-UL1
3092
+ * DD2-UL2
3093
+
3094
+ DD2-PARA
3095
+
3096
+ //endchild
3097
+ EOS
3098
+
3099
+ expected = <<-EOS
3100
+ <dl>
3101
+ <dt>DL1</dt>
3102
+ <dd>
3103
+ <ol>
3104
+ <li>DL1-OL1</li>
3105
+ <li>DL1-OL2</li>
3106
+ </ol>
3107
+ <ul>
3108
+ <li>DL1-UL1</li>
3109
+ <li>DL1-UL2</li>
3110
+ </ul>
3111
+ <dl>
3112
+ <dt>DL1-DL1</dt>
3113
+ <dd>DL1-DD1</dd>
3114
+ <dt>DL1-DL2</dt>
3115
+ <dd>DL1-DD2</dd>
3116
+ </dl>
3117
+ </dd>
3118
+
3119
+ <dt>DL2</dt>
3120
+ <dd>DD2
3121
+ <ul>
3122
+ <li>DD2-UL1</li>
3123
+ <li>DD2-UL2</li>
3124
+ </ul>
3125
+ <p>DD2-PARA</p>
3126
+ </dd>
3127
+ </dl>
3128
+ EOS
3129
+
3130
+ actual = compile_block(src)
3131
+ assert_equal expected, actual
3132
+ end
3133
+
3134
+ def test_nest_multi
3135
+ src = <<-EOS
3136
+ 1. OL1
3137
+
3138
+ //beginchild
3139
+
3140
+ 1. OL1-OL1
3141
+
3142
+ //beginchild
3143
+
3144
+ * OL1-OL1-UL1
3145
+
3146
+ OL1-OL1-PARA
3147
+
3148
+ //endchild
3149
+
3150
+ 2. OL1-OL2
3151
+
3152
+ * OL1-UL1
3153
+
3154
+ //beginchild
3155
+
3156
+ : OL1-UL1-DL1
3157
+ OL1-UL1-DD1
3158
+
3159
+ OL1-UL1-PARA
3160
+
3161
+ //endchild
3162
+
3163
+ * OL1-UL2
3164
+
3165
+ //endchild
3166
+ EOS
3167
+ expected = <<-EOS
3168
+ <ol>
3169
+ <li>OL1
3170
+ <ol>
3171
+ <li>OL1-OL1
3172
+ <ul>
3173
+ <li>OL1-OL1-UL1</li>
3174
+ </ul>
3175
+ <p>OL1-OL1-PARA</p>
3176
+ </li>
3177
+
3178
+ <li>OL1-OL2</li>
3179
+ </ol>
3180
+ <ul>
3181
+ <li>OL1-UL1
3182
+ <dl>
3183
+ <dt>OL1-UL1-DL1</dt>
3184
+ <dd>OL1-UL1-DD1</dd>
3185
+ </dl>
3186
+ <p>OL1-UL1-PARA</p>
3187
+ </li>
3188
+
3189
+ <li>OL1-UL2</li>
3190
+ </ul>
3191
+ </li>
3192
+ </ol>
3193
+ EOS
3194
+
3195
+ actual = compile_block(src)
3196
+ assert_equal expected, actual
2228
3197
  end
2229
3198
  end