From 5a009cb91f48fcbd43e89245ef58ec3109d5b2b2 Mon Sep 17 00:00:00 2001 From: Chris Fenner Date: Sun, 3 Mar 2024 17:44:09 +0900 Subject: [PATCH] support drawio.svg --- filter/convert-images.lua | 24 +++++++++++++++++------- guide.tcg | 4 ++-- sample.drawio | 28 ---------------------------- sample.drawio.svg | 1 + 4 files changed, 20 insertions(+), 37 deletions(-) delete mode 100644 sample.drawio create mode 100644 sample.drawio.svg diff --git a/filter/convert-images.lua b/filter/convert-images.lua index 3298d22..fc90e53 100644 --- a/filter/convert-images.lua +++ b/filter/convert-images.lua @@ -58,34 +58,44 @@ function imagemagick(source, dest) end local converters = { + ['.drawio'] = drawio, + ['.drawio.svg'] = drawio, ['.jpg'] = imagemagick, ['.png'] = imagemagick, - ['.svg'] = imagemagick, - ['.drawio'] = drawio + ['.svg'] = imagemagick } function string:hassuffix(suffix) return self:sub(-#suffix) == suffix end +function converterFor(filename) + for suffix, handler in pairs(converters) do + if filename:hassuffix(suffix) then + return handler + end + end + return nil +end + function Image (img) -- Try to convert anything that is not a pdf, jpg, or png. -- This allows us to support file types that latex doesn't (e.g., SVG), -- as well as speed up the latex render iterations. - local file_ext = img.src:match("^.+(%..+)$") - if file_ext and converters[file_ext] then + local converter = converterFor(img.src) + if converter then local new_filename = img.src .. '.' .. getFileHash(img.src) .. '.convert.pdf' if fileExists(new_filename) then print(string.format(" not converting %s (already up-to-date as %s)", img.src, new_filename)) img.src = new_filename - elseif converters[file_ext](img.src, new_filename) then + elseif converter(img.src, new_filename) then print(string.format(" converted %s to %s", img.src, new_filename)) -- Delete stale copies of this file. This makes it easier to cache only the latest converted pdfs deleteFilesExcept(img.src .. ".*.convert.pdf", new_filename) img.src = new_filename end - elseif file_ext ~= ".pdf" then - print(string.format(" not converting %s (extension %s)", img.src, file_ext)) + else + print(string.format(" not converting %s", img.src)) end return img end \ No newline at end of file diff --git a/guide.tcg b/guide.tcg index 67d4e22..a49a1f5 100644 --- a/guide.tcg +++ b/guide.tcg @@ -650,10 +650,10 @@ diagrams. There is a Visual Studio Code extension for it. Check in and add draw.io diagrams to your document like in @fig:sample-drawio: ```md -![Sample DrawIO Diagram](sample.drawio){#fig:sample-drawio width=50%} +![Sample DrawIO Diagram](sample.drawio.svg){#fig:sample-drawio width=50%} ``` -![Sample DrawIO Diagram](sample.drawio){#fig:sample-drawio width=50%} +![Sample DrawIO Diagram](sample.drawio.svg){#fig:sample-drawio width=50%} # Tables {#sec:tables} diff --git a/sample.drawio b/sample.drawio deleted file mode 100644 index 59f5277..0000000 --- a/sample.drawio +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample.drawio.svg b/sample.drawio.svg new file mode 100644 index 0000000..addc3f4 --- /dev/null +++ b/sample.drawio.svg @@ -0,0 +1 @@ +
Process?
Process?
DB
DB
Test
  1. One
  2. Two
  3. Three
Test...
Text
Text
Text is not SVG - cannot display
\ No newline at end of file