@@ -58,34 +58,44 @@ function imagemagick(source, dest)
5858end
5959
6060local 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
6768function string :hassuffix (suffix )
6869 return self :sub (-# suffix ) == suffix
6970end
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+
7181function 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
91101end
0 commit comments