Skip to main content

White list HTML filter

Project description


Very simple white list HTML filter.

Use it with a WYSIWYG editor on the client side.


from htmlfilter import HTMLFilter hf = HTMLFilter() cleaned_html = hf.filter(dirty_html)

Rules file

The filter is instanciated with a predefined set of rules.

You can create your own rules file:

# file:
TAGS = {
        'a': ('href', 'name',),
        'p': ('class',),

# define filters on attributes data (tag_attr)
def p_class(data):
    if data not in ('class1', 'class2',):
        data = ''
    return data

And use them this way:

from htmlfilter import HTMLFilter
import my_rules

hf = HTMLFilter(rules=my_rules)
cleaned_html = hf.filter(dirty_html)

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for htmlfilter, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size htmlfilter-0.2.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page