from docutils import nodes from docutils.parsers.rst import Directive from shutil import which import shlex import subprocess class D2langDirective(Directive): has_content = True def run(self): # TODO : add tempfile for diag_source outdir = self.state.document.settings.env.app.builder.outdir diag_source = self.content d2_bin = which('d2') cmd_line = "echo %s | %s - %s" % (diag_source, d2_bin, outdir + "/test.svg") args = shlex.split(cmd_line) subprocess.run(args) image_node = nodes.image(uri="/test.svg") return [image_node]