diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py
index 56f71ec6..ef77f3d7 100755
--- a/src/plugins/plugin_xep_0277.py
+++ b/src/plugins/plugin_xep_0277.py
@@ -178,7 +178,11 @@ class XEP_0277(object):
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
...
+ # 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:
diff --git a/src/tools/xml_tools.py b/src/tools/xml_tools.py
index dfbb71f4..ac2bf35c 100644
--- a/src/tools/xml_tools.py
+++ b/src/tools/xml_tools.py
@@ -1361,3 +1361,17 @@ def expandNewLinesToXHTML(text):
"""
# if present, replace
(HTML),
and
at end of line with
(XHTML)
return re.sub(r"
\n", "\n", text).replace("\n", "
\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