From fd1a23c7fbeec69885838a79d4780295c9a530fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=80=E4=B8=81?= <1769123563@qq.com> Date: Sat, 15 Nov 2025 15:23:05 +0800 Subject: [PATCH] Improve IR Binding Logic --- ReportEngine/core/stitcher.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ReportEngine/core/stitcher.py b/ReportEngine/core/stitcher.py index ef1c062..463a093 100644 --- a/ReportEngine/core/stitcher.py +++ b/ReportEngine/core/stitcher.py @@ -51,6 +51,8 @@ class DocumentComposer: anchor = chapter.get("anchor") or f"section-{idx}" chapter["anchor"] = self._ensure_unique_anchor(anchor) chapter.setdefault("order", idx * 10) + if chapter.get("errorPlaceholder"): + self._ensure_heading_block(chapter) document = { "version": IR_VERSION, @@ -76,5 +78,23 @@ class DocumentComposer: self._seen_anchors.add(anchor) return anchor + def _ensure_heading_block(self, chapter: Dict[str, object]) -> None: + """保证占位章节仍然拥有可用于目录的heading block。""" + blocks = chapter.get("blocks") + if isinstance(blocks, list): + for block in blocks: + if isinstance(block, dict) and block.get("type") == "heading": + return + heading = { + "type": "heading", + "level": 2, + "text": chapter.get("title") or "占位章节", + "anchor": chapter.get("anchor"), + } + if isinstance(blocks, list): + blocks.insert(0, heading) + else: + chapter["blocks"] = [heading] + __all__ = ["DocumentComposer"]