# HG changeset patch # User souliane # Date 1449752421 -3600 # Node ID cf11cfc87ef9d934016e04c99ec4c02907813479 # Parent 58ecc0e2e6fcd57b998d62975e63d0b2254c4916 xml_tools, plugin XEP-0071, XEP-0277: add method expandNewLinesToXHTML: - \n in XHTML content should not be converted to
by the frontend - save it directly in the Atom payload for better compatibility with other clients diff -r 58ecc0e2e6fc -r cf11cfc87ef9 src/plugins/plugin_xep_0071.py --- a/src/plugins/plugin_xep_0071.py Thu Dec 10 10:44:04 2015 +0100 +++ b/src/plugins/plugin_xep_0071.py Thu Dec 10 14:00:21 2015 +0100 @@ -22,6 +22,7 @@ from sat.core.log import getLogger log = getLogger(__name__) +from sat.tools import xml_tools from wokkel import disco, iwokkel from zope.interface import implements # from lxml import etree @@ -118,6 +119,7 @@ raise exceptions.DataError(_("Can't have xhtml and rich content at the same time")) if xhtml: d = self.synt_plg.clean_xhtml(xhtml) + d.addCallback(xml_tools.expandNewLinesToXHTML) d.addCallback(syntax_converted) return d diff -r 58ecc0e2e6fc -r cf11cfc87ef9 src/plugins/plugin_xep_0277.py --- a/src/plugins/plugin_xep_0277.py Thu Dec 10 10:44:04 2015 +0100 +++ b/src/plugins/plugin_xep_0277.py Thu Dec 10 14:00:21 2015 +0100 @@ -180,6 +180,7 @@ key = check_conflict(u'{}_xhtml'.format(elem.name)) data = data_elt.toXml() microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(data) + microblog_data[key] = xml_tools.expandNewLinesToXHTML(microblog_data[key]) else: key = check_conflict(elem.name) microblog_data[key] = unicode(elem) @@ -368,6 +369,7 @@ raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time"))) else: # clean the XHTML input converted = yield synt.clean_xhtml(data[attr]) + converted = xml_tools.expandNewLinesToXHTML(converted) xml_content = u'
{converted}
'.format( ns=NS_XHTML, diff -r 58ecc0e2e6fc -r cf11cfc87ef9 src/tools/xml_tools.py --- a/src/tools/xml_tools.py Thu Dec 10 10:44:04 2015 +0100 +++ b/src/tools/xml_tools.py Thu Dec 10 14:00:21 2015 +0100 @@ -29,7 +29,7 @@ from twisted.internet import defer from sat.core import exceptions from collections import OrderedDict - +import re """This library help manage XML used in SàT (parameters, registration, etc)""" @@ -1351,3 +1351,13 @@ tmp.addRawXml(raw_xml) parser.parse(tmp.toXml().encode('utf-8')) return self.result.firstChildElement() + + +def expandNewLinesToXHTML(text): + """If not present yet, add a
before all \n occurences. + + @param text(unicode) + @return unicode + """ + # if present, replace
(HTML),
and
at end of line with
(XHTML) + return re.sub(r"\n", "\n", text).replace("\n", "
\n")