rabbit 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -1
- data/data/locale/ja/LC_MESSAGES/rabbit.mo +0 -0
- data/doc/_config.yml +2 -2
- data/doc/_layouts/skeleton.html +0 -7
- data/doc/en/install/homebrew.rd +8 -13
- data/doc/en/news.rd +67 -0
- data/doc/images/screenshots/en/blue-circle-raw.png +0 -0
- data/doc/images/screenshots/en/blue-circle.png +0 -0
- data/doc/images/screenshots/en/clear-blue-raw.png +0 -0
- data/doc/images/screenshots/en/clear-blue.png +0 -0
- data/doc/images/screenshots/en/cozmixng-raw.png +0 -0
- data/doc/images/screenshots/en/cozmixng.png +0 -0
- data/doc/images/screenshots/en/dark-gradation-raw.png +0 -0
- data/doc/images/screenshots/en/dark-gradation.png +0 -0
- data/doc/images/screenshots/en/day-white-raw.png +0 -0
- data/doc/images/screenshots/en/day-white.png +0 -0
- data/doc/images/screenshots/en/debian-raw.png +0 -0
- data/doc/images/screenshots/en/debian.png +0 -0
- data/doc/images/screenshots/en/green-circle-raw.png +0 -0
- data/doc/images/screenshots/en/green-circle.png +0 -0
- data/doc/images/screenshots/en/night-black-raw.png +0 -0
- data/doc/images/screenshots/en/night-black.png +0 -0
- data/doc/images/screenshots/en/rabbit-raw.png +0 -0
- data/doc/images/screenshots/en/rabbit.png +0 -0
- data/doc/images/screenshots/en/ranguba-raw.png +0 -0
- data/doc/images/screenshots/en/ranguba.png +0 -0
- data/doc/images/screenshots/en/red-frame-raw.png +0 -0
- data/doc/images/screenshots/en/red-frame.png +0 -0
- data/doc/images/screenshots/en/ruby-gnome2-raw.png +0 -0
- data/doc/images/screenshots/en/ruby-gnome2.png +0 -0
- data/doc/images/screenshots/en/rubykaigi2011-raw.png +0 -0
- data/doc/images/screenshots/en/rubykaigi2011.png +0 -0
- data/doc/images/screenshots/ja/blue-circle-raw.png +0 -0
- data/doc/images/screenshots/ja/blue-circle.png +0 -0
- data/doc/images/screenshots/ja/clear-blue-raw.png +0 -0
- data/doc/images/screenshots/ja/clear-blue.png +0 -0
- data/doc/images/screenshots/ja/cozmixng-raw.png +0 -0
- data/doc/images/screenshots/ja/cozmixng.png +0 -0
- data/doc/images/screenshots/ja/dark-gradation-raw.png +0 -0
- data/doc/images/screenshots/ja/dark-gradation.png +0 -0
- data/doc/images/screenshots/ja/day-white-raw.png +0 -0
- data/doc/images/screenshots/ja/day-white.png +0 -0
- data/doc/images/screenshots/ja/debian-raw.png +0 -0
- data/doc/images/screenshots/ja/debian.png +0 -0
- data/doc/images/screenshots/ja/green-circle-raw.png +0 -0
- data/doc/images/screenshots/ja/green-circle.png +0 -0
- data/doc/images/screenshots/ja/night-black-raw.png +0 -0
- data/doc/images/screenshots/ja/night-black.png +0 -0
- data/doc/images/screenshots/ja/rabbit-raw.png +0 -0
- data/doc/images/screenshots/ja/rabbit.png +0 -0
- data/doc/images/screenshots/ja/ranguba-raw.png +0 -0
- data/doc/images/screenshots/ja/ranguba.png +0 -0
- data/doc/images/screenshots/ja/red-frame-raw.png +0 -0
- data/doc/images/screenshots/ja/red-frame.png +0 -0
- data/doc/images/screenshots/ja/ruby-gnome2-raw.png +0 -0
- data/doc/images/screenshots/ja/ruby-gnome2.png +0 -0
- data/doc/images/screenshots/ja/rubykaigi2011-raw.png +0 -0
- data/doc/images/screenshots/ja/rubykaigi2011.png +0 -0
- data/doc/ja/install/homebrew.rd +8 -12
- data/doc/ja/news.rd +67 -0
- data/lib/rabbit/canvas.rb +7 -5
- data/lib/rabbit/element/base.rb +1 -5
- data/lib/rabbit/element/image.rb +70 -4
- data/lib/rabbit/error.rb +7 -1
- data/lib/rabbit/formatter.rb +1 -1
- data/lib/rabbit/gem-pusher.rb +2 -1
- data/lib/rabbit/image/base.rb +67 -3
- data/lib/rabbit/image/dia.rb +7 -15
- data/lib/rabbit/image/mermaid.rb +73 -0
- data/lib/rabbit/image/pdf.rb +21 -5
- data/lib/rabbit/image.rb +3 -2
- data/lib/rabbit/parser/base.rb +2 -1
- data/lib/rabbit/parser/ext/blockdiag.rb +16 -14
- data/lib/rabbit/parser/ext/image.rb +36 -9
- data/lib/rabbit/parser/markdown/converter.rb +36 -30
- data/lib/rabbit/parser/rd/ext/block-verbatim.rb +23 -33
- data/lib/rabbit/parser/rd/ext/image.rb +23 -4
- data/lib/rabbit/parser/rd/rd2rabbit-lib.rb +3 -1
- data/lib/rabbit/parser/rd.rb +1 -1
- data/lib/rabbit/parser/wiki/output.rb +9 -9
- data/lib/rabbit/parser.rb +2 -2
- data/lib/rabbit/properties.rb +14 -1
- data/lib/rabbit/renderer/display/drawing-area-base.rb +1 -1
- data/lib/rabbit/slide-configuration.rb +4 -0
- data/lib/rabbit/task/slide.rb +4 -31
- data/lib/rabbit/theme/background-image-toolkit/background-image-toolkit.rb +38 -0
- data/lib/rabbit/theme/clear-blue/clear-blue.rb +1 -1
- data/lib/rabbit/theme/image/image.rb +3 -0
- data/lib/rabbit/theme/image-slide-number/image-slide-number.rb +7 -2
- data/lib/rabbit/theme/image-timer/image-timer.rb +8 -3
- data/lib/rabbit/theme/pdf/pdf.rb +1 -1
- data/lib/rabbit/utils.rb +25 -2
- data/lib/rabbit/version.rb +2 -2
- data/po/en/rabbit.edit.po +50 -66
- data/po/en/rabbit.po +12 -24
- data/po/fr/rabbit.edit.po +50 -66
- data/po/fr/rabbit.po +12 -24
- data/po/ja/rabbit.edit.po +82 -94
- data/po/ja/rabbit.po +18 -30
- data/rabbit.gemspec +0 -1
- data/sample/rabbit-en.md +13 -0
- data/sample/rabbit-en.rd +10 -0
- data/sample/rabbit.md +21 -0
- data/sample/rabbit.rd +20 -0
- data/test/command/test-rabbit.rb +1 -0
- data/test/parser/test-markdown.rb +2 -2
- data/test/test-slide-configuration.rb +2 -1
- metadata +7 -26
- data/doc/css/jquery-ui/themes/ui-lightness.css +0 -573
- data/doc/javascripts/jquery-ui.js +0 -11544
- data/doc/javascripts/jquery.js +0 -7179
- data/lib/rabbit/slideshare.rb +0 -192
- data/test/test-slideshare.rb +0 -34
data/lib/rabbit/image/base.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2004-
|
1
|
+
# Copyright (C) 2004-2022 Sutou Kouhei <kou@cozmixng.org>
|
2
2
|
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
@@ -14,6 +14,9 @@
|
|
14
14
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
15
15
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
16
|
|
17
|
+
require "forwardable"
|
18
|
+
require "digest/sha2"
|
19
|
+
|
17
20
|
require "gdk_pixbuf2"
|
18
21
|
|
19
22
|
require "rabbit/image-data-loader"
|
@@ -21,19 +24,40 @@ require "rabbit/properties"
|
|
21
24
|
|
22
25
|
module Rabbit
|
23
26
|
module ImageManipulable
|
24
|
-
|
25
27
|
class Base
|
26
28
|
extend ModuleLoader
|
27
29
|
|
30
|
+
class << self
|
31
|
+
def delegate
|
32
|
+
extend Forwardable
|
33
|
+
|
34
|
+
def_delegators(:@delegated_loader,
|
35
|
+
:draw,
|
36
|
+
:ensure_resize,
|
37
|
+
:height,
|
38
|
+
:internal_pixbuf,
|
39
|
+
:keep_ratio,
|
40
|
+
:keep_ratio=,
|
41
|
+
:keep_ratio?,
|
42
|
+
:original_height,
|
43
|
+
:original_width,
|
44
|
+
:pixbuf,
|
45
|
+
:resize,
|
46
|
+
:update_size,
|
47
|
+
:width)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
28
51
|
attr_reader :filename
|
29
52
|
attr_reader :properties
|
30
53
|
attr_reader :original_width
|
31
54
|
attr_reader :original_height
|
32
55
|
attr_reader :animation
|
33
56
|
|
34
|
-
def initialize(filename, props)
|
57
|
+
def initialize(filename, props, canvas: nil)
|
35
58
|
@filename = filename
|
36
59
|
@properties = Properties.new(props)
|
60
|
+
@canvas = canvas
|
37
61
|
initialize_keep_ratio
|
38
62
|
@animation = nil
|
39
63
|
@animation_iterator = nil
|
@@ -200,6 +224,46 @@ module Rabbit
|
|
200
224
|
}
|
201
225
|
end
|
202
226
|
end
|
227
|
+
|
228
|
+
# TODO: Move to more suitable location
|
229
|
+
def cache_processed_data(canvas, input, extension)
|
230
|
+
tmp_dir_name = canvas&.tmp_dir_name
|
231
|
+
return yield unless tmp_dir_name
|
232
|
+
hash = compute_hash(input)
|
233
|
+
cached_path = File.join(tmp_dir_name, "#{hash}.#{extension}")
|
234
|
+
unless File.exist?(cached_path)
|
235
|
+
processed_path = yield
|
236
|
+
FileUtils.cp(processed_path, cached_path)
|
237
|
+
end
|
238
|
+
cached_path
|
239
|
+
end
|
240
|
+
|
241
|
+
def compute_hash(input)
|
242
|
+
digest = Digest::SHA2.new
|
243
|
+
add_data = lambda do |data|
|
244
|
+
case data
|
245
|
+
when Array
|
246
|
+
data.each do |element|
|
247
|
+
add_data.call(element)
|
248
|
+
end
|
249
|
+
when Hash
|
250
|
+
data.each do |key, value|
|
251
|
+
add_data.call(key)
|
252
|
+
add_data.call(value)
|
253
|
+
end
|
254
|
+
when String
|
255
|
+
digest << data
|
256
|
+
when IO
|
257
|
+
loop do
|
258
|
+
chunk = data.read(4096)
|
259
|
+
break if chunk.nil?
|
260
|
+
digest << chunk
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
add_data.call(input)
|
265
|
+
digest.hexdigest
|
266
|
+
end
|
203
267
|
end
|
204
268
|
end
|
205
269
|
end
|
data/lib/rabbit/image/dia.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2004-
|
1
|
+
# Copyright (C) 2004-2022 Sutou Kouhei <kou@cozmixng.org>
|
2
2
|
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
@@ -14,8 +14,6 @@
|
|
14
14
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
15
15
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
16
|
|
17
|
-
require "forwardable"
|
18
|
-
|
19
17
|
require "rabbit/image/base"
|
20
18
|
|
21
19
|
module Rabbit
|
@@ -26,7 +24,6 @@ module Rabbit
|
|
26
24
|
|
27
25
|
DIA_COMMANDS = %w(dia)
|
28
26
|
|
29
|
-
extend Forwardable
|
30
27
|
include SystemRunner
|
31
28
|
|
32
29
|
class << self
|
@@ -48,26 +45,21 @@ module Rabbit
|
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
51
|
-
|
52
|
-
def_delegators(:@svg_loader, :pixbuf, :internal_pixbuf)
|
53
|
-
def_delegators(:@svg_loader, :width, :height)
|
54
|
-
def_delegators(:@svg_loader, :original_width, :original_height)
|
55
|
-
def_delegators(:@svg_loader, :resize, :ensure_resize)
|
56
|
-
def_delegators(:@svg_loader, :update_size)
|
48
|
+
delegate
|
57
49
|
|
58
|
-
def initialize(filename, props)
|
59
|
-
|
50
|
+
def initialize(filename, props, canvas: nil)
|
51
|
+
init_delegated_loader(filename, props, canvas)
|
60
52
|
super
|
61
53
|
end
|
62
54
|
|
63
55
|
private
|
64
|
-
def
|
65
|
-
@svg_file = Tempfile.new(["rabbit-loader-dia", ".svg"])
|
56
|
+
def init_delegated_loader(filename, props, canvas)
|
57
|
+
@svg_file = Tempfile.new(["rabbit-image-loader-dia", ".svg"])
|
66
58
|
args = ["--export=#{@svg_file.path}"]
|
67
59
|
args << "--filter=svg"
|
68
60
|
args << filename
|
69
61
|
if DIA_COMMANDS.any? {|dia| run(dia, *args)}
|
70
|
-
@
|
62
|
+
@delegated_loader = SVG.new(@svg_file.path, props)
|
71
63
|
else
|
72
64
|
raise DiaCanNotHandleError.new("dia #{args.join(' ')}",
|
73
65
|
DIA_COMMANDS)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (C) 2022 Sutou Kouhei <kou@cozmixng.org>
|
2
|
+
#
|
3
|
+
# This program is free software; you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation; either version 2 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
|
+
|
17
|
+
require "rabbit/image/pdf"
|
18
|
+
|
19
|
+
module Rabbit
|
20
|
+
module ImageManipulable
|
21
|
+
class Mermaid < Base
|
22
|
+
|
23
|
+
unshift_loader(self)
|
24
|
+
|
25
|
+
include SystemRunner
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def match?(filename)
|
29
|
+
File.extname(filename).downcase.end_with?(".mmd")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
delegate
|
34
|
+
|
35
|
+
def initialize(filename, props, canvas: nil)
|
36
|
+
init_delegated_loader(filename, props, canvas)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def init_delegated_loader(filename, props, canvas)
|
42
|
+
background_color = props["background_color"] || "transparent"
|
43
|
+
pdf_path = File.open(filename, "rb") do |source|
|
44
|
+
cache_processed_data(canvas, [source, background_color], "pdf") do
|
45
|
+
@pdf_file = Tempfile.new(["rabbit-image-loader-mermaid", ".pdf"])
|
46
|
+
command_line = [
|
47
|
+
"npx",
|
48
|
+
"--yes",
|
49
|
+
"--package=@mermaid-js/mermaid-cli",
|
50
|
+
"mmdc",
|
51
|
+
"--backgroundColor", background_color,
|
52
|
+
"--input", filename,
|
53
|
+
"--output", @pdf_file.path,
|
54
|
+
"--pdfFit",
|
55
|
+
]
|
56
|
+
unless SystemRunner.run(*command_line)
|
57
|
+
format = _("tried mermaid command: %s")
|
58
|
+
additional_info = format % command_line.inspect
|
59
|
+
raise MermaidCanNotHandleError.new(command_line.join(' '),
|
60
|
+
additional_info)
|
61
|
+
end
|
62
|
+
@pdf_file.path
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@delegated_loader = PDF.new(pdf_path, props)
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_image
|
69
|
+
# do nothing
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/rabbit/image/pdf.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# Copyright (C) 2006-2022 Sutou Kouhei <kou@cozmixng.org>
|
2
|
+
#
|
3
|
+
# This program is free software; you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation; either version 2 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
|
+
|
1
17
|
require "poppler"
|
2
18
|
|
3
19
|
require "rabbit/gettext"
|
@@ -36,6 +52,11 @@ module Rabbit
|
|
36
52
|
@pixbuf ||= to_pixbuf
|
37
53
|
end
|
38
54
|
|
55
|
+
def update_size
|
56
|
+
@document = Poppler::Document.new(uri)
|
57
|
+
@width, @height = page.size
|
58
|
+
end
|
59
|
+
|
39
60
|
private
|
40
61
|
def page
|
41
62
|
index = self["page"] || 1
|
@@ -53,11 +74,6 @@ module Rabbit
|
|
53
74
|
_page
|
54
75
|
end
|
55
76
|
|
56
|
-
def update_size
|
57
|
-
@document = Poppler::Document.new(uri)
|
58
|
-
@width, @height = page.size
|
59
|
-
end
|
60
|
-
|
61
77
|
def filename
|
62
78
|
File.expand_path(@filename)
|
63
79
|
end
|
data/lib/rabbit/image.rb
CHANGED
@@ -21,6 +21,7 @@ require "rabbit/image/default"
|
|
21
21
|
require "rabbit/image/dia"
|
22
22
|
require "rabbit/image/eps"
|
23
23
|
require "rabbit/image/gimp"
|
24
|
+
require "rabbit/image/mermaid"
|
24
25
|
require "rabbit/image/pdf"
|
25
26
|
require "rabbit/image/svg"
|
26
27
|
|
@@ -37,12 +38,12 @@ module Rabbit
|
|
37
38
|
def_delegators(:@loader, :properties)
|
38
39
|
alias_method :scale, :resize
|
39
40
|
|
40
|
-
def initialize(filename, props=nil, *args, &block)
|
41
|
+
def initialize(filename, props=nil, *args, canvas: nil, &block)
|
41
42
|
unless File.exist?(filename)
|
42
43
|
raise ImageFileDoesNotExistError.new(filename)
|
43
44
|
end
|
44
45
|
super(*args, &block)
|
45
|
-
@loader = Base.find_loader(filename).new(filename, props)
|
46
|
+
@loader = Base.find_loader(filename).new(filename, props, canvas: canvas)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
data/lib/rabbit/parser/base.rb
CHANGED
@@ -9,29 +9,31 @@ module Rabbit
|
|
9
9
|
# "font" is treated as specially.
|
10
10
|
AVAILABLE_VALUE_OPTIONS = []
|
11
11
|
def make_image(path, prop, logger)
|
12
|
-
image_file = Tempfile.new("rabbit-image-blockdiag")
|
13
|
-
|
14
|
-
"blockdiag",
|
12
|
+
image_file = Tempfile.new(["rabbit-image-blockdiag", ".svg"])
|
13
|
+
command_line = [
|
15
14
|
"-T", "svg",
|
16
15
|
"-o", image_file.path,
|
17
16
|
]
|
18
17
|
font = find_font(prop)
|
19
|
-
|
18
|
+
command_line.concat(["-f", font]) if font
|
20
19
|
AVAILABLE_FLAG_OPTIONS.each do |name|
|
21
|
-
|
20
|
+
command_line << "--#{name}" if /\A(?:true|yes)\z/i =~ prop[name].to_s
|
22
21
|
end
|
23
22
|
AVAILABLE_VALUE_OPTIONS.each do |name|
|
24
|
-
|
23
|
+
command_line.concat(["--#{name}", prop[name]]) if prop.has_key?(name)
|
25
24
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
raise BlockDiagCanNotHandleError.new(command.join(' '),
|
33
|
-
additional_info)
|
25
|
+
command_line << path
|
26
|
+
blockdiag_commands = ["blockdiag3", "blockdiag"]
|
27
|
+
blockdiag_commands.each do |blockdiag|
|
28
|
+
if SystemRunner.run(blockdiag, *command_line)
|
29
|
+
return image_file
|
30
|
+
end
|
34
31
|
end
|
32
|
+
command_line.unshift(blockdiag_commands.first)
|
33
|
+
format = _("tried blockdiag command: %s")
|
34
|
+
additional_info = format % command_line
|
35
|
+
raise BlockDiagCanNotHandleError.new(command_line.join(' '),
|
36
|
+
additional_info)
|
35
37
|
end
|
36
38
|
|
37
39
|
def find_font(prop)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2007-
|
1
|
+
# Copyright (C) 2007-2022 Sutou Kouhei <kou@cozmixng.org>
|
2
2
|
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
@@ -27,31 +27,58 @@ module Rabbit
|
|
27
27
|
module Ext
|
28
28
|
module Image
|
29
29
|
module_function
|
30
|
-
def make_image(canvas, uri_str, prop={})
|
30
|
+
def make_image(canvas, uri_str, prop={}, body: nil)
|
31
31
|
path = Private.uri_string_to_image_filename(canvas, uri_str)
|
32
32
|
begin
|
33
|
-
Element::Image.new(path, prop)
|
33
|
+
image = Element::Image.new(path, prop, canvas: canvas)
|
34
34
|
rescue Error
|
35
35
|
canvas.logger.warn($!.message)
|
36
36
|
nil
|
37
|
+
else
|
38
|
+
if prop["align"] == "right" and body
|
39
|
+
if body["background-image"]
|
40
|
+
raise ParseError,
|
41
|
+
_("multiple right aligns aren't supported.")
|
42
|
+
end
|
43
|
+
prop.each do |name, value|
|
44
|
+
name = name.gsub(/_/, "-")
|
45
|
+
next if name == "src"
|
46
|
+
property_name = "background-image-#{name}"
|
47
|
+
body[property_name] = value
|
48
|
+
end
|
49
|
+
body["background-image"] = uri_str
|
50
|
+
:no_element
|
51
|
+
else
|
52
|
+
image
|
53
|
+
end
|
37
54
|
end
|
38
55
|
end
|
39
56
|
|
40
|
-
def make_image_from_file(canvas, source)
|
41
|
-
|
57
|
+
def make_image_from_file(canvas, source, extension: nil, **options)
|
58
|
+
src_basename = "rabbit-image-source"
|
59
|
+
src_basename = [src_basename, extension] if extension
|
60
|
+
src_file = Tempfile.new(src_basename)
|
42
61
|
src_file.open
|
43
62
|
src_file.print(source)
|
44
63
|
src_file.close
|
45
64
|
image_file = prop = nil
|
46
65
|
begin
|
47
|
-
image_file, prop = yield(src_file
|
66
|
+
image_file, prop = yield(src_file)
|
48
67
|
rescue ImageLoadError
|
49
68
|
canvas.logger.warn($!.message)
|
50
69
|
end
|
51
70
|
return nil if image_file.nil?
|
52
|
-
image = make_image(canvas,
|
53
|
-
|
54
|
-
|
71
|
+
image = make_image(canvas,
|
72
|
+
"file://#{image_file.path}",
|
73
|
+
prop,
|
74
|
+
**options)
|
75
|
+
# Protect image from GC
|
76
|
+
case image
|
77
|
+
when Element::Image
|
78
|
+
image["_src"] = image_file
|
79
|
+
when :no_element
|
80
|
+
options[:body]["_background-image-src"] = image_file
|
81
|
+
end
|
55
82
|
image
|
56
83
|
end
|
57
84
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2012-
|
1
|
+
# Copyright (C) 2012-2022 Sutou Kouhei <kou@cozmixng.org>
|
2
2
|
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
@@ -20,8 +20,8 @@ require "rabbit/gettext"
|
|
20
20
|
require "rabbit/parser/pause-support"
|
21
21
|
require "rabbit/parser/ext/blockdiag"
|
22
22
|
require "rabbit/parser/ext/escape"
|
23
|
-
require "rabbit/parser/ext/inline"
|
24
23
|
require "rabbit/parser/ext/image"
|
24
|
+
require "rabbit/parser/ext/inline"
|
25
25
|
require "rabbit/parser/ext/rouge"
|
26
26
|
require "rabbit/parser/ext/tex"
|
27
27
|
|
@@ -165,9 +165,15 @@ module Rabbit
|
|
165
165
|
if child_types == [:img]
|
166
166
|
convert_container(element)[0]
|
167
167
|
else
|
168
|
-
if child_types.
|
168
|
+
if child_types.count(:img) > 1
|
169
169
|
raise ParseError,
|
170
|
-
|
170
|
+
_("multiple ![alt]{image}s in a paragraph isn't supported.")
|
171
|
+
end
|
172
|
+
if child_types.include?(:img)
|
173
|
+
message =
|
174
|
+
_("![alt]{image} and other contents in a paragraph " \
|
175
|
+
"isn't supported: %{types}")
|
176
|
+
raise ParseError, message % {types: child_types}
|
171
177
|
end
|
172
178
|
if element.options[:transparent] and child_types == [:text]
|
173
179
|
element.children.first.value.chomp!
|
@@ -325,12 +331,14 @@ module Rabbit
|
|
325
331
|
def convert_codeblock_language(element, language, content)
|
326
332
|
case language
|
327
333
|
when "blockdiag"
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
+
make_image_from_file(element, content) do |src_file, prop|
|
335
|
+
Ext::BlockDiag.make_image(src_file.path, prop, @canvas)
|
336
|
+
end
|
337
|
+
when "mermaid"
|
338
|
+
make_image_from_file(element,
|
339
|
+
content,
|
340
|
+
extension: ".mmd") do |src_file, prop|
|
341
|
+
src_file
|
334
342
|
end
|
335
343
|
else
|
336
344
|
logger = @canvas.logger
|
@@ -349,23 +357,11 @@ module Rabbit
|
|
349
357
|
alt = options.delete("alt")
|
350
358
|
caption = title || alt
|
351
359
|
options["caption"] ||= caption if caption
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
"isn't supported.")
|
358
|
-
end
|
359
|
-
body["background-image"] = uri
|
360
|
-
options.each do |name, value|
|
361
|
-
name = name.to_s.gsub(/_/, "-")
|
362
|
-
body["background-image-#{name}"] = value
|
363
|
-
end
|
364
|
-
:no_element
|
365
|
-
else
|
366
|
-
image = Ext::Image.make_image(@canvas, uri, options)
|
367
|
-
image || text(alt || src)
|
368
|
-
end
|
360
|
+
image = Ext::Image.make_image(@canvas,
|
361
|
+
uri,
|
362
|
+
options,
|
363
|
+
body: @slides.last.body)
|
364
|
+
image || text(alt || src)
|
369
365
|
end
|
370
366
|
|
371
367
|
def convert_em(element)
|
@@ -376,10 +372,20 @@ module Rabbit
|
|
376
372
|
Emphasis.new(Emphasis.new(convert_container(element)))
|
377
373
|
end
|
378
374
|
|
375
|
+
def make_image_from_file(element, source, **options)
|
376
|
+
Ext::Image.make_image_from_file(@canvas,
|
377
|
+
source,
|
378
|
+
body: @slides.last.body,
|
379
|
+
**options) do |src_file|
|
380
|
+
prop = element.attr
|
381
|
+
image = yield(src_file, prop)
|
382
|
+
[image, prop]
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
379
386
|
def convert_math(element)
|
380
|
-
|
381
|
-
|
382
|
-
[Ext::TeX.make_image_by_LaTeX(src_file_path, {}, @canvas), {}]
|
387
|
+
make_image_from_file(element, element.value) do |src_file, prop|
|
388
|
+
Ext::TeX.make_image_by_LaTeX(src_file.path, prop, @canvas)
|
383
389
|
end
|
384
390
|
end
|
385
391
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2004-
|
1
|
+
# Copyright (C) 2004-2022 Sutou Kouhei <kou@cozmixng.org>
|
2
2
|
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
@@ -22,14 +22,14 @@ require "rabbit/parser/rd/rt/rt2rabbit-lib"
|
|
22
22
|
require "rabbit/parser/rd/ext/base"
|
23
23
|
require "rabbit/parser/rd/ext/image"
|
24
24
|
require "rabbit/parser/rd/ext/video"
|
25
|
-
require "rabbit/parser/ext/enscript"
|
26
|
-
require "rabbit/parser/ext/tex"
|
27
25
|
require "rabbit/parser/ext/aafigure"
|
28
26
|
require "rabbit/parser/ext/blockdiag"
|
29
27
|
require "rabbit/parser/ext/charty"
|
30
28
|
require "rabbit/parser/ext/coderay"
|
31
29
|
require "rabbit/parser/ext/emacs"
|
30
|
+
require "rabbit/parser/ext/enscript"
|
32
31
|
require "rabbit/parser/ext/rouge"
|
32
|
+
require "rabbit/parser/ext/tex"
|
33
33
|
|
34
34
|
module Rabbit
|
35
35
|
module Parser
|
@@ -55,26 +55,7 @@ module Rabbit
|
|
55
55
|
return nil unless /\A(?:image|img)\z/i =~ label
|
56
56
|
src, prop = parse_source(source)
|
57
57
|
return nil if prop["src"].nil?
|
58
|
-
|
59
|
-
if prop["align"] == "right"
|
60
|
-
body = visitor.current_body
|
61
|
-
if body["background-image"]
|
62
|
-
raise ParseError,
|
63
|
-
_("multiple 'align = right' isn't supported.")
|
64
|
-
end
|
65
|
-
prop.each do |name, value|
|
66
|
-
name = name.gsub(/_/, "-")
|
67
|
-
if name == "src"
|
68
|
-
property_name = "background-image"
|
69
|
-
else
|
70
|
-
property_name = "background-image-#{name}"
|
71
|
-
end
|
72
|
-
body[property_name] = value
|
73
|
-
end
|
74
|
-
:no_element
|
75
|
-
else
|
76
|
-
make_image(visitor, prop["src"], prop)
|
77
|
-
end
|
58
|
+
make_image(visitor, prop["src"], prop, body: visitor.current_body)
|
78
59
|
end
|
79
60
|
|
80
61
|
def ext_block_verb_video(label, source, content, visitor)
|
@@ -101,30 +82,30 @@ module Rabbit
|
|
101
82
|
|
102
83
|
def ext_block_verb_LaTeX(label, source, content, visitor)
|
103
84
|
return nil unless /\ALaTeX\z/i =~ label
|
104
|
-
make_image_from_file(source, visitor) do |
|
105
|
-
Parser::Ext::TeX.make_image_by_LaTeX(
|
85
|
+
make_image_from_file(source, visitor) do |src_file, prop|
|
86
|
+
Parser::Ext::TeX.make_image_by_LaTeX(src_file.path, prop, visitor)
|
106
87
|
end
|
107
88
|
end
|
108
89
|
|
109
90
|
def ext_block_verb_mimeTeX(label, source, content, visitor)
|
110
91
|
return nil unless /\AmimeTeX\z/i =~ label
|
111
|
-
make_image_from_file(source, visitor) do |
|
112
|
-
Parser::Ext::TeX.make_image_by_mimeTeX(
|
92
|
+
make_image_from_file(source, visitor) do |src_file, prop|
|
93
|
+
Parser::Ext::TeX.make_image_by_mimeTeX(src_file.path, prop,
|
113
94
|
visitor)
|
114
95
|
end
|
115
96
|
end
|
116
97
|
|
117
98
|
def ext_block_verb_aafigure(label, source, content, visitor)
|
118
99
|
return nil unless /\Aaafigure\z/i =~ label
|
119
|
-
make_image_from_file(source, visitor) do |
|
120
|
-
Parser::Ext::AAFigure.make_image(
|
100
|
+
make_image_from_file(source, visitor) do |src_file, prop|
|
101
|
+
Parser::Ext::AAFigure.make_image(src_file.path, prop, visitor)
|
121
102
|
end
|
122
103
|
end
|
123
104
|
|
124
105
|
def ext_block_verb_blockdiag(label, source, content, visitor)
|
125
106
|
return nil unless /\Ablockdiag\z/i =~ label
|
126
|
-
make_image_from_file(source, visitor) do |
|
127
|
-
Parser::Ext::BlockDiag.make_image(
|
107
|
+
make_image_from_file(source, visitor) do |src_file, prop|
|
108
|
+
Parser::Ext::BlockDiag.make_image(src_file.path, prop, visitor)
|
128
109
|
end
|
129
110
|
end
|
130
111
|
|
@@ -205,8 +186,17 @@ module Rabbit
|
|
205
186
|
|
206
187
|
def ext_block_verb_charty(label, source, content, visitor)
|
207
188
|
return nil unless /\Acharty\z/i =~ label
|
208
|
-
make_image_from_file(source, visitor) do |
|
209
|
-
Parser::Ext::Charty.make_image(
|
189
|
+
make_image_from_file(source, visitor) do |src_file, prop|
|
190
|
+
Parser::Ext::Charty.make_image(src_file.path, prop, visitor)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def ext_block_verb_mermaid(label, source, content, visitor)
|
195
|
+
return nil unless /\Amermaid\z/i =~ label
|
196
|
+
make_image_from_file(source,
|
197
|
+
visitor,
|
198
|
+
extension: ".mmd") do |src_file, prop|
|
199
|
+
src_file
|
210
200
|
end
|
211
201
|
end
|
212
202
|
end
|