diff --git a/docling/backend/asciidoc_backend.py b/docling/backend/asciidoc_backend.py index 1b60d70fba..a60e924dfa 100644 --- a/docling/backend/asciidoc_backend.py +++ b/docling/backend/asciidoc_backend.py @@ -153,7 +153,7 @@ def _parse(self, doc: DoclingDocument): elif in_list and item["indent"] < indents[level]: # print(item["indent"], " => ", indents[level]) - while item["indent"] < indents[level]: + while level > 0 and item["indent"] < indents[level]: # print(item["indent"], " => ", indents[level]) parents[level] = None indents[level] = None diff --git a/tests/test_backend_asciidoc.py b/tests/test_backend_asciidoc.py index d6e314416d..b23961f6c0 100644 --- a/tests/test_backend_asciidoc.py +++ b/tests/test_backend_asciidoc.py @@ -1,4 +1,5 @@ import glob +from io import BytesIO from pathlib import Path from docling.backend.asciidoc_backend import ( @@ -24,6 +25,23 @@ def _get_backend(fname): return doc_backend +def test_list_dedent_to_base_does_not_crash(): + # A list that starts indented and then dedents back to the base level used + # to raise "TypeError: '<' not supported between instances of 'int' and + # 'NoneType'": the dedent loop walked past level 0, where the base indent is + # never set. It should keep both items instead. + src = b" * a\n* b\n" + in_doc = InputDocument( + path_or_stream=BytesIO(src), + format=InputFormat.ASCIIDOC, + backend=AsciiDocBackend, + filename="dedent.asciidoc", + ) + doc = in_doc._backend.convert() + + assert [item.text for item in doc.texts] == ["a", "b"] + + def test_parse_picture(): line = ( "image::images/example1.png[Example Image, width=200, height=150, align=center]"