From 23871d5aadcaa4d01b7c46cb951854572940414d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 2 Oct 2025 19:14:17 +0200 Subject: Rewrite --- process.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 process.py (limited to 'process.py') diff --git a/process.py b/process.py new file mode 100644 index 0000000..1c84810 --- /dev/null +++ b/process.py @@ -0,0 +1,29 @@ +import re +from sys import argv +from os import popen +from markdown import markdown +import subprocess + +PROCESSORS = { + "ex": lambda c: popen(c).read(), + "exmd": lambda c: markdown(popen(c).read()) +} + +def run_pi(input: str) -> str: + RE_PI = r"(?sm)\<\?(?P\w+)\W(?P.*)\?\>" + def run_pi_match(m: re.Match): + name = m.group("name") + body = m.group("body") + output = PROCESSORS[name](body) + return output + return re.sub(RE_PI, run_pi_match, input) + +def template(input: str) -> str: + tpl = open("template.html", "r").read() + return tpl.replace("CONTENT", input).replace("TITLE", "TODO TITLE") + +doc = open(argv[1], "r").read() +doc = markdown(doc) +doc = template(doc) +doc = run_pi(doc) +open(argv[2], "w+").write(doc) -- cgit v1.2.3-70-g09d2