v0.8: Serper 集成 + H1 章节标题双行居中 + 反方证据观点化 + 术语核查命令
新增:Google 系检索(SerpAPI → Serper.dev) - scripts/lib/serper_client.py:封装 serper.dev 的 Google Search / Scholar / News / Patents - 专利检索用 site:patents.google.com 技巧,serper.dev 没专用 endpoint 但效果很好 - Scholar 带引用数、年份、期刊信息,便于权威信源识别 - News 支持 time_range(d/w/m/y)时效性过滤 - scripts/lib/search_client.py 扩展为多路由门面: - search() 通用:Exa → Tavily - patents() 专利:Serper(Google Patents)→ 通用搜索 + site: 兜底 - scholar() 论文:Serper Scholar → 通用搜索兜底 - news() 新闻:Serper News → 通用搜索兜底 - 所有 httpx 客户端 trust_env=False,绕过系统 socks5 代理(v0.6 修过的 TLS EOF) - .opencode/skills/search-strategy/SKILL.md §三重写:按查询类型路由,明确何时用哪个 API H1 章节标题:两行居中 + 装饰横线 - 新增 ParagraphStyle: h1-chapter-num / h1-chapter-title - 新增 parse_chapter_title() 支持中文/阿拉伯/混合空格章号: "第一章" / "第 9 章" / "第6章" / "Chapter 1" 全覆盖 - 分隔符支持: em dash — / en dash – / - / : / : - 新增 build_chapter_header():章号小字居中 + 章名大字深蓝居中 + HRFlowable 3cm 装饰线 - 只对正文章节(_title_kind == "chapter")启用;前置件(免责声明/执行摘要/术语表/目录) 仍用单行 h1 样式 反方证据段规范化(用户反馈 v0.7 问题 #5) - skill:evidence-table 新增 §"正文中反方证据段落的写作规范": - 禁止机械标题"反驳证据" / "Counter-Evidence" / "反方观点" - 必须观点化,包含具体判断(如"另一种声音:管线虚胖还是真实进展?") - 用 H2 或 H3,禁止加粗段冒充标题 - 给出段落结构模板(1-2 句过渡 → 列表型反方论点 → 整合判断) - dr-analyst.md Hard Rules #3 改为引用该规范 术语表事实核查前置(新 command /dr-glossary) - 新增 .opencode/commands/dr-glossary.md,支持 --from phase1|phase2|phase4 三个时机 - Phase 1 末 / Phase 2 初:从 framework.md 抽取专有名词种子表,在 dr-analyst 起草前 预先核查公司名/产品名/技术名拼写,避免编造错误(Mabwell → Maywavee 这类) - Phase 4:维持当前用法,对 glossary.json 全量核查 实测:dual-target-rnai-pipeline-2026 重生 PDF 55 页,所有 10 章标题双行居中正确渲染 (第一章/第二章/... 第十章 / 第 6 章 / 第 9 章 多种形式都识别)。
This commit is contained in:
@@ -49,6 +49,7 @@ try:
|
||||
Table,
|
||||
TableStyle,
|
||||
)
|
||||
from reportlab.platypus.flowables import HRFlowable
|
||||
except ImportError:
|
||||
print("ERROR: missing reportlab. Run: uv sync", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -159,7 +160,7 @@ def build_styles() -> StyleSheet1:
|
||||
allowOrphans=0,
|
||||
))
|
||||
|
||||
# H1 (chapter) - page break before, deep blue
|
||||
# H1 (chapter) - page break before, deep blue (used for 前置件标题如"免责声明")
|
||||
ss.add(ParagraphStyle(
|
||||
name="h1",
|
||||
fontName="SrcSans-Bold",
|
||||
@@ -173,6 +174,35 @@ def build_styles() -> StyleSheet1:
|
||||
wordWrap="CJK",
|
||||
))
|
||||
|
||||
# H1 章号(正文章节第一行):小字号居中,浅色
|
||||
ss.add(ParagraphStyle(
|
||||
name="h1-chapter-num",
|
||||
fontName="SrcSans-Medium",
|
||||
fontSize=13,
|
||||
leading=20,
|
||||
alignment=TA_CENTER,
|
||||
spaceBefore=18,
|
||||
spaceAfter=6,
|
||||
textColor=colors.HexColor("#6b7280"),
|
||||
letterSpacing=3, # 章号加字距,视觉更稳
|
||||
keepWithNext=1,
|
||||
wordWrap="CJK",
|
||||
))
|
||||
|
||||
# H1 章名(正文章节第二行):大字号居中加粗深蓝
|
||||
ss.add(ParagraphStyle(
|
||||
name="h1-chapter-title",
|
||||
fontName="SrcSans-Bold",
|
||||
fontSize=20,
|
||||
leading=32,
|
||||
alignment=TA_CENTER,
|
||||
spaceBefore=0,
|
||||
spaceAfter=12,
|
||||
textColor=colors.HexColor("#1e3a8a"),
|
||||
keepWithNext=1,
|
||||
wordWrap="CJK",
|
||||
))
|
||||
|
||||
# H2 (section) - blue, no page break, keep with next
|
||||
ss.add(ParagraphStyle(
|
||||
name="h2",
|
||||
@@ -612,6 +642,62 @@ def md_inline_to_rl(text: str, *, add_cjk_space: bool = True) -> str:
|
||||
return text
|
||||
|
||||
|
||||
# H1 正文章节标题解析:拆成(章号, 章名)
|
||||
# 支持:
|
||||
# 第一章 — 为何... → ("第一章", "为何...")
|
||||
# 第 9 章:四大监管向量... → ("第 9 章", "四大监管向量...")
|
||||
# 第6章 — 固定化... → ("第6章", "固定化...")
|
||||
# 第十章 — 制造体系... → ("第十章", "制造体系...")
|
||||
# Chapter 1: Why the Second... → ("Chapter 1", "Why the Second...")
|
||||
# 分隔符:—(em dash) / –(en dash) / - / : / : / 空白多于一处
|
||||
_CHAPTER_HEAD_RE = re.compile(
|
||||
r"^\s*"
|
||||
r"(?P<num>(?:第\s*[一二三四五六七八九十百零〇两廿卅\d]+\s*章)|(?:Chapter\s+\d+))"
|
||||
r"\s*[—–\-::]\s*"
|
||||
r"(?P<title>.+?)\s*$",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
def parse_chapter_title(raw: str) -> tuple[str, str] | None:
|
||||
"""解析章节标题。命中返回 (章号, 章名),否则 None。"""
|
||||
m = _CHAPTER_HEAD_RE.match(raw.strip())
|
||||
if not m:
|
||||
return None
|
||||
num = m.group("num").strip()
|
||||
title = m.group("title").strip()
|
||||
if not title:
|
||||
return None
|
||||
# 规范化章号空白:"第 6 章" 保留"第 6 章","第6章"保留"第6章"
|
||||
num = re.sub(r"\s+", " ", num)
|
||||
return num, title
|
||||
|
||||
|
||||
def build_chapter_header(raw_title: str, styles: StyleSheet1) -> list:
|
||||
"""生成正文章节标题:两行居中 + 装饰横线。
|
||||
|
||||
解析失败时 fallback 到普通 h1 样式。
|
||||
"""
|
||||
parsed = parse_chapter_title(raw_title)
|
||||
if parsed is None:
|
||||
return [Paragraph(md_inline_to_rl(raw_title), styles["h1"])]
|
||||
|
||||
num, title = parsed
|
||||
return [
|
||||
Paragraph(md_inline_to_rl(num), styles["h1-chapter-num"]),
|
||||
Paragraph(md_inline_to_rl(title), styles["h1-chapter-title"]),
|
||||
# 装饰横线:居中、宽度约 3cm(视觉重量跟两行标题平衡)
|
||||
HRFlowable(
|
||||
width=3 * cm,
|
||||
thickness=1.2,
|
||||
color=colors.HexColor("#1e3a8a"),
|
||||
spaceBefore=2,
|
||||
spaceAfter=18,
|
||||
hAlign="CENTER",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Document builders
|
||||
# ============================================================
|
||||
@@ -1274,10 +1360,10 @@ def build_body(
|
||||
i = _skip_until_next_section(i + 1)
|
||||
continue
|
||||
|
||||
# H1 正文章节(chapter):PageBreak + h1 样式
|
||||
# H1 正文章节(chapter):PageBreak + 章号/章名双行居中 + 装饰线
|
||||
if block.kind == "h1":
|
||||
story.append(PageBreak())
|
||||
story.append(Paragraph(md_inline_to_rl(block.content), styles["h1"]))
|
||||
story.extend(build_chapter_header(block.content, styles))
|
||||
else:
|
||||
# H2 正文小节:h2 样式(不分页)
|
||||
story.append(Paragraph(md_inline_to_rl(block.content), styles["h2"]))
|
||||
|
||||
Reference in New Issue
Block a user