Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix: improve tab handling in TOC and index item processing

myhlolie3d4df3946fb
diff --git a/mineru/backend/office/model_output_to_middle_json.py b/mineru/backend/office/model_output_to_middle_json.py
index 82069c54..cd656220 100644
--- a/mineru/backend/office/model_output_to_middle_json.py
+++ b/mineru/backend/office/model_output_to_middle_json.py
@@ -252,7 +252,11 @@ def _link_index_spans_to_body_blocks(middle_json: dict) -> None:
for span in toc_spans:
content = span.get('content', '')
if '\t' in content:
- toc_text = content.split('\t', 1)[0].strip()
+ # The last tab separates the page number; strip it.
+ # Internal tabs separate section number from title (e.g. "1.1\t研究对象\t5"
+ # -> "1.1\t研究对象"). _normalize_for_match removes \t via \s+, and
+ # _strip_section_number's \s* already consumes the tab after the number.
+ toc_text = content.rsplit('\t', 1)[0].strip()
else:
toc_text = content.strip()
@@ -292,7 +296,7 @@ def _link_index_spans_to_body_blocks(middle_json: dict) -> None:
if 'target_anchor' in span:
continue
content = span.get('content', '')
- toc_text = content.split('\t', 1)[0].strip() if '\t' in content else content.strip()
+ toc_text = content.rsplit('\t', 1)[0].strip() if '\t' in content else content.strip()
if not toc_text:
continue
diff --git a/mineru/backend/office/office_middle_json_mkcontent.py b/mineru/backend/office/office_middle_json_mkcontent.py
index c79ea2b3..25ec1ca1 100644
--- a/mineru/backend/office/office_middle_json_mkcontent.py
+++ b/mineru/backend/office/office_middle_json_mkcontent.py
@@ -230,9 +230,10 @@ def _flatten_index_items(index_block):
for line in child.get('lines', []):
for span in line.get('spans', []):
content = span.get('content', '')
- # Strip trailing tab + page number (e.g. "引言\t1" -> "引言")
+ # Strip trailing tab + page number (e.g. "引言\t1" -> "引言",
+ # "1.1\t研究对象\t5" -> "1.1 研究对象")
if '\t' in content:
- content = content.split('\t', 1)[0]
+ content = content.rsplit('\t', 1)[0].replace('\t', ' ')
content = content.strip()
if content:
text_parts.append(content)