plugin text_syntaxes: fixed clean_xhml (it now return XHTML instead of HTML)
This commit is contained in:
parent
a96a957bfb
commit
c4afcee020
1 changed files with 12 additions and 6 deletions
|
|
@ -22,7 +22,9 @@ from logging import debug, info, error
|
||||||
from wokkel import disco, pubsub
|
from wokkel import disco, pubsub
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.threads import deferToThread
|
from twisted.internet.threads import deferToThread
|
||||||
from lxml.html import defs, clean
|
from lxml import html
|
||||||
|
from lxml.html import clean
|
||||||
|
|
||||||
|
|
||||||
CATEGORY = "Composition"
|
CATEGORY = "Composition"
|
||||||
NAME = "Syntax"
|
NAME = "Syntax"
|
||||||
|
|
@ -123,11 +125,15 @@ class TextSyntaxes(object):
|
||||||
@param xhtml: raw xhtml text to clean
|
@param xhtml: raw xhtml text to clean
|
||||||
"""
|
"""
|
||||||
# FIXME: styles are allowed but not cleaned, they have to be cleaned (whitelist ? cssutils ?) !
|
# FIXME: styles are allowed but not cleaned, they have to be cleaned (whitelist ? cssutils ?) !
|
||||||
safe_attrs = defs.safe_attrs.union(('style',))
|
def blocking_cleaning(xhtml):
|
||||||
cleaner = clean.Cleaner(style=False,
|
safe_attrs = html.defs.safe_attrs.union(('style',))
|
||||||
add_nofollow=False,
|
xhtml_elt = html.fromstring(xhtml)
|
||||||
safe_attrs=safe_attrs)
|
cleaner = clean.Cleaner(style=False,
|
||||||
d = deferToThread(cleaner.clean_html, xhtml)
|
add_nofollow=False,
|
||||||
|
safe_attrs=safe_attrs)
|
||||||
|
return html.tostring(cleaner.clean_html(xhtml_elt), method='xml')
|
||||||
|
|
||||||
|
d = deferToThread(blocking_cleaning, xhtml)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True):
|
def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue