review 3.2.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +31 -0
  3. data/.github/workflows/ruby-win.yml +45 -0
  4. data/.github/workflows/ruby.yml +27 -0
  5. data/.rubocop.yml +167 -42
  6. data/.travis.yml +1 -1
  7. data/Dockerfile +21 -5
  8. data/NEWS.ja.md +428 -1
  9. data/NEWS.md +429 -2
  10. data/README.md +11 -7
  11. data/Rakefile +7 -2
  12. data/appveyor.yml +0 -20
  13. data/bin/review +2 -4
  14. data/bin/review-catalog-converter +5 -5
  15. data/bin/review-check +13 -17
  16. data/bin/review-checkdep +3 -6
  17. data/bin/review-compile +13 -22
  18. data/bin/review-epub2html +1 -4
  19. data/bin/review-epubmaker +3 -4
  20. data/bin/review-idgxmlmaker +14 -0
  21. data/bin/review-index +5 -86
  22. data/bin/review-init +1 -4
  23. data/bin/review-pdfmaker +1 -3
  24. data/bin/review-preproc +11 -13
  25. data/bin/review-textmaker +1 -3
  26. data/bin/review-update +1 -4
  27. data/bin/review-validate +7 -7
  28. data/bin/review-vol +5 -82
  29. data/bin/review-webmaker +1 -3
  30. data/doc/config.yml.sample +67 -16
  31. data/doc/config.yml.sample-simple +4 -3
  32. data/doc/format.ja.md +133 -21
  33. data/doc/format.md +135 -34
  34. data/doc/makeindex.ja.md +2 -2
  35. data/doc/pdfmaker.ja.md +43 -1
  36. data/doc/pdfmaker.md +42 -1
  37. data/doc/quickstart.ja.md +55 -25
  38. data/doc/quickstart.md +47 -17
  39. data/lib/review.rb +1 -1
  40. data/lib/review/book.rb +2 -2
  41. data/lib/review/book/base.rb +89 -90
  42. data/lib/review/book/bib.rb +21 -0
  43. data/lib/review/book/book_unit.rb +158 -0
  44. data/lib/review/book/chapter.rb +51 -29
  45. data/lib/review/book/index.rb +42 -248
  46. data/lib/review/book/index/item.rb +46 -0
  47. data/lib/review/book/page_metric.rb +7 -7
  48. data/lib/review/book/part.rb +45 -10
  49. data/lib/review/book/volume.rb +5 -5
  50. data/lib/review/builder.rb +171 -54
  51. data/lib/review/call_hook.rb +20 -0
  52. data/lib/review/catalog.rb +15 -17
  53. data/lib/review/compiler.rb +240 -102
  54. data/lib/review/configure.rb +101 -12
  55. data/lib/review/converter.rb +1 -1
  56. data/lib/review/epub2html.rb +6 -1
  57. data/lib/review/epubmaker.rb +120 -118
  58. data/lib/review/epubmaker/content.rb +113 -0
  59. data/lib/review/epubmaker/epubcommon.rb +372 -0
  60. data/lib/review/epubmaker/epubv2.rb +178 -0
  61. data/lib/review/epubmaker/epubv3.rb +231 -0
  62. data/lib/review/epubmaker/producer.rb +168 -0
  63. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  64. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  65. data/lib/review/exception.rb +6 -0
  66. data/lib/review/extentions/string.rb +0 -4
  67. data/lib/review/htmlbuilder.rb +147 -149
  68. data/lib/review/htmlutils.rb +10 -14
  69. data/lib/review/i18n.rb +4 -3
  70. data/lib/review/idgxmlbuilder.rb +229 -103
  71. data/lib/review/idgxmlmaker.rb +188 -0
  72. data/lib/review/img_math.rb +245 -0
  73. data/lib/review/index_builder.rb +654 -0
  74. data/lib/review/init-web/finish.html +10 -0
  75. data/lib/review/init-web/index.html +190 -0
  76. data/lib/review/init-web/review-layout-design.js +691 -0
  77. data/lib/review/init.rb +124 -41
  78. data/lib/review/latexbox.rb +58 -0
  79. data/lib/review/latexbuilder.rb +249 -97
  80. data/lib/review/latexutils.rb +9 -1
  81. data/lib/review/lineinput.rb +113 -3
  82. data/lib/review/logger.rb +43 -8
  83. data/lib/review/makerhelper.rb +13 -186
  84. data/lib/review/markdownbuilder.rb +75 -39
  85. data/lib/review/md2inaobuilder.rb +3 -5
  86. data/lib/review/pdfmaker.rb +88 -83
  87. data/lib/review/plaintextbuilder.rb +158 -83
  88. data/lib/review/preprocessor.rb +30 -24
  89. data/lib/review/rstbuilder.rb +58 -39
  90. data/lib/review/sec_counter.rb +14 -0
  91. data/lib/review/template.rb +6 -0
  92. data/lib/review/textmaker.rb +29 -17
  93. data/lib/review/textutils.rb +68 -2
  94. data/lib/review/tocprinter.rb +242 -97
  95. data/lib/review/topbuilder.rb +147 -61
  96. data/lib/review/update.rb +27 -28
  97. data/lib/review/version.rb +1 -1
  98. data/lib/review/volumeprinter.rb +97 -0
  99. data/lib/review/webmaker.rb +36 -35
  100. data/lib/review/webtocprinter.rb +39 -35
  101. data/lib/review/yamlloader.rb +4 -0
  102. data/review.gemspec +8 -5
  103. data/samples/sample-book/README.md +7 -2
  104. data/samples/sample-book/src/.gitignore +154 -0
  105. data/samples/sample-book/src/config-ebook.yml +4 -0
  106. data/samples/sample-book/src/config-epub2.yml +1 -1
  107. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  108. data/samples/sample-book/src/config-jlreq.yml +6 -0
  109. data/samples/sample-book/src/config.yml +3 -3
  110. data/samples/sample-book/src/lib/tasks/review.rake +45 -14
  111. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  112. data/samples/syntax-book/Gemfile +1 -1
  113. data/samples/syntax-book/ch01.re +3 -1
  114. data/samples/syntax-book/ch02.re +28 -21
  115. data/samples/syntax-book/ch03.re +4 -7
  116. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  117. data/samples/syntax-book/config-jlreq.yml +5 -0
  118. data/samples/syntax-book/config-print.yml +3 -0
  119. data/samples/syntax-book/config.yml +1 -1
  120. data/samples/syntax-book/images/img3-2.png +0 -0
  121. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  122. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  123. data/templates/html/_colophon.html.erb +23 -0
  124. data/templates/html/_colophon_history.html.erb +9 -0
  125. data/templates/html/_cover.html.erb +10 -0
  126. data/templates/html/_part_body.html.erb +6 -0
  127. data/templates/html/_titlepage.html.erb +20 -0
  128. data/templates/html/layout-html5.html.erb +6 -0
  129. data/templates/html/layout-xhtml1.html.erb +6 -0
  130. data/templates/latex/config.erb +45 -27
  131. data/templates/latex/layout.tex.erb +1 -0
  132. data/templates/latex/review-jlreq/README.md +3 -1
  133. data/templates/latex/review-jlreq/review-base.sty +124 -37
  134. data/templates/latex/review-jlreq/review-jlreq.cls +29 -22
  135. data/templates/latex/review-jlreq/review-style.sty +9 -1
  136. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  137. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  138. data/templates/latex/review-jsbook/README.md +46 -5
  139. data/templates/latex/review-jsbook/review-base.sty +111 -30
  140. data/templates/latex/review-jsbook/review-jsbook.cls +16 -2
  141. data/templates/latex/review-jsbook/review-style.sty +10 -2
  142. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  143. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  144. data/templates/opf/epubv2.opf.erb +7 -7
  145. data/templates/opf/epubv3.opf.erb +7 -7
  146. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  147. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  148. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  149. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  150. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  151. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  152. data/templates/web/html/layout-html5.html.erb +9 -8
  153. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  154. data/test/assets/header_listener.html +35 -0
  155. data/test/assets/img_math/img1.png +0 -0
  156. data/test/assets/img_math/img2.png +0 -0
  157. data/test/assets/img_math/img3.png +0 -0
  158. data/test/assets/syntax_book_index_detail.txt +58 -0
  159. data/test/assets/test_template.tex +20 -9
  160. data/test/assets/test_template_backmatter.tex +20 -9
  161. data/test/book_test_helper.rb +11 -5
  162. data/test/run_test.rb +1 -1
  163. data/test/test_book.rb +123 -78
  164. data/test/test_book_chapter.rb +99 -56
  165. data/test/test_book_part.rb +3 -3
  166. data/test/test_builder.rb +24 -15
  167. data/test/test_catalog.rb +19 -42
  168. data/test/test_catalog_converter_cmd.rb +1 -1
  169. data/test/test_converter.rb +1 -0
  170. data/test/test_epub3maker.rb +170 -126
  171. data/test/test_epubmaker.rb +249 -129
  172. data/test/test_epubmaker_cmd.rb +16 -9
  173. data/test/test_helper.rb +23 -11
  174. data/test/test_htmlbuilder.rb +1083 -114
  175. data/test/test_htmlutils.rb +0 -12
  176. data/test/test_i18n.rb +37 -37
  177. data/test/test_idgxmlbuilder.rb +627 -27
  178. data/test/test_idgxmlmaker_cmd.rb +50 -0
  179. data/test/test_image_finder.rb +52 -70
  180. data/test/test_img_math.rb +111 -0
  181. data/test/test_index.rb +62 -52
  182. data/test/test_indexbuilder.rb +52 -0
  183. data/test/test_latexbuilder.rb +1189 -59
  184. data/test/test_latexbuilder_v2.rb +74 -34
  185. data/test/test_lineinput.rb +20 -93
  186. data/test/test_logger.rb +17 -4
  187. data/test/test_makerhelper.rb +2 -14
  188. data/test/test_markdownbuilder.rb +77 -4
  189. data/test/test_md2inaobuilder.rb +12 -2
  190. data/test/test_pdfmaker.rb +101 -12
  191. data/test/test_pdfmaker_cmd.rb +102 -8
  192. data/test/test_plaintextbuilder.rb +562 -31
  193. data/test/test_review_ext.rb +2 -1
  194. data/test/test_reviewheaderlistener.rb +49 -0
  195. data/test/test_rstbuilder.rb +58 -5
  196. data/test/test_sec_counter.rb +156 -0
  197. data/test/test_template.rb +12 -2
  198. data/test/test_textmaker_cmd.rb +58 -0
  199. data/test/test_textutils.rb +109 -2
  200. data/test/test_tocprinter.rb +46 -0
  201. data/test/test_topbuilder.rb +400 -17
  202. data/test/test_update.rb +53 -44
  203. data/test/test_webtocprinter.rb +75 -43
  204. data/test/test_yamlloader.rb +13 -0
  205. data/test/test_zip_exporter.rb +5 -6
  206. data/vendor/gentombow/LICENSE +1 -1
  207. data/vendor/gentombow/Makefile +0 -1
  208. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  209. data/vendor/gentombow/bounddvi-en.tex +1 -0
  210. data/vendor/gentombow/bounddvi.pdf +0 -0
  211. data/vendor/gentombow/bounddvi.sty +30 -7
  212. data/vendor/gentombow/bounddvi.tex +1 -0
  213. data/vendor/gentombow/create_archive.sh +1 -0
  214. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  215. data/vendor/gentombow/gentombow-ja.tex +9 -0
  216. data/vendor/gentombow/gentombow.pdf +0 -0
  217. data/vendor/gentombow/gentombow.sty +32 -10
  218. data/vendor/gentombow/gentombow.tex +8 -0
  219. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  220. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  221. data/vendor/jsclasses/LICENSE +1 -1
  222. data/vendor/jsclasses/Makefile +3 -2
  223. data/vendor/jsclasses/create_archive.sh +5 -5
  224. data/vendor/jsclasses/jis/Makefile +3 -2
  225. data/vendor/jsclasses/jis/jsarticle.cls +74 -31
  226. data/vendor/jsclasses/jis/jsbook.cls +74 -31
  227. data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
  228. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  229. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  230. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  231. data/vendor/jsclasses/jis/jslogo.sty +4 -16
  232. data/vendor/jsclasses/jis/jspf.cls +73 -30
  233. data/vendor/jsclasses/jis/jsreport.cls +74 -31
  234. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  235. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  236. data/vendor/jsclasses/jis/kiyou.cls +74 -31
  237. data/vendor/jsclasses/jis/minijs.sty +65 -22
  238. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  239. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  240. data/vendor/jsclasses/jis/okumacro.sty +4 -17
  241. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  242. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  243. data/vendor/jsclasses/jis/winjis.sty +23 -19
  244. data/vendor/jsclasses/jsarticle.cls +74 -31
  245. data/vendor/jsclasses/jsbook.cls +74 -31
  246. data/vendor/jsclasses/jsclasses.dtx +176 -36
  247. data/vendor/jsclasses/jsclasses.ins +15 -5
  248. data/vendor/jsclasses/jsclasses.pdf +0 -0
  249. data/vendor/jsclasses/jslogo.dtx +4 -4
  250. data/vendor/jsclasses/jslogo.ins +9 -0
  251. data/vendor/jsclasses/jslogo.pdf +0 -0
  252. data/vendor/jsclasses/jslogo.sty +4 -16
  253. data/vendor/jsclasses/jspf.cls +73 -30
  254. data/vendor/jsclasses/jsreport.cls +74 -31
  255. data/vendor/jsclasses/jsverb.ins +9 -0
  256. data/vendor/jsclasses/jsverb.pdf +0 -0
  257. data/vendor/jsclasses/jsverb.sty +1 -13
  258. data/vendor/jsclasses/kiyou.cls +74 -31
  259. data/vendor/jsclasses/minijs.sty +68 -22
  260. data/vendor/jsclasses/okumacro.dtx +4 -5
  261. data/vendor/jsclasses/okumacro.ins +9 -0
  262. data/vendor/jsclasses/okumacro.pdf +0 -0
  263. data/vendor/jsclasses/okumacro.sty +4 -17
  264. data/vendor/jsclasses/okuverb.ins +9 -0
  265. data/vendor/jsclasses/okuverb.pdf +0 -0
  266. data/vendor/jsclasses/okuverb.sty +1 -13
  267. data/vendor/jsclasses/tests/relfont.tex +10 -0
  268. data/vendor/jsclasses/winjis.sty +23 -19
  269. metadata +136 -23
  270. data/.rubocop_todo.yml +0 -7
  271. data/lib/epubmaker.rb +0 -23
  272. data/lib/epubmaker/content.rb +0 -110
  273. data/lib/epubmaker/epubcommon.rb +0 -441
  274. data/lib/epubmaker/epubv2.rb +0 -143
  275. data/lib/epubmaker/epubv3.rb +0 -233
  276. data/lib/epubmaker/producer.rb +0 -375
  277. data/lib/epubmaker/zip_exporter.rb +0 -81
  278. data/lib/lineinput.rb +0 -155
  279. data/lib/review/book/compilable.rb +0 -173
  280. data/lib/review/tocparser.rb +0 -271
  281. data/samples/syntax-book/review-ext.rb +0 -14
  282. data/test/test_tocparser.rb +0 -25
@@ -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)
@@ -138,7 +134,7 @@ module ReVIEW
138
134
  elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/i
139
135
  "id_#{id}" # dummy prefix
140
136
  else
141
- "id_#{CGI.escape(id.gsub('_', '__')).gsub('%', '_').gsub('+', '-')}" # escape all
137
+ "id_#{CGI.escape(id.gsub('_', '__')).tr('%', '_').tr('+', '-')}" # escape all
142
138
  end
143
139
  end
144
140
  end
data/lib/review/i18n.rb CHANGED
@@ -90,7 +90,8 @@ 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
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}/)
@@ -165,7 +166,7 @@ module ReVIEW
165
166
  end
166
167
  end
167
168
  remove_args.reverse_each do |idx|
168
- args.delete_at idx
169
+ args.delete_at(idx)
169
170
  end
170
171
  args_matched = (frmt.count('%') <= args.size)
171
172
  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,19 +85,27 @@ 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)
106
+ output_close_sect_tags(level)
94
107
  case level
95
108
  when 1
96
- if @secttags
97
- print '</sect4>' if @subsubsubsection > 0
98
- print '</sect3>' if @subsubsection > 0
99
- print '</sect2>' if @subsection > 0
100
- print '</sect>' if @section > 0
101
- end
102
-
103
109
  print %Q(<chapter id="chap:#{@chapter.number}">) if @secttags
104
110
 
105
111
  @section = 0
@@ -107,12 +113,6 @@ module ReVIEW
107
113
  @subsubsection = 0
108
114
  @subsubsubsection = 0
109
115
  when 2
110
- if @secttags
111
- print '</sect4>' if @subsubsubsection > 0
112
- print '</sect3>' if @subsubsection > 0
113
- print '</sect2>' if @subsection > 0
114
- print '</sect>' if @section > 0
115
- end
116
116
  @section += 1
117
117
  print %Q(<sect id="sect:#{@chapter.number}.#{@section}">) if @secttags
118
118
 
@@ -120,30 +120,17 @@ module ReVIEW
120
120
  @subsubsection = 0
121
121
  @subsubsubsection = 0
122
122
  when 3
123
- if @secttags
124
- print '</sect4>' if @subsubsubsection > 0
125
- print '</sect3>' if @subsubsection > 0
126
- print '</sect2>' if @subsection > 0
127
- end
128
-
129
123
  @subsection += 1
130
124
  print %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">) if @secttags
131
125
 
132
126
  @subsubsection = 0
133
127
  @subsubsubsection = 0
134
128
  when 4
135
- if @secttags
136
- print '</sect4>' if @subsubsubsection > 0
137
- print '</sect3>' if @subsubsection > 0
138
- end
139
-
140
129
  @subsubsection += 1
141
130
  print %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) if @secttags
142
131
 
143
132
  @subsubsubsection = 0
144
133
  when 5
145
- print '</sect4>' if @secttags && @subsubsubsection > 0
146
-
147
134
  @subsubsubsection += 1
148
135
  print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
149
136
  when 6 # rubocop:disable Lint/EmptyWhen
@@ -158,6 +145,23 @@ module ReVIEW
158
145
  puts %Q(<title#{label} aid:pstyle="h#{level}">#{prefix}#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{prefix}#{toccaption}"?>)
159
146
  end
160
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
+
161
165
  def ul_begin
162
166
  level = block_given? ? yield : ''
163
167
  level = nil if level == 1
@@ -165,7 +169,7 @@ module ReVIEW
165
169
  end
166
170
 
167
171
  def ul_item_begin(lines)
168
- print %Q(<li aid:pstyle="ul-item">#{lines.join.chomp})
172
+ print %Q(<li aid:pstyle="ul-item">#{join_lines_to_paragraph(lines).chomp})
169
173
  end
170
174
 
171
175
  def ul_item_end
@@ -200,7 +204,7 @@ module ReVIEW
200
204
  end
201
205
 
202
206
  def ol_item(lines, num)
203
- puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{lines.join.chomp}</li>)
207
+ puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{join_lines_to_paragraph(lines).chomp}</li>)
204
208
  @ol_num += 1
205
209
  end
206
210
 
@@ -222,7 +226,7 @@ module ReVIEW
222
226
  end
223
227
 
224
228
  def dd(lines)
225
- puts "<dd>#{lines.join.chomp}</dd>"
229
+ puts "<dd>#{join_lines_to_paragraph(lines).chomp}</dd>"
226
230
  end
227
231
 
228
232
  def dl_end
@@ -232,12 +236,12 @@ module ReVIEW
232
236
  def paragraph(lines)
233
237
  if @noindent.nil?
234
238
  if lines[0] =~ /\A(\t+)/
235
- puts %Q(<p inlist="#{$1.size}">#{lines.join.sub(/\A\t+/, '')}</p>)
239
+ puts %Q(<p inlist="#{$1.size}">#{join_lines_to_paragraph(lines).sub(/\A\t+/, '')}</p>)
236
240
  else
237
- puts "<p>#{lines.join}</p>"
241
+ puts "<p>#{join_lines_to_paragraph(lines)}</p>"
238
242
  end
239
243
  else
240
- puts %Q(<p aid:pstyle="noindent" noindent='1'>#{lines.join}</p>)
244
+ puts %Q(<p aid:pstyle="noindent" noindent='1'>#{join_lines_to_paragraph(lines)}</p>)
241
245
  @noindent = nil
242
246
  end
243
247
  end
@@ -269,8 +273,8 @@ module ReVIEW
269
273
  end
270
274
 
271
275
  def list_header(id, caption, _lang)
272
- puts '<codelist>'
273
276
  return true unless caption.present?
277
+
274
278
  if get_chap.nil?
275
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>)
276
280
  else
@@ -294,14 +298,20 @@ module ReVIEW
294
298
  end
295
299
  end
296
300
 
301
+ def list(lines, id, caption, lang = nil)
302
+ puts '<codelist>'
303
+ super(lines, id, caption, lang)
304
+ puts '</codelist>'
305
+ end
306
+
297
307
  def list_body(_id, lines, _lang)
298
308
  print '<pre>'
299
309
  codelines_body(lines)
300
- puts '</pre></codelist>'
310
+ print '</pre>'
301
311
  end
302
312
 
303
313
  def emlist(lines, caption = nil, _lang = nil)
304
- quotedlist lines, 'emlist', caption
314
+ quotedlist(lines, 'emlist', caption)
305
315
  end
306
316
 
307
317
  def emlistnum(lines, caption = nil, _lang = nil)
@@ -310,7 +320,13 @@ module ReVIEW
310
320
  lines.each_with_index do |line, i|
311
321
  lines2 << detab(%Q(<span type='lineno'>) + (i + first_line_num).to_s.rjust(2) + ': </span>' + line)
312
322
  end
313
- quotedlist lines2, 'emlistnum', caption
323
+ quotedlist(lines2, 'emlistnum', caption)
324
+ end
325
+
326
+ def listnum(lines, id, caption, lang = nil)
327
+ puts '<codelist>'
328
+ super(lines, id, caption, lang)
329
+ puts '</codelist>'
314
330
  end
315
331
 
316
332
  def listnum_body(lines, _lang)
@@ -329,16 +345,18 @@ module ReVIEW
329
345
  print '</listinfo>' if @book.config['listinfo']
330
346
  no += 1
331
347
  end
332
- puts '</pre></codelist>'
348
+ print '</pre>'
333
349
  end
334
350
 
335
351
  def cmd(lines, caption = nil)
336
- quotedlist lines, 'cmd', caption
352
+ quotedlist(lines, 'cmd', caption)
337
353
  end
338
354
 
339
355
  def quotedlist(lines, css_class, caption)
340
356
  print %Q(<list type='#{css_class}'>)
341
- 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
342
360
  print '<pre>'
343
361
  no = 1
344
362
  lines.each do |line|
@@ -353,7 +371,11 @@ module ReVIEW
353
371
  print '</listinfo>' if @book.config['listinfo']
354
372
  no += 1
355
373
  end
356
- 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>'
357
379
  end
358
380
  private :quotedlist
359
381
 
@@ -397,26 +419,29 @@ module ReVIEW
397
419
  def image_image(id, caption, metric = nil)
398
420
  metrics = parse_metric('idgxml', metric)
399
421
  puts '<img>'
422
+ image_header(id, caption) if caption_top?('image')
400
423
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} />)
401
- image_header id, caption
424
+ image_header(id, caption) unless caption_top?('image')
402
425
  puts '</img>'
403
426
  end
404
427
 
405
428
  def image_dummy(id, caption, lines)
406
429
  puts '<img>'
430
+ image_header(id, caption) if caption_top?('image')
407
431
  print %Q(<pre aid:pstyle="dummyimage">)
408
432
  lines.each do |line|
409
433
  print detab(line)
410
434
  print "\n"
411
435
  end
412
436
  print '</pre>'
413
- image_header id, caption
437
+ image_header(id, caption) unless caption_top?('image')
414
438
  puts '</img>'
415
439
  warn "image not bound: #{id}"
416
440
  end
417
441
 
418
442
  def image_header(id, caption)
419
443
  return true unless caption.present?
444
+
420
445
  if get_chap.nil?
421
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>)
422
447
  else
@@ -426,97 +451,118 @@ module ReVIEW
426
451
 
427
452
  def texequation(lines, id = nil, caption = '')
428
453
  @texblockequation += 1
454
+ caption_str = nil
429
455
  if id
430
456
  puts '<equationblock>'
431
457
  if get_chap.nil?
432
- 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>)
433
459
  else
434
- 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>)
435
461
  end
462
+ puts caption_str if caption_top?('equation')
436
463
  end
437
464
 
438
465
  puts %Q(<replace idref="texblock-#{@texblockequation}">)
439
466
  puts '<pre>'
440
- puts lines.join("\n")
467
+ print lines.join("\n")
441
468
  puts '</pre>'
442
469
  puts '</replace>'
443
470
 
444
471
  if id
472
+ puts caption_str unless caption_top?('equation')
445
473
  puts '</equationblock>'
446
474
  end
447
475
  end
448
476
 
449
477
  def table(lines, id = nil, caption = nil)
450
- tablewidth = @book.config['tableopt'] ? @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f : nil
451
- col = 0
478
+ @tablewidth = nil
479
+ if @book.config['tableopt']
480
+ @tablewidth = @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f
481
+ end
482
+ @col = 0
452
483
 
453
- rows = []
484
+ sepidx, rows = parse_table_rows(lines)
485
+ puts '<table>'
486
+
487
+ begin
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
504
+ rescue KeyError
505
+ error "no such table: #{id}"
506
+ end
507
+ puts '</table>'
508
+ @tsize = nil
509
+ end
510
+
511
+ def parse_table_rows(lines)
454
512
  sepidx = nil
513
+ rows = []
455
514
  lines.each_with_index do |line, idx|
456
- if /\A[\=\-]{12}/ =~ line
515
+ if /\A[=\-]{12}/ =~ line
457
516
  sepidx ||= idx
458
517
  next
459
518
  end
460
- if tablewidth
519
+ if @tablewidth
461
520
  rows.push(line.gsub(/\t\.\t/, "\tDUMMYCELLSPLITTER\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\tDUMMYCELLSPLITTER").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
462
521
  else
463
522
  rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
464
523
  end
465
- col2 = rows[rows.length - 1].split(/\t/).length
466
- col = col2 if col2 > col
524
+ col2 = rows[rows.length - 1].split(table_row_separator_regexp).length
525
+ @col = col2 if col2 > @col
467
526
  end
468
527
  error 'no rows in the table' if rows.empty?
528
+ [sepidx, rows]
529
+ end
469
530
 
470
- puts '<table>'
471
-
531
+ def table_rows(sepidx, rows)
472
532
  cellwidth = []
473
- if tablewidth
533
+ if @tablewidth
474
534
  if @tsize.nil?
475
- col.times { |n| cellwidth[n] = tablewidth / col }
535
+ @col.times { |n| cellwidth[n] = @tablewidth / @col }
476
536
  else
477
537
  cellwidth = @tsize.split(/\s*,\s*/)
478
538
  totallength = 0
479
539
  cellwidth.size.times do |n|
480
540
  cellwidth[n] = cellwidth[n].to_f / @book.config['pt_to_mm_unit'].to_f
481
541
  totallength += cellwidth[n]
482
- warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
542
+ warn "total length exceeds limit for table: #{@table_id}" if totallength > @tablewidth
483
543
  end
484
- if cellwidth.size < col
485
- cw = (tablewidth - totallength) / (col - cellwidth.size)
486
- warn "auto cell sizing exceeds limit for table: #{id}" if cw <= 0
487
- (cellwidth.size..(col - 1)).each { |i| cellwidth[i] = cw }
544
+ if cellwidth.size < @col
545
+ cw = (@tablewidth - totallength) / (@col - cellwidth.size)
546
+ warn "auto cell sizing exceeds limit for table: #{@table_id}" if cw <= 0
547
+ (cellwidth.size..(@col - 1)).each { |i| cellwidth[i] = cw }
488
548
  end
489
549
  end
490
550
  end
491
551
 
492
- begin
493
- table_header id, caption if caption.present?
494
- rescue KeyError
495
- error "no such table: #{id}"
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
-
504
552
  if sepidx
505
553
  sepidx.times do |y|
506
- if tablewidth.nil?
554
+ if @tablewidth.nil?
507
555
  puts %Q(<tr type="header">#{rows.shift}</tr>)
508
556
  else
509
557
  i = 0
510
- rows.shift.split("\t").each_with_index do |cell, x|
558
+ rows.shift.split(table_row_separator_regexp).each_with_index do |cell, x|
511
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>)
512
560
  i += 1
513
561
  end
514
562
  end
515
563
  end
516
564
  end
517
- trputs(tablewidth, rows, cellwidth, sepidx)
518
- puts '</tbody></table>'
519
- @tsize = nil
565
+ trputs(@tablewidth, rows, cellwidth, sepidx)
520
566
  end
521
567
 
522
568
  def trputs(tablewidth, rows, cellwidth, sepidx)
@@ -524,7 +570,7 @@ module ReVIEW
524
570
  if tablewidth
525
571
  rows.each_with_index do |row, y|
526
572
  i = 0
527
- row.split("\t").each_with_index do |cell, x|
573
+ row.split(table_row_separator_regexp).each_with_index do |cell, x|
528
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>)
529
575
  i += 1
530
576
  end
@@ -562,7 +608,6 @@ module ReVIEW
562
608
  end
563
609
 
564
610
  def table_end
565
- print '<?dtp tablerow last?>'
566
611
  end
567
612
 
568
613
  def emtable(lines, caption = nil)
@@ -570,22 +615,28 @@ module ReVIEW
570
615
  end
571
616
 
572
617
  def imgtable(lines, id, caption = nil, metric = nil)
573
- if @chapter.image(id).bound?
618
+ if @chapter.image_bound?(id)
574
619
  metrics = parse_metric('idgxml', metric)
575
620
  puts '<table>'
576
- table_header id, caption if caption.present?
621
+ if caption_top?('table') && caption.present?
622
+ table_header(id, caption)
623
+ end
577
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
578
628
  puts '</table>'
579
629
  else
580
630
  warn "image not bound: #{id}" if @strict
581
- image_dummy id, caption, lines
631
+ image_dummy(id, caption, lines)
582
632
  end
583
633
  end
584
634
 
585
635
  def comment(lines, comment = nil)
586
636
  return unless @book.config['draft']
637
+
587
638
  lines ||= []
588
- lines.unshift escape(comment) unless comment.blank?
639
+ lines.unshift(escape(comment)) unless comment.blank?
589
640
  str = lines.join("\n")
590
641
  print "<msg>#{str}</msg>"
591
642
  end
@@ -618,7 +669,7 @@ module ReVIEW
618
669
  then escape("#{word}(#{alt.strip})")
619
670
  else escape(word)
620
671
  end +
621
- '</keyword>' +
672
+ '</keyword>' +
622
673
  %Q(<index value="#{escape(word)}" />) +
623
674
  if alt
624
675
  alt.split(/\s*,\s*/).collect! { |e| %Q(<index value="#{escape(e.strip)}" />) }.join
@@ -691,6 +742,14 @@ module ReVIEW
691
742
  %Q(<b>#{escape(str)}</b>)
692
743
  end
693
744
 
745
+ def inline_em(str)
746
+ %Q(<em>#{escape(str)}</em>)
747
+ end
748
+
749
+ def inline_strong(str)
750
+ %Q(<strong>#{escape(str)}</strong>)
751
+ end
752
+
694
753
  def inline_tt(str)
695
754
  %Q(<tt>#{escape(str)}</tt>)
696
755
  end
@@ -709,6 +768,14 @@ module ReVIEW
709
768
  %Q(<underline>#{escape(str)}</underline>)
710
769
  end
711
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
+
712
779
  def inline_icon(id)
713
780
  begin
714
781
  %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}" type="inline" />)
@@ -888,18 +955,22 @@ module ReVIEW
888
955
  end
889
956
 
890
957
  def note(lines, caption = nil)
958
+ check_nested_minicolumn
891
959
  captionblock('note', lines, caption)
892
960
  end
893
961
 
894
962
  def memo(lines, caption = nil)
963
+ check_nested_minicolumn
895
964
  captionblock('memo', lines, caption)
896
965
  end
897
966
 
898
967
  def tip(lines, caption = nil)
968
+ check_nested_minicolumn
899
969
  captionblock('tip', lines, caption)
900
970
  end
901
971
 
902
972
  def info(lines, caption = nil)
973
+ check_nested_minicolumn
903
974
  captionblock('info', lines, caption)
904
975
  end
905
976
 
@@ -912,6 +983,7 @@ module ReVIEW
912
983
  end
913
984
 
914
985
  def important(lines, caption = nil)
986
+ check_nested_minicolumn
915
987
  captionblock('important', lines, caption)
916
988
  end
917
989
 
@@ -920,10 +992,12 @@ module ReVIEW
920
992
  end
921
993
 
922
994
  def caution(lines, caption = nil)
995
+ check_nested_minicolumn
923
996
  captionblock('caution', lines, caption)
924
997
  end
925
998
 
926
999
  def warning(lines, caption = nil)
1000
+ check_nested_minicolumn
927
1001
  captionblock('warning', lines, caption)
928
1002
  end
929
1003
 
@@ -936,6 +1010,7 @@ module ReVIEW
936
1010
  end
937
1011
 
938
1012
  def notice(lines, caption = nil)
1013
+ check_nested_minicolumn
939
1014
  if caption
940
1015
  captionblock('notice-t', lines, caption, 'notice-title')
941
1016
  else
@@ -971,7 +1046,35 @@ module ReVIEW
971
1046
  captionblock('expert', lines, nil)
972
1047
  end
973
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
+
974
1076
  def syntaxblock(type, lines, caption)
1077
+ captionstr = nil
975
1078
  if caption.present?
976
1079
  titleopentag = %Q(caption aid:pstyle="#{type}-title")
977
1080
  titleclosetag = 'caption'
@@ -979,9 +1082,13 @@ module ReVIEW
979
1082
  titleopentag = %Q(floattitle type="insn")
980
1083
  titleclosetag = 'floattitle'
981
1084
  end
982
- 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
983
1090
  else
984
- puts "<#{type}>"
1091
+ puts ''
985
1092
  end
986
1093
 
987
1094
  no = 1
@@ -997,6 +1104,9 @@ module ReVIEW
997
1104
  print '</listinfo>' if @book.config['listinfo']
998
1105
  no += 1
999
1106
  end
1107
+ unless caption_top?('list')
1108
+ print captionstr
1109
+ end
1000
1110
  puts "</#{type}>"
1001
1111
  end
1002
1112
 
@@ -1011,12 +1121,17 @@ module ReVIEW
1011
1121
  def indepimage(_lines, id, caption = nil, metric = nil)
1012
1122
  metrics = parse_metric('idgxml', metric)
1013
1123
  puts '<img>'
1124
+ if caption_top?('image')
1125
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1126
+ end
1014
1127
  begin
1015
1128
  puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}"#{metrics} />)
1016
1129
  rescue
1017
1130
  warn %Q(image not bound: #{id})
1018
1131
  end
1019
- 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
1020
1135
  puts '</img>'
1021
1136
  end
1022
1137
 
@@ -1070,10 +1185,10 @@ module ReVIEW
1070
1185
  chs = ['', '「', '」']
1071
1186
  if @book.config['chapref']
1072
1187
  chs2 = @book.config['chapref'].split(',')
1073
- if chs2.size != 3
1074
- error '--chapsplitter must have exactly 3 parameters with comma.'
1075
- else
1188
+ if chs2.size == 3
1076
1189
  chs = chs2
1190
+ else
1191
+ error '--chapsplitter must have exactly 3 parameters with comma.'
1077
1192
  end
1078
1193
  end
1079
1194
  s = "#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"
@@ -1115,25 +1230,36 @@ module ReVIEW
1115
1230
  error "unknown chapter: #{id}"
1116
1231
  end
1117
1232
 
1118
- def source_header(caption)
1233
+ def source(lines, caption = nil, lang = nil)
1119
1234
  puts '<source>'
1235
+ if caption_top?('list')
1236
+ source_header(caption)
1237
+ end
1238
+ source_body(lines, lang)
1239
+ unless caption_top?('list')
1240
+ source_header(caption)
1241
+ end
1242
+ puts '</source>'
1243
+ end
1244
+
1245
+ def source_header(caption)
1120
1246
  puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1121
1247
  end
1122
1248
 
1123
1249
  def source_body(lines, _lang)
1124
1250
  puts '<pre>'
1125
1251
  codelines_body(lines)
1126
- puts '</pre></source>'
1252
+ print '</pre>'
1127
1253
  end
1128
1254
 
1129
1255
  def bibpaper(lines, id, caption)
1130
- bibpaper_header id, caption
1131
- bibpaper_bibpaper id, caption, lines unless lines.empty?
1256
+ puts %Q(<bibitem id="bib-#{id}">)
1257
+ bibpaper_header(id, caption)
1258
+ bibpaper_bibpaper(id, caption, lines) unless lines.empty?
1132
1259
  puts '</bibitem>'
1133
1260
  end
1134
1261
 
1135
1262
  def bibpaper_header(id, caption)
1136
- puts %Q(<bibitem id="bib-#{id}">)
1137
1263
  puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>" if caption.present?
1138
1264
  end
1139
1265