diff --git a/docling/backend/opendocument_backend.py b/docling/backend/opendocument_backend.py index 2762908dc0..ec4e03ca99 100644 --- a/docling/backend/opendocument_backend.py +++ b/docling/backend/opendocument_backend.py @@ -313,6 +313,9 @@ def _odf_text_runs( if text_recursive.startswith(text): text = text_recursive return [_OdfTextRun(text=text, formatting=formatting)] + if tag == "text:s": + text_recursive = getattr(element, "text_recursive", " ") + return [_OdfTextRun(text=text_recursive, formatting=formatting)] if tag == "text:tab": return [_OdfTextRun(text="\t", formatting=formatting)] diff --git a/tests/test_backend_opendocument.py b/tests/test_backend_opendocument.py index 0512dafee2..c6860956bc 100644 --- a/tests/test_backend_opendocument.py +++ b/tests/test_backend_opendocument.py @@ -46,6 +46,7 @@ List as OdfList, ListItem, Paragraph, + Spacer, Span, Style, Table, @@ -436,6 +437,24 @@ def test_odt_text_document_text_formatting(): assert "~~The Extremes of Good and Evil~~" in markdown +def test_odt_text_after_space_in_span(tmp_path: Path): + path = tmp_path / "span_tail.odt" + doc = OdfDocument("text") + body = doc.body + body.clear() + + space = Spacer() + space.tail = "connective prose here" + span = Span() + span.append(space) + body.append(Paragraph(span)) + doc.save(str(path)) + + res = DocumentConverter(allowed_formats=[InputFormat.ODT]).convert(path) + + assert res.document.export_to_markdown() == "connective prose here" + + def test_odt_text_document_script_formatting(): path = Path("tests/data/odf/sources/text_document_01.odt")