MCPcopy Index your code
hub / github.com/reactive-python/reactpy / _vdom_attr_to_html_str

Function _vdom_attr_to_html_str

src/py/reactpy/reactpy/utils.py:266–299  ·  view source on GitHub ↗
(key: str, value: Any)

Source from the content-addressed store, hash-verified

264
265
266def _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:

Callers 1

_add_vdom_to_etreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected