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) 2008-2019 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
1
+ # Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
2
2
  # KADO Masanori
3
3
  # 2002-2007 Minero Aoki
4
4
  #
@@ -51,6 +51,7 @@ module ReVIEW
51
51
  if tail.nil? || head.nil?
52
52
  return nil
53
53
  end
54
+
54
55
  space = true
55
56
  # rule 2
56
57
  if %i[F W H].include?(Unicode::Eaw.property(tail)) &&
@@ -86,6 +87,7 @@ module ReVIEW
86
87
  unless @book.config['join_lines_by_lang']
87
88
  return lines.join
88
89
  end
90
+
89
91
  lazy = true
90
92
  lang = 'ja'
91
93
  0.upto(lines.size - 2) do |n|
@@ -96,17 +98,6 @@ module ReVIEW
96
98
  lines.join
97
99
  end
98
100
 
99
- def defer_math_image(str, path, key)
100
- # for Re:VIEW >3
101
- File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.tex'), 'a+') do |f|
102
- f.puts str
103
- f.puts '\\clearpage'
104
- end
105
- File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.map'), 'a+') do |f|
106
- f.puts key
107
- end
108
- end
109
-
110
101
  private
111
102
 
112
103
  # remove elements at the back of `lines` if element is empty string
@@ -1,148 +1,293 @@
1
- # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto
2
- # 2002-2007 Minero Aoki
1
+ # Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto
2
+ # 1999-2007 Minero Aoki
3
3
  #
4
4
  # This program is free software.
5
5
  # You can distribute or modify this program under the terms of
6
6
  # the GNU LGPL, Lesser General Public License version 2.1.
7
- # For details of LGPL, see the file "COPYING".
7
+ # For details of the GNU LGPL, see the file "COPYING".
8
8
  #
9
9
 
10
- require 'review/htmlutils'
11
- require 'review/tocparser'
10
+ require 'review/book'
11
+ require 'review/version'
12
+ require 'optparse'
13
+ require 'review/plaintextbuilder'
12
14
 
13
15
  module ReVIEW
14
- class TOCPrinter
15
- def self.default_upper_level
16
- 99 # no one use 99 level nest
16
+ class PLAINTEXTTocBuilder < PLAINTEXTBuilder
17
+ def headline(level, label, caption)
18
+ if @chapter.is_a?(ReVIEW::Book::Part)
19
+ print "\x01H0\x01" # XXX: don't modify level value. level value will be handled in sec_counter#prefix()
20
+ else
21
+ print "\x01H#{level}\x01"
22
+ end
23
+ # embed header information for tocparser
24
+ super(level, label, caption)
17
25
  end
18
26
 
19
- def initialize(print_upper, param, out = $stdout)
20
- @print_upper = print_upper
21
- @config = param
22
- @out = out
27
+ def base_block(type, lines, caption = nil)
28
+ puts "\x01STARTLIST\x01"
29
+ super(type, lines, caption)
30
+ puts "\x01ENDLIST\x01"
23
31
  end
24
32
 
25
- def print_book(book)
26
- book.each_part { |part| print_part(part) }
33
+ def blank
34
+ @blank_seen = true
27
35
  end
36
+ end
28
37
 
29
- def print_part(part)
30
- part.each_chapter { |chap| print_chapter(chap) }
38
+ class TOCPrinter
39
+ class Counter
40
+ def initialize(name: nil, level: nil, headline: nil, lines: nil, chars: nil, list_lines: nil, text_lines: nil, part: nil)
41
+ @name = name
42
+ @level = level
43
+ @headline = headline
44
+ @lines = lines
45
+ @chars = chars
46
+ @list_lines = list_lines
47
+ @text_lines = text_lines
48
+ @part = part
49
+ end
50
+
51
+ attr_accessor :name, :level, :headline, :lines, :chars, :list_lines, :text_lines, :part
31
52
  end
32
53
 
33
- def print_chapter(chap)
34
- chap_node = TOCParser.chapter_node(chap)
35
- print_node(1, chap_node)
36
- print_children(chap_node)
54
+ def self.execute(*args)
55
+ new.execute(*args)
37
56
  end
38
57
 
39
- def print?(level)
40
- level <= @print_upper
58
+ def initialize
59
+ @logger = ReVIEW.logger
60
+ @yamlfile = 'config.yml'
61
+ @upper = 4
62
+ @indent = true
63
+ @buildonly = nil
64
+ @detail = nil
65
+ @calc_char_width = nil
41
66
  end
42
- end
43
67
 
44
- class TextTOCPrinter < TOCPrinter
45
- private
68
+ attr_accessor :calc_char_width
46
69
 
47
- def print_children(node)
48
- return unless print?(node.level + 1)
49
- node.each_section_with_index do |section, idx|
50
- unless section.blank?
51
- print_node(idx + 1, section)
52
- print_children(section)
70
+ def execute(*args)
71
+ parse_options(args)
72
+ @config = ReVIEW::Configure.create(yamlfile: @yamlfile)
73
+ @book = ReVIEW::Book::Base.new('.', config: @config)
74
+ unless File.readable?(@yamlfile)
75
+ @logger.error("No such fiile or can't open #{@yamlfile}.")
76
+ exit 1
77
+ end
78
+ I18n.setup(@config['language'])
79
+
80
+ if @detail
81
+ begin
82
+ require 'unicode/eaw'
83
+ @calc_char_width = true
84
+ rescue LoadError
85
+ @logger.warn('not found unicode/eaw library. page volume may be unreliable.')
86
+ @calc_char_width = nil
53
87
  end
54
88
  end
89
+
90
+ print_result(build_result_array)
55
91
  end
56
92
 
57
- def print_node(number, node)
58
- if node.chapter?
59
- vol = node.volume
60
- @out.printf("%3s %3dKB %6dC %5dL %s (%s)\n",
61
- chapnumstr(node.number),
62
- vol.kbytes, vol.chars, vol.lines,
63
- node.label, node.chapter_id)
64
- else ## for section node
65
- @out.printf("%17s %5dL %s\n",
66
- '', node.estimated_lines,
67
- " #{' ' * (node.level - 1)}#{number} #{node.label}")
93
+ def build_result_array
94
+ result_array = []
95
+ begin
96
+ @book.parts.each do |part|
97
+ if part.name.present? && (@buildonly.nil? || @buildonly.include?(part.name))
98
+ result_array.push(Counter.new(part: 'start'))
99
+ if part.file?
100
+ content = build_chap(part)
101
+ result_array.concat(parse_contents(part.name, @upper, content))
102
+ else
103
+ title = part.format_number + I18n.t('chapter_postfix') + part.title
104
+ result_array.push(
105
+ Counter.new(name: '', lines: 1, chars: title.size, list_lines: 0, text_lines: 1),
106
+ Counter.new(level: 0, headline: title, lines: 1, chars: title.size, list_lines: 0, text_lines: 1)
107
+ )
108
+ end
109
+ end
110
+
111
+ part.chapters.each do |chap|
112
+ if @buildonly.nil? || @buildonly.include?(chap.name)
113
+ content = build_chap(chap)
114
+ result_array.concat(parse_contents(chap.name, @upper, content))
115
+ end
116
+ end
117
+ if part.name.present? && (@buildonly.nil? || @buildonly.include?(part.name))
118
+ result_array.push(Counter.new(part: 'end'))
119
+ end
120
+ end
121
+ rescue ReVIEW::FileNotFound, ReVIEW::CompileError => e
122
+ @logger.error e
123
+ exit 1
68
124
  end
125
+
126
+ result_array
69
127
  end
70
128
 
71
- def chapnumstr(n)
72
- n ? sprintf('%2d.', n) : ' '
129
+ def print_result(result_array)
130
+ result_array.each do |result|
131
+ if result.part
132
+ next
133
+ end
134
+
135
+ if result.name
136
+ # file information
137
+ if @detail
138
+ puts '============================='
139
+ printf("%6dC %5dL %5dP %s\n", result.chars, result.lines, calc_pages(result).ceil, result.name)
140
+ puts '-----------------------------'
141
+ end
142
+ next
143
+ end
144
+
145
+ # section information
146
+ if @detail
147
+ printf('%6dC %5dL %5.1fP ', result.chars, result.lines, calc_pages(result))
148
+ end
149
+ if @indent && result.level
150
+ print ' ' * (result.level == 0 ? 0 : result.level - 1)
151
+ end
152
+ puts result.headline
153
+ end
73
154
  end
74
155
 
75
- def volume_columns(level, volstr)
76
- cols = ['', '', '', nil]
77
- cols[level - 1] = volstr
78
- cols[0, 3] # does not display volume of level-4 section
156
+ def calc_pages(result)
157
+ (result.list_lines.to_f / @book.page_metric.list.n_lines) +
158
+ (result.text_lines.to_f / @book.page_metric.text.n_lines)
79
159
  end
80
- end
81
160
 
82
- class HTMLTOCPrinter < TOCPrinter
83
- include HTMLUtils
161
+ def calc_linesize(line)
162
+ return line.size unless @calc_char_width
84
163
 
85
- def print_book(book)
86
- @out.puts '<ul class="book-toc">'
87
- book.each_part { |part| print_part(part) }
88
- @out.puts '</ul>'
164
+ line.each_char.inject(0) do |result, char|
165
+ # XXX: should include A also?
166
+ if %i[Na H N].include?(Unicode::Eaw.property(char))
167
+ result + 0.5 # halfwidth
168
+ else
169
+ result + 1
170
+ end
171
+ end
89
172
  end
90
173
 
91
- def print_part(part)
92
- if part.number
93
- @out.puts li(part.title)
174
+ def parse_contents(name, upper, content)
175
+ headline_array = []
176
+ counter = Counter.new(lines: 0, chars: 0, list_lines: 0, text_lines: 0)
177
+ listmode = nil
178
+
179
+ content.each_line(chomp: true) do |l|
180
+ if l.start_with?("\x01STARTLIST\x01")
181
+ listmode = true
182
+ next
183
+ elsif l.start_with?("\x01ENDLIST\x01")
184
+ listmode = nil
185
+ next
186
+ elsif l =~ /\A\x01H(\d)\x01/
187
+ # headline
188
+ level = $1.to_i
189
+ l = $'
190
+ if level <= upper
191
+ if counter.chars > 0
192
+ headline_array.push(counter)
193
+ end
194
+ headline = l
195
+ counter = Counter.new(
196
+ level: level,
197
+ headline: headline,
198
+ lines: 1,
199
+ chars: headline.size,
200
+ list_lines: 0,
201
+ text_lines: 1
202
+ )
203
+ next
204
+ end
205
+ end
206
+
207
+ counter.lines += 1
208
+ counter.chars += l.size
209
+
210
+ if listmode
211
+ # code list: calculate line wrapping
212
+ counter.list_lines += calc_line_wrapping(l, mode: :list)
213
+ else
214
+ # normal paragraph: calculate line wrapping
215
+ counter.text_lines += calc_line_wrapping(l, mode: :text)
216
+ end
94
217
  end
95
- super
218
+ headline_array.push(counter)
219
+
220
+ total = calc_total_count(name, headline_array)
221
+ headline_array.unshift(total)
96
222
  end
97
223
 
98
- def print_chapter(chap)
99
- chap_node = TOCParser.chapter_node(chap)
100
- ext = chap.book.config['htmlext'] || 'html'
101
- path = chap.path.sub(/\.re/, '.' + ext)
102
- label = if chap_node.number && chap.on_chaps?
103
- "#{chap.number} #{chap.title}"
104
- else
105
- chap.title
106
- end
107
- @out.puts li(a_name(path, escape_html(label)))
108
- return unless print?(2)
109
- if print?(3)
110
- @out.puts chap_sections_to_s(chap_node)
111
- else
112
- @out.puts chapter_to_s(chap_node)
224
+ def calc_line_wrapping(line, mode:)
225
+ return 1 if line.size == 0
226
+
227
+ case mode
228
+ when :list
229
+ (calc_linesize(line) - 1) / @book.page_metric.list.n_columns + 1
230
+ else # mode == :text
231
+ (calc_linesize(line) - 1) / @book.page_metric.text.n_columns + 1
113
232
  end
114
233
  end
115
234
 
116
- private
235
+ def calc_total_count(name, headline_array)
236
+ total = Counter.new(name: name,
237
+ lines: 0,
238
+ chars: 0,
239
+ list_lines: 0,
240
+ text_lines: 0)
117
241
 
118
- def chap_sections_to_s(chap)
119
- return '' if chap.section_size < 1
120
- res = []
121
- res << '<ol>'
122
- chap.each_section { |sec| res << li(escape_html(sec.label)) }
123
- res << '</ol>'
124
- res.join("\n")
125
- end
242
+ headline_array.each do |h|
243
+ next unless h.lines
126
244
 
127
- def chapter_to_s(chap)
128
- res = []
129
- chap.each_section do |sec|
130
- res << li(escape_html(sec.label))
131
- next unless print?(4)
132
- next unless sec.section_size > 0
133
- res << '<ul>'
134
- sec.each_section { |node| res << li(escape_html(node.label)) }
135
- res << '</ul>'
245
+ total.lines += h.lines
246
+ total.chars += h.chars
247
+ total.list_lines += h.list_lines
248
+ total.text_lines += h.text_lines
136
249
  end
137
- res.join("\n")
250
+
251
+ total
138
252
  end
139
253
 
140
- def li(content)
141
- "<li>#{content}</li>"
254
+ def build_chap(chap)
255
+ compiler = ReVIEW::Compiler.new(ReVIEW::PLAINTEXTTocBuilder.new)
256
+ begin
257
+ compiler.compile(@book.chapter(chap.name))
258
+ rescue ReVIEW::ApplicationError => e
259
+ @logger.error e.message
260
+ ''
261
+ end
142
262
  end
143
263
 
144
- def a_name(name, label)
145
- %Q(<a name="#{name}">#{label}</a>)
264
+ def parse_options(args)
265
+ opts = OptionParser.new
266
+ opts.version = ReVIEW::VERSION
267
+ opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| @yamlfile = yaml }
268
+ opts.on('-y', '--only file1,file2,...', 'list only specified files.') do |v|
269
+ @buildonly = v.split(/\s*,\s*/).map { |m| m.strip.sub(/\.re\Z/, '') }
270
+ end
271
+ opts.on('-l', '--level N', 'list upto N level (default=4)') do |n|
272
+ @upper = n.to_i
273
+ end
274
+ opts.on('-d', '--detail', 'show characters and lines of each section.') do
275
+ @detail = true
276
+ end
277
+ opts.on('--noindent', "don't indent headlines.") do
278
+ @indent = nil
279
+ end
280
+ opts.on('--help', 'print this message and quit.') do
281
+ puts opts.help
282
+ exit 0
283
+ end
284
+ begin
285
+ opts.parse!(args)
286
+ rescue OptionParser::ParseError => e
287
+ @logger.error e.message
288
+ $stderr.puts opts.help
289
+ exit 1
290
+ end
146
291
  end
147
292
  end
148
293
  end
@@ -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-2006 Minero Aoki
3
3
  #
4
4
  # This program is free software.
@@ -78,7 +78,7 @@ module ReVIEW
78
78
 
79
79
  def dd(lines)
80
80
  split_paragraph(lines).each do |paragraph|
81
- puts "\t#{paragraph.gsub(/\n/, '')}"
81
+ puts "\t#{paragraph.delete("\n")}"
82
82
  end
83
83
  end
84
84
 
@@ -95,12 +95,18 @@ module ReVIEW
95
95
  blank
96
96
  puts "◆→開始:#{@titles['list']}←◆"
97
97
  begin
98
- list_header(id, caption, lang)
98
+ if caption_top?('list')
99
+ list_header(id, caption, lang)
100
+ blank
101
+ end
102
+ list_body(id, lines, lang)
103
+ unless caption_top?('list')
104
+ blank
105
+ list_header(id, caption, lang)
106
+ end
99
107
  rescue KeyError
100
- error "no such list: #{id}"
108
+ app_error "no such list: #{id}"
101
109
  end
102
- blank
103
- list_body(id, lines, lang)
104
110
  puts "◆→終了:#{@titles['list']}←◆"
105
111
  blank
106
112
  end
@@ -122,8 +128,13 @@ module ReVIEW
122
128
  def base_block(type, lines, caption = nil)
123
129
  blank
124
130
  puts "◆→開始:#{@titles[type]}←◆"
125
- puts "■#{compile_inline(caption)}" if caption.present?
131
+ if caption_top?('list') && caption.present?
132
+ puts "■#{compile_inline(caption)}"
133
+ end
126
134
  puts lines.join("\n")
135
+ if !caption_top?('list') && caption.present?
136
+ puts "■#{compile_inline(caption)}"
137
+ end
127
138
  puts "◆→終了:#{@titles[type]}←◆"
128
139
  blank
129
140
  end
@@ -140,10 +151,15 @@ module ReVIEW
140
151
  def emlistnum(lines, caption = nil, _lang = nil)
141
152
  blank
142
153
  puts "◆→開始:#{@titles['emlist']}←◆"
143
- puts "■#{compile_inline(caption)}" if caption.present?
154
+ if caption_top?('list') && caption.present?
155
+ puts "■#{compile_inline(caption)}"
156
+ end
144
157
  lines.each_with_index do |line, i|
145
158
  puts((i + 1).to_s.rjust(2) + ": #{line}")
146
159
  end
160
+ if !caption_top?('list') && caption.present?
161
+ puts "■#{compile_inline(caption)}"
162
+ end
147
163
  puts "◆→終了:#{@titles['emlist']}←◆"
148
164
  blank
149
165
  end
@@ -152,12 +168,18 @@ module ReVIEW
152
168
  blank
153
169
  puts "◆→開始:#{@titles['list']}←◆"
154
170
  begin
155
- list_header(id, caption, lang)
171
+ if caption_top?('list') && caption.present?
172
+ list_header(id, caption, lang)
173
+ blank
174
+ end
175
+ listnum_body(lines, lang)
176
+ if !caption_top?('list') && caption.present?
177
+ blank
178
+ list_header(id, caption, lang)
179
+ end
156
180
  rescue KeyError
157
- error "no such list: #{id}"
181
+ app_error "no such list: #{id}"
158
182
  end
159
- blank
160
- listnum_body(lines, lang)
161
183
  puts "◆→終了:#{@titles['list']}←◆"
162
184
  blank
163
185
  end
@@ -173,16 +195,22 @@ module ReVIEW
173
195
  metrics = " #{metrics}" if metrics.present?
174
196
  blank
175
197
  puts "◆→開始:#{@titles['image']}←◆"
176
- image_header(id, caption)
177
- blank
198
+ if caption_top?('image')
199
+ image_header(id, caption)
200
+ blank
201
+ end
178
202
  if @chapter.image_bound?(id)
179
203
  puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
180
204
  else
181
- warn "image not bound: #{id}"
205
+ warn "image not bound: #{id}", location: location
182
206
  lines.each do |line|
183
207
  puts line
184
208
  end
185
209
  end
210
+ unless caption_top?('image')
211
+ blank
212
+ image_header(id, caption)
213
+ end
186
214
  puts "◆→終了:#{@titles['image']}←◆"
187
215
  blank
188
216
  end
@@ -198,22 +226,20 @@ module ReVIEW
198
226
  def texequation(lines, id = nil, caption = '')
199
227
  blank
200
228
  puts "◆→開始:#{@titles['texequation']}←◆"
201
- texequation_header(id, caption)
229
+ texequation_header(id, caption) if caption_top?('equation')
202
230
 
203
- if @book.config['imgmath']
231
+ if @book.config['math_format'] == 'imgmath'
204
232
  fontsize = @book.config['imgmath_options']['fontsize'].to_f
205
233
  lineheight = @book.config['imgmath_options']['lineheight'].to_f
206
234
  math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n"
207
235
  key = Digest::SHA256.hexdigest(math_str)
208
- math_dir = File.join(@book.config['imagedir'], '_review_math_text')
209
- Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
210
- img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
211
- defer_math_image(math_str, img_path, key)
236
+ img_path = @img_math.defer_math_image(math_str, key)
212
237
  puts "◆→math:#{File.basename(img_path)}←◆"
213
238
  else
214
239
  puts lines.join("\n")
215
240
  end
216
241
 
242
+ texequation_header(id, caption) unless caption_top?('equation')
217
243
  puts "◆→終了:#{@titles['texequation']}←◆"
218
244
  blank
219
245
  end
@@ -245,6 +271,7 @@ module ReVIEW
245
271
 
246
272
  def comment(lines, comment = nil)
247
273
  return unless @book.config['draft']
274
+
248
275
  lines ||= []
249
276
  unless comment.blank?
250
277
  lines.unshift(comment)
@@ -260,7 +287,7 @@ module ReVIEW
260
287
  def inline_fn(id)
261
288
  "【注#{@chapter.footnote(id).number}】"
262
289
  rescue KeyError
263
- error "unknown footnote: #{id}"
290
+ app_error "unknown footnote: #{id}"
264
291
  end
265
292
 
266
293
  def compile_ruby(base, ruby)
@@ -338,11 +365,23 @@ module ReVIEW
338
365
  "@#{str}@◆→@〜@部分に下線←◆"
339
366
  end
340
367
 
368
+ def inline_ins(str)
369
+ "◆→開始:挿入表現←◆#{str}◆→終了:挿入表現←◆"
370
+ end
371
+
372
+ def inline_del(str)
373
+ "◆→開始:削除表現←◆#{str}◆→終了:削除表現←◆"
374
+ end
375
+
376
+ def inline_tcy(str)
377
+ "◆→開始:回転←◆#{str}◆→終了:縦回転←◆"
378
+ end
379
+
341
380
  def inline_icon(id)
342
381
  begin
343
382
  "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}←◆"
344
383
  rescue
345
- warn "image not bound: #{id}"
384
+ warn "image not bound: #{id}", location: location
346
385
  "◆→画像 #{id}←◆"
347
386
  end
348
387
  end
@@ -368,13 +407,10 @@ module ReVIEW
368
407
  end
369
408
 
370
409
  def inline_m(str)
371
- if @book.config['imgmath']
410
+ if @book.config['math_format'] == 'imgmath'
372
411
  math_str = '$' + str + '$'
373
412
  key = Digest::SHA256.hexdigest(str)
374
- math_dir = File.join(@book.config['imagedir'], '_review_math_text')
375
- Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
376
- img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
377
- defer_math_image(math_str, img_path, key)
413
+ img_path = @img_math.defer_math_image(math_str, key)
378
414
  %Q(◆→TeX式ここから←◆◆→math:#{File.basename(img_path)}←◆◆→TeX式ここまで←◆)
379
415
  else
380
416
  %Q(◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆)
@@ -389,7 +425,7 @@ module ReVIEW
389
425
  def inline_bib(id)
390
426
  %Q([#{@chapter.bibpaper(id).number}])
391
427
  rescue KeyError
392
- error "unknown bib: #{id}"
428
+ app_error "unknown bib: #{id}"
393
429
  end
394
430
 
395
431
  def noindent
@@ -415,17 +451,48 @@ module ReVIEW
415
451
  blank
416
452
  end
417
453
 
454
+ def common_block_begin(type, _level, _label, caption = nil)
455
+ blank
456
+ puts "◆→開始:#{@titles[type]}←◆"
457
+ puts '■' + compile_inline(caption) if caption.present?
458
+ end
459
+
460
+ def common_block_end(type, _level)
461
+ puts "◆→終了:#{@titles[type]}←◆"
462
+ blank
463
+ end
464
+
465
+ CAPTION_TITLES.each do |name|
466
+ class_eval %Q(
467
+ def #{name}_begin(caption = nil)
468
+ check_nested_minicolumn
469
+ @doc_status[:minicolumn] = '#{name}'
470
+ common_block_begin('#{name}', nil, nil, caption)
471
+ end
472
+
473
+ def #{name}_end
474
+ common_block_end('#{name}', nil)
475
+ @doc_status[:minicolumn] = nil
476
+ end
477
+ ), __FILE__, __LINE__ - 11
478
+ end
479
+
418
480
  def indepimage(_lines, id, caption = nil, metric = nil)
419
481
  metrics = parse_metric('top', metric)
420
482
  metrics = " #{metrics}" if metrics.present?
421
483
  blank
484
+ if caption_top?('image') && caption.present?
485
+ puts "図 #{compile_inline(caption)}"
486
+ end
422
487
  begin
423
488
  puts "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}#{metrics}←◆"
424
489
  rescue
425
- warn "image not bound: #{id}"
490
+ warn "image not bound: #{id}", location: location
426
491
  puts "◆→画像 #{id}←◆"
427
492
  end
428
- puts "図 #{compile_inline(caption)}" if caption.present?
493
+ if !caption_top?('image') && caption.present?
494
+ puts "図 #{compile_inline(caption)}"
495
+ end
429
496
  blank
430
497
  end
431
498