core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
This commit is contained in:
parent
b51b9a8887
commit
4a44b41793
1 changed files with 26 additions and 15 deletions
|
|
@ -1326,11 +1326,19 @@ class ElementParser(object):
|
|||
(c) Karl Anderson
|
||||
"""
|
||||
|
||||
def __call__(self, raw_xml, force_spaces=False):
|
||||
def __call__(self, raw_xml, force_spaces=False, namespace=None):
|
||||
"""
|
||||
@param raw_xml(unicode): the raw XML
|
||||
@param force_spaces: if True, replace occurrences of '\n' and '\t' with ' '.
|
||||
@param force_spaces (bool): if True, replace occurrences of '\n' and '\t' with ' '.
|
||||
@param namespace(unicode, None): if set, use this namespace for the wrapping element
|
||||
"""
|
||||
# we need to wrap element in case
|
||||
# there is not a unique one on the top
|
||||
if namespace is not None:
|
||||
raw_xml = u"<div xmlns='{}'>{}</div>".format(namespace, raw_xml)
|
||||
else:
|
||||
raw_xml = u"<div>{}</div>".format(raw_xml)
|
||||
|
||||
self.result = None
|
||||
|
||||
def onStart(elem):
|
||||
|
|
@ -1351,7 +1359,12 @@ class ElementParser(object):
|
|||
raw_xml = raw_xml.replace('\n', ' ').replace('\t', ' ')
|
||||
tmp.addRawXml(raw_xml)
|
||||
parser.parse(tmp.toXml().encode('utf-8'))
|
||||
return self.result.firstChildElement()
|
||||
top_elt = self.result.firstChildElement()
|
||||
# we now can check if there was a unique element on the top
|
||||
# and remove our wrapping <div/> is this was the case
|
||||
if len(top_elt.children) == 1:
|
||||
top_elt = top_elt.firstChildElement()
|
||||
return top_elt
|
||||
|
||||
|
||||
# FIXME: this method is duplicated from frontends.tools.xmlui.getText
|
||||
|
|
|
|||
Loading…
Reference in a new issue