Bleach 1.0rc2

Bleach is very nearly ready for a 1.0!

After I announced Bleach 1.0rc1, a couple of important issues were found. Those have now been fixed. (Thanks, guys!) One of these was backported to 0.5, and I uploaded 0.5.1 to PyPI yesterday.

If you use Bleach, please try out the new version. You can get it from Github and install with pip.

Upgrade Path

Bleach 1.0 drops the Bleach class. 0.5.x is intended as a stepping stone that will let you start using the new API.

1.
# Bleach <= 0.5
2.
from bleach import Bleach
3.
b = Bleach()
4.
b.clean()
5.
 
6.
# Bleach >= 0.5
7.
import bleach
8.
bleach.clean()
Hopefully this change will be minor unless you were using URL filters on `linkify()`. In that case, the change is:
1.
# Bleach <= 0.5
2.
from bleach import Bleach
3.
class MyBleach(Bleach):
4.
    def filter_url(self, url):
5.
        return‘http://google.com’
6.
b = MyBleach()
7.
b.linkify(‘a link to example.com’)
8.
 
9.
# Bleach >= 0.5
10.
import bleach
11.
def filter_url(url):
12.
    return‘http://google.com’
13.
bleach.linkify(‘a link to example.com’, filter_url=filter_url)
This is a bigger change, but I hope it won’t be too bad for users, and I think it makes the whole API much more consistent. Lots of kwargs, yes, but more consistent and logical.

Features

Bleach 1.0 doesn’t have much in the way of new features, instead focusing on clean up, improving test coverage and security, and being ready to call it a 1.0. It does have the following changes over 0.5:

  • A skip_pre option for linkify() to ignore URLs in <pre> sections.
  • Drops support for nofollow_relative. I still think that’s a good option but it needs work.

So please, check out Bleach. I’d love feedback on the new direction. Feel free to comment or open issues.