fix layout option & check sourcefile exists

This commit is contained in:
Milka64 2023-12-11 11:39:50 +01:00
parent 2143498418
commit c89985ec09

View file

@ -4,6 +4,7 @@ from docutils.parsers.rst import Directive, directives
from sphinx.util.docutils import SphinxDirective
from shutil import which
from pathlib import Path
import shlex
import subprocess
import tempfile
@ -24,12 +25,16 @@ class D2langDirective(SphinxDirective):
output_fname = self.options.get('filename')
else:
output_fname = 'test.svg'
if 'layout':
if 'layout' in self.options:
layout = self.options.get('layout')
else:
layout = 'dagre'
if self.arguments:
path = Path(srcdir + self.arguments[0])
if path.is_file():
build_svg(self.arguments[0], srcdir, output_fname, layout)
else:
raise
else:
with tempfile.NamedTemporaryFile() as fp:
for line in self.content.data: