Skip to content
Closed
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
9 changes: 4 additions & 5 deletions docling/utils/deepseekocr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,16 @@ def _collect_annotation_content(
break
ii += 1
else:
# Original logic for other labels
# Collect the block's content lines: consecutive non-empty lines up to the
# next annotation or the first blank line, so continuation lines survive.
while i < len(lines):
content_line = lines[i].strip()
if re.match(annotation_pattern, content_line):
break
if content_line:
if re.match(annotation_pattern, content_line):
break
visited_lines.add(i)
content_lines.append(lines[i].rstrip())
i += 1
if label_str not in ["figure", "image"]:
break
else:
i += 1
if content_lines:
Expand Down
55 changes: 55 additions & 0 deletions tests/test_unlimited_ocr_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,58 @@ def test_parse_builds_document_with_heading_and_table():

def test_response_format_enum_value():
assert ResponseFormat.UNLIMITED_OCR_MARKDOWN.value == "unlimited_ocr_markdown"


def test_continuation_lines_survive_in_a_text_block():
raw = (
"text[[100,100,900,300]]\n"
"First line\n"
"Second line\n"
"\n"
"text[[100,400,900,500]]\n"
"Next block\n"
)

doc = parse_unlimited_ocr_markdown(raw, PAGE_SIZE, page_no=1, filename="page.png")
markdown = doc.export_to_markdown()

assert "First line" in markdown
assert "Second line" in markdown
assert "Next block" in markdown
texts = [t.text for t in doc.texts]
assert any("First line" in t and "Second line" in t for t in texts)


def test_unlimited_ocr_continuation_lines_survive_in_a_text_block():
raw = (
"<|det|>text [100, 100, 900, 300]<|/det|>First line\n"
"Second line\n"
"\n"
"<|det|>text [100, 400, 900, 500]<|/det|>Next block\n"
)

doc = parse_unlimited_ocr_markdown(raw, PAGE_SIZE, page_no=1, filename="page.png")
texts = [t.text for t in doc.texts]

assert len(texts) >= 2
assert any("First line" in t and "Second line" in t for t in texts)


def test_annotation_and_blank_line_still_end_a_block():
raw = (
"text[[100,100,900,300]]\n"
"First line\n"
"Second line\n"
"\n"
"\n"
"Loose trailing text\n"
"text[[100,400,900,500]]\n"
"Next block\n"
)

doc = parse_unlimited_ocr_markdown(raw, PAGE_SIZE, page_no=1, filename="page.png")
texts = [t.text for t in doc.texts]

assert any(t == "First line\nSecond line" for t in texts)
assert any("Next block" in t for t in texts)
assert not any("Loose trailing text" in t for t in texts)
Loading