| 1 | #!/usr/bin/env python3 |
| 2 | """PPT Master SVG quality XML helpers. |
| 3 | |
| 4 | Provides namespace constants and compact element labels shared by quality-check |
| 5 | domains. |
| 6 | |
| 7 | Usage: |
| 8 | Import from ``svg_quality.checker`` or another ``svg_quality`` module. |
| 9 | |
| 10 | Examples: |
| 11 | from svg_quality.xml_support import local_name |
| 12 | |
| 13 | Dependencies: |
| 14 | Standard library only. |
| 15 | """ |
| 16 | |
| 17 | from xml.etree import ElementTree as ET |
| 18 | |
| 19 | SVG_NS = "http://www.w3.org/2000/svg" |
| 20 | XLINK_NS = "http://www.w3.org/1999/xlink" |
| 21 | |
| 22 | |
| 23 | def local_name(elem: ET.Element) -> str: |
| 24 | """Return an XML element's namespace-free local tag name.""" |
| 25 | tag = elem.tag |
| 26 | if not isinstance(tag, str): |
| 27 | return "" |
| 28 | return tag.rsplit("}", 1)[-1] if "}" in tag else tag |
| 29 | |
| 30 | |
| 31 | def element_label(elem: ET.Element) -> str: |
| 32 | """Return a compact element label for validation messages.""" |
| 33 | tag = local_name(elem) |
| 34 | elem_id = (elem.get("id") or "").strip() |
| 35 | return f'<{tag} id="{elem_id}">' if elem_id else f"<{tag}>" |
| 36 |