undefinedbehavior-website/filters.py
2023-10-24 14:19:59 +02:00

18 lines
809 B
Python

def add_sidenotes(html: str,
toggle_class: str = "sidenote-toggle",
label_class: str = "sidenote-number") -> str:
counter: int = 0
start: int = html.find("")
while start > -1:
counter += 1
end: int = html.find("]", start)
text: str = html[start + 2:end]
sidenote: str = f"<label for=\"sn-{counter}\" class=\"{toggle_class} {label_class}\"></label>\n" +\
f"<input type=\"checkbox\" id=\"sn-{counter}\" class=\"{toggle_class}\" />\n" +\
f"<span class=\"sidenote\">\n" +\
f" {text}\n" +\
f"</span>\n"
html = html[:start] + sidenote + html[end + 1:]
start = html.find("", start + len(sidenote))
return html