@@ -291,13 +291,43 @@ local cetz = {
291291 end ,
292292}
293293
294+ --- D2 engine for the D2 language
295+ local d2 = {
296+ line_comment_start = ' #' ,
297+ mime_types = mime_types_set {' png' , ' svg' },
298+
299+ compile = function (self , code , user_opts )
300+ return with_temporary_directory (' diagram' , function (tmpdir )
301+ return with_working_directory (tmpdir , function ()
302+ -- D2 format identifiers correspond to common file extensions.
303+ local mime_type = self .mime_type or ' image/svg+xml'
304+ local file_extension = extension_for_mimetype [mime_type ]
305+ local infile = ' diagram.d2'
306+ local outfile = ' diagram.' .. file_extension
307+
308+ args = {' --bundle' , ' --pad=0' , ' --scale=1' }
309+
310+ table.insert (args , infile )
311+ table.insert (args , outfile )
312+
313+ write_file (infile , code )
314+
315+ pipe (self .execpath or ' d2' , args , ' ' )
316+
317+ return read_file (outfile ), mime_type
318+ end )
319+ end )
320+ end ,
321+ }
322+
294323local default_engines = {
295324 asymptote = asymptote ,
296325 dot = graphviz ,
297326 mermaid = mermaid ,
298327 plantuml = plantuml ,
299328 tikz = tikz ,
300329 cetz = cetz ,
330+ d2 = d2 ,
301331}
302332
303333--
0 commit comments