do not lose paragraph text when it's set in many <span>s (#4254)

This commit is contained in:
Frédéric Péters 2014-04-24 15:27:12 +02:00
parent a795cdc0c0
commit d14fcbd1c8
2 changed files with 53 additions and 1 deletions

View File

@ -257,7 +257,12 @@ def fill_inline(para, elem, invert_bg=False):
'''
if elem.text:
para.text = elem.text.strip('\n')
if para.getchildren():
if para.getchildren()[-1].tail is None:
para.getchildren()[-1].tail = ''
para.getchildren()[-1].tail += elem.text.strip('\n')
else:
para.text = elem.text.strip('\n')
for child in elem.getchildren():
if child.tag == '{%s}span' % TEXT_NS and child.getchildren():

View File

@ -142,6 +142,18 @@ Plop
self.assertEqual(self.convert_to_legi(doc),
'''<para>Foo<footnote><para>Bar</para></footnote>. Baz</para>''')
def test_footnotes_bug4254bis(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:span><text:span
>Bar</text:span></text:p></text:note-body></text:note></text:span
><text:span>. Baz<text:s/></text:span></text:p>
'''
self.assertEqual(self.convert_to_legi(doc),
'''<para>Foo<footnote><para>Bar</para></footnote>. Baz</para>''')
class TableTestCase(unittest.TestCase):
@ -458,6 +470,41 @@ class ListTestCase(unittest.TestCase):
odf2legi.convert_to_legi_xml(doc),
'''<book><sect1><title>Chapter</title><para><orderedlist continuation="restarts" numeration="loweralpha"><listitem><para>Premiere liste</para><para><orderedlist continuation="restarts" numeration="arabic"><listitem><para>Second niveau</para></listitem></orderedlist></para></listitem><listitem><para>Tres simple</para></listitem></orderedlist></para></sect1></book>''')
def test_list_with_footnote(self):
doc = '''\
<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">
<office:automatic-styles>
<text:list-style style:name="L1">
<text:list-level-style-number text:level="1" text:style-name="Numbering_20_Symbols" style:num-suffix="." style:num-format="1">
<style:list-level-properties text:list-level-position-and-space-mode="label-alignment">
<style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="1.27cm" fo:text-indent="-0.635cm" fo:margin-left="1.27cm"/>
</style:list-level-properties>
</text:list-level-style-number>
</text:list-style>
</office:automatic-styles>
<office:body>
<office:text>
<text:h text:style-name="Heading_20_3">Chapter</text:h>
<text:list xml:id="list526489326" text:style-name="L1">
<text:list-item>
<text:p>Premiere<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
>. liste</text:p>
</text:list-item>
</text:list>
</office:text>
</office:body>
</office:document-content>
'''
self.assertEqual(
odf2legi.convert_to_legi_xml(doc),
'''<book><sect1><title>Chapter</title><para><orderedlist continuation="restarts" numeration="arabic"><listitem><para>Premiere<footnote><para>Bar</para></footnote>. liste</para></listitem></orderedlist></para></sect1></book>''')
class FigureTestCase(unittest.TestCase):
def test_figure(self):