diff options
author | metamuffin <metamuffin@disroot.org> | 2025-10-02 19:14:17 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-10-02 19:14:17 +0200 |
commit | 23871d5aadcaa4d01b7c46cb951854572940414d (patch) | |
tree | 9a3f0490675642a5b76bdda8f44f2e75b469046c /process.py | |
parent | fbc308f96dca2854bc462e6fee412b5dc35b6c3c (diff) | |
download | metamuffin-website-23871d5aadcaa4d01b7c46cb951854572940414d.tar metamuffin-website-23871d5aadcaa4d01b7c46cb951854572940414d.tar.bz2 metamuffin-website-23871d5aadcaa4d01b7c46cb951854572940414d.tar.zst |
Rewrite
Diffstat (limited to 'process.py')
-rw-r--r-- | process.py | 29 |
1 files changed, 29 insertions, 0 deletions
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<name>\w+)\W(?P<body>.*)\?\>" + 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) |