Skip to content

Commit

Permalink
html2htpy: simplify attrs serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pelme committed Jun 23, 2024
1 parent 1edbda0 commit 4237e44
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions htpy/html2htpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,11 @@ def serialize(self, shorthand_id_class: bool, use_h_prefix: bool) -> str:
_attrs = ""
_kwattrs: list[tuple[str, str | None]] = []

for a in self.attrs:
key = a[0]
if key == "class":
if shorthand_id_class:
_positional_attrs[key] = a[1]
else:
_kwattrs.append(a)

elif key == "id":
if shorthand_id_class:
_positional_attrs[key] = a[1]
else:
_kwattrs.append(a)
for key, value in self.attrs:
if key in ("id", "class") and shorthand_id_class:
_positional_attrs[key] = value
else:
_kwattrs.append(a)
_kwattrs.append((key, value))

if _positional_attrs or _kwattrs:
_attrs += "("
Expand Down

0 comments on commit 4237e44

Please sign in to comment.