(HTML) class manipulation shortcuts

Bug #1243600 reported by Xavier (Open ERP)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Fix Released
Wishlist
scoder

Bug Description

lxml.html adds a number of shortcuts for manipulating HTML trees http://lxml.de/lxmlhtml.html#html-element-methods

A useful one would be the ability to more easily set and unset classes on elements, e.g. provide a `set`-like interface to the `class` html attribute, possibly extended with a classList-type `toggle(token[, force])`[0] method: although this is probably less fraught with risks than in javascript, class interaction through the string value is not exactly fun.

[0] http://dom.spec.whatwg.org/#dom-domtokenlist-toggle

Revision history for this message
scoder (scoder) wrote :

Agreed, would be nice to have.

Changed in lxml:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
scoder (scoder) wrote :

I think a nice interface would be an attribute "classes" that provides methods "add()" and "remove()".

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

A "contains" operation is also relatively frequent. collections.MutableSet seems to fit the bill rather well.

Revision history for this message
scoder (scoder) wrote :

Absolutely. I take pull requests.

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

A few questions:

* the website (lxml.de) claims 2.6+ compatibility, but reading lxml.html there's a bunch of compatibility shims for as low as Python 2.3. Which is it? Should I remove the pre-2.6 stuff from lxml.html or should I ensure my addition is 2.3-compatible?
* PRs are on github?

Revision history for this message
scoder (scoder) wrote :

Yes, PRs should go to github. The pre-2.6 stuff is pure legacy and just hasn't been removed yet. Since version 3.4 (i.e. fairly recently), lxml supports 2.6+ only. If you care to take the time for removing dead code, I'll happily accept a PR for it, too.

Revision history for this message
scoder (scoder) wrote :
Changed in lxml:
assignee: nobody → scoder (scoder)
milestone: none → 3.5
status: Confirmed → Fix Committed
Revision history for this message
scoder (scoder) wrote :

Implemented in lxml 3.5.0.

Changed in lxml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.