plugin text_syntaxes: fixed clean_xhml (it now return XHTML instead of HTML)

This commit is contained in:
Goffi 2013-11-09 10:16:35 +01:00
commit c4afcee020

View file

@ -22,7 +22,9 @@ from logging import debug, info, error
from wokkel import disco, pubsub
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from lxml.html import defs, clean
from lxml import html
from lxml.html import clean
CATEGORY = "Composition"
NAME = "Syntax"
@ -123,11 +125,15 @@ class TextSyntaxes(object):
@param xhtml: raw xhtml text to clean
"""
# FIXME: styles are allowed but not cleaned, they have to be cleaned (whitelist ? cssutils ?) !
safe_attrs = defs.safe_attrs.union(('style',))
cleaner = clean.Cleaner(style=False,
add_nofollow=False,
safe_attrs=safe_attrs)
d = deferToThread(cleaner.clean_html, xhtml)
def blocking_cleaning(xhtml):
safe_attrs = html.defs.safe_attrs.union(('style',))
xhtml_elt = html.fromstring(xhtml)
cleaner = clean.Cleaner(style=False,
add_nofollow=False,
safe_attrs=safe_attrs)
return html.tostring(cleaner.clean_html(xhtml_elt), method='xml')
d = deferToThread(blocking_cleaning, xhtml)
return d
def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True):