Ejemplo n.º 1
0
def sanitise_html(dirty_html, opener=None, device=None):
    html = etree.fromstring("<div>%s</div>" % dirty_html,
                            parser=etree.HTMLParser())
    html = transform(html, 'external_media/html_sanitiser.xslt')

    # serialize and remove the div tag
    return etree.tostring(html, method='html')[5:-6]
Ejemplo n.º 2
0
def sanitize_html(value, args=''):
    document = etree.fromstring(u'<body>%s</body>' % value, parser=etree.HTMLParser())

    args = args.split(',') + [None, None]
    id_prefix, class_prefix = args[0] or 'sani', args[1] or 'sani'

    document = transform(document, 'utils/sanitize_html.xslt', {
        'id_prefix': id_prefix,
        'class_prefix': class_prefix,
    })
    return SafeUnicode(etree.tostring(document)[6:-7])