review 4.2.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-win.yml +11 -5
  3. data/.rubocop.yml +113 -24
  4. data/NEWS.ja.md +94 -0
  5. data/NEWS.md +94 -0
  6. data/bin/review-catalog-converter +1 -1
  7. data/bin/review-check +2 -4
  8. data/bin/review-checkdep +1 -1
  9. data/bin/review-compile +8 -14
  10. data/bin/review-validate +1 -1
  11. data/doc/config.yml.sample +4 -1
  12. data/doc/config.yml.sample-simple +1 -1
  13. data/doc/format.ja.md +83 -4
  14. data/doc/format.md +84 -7
  15. data/doc/makeindex.ja.md +2 -2
  16. data/doc/quickstart.ja.md +3 -3
  17. data/doc/quickstart.md +2 -2
  18. data/lib/epubmaker/content.rb +3 -2
  19. data/lib/epubmaker/epubcommon.rb +33 -25
  20. data/lib/epubmaker/epubv2.rb +5 -6
  21. data/lib/epubmaker/epubv3.rb +20 -18
  22. data/lib/review/book.rb +2 -2
  23. data/lib/review/book/base.rb +61 -25
  24. data/lib/review/book/bib.rb +21 -0
  25. data/lib/review/book/book_unit.rb +155 -0
  26. data/lib/review/book/chapter.rb +30 -26
  27. data/lib/review/book/index.rb +23 -185
  28. data/lib/review/book/index/item.rb +7 -1
  29. data/lib/review/book/part.rb +21 -9
  30. data/lib/review/book/volume.rb +1 -1
  31. data/lib/review/builder.rb +68 -13
  32. data/lib/review/catalog.rb +2 -2
  33. data/lib/review/compiler.rb +159 -73
  34. data/lib/review/configure.rb +22 -1
  35. data/lib/review/converter.rb +1 -1
  36. data/lib/review/epub2html.rb +6 -1
  37. data/lib/review/epubmaker.rb +12 -23
  38. data/lib/review/htmlbuilder.rb +36 -7
  39. data/lib/review/htmlutils.rb +7 -10
  40. data/lib/review/i18n.rb +1 -1
  41. data/lib/review/idgxmlbuilder.rb +51 -6
  42. data/lib/review/idgxmlmaker.rb +9 -14
  43. data/lib/review/index_builder.rb +653 -0
  44. data/lib/review/init.rb +5 -13
  45. data/lib/review/latexbuilder.rb +65 -4
  46. data/lib/review/logger.rb +2 -2
  47. data/lib/review/makerhelper.rb +11 -0
  48. data/lib/review/markdownbuilder.rb +19 -1
  49. data/lib/review/pdfmaker.rb +17 -36
  50. data/lib/review/plaintextbuilder.rb +48 -2
  51. data/lib/review/preprocessor.rb +5 -5
  52. data/lib/review/rstbuilder.rb +25 -6
  53. data/lib/review/sec_counter.rb +13 -0
  54. data/lib/review/textmaker.rb +4 -12
  55. data/lib/review/tocprinter.rb +2 -3
  56. data/lib/review/topbuilder.rb +26 -0
  57. data/lib/review/update.rb +7 -7
  58. data/lib/review/version.rb +1 -1
  59. data/lib/review/volumeprinter.rb +2 -3
  60. data/lib/review/webmaker.rb +9 -20
  61. data/review.gemspec +2 -2
  62. data/samples/sample-book/src/config.yml +1 -1
  63. data/samples/syntax-book/Gemfile +1 -1
  64. data/samples/syntax-book/config.yml +1 -1
  65. data/templates/latex/config.erb +27 -23
  66. data/templates/latex/review-jlreq/README.md +3 -1
  67. data/templates/latex/review-jlreq/review-base.sty +31 -15
  68. data/templates/latex/review-jlreq/review-jlreq.cls +8 -24
  69. data/templates/latex/review-jsbook/README.md +7 -5
  70. data/templates/latex/review-jsbook/review-base.sty +34 -16
  71. data/templates/latex/review-jsbook/review-jsbook.cls +4 -2
  72. data/templates/web/html/layout-html5.html.erb +1 -1
  73. data/test/assets/test_template.tex +3 -3
  74. data/test/assets/test_template_backmatter.tex +3 -3
  75. data/test/book_test_helper.rb +11 -5
  76. data/test/test_book.rb +54 -63
  77. data/test/test_book_chapter.rb +93 -52
  78. data/test/test_builder.rb +24 -15
  79. data/test/test_converter.rb +1 -0
  80. data/test/test_epub3maker.rb +2 -2
  81. data/test/test_epubmaker.rb +8 -0
  82. data/test/test_helper.rb +4 -1
  83. data/test/test_htmlbuilder.rb +627 -56
  84. data/test/test_htmlutils.rb +0 -12
  85. data/test/test_i18n.rb +33 -33
  86. data/test/test_idgxmlbuilder.rb +358 -11
  87. data/test/test_idgxmlmaker_cmd.rb +1 -1
  88. data/test/test_index.rb +62 -52
  89. data/test/test_indexbuilder.rb +52 -0
  90. data/test/test_latexbuilder.rb +547 -10
  91. data/test/test_latexbuilder_v2.rb +43 -5
  92. data/test/test_logger.rb +7 -7
  93. data/test/test_makerhelper.rb +0 -12
  94. data/test/test_markdownbuilder.rb +3 -0
  95. data/test/test_pdfmaker.rb +13 -12
  96. data/test/test_pdfmaker_cmd.rb +1 -1
  97. data/test/test_plaintextbuilder.rb +422 -7
  98. data/test/test_review_ext.rb +2 -1
  99. data/test/test_rstbuilder.rb +25 -1
  100. data/test/test_sec_counter.rb +156 -0
  101. data/test/test_textmaker_cmd.rb +1 -1
  102. data/test/test_topbuilder.rb +187 -10
  103. data/test/test_update.rb +10 -10
  104. data/test/test_webtocprinter.rb +12 -12
  105. data/vendor/gentombow/LICENSE +1 -1
  106. data/vendor/gentombow/Makefile +0 -1
  107. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  108. data/vendor/gentombow/bounddvi-en.tex +1 -0
  109. data/vendor/gentombow/bounddvi.pdf +0 -0
  110. data/vendor/gentombow/bounddvi.sty +30 -7
  111. data/vendor/gentombow/bounddvi.tex +1 -0
  112. data/vendor/gentombow/create_archive.sh +1 -0
  113. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  114. data/vendor/gentombow/gentombow-ja.tex +9 -0
  115. data/vendor/gentombow/gentombow.pdf +0 -0
  116. data/vendor/gentombow/gentombow.sty +32 -10
  117. data/vendor/gentombow/gentombow.tex +8 -0
  118. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  119. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  120. data/vendor/jsclasses/Makefile +3 -2
  121. data/vendor/jsclasses/create_archive.sh +5 -5
  122. data/vendor/jsclasses/jis/Makefile +3 -2
  123. data/vendor/jsclasses/jis/jsarticle.cls +22 -18
  124. data/vendor/jsclasses/jis/jsbook.cls +22 -18
  125. data/vendor/jsclasses/jis/jsclasses.dtx +94 -13
  126. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  127. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  128. data/vendor/jsclasses/jis/jslogo.sty +1 -13
  129. data/vendor/jsclasses/jis/jspf.cls +22 -18
  130. data/vendor/jsclasses/jis/jsreport.cls +22 -18
  131. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  132. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  133. data/vendor/jsclasses/jis/kiyou.cls +22 -18
  134. data/vendor/jsclasses/jis/minijs.sty +65 -22
  135. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  136. data/vendor/jsclasses/jis/okumacro.sty +1 -13
  137. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  138. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  139. data/vendor/jsclasses/jis/winjis.sty +23 -19
  140. data/vendor/jsclasses/jsarticle.cls +22 -18
  141. data/vendor/jsclasses/jsbook.cls +22 -18
  142. data/vendor/jsclasses/jsclasses.dtx +94 -13
  143. data/vendor/jsclasses/jsclasses.ins +15 -5
  144. data/vendor/jsclasses/jsclasses.pdf +0 -0
  145. data/vendor/jsclasses/jslogo.ins +9 -0
  146. data/vendor/jsclasses/jslogo.pdf +0 -0
  147. data/vendor/jsclasses/jslogo.sty +1 -13
  148. data/vendor/jsclasses/jspf.cls +22 -18
  149. data/vendor/jsclasses/jsreport.cls +22 -18
  150. data/vendor/jsclasses/jsverb.ins +9 -0
  151. data/vendor/jsclasses/jsverb.pdf +0 -0
  152. data/vendor/jsclasses/jsverb.sty +1 -13
  153. data/vendor/jsclasses/kiyou.cls +22 -18
  154. data/vendor/jsclasses/minijs.sty +68 -22
  155. data/vendor/jsclasses/okumacro.ins +9 -0
  156. data/vendor/jsclasses/okumacro.pdf +0 -0
  157. data/vendor/jsclasses/okumacro.sty +1 -13
  158. data/vendor/jsclasses/okuverb.ins +9 -0
  159. data/vendor/jsclasses/okuverb.pdf +0 -0
  160. data/vendor/jsclasses/okuverb.sty +1 -13
  161. data/vendor/jsclasses/tests/relfont.tex +10 -0
  162. data/vendor/jsclasses/winjis.sty +23 -19
  163. metadata +14 -6
  164. data/.rubocop_todo.yml +0 -7
  165. data/lib/review/book/compilable.rb +0 -174
@@ -2,6 +2,10 @@ require 'book_test_helper'
2
2
  class ChapterTest < Test::Unit::TestCase
3
3
  include BookTestHelper
4
4
 
5
+ def setup
6
+ I18n.setup
7
+ end
8
+
5
9
  def test_initialize
6
10
  ch = Book::Chapter.new(:book, :number, :name, '/foo/bar', :io)
7
11
  assert_equal :book, ch.book
@@ -66,6 +70,7 @@ class ChapterTest < Test::Unit::TestCase
66
70
 
67
71
  book = Book::Base.new
68
72
  ch = Book::Chapter.new(book, nil, nil, tf.path)
73
+ ch.generate_indexes
69
74
  assert_equal lines, ch.lines
70
75
 
71
76
  lines = ["1\n", "2\n", '3']
@@ -78,6 +83,7 @@ class ChapterTest < Test::Unit::TestCase
78
83
  tf2.close
79
84
 
80
85
  ch = Book::Chapter.new(book, nil, nil, tf1.path, tf2.path)
86
+ ch.generate_indexes
81
87
  assert_equal lines, ch.lines # XXX: OK?
82
88
  end
83
89
 
@@ -103,19 +109,19 @@ class ChapterTest < Test::Unit::TestCase
103
109
  end
104
110
 
105
111
  def test_on_chaps?
106
- mktmpbookdir 'CHAPS' => "chapter1.re\nchapter2.re",
107
- 'chapter1.re' => '12345', 'preface.re' => 'abcde' do |dir, book, files|
112
+ mktmpbookdir('CHAPS' => "chapter1.re\nchapter2.re",
113
+ 'chapter1.re' => '12345', 'preface.re' => 'abcde') do |dir, book, files|
108
114
  ch1 = Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
109
115
  pre = Book::Chapter.new(book, nil, 'preface', files['preface.re'])
110
116
 
111
117
  assert ch1.on_chaps?
112
118
  assert !pre.on_chaps?
113
119
 
114
- ch2_path = File.join(dir, 'chapter2.er')
120
+ ch2_path = File.join(dir, 'chapter2.re')
115
121
  File.open(ch2_path, 'w') {}
116
122
  ch2 = Book::Chapter.new(book, 2, 'chapter2', ch2_path)
117
123
 
118
- ch3_path = File.join(dir, 'chapter3.er')
124
+ ch3_path = File.join(dir, 'chapter3.re')
119
125
  File.open(ch3_path, 'w') {}
120
126
  ch3 = Book::Chapter.new(book, 3, 'chapter3', ch3_path)
121
127
 
@@ -124,50 +130,70 @@ class ChapterTest < Test::Unit::TestCase
124
130
  end
125
131
  end
126
132
 
133
+ def test_invalid_encoding
134
+ mktmpbookdir('CHAPS' => 'chapter1.re',
135
+ 'chapter1.re' => "= 日本語UTF-8\n") do |_dir, book, files|
136
+ assert Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
137
+ end
138
+
139
+ # UTF-16LE UTF-16BE UTF-32LE UTF-32BE cause error on Windows
140
+ %w[CP932 SHIFT_JIS EUC-JP].each do |enc|
141
+ mktmpbookdir('CHAPS' => 'chapter1.re',
142
+ 'chapter1.re' => "= 日本語UTF-8\n".encode(enc)) do |_dir, book, files|
143
+ e = assert_raises(ReVIEW::CompileError) { Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re']) }
144
+ assert_equal 'chapter1: invalid byte sequence in UTF-8', e.message
145
+ end
146
+ end
147
+ end
148
+
127
149
  def test_list_index
128
150
  do_test_index(<<E, Book::ListIndex, :list_index, :list)
129
- //list
130
- //listnum [abc]
131
- //list [def]
132
- //table [def]
133
- //table [others]
151
+ //listnum[abc][abc-listnum]{
152
+ //}
153
+ //list[def][def-list]{
154
+ //}
155
+ //table[def]{
156
+ //}
157
+ //table[others]{
158
+ //}
134
159
  E
135
160
  end
136
161
 
137
162
  def test_table_index
138
163
  do_test_index(<<E, Book::TableIndex, :table_index, :table)
139
- //table
140
- //table [abc]
141
- //table [def]
142
- //list [def]
143
- //list [others]
164
+ //table[abc]{
165
+ //}
166
+ //table[def]{
167
+ //}
168
+ //list[def][def-list]{
169
+ //}
170
+ //list[others][other-list]{
171
+ //}
144
172
  E
145
173
  end
146
174
 
147
175
  def test_footnote_index
148
176
  content = <<E
149
- //footnote
150
- //footnote [abc][text...]
151
- //footnote [def][text...]
152
- //footnote [xyz]
153
- //list [def]
154
- //list [others]
177
+ //footnote[abc][textabc...]
178
+ //footnote[def][textdef...]
179
+ //footnote[xyz][textxyz...]
180
+ //list[def][def-list]{
181
+ //}
182
+ //list[others][others-list]{
183
+ //}
155
184
  E
156
185
  do_test_index(content, Book::FootnoteIndex, :footnote_index, :footnote) do |ch|
157
186
  assert_raises ReVIEW::KeyError do
158
- ch.footnote('xyz')
187
+ ch.footnote('xyz2')
159
188
  end
160
189
  end
161
190
  end
162
191
 
163
192
  def test_bibpaper
164
193
  do_test_index(<<E, Book::BibpaperIndex, :bibpaper_index, :bibpaper, filename: 'bib.re')
165
- //bibpaper
166
- //bibpaper [abc][text...]
167
- //bibpaper [def][text...]
168
- //bibpaper [xyz]
169
- //list [def]
170
- //list [others]
194
+ //bibpaper[abc][text...]
195
+ //bibpaper[def][text...]
196
+ //bibpaper[xyz][text...]
171
197
  E
172
198
  assert_raises FileNotFound do
173
199
  do_test_index('', Book::BibpaperIndex, :bibpaper_index, :bibpaper, filename: 'bib')
@@ -176,11 +202,12 @@ E
176
202
 
177
203
  def test_headline_index
178
204
  do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, propagate: false)
179
- ==
205
+ == x
180
206
  == abc
181
207
  == def
182
208
  === def
183
- //table others
209
+ //table[others]{
210
+ //}
184
211
  E
185
212
  end
186
213
 
@@ -204,35 +231,47 @@ E
204
231
 
205
232
  def test_image
206
233
  do_test_index(<<E, Book::ImageIndex, :image_index, :image)
207
- //image
208
- //image [abc]
209
- //image [def]
210
- //list [def]
211
- //list [others]
234
+ //image[abc][abc-image]{
235
+ //}
236
+ //image[def][abc-image]{
237
+ //}
238
+ //list[def][def-list]{
239
+ //}
240
+ //list[others][others-list]{
241
+ //}
212
242
  E
213
243
 
214
244
  do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, propagate: false)
215
- //numberlessimage
216
- //numberlessimage [abc]
217
- //numberlessimage [def]
218
- //list [def]
219
- //list [others]
245
+ //numberlessimage[abc]{
246
+ //}
247
+ //numberlessimage[def]{
248
+ //}
249
+ //list[def][def-list]{
250
+ //}
251
+ //list[others][others-list]{
252
+ //}
220
253
  E
221
254
 
222
255
  do_test_index(<<E, Book::ImageIndex, :image_index, :image)
223
- //image
224
- //numberlessimage [abc]
225
- //image [def]
226
- //list [def]
227
- //list [others]
256
+ //numberlessimage[abc]{
257
+ //}
258
+ //image[def][def-image]{
259
+ //}
260
+ //list[def][def-list]{
261
+ //}
262
+ //list[others][others-list]{
263
+ //}
228
264
  E
229
265
 
230
266
  do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, propagate: false)
231
- //image
232
- //numberlessimage [abc]
233
- //image [def]
234
- //list [def]
235
- //list [others]
267
+ //numberlessimage[abc]{
268
+ //}
269
+ //image[def][def-image]{
270
+ //}
271
+ //list[def][def-list]{
272
+ //}
273
+ //list[others][others-list]{
274
+ //}
236
275
  E
237
276
  end
238
277
 
@@ -240,13 +279,15 @@ E
240
279
  Dir.mktmpdir do |dir|
241
280
  path = File.join(dir, opts[:filename] || 'chapter.re')
242
281
 
243
- book = Book::Base.new(dir)
244
-
245
282
  File.open(path, 'w') do |o|
246
283
  o.print content
247
284
  end
248
- ch = Book::Chapter.new(book, 1, 'chapter', path)
249
285
 
286
+ book = Book::Base.new(dir)
287
+
288
+ ch = Book::Chapter.new(book, 1, 'chapter', path)
289
+ book.generate_indexes
290
+ ch.generate_indexes
250
291
  assert ch.__send__(ref_method, 'abc')
251
292
  assert ch.__send__(ref_method, 'def')
252
293
  assert_raises ReVIEW::KeyError do
@@ -24,7 +24,7 @@ class BuidlerTest < Test::Unit::TestCase
24
24
 
25
25
  def test_bind
26
26
  b = Builder.new
27
- chap = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load, nil, '-', nil)
27
+ chap = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.new, nil, '-', nil)
28
28
  assert_nothing_raised do
29
29
  b.bind(nil, chap, nil)
30
30
  end
@@ -37,7 +37,7 @@ class BuidlerTest < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  b = Builder.new
40
- chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load, nil, '-', nil)
40
+ chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.new, nil, '-', nil)
41
41
  b.bind(nil, chapter, nil)
42
42
  assert_equal '', b.result
43
43
  end
@@ -82,7 +82,7 @@ class BuidlerTest < Test::Unit::TestCase
82
82
 
83
83
  def test_inline_missing_ref
84
84
  b = Builder.new
85
- chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load, 1, 'chap1', nil, StringIO.new)
85
+ chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.new, 1, 'chap1', nil, StringIO.new)
86
86
  b.bind(nil, chapter, nil)
87
87
  e = assert_raises(ReVIEW::ApplicationError) { b.inline_list('unknown|list1') }
88
88
  assert_equal ': error: unknown list: unknown|list1', e.message
@@ -96,20 +96,29 @@ class BuidlerTest < Test::Unit::TestCase
96
96
  assert_equal ': error: unknown footnote: unknown|footnote1', e.message
97
97
  end
98
98
 
99
- class XBuilder < Builder
100
- def list_header(id, caption)
101
- end
102
-
103
- def list_body(lines)
104
- end
105
-
106
- def listnum_body(lines)
107
- end
99
+ def test_nest_error
100
+ b = XBuilder.new
101
+ b.children = nil
102
+ assert_equal '', b.solve_nest('')
103
+ b.children = ['dl']
104
+ e = assert_raises(ReVIEW::ApplicationError) { b.solve_nest('') }
105
+ assert_equal ': error: //beginchild of dl misses //endchild', e.message
106
+ b.children = ['ul', 'dl', 'ol']
107
+ e = assert_raises(ReVIEW::ApplicationError) { b.solve_nest('') }
108
+ assert_equal ': error: //beginchild of ol,dl,ul misses //endchild', e.message
109
+
110
+ assert_equal "\u0001→/ol←\u0001", b.endchild
111
+ assert_equal "\u0001→/dl←\u0001", b.endchild
112
+ assert_equal "\u0001→/ul←\u0001", b.endchild
113
+ e = assert_raises(ReVIEW::ApplicationError) { b.endchild }
114
+ assert_equal ": error: //endchild is shown, but any opened //beginchild doesn't exist", e.message
115
+ end
108
116
 
109
- def source_header(caption)
110
- end
117
+ class XBuilder < Builder
118
+ attr_accessor :children
111
119
 
112
- def source_body(lines)
120
+ def puts(s)
121
+ s
113
122
  end
114
123
  end
115
124
  end
@@ -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,7 +16,7 @@ def prepare_samplebook(srcdir, bookdir, latextemplatedir, configfile)
16
16
  samplebook_dir = File.expand_path("../samples/#{bookdir}/", File.dirname(__FILE__))
17
17
  files = Dir.glob(File.join(samplebook_dir, '*'))
18
18
  # ignore temporary built files
19
- files.delete_if { |file| file =~ /.*\-(pdf|epub|text)/ || file == 'webroot' }
19
+ files.delete_if { |file| file =~ /.*-(pdf|epub|text)/ || file == 'webroot' }
20
20
  FileUtils.cp_r(files, srcdir)
21
21
  if latextemplatedir
22
22
  # copy from review-jsbook or review-jlreq
@@ -39,11 +39,13 @@ end
39
39
 
40
40
  def compile_block_default(text)
41
41
  @chapter.content = text
42
+ @chapter.execute_indexer(force: true)
42
43
  @compiler.compile(@chapter)
43
44
  end
44
45
 
45
46
  def compile_block_html(text)
46
47
  @chapter.content = text
48
+ @chapter.execute_indexer(force: true)
47
49
  matched = @compiler.compile(@chapter).match(Regexp.new(%Q(<body>\n(.+)</body>), Regexp::MULTILINE))
48
50
  if matched && matched.size > 1
49
51
  matched[1]
@@ -54,5 +56,6 @@ end
54
56
 
55
57
  def compile_block_idgxml(text)
56
58
  @chapter.content = text
59
+ @chapter.execute_indexer(force: true)
57
60
  @compiler.compile(@chapter).gsub(Regexp.new(%Q(.*<doc xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">), Regexp::MULTILINE), '').gsub("</doc>\n", '')
58
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
@@ -250,6 +250,15 @@ EOS
250
250
  idx
251
251
  end
252
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
253
262
  @config['secnolevel'] = 2
254
263
  actual = compile_inline('test @<hd>{chap1|test} test2')
255
264
  assert_equal 'test 「te_st」 test2', actual
@@ -263,7 +272,7 @@ EOS
263
272
  Dir.mktmpdir do |dir|
264
273
  Dir.chdir(dir) do
265
274
  file = File.join(dir, 'locale.yml')
266
- File.open(file, 'w') { |f| f.write "locale: ja\nappendix: 付録%pR" }
275
+ File.write(file, "locale: ja\nappendix: 付録%pR")
267
276
  I18n.setup('ja')
268
277
  @chapter.instance_eval do
269
278
  def on_appendix?
@@ -278,6 +287,10 @@ EOS
278
287
  idx
279
288
  end
280
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
281
294
  actual = compile_inline('test @<hd>{test} test2')
282
295
  assert_equal 'test 「I.1 te_st」 test2', actual
283
296
  end
@@ -288,7 +301,7 @@ EOS
288
301
  Dir.mktmpdir do |dir|
289
302
  Dir.chdir(dir) do
290
303
  file = File.join(dir, 'locale.yml')
291
- File.open(file, 'w') { |f| f.write "locale: ja\nappendix: 付録%pA" }
304
+ File.write(file, "locale: ja\nappendix: 付録%pA")
292
305
  I18n.setup('ja')
293
306
  @chapter.instance_eval do
294
307
  def on_appendix?
@@ -303,6 +316,10 @@ EOS
303
316
  idx
304
317
  end
305
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
306
323
  actual = compile_inline('test @<hd>{test} test2')
307
324
  assert_equal 'test 「A.1 te_st」 test2', actual
308
325
  end
@@ -354,6 +371,11 @@ EOS
354
371
  item
355
372
  end
356
373
 
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
357
379
  actual = compile_block("@<img>{sampleimg}\n")
358
380
  expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
359
381
  assert_equal expected, actual
@@ -366,6 +388,11 @@ EOS
366
388
  item
367
389
  end
368
390
 
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
369
396
  actual = compile_block("@<imgref>{sampleimg}\n")
370
397
  expected = %Q(<p><span class="imgref">図1.1</span>「sample photo」</p>\n)
371
398
  assert_equal expected, actual
@@ -378,6 +405,11 @@ EOS
378
405
  item
379
406
  end
380
407
 
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
381
413
  actual = compile_block("@<imgref>{sampleimg}\n")
382
414
  expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
383
415
  assert_equal expected, actual
@@ -389,20 +421,24 @@ EOS
389
421
  file1 = File.join(dir, 'images', 'img1.png')
390
422
  filet1 = File.join(dir, 'images', 'tbl1.png')
391
423
  file2 = File.join(dir, 'images', 'img2.png')
424
+ file3 = File.join(dir, 'images', 'icon3.png')
392
425
  re1 = File.join(dir, 'sample1.re')
393
426
  cat = File.join(dir, 'catalog.yml')
394
427
  FileUtils.mkdir_p(File.join(dir, 'images'))
395
- File.open(file1, 'w') { |f| f.write '' }
396
- File.open(filet1, 'w') { |f| f.write '' }
397
- File.open(file2, 'w') { |f| f.write '' }
398
- File.open(cat, 'w') { |f| f.write "CHAPS:\n - sample1.re\n" }
399
- 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)
400
434
  = test
401
435
 
402
436
  tbl1 is @<table>{tbl1}.
403
437
 
404
438
  img2 is @<img>{img2}.
405
439
 
440
+ icon3 is @<icon>{icon3}.
441
+
406
442
  //image[img1][image 1]{
407
443
  //}
408
444
 
@@ -417,8 +453,37 @@ EOF
417
453
 
418
454
  expected = <<-EOS
419
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>
420
484
  <p>tbl1 is <span class="tableref">表1.1</span>.</p>
421
485
  <p>img2 is <span class="imgref">図1.2</span>.</p>
486
+ <p>icon3 is <img src="images/icon3.png" alt="[icon3]" />.</p>
422
487
  <div id="img1" class="image">
423
488
  <img src="images/img1.png" alt="image 1" />
424
489
  <p class="caption">
@@ -600,21 +665,22 @@ EOS
600
665
  assert_equal expected, actual
601
666
  end
602
667
 
603
- def test_image_with_tricky_id
668
+ def test_image_with_tricky_id_kana
604
669
  def @chapter.image(_id)
605
- item = Book::Index::Item.new('123 あ_;', 1)
606
- item.instance_eval { @path = './images/chap1-123 あ_;.png' }
670
+ item = Book::Index::Item.new('123あいう', 1)
671
+ item.instance_eval { @path = './images/123あいう.png' }
607
672
  item
608
673
  end
609
-
610
- actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
674
+ @chapter.instance_eval { @name = 'ch01' }
675
+ actual = compile_block("//image[123あいう][sample photo]{\n//}\nimg: @<img>{123あいう}\n")
611
676
  expected = <<-EOS
612
- <div id="id_123-_E3_81_82___3B" class="image">
613
- <img src="images/chap1-123 あ_;.png" alt="sample photo" />
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" />
614
679
  <p class="caption">
615
680
  図1.1: sample photo
616
681
  </p>
617
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>
618
684
  EOS
619
685
  assert_equal expected, actual
620
686
  end
@@ -803,11 +869,10 @@ EOS
803
869
  end
804
870
 
805
871
  def test_dt_inline
806
- fn = Book::FootnoteIndex.parse(['//footnote[bar][bar]'])
807
- @chapter.instance_eval { @footnote_index = fn }
808
- actual = compile_block(" : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
872
+ actual = compile_block("//footnote[bar][bar]\n\n : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
809
873
 
810
874
  expected = <<-EOS
875
+ <div class="footnote" epub:type="footnote" id="fn-bar"><p class="footnote">[*1] bar</p></div>
811
876
  <dl>
812
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>
813
878
  <dd></dd>
@@ -852,22 +917,28 @@ EOS
852
917
  def @chapter.list(_id)
853
918
  Book::Index::Item.new('samplelist', 1)
854
919
  end
855
- 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")
856
925
  assert_equal %Q(<p><span class="listref">リスト1.1</span></p>\n), actual
857
926
  end
858
927
 
859
928
  def test_inline_list_href
860
- book = ReVIEW::Book::Base.load
929
+ book = ReVIEW::Book::Base.new
861
930
  book.config['chapterlink'] = true
862
931
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
863
- io1 = StringIO.new("//list[sampletest]{\nfoo\n//}\n")
932
+ io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n")
864
933
  io2 = StringIO.new("= BAR\n")
865
934
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
866
935
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
867
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
936
+ book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
868
937
  builder = ReVIEW::HTMLBuilder.new
869
938
  comp = ReVIEW::Compiler.new(builder)
870
939
  builder.bind(comp, chap2, nil)
940
+
941
+ chap1.generate_indexes
871
942
  actual = builder.inline_list('ch1|sampletest')
872
943
  assert_equal %Q(<span class="listref"><a href="./ch1.html#sampletest">リスト1.1</a></span>), actual
873
944
  end
@@ -1771,6 +1842,20 @@ EOS
1771
1842
  <p>inside column</p>
1772
1843
  </div>
1773
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
+
1774
1859
  <h3><a id="h1-0-1"></a>next level</h3>
1775
1860
  <p>this is コラム「test」.</p>
1776
1861
  EOS
@@ -1786,6 +1871,11 @@ EOS
1786
1871
  idx
1787
1872
  end
1788
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
1789
1879
  actual = compile_inline('test @<column>{chap1|column} test2')
1790
1880
  expected = 'test コラム「column_cap」 test2'
1791
1881
  assert_equal expected, actual
@@ -2083,8 +2173,6 @@ EOS
2083
2173
  end
2084
2174
 
2085
2175
  def test_footnote
2086
- fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
2087
- @chapter.instance_eval { @footnote_index = fn }
2088
2176
  actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
2089
2177
  expected = <<-'EOS'
2090
2178
  <div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote">[*1] bar\a\$buz</p></div>
@@ -2109,58 +2197,69 @@ EOS
2109
2197
  end
2110
2198
 
2111
2199
  def test_footnote_with_tricky_id
2112
- fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
2113
- @chapter.instance_eval { @footnote_index = fn }
2114
- actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
2200
+ actual = compile_block("//footnote[123あ_;][bar\\a\\$buz]\n")
2115
2201
  expected = <<-'EOS'
2116
- <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>
2117
2203
  EOS
2118
2204
  assert_equal expected, actual
2119
2205
  end
2120
2206
 
2121
2207
  def test_inline_fn
2122
- book = ReVIEW::Book::Base.load
2123
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re])
2124
- io1 = StringIO.new("//footnote[foo][bar]\n")
2125
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
2126
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1])]
2127
- builder = ReVIEW::HTMLBuilder.new
2128
- comp = ReVIEW::Compiler.new(builder)
2129
- builder.bind(comp, chap1, nil)
2130
- fn = builder.inline_fn('foo')
2131
- 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
2132
2214
  I18n.set('html_footnote_refmark', '+%s')
2133
- fn = builder.inline_fn('foo')
2134
- 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
2135
2221
  end
2136
2222
 
2137
2223
  def test_inline_hd
2138
- book = ReVIEW::Book::Base.load
2224
+ book = ReVIEW::Book::Base.new
2139
2225
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
2140
2226
  io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
2141
2227
  io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
2142
2228
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
2143
2229
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
2144
- book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
2230
+ book.parts = [ReVIEW::Book::Part.new(book, nil, [chap1, chap2])]
2145
2231
  builder = ReVIEW::HTMLBuilder.new
2146
2232
  comp = ReVIEW::Compiler.new(builder)
2147
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 }
2148
2241
  hd = builder.inline_hd('ch1|test1-1')
2149
2242
  assert_equal '「1.1 test1-1」', hd
2150
2243
  end
2151
2244
 
2152
2245
  def test_inline_hd_for_part
2153
- book = ReVIEW::Book::Base.load
2246
+ book = ReVIEW::Book::Base.new
2154
2247
  book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
2155
2248
  io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
2156
2249
  io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
2157
2250
  io_p1 = StringIO.new("= part1\n\nfoo\n\n== part1-1\n\nbar\n\n== part1-2\n\nbar\n\n")
2158
2251
  chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
2159
2252
  chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
2160
- 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)]
2161
2254
  builder = ReVIEW::HTMLBuilder.new
2162
2255
  comp = ReVIEW::Compiler.new(builder)
2163
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 }
2164
2263
  hd = builder.inline_hd('part1|part1-1')
2165
2264
  assert_equal '「1.1 part1-1」', hd
2166
2265
  end
@@ -2171,7 +2270,12 @@ EOS
2171
2270
  location = Location.new(nil, nil)
2172
2271
  @builder.bind(@compiler, chap1, location)
2173
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')
2174
2277
  assert_equal '「1.1 foo」', hd
2278
+
2175
2279
  hd = @builder.inline_hd('bar')
2176
2280
  assert_equal '「1.2 bar」', hd
2177
2281
  end
@@ -2215,10 +2319,10 @@ EOS
2215
2319
  end
2216
2320
 
2217
2321
  def test_empty_table
2218
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "//table{\n//}\n" }
2322
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
2219
2323
  assert_equal ':2: error: no rows in the table', e.message
2220
2324
 
2221
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "//table{\n------------\n//}\n" }
2325
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
2222
2326
  assert_equal ':3: error: no rows in the table', e.message
2223
2327
  end
2224
2328
 
@@ -2227,6 +2331,10 @@ EOS
2227
2331
  Book::Index::Item.new('sampletable', 1)
2228
2332
  end
2229
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")
2230
2338
  assert_equal %Q(<p><span class="tableref">表1.1</span></p>\n), actual
2231
2339
  end
2232
2340
 
@@ -2452,6 +2560,163 @@ EOS
2452
2560
  assert_equal expected, actual
2453
2561
  end
2454
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
+
2455
2720
  def test_comment
2456
2721
  actual = compile_block('//comment[コメント]')
2457
2722
  assert_equal '', actual
@@ -2499,18 +2764,18 @@ EOB
2499
2764
  end
2500
2765
 
2501
2766
  def test_inline_unknown
2502
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
2767
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2503
2768
  assert_equal ':1: error: unknown image: n', e.message
2504
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" }
2769
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2505
2770
  assert_equal ':1: error: unknown footnote: n', e.message
2506
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" }
2771
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2507
2772
  assert_equal ':1: error: unknown headline: n', e.message
2508
2773
  %w[list table column].each do |name|
2509
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
2774
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2510
2775
  assert_equal ":1: error: unknown #{name}: n", e.message
2511
2776
  end
2512
2777
  %w[chap chapref title].each do |name|
2513
- e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
2778
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2514
2779
  assert_equal ':1: error: key not found: "n"', e.message
2515
2780
  end
2516
2781
  end
@@ -2540,6 +2805,20 @@ e=mc^2
2540
2805
  //}
2541
2806
  EOS
2542
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
2543
2822
  <p><span class="eqref">式1.1</span></p>
2544
2823
  <div id="emc2" class="caption-equation">
2545
2824
  <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
@@ -2566,4 +2845,296 @@ EOS
2566
2845
  actual = compile_block(src)
2567
2846
  assert_equal expected, actual
2568
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
3139
+ end
2569
3140
  end