feat(writer): add template_mapper (ParsedTemplate -> ChapterSpec)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""模板 → 有序章节规格映射(Phase 5)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from genesis.writer.models import ChapterSpec
|
||||
|
||||
|
||||
def map_template(parsed) -> list[ChapterSpec]:
|
||||
"""按模板 Heading 层级顺序产出有序章节列表。
|
||||
|
||||
`parsed.chapters` 为 WordTemplateParser 产出的章节标记列表,
|
||||
每项含 chapter_id / title / section_placeholder 属性。
|
||||
"""
|
||||
specs: list[ChapterSpec] = []
|
||||
for ch in getattr(parsed, "chapters", []):
|
||||
specs.append(
|
||||
ChapterSpec(
|
||||
chapter_id=getattr(ch, "chapter_id", ""),
|
||||
title=getattr(ch, "title", ""),
|
||||
section_placeholder=getattr(ch, "section_placeholder", None),
|
||||
)
|
||||
)
|
||||
return specs
|
||||
Reference in New Issue
Block a user