handle <span> leftover text (#4254)

This commit is contained in:
Frédéric Péters 2014-01-28 08:37:44 +00:00
parent e9d4ebc7fd
commit 71f4dc9df1
2 changed files with 18 additions and 1 deletions

View File

@ -262,6 +262,7 @@ def fill_inline(para, elem, invert_bg=False):
for child in elem.getchildren():
if child.tag == '{%s}span' % TEXT_NS and child.getchildren():
fill_inline(para, child, invert_bg=invert_bg)
append_remaining_text(para, child.tail)
elif child.tag == '{%s}span' % TEXT_NS and not child.getchildren():
try:
@ -295,6 +296,9 @@ def fill_inline(para, elem, invert_bg=False):
elif child.tag == '{%s}sequence' % TEXT_NS:
append_remaining_text(para, child.text, child.tail)
elif child.tag == '{%s}s' % TEXT_NS:
append_remaining_text(para, child.text, child.tail)
elif child.tag == '{%s}sequence-ref' % TEXT_NS:
xref = ET.Element('xref')
xref.attrib['linkend'] = child.attrib.get('{%s}ref-name' % TEXT_NS)

View File

@ -130,6 +130,20 @@ Plop
'''<para>\nPlop\n</para>''')
def test_footnotes_bug4254(self):
doc = '''\
<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Foo
<text:span><text:note><text:note-citation>2</text:note-citation
><text:note-body><text:p><text:span ><text:s/></text:span><text:span
>Bar</text:span></text:p></text:note-body></text:note></text:span
>. Baz</text:p>
'''
self.assertEqual(self.convert_to_legi(doc),
'''<para>Foo<footnote><para>Bar</para></footnote>. Baz</para>''')
class TableTestCase(unittest.TestCase):
def test_plain_table(self):
doc = '''\
@ -859,6 +873,5 @@ M. Michu bla bla bla
odf2legi.convert_to_legi_xml(doc),
'''<book><sect1><title>Chapter</title><para>Hello</para><para><emphasis role="italic">World</emphasis></para></sect1></book>''')
if __name__ == '__main__':
unittest.main()