Inline SVG
This commit is contained in:
parent
82cbcee377
commit
7660b22d28
|
@ -7,3 +7,6 @@ title = "The Synit Manual"
|
|||
|
||||
[preprocessor.ditaa]
|
||||
command = "./mdbook-ditaa figures/ditaa"
|
||||
|
||||
[output.html]
|
||||
additional-css = ["style.css"]
|
||||
|
|
35
mdbook-ditaa
35
mdbook-ditaa
|
@ -65,28 +65,31 @@ def expand_ditaa(m, context, directory):
|
|||
if cached:
|
||||
svg = cached[0][0]
|
||||
else:
|
||||
svg = subprocess.check_output(['ditaa', '--svg', '-'], input=ditaa_source.encode('utf-8'))
|
||||
svg = subprocess.check_output(['ditaa', '-T', '--svg', '-'], input=ditaa_source.encode('utf-8'))
|
||||
svg = svg.decode('utf-8')
|
||||
cache.cursor().execute('INSERT INTO diagrams VALUES (?, ?)', (ditaa_source, svg))
|
||||
cache.cursor().execute('COMMIT')
|
||||
|
||||
svgfilename = os.path.join(sourcedir, output_prefix, filename)
|
||||
os.makedirs(os.path.dirname(svgfilename), exist_ok=True)
|
||||
# svgfilename = os.path.join(sourcedir, output_prefix, filename)
|
||||
# os.makedirs(os.path.dirname(svgfilename), exist_ok=True)
|
||||
|
||||
need_write = True
|
||||
if os.path.exists(svgfilename):
|
||||
with open(svgfilename, 'rt') as f:
|
||||
existing = f.read()
|
||||
if existing == svg:
|
||||
need_write = False
|
||||
if need_write:
|
||||
sys.stderr.write('updated\n')
|
||||
with open(svgfilename, 'wt') as f:
|
||||
f.write(svg)
|
||||
else:
|
||||
sys.stderr.write('unchanged\n')
|
||||
# need_write = True
|
||||
# if os.path.exists(svgfilename):
|
||||
# with open(svgfilename, 'rt') as f:
|
||||
# existing = f.read()
|
||||
# if existing == svg:
|
||||
# need_write = False
|
||||
# if need_write:
|
||||
# sys.stderr.write('updated\n')
|
||||
# with open(svgfilename, 'wt') as f:
|
||||
# f.write(svg)
|
||||
# else:
|
||||
# sys.stderr.write('unchanged\n')
|
||||
|
||||
return f'<p><img class="ditaa" alt="{filename}" src="{os.path.join(baseurl, output_prefix, filename)}"></p>\n'
|
||||
# return f'<p><img class="ditaa" alt="{filename}" src="{os.path.join(baseurl, output_prefix, filename)}"></p>\n'
|
||||
|
||||
sys.stderr.write('inlined\n')
|
||||
return f'<div class="ditaa">{svg}</div>\n'
|
||||
|
||||
def structure(items):
|
||||
answer = []
|
||||
|
|
Loading…
Reference in New Issue