review 3.1.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-win.yml +45 -0
  3. data/.github/workflows/ruby.yml +27 -0
  4. data/.rubocop.yml +161 -34
  5. data/.travis.yml +16 -15
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +394 -0
  8. data/NEWS.md +395 -1
  9. data/README.md +10 -7
  10. data/appveyor.yml +1 -3
  11. data/bin/review-catalog-converter +5 -5
  12. data/bin/review-check +10 -12
  13. data/bin/review-checkdep +2 -2
  14. data/bin/review-compile +17 -23
  15. data/bin/review-epubmaker +3 -35
  16. data/bin/review-idgxmlmaker +16 -0
  17. data/bin/review-index +2 -89
  18. data/bin/review-preproc +13 -13
  19. data/bin/review-validate +4 -4
  20. data/bin/review-vol +4 -78
  21. data/doc/config.yml.sample +47 -12
  22. data/doc/config.yml.sample-simple +3 -2
  23. data/doc/format.ja.md +120 -17
  24. data/doc/format.md +119 -27
  25. data/doc/makeindex.ja.md +2 -2
  26. data/doc/pdfmaker.ja.md +43 -1
  27. data/doc/pdfmaker.md +42 -1
  28. data/doc/quickstart.ja.md +45 -25
  29. data/doc/quickstart.md +37 -16
  30. data/lib/epubmaker/content.rb +3 -2
  31. data/lib/epubmaker/epubcommon.rb +34 -27
  32. data/lib/epubmaker/epubv2.rb +5 -6
  33. data/lib/epubmaker/epubv3.rb +21 -18
  34. data/lib/epubmaker/producer.rb +2 -1
  35. data/lib/review/book.rb +2 -2
  36. data/lib/review/book/base.rb +91 -96
  37. data/lib/review/book/bib.rb +21 -0
  38. data/lib/review/book/book_unit.rb +155 -0
  39. data/lib/review/book/chapter.rb +48 -29
  40. data/lib/review/book/index.rb +46 -240
  41. data/lib/review/book/index/item.rb +46 -0
  42. data/lib/review/book/page_metric.rb +7 -7
  43. data/lib/review/book/part.rb +45 -10
  44. data/lib/review/book/volume.rb +4 -5
  45. data/lib/review/builder.rb +172 -56
  46. data/lib/review/catalog.rb +14 -17
  47. data/lib/review/compiler.rb +219 -121
  48. data/lib/review/configure.rb +39 -7
  49. data/lib/review/converter.rb +1 -1
  50. data/lib/review/epub2html.rb +43 -5
  51. data/lib/review/epubmaker.rb +69 -27
  52. data/lib/review/extentions/string.rb +0 -4
  53. data/lib/review/htmlbuilder.rb +112 -101
  54. data/lib/review/htmlutils.rb +9 -13
  55. data/lib/review/i18n.rb +3 -3
  56. data/lib/review/idgxmlbuilder.rb +202 -78
  57. data/lib/review/idgxmlmaker.rb +186 -0
  58. data/lib/review/index_builder.rb +653 -0
  59. data/lib/review/init-web/finish.html +10 -0
  60. data/lib/review/init-web/index.html +190 -0
  61. data/lib/review/init-web/review-layout-design.js +691 -0
  62. data/lib/review/init.rb +129 -46
  63. data/lib/review/latexbuilder.rb +255 -92
  64. data/lib/review/lineinput.rb +1 -1
  65. data/lib/review/location.rb +32 -0
  66. data/lib/review/logger.rb +4 -8
  67. data/lib/review/makerhelper.rb +35 -5
  68. data/lib/review/markdownbuilder.rb +50 -38
  69. data/lib/review/md2inaobuilder.rb +3 -5
  70. data/lib/review/pdfmaker.rb +60 -57
  71. data/lib/review/plaintextbuilder.rb +154 -87
  72. data/lib/review/preprocessor.rb +20 -42
  73. data/lib/review/rstbuilder.rb +57 -38
  74. data/lib/review/sec_counter.rb +13 -0
  75. data/lib/review/textmaker.rb +23 -15
  76. data/lib/review/textutils.rb +76 -2
  77. data/lib/review/tocprinter.rb +230 -102
  78. data/lib/review/topbuilder.rb +139 -60
  79. data/lib/review/update.rb +24 -24
  80. data/lib/review/version.rb +1 -1
  81. data/lib/review/volumeprinter.rb +98 -0
  82. data/lib/review/webmaker.rb +20 -24
  83. data/lib/review/webtocprinter.rb +38 -35
  84. data/lib/review/yamlloader.rb +26 -16
  85. data/review.gemspec +6 -4
  86. data/samples/sample-book/README.md +7 -2
  87. data/samples/sample-book/src/.gitignore +154 -0
  88. data/samples/sample-book/src/config-ebook.yml +4 -0
  89. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  90. data/samples/sample-book/src/config-jlreq.yml +6 -0
  91. data/samples/sample-book/src/config.yml +2 -2
  92. data/samples/sample-book/src/lib/tasks/review.rake +29 -14
  93. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  94. data/samples/syntax-book/Gemfile +1 -1
  95. data/samples/syntax-book/ch01.re +4 -2
  96. data/samples/syntax-book/ch02.re +8 -16
  97. data/samples/syntax-book/ch03.re +3 -6
  98. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  99. data/samples/syntax-book/config-jlreq.yml +5 -0
  100. data/samples/syntax-book/config-print.yml +3 -0
  101. data/samples/syntax-book/config.yml +1 -1
  102. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  103. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  104. data/templates/latex/config.erb +39 -25
  105. data/templates/latex/layout.tex.erb +1 -0
  106. data/templates/latex/review-jlreq/README.md +3 -1
  107. data/templates/latex/review-jlreq/review-base.sty +161 -50
  108. data/templates/latex/review-jlreq/review-jlreq.cls +21 -22
  109. data/templates/latex/review-jlreq/review-style.sty +4 -1
  110. data/templates/latex/review-jsbook/README.md +46 -5
  111. data/templates/latex/review-jsbook/review-base.sty +123 -35
  112. data/templates/latex/review-jsbook/review-jsbook.cls +10 -4
  113. data/templates/latex/review-jsbook/review-style.sty +5 -2
  114. data/templates/opf/epubv3.opf.erb +1 -0
  115. data/templates/web/html/layout-html5.html.erb +3 -3
  116. data/test/assets/test_template.tex +19 -7
  117. data/test/assets/test_template_backmatter.tex +19 -7
  118. data/test/book_test_helper.rb +11 -5
  119. data/test/test_book.rb +124 -79
  120. data/test/test_book_chapter.rb +97 -54
  121. data/test/test_book_part.rb +3 -3
  122. data/test/test_builder.rb +38 -13
  123. data/test/test_catalog.rb +24 -42
  124. data/test/test_catalog_converter_cmd.rb +1 -1
  125. data/test/test_converter.rb +1 -0
  126. data/test/test_epub3maker.rb +2 -2
  127. data/test/test_epubmaker.rb +8 -0
  128. data/test/test_epubmaker_cmd.rb +14 -7
  129. data/test/test_helper.rb +18 -7
  130. data/test/test_htmlbuilder.rb +1491 -205
  131. data/test/test_htmlutils.rb +0 -12
  132. data/test/test_i18n.rb +37 -37
  133. data/test/test_idgxmlbuilder.rb +744 -42
  134. data/test/test_idgxmlmaker_cmd.rb +46 -0
  135. data/test/test_image_finder.rb +52 -70
  136. data/test/test_index.rb +94 -44
  137. data/test/test_indexbuilder.rb +52 -0
  138. data/test/test_latexbuilder.rb +1784 -161
  139. data/test/test_latexbuilder_v2.rb +671 -102
  140. data/test/test_logger.rb +17 -4
  141. data/test/test_makerhelper.rb +2 -14
  142. data/test/test_markdownbuilder.rb +137 -16
  143. data/test/test_md2inaobuilder.rb +32 -9
  144. data/test/test_pdfmaker.rb +30 -12
  145. data/test/test_pdfmaker_cmd.rb +100 -6
  146. data/test/test_plaintextbuilder.rb +791 -30
  147. data/test/test_preprocessor.rb +2 -16
  148. data/test/test_review_ext.rb +2 -1
  149. data/test/test_rstbuilder.rb +274 -27
  150. data/test/test_sec_counter.rb +156 -0
  151. data/test/test_textmaker_cmd.rb +54 -0
  152. data/test/test_textutils.rb +109 -2
  153. data/test/test_topbuilder.rb +724 -34
  154. data/test/test_update.rb +20 -11
  155. data/test/test_webtocprinter.rb +75 -43
  156. data/test/test_yamlloader.rb +13 -0
  157. data/vendor/gentombow/LICENSE +1 -1
  158. data/vendor/gentombow/Makefile +0 -1
  159. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  160. data/vendor/gentombow/bounddvi-en.tex +1 -0
  161. data/vendor/gentombow/bounddvi.pdf +0 -0
  162. data/vendor/gentombow/bounddvi.sty +30 -7
  163. data/vendor/gentombow/bounddvi.tex +1 -0
  164. data/vendor/gentombow/create_archive.sh +1 -0
  165. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  166. data/vendor/gentombow/gentombow-ja.tex +9 -0
  167. data/vendor/gentombow/gentombow.pdf +0 -0
  168. data/vendor/gentombow/gentombow.sty +32 -10
  169. data/vendor/gentombow/gentombow.tex +8 -0
  170. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  171. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  172. data/vendor/jsclasses/LICENSE +1 -1
  173. data/vendor/jsclasses/Makefile +3 -2
  174. data/vendor/jsclasses/create_archive.sh +5 -5
  175. data/vendor/jsclasses/jis/Makefile +3 -2
  176. data/vendor/jsclasses/jis/jsarticle.cls +74 -31
  177. data/vendor/jsclasses/jis/jsbook.cls +74 -31
  178. data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
  179. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  180. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  181. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  182. data/vendor/jsclasses/jis/jslogo.sty +4 -16
  183. data/vendor/jsclasses/jis/jspf.cls +73 -30
  184. data/vendor/jsclasses/jis/jsreport.cls +74 -31
  185. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  186. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  187. data/vendor/jsclasses/jis/kiyou.cls +74 -31
  188. data/vendor/jsclasses/jis/minijs.sty +65 -22
  189. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  190. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  191. data/vendor/jsclasses/jis/okumacro.sty +4 -17
  192. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  193. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  194. data/vendor/jsclasses/jis/winjis.sty +23 -19
  195. data/vendor/jsclasses/jsarticle.cls +74 -31
  196. data/vendor/jsclasses/jsbook.cls +74 -31
  197. data/vendor/jsclasses/jsclasses.dtx +176 -36
  198. data/vendor/jsclasses/jsclasses.ins +15 -5
  199. data/vendor/jsclasses/jsclasses.pdf +0 -0
  200. data/vendor/jsclasses/jslogo.dtx +4 -4
  201. data/vendor/jsclasses/jslogo.ins +9 -0
  202. data/vendor/jsclasses/jslogo.pdf +0 -0
  203. data/vendor/jsclasses/jslogo.sty +4 -16
  204. data/vendor/jsclasses/jspf.cls +73 -30
  205. data/vendor/jsclasses/jsreport.cls +74 -31
  206. data/vendor/jsclasses/jsverb.ins +9 -0
  207. data/vendor/jsclasses/jsverb.pdf +0 -0
  208. data/vendor/jsclasses/jsverb.sty +1 -13
  209. data/vendor/jsclasses/kiyou.cls +74 -31
  210. data/vendor/jsclasses/minijs.sty +68 -22
  211. data/vendor/jsclasses/okumacro.dtx +4 -5
  212. data/vendor/jsclasses/okumacro.ins +9 -0
  213. data/vendor/jsclasses/okumacro.pdf +0 -0
  214. data/vendor/jsclasses/okumacro.sty +4 -17
  215. data/vendor/jsclasses/okuverb.ins +9 -0
  216. data/vendor/jsclasses/okuverb.pdf +0 -0
  217. data/vendor/jsclasses/okuverb.sty +1 -13
  218. data/vendor/jsclasses/tests/relfont.tex +10 -0
  219. data/vendor/jsclasses/winjis.sty +23 -19
  220. metadata +65 -12
  221. data/.rubocop_todo.yml +0 -7
  222. data/lib/review/book/compilable.rb +0 -173
  223. data/lib/review/tocparser.rb +0 -271
  224. data/samples/syntax-book/review-ext.rb +0 -14
  225. data/test/test_tocparser.rb +0 -25
@@ -7,19 +7,16 @@
7
7
  # the GNU LGPL, Lesser General Public License version 2.1.
8
8
  #
9
9
 
10
- require 'cgi/util'
10
+ begin
11
+ require 'cgi/escape'
12
+ rescue
13
+ require 'cgi/util'
14
+ end
15
+
11
16
  module ReVIEW
12
17
  module HTMLUtils
13
- ESC = {
14
- '&' => '&',
15
- '<' => '&lt;',
16
- '>' => '&gt;',
17
- '"' => '&quot;'
18
- } # .freeze
19
-
20
18
  def escape(str)
21
- t = ESC
22
- str.gsub(/[&"<>]/) { |c| t[c] }
19
+ CGI.escapeHTML(str)
23
20
  end
24
21
 
25
22
  alias_method :escape_html, :escape # for backward compatibility
@@ -82,7 +79,7 @@ module ReVIEW
82
79
  begin
83
80
  require 'pygments'
84
81
  begin
85
- Pygments.highlight(unescape(body),
82
+ Pygments.highlight(body,
86
83
  options: options,
87
84
  formatter: format,
88
85
  lexer: lexer)
@@ -128,8 +125,7 @@ module ReVIEW
128
125
  return body
129
126
  end
130
127
 
131
- text = unescape(body)
132
- formatter.format(lexer.lex(text))
128
+ formatter.format(lexer.lex(body))
133
129
  end
134
130
 
135
131
  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
@@ -125,7 +125,7 @@ module ReVIEW
125
125
  frmt.gsub!('%%', '##')
126
126
 
127
127
  unless args.is_a?(Array)
128
- args = args.nil? && frmt !~ /\%/ ? [] : [args]
128
+ args = args.nil? && frmt !~ /%/ ? [] : [args]
129
129
  end
130
130
 
131
131
  percents = frmt.scan(/%[A-Za-z]{1,3}/)
@@ -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!('##', '%%')
@@ -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)
@@ -44,10 +46,6 @@ module ReVIEW
44
46
  '.xml'
45
47
  end
46
48
 
47
- def builder_init
48
- end
49
- private :builder_init
50
-
51
49
  def builder_init_file
52
50
  @warns = []
53
51
  @errors = []
@@ -87,7 +85,21 @@ module ReVIEW
87
85
  s += '</sect>' if @section > 0
88
86
  s += '</chapter>' if @chapter.number > 0
89
87
  end
90
- @output.string + s + "</#{@rootelement}>\n"
88
+ solve_nest(@output.string) + s + "</#{@rootelement}>\n"
89
+ end
90
+
91
+ def solve_nest(s)
92
+ check_nest
93
+ s.gsub("</dd></dl>\x01→dl←\x01", '').
94
+ gsub("\x01→/dl←\x01", "</dd></dl>←END\x01").
95
+ gsub("</li></ul>\x01→ul←\x01", '').
96
+ gsub("\x01→/ul←\x01", "</li></ul>←END\x01").
97
+ gsub("</li></ol>\x01→ol←\x01", '').
98
+ gsub("\x01→/ol←\x01", "</li></ol>←END\x01").
99
+ gsub("</dl>←END\x01<dl>", '').
100
+ gsub("</ul>←END\x01<ul>", '').
101
+ gsub("</ol>←END\x01<ol>", '').
102
+ gsub("←END\x01", '')
91
103
  end
92
104
 
93
105
  def headline(level, label, caption)
@@ -146,6 +158,7 @@ module ReVIEW
146
158
 
147
159
  @subsubsubsection += 1
148
160
  print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
161
+ when 6 # rubocop:disable Lint/EmptyWhen
149
162
  else
150
163
  raise "caption level too deep or unsupported: #{level}"
151
164
  end
@@ -164,7 +177,7 @@ module ReVIEW
164
177
  end
165
178
 
166
179
  def ul_item_begin(lines)
167
- print %Q(<li aid:pstyle="ul-item">#{lines.join.chomp})
180
+ print %Q(<li aid:pstyle="ul-item">#{join_lines_to_paragraph(lines).chomp})
168
181
  end
169
182
 
170
183
  def ul_item_end
@@ -199,7 +212,7 @@ module ReVIEW
199
212
  end
200
213
 
201
214
  def ol_item(lines, num)
202
- puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{lines.join.chomp}</li>)
215
+ puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{join_lines_to_paragraph(lines).chomp}</li>)
203
216
  @ol_num += 1
204
217
  end
205
218
 
@@ -221,7 +234,7 @@ module ReVIEW
221
234
  end
222
235
 
223
236
  def dd(lines)
224
- puts "<dd>#{lines.join.chomp}</dd>"
237
+ puts "<dd>#{join_lines_to_paragraph(lines).chomp}</dd>"
225
238
  end
226
239
 
227
240
  def dl_end
@@ -231,12 +244,12 @@ module ReVIEW
231
244
  def paragraph(lines)
232
245
  if @noindent.nil?
233
246
  if lines[0] =~ /\A(\t+)/
234
- puts %Q(<p inlist="#{$1.size}">#{lines.join.sub(/\A\t+/, '')}</p>)
247
+ puts %Q(<p inlist="#{$1.size}">#{join_lines_to_paragraph(lines).sub(/\A\t+/, '')}</p>)
235
248
  else
236
- puts "<p>#{lines.join}</p>"
249
+ puts "<p>#{join_lines_to_paragraph(lines)}</p>"
237
250
  end
238
251
  else
239
- puts %Q(<p aid:pstyle="noindent" noindent='1'>#{lines.join}</p>)
252
+ puts %Q(<p aid:pstyle="noindent" noindent='1'>#{join_lines_to_paragraph(lines)}</p>)
240
253
  @noindent = nil
241
254
  end
242
255
  end
@@ -268,7 +281,6 @@ module ReVIEW
268
281
  end
269
282
 
270
283
  def list_header(id, caption, _lang)
271
- puts '<codelist>'
272
284
  return true unless caption.present?
273
285
  if get_chap.nil?
274
286
  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 +305,20 @@ module ReVIEW
293
305
  end
294
306
  end
295
307
 
308
+ def list(lines, id, caption, lang = nil)
309
+ puts '<codelist>'
310
+ super(lines, id, caption, lang)
311
+ puts '</codelist>'
312
+ end
313
+
296
314
  def list_body(_id, lines, _lang)
297
315
  print '<pre>'
298
316
  codelines_body(lines)
299
- puts '</pre></codelist>'
317
+ print '</pre>'
300
318
  end
301
319
 
302
320
  def emlist(lines, caption = nil, _lang = nil)
303
- quotedlist lines, 'emlist', caption
321
+ quotedlist(lines, 'emlist', caption)
304
322
  end
305
323
 
306
324
  def emlistnum(lines, caption = nil, _lang = nil)
@@ -309,7 +327,13 @@ module ReVIEW
309
327
  lines.each_with_index do |line, i|
310
328
  lines2 << detab(%Q(<span type='lineno'>) + (i + first_line_num).to_s.rjust(2) + ': </span>' + line)
311
329
  end
312
- quotedlist lines2, 'emlistnum', caption
330
+ quotedlist(lines2, 'emlistnum', caption)
331
+ end
332
+
333
+ def listnum(lines, id, caption, lang = nil)
334
+ puts '<codelist>'
335
+ super(lines, id, caption, lang)
336
+ puts '</codelist>'
313
337
  end
314
338
 
315
339
  def listnum_body(lines, _lang)
@@ -328,16 +352,18 @@ module ReVIEW
328
352
  print '</listinfo>' if @book.config['listinfo']
329
353
  no += 1
330
354
  end
331
- puts '</pre></codelist>'
355
+ print '</pre>'
332
356
  end
333
357
 
334
358
  def cmd(lines, caption = nil)
335
- quotedlist lines, 'cmd', caption
359
+ quotedlist(lines, 'cmd', caption)
336
360
  end
337
361
 
338
362
  def quotedlist(lines, css_class, caption)
339
363
  print %Q(<list type='#{css_class}'>)
340
- puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>" if caption.present?
364
+ if caption_top?('list') && caption.present?
365
+ puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>"
366
+ end
341
367
  print '<pre>'
342
368
  no = 1
343
369
  lines.each do |line|
@@ -352,7 +378,11 @@ module ReVIEW
352
378
  print '</listinfo>' if @book.config['listinfo']
353
379
  no += 1
354
380
  end
355
- puts '</pre></list>'
381
+ puts '</pre>'
382
+ if !caption_top?('list') && caption.present?
383
+ puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>"
384
+ end
385
+ puts '</list>'
356
386
  end
357
387
  private :quotedlist
358
388
 
@@ -396,20 +426,22 @@ module ReVIEW
396
426
  def image_image(id, caption, metric = nil)
397
427
  metrics = parse_metric('idgxml', metric)
398
428
  puts '<img>'
429
+ image_header(id, caption) if caption_top?('image')
399
430
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} />)
400
- image_header id, caption
431
+ image_header(id, caption) unless caption_top?('image')
401
432
  puts '</img>'
402
433
  end
403
434
 
404
435
  def image_dummy(id, caption, lines)
405
436
  puts '<img>'
437
+ image_header(id, caption) if caption_top?('image')
406
438
  print %Q(<pre aid:pstyle="dummyimage">)
407
439
  lines.each do |line|
408
440
  print detab(line)
409
441
  print "\n"
410
442
  end
411
443
  print '</pre>'
412
- image_header id, caption
444
+ image_header(id, caption) unless caption_top?('image')
413
445
  puts '</img>'
414
446
  warn "image not bound: #{id}"
415
447
  end
@@ -425,96 +457,118 @@ module ReVIEW
425
457
 
426
458
  def texequation(lines, id = nil, caption = '')
427
459
  @texblockequation += 1
460
+ caption_str = nil
428
461
  if id
429
462
  puts '<equationblock>'
430
463
  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>)
464
+ 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
465
  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>)
466
+ 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
467
  end
468
+ puts caption_str if caption_top?('equation')
435
469
  end
436
470
 
437
471
  puts %Q(<replace idref="texblock-#{@texblockequation}">)
438
472
  puts '<pre>'
439
- puts lines.join("\n")
473
+ print lines.join("\n")
440
474
  puts '</pre>'
441
475
  puts '</replace>'
442
476
 
443
477
  if id
478
+ puts caption_str unless caption_top?('equation')
444
479
  puts '</equationblock>'
445
480
  end
446
481
  end
447
482
 
448
483
  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
484
+ @tablewidth = nil
485
+ if @book.config['tableopt']
486
+ @tablewidth = @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f
487
+ end
488
+ @col = 0
451
489
 
490
+ sepidx, rows = parse_table_rows(lines)
452
491
  puts '<table>'
453
- rows = []
492
+
493
+ begin
494
+ if caption_top?('table') && caption.present?
495
+ table_header(id, caption)
496
+ end
497
+
498
+ if @tablewidth.nil?
499
+ print '<tbody>'
500
+ else
501
+ print %Q(<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{@col}">)
502
+ end
503
+ @table_id = id
504
+ table_rows(sepidx, rows)
505
+ puts '</tbody>'
506
+
507
+ if !caption_top?('table') && caption.present?
508
+ table_header(id, caption)
509
+ end
510
+ rescue KeyError
511
+ error "no such table: #{id}"
512
+ end
513
+ puts '</table>'
514
+ @tsize = nil
515
+ end
516
+
517
+ def parse_table_rows(lines)
454
518
  sepidx = nil
519
+ rows = []
455
520
  lines.each_with_index do |line, idx|
456
- if /\A[\=\-]{12}/ =~ line
521
+ if /\A[=\-]{12}/ =~ line
457
522
  sepidx ||= idx
458
523
  next
459
524
  end
460
- if tablewidth
525
+ if @tablewidth
461
526
  rows.push(line.gsub(/\t\.\t/, "\tDUMMYCELLSPLITTER\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\tDUMMYCELLSPLITTER").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
462
527
  else
463
528
  rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
464
529
  end
465
- col2 = rows[rows.length - 1].split(/\t/).length
466
- col = col2 if col2 > col
530
+ col2 = rows[rows.length - 1].split(table_row_separator_regexp).length
531
+ @col = col2 if col2 > @col
467
532
  end
533
+ error 'no rows in the table' if rows.empty?
534
+ [sepidx, rows]
535
+ end
468
536
 
537
+ def table_rows(sepidx, rows)
469
538
  cellwidth = []
470
- if tablewidth
539
+ if @tablewidth
471
540
  if @tsize.nil?
472
- col.times { |n| cellwidth[n] = tablewidth / col }
541
+ @col.times { |n| cellwidth[n] = @tablewidth / @col }
473
542
  else
474
543
  cellwidth = @tsize.split(/\s*,\s*/)
475
544
  totallength = 0
476
545
  cellwidth.size.times do |n|
477
546
  cellwidth[n] = cellwidth[n].to_f / @book.config['pt_to_mm_unit'].to_f
478
547
  totallength += cellwidth[n]
479
- warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
548
+ warn "total length exceeds limit for table: #{@table_id}" if totallength > @tablewidth
480
549
  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 }
550
+ if cellwidth.size < @col
551
+ cw = (@tablewidth - totallength) / (@col - cellwidth.size)
552
+ warn "auto cell sizing exceeds limit for table: #{@table_id}" if cw <= 0
553
+ (cellwidth.size..(@col - 1)).each { |i| cellwidth[i] = cw }
485
554
  end
486
555
  end
487
556
  end
488
557
 
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
558
  if sepidx
503
559
  sepidx.times do |y|
504
- if tablewidth.nil?
560
+ if @tablewidth.nil?
505
561
  puts %Q(<tr type="header">#{rows.shift}</tr>)
506
562
  else
507
563
  i = 0
508
- rows.shift.split("\t").each_with_index do |cell, x|
564
+ rows.shift.split(table_row_separator_regexp).each_with_index do |cell, x|
509
565
  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
566
  i += 1
511
567
  end
512
568
  end
513
569
  end
514
570
  end
515
- trputs(tablewidth, rows, cellwidth, sepidx)
516
- puts '</tbody></table>'
517
- @tsize = nil
571
+ trputs(@tablewidth, rows, cellwidth, sepidx)
518
572
  end
519
573
 
520
574
  def trputs(tablewidth, rows, cellwidth, sepidx)
@@ -522,7 +576,7 @@ module ReVIEW
522
576
  if tablewidth
523
577
  rows.each_with_index do |row, y|
524
578
  i = 0
525
- row.split("\t").each_with_index do |cell, x|
579
+ row.split(table_row_separator_regexp).each_with_index do |cell, x|
526
580
  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
581
  i += 1
528
582
  end
@@ -560,7 +614,6 @@ module ReVIEW
560
614
  end
561
615
 
562
616
  def table_end
563
- print '<?dtp tablerow last?>'
564
617
  end
565
618
 
566
619
  def emtable(lines, caption = nil)
@@ -568,22 +621,27 @@ module ReVIEW
568
621
  end
569
622
 
570
623
  def imgtable(lines, id, caption = nil, metric = nil)
571
- if @chapter.image(id).bound?
624
+ if @chapter.image_bound?(id)
572
625
  metrics = parse_metric('idgxml', metric)
573
626
  puts '<table>'
574
- table_header id, caption if caption.present?
627
+ if caption_top?('table') && caption.present?
628
+ table_header(id, caption)
629
+ end
575
630
  puts %Q(<imgtable><Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} /></imgtable>)
631
+ if !caption_top?('table') && caption.present?
632
+ table_header(id, caption)
633
+ end
576
634
  puts '</table>'
577
635
  else
578
636
  warn "image not bound: #{id}" if @strict
579
- image_dummy id, caption, lines
637
+ image_dummy(id, caption, lines)
580
638
  end
581
639
  end
582
640
 
583
641
  def comment(lines, comment = nil)
584
642
  return unless @book.config['draft']
585
643
  lines ||= []
586
- lines.unshift escape(comment) unless comment.blank?
644
+ lines.unshift(escape(comment)) unless comment.blank?
587
645
  str = lines.join("\n")
588
646
  print "<msg>#{str}</msg>"
589
647
  end
@@ -689,6 +747,14 @@ module ReVIEW
689
747
  %Q(<b>#{escape(str)}</b>)
690
748
  end
691
749
 
750
+ def inline_em(str)
751
+ %Q(<em>#{escape(str)}</em>)
752
+ end
753
+
754
+ def inline_strong(str)
755
+ %Q(<strong>#{escape(str)}</strong>)
756
+ end
757
+
692
758
  def inline_tt(str)
693
759
  %Q(<tt>#{escape(str)}</tt>)
694
760
  end
@@ -886,18 +952,22 @@ module ReVIEW
886
952
  end
887
953
 
888
954
  def note(lines, caption = nil)
955
+ check_nested_minicolumn
889
956
  captionblock('note', lines, caption)
890
957
  end
891
958
 
892
959
  def memo(lines, caption = nil)
960
+ check_nested_minicolumn
893
961
  captionblock('memo', lines, caption)
894
962
  end
895
963
 
896
964
  def tip(lines, caption = nil)
965
+ check_nested_minicolumn
897
966
  captionblock('tip', lines, caption)
898
967
  end
899
968
 
900
969
  def info(lines, caption = nil)
970
+ check_nested_minicolumn
901
971
  captionblock('info', lines, caption)
902
972
  end
903
973
 
@@ -910,6 +980,7 @@ module ReVIEW
910
980
  end
911
981
 
912
982
  def important(lines, caption = nil)
983
+ check_nested_minicolumn
913
984
  captionblock('important', lines, caption)
914
985
  end
915
986
 
@@ -918,10 +989,12 @@ module ReVIEW
918
989
  end
919
990
 
920
991
  def caution(lines, caption = nil)
992
+ check_nested_minicolumn
921
993
  captionblock('caution', lines, caption)
922
994
  end
923
995
 
924
996
  def warning(lines, caption = nil)
997
+ check_nested_minicolumn
925
998
  captionblock('warning', lines, caption)
926
999
  end
927
1000
 
@@ -934,6 +1007,7 @@ module ReVIEW
934
1007
  end
935
1008
 
936
1009
  def notice(lines, caption = nil)
1010
+ check_nested_minicolumn
937
1011
  if caption
938
1012
  captionblock('notice-t', lines, caption, 'notice-title')
939
1013
  else
@@ -969,7 +1043,35 @@ module ReVIEW
969
1043
  captionblock('expert', lines, nil)
970
1044
  end
971
1045
 
1046
+ CAPTION_TITLES.each do |name|
1047
+ class_eval %Q(
1048
+ def #{name}_begin(caption = nil)
1049
+ check_nested_minicolumn
1050
+ if '#{name}' == 'notice' && caption.present?
1051
+ @doc_status[:minicolumn] = '#{name}-t'
1052
+ print "<#{name}-t>"
1053
+ else
1054
+ @doc_status[:minicolumn] = '#{name}'
1055
+ print "<#{name}>"
1056
+ end
1057
+ if caption.present?
1058
+ puts %Q(<title aid:pstyle='#{name}-title'>\#{compile_inline(caption)}</title>)
1059
+ end
1060
+ end
1061
+
1062
+ def #{name}_end
1063
+ if '#{name}' == 'notice' && @doc_status[:minicolumn] == 'notice-t'
1064
+ print "</#{name}-t>"
1065
+ else
1066
+ print "</#{name}>"
1067
+ end
1068
+ @doc_status[:minicolumn] = nil
1069
+ end
1070
+ ), __FILE__, __LINE__ - 23
1071
+ end
1072
+
972
1073
  def syntaxblock(type, lines, caption)
1074
+ captionstr = nil
973
1075
  if caption.present?
974
1076
  titleopentag = %Q(caption aid:pstyle="#{type}-title")
975
1077
  titleclosetag = 'caption'
@@ -977,9 +1079,13 @@ module ReVIEW
977
1079
  titleopentag = %Q(floattitle type="insn")
978
1080
  titleclosetag = 'floattitle'
979
1081
  end
980
- puts %Q(<#{type}><#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
1082
+ captionstr = %Q(<#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
1083
+ end
1084
+ print "<#{type}>"
1085
+ if caption_top?('list')
1086
+ puts captionstr
981
1087
  else
982
- puts "<#{type}>"
1088
+ puts ''
983
1089
  end
984
1090
 
985
1091
  no = 1
@@ -995,6 +1101,9 @@ module ReVIEW
995
1101
  print '</listinfo>' if @book.config['listinfo']
996
1102
  no += 1
997
1103
  end
1104
+ unless caption_top?('list')
1105
+ print captionstr
1106
+ end
998
1107
  puts "</#{type}>"
999
1108
  end
1000
1109
 
@@ -1009,12 +1118,17 @@ module ReVIEW
1009
1118
  def indepimage(_lines, id, caption = nil, metric = nil)
1010
1119
  metrics = parse_metric('idgxml', metric)
1011
1120
  puts '<img>'
1121
+ if caption_top?('image')
1122
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1123
+ end
1012
1124
  begin
1013
1125
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}"#{metrics} />)
1014
1126
  rescue
1015
1127
  warn %Q(image not bound: #{id})
1016
1128
  end
1017
- puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1129
+ unless caption_top?('image')
1130
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1131
+ end
1018
1132
  puts '</img>'
1019
1133
  end
1020
1134
 
@@ -1113,25 +1227,36 @@ module ReVIEW
1113
1227
  error "unknown chapter: #{id}"
1114
1228
  end
1115
1229
 
1116
- def source_header(caption)
1230
+ def source(lines, caption = nil, lang = nil)
1117
1231
  puts '<source>'
1232
+ if caption_top?('list')
1233
+ source_header(caption)
1234
+ end
1235
+ source_body(lines, lang)
1236
+ unless caption_top?('list')
1237
+ source_header(caption)
1238
+ end
1239
+ puts '</source>'
1240
+ end
1241
+
1242
+ def source_header(caption)
1118
1243
  puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1119
1244
  end
1120
1245
 
1121
1246
  def source_body(lines, _lang)
1122
1247
  puts '<pre>'
1123
1248
  codelines_body(lines)
1124
- puts '</pre></source>'
1249
+ print '</pre>'
1125
1250
  end
1126
1251
 
1127
1252
  def bibpaper(lines, id, caption)
1128
- bibpaper_header id, caption
1129
- bibpaper_bibpaper id, caption, lines unless lines.empty?
1253
+ puts %Q(<bibitem id="bib-#{id}">)
1254
+ bibpaper_header(id, caption)
1255
+ bibpaper_bibpaper(id, caption, lines) unless lines.empty?
1130
1256
  puts '</bibitem>'
1131
1257
  end
1132
1258
 
1133
1259
  def bibpaper_header(id, caption)
1134
- puts %Q(<bibitem id="bib-#{id}">)
1135
1260
  puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>" if caption.present?
1136
1261
  end
1137
1262
 
@@ -1146,13 +1271,12 @@ module ReVIEW
1146
1271
  end
1147
1272
 
1148
1273
  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
1274
+ n = chap.headline_index.number(id)
1275
+ if n.present? && chap.number && over_secnolevel?(n)
1276
+ I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
1277
+ else
1278
+ I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
1154
1279
  end
1155
- I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
1156
1280
  rescue KeyError
1157
1281
  error "unknown headline: #{id}"
1158
1282
  end