From 0606abaad364639a16d3c0dcb4670beb8ae30c34 Mon Sep 17 00:00:00 2001 From: kernelvale <258480682+kernelvale@users.noreply.github.com> Date: Sat, 14 Nov 2026 04:26:52 +0800 Subject: [PATCH] fix(table): recognize leading continuation captions --- src/docvortex/content/table/rules.py | 14 ++++++++++---- tests/unittest/test_table_merge.py | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/docvortex/content/table/rules.py b/src/docvortex/content/table/rules.py index 9aee2663..e75d68f4 100644 --- a/src/docvortex/content/table/rules.py +++ b/src/docvortex/content/table/rules.py @@ -1,5 +1,7 @@ """跨页表格延续文本与 caption 的轻量判定规则。""" +import re + from ...foundation._text import full_to_half CONTINUATION_END_MARKERS = [ @@ -18,16 +20,20 @@ "(continued)", ] +_CONTINUATION_PREFIX_RE = re.compile(r"^(?:(?:续表|续上表)\s*|continued\s+table\s+)(?=[a-z]?\d)") + def is_table_continuation_text(text: str) -> bool: - """判断文本是否表达续表语义,供表格归组和跨页合并共同复用。""" + """判断后缀、行内或带编号前缀是否表达续表语义。""" continuation_text = full_to_half((text or "").strip()).lower() if not continuation_text: return False - return any( - _matches_continuation_end_marker(continuation_text, marker.lower()) for marker in CONTINUATION_END_MARKERS - ) or any(marker.lower() in continuation_text for marker in CONTINUATION_INLINE_MARKERS) + return ( + any(_matches_continuation_end_marker(continuation_text, marker.lower()) for marker in CONTINUATION_END_MARKERS) + or any(marker.lower() in continuation_text for marker in CONTINUATION_INLINE_MARKERS) + or _CONTINUATION_PREFIX_RE.match(continuation_text) is not None + ) def _matches_continuation_end_marker(text: str, marker: str) -> bool: diff --git a/tests/unittest/test_table_merge.py b/tests/unittest/test_table_merge.py index 293bffa9..b8e61006 100644 --- a/tests/unittest/test_table_merge.py +++ b/tests/unittest/test_table_merge.py @@ -210,6 +210,28 @@ def test_merge_table_applies_caption_and_footnote_rules( assert current_table.get("continues_prev", False) is expected +@pytest.mark.parametrize( + ("current_caption", "expected"), + [ + ("续表 2-1 临床信息表", True), + ("续表2-1 临床信息表", True), + ("续上表 2-1 临床信息表", True), + ("Continued table 2-1 Clinical information", True), + ("CONTINUED TABLE A1 Clinical information", True), + ("续表说明见正文", False), + ("Continued table of contents", False), + ("Previous table 2-1", False), + ], +) +def test_merge_table_scopes_leading_continuation_markers(current_caption: str, expected: bool) -> None: + """验证带编号的中英前置续表标记,并拒绝相似普通文字。""" + current_table = _table(1, children=[_caption(current_caption), _table_body(index=1)]) + + merge_table([_page(0, [_table(0)]), _page(1, [current_table])]) + + assert current_table.get("continues_prev", False) is expected + + def test_post_table_non_continuation_caption_does_not_block_merge() -> None: """验证 table body 下方的非续表 caption 不参与阻断判断。""" current_children = [