(key: str, value: Any)
| 264 | |
| 265 | |
| 266 | def _vdom_attr_to_html_str(key: str, value: Any) -> tuple[str, str]: |
| 267 | if key == "style": |
| 268 | if isinstance(value, dict): |
| 269 | value = ";".join( |
| 270 | # We lower only to normalize - CSS is case-insensitive: |
| 271 | # https://www.w3.org/TR/css-fonts-3/#font-family-casing |
| 272 | f"{_CAMEL_CASE_SUB_PATTERN.sub('-', k).lower()}:{v}" |
| 273 | for k, v in value.items() |
| 274 | ) |
| 275 | elif ( |
| 276 | # camel to data-* attributes |
| 277 | key.startswith("data_") |
| 278 | # camel to aria-* attributes |
| 279 | or key.startswith("aria_") |
| 280 | # handle special cases |
| 281 | or key in DASHED_HTML_ATTRS |
| 282 | ): |
| 283 | key = key.replace("_", "-") |
| 284 | elif ( |
| 285 | # camel to data-* attributes |
| 286 | key.startswith("data") |
| 287 | # camel to aria-* attributes |
| 288 | or key.startswith("aria") |
| 289 | # handle special cases |
| 290 | or key in DASHED_HTML_ATTRS |
| 291 | ): |
| 292 | key = _CAMEL_CASE_SUB_PATTERN.sub("-", key) |
| 293 | |
| 294 | if callable(value): # nocov |
| 295 | raise TypeError(f"Cannot convert callable attribute {key}={value} to HTML") |
| 296 | |
| 297 | # Again, we lower the attribute name only to normalize - HTML is case-insensitive: |
| 298 | # http://w3c.github.io/html-reference/documents.html#case-insensitivity |
| 299 | return key.lower(), str(value) |
| 300 | |
| 301 | |
| 302 | # see list of HTML attributes with dashes in them: |
no outgoing calls
no test coverage detected