comparison src/plugins/plugin_xep_0277.py @ 1817:7ef0f5f90862

core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
author Goffi <goffi@goffi.org>
date Fri, 22 Jan 2016 20:24:17 +0100
parents 602a47ccc07c
children 3c8cf120a0fd
comparison
equal deleted inserted replaced
1816:2a030a830ebd 1817:7ef0f5f90862
359 attr = "{}{}".format(elem_name, type_) 359 attr = "{}{}".format(elem_name, type_)
360 if attr in data: 360 if attr in data:
361 elem = entry_elt.addElement(elem_name) 361 elem = entry_elt.addElement(elem_name)
362 if type_: 362 if type_:
363 if type_ == '_rich': # convert input from current syntax to XHTML 363 if type_ == '_rich': # convert input from current syntax to XHTML
364 converted = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML") 364 xml_content = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML")
365 if '{}_xhtml'.format(elem_name) in data: 365 if '{}_xhtml'.format(elem_name) in data:
366 raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time"))) 366 raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time")))
367 367 else:
368 xml_content = u'<div xmlns="{ns}">{converted}</div>'.format( 368 xml_content = data[attr]
369 ns=NS_XHTML, 369
370 converted=converted) 370 div_elt = xml_tools.ElementParser()(xml_content, namespace=NS_XHTML)
371 div_elt = xml_tools.ElementParser()(xml_content) 371 if div_elt.name != 'div' or div_elt.uri != NS_XHTML or div_elt.attributes:
372 if len(div_elt.children) == 1: 372 # we need a wrapping <div/> at the top with XHTML namespace
373 # if we have two <div> wrapping the content, 373 wrap_div_elt = domish.Element((NS_XHTML, 'div'))
374 # we remove the one we have just added 374 wrap_div_elt.addChild(div_elt)
375 child = div_elt.children[0] 375 div_elt = wrap_div_elt
376 if child.name == 'div' and not child.attributes and child.uri == div_elt.uri:
377 div_elt = child
378 elem.addChild(div_elt) 376 elem.addChild(div_elt)
379 elem['type'] = 'xhtml' 377 elem['type'] = 'xhtml'
380 if elem_name not in data: 378 if elem_name not in data:
381 # there is raw text content, which is mandatory 379 # there is raw text content, which is mandatory
382 # so we create one from xhtml content 380 # so we create one from xhtml content