summaryrefslogtreecommitdiff
path: root/process.py
diff options
context:
space:
mode:
Diffstat (limited to 'process.py')
-rw-r--r--process.py29
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)