Esempio n. 1
0
def html_check_and_safe(value):

    tags = bleach.ALLOWED_TAGS + [
        'div', 'br', 'font', 'p', 'table', 'tr', 'td', 'th', 'img', 'u',
        'span', 'tbody', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr'
    ]
    attrs = {
        '*': [
            'class', 'style', 'color', 'align', 'title', 'data-toggle',
            'data-placement'
        ],
        'a': ['href', 'rel'],
        'img': ['src', 'alt'],
    }
    style = ['line-height', 'background-color', 'font-size', 'margin-top']

    text = force_unicode(value)

    class s(BleachSanitizer):
        allowed_elements = tags
        allowed_attributes = attrs
        allowed_css_properties = style
        strip_disallowed_elements = True
        strip_html_comments = True
        allowed_protocols = ['http', 'https', 'data']

    parser = html5lib.HTMLParser(tokenizer=s)

    return mark_safe(bleach._render(parser.parseFragment(text)))
Esempio n. 2
0
def html_check_and_safe(value):

    tags = bleach.ALLOWED_TAGS + ['div', 'br', 'font', 'p', 'table', 'tr', 'td', 'th', 'img', 'u', 'span', 'tbody', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr']
    attrs = {
        '*': ['class', 'style', 'color', 'align', 'title', 'data-toggle', 'data-placement'],
        'a': ['href', 'rel'],
        'img': ['src', 'alt'],
    }
    style = ['line-height', 'background-color', 'font-size', 'margin-top']

    text = force_unicode(value)

    class s(BleachSanitizer):
        allowed_elements = tags
        allowed_attributes = attrs
        allowed_css_properties = style
        strip_disallowed_elements = True
        strip_html_comments = True
        allowed_protocols = ['http', 'https', 'data']

    parser = html5lib.HTMLParser(tokenizer=s)

    return mark_safe(bleach._render(parser.parseFragment(text)))
Esempio n. 3
0
def test_xml_render():
    parser = html5lib.HTMLParser()
    eq_(bleach._render(parser.parseFragment('')), '')
Esempio n. 4
0
def test_xml_render():
    parser = html5lib.HTMLParser()
    assert bleach._render(parser.parseFragment('')) == ''
Esempio n. 5
0
def test_xml_render():
    parser = html5lib.HTMLParser()
    eq_(bleach._render(parser.parseFragment('')), '')
Esempio n. 6
0
def data_uris_to_s3(raw_html):
    parser = html5lib.HTMLParser(tokenizer=DataUriReplacer)
    clean = _render(parser.parseFragment(raw_html))
    return clean
Esempio n. 7
0
def _sanitize_html(raw_html, tokenizer):
    parser = html5lib.HTMLParser(tokenizer=tokenizer)
    clean = _render(parser.parseFragment(raw_html))
    return clean
Esempio n. 8
0
def data_uris_to_s3(raw_html):
    parser = html5lib.HTMLParser(tokenizer=DataUriReplacer)
    clean = _render(parser.parseFragment(raw_html))
    return clean
Esempio n. 9
0
def _sanitize_html(raw_html, tokenizer):
    parser = html5lib.HTMLParser(tokenizer=tokenizer)
    clean = _render(parser.parseFragment(raw_html))
    return clean