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)))
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)))
def test_xml_render(): parser = html5lib.HTMLParser() eq_(bleach._render(parser.parseFragment('')), '')
def test_xml_render(): parser = html5lib.HTMLParser() assert bleach._render(parser.parseFragment('')) == ''
def data_uris_to_s3(raw_html): parser = html5lib.HTMLParser(tokenizer=DataUriReplacer) clean = _render(parser.parseFragment(raw_html)) return clean
def _sanitize_html(raw_html, tokenizer): parser = html5lib.HTMLParser(tokenizer=tokenizer) clean = _render(parser.parseFragment(raw_html)) return clean