Created
May 29, 2019 05:50
-
-
Save minoki/344aa8dfa6accd5399de273147ebb19b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local PDF_DIR = ".converted-pdf" | |
os.execute("mkdir -p " .. PDF_DIR) | |
local function file_exists(fn) | |
local f = io.open(fn,"r") | |
if f then | |
f:close() | |
return true | |
else | |
return false | |
end | |
end | |
function Image(elem) | |
-- el.caption, src, title, attr | |
local base = elem.src:match("^(.+)%.svg$") | |
if base ~= nil then | |
local infile = assert(io.open(elem.src,"r")) | |
local svgContents = infile:read("*a") | |
infile:close() | |
local hash = pandoc.sha1(svgContents) | |
local pdfPath = PDF_DIR .. "/" .. hash .. ".pdf" | |
if not file_exists(pdfPath) then | |
io.stderr:write("Running Inkscape: from " .. elem.src .. " to " .. pdfPath .. "\n") | |
os.execute("inkscape --without-gui --export-pdf=" .. pdfPath .. " " .. elem.src) | |
end | |
return pandoc.Image(elem.caption, pdfPath, elem.title, elem.attr) | |
else | |
return elem | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment