Skip to content

samueladam/htmlfilter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About
-----

Very simple white list HTML filter.

Use it with a WYSIWYG editor on the client side.


Usage
-----

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


Rules file
----------

The filter is instanciated with a predefined set of rules.
http://github.com/samueladam/htmlfilter/blob/master/htmlfilter/rules.py

You can create your own rules file::

	# file: my_rules.py
	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)

About

Filter HTML data with a white list and a set of rules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages