2023-12-10 08:07:10 +01:00
|
|
|
from docutils import nodes
|
|
|
|
|
|
|
|
from docutils.parsers.rst import Directive
|
|
|
|
|
2023-12-10 09:04:28 +01:00
|
|
|
from shutil import which
|
2023-12-10 09:03:13 +01:00
|
|
|
import shlex
|
2023-12-10 09:05:27 +01:00
|
|
|
import subprocess
|
2023-12-10 09:03:13 +01:00
|
|
|
|
2023-12-09 23:11:43 +01:00
|
|
|
class D2langDirective(Directive):
|
2023-12-10 09:03:13 +01:00
|
|
|
has_content = True
|
2023-12-09 23:11:43 +01:00
|
|
|
def run(self):
|
2023-12-10 21:32:38 +01:00
|
|
|
# TODO : add tempfile for diag_source
|
|
|
|
outdir = self.state.document.settings.env.app.builder.outdir
|
2023-12-10 21:41:35 +01:00
|
|
|
srcdir = self.state.document.settings.env.srcdir
|
2023-12-10 09:03:13 +01:00
|
|
|
diag_source = self.content
|
|
|
|
d2_bin = which('d2')
|
2023-12-10 21:44:48 +01:00
|
|
|
cmd_line = 'echo "%s" | %s - %s' % (diag_source, d2_bin, srcdir + "/test.svg")
|
2023-12-10 09:03:13 +01:00
|
|
|
args = shlex.split(cmd_line)
|
|
|
|
subprocess.run(args)
|
2023-12-10 21:39:08 +01:00
|
|
|
image_node = nodes.image(uri="/test.svg")
|
2023-12-10 21:32:38 +01:00
|
|
|
return [image_node]
|