review 5.6.0 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +31 -0
  3. data/.github/workflows/ruby-tex.yml +5 -1
  4. data/.github/workflows/ruby-win.yml +1 -1
  5. data/.github/workflows/ruby.yml +2 -2
  6. data/.rubocop.yml +13 -2
  7. data/NEWS.ja.md +39 -0
  8. data/NEWS.md +38 -0
  9. data/README.md +1 -1
  10. data/doc/config.yml.sample +11 -0
  11. data/doc/format.ja.md +50 -2
  12. data/doc/format.md +50 -2
  13. data/lib/review/book/base.rb +2 -2
  14. data/lib/review/book/image_finder.rb +29 -14
  15. data/lib/review/book/index.rb +1 -8
  16. data/lib/review/builder.rb +18 -9
  17. data/lib/review/configure.rb +7 -0
  18. data/lib/review/epubmaker/epubcommon.rb +13 -7
  19. data/lib/review/epubmaker/epubv2.rb +0 -5
  20. data/lib/review/epubmaker/epubv3.rb +9 -1
  21. data/lib/review/epubmaker/producer.rb +2 -3
  22. data/lib/review/epubmaker.rb +14 -5
  23. data/lib/review/htmlbuilder.rb +3 -3
  24. data/lib/review/idgxmlbuilder.rb +4 -3
  25. data/lib/review/idgxmlmaker.rb +13 -2
  26. data/lib/review/img_graph.rb +79 -0
  27. data/lib/review/img_math.rb +9 -2
  28. data/lib/review/init.rb +3 -3
  29. data/lib/review/latexbuilder.rb +1 -1
  30. data/lib/review/lineinput.rb +2 -2
  31. data/lib/review/makerhelper.rb +2 -2
  32. data/lib/review/pdfmaker.rb +14 -6
  33. data/lib/review/plaintextbuilder.rb +13 -1
  34. data/lib/review/textmaker.rb +14 -3
  35. data/lib/review/update.rb +3 -7
  36. data/lib/review/version.rb +1 -1
  37. data/lib/review/yamlloader.rb +0 -3
  38. data/review.gemspec +3 -3
  39. data/samples/syntax-book/Gemfile +1 -1
  40. data/samples/syntax-book/ch02.re +6 -0
  41. data/templates/latex/review-jlreq/review-jlreq.cls +14 -0
  42. data/templates/latex/review-jsbook/review-jsbook.cls +14 -0
  43. data/templates/opf/epubv2.opf.erb +2 -0
  44. data/templates/opf/epubv3.opf.erb +2 -0
  45. data/templates/opf/opf_manifest_epubv2.opf.erb +2 -0
  46. data/templates/opf/opf_manifest_epubv3.opf.erb +2 -0
  47. data/templates/opf/opf_tocx_epubv3.opf.erb +2 -0
  48. metadata +22 -136
  49. data/test/assets/black.eps +0 -280
  50. data/test/assets/fit.png +0 -0
  51. data/test/assets/header_listener.html +0 -35
  52. data/test/assets/img_math/img1.png +0 -0
  53. data/test/assets/img_math/img2.png +0 -0
  54. data/test/assets/img_math/img3.png +0 -0
  55. data/test/assets/large.gif +0 -0
  56. data/test/assets/large.jpg +0 -0
  57. data/test/assets/large.png +0 -0
  58. data/test/assets/large.svg +0 -65
  59. data/test/assets/syntax_book_index_detail.txt +0 -60
  60. data/test/assets/test.xml.erb +0 -3
  61. data/test/assets/test_template.tex +0 -189
  62. data/test/assets/test_template_backmatter.tex +0 -200
  63. data/test/book_test_helper.rb +0 -44
  64. data/test/run_test.rb +0 -12
  65. data/test/test_book.rb +0 -588
  66. data/test/test_book_chapter.rb +0 -329
  67. data/test/test_book_part.rb +0 -53
  68. data/test/test_builder.rb +0 -128
  69. data/test/test_catalog.rb +0 -174
  70. data/test/test_catalog_converter_cmd.rb +0 -73
  71. data/test/test_compiler.rb +0 -52
  72. data/test/test_configure.rb +0 -91
  73. data/test/test_converter.rb +0 -21
  74. data/test/test_epub3maker.rb +0 -733
  75. data/test/test_epubmaker.rb +0 -931
  76. data/test/test_epubmaker_cmd.rb +0 -56
  77. data/test/test_extentions_hash.rb +0 -66
  78. data/test/test_helper.rb +0 -62
  79. data/test/test_htmlbuilder.rb +0 -3315
  80. data/test/test_htmltoc.rb +0 -29
  81. data/test/test_htmlutils.rb +0 -43
  82. data/test/test_i18n.rb +0 -300
  83. data/test/test_idgxmlbuilder.rb +0 -1529
  84. data/test/test_idgxmlmaker_cmd.rb +0 -50
  85. data/test/test_image_finder.rb +0 -81
  86. data/test/test_img_math.rb +0 -120
  87. data/test/test_index.rb +0 -287
  88. data/test/test_indexbuilder.rb +0 -52
  89. data/test/test_latexbuilder.rb +0 -2972
  90. data/test/test_latexbuilder_v2.rb +0 -1654
  91. data/test/test_lineinput.rb +0 -104
  92. data/test/test_location.rb +0 -30
  93. data/test/test_logger.rb +0 -33
  94. data/test/test_makerhelper.rb +0 -44
  95. data/test/test_markdownbuilder.rb +0 -371
  96. data/test/test_md2inaobuilder.rb +0 -90
  97. data/test/test_pdfmaker.rb +0 -354
  98. data/test/test_pdfmaker_cmd.rb +0 -130
  99. data/test/test_plaintextbuilder.rb +0 -1214
  100. data/test/test_preprocessor.rb +0 -196
  101. data/test/test_review_ext.rb +0 -30
  102. data/test/test_reviewheaderlistener.rb +0 -49
  103. data/test/test_rstbuilder.rb +0 -619
  104. data/test/test_sec_counter.rb +0 -156
  105. data/test/test_template.rb +0 -33
  106. data/test/test_textmaker_cmd.rb +0 -58
  107. data/test/test_textutils.rb +0 -187
  108. data/test/test_tocprinter.rb +0 -46
  109. data/test/test_topbuilder.rb +0 -1301
  110. data/test/test_update.rb +0 -473
  111. data/test/test_webtocprinter.rb +0 -195
  112. data/test/test_yamlloader.rb +0 -186
  113. data/test/test_zip_exporter.rb +0 -106
@@ -1,6 +1,6 @@
1
1
  # = epubv3.rb -- EPUB version 3 producer.
2
2
  #
3
- # Copyright (c) 2010-2022 Kenshi Muto
3
+ # Copyright (c) 2010-2023 Kenshi Muto
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -213,6 +213,14 @@ module ReVIEW
213
213
  ReVIEW::Template.generate(path: template_name, binding: binding)
214
214
  end
215
215
 
216
+ def coveritem
217
+ if config['cover']
218
+ [Content.new(file: config['cover'], title: ReVIEW::I18n.t('covertitle'), level: 1, chaptype: 'cover')]
219
+ else
220
+ []
221
+ end
222
+ end
223
+
216
224
  # Produce EPUB file +epubfile+.
217
225
  # +work_dir+ points the directory has contents.
218
226
  # +tmpdir+ defines temporary directory.
@@ -1,6 +1,6 @@
1
1
  # = producer.rb -- EPUB producer.
2
2
  #
3
- # Copyright (c) 2010-2021 Kenshi Muto
3
+ # Copyright (c) 2010-2023 Kenshi Muto
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -119,8 +119,7 @@ module ReVIEW
119
119
  epubfile = "#{current}/#{epubfile}"
120
120
  end
121
121
 
122
- # FIXME: error check
123
- File.unlink(epubfile) if File.exist?(epubfile)
122
+ FileUtils.rm_f(epubfile)
124
123
 
125
124
  begin
126
125
  @epub.produce(epubfile, work_dir, new_tmpdir, base_dir: base_dir)
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
1
+ # Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -17,6 +17,7 @@ require 'review/version'
17
17
  require 'review/htmltoc'
18
18
  require 'review/htmlbuilder'
19
19
  require 'review/img_math'
20
+ require 'review/img_graph'
20
21
 
21
22
  require 'rexml/document'
22
23
  require 'rexml/streamlistener'
@@ -41,6 +42,7 @@ module ReVIEW
41
42
  @buildlogtxt = 'build-log.txt'
42
43
  @logger = ReVIEW.logger
43
44
  @img_math = nil
45
+ @img_graph = nil
44
46
  @basedir = nil
45
47
  end
46
48
 
@@ -106,9 +108,7 @@ module ReVIEW
106
108
  def build_path
107
109
  if @config['debug']
108
110
  path = File.expand_path("#{@config['bookname']}-epub", Dir.pwd)
109
- if File.exist?(path)
110
- FileUtils.rm_rf(path, secure: true)
111
- end
111
+ FileUtils.rm_rf(path, secure: true)
112
112
  Dir.mkdir(path)
113
113
  path
114
114
  else
@@ -284,11 +284,12 @@ module ReVIEW
284
284
  @manifeststr = ''
285
285
  @ncxstr = ''
286
286
  @tocdesc = []
287
+ @img_graph = ReVIEW::ImgGraph.new(@config, 'html', path_name: '_review_graph')
287
288
 
288
289
  basedir = File.dirname(yamlfile)
289
290
  base_path = Pathname.new(basedir)
290
291
  book = ReVIEW::Book::Base.new(basedir, config: @config)
291
- @converter = ReVIEW::Converter.new(book, ReVIEW::HTMLBuilder.new(img_math: @img_math))
292
+ @converter = ReVIEW::Converter.new(book, ReVIEW::HTMLBuilder.new(img_math: @img_math, img_graph: @img_graph))
292
293
  @compile_errors = nil
293
294
 
294
295
  book.parts.each do |part|
@@ -312,6 +313,13 @@ module ReVIEW
312
313
  end
313
314
  end
314
315
  check_compile_status
316
+
317
+ begin
318
+ @img_graph.make_mermaid_images
319
+ rescue ApplicationError => e
320
+ error! e.message
321
+ end
322
+ @img_graph.cleanup_graphimg
315
323
  end
316
324
 
317
325
  def build_part(part, basetmpdir, htmlfile)
@@ -319,6 +327,7 @@ module ReVIEW
319
327
  File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
320
328
  @part_number = part.number
321
329
  @part_title = part.name.strip
330
+ @title = @part_title
322
331
  @body = ReVIEW::Template.generate(path: template_name(localfile: '_part_body.html.erb', systemfile: 'html/_part_body.html.erb'), binding: binding)
323
332
  @language = @producer.config['language']
324
333
  @stylesheets = @producer.config['stylesheet']
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2022 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
1
+ # Copyright (c) 2008-2023 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
2
2
  # KADO Masanori
3
3
  # 2002-2007 Minero Aoki
4
4
  #
@@ -656,7 +656,7 @@ module ReVIEW
656
656
  p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
657
657
  print p.parse(lines.join("\n") + "\n", true)
658
658
  elsif @book.config['math_format'] == 'mathjax'
659
- puts "$$#{lines.join("\n")}$$"
659
+ puts "$$#{lines.join("\n").gsub('<', '\lt{}').gsub('>', '\gt{}').gsub('&', '&amp;')}$$"
660
660
  elsif @book.config['math_format'] == 'imgmath'
661
661
  fontsize = @book.config['imgmath_options']['fontsize'].to_f
662
662
  lineheight = @book.config['imgmath_options']['lineheight'].to_f
@@ -1051,7 +1051,7 @@ EOS
1051
1051
  parser = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
1052
1052
  %Q(<span class="equation">#{parser.parse(str, nil)}</span>)
1053
1053
  elsif @book.config['math_format'] == 'mathjax'
1054
- %Q(<span class="equation">\\( #{str} \\)</span>)
1054
+ %Q(<span class="equation">\\( #{str.gsub('<', '\lt{}').gsub('>', '\gt{}').gsub('&', '&amp;')} \\)</span>)
1055
1055
  elsif @book.config['math_format'] == 'imgmath'
1056
1056
  math_str = '$' + str + '$'
1057
1057
  key = Digest::SHA256.hexdigest(str)
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2022 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2023 Minero Aoki, Kenshi Muto
2
2
  # 2002-2007 Minero Aoki
3
3
  #
4
4
  # This program is free software.
@@ -136,7 +136,8 @@ module ReVIEW
136
136
  when 5
137
137
  @subsubsubsection += 1
138
138
  print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
139
- when 6 # rubocop:disable Lint/EmptyWhen
139
+ when 6
140
+ # ignore
140
141
  else
141
142
  raise "caption level too deep or unsupported: #{level}"
142
143
  end
@@ -526,7 +527,7 @@ module ReVIEW
526
527
  sepidx = nil
527
528
  rows = []
528
529
  lines.each_with_index do |line, idx|
529
- if /\A[=\-]{12}/.match?(line)
530
+ if /\A[=-]{12}/.match?(line)
530
531
  sepidx ||= idx
531
532
  next
532
533
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2019-2022 Kenshi Muto
1
+ # Copyright (c) 2019-2023 Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -17,6 +17,7 @@ require 'review/idgxmlbuilder'
17
17
  require 'review/version'
18
18
  require 'review/makerhelper'
19
19
  require 'review/img_math'
20
+ require 'review/img_graph'
20
21
  require 'review/loggable'
21
22
 
22
23
  module ReVIEW
@@ -30,6 +31,7 @@ module ReVIEW
30
31
  @basedir = nil
31
32
  @logger = ReVIEW.logger
32
33
  @img_math = nil
34
+ @img_graph = nil
33
35
  @plaintext = nil
34
36
  @compile_errors = nil
35
37
  end
@@ -70,6 +72,7 @@ module ReVIEW
70
72
 
71
73
  def remove_old_files(path)
72
74
  @img_math.cleanup_mathimg
75
+ @img_graph.cleanup_graphimg
73
76
  FileUtils.rm_rf(path)
74
77
  end
75
78
 
@@ -86,6 +89,7 @@ module ReVIEW
86
89
  end
87
90
 
88
91
  @img_math = ReVIEW::ImgMath.new(@config)
92
+ @img_graph = ReVIEW::ImgGraph.new(@config, 'idgxml', path_name: '_review_graph')
89
93
 
90
94
  I18n.setup(@config['language'])
91
95
  begin
@@ -100,6 +104,13 @@ module ReVIEW
100
104
  if @config['math_format'] == 'imgmath'
101
105
  @img_math.make_math_images
102
106
  end
107
+
108
+ begin
109
+ @img_graph.make_mermaid_images
110
+ rescue ApplicationError => e
111
+ error! e.message
112
+ end
113
+ @img_graph.cleanup_graphimg
103
114
  end
104
115
 
105
116
  def generate_idgxml_files(yamlfile)
@@ -140,7 +151,7 @@ module ReVIEW
140
151
 
141
152
  def build_body(basetmpdir, _yamlfile)
142
153
  base_path = Pathname.new(@basedir)
143
- @converter = ReVIEW::Converter.new(@book, ReVIEW::IDGXMLBuilder.new(img_math: @img_math))
154
+ @converter = ReVIEW::Converter.new(@book, ReVIEW::IDGXMLBuilder.new(img_math: @img_math, img_graph: @img_graph))
144
155
  @book.parts.each do |part|
145
156
  if part.name.present?
146
157
  if part.file?
@@ -0,0 +1,79 @@
1
+ #
2
+ # Copyright (c) 2023 Kenshi Muto
3
+ #
4
+ # This program is free software.
5
+ # You can distribute/modify this program under the terms of
6
+ # the GNU LGPL, Lesser General Public License version 2.1.
7
+ #
8
+ require 'review/loggable'
9
+
10
+ module ReVIEW
11
+ class ImgGraph
12
+ include Loggable
13
+
14
+ def initialize(config, target_name, path_name: '_review_graph')
15
+ @config = config
16
+ @target_name = target_name
17
+ @logger = ReVIEW.logger
18
+ @graph_dir = File.join(@config['imagedir'], target_name, path_name)
19
+ @graph_maps = {}
20
+ end
21
+
22
+ attr_reader :graph_maps
23
+
24
+ def cleanup_graphimg
25
+ FileUtils.rm_rf(@graph_dir)
26
+ end
27
+
28
+ def graph_ext
29
+ if %w[html markdown rst].include?(@target_name)
30
+ 'svg'
31
+ else
32
+ 'pdf'
33
+ end
34
+ end
35
+
36
+ def defer_mermaid_image(str, key)
37
+ @graph_maps[key] = { type: 'mermaid', content: str }
38
+ File.join('.', @config['imagedir'], @target_name, "#{key}.#{graph_ext}")
39
+ end
40
+
41
+ def mermaid_html(content)
42
+ <<-EOB
43
+ <!DOCTYPE html>
44
+ <html>
45
+ <head><meta charset="UTF-8"><script type="module">import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs'; mermaid.initialize({ startOnLoad: true });</script></head>
46
+ <body><div><pre class="mermaid">#{content}</pre></div></body></html>
47
+ EOB
48
+ end
49
+
50
+ def make_mermaid_images
51
+ mermaid_graph_maps = @graph_maps.select { |_k, v| v[:type] == 'mermaid' }
52
+ return if mermaid_graph_maps.empty?
53
+
54
+ FileUtils.mkdir_p(File.join(@graph_dir, 'mermaid'))
55
+ mermaid_graph_maps.each_pair do |key, val|
56
+ File.write(File.join(@graph_dir, 'mermaid', "#{key}.html"), mermaid_html(val[:content]))
57
+ end
58
+ @logger.info 'calling Playwright'
59
+
60
+ begin
61
+ require 'playwrightrunner'
62
+ PlaywrightRunner.mermaids_to_images(
63
+ { playwright_path: @config['playwright_options']['playwright_path'],
64
+ selfcrop: @config['playwright_options']['selfcrop'],
65
+ pdfcrop_path: @config['playwright_options']['pdfcrop_path'],
66
+ pdftocairo_path: @config['playwright_options']['pdftocairo_path'] },
67
+ src: File.join(@graph_dir, 'mermaid'),
68
+ dest: File.join(@config['imagedir'], @target_name),
69
+ type: graph_ext
70
+ )
71
+ rescue SystemCallError => e
72
+ raise ApplicationError, "converting mermaid failed: #{e}"
73
+ rescue LoadError
74
+ raise ApplicationError, 'could not handle Mermaid of //graph in this builder.'
75
+ end
76
+ FileUtils.rm_rf(File.join(@graph_dir, 'mermaid'))
77
+ end
78
+ end
79
+ end
@@ -1,3 +1,10 @@
1
+ #
2
+ # Copyright (c) 2021-2023 Masayoshi Takahashi, Kenshi Muto
3
+ #
4
+ # This program is free software.
5
+ # You can distribute/modify this program under the terms of
6
+ # the GNU LGPL, Lesser General Public License version 2.1.
7
+ #
1
8
  require 'fileutils'
2
9
  require 'shellwords'
3
10
  require 'review/loggable'
@@ -29,7 +36,7 @@ module ReVIEW
29
36
  # Re:VIEW 2 compatibility
30
37
 
31
38
  img_path = File.join(@math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")
32
- Dir.mkdir(@math_dir) unless Dir.exist?(@math_dir)
39
+ FileUtils.mkdir_p(@math_dir)
33
40
  fontsize2 = (fontsize * 1.2).round.to_i
34
41
  texsrc = <<-EOB
35
42
  \\documentclass[12pt]{article}
@@ -63,7 +70,7 @@ module ReVIEW
63
70
  def make_math_images
64
71
  return if @math_maps.empty?
65
72
 
66
- Dir.mkdir(@math_dir) unless Dir.exist?(@math_dir)
73
+ FileUtils.mkdir_p(@math_dir)
67
74
  fontsize = @config['imgmath_options']['fontsize'].to_f
68
75
  lineheight = @config['imgmath_options']['lineheight'].to_f
69
76
 
data/lib/review/init.rb CHANGED
@@ -61,7 +61,7 @@ module ReVIEW
61
61
 
62
62
  def parse_options(args)
63
63
  @port = 18000
64
- @bind = '0'
64
+ @bind = '0.0.0.0'
65
65
 
66
66
  opts = OptionParser.new
67
67
  opts.version = ReVIEW::VERSION
@@ -97,7 +97,7 @@ module ReVIEW
97
97
  opts.on('', '--port port', 'port to use for Web based layout configuration. (default: 18000)') do |port|
98
98
  @port = port
99
99
  end
100
- opts.on('', '--bind bindaddress', 'address to use for Web based layout configuration. (default: 0 (any))') do |bind|
100
+ opts.on('', '--bind bindaddress', 'address to use for Web based layout configuration. (default: 0.0.0.0 (any))') do |bind|
101
101
  @bind = bind
102
102
  end
103
103
 
@@ -321,7 +321,7 @@ EOS
321
321
  AccessLog: [[File.open(IO::NULL, 'w'), '']]
322
322
  }
323
323
 
324
- bind_address = (@bind == '0') ? '<thishost>' : @bind
324
+ bind_address = (@bind == '0.0.0.0') ? '<thishost>' : @bind
325
325
  puts "Please access http://#{bind_address}:#{web_config[:Port]} from Web browser."
326
326
  begin
327
327
  @web_server = WEBrick::HTTPServer.new(web_config)
@@ -1038,7 +1038,7 @@ module ReVIEW
1038
1038
  end
1039
1039
 
1040
1040
  def blankline
1041
- puts '\vspace*{\baselineskip}'
1041
+ puts '\par\vspace{\baselineskip}\par'
1042
1042
  end
1043
1043
 
1044
1044
  def noindent
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2002-2020 Minero Aoki, Masayoshi Takahashi, Kenshi Muto
2
+ # Copyright (c) 2002-2023 Minero Aoki, Masayoshi Takahashi, Kenshi Muto
3
3
  #
4
4
  # This program is free software.
5
5
  # You can distribute/modify this program under the terms of
@@ -21,7 +21,7 @@ module ReVIEW
21
21
  end
22
22
 
23
23
  def inspect
24
- "\#<#{self.class} file=#{@input.inspect} line=#{lineno}>"
24
+ "#<#{self.class} file=#{@input.inspect} line=#{lineno}>"
25
25
  end
26
26
 
27
27
  def eof?
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012-2020 Yuto HAYAMIZU, Kenshi Muto
1
+ # Copyright (c) 2012-2023 Yuto HAYAMIZU, Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -48,7 +48,7 @@ module ReVIEW
48
48
  if FileTest.directory?("#{from_dir}/#{fname}")
49
49
  image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
50
50
  else
51
- FileUtils.mkdir_p(to_dir) unless File.exist?(to_dir)
51
+ FileUtils.mkdir_p(to_dir)
52
52
 
53
53
  is_converted = false
54
54
  (options[:convert] || {}).each do |orig_type, conv_type|
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
1
+ # Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -25,6 +25,7 @@ require 'review/template'
25
25
  require 'review/latexbox'
26
26
  require 'review/call_hook'
27
27
  require 'review/loggable'
28
+ require 'review/img_graph'
28
29
 
29
30
  module ReVIEW
30
31
  class PDFMaker
@@ -69,9 +70,7 @@ module ReVIEW
69
70
  def build_path
70
71
  if @config['debug']
71
72
  path = "#{@config['bookname']}-pdf"
72
- if File.exist?(path)
73
- FileUtils.rm_rf(path, secure: true)
74
- end
73
+ FileUtils.rm_rf(path, secure: true)
75
74
  Dir.mkdir(path)
76
75
  path
77
76
  else
@@ -262,17 +261,26 @@ module ReVIEW
262
261
  def generate_pdf
263
262
  remove_old_file
264
263
  @path = build_path
264
+ @img_graph = ReVIEW::ImgGraph.new(@config, 'latex', path_name: '_review_graph')
265
+
265
266
  begin
266
267
  @compile_errors = nil
267
268
 
268
269
  book = ReVIEW::Book::Base.new(@basedir, config: @config)
269
- @converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new)
270
+ @converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new(img_graph: @img_graph))
270
271
  erb_config
271
272
 
272
273
  @input_files = make_input_files(book)
273
274
 
274
275
  check_compile_status(@config['ignore-errors'])
275
276
 
277
+ begin
278
+ @img_graph.make_mermaid_images
279
+ rescue ApplicationError => e
280
+ error! e.message
281
+ end
282
+ @img_graph.cleanup_graphimg
283
+
276
284
  # for backward compatibility
277
285
  @config['usepackage'] = ''
278
286
  @config['usepackage'] = "\\usepackage{#{@config['texstyle']}}" if @config['texstyle']
@@ -517,7 +525,7 @@ module ReVIEW
517
525
  dir.sort.each do |fname|
518
526
  next unless File.extname(fname).downcase == '.' + extname
519
527
 
520
- FileUtils.mkdir_p(copybase) unless Dir.exist?(copybase)
528
+ FileUtils.mkdir_p(copybase)
521
529
  if extname == 'erb'
522
530
  File.open(File.join(copybase, fname.sub(/\.erb\Z/, '')), 'w') do |f|
523
531
  f.print erb_content(File.join(dirname, fname))
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2018-2022 Kenshi Muto
1
+ # Copyright (c) 2018-2023 Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -723,6 +723,18 @@ module ReVIEW
723
723
  str
724
724
  end
725
725
 
726
+ def graph_mermaid(_id, file_path, _line, _tf_path)
727
+ if self.instance_of?(ReVIEW::PLAINTEXTBuilder)
728
+ file_path
729
+ else
730
+ super
731
+ end
732
+ end
733
+
734
+ def image_ext
735
+ 'png'
736
+ end
737
+
726
738
  alias_method :th, :nofunc_text
727
739
  alias_method :td, :nofunc_text
728
740
  alias_method :inline_sup, :nofunc_text
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2018-2022 Kenshi Muto
1
+ # Copyright (c) 2018-2023 Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -17,6 +17,7 @@ require 'review/topbuilder'
17
17
  require 'review/version'
18
18
  require 'review/makerhelper'
19
19
  require 'review/img_math'
20
+ require 'review/img_graph'
20
21
  require 'review/loggable'
21
22
 
22
23
  module ReVIEW
@@ -31,6 +32,7 @@ module ReVIEW
31
32
  @logger = ReVIEW.logger
32
33
  @plaintext = nil
33
34
  @img_math = nil
35
+ @img_graph = nil
34
36
  @compile_errors = nil
35
37
  end
36
38
 
@@ -67,6 +69,7 @@ module ReVIEW
67
69
 
68
70
  def remove_old_files(path)
69
71
  @img_math.cleanup_mathimg
72
+ @img_graph.cleanup_graphimg
70
73
  FileUtils.rm_rf(path)
71
74
  end
72
75
 
@@ -83,6 +86,7 @@ module ReVIEW
83
86
  end
84
87
 
85
88
  @img_math = ReVIEW::ImgMath.new(@config, path_name: '_review_math_text')
89
+ @img_graph = ReVIEW::ImgGraph.new(@config, 'top', path_name: '_review_graph')
86
90
 
87
91
  I18n.setup(@config['language'])
88
92
  begin
@@ -97,6 +101,13 @@ module ReVIEW
97
101
  if @config['math_format'] == 'imgmath'
98
102
  @img_math.make_math_images
99
103
  end
104
+
105
+ begin
106
+ @img_graph.make_mermaid_images
107
+ rescue ApplicationError => e
108
+ error! e.message
109
+ end
110
+ @img_graph.cleanup_graphimg
100
111
  end
101
112
 
102
113
  def generate_text_files(yamlfile)
@@ -117,9 +128,9 @@ module ReVIEW
117
128
  def build_body(basetmpdir, _yamlfile)
118
129
  base_path = Pathname.new(@basedir)
119
130
  builder = if @plaintext
120
- ReVIEW::PLAINTEXTBuilder.new(img_math: @img_math)
131
+ ReVIEW::PLAINTEXTBuilder.new(img_math: @img_math, img_graph: @img_graph)
121
132
  else
122
- ReVIEW::TOPBuilder.new(img_math: @img_math)
133
+ ReVIEW::TOPBuilder.new(img_math: @img_math, img_graph: @img_graph)
123
134
  end
124
135
  @converter = ReVIEW::Converter.new(@book, builder)
125
136
  @book.parts.each do |part|
data/lib/review/update.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2018-2022 Kenshi Muto
2
+ # Copyright (c) 2018-2023 Kenshi Muto
3
3
  #
4
4
  # This program is free software.
5
5
  # You can distribute or modify this program under the terms of
@@ -258,9 +258,7 @@ module ReVIEW
258
258
 
259
259
  def update_rakefile(dir)
260
260
  taskdir = File.join(dir, 'lib/tasks')
261
- unless File.exist?(taskdir)
262
- FileUtils.mkdir_p(taskdir)
263
- end
261
+ FileUtils.mkdir_p(taskdir)
264
262
 
265
263
  master_rakefile = File.join(@review_dir, 'samples/sample-book/src/Rakefile')
266
264
 
@@ -474,9 +472,7 @@ module ReVIEW
474
472
 
475
473
  def update_tex_stys(template, dir)
476
474
  texmacrodir = File.join(dir, 'sty')
477
- unless File.exist?(texmacrodir)
478
- FileUtils.mkdir(texmacrodir)
479
- end
475
+ FileUtils.mkdir_p(texmacrodir)
480
476
 
481
477
  tdir = File.join(@review_dir, 'templates/latex', template)
482
478
  Dir.glob(File.join(tdir, '*.*')).each do |master_styfile|
@@ -1,3 +1,3 @@
1
1
  module ReVIEW
2
- VERSION = '5.6.0'.freeze
2
+ VERSION = '5.8.0'.freeze
3
3
  end
@@ -36,9 +36,6 @@ module ReVIEW
36
36
  end
37
37
  end
38
38
 
39
- def initialize
40
- end
41
-
42
39
  # load YAML files
43
40
  #
44
41
  # `inherit: [3.yml, 6.yml]` in 7.yml; `inherit: [1.yml, 2.yml]` in 3.yml; `inherit: [4.yml, 5.yml]` in 6.yml
data/review.gemspec CHANGED
@@ -14,8 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.required_rubygems_version = Gem::Requirement.new('>= 0') if gem.respond_to?(:required_rubygems_version=)
15
15
  gem.metadata = { 'rubygems_mfa_required' => 'true' }
16
16
 
17
- gem.files = `git ls-files`.split("\n")
18
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.files = `git ls-files`.split("\n").reject { |f| f.match(/^test/) }
19
18
  gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
19
  gem.extra_rdoc_files = []
21
20
  gem.require_paths = ['lib']
@@ -26,9 +25,10 @@ Gem::Specification.new do |gem|
26
25
  gem.add_dependency('rubyzip')
27
26
  gem.add_dependency('tty-logger')
28
27
  gem.add_development_dependency('mini_magick')
28
+ gem.add_development_dependency('playwright-runner')
29
29
  gem.add_development_dependency('pygments.rb')
30
30
  gem.add_development_dependency('rake')
31
- gem.add_development_dependency('rubocop', '~> 1.12.0')
31
+ gem.add_development_dependency('rubocop', '~> 1.45.1')
32
32
  gem.add_development_dependency('rubocop-performance')
33
33
  gem.add_development_dependency('rubocop-rake')
34
34
  gem.add_development_dependency('simplecov')
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
- gem 'review', '4.2.0'
4
+ gem 'review', '~> 5.3.0'
@@ -365,6 +365,12 @@ labelで定義したラベルへの参照の例です。EPUBだと@<href>{#inlin
365
365
  : @<column>{ch03|column2}
366
366
  コラム参照
367
367
 
368
+ URLは@<embed>{@}<href>を使います。@<href>{https://localhost/longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong}@<fn>{fnref}
369
+
370
+ //footnote[fnref][脚注に長いURLを入れてみます。@<href>{https://localhost/longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong}]
371
+
372
+
373
+
368
374
  === 参考文献
369
375
  参考文献@<tt>{bib.re}ファイルへの文献参照は、@<bib>{lins}とします。
370
376
 
@@ -224,6 +224,20 @@
224
224
  \RequirePackage{pxjahyper}
225
225
  \fi
226
226
 
227
+ %% better line breaks for long urls
228
+ \AtBeginDocument{%
229
+ %% modified url.sty
230
+ \def\UrlBreaks{%
231
+ \do\0\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9%
232
+ \do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
233
+ \do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z%
234
+ \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n%
235
+ \do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z%
236
+ %%
237
+ \do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]%
238
+ \do\)\do\,\do\?\do\&\do\'\do+\do\=\do\#}%
239
+ }
240
+
227
241
  %% include fullpage graphics
228
242
  \edef\grnchry@head{\dimexpr\topmargin+1in+\headheight+\headsep}
229
243
  \edef\grnchry@gutter{\evensidemargin}