@@ -289,17 +289,6 @@ def _hypen_to_camel_case(string: str) -> str:
289
289
return first .lower () + remainder .title ().replace ("-" , "" )
290
290
291
291
292
- # Pattern for delimitting camelCase names (e.g. camelCase to camel-case)
293
- _CAMEL_CASE_SUB_PATTERN = re .compile (r"(?<!^)(?=[A-Z])" )
294
-
295
- # see list of HTML attributes with dashes in them:
296
- # https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#attribute_list
297
- _CAMEL_TO_DASH_CASE_HTML_ATTRS = {
298
- "acceptCharset" : "accept-charset" ,
299
- "httpEquiv" : "http-equiv" ,
300
- }
301
-
302
-
303
292
def _vdom_attr_to_html_str (key : str , value : Any ) -> tuple [str , str ]:
304
293
if key == "style" :
305
294
if isinstance (value , dict ):
@@ -309,11 +298,15 @@ def _vdom_attr_to_html_str(key: str, value: Any) -> tuple[str, str]:
309
298
f"{ _CAMEL_CASE_SUB_PATTERN .sub ('-' , k ).lower ()} :{ v } "
310
299
for k , v in value .items ()
311
300
)
312
- elif key .startswith ("data" ) or key .startswith ("aria" ):
313
- # Handle data-* attribute names
301
+ elif (
302
+ # camel to data-* attributes
303
+ key .startswith ("data" )
304
+ # camel to aria-* attributes
305
+ or key .startswith ("aria" )
306
+ # handle special cases
307
+ or key in _DASHED_HTML_ATTRS
308
+ ):
314
309
key = _CAMEL_CASE_SUB_PATTERN .sub ("-" , key )
315
- else :
316
- key = _CAMEL_TO_DASH_CASE_HTML_ATTRS .get (key , key )
317
310
318
311
assert not callable (
319
312
value
@@ -322,3 +315,11 @@ def _vdom_attr_to_html_str(key: str, value: Any) -> tuple[str, str]:
322
315
# Again, we lower the attribute name only to normalize - HTML is case-insensitive:
323
316
# http://w3c.github.io/html-reference/documents.html#case-insensitivity
324
317
return key .lower (), str (value )
318
+
319
+
320
+ # Pattern for delimitting camelCase names (e.g. camelCase to camel-case)
321
+ _CAMEL_CASE_SUB_PATTERN = re .compile (r"(?<!^)(?=[A-Z])" )
322
+
323
+ # see list of HTML attributes with dashes in them:
324
+ # https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#attribute_list
325
+ _DASHED_HTML_ATTRS = {"acceptCharset" , "httpEquiv" }
0 commit comments