(HTML) class manipulation shortcuts

Bug #1243600 reported by Xavier (Open ERP) on 2013-10-23
This bug affects 1 person
Affects Status Importance Assigned to Milestone

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

scoder (scoder) wrote :

Agreed, would be nice to have.

Changed in lxml:
importance: Undecided → Wishlist
status: New → Confirmed
scoder (scoder) wrote :

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

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

scoder (scoder) wrote :

Absolutely. I take pull requests.

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?

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.

scoder (scoder) wrote :
Changed in lxml:
assignee: nobody → scoder (scoder)
milestone: none → 3.5
status: Confirmed → Fix Committed
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  Edit
Everyone can see this information.

Other bug subscribers