comparison src/tools/xml_tools.py @ 1732:cf11cfc87ef9

xml_tools, plugin XEP-0071, XEP-0277: add method expandNewLinesToXHTML: - \n in XHTML content should not be converted to <br /> by the frontend - save it directly in the Atom payload for better compatibility with other clients
author souliane <souliane@mailoo.org>
date Thu, 10 Dec 2015 14:00:21 +0100
parents 0fdd8fe34fbf
children 3770d13776e8
comparison
equal deleted inserted replaced
1731:58ecc0e2e6fc 1732:cf11cfc87ef9
27 from twisted.words.xish import domish 27 from twisted.words.xish import domish
28 from twisted.words.protocols.jabber import jid 28 from twisted.words.protocols.jabber import jid
29 from twisted.internet import defer 29 from twisted.internet import defer
30 from sat.core import exceptions 30 from sat.core import exceptions
31 from collections import OrderedDict 31 from collections import OrderedDict
32 32 import re
33 33
34 """This library help manage XML used in SàT (parameters, registration, etc)""" 34 """This library help manage XML used in SàT (parameters, registration, etc)"""
35 35
36 SAT_FORM_PREFIX = "SAT_FORM_" 36 SAT_FORM_PREFIX = "SAT_FORM_"
37 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names 37 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
1349 if force_spaces: 1349 if force_spaces:
1350 raw_xml = raw_xml.replace('\n', ' ').replace('\t', ' ') 1350 raw_xml = raw_xml.replace('\n', ' ').replace('\t', ' ')
1351 tmp.addRawXml(raw_xml) 1351 tmp.addRawXml(raw_xml)
1352 parser.parse(tmp.toXml().encode('utf-8')) 1352 parser.parse(tmp.toXml().encode('utf-8'))
1353 return self.result.firstChildElement() 1353 return self.result.firstChildElement()
1354
1355
1356 def expandNewLinesToXHTML(text):
1357 """If not present yet, add a <br /> before all \n occurences.
1358
1359 @param text(unicode)
1360 @return unicode
1361 """
1362 # if present, replace <br> (HTML), <br > and <br/> at end of line with <br /> (XHTML)
1363 return re.sub(r"<br[ ]?/?>\n", "\n", text).replace("\n", "<br />\n")