From 1cbb2a40c886603a2e2ccc883179cc2d196280e1 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 11 May 2025 21:38:22 -0600 Subject: make rules in html linkable --- scripts/prepare_html_rules.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 scripts/prepare_html_rules.py (limited to 'scripts') diff --git a/scripts/prepare_html_rules.py b/scripts/prepare_html_rules.py new file mode 100755 index 00000000..4d533bec --- /dev/null +++ b/scripts/prepare_html_rules.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# TODO: support nested lists + +import sys +import re + +def add_ids(ol): + """add ids to all li""" + id = "" + for s in ol.previous_siblings: + if not s.name: + continue + if s.name.startswith("h"): + id = s.attrs["data-number"] + break + + for i, li in enumerate(ol.find_all("li")): + li["id"] = f"{id}-{i+1}" + li["class"] = "rule" + +header_re = re.compile(r' str: + m = data_number_re.search(line) + if m: + return m.group(1) + else: + return "" + +headline = "" +i = 0 +for line in sys.stdin.readlines(): + if header_re.match(line): + headline = extract_headline_nr(line) + h_idx = line.find('