From c89985ec0970d537bcfe11ec58663aae1d28444f Mon Sep 17 00:00:00 2001 From: Milka64 Date: Mon, 11 Dec 2023 11:39:50 +0100 Subject: [PATCH] fix layout option & check sourcefile exists --- sphinx_d2lang/d2lang.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sphinx_d2lang/d2lang.py b/sphinx_d2lang/d2lang.py index cb343aa..1588eed 100644 --- a/sphinx_d2lang/d2lang.py +++ b/sphinx_d2lang/d2lang.py @@ -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: - build_svg(self.arguments[0], srcdir, output_fname, layout) + 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: