fix layout option & check sourcefile exists
This commit is contained in:
parent
2143498418
commit
c89985ec09
1 changed files with 7 additions and 2 deletions
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue