Created
April 20, 2019 16:17
-
-
Save Yepoleb/53f8ead3b0f43cbd4cf93565df75b54b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import mistune | |
import sys | |
import os.path | |
import tempfile | |
import subprocess | |
XSL_PATH = os.path.expanduser("~/Coden/xml/outline-tmpl.xsl") | |
TEMPLATE = \ | |
"""<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>{title}</title> | |
<style> | |
body {{ | |
font-family: Ubuntu; | |
}} | |
</style> | |
</head> | |
<body> | |
{content} | |
</body> | |
</html> | |
""" | |
filename_md = sys.argv[1] | |
filebase = os.path.splitext(filename_md)[0] | |
filename_pdf = filebase + ".pdf" | |
with open(filename_md, "r") as md_file: | |
md_cont = md_file.read() | |
html_cont = mistune.markdown(md_cont) | |
html_data = TEMPLATE.format(title=filebase, content=html_cont) | |
with tempfile.NamedTemporaryFile("w", suffix=".html") as html_file: | |
html_file.write(html_data) | |
html_file.flush() | |
subprocess.run([ | |
"wkhtmltopdf", | |
"toc", "--xsl-style-sheet", XSL_PATH, | |
html_file.name, filename_pdf]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment