Produces a safe HTML id attribute value from a raw entity name.
Unlike sanitize_filename_slug, this targets HTML id semantics, not
filesystem safety: a primary template’s display name carries its formal
parameter list with literal </>/whitespace (e.g.
"MockExchangeTraits< kMock2Ifc >") – valid inside a
double-quoted HTML attribute per spec, but the whitespace and angle
brackets break #id-style CSS/JS selectors and anchor-link ergonomics.
Collapses any run of characters outside [A-Za-z0-9_-] to a single
underscore, trims leading/trailing underscores, and falls back to a
literal “_” for an empty/all-punctuation input so the id is never blank.
Methods
sanitize_html_id
sanitize_html_id(value: str) -> str
Produces a safe HTML id attribute value from a raw entity name.
Unlike sanitize_filename_slug, this targets HTML id semantics, not
filesystem safety: a primary template’s display name carries its formal
parameter list with literal </>/whitespace (e.g.
"MockExchangeTraits< kMock2Ifc >") – valid inside a
double-quoted HTML attribute per spec, but the whitespace and angle
brackets break #id-style CSS/JS selectors and anchor-link ergonomics.
Collapses any run of characters outside [A-Za-z0-9_-] to a single
underscore, trims leading/trailing underscores, and falls back to a
literal “_” for an empty/all-punctuation input so the id is never blank.
| Parameter | Type | Description |
|---|---|---|
| value | str |
Generated with Flude
Copyright © 2026