review 4.0.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +31 -0
  3. data/.github/workflows/ruby-win.yml +45 -0
  4. data/.github/workflows/ruby.yml +27 -0
  5. data/.rubocop.yml +141 -38
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +338 -1
  8. data/NEWS.md +339 -2
  9. data/README.md +11 -7
  10. data/Rakefile +7 -2
  11. data/appveyor.yml +0 -20
  12. data/bin/review +2 -4
  13. data/bin/review-catalog-converter +4 -4
  14. data/bin/review-check +8 -12
  15. data/bin/review-checkdep +2 -5
  16. data/bin/review-compile +11 -20
  17. data/bin/review-epub2html +1 -4
  18. data/bin/review-epubmaker +3 -4
  19. data/bin/review-idgxmlmaker +1 -3
  20. data/bin/review-index +5 -86
  21. data/bin/review-init +1 -4
  22. data/bin/review-pdfmaker +1 -3
  23. data/bin/review-preproc +3 -5
  24. data/bin/review-textmaker +1 -3
  25. data/bin/review-update +1 -4
  26. data/bin/review-validate +5 -5
  27. data/bin/review-vol +5 -82
  28. data/bin/review-webmaker +1 -3
  29. data/doc/config.yml.sample +55 -12
  30. data/doc/config.yml.sample-simple +4 -3
  31. data/doc/format.ja.md +119 -17
  32. data/doc/format.md +106 -17
  33. data/doc/makeindex.ja.md +2 -2
  34. data/doc/pdfmaker.ja.md +42 -0
  35. data/doc/pdfmaker.md +41 -0
  36. data/doc/quickstart.ja.md +55 -25
  37. data/doc/quickstart.md +47 -17
  38. data/lib/review.rb +1 -1
  39. data/lib/review/book.rb +2 -2
  40. data/lib/review/book/base.rb +69 -30
  41. data/lib/review/book/bib.rb +21 -0
  42. data/lib/review/book/book_unit.rb +158 -0
  43. data/lib/review/book/chapter.rb +33 -26
  44. data/lib/review/book/index.rb +39 -206
  45. data/lib/review/book/index/item.rb +8 -2
  46. data/lib/review/book/page_metric.rb +7 -7
  47. data/lib/review/book/part.rb +26 -11
  48. data/lib/review/book/volume.rb +5 -5
  49. data/lib/review/builder.rb +124 -27
  50. data/lib/review/call_hook.rb +20 -0
  51. data/lib/review/catalog.rb +3 -2
  52. data/lib/review/compiler.rb +197 -91
  53. data/lib/review/configure.rb +95 -9
  54. data/lib/review/converter.rb +1 -1
  55. data/lib/review/epub2html.rb +6 -1
  56. data/lib/review/epubmaker.rb +116 -117
  57. data/lib/review/epubmaker/content.rb +113 -0
  58. data/lib/review/epubmaker/epubcommon.rb +372 -0
  59. data/lib/review/epubmaker/epubv2.rb +178 -0
  60. data/lib/review/epubmaker/epubv3.rb +231 -0
  61. data/lib/review/epubmaker/producer.rb +168 -0
  62. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  63. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  64. data/lib/review/exception.rb +6 -0
  65. data/lib/review/extentions/string.rb +0 -4
  66. data/lib/review/htmlbuilder.rb +132 -87
  67. data/lib/review/htmlutils.rb +8 -11
  68. data/lib/review/i18n.rb +2 -1
  69. data/lib/review/idgxmlbuilder.rb +156 -76
  70. data/lib/review/idgxmlmaker.rb +22 -18
  71. data/lib/review/img_math.rb +245 -0
  72. data/lib/review/index_builder.rb +654 -0
  73. data/lib/review/init.rb +17 -18
  74. data/lib/review/latexbox.rb +58 -0
  75. data/lib/review/latexbuilder.rb +173 -43
  76. data/lib/review/latexutils.rb +9 -1
  77. data/lib/review/lineinput.rb +112 -2
  78. data/lib/review/logger.rb +42 -3
  79. data/lib/review/makerhelper.rb +12 -187
  80. data/lib/review/markdownbuilder.rb +51 -2
  81. data/lib/review/pdfmaker.rb +78 -73
  82. data/lib/review/plaintextbuilder.rb +98 -14
  83. data/lib/review/preprocessor.rb +18 -12
  84. data/lib/review/rstbuilder.rb +28 -9
  85. data/lib/review/sec_counter.rb +14 -0
  86. data/lib/review/template.rb +6 -0
  87. data/lib/review/textmaker.rb +21 -19
  88. data/lib/review/textutils.rb +3 -12
  89. data/lib/review/tocprinter.rb +242 -97
  90. data/lib/review/topbuilder.rb +91 -24
  91. data/lib/review/update.rb +12 -13
  92. data/lib/review/version.rb +1 -1
  93. data/lib/review/volumeprinter.rb +97 -0
  94. data/lib/review/webmaker.rb +34 -33
  95. data/lib/review/webtocprinter.rb +39 -35
  96. data/lib/review/yamlloader.rb +2 -1
  97. data/review.gemspec +5 -3
  98. data/samples/sample-book/src/.gitignore +1 -0
  99. data/samples/sample-book/src/config-ebook.yml +4 -0
  100. data/samples/sample-book/src/config-epub2.yml +1 -1
  101. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  102. data/samples/sample-book/src/config.yml +3 -3
  103. data/samples/sample-book/src/lib/tasks/review.rake +26 -6
  104. data/samples/syntax-book/Gemfile +1 -1
  105. data/samples/syntax-book/ch01.re +3 -1
  106. data/samples/syntax-book/ch02.re +28 -21
  107. data/samples/syntax-book/ch03.re +1 -1
  108. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  109. data/samples/syntax-book/config-print.yml +3 -0
  110. data/samples/syntax-book/config.yml +1 -1
  111. data/samples/syntax-book/images/img3-2.png +0 -0
  112. data/samples/syntax-book/lib/tasks/review.rake +23 -8
  113. data/templates/html/_colophon.html.erb +23 -0
  114. data/templates/html/_colophon_history.html.erb +9 -0
  115. data/templates/html/_cover.html.erb +10 -0
  116. data/templates/html/_part_body.html.erb +6 -0
  117. data/templates/html/_titlepage.html.erb +20 -0
  118. data/templates/html/layout-html5.html.erb +6 -0
  119. data/templates/html/layout-xhtml1.html.erb +6 -0
  120. data/templates/latex/config.erb +41 -29
  121. data/templates/latex/review-jlreq/README.md +3 -1
  122. data/templates/latex/review-jlreq/review-base.sty +47 -22
  123. data/templates/latex/review-jlreq/review-jlreq.cls +25 -24
  124. data/templates/latex/review-jlreq/review-style.sty +6 -1
  125. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  126. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  127. data/templates/latex/review-jsbook/README.md +7 -5
  128. data/templates/latex/review-jsbook/review-base.sty +47 -21
  129. data/templates/latex/review-jsbook/review-jsbook.cls +12 -2
  130. data/templates/latex/review-jsbook/review-style.sty +6 -1
  131. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  132. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  133. data/templates/opf/epubv2.opf.erb +7 -7
  134. data/templates/opf/epubv3.opf.erb +7 -7
  135. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  136. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  137. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  138. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  139. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  140. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  141. data/templates/web/html/layout-html5.html.erb +9 -8
  142. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  143. data/test/assets/header_listener.html +35 -0
  144. data/test/assets/img_math/img1.png +0 -0
  145. data/test/assets/img_math/img2.png +0 -0
  146. data/test/assets/img_math/img3.png +0 -0
  147. data/test/assets/syntax_book_index_detail.txt +58 -0
  148. data/test/assets/test_template.tex +12 -9
  149. data/test/assets/test_template_backmatter.tex +12 -9
  150. data/test/book_test_helper.rb +11 -5
  151. data/test/run_test.rb +1 -1
  152. data/test/test_book.rb +62 -63
  153. data/test/test_book_chapter.rb +99 -56
  154. data/test/test_book_part.rb +3 -3
  155. data/test/test_builder.rb +24 -15
  156. data/test/test_catalog.rb +1 -0
  157. data/test/test_catalog_converter_cmd.rb +1 -1
  158. data/test/test_converter.rb +1 -0
  159. data/test/test_epub3maker.rb +170 -126
  160. data/test/test_epubmaker.rb +249 -129
  161. data/test/test_epubmaker_cmd.rb +14 -7
  162. data/test/test_helper.rb +23 -11
  163. data/test/test_htmlbuilder.rb +956 -76
  164. data/test/test_htmlutils.rb +0 -12
  165. data/test/test_i18n.rb +33 -33
  166. data/test/test_idgxmlbuilder.rb +568 -10
  167. data/test/test_idgxmlmaker_cmd.rb +50 -0
  168. data/test/test_image_finder.rb +52 -70
  169. data/test/test_img_math.rb +111 -0
  170. data/test/test_index.rb +62 -52
  171. data/test/test_indexbuilder.rb +52 -0
  172. data/test/test_latexbuilder.rb +1056 -30
  173. data/test/test_latexbuilder_v2.rb +52 -12
  174. data/test/test_lineinput.rb +20 -93
  175. data/test/test_logger.rb +7 -7
  176. data/test/test_makerhelper.rb +0 -12
  177. data/test/test_markdownbuilder.rb +32 -0
  178. data/test/test_pdfmaker.rb +100 -11
  179. data/test/test_pdfmaker_cmd.rb +101 -7
  180. data/test/test_plaintextbuilder.rb +531 -25
  181. data/test/test_review_ext.rb +2 -1
  182. data/test/test_reviewheaderlistener.rb +49 -0
  183. data/test/test_rstbuilder.rb +25 -1
  184. data/test/test_sec_counter.rb +156 -0
  185. data/test/test_template.rb +12 -2
  186. data/test/test_textmaker_cmd.rb +58 -0
  187. data/test/test_tocprinter.rb +46 -0
  188. data/test/test_topbuilder.rb +365 -10
  189. data/test/test_update.rb +44 -44
  190. data/test/test_webtocprinter.rb +75 -43
  191. data/test/test_zip_exporter.rb +5 -6
  192. data/vendor/gentombow/LICENSE +1 -1
  193. data/vendor/gentombow/Makefile +0 -1
  194. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  195. data/vendor/gentombow/bounddvi-en.tex +1 -0
  196. data/vendor/gentombow/bounddvi.pdf +0 -0
  197. data/vendor/gentombow/bounddvi.sty +30 -7
  198. data/vendor/gentombow/bounddvi.tex +1 -0
  199. data/vendor/gentombow/create_archive.sh +1 -0
  200. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  201. data/vendor/gentombow/gentombow-ja.tex +9 -0
  202. data/vendor/gentombow/gentombow.pdf +0 -0
  203. data/vendor/gentombow/gentombow.sty +32 -10
  204. data/vendor/gentombow/gentombow.tex +8 -0
  205. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  206. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  207. data/vendor/jsclasses/LICENSE +1 -1
  208. data/vendor/jsclasses/Makefile +3 -2
  209. data/vendor/jsclasses/create_archive.sh +5 -5
  210. data/vendor/jsclasses/jis/Makefile +3 -2
  211. data/vendor/jsclasses/jis/jsarticle.cls +74 -31
  212. data/vendor/jsclasses/jis/jsbook.cls +74 -31
  213. data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
  214. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  215. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  216. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  217. data/vendor/jsclasses/jis/jslogo.sty +4 -16
  218. data/vendor/jsclasses/jis/jspf.cls +73 -30
  219. data/vendor/jsclasses/jis/jsreport.cls +74 -31
  220. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  221. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  222. data/vendor/jsclasses/jis/kiyou.cls +74 -31
  223. data/vendor/jsclasses/jis/minijs.sty +65 -22
  224. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  225. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  226. data/vendor/jsclasses/jis/okumacro.sty +4 -17
  227. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  228. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  229. data/vendor/jsclasses/jis/winjis.sty +23 -19
  230. data/vendor/jsclasses/jsarticle.cls +74 -31
  231. data/vendor/jsclasses/jsbook.cls +74 -31
  232. data/vendor/jsclasses/jsclasses.dtx +176 -36
  233. data/vendor/jsclasses/jsclasses.ins +15 -5
  234. data/vendor/jsclasses/jsclasses.pdf +0 -0
  235. data/vendor/jsclasses/jslogo.dtx +4 -4
  236. data/vendor/jsclasses/jslogo.ins +9 -0
  237. data/vendor/jsclasses/jslogo.pdf +0 -0
  238. data/vendor/jsclasses/jslogo.sty +4 -16
  239. data/vendor/jsclasses/jspf.cls +73 -30
  240. data/vendor/jsclasses/jsreport.cls +74 -31
  241. data/vendor/jsclasses/jsverb.ins +9 -0
  242. data/vendor/jsclasses/jsverb.pdf +0 -0
  243. data/vendor/jsclasses/jsverb.sty +1 -13
  244. data/vendor/jsclasses/kiyou.cls +74 -31
  245. data/vendor/jsclasses/minijs.sty +68 -22
  246. data/vendor/jsclasses/okumacro.dtx +4 -5
  247. data/vendor/jsclasses/okumacro.ins +9 -0
  248. data/vendor/jsclasses/okumacro.pdf +0 -0
  249. data/vendor/jsclasses/okumacro.sty +4 -17
  250. data/vendor/jsclasses/okuverb.ins +9 -0
  251. data/vendor/jsclasses/okuverb.pdf +0 -0
  252. data/vendor/jsclasses/okuverb.sty +1 -13
  253. data/vendor/jsclasses/tests/relfont.tex +10 -0
  254. data/vendor/jsclasses/winjis.sty +23 -19
  255. metadata +109 -20
  256. data/.rubocop_todo.yml +0 -7
  257. data/lib/epubmaker.rb +0 -23
  258. data/lib/epubmaker/content.rb +0 -110
  259. data/lib/epubmaker/epubcommon.rb +0 -441
  260. data/lib/epubmaker/epubv2.rb +0 -143
  261. data/lib/epubmaker/epubv3.rb +0 -233
  262. data/lib/epubmaker/producer.rb +0 -375
  263. data/lib/epubmaker/zip_exporter.rb +0 -81
  264. data/lib/lineinput.rb +0 -155
  265. data/lib/review/book/compilable.rb +0 -178
  266. data/lib/review/tocparser.rb +0 -271
  267. data/samples/syntax-book/review-ext.rb +0 -14
  268. 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
@@ -137,7 +134,7 @@ module ReVIEW
137
134
  elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/i
138
135
  "id_#{id}" # dummy prefix
139
136
  else
140
- "id_#{CGI.escape(id.gsub('_', '__')).gsub('%', '_').gsub('+', '-')}" # escape all
137
+ "id_#{CGI.escape(id.gsub('_', '__')).tr('%', '_').tr('+', '-')}" # escape all
141
138
  end
142
139
  end
143
140
  end
data/lib/review/i18n.rb CHANGED
@@ -91,6 +91,7 @@ module ReVIEW
91
91
  else
92
92
  user_i18n.each do |key, values|
93
93
  raise KeyError, "Invalid locale file: #{path}" unless values.is_a?(Hash)
94
+
94
95
  @store[key].merge!(values)
95
96
  end
96
97
  end
@@ -125,7 +126,7 @@ module ReVIEW
125
126
  frmt.gsub!('%%', '##')
126
127
 
127
128
  unless args.is_a?(Array)
128
- args = args.nil? && frmt !~ /\%/ ? [] : [args]
129
+ args = args.nil? && frmt !~ /%/ ? [] : [args]
129
130
  end
130
131
 
131
132
  percents = frmt.scan(/%[A-Za-z]{1,3}/)
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2019 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.
@@ -46,10 +46,6 @@ module ReVIEW
46
46
  '.xml'
47
47
  end
48
48
 
49
- def builder_init
50
- end
51
- private :builder_init
52
-
53
49
  def builder_init_file
54
50
  @warns = []
55
51
  @errors = []
@@ -89,19 +85,27 @@ module ReVIEW
89
85
  s += '</sect>' if @section > 0
90
86
  s += '</chapter>' if @chapter.number > 0
91
87
  end
92
- @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", '')
93
103
  end
94
104
 
95
105
  def headline(level, label, caption)
106
+ output_close_sect_tags(level)
96
107
  case level
97
108
  when 1
98
- if @secttags
99
- print '</sect4>' if @subsubsubsection > 0
100
- print '</sect3>' if @subsubsection > 0
101
- print '</sect2>' if @subsection > 0
102
- print '</sect>' if @section > 0
103
- end
104
-
105
109
  print %Q(<chapter id="chap:#{@chapter.number}">) if @secttags
106
110
 
107
111
  @section = 0
@@ -109,12 +113,6 @@ module ReVIEW
109
113
  @subsubsection = 0
110
114
  @subsubsubsection = 0
111
115
  when 2
112
- if @secttags
113
- print '</sect4>' if @subsubsubsection > 0
114
- print '</sect3>' if @subsubsection > 0
115
- print '</sect2>' if @subsection > 0
116
- print '</sect>' if @section > 0
117
- end
118
116
  @section += 1
119
117
  print %Q(<sect id="sect:#{@chapter.number}.#{@section}">) if @secttags
120
118
 
@@ -122,30 +120,17 @@ module ReVIEW
122
120
  @subsubsection = 0
123
121
  @subsubsubsection = 0
124
122
  when 3
125
- if @secttags
126
- print '</sect4>' if @subsubsubsection > 0
127
- print '</sect3>' if @subsubsection > 0
128
- print '</sect2>' if @subsection > 0
129
- end
130
-
131
123
  @subsection += 1
132
124
  print %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">) if @secttags
133
125
 
134
126
  @subsubsection = 0
135
127
  @subsubsubsection = 0
136
128
  when 4
137
- if @secttags
138
- print '</sect4>' if @subsubsubsection > 0
139
- print '</sect3>' if @subsubsection > 0
140
- end
141
-
142
129
  @subsubsection += 1
143
130
  print %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) if @secttags
144
131
 
145
132
  @subsubsubsection = 0
146
133
  when 5
147
- print '</sect4>' if @secttags && @subsubsubsection > 0
148
-
149
134
  @subsubsubsection += 1
150
135
  print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
151
136
  when 6 # rubocop:disable Lint/EmptyWhen
@@ -160,6 +145,23 @@ module ReVIEW
160
145
  puts %Q(<title#{label} aid:pstyle="h#{level}">#{prefix}#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{prefix}#{toccaption}"?>)
161
146
  end
162
147
 
148
+ def output_close_sect_tags(level)
149
+ if @secttags
150
+ if level <= 5 && @subsubsubsection > 0
151
+ print '</sect4>'
152
+ end
153
+ if level <= 4 && @subsubsection > 0
154
+ print '</sect3>'
155
+ end
156
+ if level <= 3 && @subsection > 0
157
+ print '</sect2>'
158
+ end
159
+ if level <= 2 && @section > 0
160
+ print '</sect>'
161
+ end
162
+ end
163
+ end
164
+
163
165
  def ul_begin
164
166
  level = block_given? ? yield : ''
165
167
  level = nil if level == 1
@@ -272,6 +274,7 @@ module ReVIEW
272
274
 
273
275
  def list_header(id, caption, _lang)
274
276
  return true unless caption.present?
277
+
275
278
  if get_chap.nil?
276
279
  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>)
277
280
  else
@@ -297,12 +300,7 @@ module ReVIEW
297
300
 
298
301
  def list(lines, id, caption, lang = nil)
299
302
  puts '<codelist>'
300
- begin
301
- list_header(id, caption, lang)
302
- rescue KeyError
303
- error "no such list: #{id}"
304
- end
305
- list_body(id, lines, lang)
303
+ super(lines, id, caption, lang)
306
304
  puts '</codelist>'
307
305
  end
308
306
 
@@ -327,12 +325,7 @@ module ReVIEW
327
325
 
328
326
  def listnum(lines, id, caption, lang = nil)
329
327
  puts '<codelist>'
330
- begin
331
- list_header(id, caption, lang)
332
- rescue KeyError
333
- error "no such list: #{id}"
334
- end
335
- listnum_body(lines, lang)
328
+ super(lines, id, caption, lang)
336
329
  puts '</codelist>'
337
330
  end
338
331
 
@@ -361,7 +354,9 @@ module ReVIEW
361
354
 
362
355
  def quotedlist(lines, css_class, caption)
363
356
  print %Q(<list type='#{css_class}'>)
364
- puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>" if caption.present?
357
+ if caption_top?('list') && caption.present?
358
+ puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>"
359
+ end
365
360
  print '<pre>'
366
361
  no = 1
367
362
  lines.each do |line|
@@ -376,7 +371,11 @@ module ReVIEW
376
371
  print '</listinfo>' if @book.config['listinfo']
377
372
  no += 1
378
373
  end
379
- puts '</pre></list>'
374
+ puts '</pre>'
375
+ if !caption_top?('list') && caption.present?
376
+ puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>"
377
+ end
378
+ puts '</list>'
380
379
  end
381
380
  private :quotedlist
382
381
 
@@ -420,26 +419,29 @@ module ReVIEW
420
419
  def image_image(id, caption, metric = nil)
421
420
  metrics = parse_metric('idgxml', metric)
422
421
  puts '<img>'
422
+ image_header(id, caption) if caption_top?('image')
423
423
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} />)
424
- image_header(id, caption)
424
+ image_header(id, caption) unless caption_top?('image')
425
425
  puts '</img>'
426
426
  end
427
427
 
428
428
  def image_dummy(id, caption, lines)
429
429
  puts '<img>'
430
+ image_header(id, caption) if caption_top?('image')
430
431
  print %Q(<pre aid:pstyle="dummyimage">)
431
432
  lines.each do |line|
432
433
  print detab(line)
433
434
  print "\n"
434
435
  end
435
436
  print '</pre>'
436
- image_header(id, caption)
437
+ image_header(id, caption) unless caption_top?('image')
437
438
  puts '</img>'
438
439
  warn "image not bound: #{id}"
439
440
  end
440
441
 
441
442
  def image_header(id, caption)
442
443
  return true unless caption.present?
444
+
443
445
  if get_chap.nil?
444
446
  puts %Q(<caption>#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
445
447
  else
@@ -449,13 +451,15 @@ module ReVIEW
449
451
 
450
452
  def texequation(lines, id = nil, caption = '')
451
453
  @texblockequation += 1
454
+ caption_str = nil
452
455
  if id
453
456
  puts '<equationblock>'
454
457
  if get_chap.nil?
455
- 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>)
458
+ 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>)
456
459
  else
457
- 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>)
460
+ 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>)
458
461
  end
462
+ puts caption_str if caption_top?('equation')
459
463
  end
460
464
 
461
465
  puts %Q(<replace idref="texblock-#{@texblockequation}">)
@@ -465,6 +469,7 @@ module ReVIEW
465
469
  puts '</replace>'
466
470
 
467
471
  if id
472
+ puts caption_str unless caption_top?('equation')
468
473
  puts '</equationblock>'
469
474
  end
470
475
  end
@@ -480,18 +485,26 @@ module ReVIEW
480
485
  puts '<table>'
481
486
 
482
487
  begin
483
- table_header(id, caption) if caption.present?
488
+ if caption_top?('table') && caption.present?
489
+ table_header(id, caption)
490
+ end
491
+
492
+ if @tablewidth.nil?
493
+ print '<tbody>'
494
+ else
495
+ print %Q(<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{@col}">)
496
+ end
497
+ @table_id = id
498
+ table_rows(sepidx, rows)
499
+ puts '</tbody>'
500
+
501
+ if !caption_top?('table') && caption.present?
502
+ table_header(id, caption)
503
+ end
484
504
  rescue KeyError
485
505
  error "no such table: #{id}"
486
506
  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_rows(sepidx, rows)
494
- puts '</tbody></table>'
507
+ puts '</table>'
495
508
  @tsize = nil
496
509
  end
497
510
 
@@ -499,7 +512,7 @@ module ReVIEW
499
512
  sepidx = nil
500
513
  rows = []
501
514
  lines.each_with_index do |line, idx|
502
- if /\A[\=\-]{12}/ =~ line
515
+ if /\A[=\-]{12}/ =~ line
503
516
  sepidx ||= idx
504
517
  next
505
518
  end
@@ -508,7 +521,7 @@ module ReVIEW
508
521
  else
509
522
  rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
510
523
  end
511
- col2 = rows[rows.length - 1].split(/\t/).length
524
+ col2 = rows[rows.length - 1].split(table_row_separator_regexp).length
512
525
  @col = col2 if col2 > @col
513
526
  end
514
527
  error 'no rows in the table' if rows.empty?
@@ -526,11 +539,11 @@ module ReVIEW
526
539
  cellwidth.size.times do |n|
527
540
  cellwidth[n] = cellwidth[n].to_f / @book.config['pt_to_mm_unit'].to_f
528
541
  totallength += cellwidth[n]
529
- warn "total length exceeds limit for table: #{id}" if totallength > @tablewidth
542
+ warn "total length exceeds limit for table: #{@table_id}" if totallength > @tablewidth
530
543
  end
531
544
  if cellwidth.size < @col
532
545
  cw = (@tablewidth - totallength) / (@col - cellwidth.size)
533
- warn "auto cell sizing exceeds limit for table: #{id}" if cw <= 0
546
+ warn "auto cell sizing exceeds limit for table: #{@table_id}" if cw <= 0
534
547
  (cellwidth.size..(@col - 1)).each { |i| cellwidth[i] = cw }
535
548
  end
536
549
  end
@@ -542,7 +555,7 @@ module ReVIEW
542
555
  puts %Q(<tr type="header">#{rows.shift}</tr>)
543
556
  else
544
557
  i = 0
545
- rows.shift.split("\t").each_with_index do |cell, x|
558
+ rows.shift.split(table_row_separator_regexp).each_with_index do |cell, x|
546
559
  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>)
547
560
  i += 1
548
561
  end
@@ -557,7 +570,7 @@ module ReVIEW
557
570
  if tablewidth
558
571
  rows.each_with_index do |row, y|
559
572
  i = 0
560
- row.split("\t").each_with_index do |cell, x|
573
+ row.split(table_row_separator_regexp).each_with_index do |cell, x|
561
574
  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>)
562
575
  i += 1
563
576
  end
@@ -602,11 +615,16 @@ module ReVIEW
602
615
  end
603
616
 
604
617
  def imgtable(lines, id, caption = nil, metric = nil)
605
- if @chapter.image(id).bound?
618
+ if @chapter.image_bound?(id)
606
619
  metrics = parse_metric('idgxml', metric)
607
620
  puts '<table>'
608
- table_header(id, caption) if caption.present?
621
+ if caption_top?('table') && caption.present?
622
+ table_header(id, caption)
623
+ end
609
624
  puts %Q(<imgtable><Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} /></imgtable>)
625
+ if !caption_top?('table') && caption.present?
626
+ table_header(id, caption)
627
+ end
610
628
  puts '</table>'
611
629
  else
612
630
  warn "image not bound: #{id}" if @strict
@@ -616,6 +634,7 @@ module ReVIEW
616
634
 
617
635
  def comment(lines, comment = nil)
618
636
  return unless @book.config['draft']
637
+
619
638
  lines ||= []
620
639
  lines.unshift(escape(comment)) unless comment.blank?
621
640
  str = lines.join("\n")
@@ -650,7 +669,7 @@ module ReVIEW
650
669
  then escape("#{word}(#{alt.strip})")
651
670
  else escape(word)
652
671
  end +
653
- '</keyword>' +
672
+ '</keyword>' +
654
673
  %Q(<index value="#{escape(word)}" />) +
655
674
  if alt
656
675
  alt.split(/\s*,\s*/).collect! { |e| %Q(<index value="#{escape(e.strip)}" />) }.join
@@ -749,6 +768,14 @@ module ReVIEW
749
768
  %Q(<underline>#{escape(str)}</underline>)
750
769
  end
751
770
 
771
+ def inline_ins(str)
772
+ %Q(<ins>#{escape(str)}</ins>)
773
+ end
774
+
775
+ def inline_del(str)
776
+ %Q(<del>#{escape(str)}</del>)
777
+ end
778
+
752
779
  def inline_icon(id)
753
780
  begin
754
781
  %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}" type="inline" />)
@@ -928,18 +955,22 @@ module ReVIEW
928
955
  end
929
956
 
930
957
  def note(lines, caption = nil)
958
+ check_nested_minicolumn
931
959
  captionblock('note', lines, caption)
932
960
  end
933
961
 
934
962
  def memo(lines, caption = nil)
963
+ check_nested_minicolumn
935
964
  captionblock('memo', lines, caption)
936
965
  end
937
966
 
938
967
  def tip(lines, caption = nil)
968
+ check_nested_minicolumn
939
969
  captionblock('tip', lines, caption)
940
970
  end
941
971
 
942
972
  def info(lines, caption = nil)
973
+ check_nested_minicolumn
943
974
  captionblock('info', lines, caption)
944
975
  end
945
976
 
@@ -952,6 +983,7 @@ module ReVIEW
952
983
  end
953
984
 
954
985
  def important(lines, caption = nil)
986
+ check_nested_minicolumn
955
987
  captionblock('important', lines, caption)
956
988
  end
957
989
 
@@ -960,10 +992,12 @@ module ReVIEW
960
992
  end
961
993
 
962
994
  def caution(lines, caption = nil)
995
+ check_nested_minicolumn
963
996
  captionblock('caution', lines, caption)
964
997
  end
965
998
 
966
999
  def warning(lines, caption = nil)
1000
+ check_nested_minicolumn
967
1001
  captionblock('warning', lines, caption)
968
1002
  end
969
1003
 
@@ -976,6 +1010,7 @@ module ReVIEW
976
1010
  end
977
1011
 
978
1012
  def notice(lines, caption = nil)
1013
+ check_nested_minicolumn
979
1014
  if caption
980
1015
  captionblock('notice-t', lines, caption, 'notice-title')
981
1016
  else
@@ -1011,7 +1046,35 @@ module ReVIEW
1011
1046
  captionblock('expert', lines, nil)
1012
1047
  end
1013
1048
 
1049
+ CAPTION_TITLES.each do |name|
1050
+ class_eval %Q(
1051
+ def #{name}_begin(caption = nil)
1052
+ check_nested_minicolumn
1053
+ if '#{name}' == 'notice' && caption.present?
1054
+ @doc_status[:minicolumn] = '#{name}-t'
1055
+ print "<#{name}-t>"
1056
+ else
1057
+ @doc_status[:minicolumn] = '#{name}'
1058
+ print "<#{name}>"
1059
+ end
1060
+ if caption.present?
1061
+ puts %Q(<title aid:pstyle='#{name}-title'>\#{compile_inline(caption)}</title>)
1062
+ end
1063
+ end
1064
+
1065
+ def #{name}_end
1066
+ if '#{name}' == 'notice' && @doc_status[:minicolumn] == 'notice-t'
1067
+ print "</#{name}-t>"
1068
+ else
1069
+ print "</#{name}>"
1070
+ end
1071
+ @doc_status[:minicolumn] = nil
1072
+ end
1073
+ ), __FILE__, __LINE__ - 23
1074
+ end
1075
+
1014
1076
  def syntaxblock(type, lines, caption)
1077
+ captionstr = nil
1015
1078
  if caption.present?
1016
1079
  titleopentag = %Q(caption aid:pstyle="#{type}-title")
1017
1080
  titleclosetag = 'caption'
@@ -1019,9 +1082,13 @@ module ReVIEW
1019
1082
  titleopentag = %Q(floattitle type="insn")
1020
1083
  titleclosetag = 'floattitle'
1021
1084
  end
1022
- puts %Q(<#{type}><#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
1085
+ captionstr = %Q(<#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
1086
+ end
1087
+ print "<#{type}>"
1088
+ if caption_top?('list')
1089
+ puts captionstr
1023
1090
  else
1024
- puts "<#{type}>"
1091
+ puts ''
1025
1092
  end
1026
1093
 
1027
1094
  no = 1
@@ -1037,6 +1104,9 @@ module ReVIEW
1037
1104
  print '</listinfo>' if @book.config['listinfo']
1038
1105
  no += 1
1039
1106
  end
1107
+ unless caption_top?('list')
1108
+ print captionstr
1109
+ end
1040
1110
  puts "</#{type}>"
1041
1111
  end
1042
1112
 
@@ -1051,12 +1121,17 @@ module ReVIEW
1051
1121
  def indepimage(_lines, id, caption = nil, metric = nil)
1052
1122
  metrics = parse_metric('idgxml', metric)
1053
1123
  puts '<img>'
1124
+ if caption_top?('image')
1125
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1126
+ end
1054
1127
  begin
1055
1128
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}"#{metrics} />)
1056
1129
  rescue
1057
1130
  warn %Q(image not bound: #{id})
1058
1131
  end
1059
- puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1132
+ unless caption_top?('image')
1133
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1134
+ end
1060
1135
  puts '</img>'
1061
1136
  end
1062
1137
 
@@ -1110,10 +1185,10 @@ module ReVIEW
1110
1185
  chs = ['', '「', '」']
1111
1186
  if @book.config['chapref']
1112
1187
  chs2 = @book.config['chapref'].split(',')
1113
- if chs2.size != 3
1114
- error '--chapsplitter must have exactly 3 parameters with comma.'
1115
- else
1188
+ if chs2.size == 3
1116
1189
  chs = chs2
1190
+ else
1191
+ error '--chapsplitter must have exactly 3 parameters with comma.'
1117
1192
  end
1118
1193
  end
1119
1194
  s = "#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"
@@ -1155,10 +1230,15 @@ module ReVIEW
1155
1230
  error "unknown chapter: #{id}"
1156
1231
  end
1157
1232
 
1158
- def source(lines, caption, lang = nil)
1233
+ def source(lines, caption = nil, lang = nil)
1159
1234
  puts '<source>'
1160
- source_header(caption)
1235
+ if caption_top?('list')
1236
+ source_header(caption)
1237
+ end
1161
1238
  source_body(lines, lang)
1239
+ unless caption_top?('list')
1240
+ source_header(caption)
1241
+ end
1162
1242
  puts '</source>'
1163
1243
  end
1164
1244