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