Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created June 10, 2014 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanasco/2cda35740de8afc0a003 to your computer and use it in GitHub Desktop.
Save jvanasco/2cda35740de8afc0a003 to your computer and use it in GitHub Desktop.
issue with html5lib
import bleach
sample_text = """<button class="navbar-toggle collapsed" data-target=".navbar-collapse" data-toggle="collapse" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>"""
tags_ok = [ 'button', 'span', ]
attributes_ok = [ 'button', 'span', ]
attributes_ok = {
'*': ['class', 'data-toggle', 'data-target', 'type'],
}
def clean_text( text ):
text = bleach.clean( text, tags=tags_ok, attributes=attributes_ok, strip=True, strip_comments=False )
return text
for i in range( 1, 10 ):
sample_text = clean_text( sample_text )
print "*" * 10
print sample_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment