v2ex/babel/ext/bleach/__init__.py
def clean(text, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES,
          styles=ALLOWED_STYLES, strip=False, strip_comments=True):
    """Clean an HTML fragment and return it"""
    if not text:
        return u''

    text = force_unicode(text)
    if text.startswith(u'<!--'):
        text = u' ' + text

    class s(BleachSanitizer):
        allowed_elements = tags
        allowed_attributes = attributes
        allowed_css_properties = styles
        strip_disallowed_elements = strip
        strip_html_comments = strip_comments

    parser = html5lib.HTMLParser(tokenizer=s)

    return _render(parser.parseFragment(text)).strip()
Clean an HTML fragment and return it
Clean an HTML fragment and return it
Clean an HTML fragment and return it
def clean(text, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES,
          styles=ALLOWED_STYLES, strip=False, strip_comments=True):
    if not text:
        return u''
    text = force_unicode(text)
    if text.startswith(u'<!--'):
        text = u' ' + text
    class s(BleachSanitizer):
        allowed_elements = tags
        allowed_attributes = attributes
        allowed_css_properties = styles
        strip_disallowed_elements = strip
        strip_html_comments = strip_comments
    parser = html5lib.HTMLParser(tokenizer=s)
    return _render(parser.parseFragment(text)).strip()
def clean ( text , tags = ALLOWED_TAGS , attributes = ALLOWED_ATTRIBUTES , styles = ALLOWED_STYLES , strip = False , strip_comments = True ) : if not text : return u'' text = force_unicode ( text ) if text . startswith ( u'<!--' ) : text = u' ' + text class s ( BleachSanitizer ) : allowed_elements = tags allowed_attributes = attributes allowed_css_properties = styles strip_disallowed_elements = strip strip_html_comments = strip_comments parser = html5lib . HTMLParser ( tokenizer = s ) return _render ( parser . parseFragment ( text ) ) . strip ( )
Clean an HTML fragment and return it
Clean an HTML fragment and return it
"""Clean an HTML fragment and return it"""
text
tags
attributes
styles
strip
strip_comments