review 5.7.0 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11969067c8cb25999f37895ba330bd5c030c62402d1540510e241c6029c38d90
4
- data.tar.gz: 4294e10f33abcb6063ea0098c3b7256374a5696d693fe2284dcb0fed4f2b2348
3
+ metadata.gz: 368cf93a0b3ae0f5aaecebdef459f759ab45998b9236cfa983294711a4f135b6
4
+ data.tar.gz: 9990d2ed06a889cc951c3db58b47431e8ad414842fb4e6868082e2c33dd73139
5
5
  SHA512:
6
- metadata.gz: dddd61f8870c1f2e0d1117d3318cb456bcf49db10a12c4c93dc8b7638b08e5b6894efdfbdbd635d432196f82d40f906b29435f4f6e5ddbb78d2dcbd3829715af
7
- data.tar.gz: 695257c02903d581c061cd7813e8951923a4a63986e879aa6e6ee31d963d627bf0e9512f85ffc56ca6a596a8f8f114ed012c3cce9daa7dd41072aabc89a9cb3d
6
+ metadata.gz: a78a8e4f75a856c15c492a9ef466efd72cad538a6c3378023b6c0dd83ec268e7a99126b16cb3d2ec158035b9f620380a50b759319131227c403b09b27bd8e8b6
7
+ data.tar.gz: 7f14b429a757435416de52eb8bed9d05925c1694e647c2165b68c46c835fcea9f0f1e4ea7d908219ceceb3edb179bf130ffe2ef811fe58416d00aba6f0d4e068
@@ -28,6 +28,10 @@ jobs:
28
28
  - name: fix ImageMagick policy.xml on Linux
29
29
  if: runner.os == 'Linux'
30
30
  run: sudo sed -i 's/none/read|write/g' /etc/ImageMagick-6/policy.xml
31
+ - name: use Node.js 18.x
32
+ uses: actions/setup-node@v3
33
+ with:
34
+ node-version: 18
31
35
  - name: Build and test with Rake
32
36
  run: |
33
37
  gem install bundler --no-document
data/NEWS.ja.md CHANGED
@@ -1,3 +1,20 @@
1
+ # Version 5.8.0
2
+ ## 新機能
3
+ * `//graph` 命令でMermaid記法によるグラフ記述ができるようになりました。外部ツールの用意や設定については`doc/format.ja.md`を参照してください ([#1885])
4
+
5
+ ## バグ修正
6
+ * EPUBMaker: 自動生成される部の内容に`<title>`が入らないのを修正しました ([#1898])
7
+
8
+ ## 機能強化
9
+ * PDFMaker: `@<href>`命令で長いURLを記述したときに、ページをはみ出さずに折り返すようにしました ([#1890])
10
+
11
+ ## コントリビューターのみなさん
12
+ * [@munepi](https://github.com/munepi)
13
+
14
+ [#1885]: https://github.com/kmuto/review/pull/1885
15
+ [#1890]: https://github.com/kmuto/review/issues/1890
16
+ [#1898]: https://github.com/kmuto/review/pull/1898
17
+
1
18
  # Version 5.7.0
2
19
  ## バグ修正
3
20
  * Windows において、`review-init -w` の実行時にバインドアドレスを省略したときにエラーが発生するのを修正しました ([#1824])
data/NEWS.md CHANGED
@@ -1,3 +1,20 @@
1
+ # Version 5.8.0
2
+ ## New Features
3
+ * The `//graph` operator allows graphical description in Mermaid notation. See `doc/format.md` for details on prepairing and setting up external tools ([#1885])
4
+
5
+ ## Bug Fixes
6
+ * EPUBMaker: fix `<title>` not being included in the auto-generated part content ([#1898])
7
+
8
+ ## Enhancements
9
+ * PDFMaker: fix to wrap long URLs with `@<href>` operator ([#1890])
10
+
11
+ ## Contributors
12
+ * [@munepi](https://github.com/munepi)
13
+
14
+ [#1885]: https://github.com/kmuto/review/pull/1885
15
+ [#1890]: https://github.com/kmuto/review/issues/1890
16
+ [#1898]: https://github.com/kmuto/review/pull/1898
17
+
1
18
  # Version 5.7.0
2
19
  ## Bug Fixes
3
20
  * Fixed error when omitting a bind address of `review-init -w` on Windows ([#1824])
@@ -262,6 +262,17 @@ toc: true
262
262
  # 追加する<meta>要素のプロパティとその値
263
263
  # opf_meta: {"ebpaj:guide-version": "1.1.3"}
264
264
 
265
+ # Playwrightの利用オプション
266
+ # playwright_options:
267
+ # playwrightコマンドのパス
268
+ # playwright_path: "./node_modules/.bin/playwright"
269
+ # playwright-runnerの切り取りを使う。pdfcropを使う場合はfalseにする
270
+ # selfcrop: true
271
+ # pdfcropコマンドのパス
272
+ # pdfcrop_path: "pdfcrop"
273
+ # pdftocairoコマンドのパス
274
+ # pdftocairo_path: "pdftocairo"
275
+
265
276
  # 以下のパラメータを有効にするときには、
266
277
  # epubmaker:
267
278
  # パラメータ: 値
data/doc/format.ja.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Re:VIEW フォーマットの文法について解説します。Re:VIEW フォーマットはアスキー社(現カドカワ)の EWB を基本としながら、一部に RD や各種 Wiki の文法を取り入れて簡素化しています。
4
4
 
5
- このドキュメントは、Re:VIEW 5.5 に基づいています。
5
+ このドキュメントは、Re:VIEW 5.8 に基づいています。
6
6
 
7
7
  ## 段落
8
8
 
@@ -407,13 +407,61 @@ plot sin(x)
407
407
  //}
408
408
  ```
409
409
 
410
- コマンド名には、「`graphviz`」「`gnuplot`」「`blockdiag`」「`aafigure`」「`plantuml`」のいずれかを指定できます。ツールはそれぞれ別途インストールし、インストール先のフォルダ名を指定することなく実行できる (パスを通す) 必要があります。
410
+ コマンド名には、「`graphviz`」「`gnuplot`」「`blockdiag`」「`aafigure`」「`plantuml`」「`mermaid`」のいずれかを指定できます。ツールはそれぞれ別途インストールし、インストール先のフォルダ名を指定することなく実行できる (パスを通す) 必要があります。
411
411
 
412
412
  * Graphviz ( https://www.graphviz.org/ ) : `dot` コマンドへのパスを OS に設定すること
413
413
  * Gnuplot ( http://www.gnuplot.info/ ) : `gnuplot` コマンドへのパスを OS に設定すること
414
414
  * Blockdiag ( http://blockdiag.com/ ) : `blockdiag` コマンドへのパスを OS に設定すること。PDF を生成する場合は ReportLab もインストールすること
415
415
  * aafigure ( https://launchpad.net/aafigure ) : `aafigure` コマンドへのパスを OS に設定すること
416
416
  * PlantUML ( http://plantuml.com/ ) : `java` コマンドへのパスを OS に設定し、`plantuml.jar` が作業フォルダ、または `/usr/share/plantuml` あるいは `/usr/share/java` フォルダにあること
417
+ * Mermaid ( https://mermaid.js.org/ ) : 以下を参照
418
+
419
+ ### Mermaid の利用
420
+
421
+ Mermaid は Web ブラウザ上で動作する JavaScript ベースの図形描画ツールです。EPUB や LaTeX 経由の PDF で利用するには、Web ブラウザを内部的に呼び出して画像化する必要があります。現時点で、Linux 以外の動作は確認していません。
422
+
423
+ 1. プロジェクトに次のように `package.json` を作成します(既存のファイルがあるときには、`dependencies` に `"playwright"〜` の行を追加します)。
424
+ ```
425
+ {
426
+ "name": "book",
427
+ "dependencies": {
428
+ "playwright": "^1.32.2"
429
+ }
430
+ }
431
+ ```
432
+ 2. Playwright ライブラリをインストールします。`npm` がない場合は、[Node.js](https://nodejs.org/) の環境をセットアップしてください。
433
+ ```
434
+ npm install
435
+ ```
436
+ 3. Playwright ライブラリを Ruby から呼び出すモジュールである [playwright-runner](https://github.com/kmuto/playwright-runner) をインストールします。
437
+ ```
438
+ gem install playwright-runner
439
+ ```
440
+ 4. (オプション) EPUB には SVG 形式を作成する必要がありますが、SVG に変換するには、[poppler](https://gitlab.freedesktop.org/poppler/poppler) に含まれる `pdftocairo` コマンドが必要です。Debian およびその派生物では以下のようにしてインストールできます。
441
+ ```
442
+ apt install poppler-utils
443
+ ```
444
+ 5. (オプション) デフォルトでは図の周囲に大きめの余白ができてしまいます。これを詰めるには、TeXLive に含まれる `pdfcrop` コマンドが必要です。Debian およびその派生物では以下のようにしてインストールできます。
445
+ ```
446
+ apt install texlive-extra-utils
447
+ ```
448
+
449
+ プロジェクトの `config.yml` を適宜調整します。デフォルト値は以下のとおりです。
450
+
451
+ ```
452
+ playwright_options:
453
+ playwright_path: "./node_modules/.bin/playwright"
454
+ selfcrop: true
455
+ pdfcrop_path: "pdfcrop"
456
+ pdftocairo_path: "pdftocairo"
457
+ ```
458
+
459
+ - `playwright_path`: `playwright` コマンドのパスを相対パスまたは絶対パスで指定する
460
+ - `selfcrop`: `playwright-runner` の画像切り出しを使う。`pdfcrop` が不要になるが、周囲に余白が生じる。`pdfcrop` を使うときには `false` に設定する
461
+ - `pdfcrop_path`: `pdfcrop` コマンドのパス。`selfcrop` が `true` のときには無視される
462
+ - `pdftocairo_path`: `pdftocairo` コマンドのパス
463
+
464
+ Re:VIEW 側の記法としては `//graph[ID][mermaid][キャプション]` または `//graph[ID][mermaid]` となりますが、この ID に基づき、`images/html/ID.svg`(EPUB の場合)や `images/latex/ID.pdf`(LaTeX PDF の場合)が生成されます。
417
465
 
418
466
  ## 表
419
467
 
data/doc/format.md CHANGED
@@ -4,7 +4,7 @@ The document is a brief guide for Re:VIEW markup syntax.
4
4
 
5
5
  Re:VIEW is based on EWB of ASCII (now KADOKAWA), influenced RD and other Wiki system's syntax.
6
6
 
7
- This document explains about the format of Re:VIEW 5.5.
7
+ This document explains about the format of Re:VIEW 5.8.
8
8
 
9
9
  ## Paragraph
10
10
 
@@ -425,7 +425,7 @@ plot sin(x)
425
425
  //}
426
426
  ```
427
427
 
428
- You can use `graphviz`, `gnuplot`, `blockdiag`, `aafigure`, and `plantuml` as the command name.
428
+ You can use `graphviz`, `gnuplot`, `blockdiag`, `aafigure`, `plantuml`, and `mermaid` as the command name.
429
429
  Before using these tools, you should installed them and configured path appropriately.
430
430
 
431
431
  * Graphviz ( https://www.graphviz.org/ ) : set path to `dot` command
@@ -433,6 +433,54 @@ Before using these tools, you should installed them and configured path appropri
433
433
  * Blockdiag ( http://blockdiag.com/ ) : set path to `blockdiag` command. Install ReportLab also to make a PDF
434
434
  * aafigure ( https://launchpad.net/aafigure ) : set path to `aafigure` command
435
435
  * PlantUML ( http://plantuml.com/ ) : set path to `java` command. place `plantuml.jar` on working folder, `/usr/share/plantuml` or `/usr/share/java`.
436
+ * Mermaid ( https://mermaid.js.org/ ) : see below
437
+
438
+ ### using Mermaid
439
+
440
+ Mermaid is a JavaScript-based diagram tool that runs in a Web browser. For use with EPUB or LaTeX PDF, Re:VIEW calls the Web browser internally to create images. At this time, we have not confirmed that Mermaid works on any platforms other than Linux.
441
+
442
+ 1. Create `package.json` in your project (if you have an existing file, add the line `"playwright"...` to the `dependencies`).
443
+ ```
444
+ {
445
+ "name": "book",
446
+ "dependencies": {
447
+ "playwright": "^1.32.2"
448
+ }
449
+ }
450
+ ```
451
+ 2. Install Playwright library. If you don't have `npm`, set up [Node.js](https://nodejs.org/) first.
452
+ ```
453
+ npm install
454
+ ```
455
+ 3. Install [playwright-runner](https://github.com/kmuto/playwright-runner), a module that calls the Playwright library from Ruby.
456
+ ```
457
+ gem install playwright-runner
458
+ ```
459
+ 4. (Optional) Since EPUB cannot handle PDF, the images must be in SVG format; to convert them to SVG, you need the `pdftocairo` command included in [poppler](https://gitlab.freedesktop.org/poppler/poppler). It can be installed in Debian and its derivatives as follows:
460
+ ```
461
+ apt install poppler-utils
462
+ ```
463
+ 5. (Optional )By default, there will be white margins around the figure. To crop them, you need the `pdfcrop` command included in TeXLive, which can be installed in Debian and its derivatives as follows:
464
+ ```
465
+ apt install texlive-extra-utils
466
+ ```
467
+
468
+ Adjust `config.yml`. The default values are as follows:
469
+
470
+ ```
471
+ playwright_options:
472
+ playwright_path: "./node_modules/.bin/playwright"
473
+ selfcrop: true
474
+ pdfcrop_path: "pdfcrop"
475
+ pdftocairo_path: "pdftocairo"
476
+ ```
477
+
478
+ - `playwright_path`: path of the `playwright` command.
479
+ - `selfcrop`: use the default cropper of `playwright-runner`. The `pdfcrop` will not be needed, but there will be margins around it. Set to `false` if you can use `pdfcrop`.
480
+ - `pdfcrop_path`: path of the `pdfcrop` command. Ignored if `selfcrop` is `true`.
481
+ - `pdftocairo_path`: path of the `pdftocairo` command.
482
+
483
+ The notation in Re:VIEW is `//graph[ID][mermaid][caption]` or `//graph[ID][mermaid]`. Based on this ID, `images/html/ID.svg` (for EPUB) or `images/latex/ID.pdf` (for LaTeX PDF) will be generated.
436
484
 
437
485
  ## Tables
438
486
 
@@ -73,7 +73,7 @@ module ReVIEW
73
73
  end
74
74
 
75
75
  def imagedir
76
- File.join(@basedir, config['imagedir'])
76
+ config['imagedir']
77
77
  end
78
78
 
79
79
  def image_types
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014-2018 Minero Aoki, Kenshi Muto, Masayoshi Takahashi
2
+ # Copyright (c) 2014-2023 Minero Aoki, Kenshi Muto, Masayoshi Takahashi
3
3
  #
4
4
  # This program is free software.
5
5
  # You can distribute or modify this program under the terms of
@@ -13,35 +13,50 @@ require 'review/exception'
13
13
  module ReVIEW
14
14
  module Book
15
15
  class ImageFinder
16
- def initialize(basedir, chapid, builder, exts)
17
- @basedir = basedir
18
- @chapid = chapid
19
- @builder = builder
20
- @exts = exts
21
- @entries = dir_entries
16
+ def initialize(chapter)
17
+ @book = chapter.book
18
+ @basedir = @book.imagedir
19
+ @chapid = chapter.id
20
+ @builder = @book.config['builder']
21
+ @entries = dir_entries.map { |path| entry_object(path) }
22
+ end
23
+
24
+ def entry_object(path)
25
+ { path: path, basename: path.sub(/\.[^.]+$/, ''), downcase: path.sub(/\.[^.]+$/, $&.downcase) }
22
26
  end
23
27
 
24
28
  def dir_entries
25
- Dir.glob(File.join(@basedir, '**{,/*/**}/*.*')).uniq.sort
29
+ Dir.glob(File.join(@basedir, '**{,/*/**}/*.*')).uniq.sort.map { |entry| entry.sub(%r{^\./}, '') }
26
30
  end
27
31
 
28
32
  def add_entry(path)
29
- @entries << path unless @entries.include?(path)
33
+ path.sub!(%r{^\./}, '')
34
+ unless @entries.find { |entry| entry[:path] == path }
35
+ @entries << entry_object(path)
36
+ end
30
37
  @entries
31
38
  end
32
39
 
33
40
  def find_path(id)
34
41
  targets = target_list(id)
35
42
  targets.each do |target|
36
- @exts.each do |ext|
37
- @entries.find do |entry|
38
- downname = entry.sub(/\.[^.]+$/, File.extname(entry).downcase)
39
- if downname == "#{target}#{ext}"
40
- return entry
43
+ @book.image_types.each do |ext|
44
+ entries = @entries.select do |entry|
45
+ entry[:basename] == target
46
+ end
47
+
48
+ unless entries
49
+ break
50
+ end
51
+
52
+ entries.find do |entry|
53
+ if entry[:downcase] == "#{target}#{ext}"
54
+ return entry[:path]
41
55
  end
42
56
  end
43
57
  end
44
58
  end
59
+
45
60
  nil
46
61
  end
47
62
 
@@ -138,14 +138,7 @@ module ReVIEW
138
138
  def initialize(chapter)
139
139
  super()
140
140
  @chapter = chapter
141
- book = @chapter.book
142
-
143
- chapid = chapter.id
144
- basedir = book.imagedir
145
- builder = book.config['builder']
146
- types = book.image_types
147
-
148
- @image_finder = ReVIEW::Book::ImageFinder.new(basedir, chapid, builder, types)
141
+ @image_finder = ReVIEW::Book::ImageFinder.new(@chapter)
149
142
  end
150
143
 
151
144
  def find_path(id)
@@ -11,6 +11,7 @@ require 'review/textutils'
11
11
  require 'review/compiler'
12
12
  require 'review/sec_counter'
13
13
  require 'review/img_math'
14
+ require 'review/img_graph'
14
15
  require 'review/loggable'
15
16
  require 'stringio'
16
17
  require 'fileutils'
@@ -35,13 +36,14 @@ module ReVIEW
35
36
  attr_accessor :doc_status
36
37
  attr_reader :location
37
38
 
38
- def initialize(strict = false, *_args, img_math: nil)
39
+ def initialize(strict = false, *_args, img_math: nil, img_graph: nil)
39
40
  @strict = strict
40
41
  @output = nil
41
42
  @logger = ReVIEW.logger
42
43
  @doc_status = {}
43
44
  @dictionary = {}
44
45
  @img_math = img_math
46
+ @img_graph = img_graph
45
47
  @shown_endnotes = true
46
48
  end
47
49
 
@@ -61,6 +63,7 @@ module ReVIEW
61
63
  @tsize = nil
62
64
  if @book && @book.config
63
65
  @img_math ||= ReVIEW::ImgMath.new(@book.config)
66
+ @img_graph ||= ReVIEW::ImgGraph.new(@book.config, target_name)
64
67
  if words_file_path = @book.config['words_file']
65
68
  words_files = if words_file_path.is_a?(String)
66
69
  [words_file_path]
@@ -699,6 +702,16 @@ EOTGNUPLOT
699
702
  file_path
700
703
  end
701
704
 
705
+ def graph_mermaid(id, _file_path, _line, tf_path)
706
+ begin
707
+ require 'playwrightrunner'
708
+ rescue LoadError
709
+ app_error "#{@location}: could not handle Mermaid of //graph in this builder."
710
+ end
711
+
712
+ @img_graph.defer_mermaid_image(File.read(tf_path), id)
713
+ end
714
+
702
715
  def image_ext
703
716
  raise NotImplementedError
704
717
  end
@@ -68,6 +68,13 @@ module ReVIEW
68
68
  'externallink' => true,
69
69
  'join_lines_by_lang' => nil, # experimental. default should be nil
70
70
  'table_row_separator' => 'tabs',
71
+ # for Playwright
72
+ 'playwright_options' => {
73
+ 'playwright_path' => './node_modules/.bin/playwright',
74
+ 'selfcrop' => true,
75
+ 'pdfcrop_path' => 'pdfcrop',
76
+ 'pdftocairo_path' => 'pdftocairo'
77
+ },
71
78
  # for IDGXML
72
79
  'tableopt' => nil,
73
80
  'listinfo' => nil,
@@ -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
 
@@ -282,11 +284,12 @@ module ReVIEW
282
284
  @manifeststr = ''
283
285
  @ncxstr = ''
284
286
  @tocdesc = []
287
+ @img_graph = ReVIEW::ImgGraph.new(@config, 'html', path_name: '_review_graph')
285
288
 
286
289
  basedir = File.dirname(yamlfile)
287
290
  base_path = Pathname.new(basedir)
288
291
  book = ReVIEW::Book::Base.new(basedir, config: @config)
289
- @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))
290
293
  @compile_errors = nil
291
294
 
292
295
  book.parts.each do |part|
@@ -310,6 +313,13 @@ module ReVIEW
310
313
  end
311
314
  end
312
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
313
323
  end
314
324
 
315
325
  def build_part(part, basetmpdir, htmlfile)
@@ -317,6 +327,7 @@ module ReVIEW
317
327
  File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
318
328
  @part_number = part.number
319
329
  @part_title = part.name.strip
330
+ @title = @part_title
320
331
  @body = ReVIEW::Template.generate(path: template_name(localfile: '_part_body.html.erb', systemfile: 'html/_part_body.html.erb'), binding: binding)
321
332
  @language = @producer.config['language']
322
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
  #
@@ -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
@@ -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
@@ -260,17 +261,26 @@ module ReVIEW
260
261
  def generate_pdf
261
262
  remove_old_file
262
263
  @path = build_path
264
+ @img_graph = ReVIEW::ImgGraph.new(@config, 'latex', path_name: '_review_graph')
265
+
263
266
  begin
264
267
  @compile_errors = nil
265
268
 
266
269
  book = ReVIEW::Book::Base.new(@basedir, config: @config)
267
- @converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new)
270
+ @converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new(img_graph: @img_graph))
268
271
  erb_config
269
272
 
270
273
  @input_files = make_input_files(book)
271
274
 
272
275
  check_compile_status(@config['ignore-errors'])
273
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
+
274
284
  # for backward compatibility
275
285
  @config['usepackage'] = ''
276
286
  @config['usepackage'] = "\\usepackage{#{@config['texstyle']}}" if @config['texstyle']
@@ -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|
@@ -1,3 +1,3 @@
1
1
  module ReVIEW
2
- VERSION = '5.7.0'.freeze
2
+ VERSION = '5.8.0'.freeze
3
3
  end
data/review.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
25
25
  gem.add_dependency('rubyzip')
26
26
  gem.add_dependency('tty-logger')
27
27
  gem.add_development_dependency('mini_magick')
28
+ gem.add_development_dependency('playwright-runner')
28
29
  gem.add_development_dependency('pygments.rb')
29
30
  gem.add_development_dependency('rake')
30
31
  gem.add_development_dependency('rubocop', '~> 1.45.1')
@@ -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}
@@ -400,6 +400,20 @@
400
400
  ]{hyperref}
401
401
  \RequirePackage{pxjahyper}
402
402
 
403
+ %% better line breaks for long urls
404
+ \AtBeginDocument{%
405
+ %% modified url.sty
406
+ \def\UrlBreaks{%
407
+ \do\0\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9%
408
+ \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%
409
+ \do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z%
410
+ \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%
411
+ \do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z%
412
+ %%
413
+ \do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]%
414
+ \do\)\do\,\do\?\do\&\do\'\do+\do\=\do\#}%
415
+ }
416
+
403
417
  %% more useful macros
404
418
  %% ----------
405
419
  %% include fullpage graphics
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: review
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.0
4
+ version: 5.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kmuto
8
8
  - takahashim
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-28 00:00:00.000000000 Z
12
+ date: 2023-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: image_size
@@ -95,6 +95,20 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: playwright-runner
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  - !ruby/object:Gem::Dependency
99
113
  name: pygments.rb
100
114
  requirement: !ruby/object:Gem::Requirement
@@ -354,6 +368,7 @@ files:
354
368
  - lib/review/i18n.yml
355
369
  - lib/review/idgxmlbuilder.rb
356
370
  - lib/review/idgxmlmaker.rb
371
+ - lib/review/img_graph.rb
357
372
  - lib/review/img_math.rb
358
373
  - lib/review/index_builder.rb
359
374
  - lib/review/init-web/finish.html
@@ -590,7 +605,7 @@ licenses:
590
605
  - LGPL
591
606
  metadata:
592
607
  rubygems_mfa_required: 'true'
593
- post_install_message:
608
+ post_install_message:
594
609
  rdoc_options: []
595
610
  require_paths:
596
611
  - lib
@@ -605,8 +620,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
620
  - !ruby/object:Gem::Version
606
621
  version: '0'
607
622
  requirements: []
608
- rubygems_version: 3.0.3.1
609
- signing_key:
623
+ rubygems_version: 3.4.14
624
+ signing_key:
610
625
  specification_version: 4
611
626
  summary: 'Re:VIEW: a easy-to-use digital publishing system'
612
627
  test_files: []