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
|
from shutil import which
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
class D2langDirective(Directive):
|
class D2langDirective(Directive):
|
||||||
has_content = True
|
has_content = True
|
||||||
def run(self):
|
def run(self):
|
||||||
# TODO : add tempfile for diag_source
|
# TODO : add tempfile for diag_source
|
||||||
|
d2_bin = which('d2')
|
||||||
outdir = self.state.document.settings.env.app.builder.outdir
|
outdir = self.state.document.settings.env.app.builder.outdir
|
||||||
srcdir = self.state.document.settings.env.srcdir
|
srcdir = self.state.document.settings.env.srcdir
|
||||||
diag_source = self.content
|
diag_source = self.content
|
||||||
d2_bin = which('d2')
|
with tempfile.NamedTemporaryFile() as fp:
|
||||||
cmd_line = 'echo "%s" | %s - %s' % (diag_source, d2_bin, srcdir + "/test.svg")
|
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)
|
args = shlex.split(cmd_line)
|
||||||
subprocess.run(args)
|
subprocess.run(args)
|
||||||
image_node = nodes.image(uri="/test.svg")
|
image_node = nodes.image(uri="/test.svg")
|
||||||
|
|
Loading…
Reference in a new issue