diff --git a/sphinx_d2lang/d2lang.py b/sphinx_d2lang/d2lang.py index 6a6d7bb..e7e65d5 100644 --- a/sphinx_d2lang/d2lang.py +++ b/sphinx_d2lang/d2lang.py @@ -5,16 +5,20 @@ from docutils.parsers.rst import Directive from shutil import which import shlex import subprocess +import tempfile class D2langDirective(Directive): has_content = True def run(self): # TODO : add tempfile for diag_source + d2_bin = which('d2') outdir = self.state.document.settings.env.app.builder.outdir srcdir = self.state.document.settings.env.srcdir diag_source = self.content - d2_bin = which('d2') - cmd_line = 'echo "%s" | %s - %s' % (diag_source, d2_bin, srcdir + "/test.svg") + with tempfile.NamedTemporaryFile() as fp: + for line in self.content: + fp.write(line) + cmd_line = '%s %s %s' % (d2_bin, fp.name, srcdir + "/test.svg") args = shlex.split(cmd_line) subprocess.run(args) image_node = nodes.image(uri="/test.svg")