Empty Attributes and Dots in Attribute Names
avila-gabriel opened this issue · 4 comments
Issue: Lack of Support for Empty Attributes and Dots in Attribute Names in htpy
Description
I'm currently integrating the htpy library with the Datastar framework and have encountered issues with how htpy handles HTML attributes. Specifically, htpy does not support:
- Empty attributes - Attributes in HTML that do not have a value.
- Dots in attribute names - Attributes that include dots (.) in their names.
These features are crucial for working with Datastar as you can see below.
Examples
- Dots in attribute names:
<div data-on-store-change.remote="value"></div>
- Empty attributes:
<div data-scroll-into-view></div>
Current Workaround
I have tried passing attributes as a dictionary to bypass the issue with dots in attribute names, which works fine, although not as delicious as using a parameter. However, this approach does not address the problem with empty attributes, as there is currently no way to include them without assigning a value.
Request
I am seeking a way to enhance htpy's functionality to support both empty attributes and attributes with dots in their names. Any guidance or potential updates to address these issues would be highly appreciated as I'm currently unsure how to proceed without these capabilities.
Thank you for looking into this.
Regarding empty attributes have you tried Boolean attributes?
>>> div(data_scroll_into_view=True)
<Element '<div data-scroll-into-view></div>'>
Thanks for opening the issue.
There are a lot of characters in addition to dots that are not valid as python parameters, using the dictionary style is the way to go to deal with it. We do replace _ with - since _ is not typically used in HTML while - is not supported in python.
Do you have any ideas for how it could be improved?
Thank you guys for your help. The only thing I can think of would be using double underscores for dots, as its the only python accepted that html don't, but once in data-* attributes which are valid html I have something to share, I'll open a new issue for it #33