From d8807859cff045c40c0ca0aaedd40b077bc6f178 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sun, 3 Sep 2023 09:17:09 +0200 Subject: [PATCH] HTML helper: add boilerplate code to every file --- html_resources/{md2htmlbody.py => md2htmlhelper.py} | 11 +++++++++++ 1 file changed, 11 insertions(+) rename html_resources/{md2htmlbody.py => md2htmlhelper.py} (84%) diff --git a/html_resources/md2htmlbody.py b/html_resources/md2htmlhelper.py similarity index 84% rename from html_resources/md2htmlbody.py rename to html_resources/md2htmlhelper.py index 59fd13e..84c2766 100755 --- a/html_resources/md2htmlbody.py +++ b/html_resources/md2htmlhelper.py @@ -36,8 +36,15 @@ if os.path.isfile(sys.argv[2]): print("Refusing to operate.") sys.exit(2) + +chapter_name = input("Chapter name: ") +template_file = open("html_resources/template.html", "r") +template_lines = template_file.readlines(); +template_lines[0].replace("Chapter Name", chapter_name) + source_file = open(sys.argv[1], "r", encoding="utf-8") destination_file = open(sys.argv[2], "w", encoding="ascii") +destination_file.write(template_lines[0]) element_type="" next_source_line = source_file.readline() @@ -63,3 +70,7 @@ while not next_source_line=="": if next_source_line=="" and not element_type=="": #TODO: deal with closing nested elements destination_file.write("\n") + +destination_file.write(template_lines[1]) +source_file.close() +destination_file.close()