Skip to content

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

feat: update minimum length ratio for text decoration to 1.8 heights and add corresponding tests

myhlolif00a85cde654
diff --git a/mineru/utils/pdf_text_styles.py b/mineru/utils/pdf_text_styles.py
index 9345062a..3d6db736 100644
--- a/mineru/utils/pdf_text_styles.py
+++ b/mineru/utils/pdf_text_styles.py
@@ -17,7 +17,7 @@ from mineru.utils.pdf_document import PDFLinkAnnotation
from mineru.utils.text_utils import is_hyphen_at_line_end
-TEXT_DECORATION_MIN_LENGTH_HEIGHT_RATIO = 2.0
+TEXT_DECORATION_MIN_LENGTH_HEIGHT_RATIO = 1.8
STRIKETHROUGH_CENTER_TOLERANCE_HEIGHT_RATIO = 0.2
UNDERLINE_BOTTOM_TOLERANCE_HEIGHT_RATIO = 0.2
TEXT_DECORATION_MAX_WIDTH_HEIGHT_RATIO = 0.2
diff --git a/tests/unittest/test_pdf_text_styles.py b/tests/unittest/test_pdf_text_styles.py
index e967c562..15759fcb 100644
--- a/tests/unittest/test_pdf_text_styles.py
+++ b/tests/unittest/test_pdf_text_styles.py
@@ -1168,6 +1168,31 @@ def test_rejects_thick_short_and_column_rules() -> None:
assert all(not item.style_ranges for item in detected)
+ ("drawing_length", "expected_styles"),
+ [
+ (17.99, ()),
+ (18.0, (PDFTextStyleRange(0, 3, ("strikethrough",)),)),
+ ],
+)
+def test_text_decoration_minimum_length_is_one_point_eight_heights(
+ drawing_length: float,
+ expected_styles: tuple[PDFTextStyleRange, ...],
+) -> None:
+ """验证文本装饰线长度达到 1.8 倍中位字高时才允许生成样式。"""
+
+ line = _text_line("abc")
+ detected = detect_pdf_text_style_lines(
+ [line],
+ [_drawing(line.bbox[0], line.bbox[0] + drawing_length, 15.0)],
+ )
+
+ if expected_styles:
+ assert detected[0].style_ranges == expected_styles
+ else:
+ assert detected == []
+
+
def test_accepts_one_aligned_endpoint_and_merges_adjacent_drawings() -> None:
"""验证尾部延长 drawing 可由左端点确认,邻接命中区间会合并。"""