def sanitize_html(html_code):
 attributes = bleach.ALLOWED_ATTRIBUTES.copy()
 if (u'data' not in bleach.BleachSanitizer.allowed_protocols):
  bleach.BleachSanitizer.allowed_protocols.append(u'data')
 attributes.update({'*': ['class', 'style', 'id'], 'audio': ['controls', 'autobuffer', 'autoplay', 'src'], 'img': ['src', 'width', 'height', 'class']})
 output = bleach.clean(html_code, tags=(bleach.ALLOWED_TAGS + ['div', 'p', 'audio', 'pre', 'img', 'span']), styles=['white-space'], attributes=attributes)
 return output

def sanitize_html ( html_code ) : attributes = bleach . ALLOWED_ATTRIBUTES . copy ( ) if ( u'data' not in bleach . BleachSanitizer . allowed_protocols ) : bleach . BleachSanitizer . allowed_protocols . append ( u'data' ) attributes . update ( { '*' : [ 'class' , 'style' , 'id' ] , 'audio' : [ 'controls' , 'autobuffer' , 'autoplay' , 'src' ] , 'img' : [ 'src' , 'width' , 'height' , 'class' ] } ) output = bleach . clean ( html_code , tags = ( bleach . ALLOWED_TAGS + [ 'div' , 'p' , 'audio' , 'pre' , 'img' , 'span' ] ) , styles = [ 'white-space' ] , attributes = attributes ) return output
sanitizes an html fragment .