Skip to content

Commit

Permalink
html2htpy: simplify attrs serialization more
Browse files Browse the repository at this point in the history
  • Loading branch information
pelme committed Jun 23, 2024
1 parent 4237e44 commit 6b2625c
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions htpy/html2htpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,20 @@ def serialize(self, shorthand_id_class: bool, use_h_prefix: bool) -> str:

_attrs += '"' + arg0 + '",'

if _kwattrs:
for a in _kwattrs:
key = a[0]
if "-" in key:
key = key.replace("-", "_")
for key, value in _kwattrs:
if "-" in key:
key = key.replace("-", "_")

if key == "class":
key = "class_"
elif key == "for":
key = "for_"
if key == "class":
key = "class_"
elif key == "for":
key = "for_"

val = a[1]
if not val:
_attrs += f"{key}=True,"
if not value:
_attrs += f"{key}=True,"

else:
_attrs += f'{key}="{val}",'
else:
_attrs += f'{key}="{value}",'

if _positional_attrs or _kwattrs:
_attrs = _attrs[:-1] + ")"
Expand Down

0 comments on commit 6b2625c

Please sign in to comment.