webgen/md2html.py
2023-10-29 13:37:57 +01:00

27 lines
831 B
Python
Executable file

#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Liest markdownfile ein und spuckt html aus: md2html meinmarkdownfile.md
"""
import sys, markdown2 as markdown
markdown.Markdown.extras = ["footnotes", "break-on-newline"]
try:
mdfile = sys.argv[1]
except:
sys.exit("No file, honey.\n" + sys.argv[0] + ": Liest markdownfile ein und spuckt html aus: md2html meinmarkdownfile.md")
headline = mdfile.split(".md")[0]
htmlfilename = headline + ".html"
myhead = "<!DOCTYPE HTML><html><head><title>" + headline + "</title></head><body>"
myfooter = "</body></html>"
with open(mdfile, "r", encoding="utf-8") as datafile:
md = datafile.read()
htmlcontent = markdown.markdown(md, extras=markdown.Markdown.extras)
with open(htmlfilename, "w", encoding="utf-8") as outfile:
outfile.write(myhead + htmlcontent + myfooter)