review 3.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-win.yml +39 -0
  3. data/.github/workflows/ruby.yml +27 -0
  4. data/.rubocop.yml +50 -12
  5. data/.travis.yml +17 -8
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +358 -0
  8. data/NEWS.md +358 -1
  9. data/README.md +11 -8
  10. data/appveyor.yml +1 -3
  11. data/bin/review-catalog-converter +4 -4
  12. data/bin/review-check +8 -8
  13. data/bin/review-checkdep +1 -1
  14. data/bin/review-compile +12 -12
  15. data/bin/review-epubmaker +3 -35
  16. data/bin/review-idgxmlmaker +16 -0
  17. data/bin/review-index +2 -89
  18. data/bin/review-preproc +14 -19
  19. data/bin/review-validate +3 -3
  20. data/bin/review-vol +4 -78
  21. data/doc/LICENSE +1 -1
  22. data/doc/config.yml.sample +46 -12
  23. data/doc/config.yml.sample-simple +4 -2
  24. data/doc/format.ja.md +37 -13
  25. data/doc/format.md +35 -20
  26. data/doc/pdfmaker.ja.md +43 -1
  27. data/doc/pdfmaker.md +42 -1
  28. data/doc/quickstart.ja.md +46 -26
  29. data/doc/quickstart.md +38 -17
  30. data/lib/epubmaker/epubcommon.rb +10 -5
  31. data/lib/epubmaker/epubv2.rb +1 -1
  32. data/lib/epubmaker/epubv3.rb +1 -0
  33. data/lib/epubmaker/producer.rb +4 -2
  34. data/lib/review/book.rb +1 -1
  35. data/lib/review/book/base.rb +38 -79
  36. data/lib/review/book/chapter.rb +18 -3
  37. data/lib/review/book/compilable.rb +6 -5
  38. data/lib/review/book/index.rb +69 -101
  39. data/lib/review/book/index/item.rb +40 -0
  40. data/lib/review/book/page_metric.rb +7 -7
  41. data/lib/review/book/part.rb +28 -5
  42. data/lib/review/book/volume.rb +3 -4
  43. data/lib/review/builder.rb +105 -44
  44. data/lib/review/catalog.rb +13 -16
  45. data/lib/review/compiler.rb +84 -72
  46. data/lib/review/configure.rb +19 -8
  47. data/lib/review/epub2html.rb +37 -4
  48. data/lib/review/epubmaker.rb +62 -7
  49. data/lib/review/extentions/string.rb +0 -4
  50. data/lib/review/htmlbuilder.rb +102 -115
  51. data/lib/review/htmlutils.rb +2 -3
  52. data/lib/review/i18n.rb +2 -2
  53. data/lib/review/i18n.yml +9 -0
  54. data/lib/review/idgxmlbuilder.rb +153 -74
  55. data/lib/review/idgxmlmaker.rb +191 -0
  56. data/lib/review/init-web/finish.html +10 -0
  57. data/lib/review/init-web/index.html +190 -0
  58. data/lib/review/init-web/review-layout-design.js +691 -0
  59. data/lib/review/init.rb +125 -34
  60. data/lib/review/latexbuilder.rb +199 -88
  61. data/lib/review/lineinput.rb +1 -1
  62. data/lib/review/location.rb +32 -0
  63. data/lib/review/logger.rb +4 -8
  64. data/lib/review/makerhelper.rb +24 -5
  65. data/lib/review/markdownbuilder.rb +31 -37
  66. data/lib/review/md2inaobuilder.rb +3 -5
  67. data/lib/review/pdfmaker.rb +44 -22
  68. data/lib/review/plaintextbuilder.rb +106 -85
  69. data/lib/review/preprocessor.rb +32 -41
  70. data/lib/review/rstbuilder.rb +33 -33
  71. data/lib/review/textmaker.rb +19 -3
  72. data/lib/review/textutils.rb +76 -2
  73. data/lib/review/tocprinter.rb +231 -102
  74. data/lib/review/topbuilder.rb +114 -61
  75. data/lib/review/update.rb +19 -19
  76. data/lib/review/version.rb +1 -1
  77. data/lib/review/volumeprinter.rb +99 -0
  78. data/lib/review/webmaker.rb +11 -4
  79. data/lib/review/webtocprinter.rb +38 -35
  80. data/lib/review/yamlloader.rb +26 -16
  81. data/review.gemspec +6 -4
  82. data/samples/sample-book/README.md +7 -2
  83. data/samples/sample-book/src/.gitignore +154 -0
  84. data/samples/sample-book/src/config-ebook.yml +4 -0
  85. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  86. data/samples/sample-book/src/config-jlreq.yml +6 -0
  87. data/samples/sample-book/src/config.yml +2 -2
  88. data/samples/sample-book/src/lib/tasks/review.rake +29 -14
  89. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  90. data/samples/syntax-book/ch01.re +4 -2
  91. data/samples/syntax-book/ch02.re +8 -16
  92. data/samples/syntax-book/ch03.re +3 -6
  93. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  94. data/samples/syntax-book/config-jlreq.yml +5 -0
  95. data/samples/syntax-book/config-print.yml +3 -0
  96. data/samples/syntax-book/config.yml +1 -1
  97. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  98. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  99. data/templates/latex/config.erb +16 -0
  100. data/templates/latex/layout.tex.erb +4 -0
  101. data/templates/latex/review-jlreq/review-base.sty +150 -61
  102. data/templates/latex/review-jlreq/review-jlreq.cls +74 -8
  103. data/templates/latex/review-jlreq/review-style.sty +4 -1
  104. data/templates/latex/review-jsbook/README.md +39 -0
  105. data/templates/latex/review-jsbook/review-base.sty +101 -23
  106. data/templates/latex/review-jsbook/review-jsbook.cls +28 -5
  107. data/templates/latex/review-jsbook/review-style.sty +5 -2
  108. data/templates/opf/epubv3.opf.erb +1 -0
  109. data/templates/web/html/layout-html5.html.erb +2 -2
  110. data/test/assets/test_template.tex +24 -3
  111. data/test/assets/test_template_backmatter.tex +24 -3
  112. data/test/test_book.rb +75 -21
  113. data/test/test_book_chapter.rb +4 -2
  114. data/test/test_book_part.rb +3 -3
  115. data/test/test_builder.rb +16 -0
  116. data/test/test_catalog.rb +24 -42
  117. data/test/test_catalog_converter_cmd.rb +1 -1
  118. data/test/test_epubmaker_cmd.rb +14 -7
  119. data/test/test_helper.rb +15 -7
  120. data/test/test_htmlbuilder.rb +909 -159
  121. data/test/test_i18n.rb +25 -25
  122. data/test/test_idgxmlbuilder.rb +395 -38
  123. data/test/test_idgxmlmaker_cmd.rb +46 -0
  124. data/test/test_image_finder.rb +52 -70
  125. data/test/test_index.rb +50 -10
  126. data/test/test_latexbuilder.rb +1194 -106
  127. data/test/test_latexbuilder_v2.rb +628 -97
  128. data/test/test_logger.rb +14 -1
  129. data/test/test_makerhelper.rb +3 -3
  130. data/test/test_markdownbuilder.rb +134 -16
  131. data/test/test_md2inaobuilder.rb +32 -9
  132. data/test/test_pdfmaker.rb +18 -1
  133. data/test/test_pdfmaker_cmd.rb +100 -6
  134. data/test/test_plaintextbuilder.rb +371 -25
  135. data/test/test_preprocessor.rb +2 -16
  136. data/test/test_rstbuilder.rb +249 -26
  137. data/test/test_textmaker_cmd.rb +54 -0
  138. data/test/test_textutils.rb +109 -2
  139. data/test/test_topbuilder.rb +546 -31
  140. data/test/test_update.rb +17 -8
  141. data/test/test_webtocprinter.rb +66 -34
  142. data/test/test_yamlloader.rb +13 -0
  143. data/vendor/jsclasses/LICENSE +1 -1
  144. data/vendor/jsclasses/jis/jsarticle.cls +53 -14
  145. data/vendor/jsclasses/jis/jsbook.cls +53 -14
  146. data/vendor/jsclasses/jis/jsclasses.dtx +84 -25
  147. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  148. data/vendor/jsclasses/jis/jslogo.sty +3 -3
  149. data/vendor/jsclasses/jis/jspf.cls +52 -13
  150. data/vendor/jsclasses/jis/jsreport.cls +53 -14
  151. data/vendor/jsclasses/jis/kiyou.cls +53 -14
  152. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  153. data/vendor/jsclasses/jis/okumacro.sty +3 -4
  154. data/vendor/jsclasses/jsarticle.cls +53 -14
  155. data/vendor/jsclasses/jsbook.cls +53 -14
  156. data/vendor/jsclasses/jsclasses.dtx +84 -25
  157. data/vendor/jsclasses/jsclasses.pdf +0 -0
  158. data/vendor/jsclasses/jslogo.dtx +4 -4
  159. data/vendor/jsclasses/jslogo.pdf +0 -0
  160. data/vendor/jsclasses/jslogo.sty +3 -3
  161. data/vendor/jsclasses/jspf.cls +52 -13
  162. data/vendor/jsclasses/jsreport.cls +53 -14
  163. data/vendor/jsclasses/kiyou.cls +53 -14
  164. data/vendor/jsclasses/okumacro.dtx +4 -5
  165. data/vendor/jsclasses/okumacro.pdf +0 -0
  166. data/vendor/jsclasses/okumacro.sty +3 -4
  167. metadata +55 -10
  168. data/lib/review/tocparser.rb +0 -271
  169. data/samples/syntax-book/review-ext.rb +0 -14
  170. data/test/test_tocparser.rb +0 -25
@@ -82,7 +82,7 @@ module ReVIEW
82
82
  begin
83
83
  require 'pygments'
84
84
  begin
85
- Pygments.highlight(unescape(body),
85
+ Pygments.highlight(body,
86
86
  options: options,
87
87
  formatter: format,
88
88
  lexer: lexer)
@@ -128,8 +128,7 @@ module ReVIEW
128
128
  return body
129
129
  end
130
130
 
131
- text = unescape(body)
132
- formatter.format(lexer.lex(text))
131
+ formatter.format(lexer.lex(body))
133
132
  end
134
133
 
135
134
  def normalize_id(id)
@@ -90,7 +90,7 @@ module ReVIEW
90
90
  end
91
91
  else
92
92
  user_i18n.each do |key, values|
93
- raise KeyError, "Invalid locale file: #{path}" unless values.is_a? Hash
93
+ raise KeyError, "Invalid locale file: #{path}" unless values.is_a?(Hash)
94
94
  @store[key].merge!(values)
95
95
  end
96
96
  end
@@ -165,7 +165,7 @@ module ReVIEW
165
165
  end
166
166
  end
167
167
  remove_args.reverse_each do |idx|
168
- args.delete_at idx
168
+ args.delete_at(idx)
169
169
  end
170
170
  args_matched = (frmt.count('%') <= args.size)
171
171
  frmt.gsub!('##', '%%')
@@ -29,6 +29,9 @@ ja:
29
29
  ruby_postfix: ")"
30
30
  external_link: "%s(%s)"
31
31
  label_marker: "●● "
32
+ html_footnote_refmark: "*%s"
33
+ html_footnote_textmark: "[*%s] "
34
+ html_footnote_backmark: "⏎"
32
35
  aut: "著 者"
33
36
  csl: "監 修"
34
37
  dsr: "デザイン"
@@ -114,6 +117,9 @@ en:
114
117
  ruby_prefix: "("
115
118
  ruby_postfix: ")"
116
119
  label_marker: "●● "
120
+ html_footnote_refmark: "*%s"
121
+ html_footnote_textmark: "[*%s] "
122
+ html_footnote_backmark: "⏎"
117
123
  aut: "Author"
118
124
  csl: "Consultant"
119
125
  dsr: "Design"
@@ -179,6 +185,9 @@ zh-TW:
179
185
  ruby_postfix: ")"
180
186
  external_link: "%s (%s)"
181
187
  label_marker: "●● "
188
+ html_footnote_refmark: "*%s"
189
+ html_footnote_textmark: "[*%s] "
190
+ html_footnote_backmark: "⏎"
182
191
  aut: "著作人"
183
192
  csl: "監 修"
184
193
  dsr: "美術編輯"
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2018 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto
2
2
  # 2002-2007 Minero Aoki
3
3
  #
4
4
  # This program is free software.
@@ -16,7 +16,9 @@ module ReVIEW
16
16
  include TextUtils
17
17
  include HTMLUtils
18
18
 
19
- %i[ttbold hint maru keytop labelref ref].each { |e| Compiler.definline(e) }
19
+ %i[ttbold hint maru keytop labelref ref strong em].each do |e|
20
+ Compiler.definline(e)
21
+ end
20
22
  Compiler.defsingle(:dtp, 1)
21
23
 
22
24
  Compiler.defblock(:insn, 0..1)
@@ -146,6 +148,7 @@ module ReVIEW
146
148
 
147
149
  @subsubsubsection += 1
148
150
  print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
151
+ when 6 # rubocop:disable Lint/EmptyWhen
149
152
  else
150
153
  raise "caption level too deep or unsupported: #{level}"
151
154
  end
@@ -164,7 +167,7 @@ module ReVIEW
164
167
  end
165
168
 
166
169
  def ul_item_begin(lines)
167
- print %Q(<li aid:pstyle="ul-item">#{lines.join.chomp})
170
+ print %Q(<li aid:pstyle="ul-item">#{join_lines_to_paragraph(lines).chomp})
168
171
  end
169
172
 
170
173
  def ul_item_end
@@ -199,7 +202,7 @@ module ReVIEW
199
202
  end
200
203
 
201
204
  def ol_item(lines, num)
202
- puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{lines.join.chomp}</li>)
205
+ puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{join_lines_to_paragraph(lines).chomp}</li>)
203
206
  @ol_num += 1
204
207
  end
205
208
 
@@ -221,7 +224,7 @@ module ReVIEW
221
224
  end
222
225
 
223
226
  def dd(lines)
224
- puts "<dd>#{lines.join.chomp}</dd>"
227
+ puts "<dd>#{join_lines_to_paragraph(lines).chomp}</dd>"
225
228
  end
226
229
 
227
230
  def dl_end
@@ -231,12 +234,12 @@ module ReVIEW
231
234
  def paragraph(lines)
232
235
  if @noindent.nil?
233
236
  if lines[0] =~ /\A(\t+)/
234
- puts %Q(<p inlist="#{$1.size}">#{lines.join.sub(/\A\t+/, '')}</p>)
237
+ puts %Q(<p inlist="#{$1.size}">#{join_lines_to_paragraph(lines).sub(/\A\t+/, '')}</p>)
235
238
  else
236
- puts "<p>#{lines.join}</p>"
239
+ puts "<p>#{join_lines_to_paragraph(lines)}</p>"
237
240
  end
238
241
  else
239
- puts %Q(<p aid:pstyle="noindent" noindent='1'>#{lines.join}</p>)
242
+ puts %Q(<p aid:pstyle="noindent" noindent='1'>#{join_lines_to_paragraph(lines)}</p>)
240
243
  @noindent = nil
241
244
  end
242
245
  end
@@ -268,7 +271,6 @@ module ReVIEW
268
271
  end
269
272
 
270
273
  def list_header(id, caption, _lang)
271
- puts '<codelist>'
272
274
  return true unless caption.present?
273
275
  if get_chap.nil?
274
276
  puts %Q(<caption>#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
@@ -293,14 +295,20 @@ module ReVIEW
293
295
  end
294
296
  end
295
297
 
298
+ def list(lines, id, caption, lang = nil)
299
+ puts '<codelist>'
300
+ super(lines, id, caption, lang)
301
+ puts '</codelist>'
302
+ end
303
+
296
304
  def list_body(_id, lines, _lang)
297
305
  print '<pre>'
298
306
  codelines_body(lines)
299
- puts '</pre></codelist>'
307
+ print '</pre>'
300
308
  end
301
309
 
302
310
  def emlist(lines, caption = nil, _lang = nil)
303
- quotedlist lines, 'emlist', caption
311
+ quotedlist(lines, 'emlist', caption)
304
312
  end
305
313
 
306
314
  def emlistnum(lines, caption = nil, _lang = nil)
@@ -309,7 +317,13 @@ module ReVIEW
309
317
  lines.each_with_index do |line, i|
310
318
  lines2 << detab(%Q(<span type='lineno'>) + (i + first_line_num).to_s.rjust(2) + ': </span>' + line)
311
319
  end
312
- quotedlist lines2, 'emlistnum', caption
320
+ quotedlist(lines2, 'emlistnum', caption)
321
+ end
322
+
323
+ def listnum(lines, id, caption, lang = nil)
324
+ puts '<codelist>'
325
+ super(lines, id, caption, lang)
326
+ puts '</codelist>'
313
327
  end
314
328
 
315
329
  def listnum_body(lines, _lang)
@@ -328,16 +342,18 @@ module ReVIEW
328
342
  print '</listinfo>' if @book.config['listinfo']
329
343
  no += 1
330
344
  end
331
- puts '</pre></codelist>'
345
+ print '</pre>'
332
346
  end
333
347
 
334
348
  def cmd(lines, caption = nil)
335
- quotedlist lines, 'cmd', caption
349
+ quotedlist(lines, 'cmd', caption)
336
350
  end
337
351
 
338
352
  def quotedlist(lines, css_class, caption)
339
353
  print %Q(<list type='#{css_class}'>)
340
- puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>" if caption.present?
354
+ if caption_top?('list') && caption.present?
355
+ puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>"
356
+ end
341
357
  print '<pre>'
342
358
  no = 1
343
359
  lines.each do |line|
@@ -352,7 +368,11 @@ module ReVIEW
352
368
  print '</listinfo>' if @book.config['listinfo']
353
369
  no += 1
354
370
  end
355
- puts '</pre></list>'
371
+ puts '</pre>'
372
+ if !caption_top?('list') && caption.present?
373
+ puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>"
374
+ end
375
+ puts '</list>'
356
376
  end
357
377
  private :quotedlist
358
378
 
@@ -396,20 +416,22 @@ module ReVIEW
396
416
  def image_image(id, caption, metric = nil)
397
417
  metrics = parse_metric('idgxml', metric)
398
418
  puts '<img>'
419
+ image_header(id, caption) if caption_top?('image')
399
420
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} />)
400
- image_header id, caption
421
+ image_header(id, caption) unless caption_top?('image')
401
422
  puts '</img>'
402
423
  end
403
424
 
404
425
  def image_dummy(id, caption, lines)
405
426
  puts '<img>'
427
+ image_header(id, caption) if caption_top?('image')
406
428
  print %Q(<pre aid:pstyle="dummyimage">)
407
429
  lines.each do |line|
408
430
  print detab(line)
409
431
  print "\n"
410
432
  end
411
433
  print '</pre>'
412
- image_header id, caption
434
+ image_header(id, caption) unless caption_top?('image')
413
435
  puts '</img>'
414
436
  warn "image not bound: #{id}"
415
437
  end
@@ -425,96 +447,118 @@ module ReVIEW
425
447
 
426
448
  def texequation(lines, id = nil, caption = '')
427
449
  @texblockequation += 1
450
+ caption_str = nil
428
451
  if id
429
452
  puts '<equationblock>'
430
453
  if get_chap.nil?
431
- puts %Q(<caption>#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
454
+ caption_str = %Q(<caption>#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
432
455
  else
433
- puts %Q(<caption>#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
456
+ caption_str = %Q(<caption>#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
434
457
  end
458
+ puts caption_str if caption_top?('equation')
435
459
  end
436
460
 
437
461
  puts %Q(<replace idref="texblock-#{@texblockequation}">)
438
462
  puts '<pre>'
439
- puts lines.join("\n")
463
+ print lines.join("\n")
440
464
  puts '</pre>'
441
465
  puts '</replace>'
442
466
 
443
467
  if id
468
+ puts caption_str unless caption_top?('equation')
444
469
  puts '</equationblock>'
445
470
  end
446
471
  end
447
472
 
448
473
  def table(lines, id = nil, caption = nil)
449
- tablewidth = @book.config['tableopt'] ? @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f : nil
450
- col = 0
474
+ @tablewidth = nil
475
+ if @book.config['tableopt']
476
+ @tablewidth = @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f
477
+ end
478
+ @col = 0
451
479
 
480
+ sepidx, rows = parse_table_rows(lines)
452
481
  puts '<table>'
453
- rows = []
482
+
483
+ begin
484
+ if caption_top?('table') && caption.present?
485
+ table_header(id, caption)
486
+ end
487
+
488
+ if @tablewidth.nil?
489
+ print '<tbody>'
490
+ else
491
+ print %Q(<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{@col}">)
492
+ end
493
+ @table_id = id
494
+ table_rows(sepidx, rows)
495
+ puts '</tbody>'
496
+
497
+ if !caption_top?('table') && caption.present?
498
+ table_header(id, caption)
499
+ end
500
+ rescue KeyError
501
+ error "no such table: #{id}"
502
+ end
503
+ puts '</table>'
504
+ @tsize = nil
505
+ end
506
+
507
+ def parse_table_rows(lines)
454
508
  sepidx = nil
509
+ rows = []
455
510
  lines.each_with_index do |line, idx|
456
511
  if /\A[\=\-]{12}/ =~ line
457
512
  sepidx ||= idx
458
513
  next
459
514
  end
460
- if tablewidth
515
+ if @tablewidth
461
516
  rows.push(line.gsub(/\t\.\t/, "\tDUMMYCELLSPLITTER\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\tDUMMYCELLSPLITTER").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
462
517
  else
463
518
  rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
464
519
  end
465
- col2 = rows[rows.length - 1].split(/\t/).length
466
- col = col2 if col2 > col
520
+ col2 = rows[rows.length - 1].split(table_row_separator_regexp).length
521
+ @col = col2 if col2 > @col
467
522
  end
523
+ error 'no rows in the table' if rows.empty?
524
+ [sepidx, rows]
525
+ end
468
526
 
527
+ def table_rows(sepidx, rows)
469
528
  cellwidth = []
470
- if tablewidth
529
+ if @tablewidth
471
530
  if @tsize.nil?
472
- col.times { |n| cellwidth[n] = tablewidth / col }
531
+ @col.times { |n| cellwidth[n] = @tablewidth / @col }
473
532
  else
474
533
  cellwidth = @tsize.split(/\s*,\s*/)
475
534
  totallength = 0
476
535
  cellwidth.size.times do |n|
477
536
  cellwidth[n] = cellwidth[n].to_f / @book.config['pt_to_mm_unit'].to_f
478
537
  totallength += cellwidth[n]
479
- warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
538
+ warn "total length exceeds limit for table: #{@table_id}" if totallength > @tablewidth
480
539
  end
481
- if cellwidth.size < col
482
- cw = (tablewidth - totallength) / (col - cellwidth.size)
483
- warn "auto cell sizing exceeds limit for table: #{id}" if cw <= 0
484
- (cellwidth.size..(col - 1)).each { |i| cellwidth[i] = cw }
540
+ if cellwidth.size < @col
541
+ cw = (@tablewidth - totallength) / (@col - cellwidth.size)
542
+ warn "auto cell sizing exceeds limit for table: #{@table_id}" if cw <= 0
543
+ (cellwidth.size..(@col - 1)).each { |i| cellwidth[i] = cw }
485
544
  end
486
545
  end
487
546
  end
488
547
 
489
- begin
490
- table_header id, caption if caption.present?
491
- rescue KeyError
492
- error "no such table: #{id}"
493
- end
494
- return if rows.empty?
495
-
496
- if tablewidth.nil?
497
- print '<tbody>'
498
- else
499
- print %Q(<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{col}">)
500
- end
501
-
502
548
  if sepidx
503
549
  sepidx.times do |y|
504
- if tablewidth.nil?
550
+ if @tablewidth.nil?
505
551
  puts %Q(<tr type="header">#{rows.shift}</tr>)
506
552
  else
507
553
  i = 0
508
- rows.shift.split("\t").each_with_index do |cell, x|
554
+ rows.shift.split(table_row_separator_regexp).each_with_index do |cell, x|
509
555
  print %Q(<td xyh="#{x + 1},#{y + 1},#{sepidx}" aid:table="cell" aid:theader="1" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf('%.3f', cellwidth[i])}">#{cell.sub('DUMMYCELLSPLITTER', '')}</td>)
510
556
  i += 1
511
557
  end
512
558
  end
513
559
  end
514
560
  end
515
- trputs(tablewidth, rows, cellwidth, sepidx)
516
- puts '</tbody></table>'
517
- @tsize = nil
561
+ trputs(@tablewidth, rows, cellwidth, sepidx)
518
562
  end
519
563
 
520
564
  def trputs(tablewidth, rows, cellwidth, sepidx)
@@ -522,7 +566,7 @@ module ReVIEW
522
566
  if tablewidth
523
567
  rows.each_with_index do |row, y|
524
568
  i = 0
525
- row.split("\t").each_with_index do |cell, x|
569
+ row.split(table_row_separator_regexp).each_with_index do |cell, x|
526
570
  print %Q(<td xyh="#{x + 1},#{y + 1 + sepidx},#{sepidx}" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf('%.3f', cellwidth[i])}">#{cell.sub('DUMMYCELLSPLITTER', '')}</td>)
527
571
  i += 1
528
572
  end
@@ -560,7 +604,6 @@ module ReVIEW
560
604
  end
561
605
 
562
606
  def table_end
563
- print '<?dtp tablerow last?>'
564
607
  end
565
608
 
566
609
  def emtable(lines, caption = nil)
@@ -568,24 +611,29 @@ module ReVIEW
568
611
  end
569
612
 
570
613
  def imgtable(lines, id, caption = nil, metric = nil)
571
- if @chapter.image(id).bound?
614
+ if @chapter.image_bound?(id)
572
615
  metrics = parse_metric('idgxml', metric)
573
616
  puts '<table>'
574
- table_header id, caption if caption.present?
617
+ if caption_top?('table') && caption.present?
618
+ table_header(id, caption)
619
+ end
575
620
  puts %Q(<imgtable><Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} /></imgtable>)
621
+ if !caption_top?('table') && caption.present?
622
+ table_header(id, caption)
623
+ end
576
624
  puts '</table>'
577
625
  else
578
626
  warn "image not bound: #{id}" if @strict
579
- image_dummy id, caption, lines
627
+ image_dummy(id, caption, lines)
580
628
  end
581
629
  end
582
630
 
583
631
  def comment(lines, comment = nil)
584
- return true unless @book.config['draft']
632
+ return unless @book.config['draft']
585
633
  lines ||= []
586
- lines.unshift comment unless comment.blank?
634
+ lines.unshift(escape(comment)) unless comment.blank?
587
635
  str = lines.join("\n")
588
- print "<msg>#{escape(str)}</msg>"
636
+ print "<msg>#{str}</msg>"
589
637
  end
590
638
 
591
639
  def inline_comment(str)
@@ -689,6 +737,14 @@ module ReVIEW
689
737
  %Q(<b>#{escape(str)}</b>)
690
738
  end
691
739
 
740
+ def inline_em(str)
741
+ %Q(<em>#{escape(str)}</em>)
742
+ end
743
+
744
+ def inline_strong(str)
745
+ %Q(<strong>#{escape(str)}</strong>)
746
+ end
747
+
692
748
  def inline_tt(str)
693
749
  %Q(<tt>#{escape(str)}</tt>)
694
750
  end
@@ -970,6 +1026,7 @@ module ReVIEW
970
1026
  end
971
1027
 
972
1028
  def syntaxblock(type, lines, caption)
1029
+ captionstr = nil
973
1030
  if caption.present?
974
1031
  titleopentag = %Q(caption aid:pstyle="#{type}-title")
975
1032
  titleclosetag = 'caption'
@@ -977,9 +1034,13 @@ module ReVIEW
977
1034
  titleopentag = %Q(floattitle type="insn")
978
1035
  titleclosetag = 'floattitle'
979
1036
  end
980
- puts %Q(<#{type}><#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
1037
+ captionstr = %Q(<#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
1038
+ end
1039
+ print "<#{type}>"
1040
+ if caption_top?('list')
1041
+ puts captionstr
981
1042
  else
982
- puts "<#{type}>"
1043
+ puts ''
983
1044
  end
984
1045
 
985
1046
  no = 1
@@ -995,6 +1056,9 @@ module ReVIEW
995
1056
  print '</listinfo>' if @book.config['listinfo']
996
1057
  no += 1
997
1058
  end
1059
+ unless caption_top?('list')
1060
+ print captionstr
1061
+ end
998
1062
  puts "</#{type}>"
999
1063
  end
1000
1064
 
@@ -1009,12 +1073,17 @@ module ReVIEW
1009
1073
  def indepimage(_lines, id, caption = nil, metric = nil)
1010
1074
  metrics = parse_metric('idgxml', metric)
1011
1075
  puts '<img>'
1076
+ if caption_top?('image')
1077
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1078
+ end
1012
1079
  begin
1013
1080
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}"#{metrics} />)
1014
1081
  rescue
1015
1082
  warn %Q(image not bound: #{id})
1016
1083
  end
1017
- puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1084
+ unless caption_top?('image')
1085
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1086
+ end
1018
1087
  puts '</img>'
1019
1088
  end
1020
1089
 
@@ -1113,25 +1182,36 @@ module ReVIEW
1113
1182
  error "unknown chapter: #{id}"
1114
1183
  end
1115
1184
 
1116
- def source_header(caption)
1185
+ def source(lines, caption = nil, lang = nil)
1117
1186
  puts '<source>'
1187
+ if caption_top?('list')
1188
+ source_header(caption)
1189
+ end
1190
+ source_body(lines, lang)
1191
+ unless caption_top?('list')
1192
+ source_header(caption)
1193
+ end
1194
+ puts '</source>'
1195
+ end
1196
+
1197
+ def source_header(caption)
1118
1198
  puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1119
1199
  end
1120
1200
 
1121
1201
  def source_body(lines, _lang)
1122
1202
  puts '<pre>'
1123
1203
  codelines_body(lines)
1124
- puts '</pre></source>'
1204
+ print '</pre>'
1125
1205
  end
1126
1206
 
1127
1207
  def bibpaper(lines, id, caption)
1128
- bibpaper_header id, caption
1129
- bibpaper_bibpaper id, caption, lines unless lines.empty?
1208
+ puts %Q(<bibitem id="bib-#{id}">)
1209
+ bibpaper_header(id, caption)
1210
+ bibpaper_bibpaper(id, caption, lines) unless lines.empty?
1130
1211
  puts '</bibitem>'
1131
1212
  end
1132
1213
 
1133
1214
  def bibpaper_header(id, caption)
1134
- puts %Q(<bibitem id="bib-#{id}">)
1135
1215
  puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>" if caption.present?
1136
1216
  end
1137
1217
 
@@ -1146,13 +1226,12 @@ module ReVIEW
1146
1226
  end
1147
1227
 
1148
1228
  def inline_hd_chap(chap, id)
1149
- if chap.number
1150
- n = chap.headline_index.number(id)
1151
- if @book.config['secnolevel'] >= n.split('.').size
1152
- return I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
1153
- end
1229
+ n = chap.headline_index.number(id)
1230
+ if n.present? && chap.number && over_secnolevel?(n)
1231
+ I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
1232
+ else
1233
+ I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
1154
1234
  end
1155
- I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
1156
1235
  rescue KeyError
1157
1236
  error "unknown headline: #{id}"
1158
1237
  end