Files
Igor20264 f7136bd8bd
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled
v0.5.3
- Мелкие исправления увеличивающие работу конвертера
2026-09-10 10:50:15 +03:00

21 lines
574 B
Python

"""Cross-reference slugs shared by the export backends."""
from __future__ import annotations
import re
_LABEL_RE = re.compile(r"[^\w\-]+", re.UNICODE)
def sanitize_label(name: str | None, prefix: str = "obj", separator: str = ":") -> str:
"""
Turn a `%id` caption name into a target usable as an anchor.
`separator` differs per backend: LaTeX `\\label` accepts a colon, an
XML `NCName` does not.
"""
if not name:
return prefix
cleaned = _LABEL_RE.sub("-", name.strip()).strip("-")
return f"{prefix}{separator}{cleaned or 'x'}"