from __future__ import annotations from datetime import date, datetime from html import escape from typing import Any def text(value: Any) -> str: if value is None or value == "": return "nicht erfasst" if isinstance(value, (date, datetime)): return value.strftime("%d.%m.%Y") return escape(str(value)) def paragraph(value: Any) -> str: content = text(value) return content.replace("\n", "
") def yes_no(value: Any) -> str: labels = {"yes": "Ja", "no": "Nein", "na": "Nicht zutreffend", True: "Ja", False: "Nein"} return text(labels.get(value, value)) def definition_list(rows: list[tuple[str, Any]]) -> str: items = "".join( f"
{text(label)}
{paragraph(value)}
" for label, value in rows if value not in (None, "", []) ) return f"
{items}
" def table(headers: list[str], rows: list[list[Any]], css_class: str = "") -> str: head = "".join(f"{text(header)}" for header in headers) body = "".join( "" + "".join(f"{paragraph(cell)}" for cell in row) + "" for row in rows ) return f"{head}{body}
" def section(chapter_id: str, title: str, body: str) -> str: return f"

{text(title)}

{body}
"