summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--main.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..056c9c5
--- /dev/null
+++ b/main.py
@@ -0,0 +1,43 @@
+import sys
+import markdown
+from string import Template
+
+txt = str(sys.stdin.read())
+md = markdown.Markdown(extensions=["meta", "fenced_code"])
+
+html_string = md.convert(txt)
+document_template = Template("""<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8"/>
+$title_heading
+$meta_heading
+<meta name="viewport" content="width=device-width,initial-scale=1"/>
+</head>
+<body>
+$body_text
+</body>
+</html>""")
+
+title_heading = """<title>{}</title>"""
+meta_template = """<meta name="{}" content="{}"/>"""
+
+def getTitle():
+	for key, value in md.Meta.items():
+		if key == "title":
+			return str(*value)
+
+my_title = getTitle()
+my_title_headings = title_heading.format(my_title)
+my_meta_heading_content = []
+def getMetaHeadings():
+	for key, value in md.Meta.items():
+		if key != "title":
+			my_meta_heading_content.append(
+			meta_template.format(key, str(*value))
+			)
+
+getMetaHeadings()
+
+print(document_template.substitute(title_heading=my_title_headings, meta_heading="\n".join(my_meta_heading_content), body_text=html_string))
+