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:
Goffi 2016-01-22 20:24:17 +01:00
commit 4a44b41793
2 changed files with 26 additions and 15 deletions

View file

@ -361,20 +361,18 @@ class XEP_0277(object):
elem = entry_elt.addElement(elem_name)
if type_:
if type_ == '_rich': # convert input from current syntax to XHTML
converted = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML")
xml_content = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML")
if '{}_xhtml'.format(elem_name) in data:
raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time")))
else:
xml_content = data[attr]
xml_content = u'<div xmlns="{ns}">{converted}</div>'.format(
ns=NS_XHTML,
converted=converted)
div_elt = xml_tools.ElementParser()(xml_content)
if len(div_elt.children) == 1:
# if we have two <div> wrapping the content,
# we remove the one we have just added
child = div_elt.children[0]
if child.name == 'div' and not child.attributes and child.uri == div_elt.uri:
div_elt = child
div_elt = xml_tools.ElementParser()(xml_content, namespace=NS_XHTML)
if div_elt.name != 'div' or div_elt.uri != NS_XHTML or div_elt.attributes:
# we need a wrapping <div/> at the top with XHTML namespace
wrap_div_elt = domish.Element((NS_XHTML, 'div'))
wrap_div_elt.addChild(div_elt)
div_elt = wrap_div_elt
elem.addChild(div_elt)
elem['type'] = 'xhtml'
if elem_name not in data: