Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docling/backend/asciidoc_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ def _parse(self, doc: DoclingDocument):

if not in_list:
in_list = True
# The list ends the paragraph before it, which would
# otherwise be added later, inside the list.
text_data = self._flush_text_data(
doc=doc, text_data=text_data, parent=parents[level]
)
# GroupItem has no caption slot; emit the pending block
# title as a bold paragraph immediately before the list.
if caption_data:
Expand Down Expand Up @@ -387,6 +392,13 @@ def _parse(self, doc: DoclingDocument):
in_delimited_table = False
table_data = []
else:
# The table ends the paragraph before it, which would
# otherwise be added after the table.
text_data = self._flush_text_data(
doc=doc,
text_data=text_data,
parent=self._get_current_parent(parents),
)
in_table = True
in_delimited_table = True

Expand Down
31 changes: 31 additions & 0 deletions tests/test_backend_asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,37 @@ def test_symmetric_titles_drop_their_closing_marks() -> None:
]


def _convert_source(src: bytes) -> DoclingDocument:
in_doc = InputDocument(
path_or_stream=BytesIO(src),
format=InputFormat.ASCIIDOC,
backend=AsciiDocBackend,
filename="flush.adoc",
)
return in_doc._backend.convert()


def test_list_flushes_pending_paragraph() -> None:
# The text before a list was only added at the next blank line, so it
# landed inside the list group, after the list items.
doc = _convert_source(b"Intro:\n* a\n* b\n")

intro = next(item for item in doc.texts if item.text == "Intro:")
assert intro.parent == doc.body.get_ref()
assert doc.export_to_markdown() == "Intro:\n\n- a\n- b"


def test_table_flushes_pending_paragraph() -> None:
# The text before a delimited table was added after the table.
doc = _convert_source(b"Before\n|===\n|a|b\n|===\n")

assert [item.label for item, _ in doc.iterate_items()] == [
DocItemLabel.PARAGRAPH,
DocItemLabel.TABLE,
]
assert doc.export_to_markdown().startswith("Before\n\n| a ")


def test_block_title_without_floating_target_keeps_content() -> None:
# A block title followed by a paragraph used to absorb every following
# line as "multiline caption" and drop all of it at EOF.
Expand Down
Loading