diff src/plugins/plugin_xep_0277.py @ 1802:fed95a6c56f8

plugin (xep-0277): avoid wrapping XML in an extra <div> in data2entry
author Goffi <goffi@goffi.org>
date Fri, 15 Jan 2016 17:13:59 +0100
parents 1359ad0b37c2
children 160b0d4c6520
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Fri Jan 15 12:27:34 2016 +0100
+++ b/src/plugins/plugin_xep_0277.py	Fri Jan 15 17:13:59 2016 +0100
@@ -370,7 +370,14 @@
                         xml_content = u'<div xmlns="{ns}">{converted}</div>'.format(
                                         ns=NS_XHTML,
                                         converted=converted)
-                        elem.addChild(xml_tools.ElementParser()(xml_content))
+                        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
+                        elem.addChild(div_elt)
                         elem['type'] = 'xhtml'
                         if elem_name not in data:
                             # there is raw text content, which is mandatory