Files
md_to_gost/md2fodt/escape.py
T
Igor20264 516abe7b83
Python application / build (push) Has been cancelled
BigUpdate
2026-09-03 10:44:08 +03:00

23 lines
512 B
Python

"""XML escape helpers for FODT output."""
from __future__ import annotations
import re
from xml.sax.saxutils import escape as _xml_escape
def escape_text(s: str) -> str:
if not s:
return ""
return _xml_escape(s, {"\"": """, "'": "'"})
_LABEL_RE = re.compile(r"[^\w\-]+", re.UNICODE)
def xml_id(name: str | None, prefix: str = "obj") -> str:
if not name:
return prefix
cleaned = _LABEL_RE.sub("-", name.strip()).strip("-")
return f"{prefix}-{cleaned or 'x'}"