Skip to content

Commit 5a009cb

Browse files
committed
support drawio.svg
1 parent 951beec commit 5a009cb

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

filter/convert-images.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,44 @@ function imagemagick(source, dest)
5858
end
5959

6060
local converters = {
61+
['.drawio'] = drawio,
62+
['.drawio.svg'] = drawio,
6163
['.jpg'] = imagemagick,
6264
['.png'] = imagemagick,
63-
['.svg'] = imagemagick,
64-
['.drawio'] = drawio
65+
['.svg'] = imagemagick
6566
}
6667

6768
function string:hassuffix(suffix)
6869
return self:sub(-#suffix) == suffix
6970
end
7071

72+
function converterFor(filename)
73+
for suffix, handler in pairs(converters) do
74+
if filename:hassuffix(suffix) then
75+
return handler
76+
end
77+
end
78+
return nil
79+
end
80+
7181
function Image (img)
7282
-- Try to convert anything that is not a pdf, jpg, or png.
7383
-- This allows us to support file types that latex doesn't (e.g., SVG),
7484
-- as well as speed up the latex render iterations.
75-
local file_ext = img.src:match("^.+(%..+)$")
76-
if file_ext and converters[file_ext] then
85+
local converter = converterFor(img.src)
86+
if converter then
7787
local new_filename = img.src .. '.' .. getFileHash(img.src) .. '.convert.pdf'
7888
if fileExists(new_filename) then
7989
print(string.format(" not converting %s (already up-to-date as %s)", img.src, new_filename))
8090
img.src = new_filename
81-
elseif converters[file_ext](img.src, new_filename) then
91+
elseif converter(img.src, new_filename) then
8292
print(string.format(" converted %s to %s", img.src, new_filename))
8393
-- Delete stale copies of this file. This makes it easier to cache only the latest converted pdfs
8494
deleteFilesExcept(img.src .. ".*.convert.pdf", new_filename)
8595
img.src = new_filename
8696
end
87-
elseif file_ext ~= ".pdf" then
88-
print(string.format(" not converting %s (extension %s)", img.src, file_ext))
97+
else
98+
print(string.format(" not converting %s", img.src))
8999
end
90100
return img
91101
end

guide.tcg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,10 @@ diagrams. There is a Visual Studio Code extension for it.
650650
Check in and add draw.io diagrams to your document like in @fig:sample-drawio:
651651

652652
```md
653-
![Sample DrawIO Diagram](sample.drawio){#fig:sample-drawio width=50%}
653+
![Sample DrawIO Diagram](sample.drawio.svg){#fig:sample-drawio width=50%}
654654
```
655655

656-
![Sample DrawIO Diagram](sample.drawio){#fig:sample-drawio width=50%}
656+
![Sample DrawIO Diagram](sample.drawio.svg){#fig:sample-drawio width=50%}
657657

658658
# Tables {#sec:tables}
659659

sample.drawio

Lines changed: 0 additions & 28 deletions
This file was deleted.

sample.drawio.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)