use tempfile for d2 source
This commit is contained in:
parent
d2c41c2ae9
commit
9673ccfd83
1 changed files with 6 additions and 2 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue