Merge branch 'main' into feat/improve-reference-counting

This commit is contained in:
Tim Grelka
2026-05-06 10:23:00 +02:00
50 changed files with 1289 additions and 33396 deletions
+30 -1
View File
@@ -1,3 +1,5 @@
import re
from jinja2 import Environment, FileSystemLoader
from mistletoe import HtmlRenderer
@@ -7,6 +9,7 @@ from .document import Document
from .formula import Formula
from .halfwidth_spaces import HalfwidthSpaces
from .include import Include
from .index import Index
from .morse import Morse
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
from .photo import Photo
@@ -71,6 +74,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
Qso,
Include,
Formula,
Index,
*extras,
**kwargs,
)
@@ -95,6 +99,9 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
# Single unified counter for all figure types (pictures, photos, tables)
self.figure_counter = 0
# Keep track of index ids already emitted in this document.
self.index_anchor_ids = set()
def get_reference_label(self, marker: str):
if marker in self.references:
return f"{self.edition}-{self.chapter}.{self.section}.{self.references[marker]}", True
@@ -290,7 +297,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
def render_photo_helper(id, ref, text, number, alt_text):
return f"""
<figure class="photo" id="ref_{ref}" name="{ref}">
<img src="photos/{id}.jpg" alt="{alt_text}">
<img src="photos/{id}.png" alt="{alt_text}">
<figcaption>Abbildung {number}: {text}</figcaption>
</figure>
"""
@@ -345,3 +352,25 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
def render_formula(self, token):
return f"\n$${token.formula}$$\n"
@staticmethod
def _normalize_index_part(value: str) -> str:
normalized = value.strip().lower()
normalized = re.sub(r"\s+", "_", normalized)
normalized = re.sub(r"[^\w]", "_", normalized)
normalized = re.sub(r"_+", "_", normalized).strip("_")
return normalized or "index"
def render_index(self, token):
first = self._normalize_index_part(token.first)
if token.second:
second = self._normalize_index_part(token.second)
span_id = f"index_{first}__{second}"
else:
span_id = f"index_{first}"
if span_id in self.index_anchor_ids:
return ""
self.index_anchor_ids.add(span_id)
return f'<span id="{span_id}" class="index-anchor" aria-hidden="true"></span>'