From cfabb8b9eb5ef1275b7b4ea7bbca2d8f88c6487b Mon Sep 17 00:00:00 2001 From: chengke <404835780@qq.com> Date: Tue, 1 Sep 2026 08:34:07 +0800 Subject: [PATCH] fix: ignore bare markdown hash lines as headings Lines that are only '#' markers have no title text after stripping and must not open an empty section path during chunking. Co-authored-by: Cursor --- .../services/document_parser/structure/heading_candidates.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/worker/app/services/document_parser/structure/heading_candidates.py b/apps/worker/app/services/document_parser/structure/heading_candidates.py index b6f80512b..b77b51e45 100644 --- a/apps/worker/app/services/document_parser/structure/heading_candidates.py +++ b/apps/worker/app/services/document_parser/structure/heading_candidates.py @@ -303,6 +303,10 @@ def _estimate_markdown_heading_level(line: str, meta_ctx: Any | None): if hash_level <= 0: return code_level, code_reason, line_clean + # "#" / "##" with no title text must not become headings via hash_level alone. + if not stripped_line.strip(): + return -1, f"{hash_level}# AND empty-title {code_reason}", line_clean + if isinstance(code_level, int): est_level = max(hash_level, code_level) else: