From 85a242f098af335c66365029639b371a4837e190 Mon Sep 17 00:00:00 2001 From: My Dear Diary Date: Wed, 24 Jan 2024 02:40:36 +0000 Subject: initial commit Initial working prototype of simple markdown to html generator with support for meta headings and title headings. --- main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.py 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(""" + + + +$title_heading +$meta_heading + + + +$body_text + +""") + +title_heading = """{}""" +meta_template = """""" + +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)) + -- cgit