# HG changeset patch # User Goffi # Date 1383988595 -3600 # Node ID fb0b1100c9085599a699f45612ebda72f4eaf3f4 # Parent 903c4749de15e0a394eabebd7fc860165cfb238f plugin text_syntaxes: fixed clean_xhml (it now return XHTML instead of HTML) diff -r 903c4749de15 -r fb0b1100c908 src/plugins/plugin_misc_text_syntaxes.py --- a/src/plugins/plugin_misc_text_syntaxes.py Fri Nov 08 16:35:51 2013 +0100 +++ b/src/plugins/plugin_misc_text_syntaxes.py Sat Nov 09 10:16:35 2013 +0100 @@ -22,7 +22,9 @@ 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 @@ @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):