review 4.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +35 -0
  3. data/.github/workflows/ruby-win.yml +19 -9
  4. data/.github/workflows/ruby.yml +7 -3
  5. data/.rubocop.yml +138 -34
  6. data/NEWS.ja.md +285 -0
  7. data/NEWS.md +285 -1
  8. data/README.md +7 -6
  9. data/Rakefile +7 -2
  10. data/bin/review +2 -4
  11. data/bin/review-catalog-converter +4 -4
  12. data/bin/review-check +8 -12
  13. data/bin/review-checkdep +2 -5
  14. data/bin/review-compile +18 -34
  15. data/bin/review-epub2html +1 -4
  16. data/bin/review-epubmaker +3 -4
  17. data/bin/review-idgxmlmaker +1 -3
  18. data/bin/review-index +5 -86
  19. data/bin/review-init +1 -4
  20. data/bin/review-pdfmaker +1 -3
  21. data/bin/review-preproc +30 -38
  22. data/bin/review-textmaker +1 -3
  23. data/bin/review-update +1 -4
  24. data/bin/review-validate +4 -4
  25. data/bin/review-vol +5 -82
  26. data/bin/review-webmaker +1 -3
  27. data/doc/config.yml.sample +45 -11
  28. data/doc/config.yml.sample-simple +3 -3
  29. data/doc/format.ja.md +103 -13
  30. data/doc/format.md +104 -16
  31. data/doc/makeindex.ja.md +2 -2
  32. data/doc/pdfmaker.ja.md +42 -0
  33. data/doc/pdfmaker.md +41 -0
  34. data/doc/quickstart.ja.md +19 -6
  35. data/doc/quickstart.md +18 -6
  36. data/doc/writing_vertical.ja.md +6 -0
  37. data/lib/review.rb +1 -1
  38. data/lib/review/book.rb +2 -2
  39. data/lib/review/book/base.rb +67 -29
  40. data/lib/review/book/bib.rb +21 -0
  41. data/lib/review/book/book_unit.rb +158 -0
  42. data/lib/review/book/chapter.rb +33 -26
  43. data/lib/review/book/index.rb +24 -185
  44. data/lib/review/book/index/item.rb +7 -1
  45. data/lib/review/book/page_metric.rb +7 -7
  46. data/lib/review/book/part.rb +26 -11
  47. data/lib/review/book/volume.rb +5 -5
  48. data/lib/review/builder.rb +121 -52
  49. data/lib/review/call_hook.rb +20 -0
  50. data/lib/review/catalog.rb +3 -2
  51. data/lib/review/compiler.rb +230 -111
  52. data/lib/review/configure.rb +91 -7
  53. data/lib/review/converter.rb +1 -1
  54. data/lib/review/epub2html.rb +6 -1
  55. data/lib/review/epubmaker.rb +124 -152
  56. data/lib/review/epubmaker/content.rb +113 -0
  57. data/lib/review/epubmaker/epubcommon.rb +372 -0
  58. data/lib/review/epubmaker/epubv2.rb +178 -0
  59. data/lib/review/epubmaker/epubv3.rb +231 -0
  60. data/lib/review/epubmaker/producer.rb +167 -0
  61. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  62. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  63. data/lib/review/exception.rb +13 -0
  64. data/lib/review/htmlbuilder.rb +176 -89
  65. data/lib/review/htmlutils.rb +8 -11
  66. data/lib/review/i18n.rb +2 -1
  67. data/lib/review/idgxmlbuilder.rb +165 -75
  68. data/lib/review/idgxmlmaker.rb +24 -28
  69. data/lib/review/img_math.rb +238 -0
  70. data/lib/review/index_builder.rb +645 -0
  71. data/lib/review/init.rb +9 -17
  72. data/lib/review/latexbox.rb +58 -0
  73. data/lib/review/latexbuilder.rb +193 -75
  74. data/lib/review/latexutils.rb +9 -1
  75. data/lib/review/lineinput.rb +112 -2
  76. data/lib/review/loggable.rb +27 -0
  77. data/lib/review/logger.rb +90 -3
  78. data/lib/review/makerhelper.rb +17 -188
  79. data/lib/review/markdownbuilder.rb +54 -4
  80. data/lib/review/pdfmaker.rb +76 -84
  81. data/lib/review/plaintextbuilder.rb +106 -22
  82. data/lib/review/preprocessor.rb +107 -303
  83. data/lib/review/preprocessor/directive.rb +35 -0
  84. data/lib/review/preprocessor/line.rb +34 -0
  85. data/lib/review/preprocessor/repository.rb +177 -0
  86. data/lib/review/rstbuilder.rb +27 -8
  87. data/lib/review/sec_counter.rb +14 -0
  88. data/lib/review/template.rb +11 -1
  89. data/lib/review/textmaker.rb +27 -32
  90. data/lib/review/textutils.rb +3 -12
  91. data/lib/review/tocprinter.rb +242 -97
  92. data/lib/review/topbuilder.rb +98 -31
  93. data/lib/review/update.rb +12 -13
  94. data/lib/review/version.rb +1 -1
  95. data/lib/review/volumeprinter.rb +97 -0
  96. data/lib/review/webmaker.rb +40 -47
  97. data/lib/review/webtocprinter.rb +39 -35
  98. data/lib/review/yamlloader.rb +2 -1
  99. data/review.gemspec +5 -3
  100. data/samples/sample-book/src/config-epub2.yml +1 -1
  101. data/samples/sample-book/src/config.yml +3 -3
  102. data/samples/sample-book/src/lib/tasks/review.rake +19 -1
  103. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
  104. data/samples/syntax-book/Gemfile +1 -1
  105. data/samples/syntax-book/ch01.re +1 -1
  106. data/samples/syntax-book/ch02.re +21 -6
  107. data/samples/syntax-book/ch03.re +1 -1
  108. data/samples/syntax-book/config.yml +1 -1
  109. data/samples/syntax-book/images/img3-2.png +0 -0
  110. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
  111. data/templates/html/_colophon.html.erb +23 -0
  112. data/templates/html/_colophon_history.html.erb +9 -0
  113. data/templates/html/_cover.html.erb +10 -0
  114. data/templates/html/_part_body.html.erb +6 -0
  115. data/templates/html/_titlepage.html.erb +20 -0
  116. data/templates/html/layout-html5.html.erb +6 -0
  117. data/templates/html/layout-xhtml1.html.erb +6 -0
  118. data/templates/latex/config.erb +35 -23
  119. data/templates/latex/review-jlreq/README.md +3 -1
  120. data/templates/latex/review-jlreq/review-base.sty +36 -23
  121. data/templates/latex/review-jlreq/review-jlreq.cls +18 -25
  122. data/templates/latex/review-jlreq/review-style.sty +6 -1
  123. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  124. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  125. data/templates/latex/review-jsbook/README.md +7 -5
  126. data/templates/latex/review-jsbook/review-base.sty +40 -24
  127. data/templates/latex/review-jsbook/review-jsbook.cls +13 -3
  128. data/templates/latex/review-jsbook/review-style.sty +6 -1
  129. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  130. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  131. data/templates/opf/epubv2.opf.erb +7 -7
  132. data/templates/opf/epubv3.opf.erb +7 -7
  133. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  134. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  135. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  136. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  137. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  138. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  139. data/templates/web/html/layout-html5.html.erb +9 -8
  140. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  141. data/test/assets/header_listener.html +35 -0
  142. data/test/assets/img_math/img1.png +0 -0
  143. data/test/assets/img_math/img2.png +0 -0
  144. data/test/assets/img_math/img3.png +0 -0
  145. data/test/assets/syntax_book_index_detail.txt +58 -0
  146. data/test/assets/test_template.tex +6 -3
  147. data/test/assets/test_template_backmatter.tex +6 -3
  148. data/test/book_test_helper.rb +11 -5
  149. data/test/run_test.rb +1 -1
  150. data/test/test_book.rb +54 -63
  151. data/test/test_book_chapter.rb +95 -54
  152. data/test/test_book_part.rb +3 -3
  153. data/test/test_builder.rb +29 -20
  154. data/test/test_catalog_converter_cmd.rb +1 -1
  155. data/test/test_converter.rb +1 -0
  156. data/test/test_epub3maker.rb +170 -126
  157. data/test/test_epubmaker.rb +254 -129
  158. data/test/test_epubmaker_cmd.rb +15 -4
  159. data/test/test_helper.rb +12 -5
  160. data/test/test_htmlbuilder.rb +926 -76
  161. data/test/test_htmlutils.rb +0 -12
  162. data/test/test_i18n.rb +33 -33
  163. data/test/test_idgxmlbuilder.rb +531 -20
  164. data/test/test_idgxmlmaker_cmd.rb +7 -3
  165. data/test/test_img_math.rb +111 -0
  166. data/test/test_index.rb +62 -52
  167. data/test/test_indexbuilder.rb +52 -0
  168. data/test/test_latexbuilder.rb +891 -20
  169. data/test/test_latexbuilder_v2.rb +56 -10
  170. data/test/test_lineinput.rb +20 -93
  171. data/test/test_logger.rb +7 -7
  172. data/test/test_makerhelper.rb +0 -12
  173. data/test/test_markdownbuilder.rb +32 -0
  174. data/test/test_pdfmaker.rb +100 -11
  175. data/test/test_pdfmaker_cmd.rb +3 -3
  176. data/test/test_plaintextbuilder.rb +546 -32
  177. data/test/test_preprocessor.rb +188 -1
  178. data/test/test_review_ext.rb +2 -1
  179. data/test/test_reviewheaderlistener.rb +49 -0
  180. data/test/test_rstbuilder.rb +25 -1
  181. data/test/test_sec_counter.rb +156 -0
  182. data/test/test_template.rb +12 -2
  183. data/test/test_textmaker_cmd.rb +5 -1
  184. data/test/test_tocprinter.rb +46 -0
  185. data/test/test_topbuilder.rb +324 -20
  186. data/test/test_update.rb +44 -44
  187. data/test/test_webtocprinter.rb +75 -43
  188. data/test/test_zip_exporter.rb +5 -6
  189. data/vendor/gentombow/LICENSE +1 -1
  190. data/vendor/gentombow/Makefile +0 -1
  191. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  192. data/vendor/gentombow/bounddvi-en.tex +1 -0
  193. data/vendor/gentombow/bounddvi.pdf +0 -0
  194. data/vendor/gentombow/bounddvi.sty +30 -7
  195. data/vendor/gentombow/bounddvi.tex +1 -0
  196. data/vendor/gentombow/create_archive.sh +1 -0
  197. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  198. data/vendor/gentombow/gentombow-ja.tex +9 -0
  199. data/vendor/gentombow/gentombow.pdf +0 -0
  200. data/vendor/gentombow/gentombow.sty +32 -10
  201. data/vendor/gentombow/gentombow.tex +8 -0
  202. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  203. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  204. data/vendor/jsclasses/Makefile +3 -2
  205. data/vendor/jsclasses/create_archive.sh +5 -5
  206. data/vendor/jsclasses/jis/Makefile +3 -2
  207. data/vendor/jsclasses/jis/jsarticle.cls +22 -18
  208. data/vendor/jsclasses/jis/jsbook.cls +22 -18
  209. data/vendor/jsclasses/jis/jsclasses.dtx +94 -13
  210. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  211. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  212. data/vendor/jsclasses/jis/jslogo.sty +1 -13
  213. data/vendor/jsclasses/jis/jspf.cls +22 -18
  214. data/vendor/jsclasses/jis/jsreport.cls +22 -18
  215. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  216. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  217. data/vendor/jsclasses/jis/kiyou.cls +22 -18
  218. data/vendor/jsclasses/jis/minijs.sty +65 -22
  219. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  220. data/vendor/jsclasses/jis/okumacro.sty +1 -13
  221. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  222. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  223. data/vendor/jsclasses/jis/winjis.sty +23 -19
  224. data/vendor/jsclasses/jsarticle.cls +22 -18
  225. data/vendor/jsclasses/jsbook.cls +22 -18
  226. data/vendor/jsclasses/jsclasses.dtx +94 -13
  227. data/vendor/jsclasses/jsclasses.ins +15 -5
  228. data/vendor/jsclasses/jsclasses.pdf +0 -0
  229. data/vendor/jsclasses/jslogo.ins +9 -0
  230. data/vendor/jsclasses/jslogo.pdf +0 -0
  231. data/vendor/jsclasses/jslogo.sty +1 -13
  232. data/vendor/jsclasses/jspf.cls +22 -18
  233. data/vendor/jsclasses/jsreport.cls +22 -18
  234. data/vendor/jsclasses/jsverb.ins +9 -0
  235. data/vendor/jsclasses/jsverb.pdf +0 -0
  236. data/vendor/jsclasses/jsverb.sty +1 -13
  237. data/vendor/jsclasses/kiyou.cls +22 -18
  238. data/vendor/jsclasses/minijs.sty +68 -22
  239. data/vendor/jsclasses/okumacro.ins +9 -0
  240. data/vendor/jsclasses/okumacro.pdf +0 -0
  241. data/vendor/jsclasses/okumacro.sty +1 -13
  242. data/vendor/jsclasses/okuverb.ins +9 -0
  243. data/vendor/jsclasses/okuverb.pdf +0 -0
  244. data/vendor/jsclasses/okuverb.sty +1 -13
  245. data/vendor/jsclasses/tests/relfont.tex +10 -0
  246. data/vendor/jsclasses/winjis.sty +23 -19
  247. metadata +106 -22
  248. data/.rubocop_todo.yml +0 -7
  249. data/lib/epubmaker.rb +0 -23
  250. data/lib/epubmaker/content.rb +0 -110
  251. data/lib/epubmaker/epubcommon.rb +0 -441
  252. data/lib/epubmaker/epubv2.rb +0 -143
  253. data/lib/epubmaker/epubv3.rb +0 -233
  254. data/lib/epubmaker/producer.rb +0 -375
  255. data/lib/epubmaker/zip_exporter.rb +0 -81
  256. data/lib/lineinput.rb +0 -155
  257. data/lib/review/book/compilable.rb +0 -178
  258. data/lib/review/tocparser.rb +0 -275
  259. data/test/test_tocparser.rb +0 -25
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2002-2019 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2002-2020 Minero Aoki, Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -10,8 +10,9 @@ require 'review/exception'
10
10
  require 'review/textutils'
11
11
  require 'review/compiler'
12
12
  require 'review/sec_counter'
13
+ require 'review/img_math'
14
+ require 'review/loggable'
13
15
  require 'stringio'
14
- require 'cgi'
15
16
  require 'fileutils'
16
17
  require 'tempfile'
17
18
  require 'csv'
@@ -19,8 +20,9 @@ require 'csv'
19
20
  module ReVIEW
20
21
  class Builder
21
22
  include TextUtils
23
+ include Loggable
22
24
 
23
- CAPTION_TITLES = %w[note memo tip info warning important caution notice].freeze
25
+ CAPTION_TITLES = Compiler.minicolumn_names
24
26
 
25
27
  def pre_paragraph
26
28
  nil
@@ -31,20 +33,17 @@ module ReVIEW
31
33
  end
32
34
 
33
35
  attr_accessor :doc_status
36
+ attr_reader :location
34
37
 
35
- def initialize(strict = false, *args)
38
+ def initialize(strict = false, *_args, img_math: nil)
36
39
  @strict = strict
37
40
  @output = nil
38
41
  @logger = ReVIEW.logger
39
42
  @doc_status = {}
40
43
  @dictionary = {}
41
- builder_init(*args)
44
+ @img_math = img_math
42
45
  end
43
46
 
44
- def builder_init(*args)
45
- end
46
- private :builder_init
47
-
48
47
  def bind(compiler, chapter, location)
49
48
  @compiler = compiler
50
49
  @chapter = chapter
@@ -53,9 +52,14 @@ module ReVIEW
53
52
  if @chapter.present?
54
53
  @book = @chapter.book
55
54
  end
55
+ @chapter.generate_indexes
56
+ if @book
57
+ @book.generate_indexes
58
+ end
56
59
  @tabwidth = nil
57
60
  @tsize = nil
58
61
  if @book && @book.config
62
+ @img_math ||= ReVIEW::ImgMath.new(@book.config)
59
63
  if words_file_path = @book.config['words_file']
60
64
  if words_file_path.is_a?(String)
61
65
  words_files = [words_file_path]
@@ -74,7 +78,7 @@ module ReVIEW
74
78
  begin
75
79
  require 'unicode/eaw'
76
80
  rescue LoadError
77
- warn 'not found unicode/eaw. disabled join_lines_by_lang feature.'
81
+ warn 'not found unicode/eaw. disabled join_lines_by_lang feature.', location: @location
78
82
  @book.config['join_lines_by_lang'] = nil
79
83
  end
80
84
  end
@@ -84,6 +88,7 @@ module ReVIEW
84
88
 
85
89
  def builder_init_file
86
90
  @sec_counter = SecCounter.new(5, @chapter)
91
+ @doc_status = {}
87
92
  end
88
93
  private :builder_init_file
89
94
 
@@ -91,8 +96,19 @@ module ReVIEW
91
96
  false
92
97
  end
93
98
 
99
+ def solve_nest(s)
100
+ check_nest
101
+ s.gsub(/\x01→.+?←\x01/, '')
102
+ end
103
+
104
+ def check_nest
105
+ if @children && !@children.empty?
106
+ app_error "//beginchild of #{@children.reverse.join(',')} misses //endchild"
107
+ end
108
+ end
109
+
94
110
  def result
95
- @output.string
111
+ solve_nest(@output.string)
96
112
  end
97
113
 
98
114
  alias_method :raw_result, :result
@@ -134,6 +150,7 @@ module ReVIEW
134
150
 
135
151
  def line_num
136
152
  return 1 unless @first_line_num
153
+
137
154
  line_n = @first_line_num
138
155
  @first_line_num = nil
139
156
 
@@ -142,32 +159,35 @@ module ReVIEW
142
159
 
143
160
  def list(lines, id, caption, lang = nil)
144
161
  begin
145
- list_header(id, caption, lang)
162
+ list_header(id, caption, lang) if caption_top?('list')
163
+ list_body(id, lines, lang)
164
+ list_header(id, caption, lang) unless caption_top?('list')
146
165
  rescue KeyError
147
- error "no such list: #{id}"
166
+ app_error "no such list: #{id}"
148
167
  end
149
- list_body(id, lines, lang)
150
168
  end
151
169
 
152
170
  def listnum(lines, id, caption, lang = nil)
153
171
  begin
154
- list_header(id, caption, lang)
172
+ list_header(id, caption, lang) if caption_top?('list')
173
+ listnum_body(lines, lang)
174
+ list_header(id, caption, lang) unless caption_top?('list')
155
175
  rescue KeyError
156
- error "no such list: #{id}"
176
+ app_error "no such list: #{id}"
157
177
  end
158
- listnum_body(lines, lang)
159
178
  end
160
179
 
161
180
  def source(lines, caption = nil, lang = nil)
162
- source_header(caption)
181
+ source_header(caption) if caption_top?('list')
163
182
  source_body(lines, lang)
183
+ source_header(caption) unless caption_top?('list')
164
184
  end
165
185
 
166
186
  def image(lines, id, caption, metric = nil)
167
187
  if @chapter.image_bound?(id)
168
188
  image_image(id, caption, metric)
169
189
  else
170
- warn "image not bound: #{id}" if @strict
190
+ warn "image not bound: #{id}", location: @location if @strict
171
191
  image_dummy(id, caption, lines)
172
192
  end
173
193
  end
@@ -175,15 +195,18 @@ module ReVIEW
175
195
  def table(lines, id = nil, caption = nil)
176
196
  sepidx, rows = parse_table_rows(lines)
177
197
  begin
178
- if caption.present?
198
+ if caption_top?('table') && caption.present?
199
+ table_header(id, caption)
200
+ end
201
+ table_begin(rows.first.size)
202
+ table_rows(sepidx, rows)
203
+ table_end
204
+ if !caption_top?('table') && caption.present?
179
205
  table_header(id, caption)
180
206
  end
181
207
  rescue KeyError
182
- error "no such table: #{id}"
208
+ app_error "no such table: #{id}"
183
209
  end
184
- table_begin(rows.first.size)
185
- table_rows(sepidx, rows)
186
- table_end
187
210
  end
188
211
 
189
212
  def table_row_separator_regexp
@@ -197,7 +220,7 @@ module ReVIEW
197
220
  when 'verticalbar'
198
221
  Regexp.new('\s*\\' + escape('|') + '\s*')
199
222
  else
200
- error "Unknown value for 'table_row_separator', shold be: tabs, singletab, spaces, verticalbar"
223
+ app_error "Unknown value for 'table_row_separator', shold be: tabs, singletab, spaces, verticalbar"
201
224
  end
202
225
  end
203
226
 
@@ -205,14 +228,14 @@ module ReVIEW
205
228
  sepidx = nil
206
229
  rows = []
207
230
  lines.each_with_index do |line, idx|
208
- if /\A[\=\-]{12}/ =~ line || /\A[\=\{\-\}]{12}/ =~ line
231
+ if /\A[=\-]{12}/ =~ line || /\A[={\-}]{12}/ =~ line
209
232
  sepidx ||= idx
210
233
  next
211
234
  end
212
235
  rows.push(line.strip.split(table_row_separator_regexp).map { |s| s.sub(/\A\./, '') })
213
236
  end
214
237
  rows = adjust_n_cols(rows)
215
- error 'no rows in the table' if rows.empty?
238
+ app_error 'no rows in the table' if rows.empty?
216
239
  [sepidx, rows]
217
240
  end
218
241
 
@@ -234,7 +257,7 @@ module ReVIEW
234
257
 
235
258
  def adjust_n_cols(rows)
236
259
  rows.each do |cols|
237
- while cols.last and cols.last.strip.empty?
260
+ while cols.last && cols.last.strip.empty?
238
261
  cols.pop
239
262
  end
240
263
  end
@@ -273,19 +296,19 @@ module ReVIEW
273
296
  def inline_chapref(id)
274
297
  compile_inline(@book.chapter_index.display_string(id))
275
298
  rescue KeyError
276
- error "unknown chapter: #{id}"
299
+ app_error "unknown chapter: #{id}"
277
300
  end
278
301
 
279
302
  def inline_chap(id)
280
303
  @book.chapter_index.number(id)
281
304
  rescue KeyError
282
- error "unknown chapter: #{id}"
305
+ app_error "unknown chapter: #{id}"
283
306
  end
284
307
 
285
308
  def inline_title(id)
286
309
  compile_inline(@book.chapter_index.title(id))
287
310
  rescue KeyError
288
- error "unknown chapter: #{id}"
311
+ app_error "unknown chapter: #{id}"
289
312
  end
290
313
 
291
314
  def inline_list(id)
@@ -296,7 +319,7 @@ module ReVIEW
296
319
  %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [chapter.list(id).number])})
297
320
  end
298
321
  rescue KeyError
299
- error "unknown list: #{id}"
322
+ app_error "unknown list: #{id}"
300
323
  end
301
324
 
302
325
  def inline_img(id)
@@ -307,7 +330,7 @@ module ReVIEW
307
330
  %Q(#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [chapter.image(id).number])})
308
331
  end
309
332
  rescue KeyError
310
- error "unknown image: #{id}"
333
+ app_error "unknown image: #{id}"
311
334
  end
312
335
 
313
336
  def inline_imgref(id)
@@ -328,7 +351,7 @@ module ReVIEW
328
351
  %Q(#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [chapter.table(id).number])})
329
352
  end
330
353
  rescue KeyError
331
- error "unknown table: #{id}"
354
+ app_error "unknown table: #{id}"
332
355
  end
333
356
 
334
357
  def inline_eq(id)
@@ -339,13 +362,13 @@ module ReVIEW
339
362
  %Q(#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [chapter.equation(id).number])})
340
363
  end
341
364
  rescue KeyError
342
- error "unknown equation: #{id}"
365
+ app_error "unknown equation: #{id}"
343
366
  end
344
367
 
345
368
  def inline_fn(id)
346
369
  @chapter.footnote(id).content
347
370
  rescue KeyError
348
- error "unknown footnote: #{id}"
371
+ app_error "unknown footnote: #{id}"
349
372
  end
350
373
 
351
374
  def inline_bou(str)
@@ -401,7 +424,7 @@ module ReVIEW
401
424
  inline_hd_chap(@chapter, id)
402
425
  end
403
426
  rescue KeyError
404
- error "unknown headline: #{id}"
427
+ app_error "unknown headline: #{id}"
405
428
  end
406
429
 
407
430
  def inline_column(id)
@@ -415,7 +438,7 @@ module ReVIEW
415
438
  inline_column_chap(@chapter, id)
416
439
  end
417
440
  rescue KeyError
418
- error "unknown column: #{id}"
441
+ app_error "unknown column: #{id}"
419
442
  end
420
443
 
421
444
  def inline_column_chap(chapter, id)
@@ -439,7 +462,7 @@ module ReVIEW
439
462
  if translated
440
463
  escape(translated)
441
464
  else
442
- warn "word not bound: #{s}"
465
+ warn "word not bound: #{s}", location: @location
443
466
  escape("[missing word: #{s}]")
444
467
  end
445
468
  end
@@ -475,18 +498,6 @@ module ReVIEW
475
498
  end
476
499
  end
477
500
 
478
- def warn(msg)
479
- @logger.warn "#{@location}: #{msg}"
480
- end
481
-
482
- def error(msg)
483
- if msg =~ /:\d+: error: /
484
- raise ApplicationError, msg
485
- else
486
- raise ApplicationError, "#{@location}: error: #{msg}"
487
- end
488
- end
489
-
490
501
  def handle_metric(str)
491
502
  str
492
503
  end
@@ -497,11 +508,13 @@ module ReVIEW
497
508
 
498
509
  def parse_metric(type, metric)
499
510
  return '' if metric.blank?
511
+
500
512
  params = metric.split(/,\s*/)
501
513
  results = []
502
514
  params.each do |param|
503
515
  if param =~ /\A.+?::/
504
516
  next unless param =~ /\A#{type}::/
517
+
505
518
  param.sub!(/\A#{type}::/, '')
506
519
  end
507
520
  param2 = handle_metric(param)
@@ -526,6 +539,7 @@ module ReVIEW
526
539
  if m
527
540
  ch = @book.contents.detect { |chap| chap.id == m[1] }
528
541
  raise KeyError unless ch
542
+
529
543
  return [ch, m[2]]
530
544
  end
531
545
  [@chapter, chap_ref]
@@ -538,9 +552,36 @@ module ReVIEW
538
552
  CAPTION_TITLES.each do |name|
539
553
  class_eval %Q(
540
554
  def #{name}(lines, caption = nil)
555
+ check_nested_minicolumn
541
556
  captionblock("#{name}", lines, caption)
542
557
  end
543
- )
558
+
559
+ def #{name}_begin(caption = nil)
560
+ check_nested_minicolumn
561
+ @doc_status[:minicolumn] = '#{name}'
562
+ if caption
563
+ puts compile_inline(caption)
564
+ end
565
+ end
566
+
567
+ def #{name}_end
568
+ @doc_status[:minicolumn] = nil
569
+ end
570
+ ), __FILE__, __LINE__ - 17
571
+ end
572
+
573
+ def check_nested_minicolumn
574
+ if @doc_status[:minicolumn]
575
+ app_error "#{@location}: nested mini-column is not allowed"
576
+ end
577
+ end
578
+
579
+ def in_minicolumn?
580
+ @doc_status[:minicolumn]
581
+ end
582
+
583
+ def minicolumn_block_name?(name)
584
+ CAPTION_TITLES.include?(name)
544
585
  end
545
586
 
546
587
  def graph(lines, id, command, caption = '')
@@ -680,5 +721,33 @@ EOTGNUPLOT
680
721
  def escape(str)
681
722
  str
682
723
  end
724
+
725
+ def previous_list_type
726
+ @compiler.previous_list_type
727
+ end
728
+
729
+ def beginchild
730
+ @children ||= []
731
+ unless previous_list_type
732
+ app_error "//beginchild is shown, but previous element isn't ul, ol, or dl"
733
+ end
734
+ puts "\x01→#{previous_list_type}←\x01"
735
+ @children.push(previous_list_type)
736
+ end
737
+
738
+ def endchild
739
+ if @children.nil? || @children.empty?
740
+ app_error "//endchild is shown, but any opened //beginchild doesn't exist"
741
+ else
742
+ puts "\x01→/#{@children.pop}←\x01"
743
+ end
744
+ end
745
+
746
+ def caption_top?(type)
747
+ unless %w[top bottom].include?(@book.config['caption_position'][type])
748
+ warn "invalid caption_position/#{type} parameter. 'top' is assumed", location: @location
749
+ end
750
+ @book.config['caption_position'][type] != 'bottom'
751
+ end
683
752
  end
684
753
  end # module ReVIEW
@@ -0,0 +1,20 @@
1
+ module ReVIEW
2
+ module CallHook
3
+ def call_hook(hook_name, *params, base_dir: nil)
4
+ maker = @config.maker
5
+ filename = @config.dig(maker, hook_name)
6
+ return unless filename
7
+
8
+ hook = File.absolute_path(filename, base_dir)
9
+ @logger.debug("Call #{hook_name}. (#{hook})")
10
+
11
+ return if !File.exist?(hook) || !FileTest.executable?(hook)
12
+
13
+ if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
14
+ warn 'hook configuration is prohibited in safe mode. ignored.'
15
+ else
16
+ system(hook, *params)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -41,7 +41,7 @@ module ReVIEW
41
41
 
42
42
  def replace_part(old_name, new_name)
43
43
  @yaml['CHAPS'].map! do |e|
44
- if e.is_a?(Hash) and (e.keys.first == old_name)
44
+ if e.is_a?(Hash) && (e.keys.first == old_name)
45
45
  e = { new_name => e.values.first }
46
46
  end
47
47
  e
@@ -50,6 +50,7 @@ module ReVIEW
50
50
 
51
51
  def parts_with_chaps
52
52
  return [] unless @yaml['CHAPS']
53
+
53
54
  @yaml['CHAPS'].flatten.compact
54
55
  end
55
56
 
@@ -89,7 +90,7 @@ module ReVIEW
89
90
  filenames.concat(postdef)
90
91
  end
91
92
  filenames.each do |filename|
92
- refile = File.join(basedir, config['contentdir'], filename)
93
+ refile = File.expand_path(File.join(config['contentdir'], filename), basedir)
93
94
  unless File.exist?(refile)
94
95
  raise FileNotFound, "file not found in catalog.yml: #{refile}"
95
96
  end