2022-08-28 18:56:24 +02:00
|
|
|
def add_sidenotes(html: str,
|
|
|
|
toggle_class: str = "sidenote-toggle",
|
2023-10-24 14:19:59 +02:00
|
|
|
label_class: str = "sidenote-number") -> str:
|
2022-08-28 18:56:24 +02:00
|
|
|
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" +\
|
2023-10-24 14:19:59 +02:00
|
|
|
f"<span class=\"sidenote\">\n" +\
|
2022-08-28 18:56:24 +02:00
|
|
|
f" {text}\n" +\
|
|
|
|
f"</span>\n"
|
|
|
|
html = html[:start] + sidenote + html[end + 1:]
|
|
|
|
start = html.find("[°", start + len(sidenote))
|
|
|
|
return html
|