# HG changeset patch # User souliane # Date 1449753711 -3600 # Node ID 3770d13776e8f2304ab355760d7231908e5fcc62 # Parent cf11cfc87ef9d934016e04c99ec4c02907813479 plugin XEP-0277, xml_tools: restore decapsulation of XHTML content - to avoid successive nesting of the content in
- otherwise there is a new
at each item modification diff -r cf11cfc87ef9 -r 3770d13776e8 src/plugins/plugin_xep_0277.py --- 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
...
+ # 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 -r cf11cfc87ef9 -r 3770d13776e8 src/tools/xml_tools.py --- 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
(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