From c4afcee0208899c5c73c187994d15eea07bde4e0 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 9 Nov 2013 10:16:35 +0100 Subject: [PATCH] plugin text_syntaxes: fixed clean_xhml (it now return XHTML instead of HTML) --- src/plugins/plugin_misc_text_syntaxes.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/plugins/plugin_misc_text_syntaxes.py b/src/plugins/plugin_misc_text_syntaxes.py index a6d11852..7551734a 100755 --- a/src/plugins/plugin_misc_text_syntaxes.py +++ b/src/plugins/plugin_misc_text_syntaxes.py @@ -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):