Coverage for src\genesis\writer\renderer.py: 100%
16 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-26 14:20 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-26 14:20 +0800
1"""渲染:ChapterContent 的 ContentBlock 序列 → DocxInjector.Block 序列(Phase 5)。
3字段塌缩(外视 #6):table.headers/caption、list.items/style 在渲染时显式丢弃,
4仅保留 DocxInjector.Block 支持的 (kind, text, level, rows)。
5"""
6from __future__ import annotations
8from genesis.writer.docx_injector import Block
9from genesis.writer.models import ChapterContent
12def render_chapter_blocks(content: ChapterContent) -> list[Block]:
13 out: list[Block] = []
14 for b in content.blocks:
15 if b.type == "heading":
16 out.append(Block(kind="heading", text=b.text or b.caption or "", level=b.level or 1))
17 elif b.type == "table":
18 out.append(Block(kind="table", text=b.caption or "", rows=b.rows or []))
19 elif b.type == "list":
20 out.append(Block(kind="list", text="\n".join(b.items or [])))
21 elif b.type == "note":
22 out.append(Block(kind="note", text=b.text or b.caption or ""))
23 else: # paragraph 及未知类型
24 out.append(Block(kind="paragraph", text=b.text or b.caption or ""))
25 return out