1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

Convert without temporary file

This commit is contained in:
Unrud 2021-03-23 00:12:42 +01:00
parent 86a8e3dbfd
commit d14688107e

View file

@ -23,6 +23,7 @@ GIT_CONFIG = {"protocol.version": "2",
COMMIT_MESSAGE = "Generate documentation" COMMIT_MESSAGE = "Generate documentation"
DOCUMENTATION_SRC = "DOCUMENTATION.md" DOCUMENTATION_SRC = "DOCUMENTATION.md"
SHIFT_HEADING = 1 SHIFT_HEADING = 1
TOC_DEPTH = 3
TOOLS_PATH = os.path.dirname(__file__) TOOLS_PATH = os.path.dirname(__file__)
TEMPLATE_INDEX_PATH = os.path.join(TOOLS_PATH, "template-index.html") TEMPLATE_INDEX_PATH = os.path.join(TOOLS_PATH, "template-index.html")
TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template.html") TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template.html")
@ -37,27 +38,25 @@ BRANCH_ORDERING = [ # Format: (REGEX, ORDER, DEFAULT)
def convert_doc(src_path, to_path, branch, branches): def convert_doc(src_path, to_path, branch, branches):
subprocess.run([ raw_html = subprocess.run([
PANDOC_EXE, PANDOC_EXE,
"--from=gfm", "--from=gfm",
"--to=html5", "--to=html5",
os.path.abspath(src_path), os.path.abspath(src_path),
"--toc", "--toc",
"--template=%s" % os.path.basename(TEMPLATE_PATH), "--template=%s" % os.path.basename(TEMPLATE_PATH),
"--output=%s" % os.path.abspath(to_path),
"--section-divs", "--section-divs",
"--shift-heading-level-by=%d" % SHIFT_HEADING, "--shift-heading-level-by=%d" % SHIFT_HEADING,
"--toc-depth=4", "--toc-depth=%d" % (TOC_DEPTH+SHIFT_HEADING),
"--filter=%s" % os.path.abspath(FILTER_EXE), "--filter=%s" % os.path.abspath(FILTER_EXE),
"--variable=branch=%s" % branch, "--variable=branch=%s" % branch,
*("--variable=branches=%s" % b for b in branches)], *("--variable=branches=%s" % b for b in branches)],
check=True, cwd=os.path.dirname(TEMPLATE_PATH)) cwd=os.path.dirname(TEMPLATE_PATH),
with open(to_path, "rb+") as f:
data = subprocess.run([POSTPROCESSOR_EXE], input=f.read(),
stdout=subprocess.PIPE, check=True).stdout stdout=subprocess.PIPE, check=True).stdout
f.seek(0) raw_html = subprocess.run([POSTPROCESSOR_EXE], input=raw_html,
f.truncate() stdout=subprocess.PIPE, check=True).stdout
f.write(data) with open(to_path, "wb") as f:
f.write(raw_html)
def install_dependencies(): def install_dependencies():