changeset 1733:3770d13776e8

plugin XEP-0277, xml_tools: restore decapsulation of XHTML content - to avoid successive nesting of the content in <div> - otherwise there is a new <div> at each item modification
author souliane <souliane@mailoo.org>
date Thu, 10 Dec 2015 14:21:51 +0100
parents cf11cfc87ef9
children 56fa4e7e158c
files src/plugins/plugin_xep_0277.py src/tools/xml_tools.py
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Thu Dec 10 14:00:21 2015 +0100
+++ b/src/plugins/plugin_xep_0277.py	Thu Dec 10 14:21:51 2015 +0100
@@ -178,7 +178,11 @@
                 if data_elt.uri != NS_XHTML:
                     raise failure.Failure(exceptions.DataError(_('Content of type XHTML must declare its namespace!')))
                 key = check_conflict(u'{}_xhtml'.format(elem.name))
-                data = data_elt.toXml()
+
+                # This is needed to avoid a successive encapsulation with a new <div>...</div>
+                # each time the item is modified (encapsulation is done in self.data2entry).
+                data = xml_tools.decapsulateDomishContent(data_elt)
+
                 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(data)
                 microblog_data[key] = xml_tools.expandNewLinesToXHTML(microblog_data[key])
             else:
--- a/src/tools/xml_tools.py	Thu Dec 10 14:00:21 2015 +0100
+++ b/src/tools/xml_tools.py	Thu Dec 10 14:21:51 2015 +0100
@@ -1361,3 +1361,17 @@
     """
     # if present, replace <br> (HTML), <br > and <br/> at end of line with <br /> (XHTML)
     return re.sub(r"<br[ ]?/?>\n", "\n", text).replace("\n", "<br />\n")
+
+
+def decapsulateDomishContent(elt):
+    """Return the inner content of a domish.Element.
+
+    @return unicode
+    """
+    result = ''
+    for child in elt.children:
+        try:
+            result += child.toXml()  # child id a domish.Element
+        except AttributeError:
+            result += child  # child is unicode
+    return result