Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1801:07390a9d1c09 | 1802:fed95a6c56f8 |
---|---|
368 converted = yield synt.clean_xhtml(data[attr]) | 368 converted = yield synt.clean_xhtml(data[attr]) |
369 | 369 |
370 xml_content = u'<div xmlns="{ns}">{converted}</div>'.format( | 370 xml_content = u'<div xmlns="{ns}">{converted}</div>'.format( |
371 ns=NS_XHTML, | 371 ns=NS_XHTML, |
372 converted=converted) | 372 converted=converted) |
373 elem.addChild(xml_tools.ElementParser()(xml_content)) | 373 div_elt = xml_tools.ElementParser()(xml_content) |
374 if len(div_elt.children) == 1: | |
375 # if we have two <div> wrapping the content, | |
376 # we remove the one we have just added | |
377 child = div_elt.children[0] | |
378 if child.name == 'div' and not child.attributes and child.uri == div_elt.uri: | |
379 div_elt = child | |
380 elem.addChild(div_elt) | |
374 elem['type'] = 'xhtml' | 381 elem['type'] = 'xhtml' |
375 if elem_name not in data: | 382 if elem_name not in data: |
376 # there is raw text content, which is mandatory | 383 # there is raw text content, which is mandatory |
377 # so we create one from xhtml content | 384 # so we create one from xhtml content |
378 elem_txt = entry_elt.addElement(elem_name) | 385 elem_txt = entry_elt.addElement(elem_name) |