Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
refactor: enhance local metric line resolution and cross-page handling in text merging
myhloli4cfa9e8247c5
diff --git a/mineru/backend/utils/para_block_utils.py b/mineru/backend/utils/para_block_utils.pyindex 21679f85..d0d622b1 100644--- a/mineru/backend/utils/para_block_utils.py+++ b/mineru/backend/utils/para_block_utils.py@@ -148,8 +148,8 @@ def can_auto_merge_text_blocks("""按段落首尾文本和行几何规则判断 text 是否可合并。"""current_lines = current_block.get("lines", [])previous_lines = previous_block.get("lines", [])- current_metric_lines = _resolve_auto_metric_lines(current_block)- previous_metric_lines = _resolve_auto_metric_lines(previous_block)+ current_metric_lines = _resolve_local_metric_lines(current_block)+ previous_metric_lines = _resolve_local_metric_lines(previous_block)if (not current_linesor not previous_lines@@ -280,11 +280,19 @@ def _resolve_auto_metric_lines(block):return block.get(OCR_DET_LINES_KEY) or block.get("lines", [])+def _resolve_local_metric_lines(block):+ """过滤跨页追加行,避免已合并内容污染后续本地几何判定。"""+ metric_lines = _resolve_auto_metric_lines(block)+ local_metric_lines = [+ line for line in metric_lines if not _is_cross_page_line(line)+ ]+ return local_metric_lines or metric_lines++def _merge_text_block(current_block, previous_block, is_cross_page):if is_cross_page:- for line in current_block.get("lines", []):- for span in line.get("spans", []):- span[SplitFlag.CROSS_PAGE] = True+ _mark_lines_cross_page(current_block.get("lines", []))+ _mark_lines_cross_page(current_block.get(OCR_DET_LINES_KEY, []))previous_block.setdefault("lines", []).extend(current_block.get("lines", []))if current_block.get(OCR_DET_LINES_KEY):@@ -296,6 +304,19 @@ def _merge_text_block(current_block, previous_block, is_cross_page):current_block[SplitFlag.LINES_DELETED] = True+def _mark_lines_cross_page(lines):+ """给跨页合并进来的文本行和 det hint 行同步打跨页标记。"""+ for line in lines:+ for span in line.get("spans", []):+ span[SplitFlag.CROSS_PAGE] = True+++def _is_cross_page_line(line):+ """判断整行是否来自跨页追加,供几何度量时排除。"""+ spans = line.get("spans", [])+ return bool(spans) and all(span.get(SplitFlag.CROSS_PAGE) for span in spans)++def _merge_ref_text_list_block(current_block, previous_block, is_cross_page):"""合并相邻 ref_text list,并在跨页时给当前 list 内 span 标记跨页。"""if is_cross_page: