Skip to content

Commit

Permalink
Added off-line renderer that invokes dot.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed Jan 7, 2022
1 parent 11c9468 commit 8716432
Show file tree
Hide file tree
Showing 3 changed files with 691 additions and 135 deletions.
24 changes: 21 additions & 3 deletions doc/render.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
#!/usr/bin/env python3

import subprocess
import sys

if len(sys.argv) < 2:
print("Must pass a filename argument")
sys.exit(1)

in_file = sys.argv[1]
out_file = in_file.replace(".in.md", ".md")
in_filename = sys.argv[1]
out_filename = in_filename.replace(".in.md", ".md")

if in_file == out_file:
if in_filename == out_filename:
print("File must end in .in.md")
sys.exit(1)

with open(out_filename, "wb") as out_file, open(in_filename, "rb") as in_file:
for line in in_file:
if line.startswith(b"```dot"):
dot_lines = []
while True:
dot_line = next(in_file)
if dot_line == b"```\n":
break
dot_lines.append(dot_line)
dot_input = b"".join(dot_lines)
svg = subprocess.check_output(['dot', '-Tsvg'], input=dot_input)
out_file.write(b"<div align=center>")
out_file.write(svg)
out_file.write(b"</div>")
else:
out_file.write(line)
Loading

0 comments on commit 8716432

Please sign in to comment.