From 5c92840108a05f0f311d5bef2d6512579b593438 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 3 Oct 2025 23:14:58 +0200 Subject: read title from h1 --- process.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/process.py b/process.py index 6cef2a8..c9db002 100644 --- a/process.py +++ b/process.py @@ -11,18 +11,21 @@ PROCESSORS = { } def run_pi(input: str) -> str: - RE_PI = r"(?sm)\<\?(?P\w+)\W(?P.*?)\?\>" + RE_PI = r"(?sm)<\?(?P\w+)\W(?P.*?)\?>" def run_pi_match(m: re.Match): - name = m.group("n") - body = m.group("b") + name = m.group("name") + body = m.group("body") print(f"({name})$ {body}") output = PROCESSORS[name](body) return output return re.sub(RE_PI, run_pi_match, input) def template(input: str) -> str: + RE_TITLE = r"

(?P.*?)</h1>" + title_match = re.match(RE_TITLE, input) + title = title_match.group(1) if title_match != None else "no title :(" tpl = open("template.html", "r").read() - return tpl.replace("CONTENT", input).replace("TITLE", "TODO TITLE") + return tpl.replace("CONTENT", input).replace("TITLE", title) doc = open(argv[1], "r").read() doc = markdown(doc) -- cgit v1.2.3-70-g09d2