pelme / htpy

Generate HTML in Python
http://htpy.dev
MIT License
261 stars 11 forks source link

html2htpy handling of classes with # in their names #35

Closed alexandermalyga closed 4 months ago

alexandermalyga commented 4 months ago

Hi, thanks for the amazing work on this project! I've been using the html2htpy tool to convert TailwindUI templates into Python code, but I'm facing an issue where classes with the # symbol in their names produce ValueError("id (#) must be specified before classes (.)") errors. For example:

<div class="aspect-[801/1036] w-[50.0625rem] bg-gradient-to-tr from-[#ff80b5] to-[#9089fc] opacity-30"></div>

produces

h.div(".aspect-[801/1036].w-[50.0625rem].bg-gradient-to-tr.from-[#ff80b5].to-[#9089fc].opacity-30")

which then raises the above error when rendering.

This can be fixed by using explicit class_= parameters, and I think it would be nice if html2htpy detected this and did it automatically. WDYT?

pelme commented 4 months ago

Hi @alexandermalyga! Thanks for reporting this issue! I was not aware that Tailwind used both dots and hashtags in classnames.

Please give 24.7.1 a try, it should use the class_ argument automatically if detects # or . as part of the class attribute.