From e189c78748d094366f21814a438fec8dfd72e16b Mon Sep 17 00:00:00 2001 From: Milka64 Date: Sun, 10 Dec 2023 09:03:13 +0100 Subject: [PATCH] add d2 command --- sphinx_d2lang/d2lang.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sphinx_d2lang/d2lang.py b/sphinx_d2lang/d2lang.py index 2e70078..9ac8ae3 100644 --- a/sphinx_d2lang/d2lang.py +++ b/sphinx_d2lang/d2lang.py @@ -2,7 +2,16 @@ from docutils import nodes from docutils.parsers.rst import Directive +from shutils import which +import shlex + class D2langDirective(Directive): + has_content = True def run(self): + diag_source = self.content + d2_bin = which('d2') + cmd_line = "echo %s | %s - %s" % (diag_source, d2_bin, "/tmp/test.svg") + args = shlex.split(cmd_line) + subprocess.run(args) paragraph_node = nodes.paragraph(text="""BobBobAliceAlicehello""") return [paragraph_node]