Leave pre-formatted kwarg attributes as-is#118
Leave pre-formatted kwarg attributes as-is#118gazpachoking wants to merge 1 commit intopelme:mainfrom
Conversation
|
did you consider just passing the dict directly? then it is used directly as-is: >>> print(div({"data-foo__bar": "value"}))
<div data-foo__bar="value"></div> |
|
This is related to the datastar attribute helper again, and it was a workaround for not being able to pass in more than one dict of attributes. I was looking at how fasthtml does it (like this, with unpacked kwargs) and I thought leaving already formatted attributes would be 'the right thing' and decided to raise this PR. Either this or #117 would solve the issue of not being able to use multiple dicts at the moment. I'd probably use #117 way if they both went in, but this PR seemed like it'd also be the intended behavior in any case. |
|
In fact perhaps the check should be |
|
Actually, I think I changed my mind on this one. Since we can't be sure which kwargs came from an unpacked dict and which were actual keyword arguments it's not a safe way to pass preformatted attributes (i.e. |
Prevents the underscore replacement in attribute names if the name already has a dash, e.g.:
Previously the underscore would have been written as a dash.
Motivation is to be able to use datastar attributes, which have both dashes and underscores.
Since the only way to get dashes in the kwargs dict is to unpack them from a dict on the calling side this feels pretty safe. Similar to how attributes are not rewritten when they are passed in a dict as the first argument.