fix: 修复样式问题

This commit is contained in:
Daniel
2026-04-07 19:09:09 +08:00
parent 780871e93c
commit 869e3b5976
4 changed files with 62 additions and 30 deletions

View File

@@ -56,7 +56,9 @@ SYSTEM_PROMPT = """
3) 只输出合法 JSONtitle, summary, body_markdown
4) **body_markdown 约束**:恰好 **5 个自然段**;段与段之间用一个空行分隔;**不要**使用 # / ## 标题符号;全文(正文)总字数 **不超过 500 字**(含标点);
5) title、summary 也要短:标题约 818 字;摘要约 4080 字;
6) JSON 字符串内引号请用「」或『』,勿用未转义的英文 "
6) 正文每段需首行缩进(建议段首使用两个全角空格「  」),避免顶格;
7) 关键观点需要加粗:请用 Markdown `**加粗**` 标出 2~4 个重点短语;
8) JSON 字符串内引号请用「」或『』,勿用未转义的英文 "
""".strip()
@@ -72,6 +74,8 @@ body_markdown 写法:
- 必须且只能有 **5 段**:每段若干完整句子,段之间 **\\n\\n**(空一行);
- **禁止** markdown 标题(不要用 #
- 正文总长 **≤500 字**,宁可短而清楚,不要写满废话;
- 每段段首请保留首行缩进(两个全角空格「  」);
- 请用 `**...**` 加粗 2~4 个关键观点词;
- 内容顺序建议:第 1 段交代在说什么;中间 3 段展开关键信息;最后 1 段收束或提醒(均须紧扣原文,勿乱发挥)。
""".strip()
@@ -759,6 +763,15 @@ class AIRewriter:
if re.search(r"(?m)^#+\s", body):
issues.append("正文请勿使用 # 标题符号,只用自然段")
if "**" not in body:
issues.append("关键观点未加粗(建议 2~4 处)")
paragraphs = [p.strip() for p in re.split(r"\n\s*\n", body) if p.strip()]
if paragraphs:
no_indent = sum(1 for p in paragraphs if not p.startswith("  "))
if no_indent >= max(2, len(paragraphs) // 2):
issues.append("正文缺少首行缩进(建议每段段首使用两个全角空格)")
if self._looks_like_raw_copy(source, body, lenient=lenient):
issues.append("改写与原文相似度过高,疑似未充分重写")
@@ -799,4 +812,29 @@ class AIRewriter:
def _format_markdown(self, text: str) -> str:
body = text.replace("\r\n", "\n").strip()
body = re.sub(r"\n{3,}", "\n\n", body)
return body.strip() + "\n"
paragraphs = [p.strip() for p in re.split(r"\n\s*\n", body) if p.strip()]
if not paragraphs:
return body.strip() + "\n"
# 若模型未加粗,兜底给第一段的核心短语加粗一次
merged = "\n\n".join(paragraphs)
if "**" not in merged:
first = paragraphs[0]
first_plain = first.lstrip("  ").strip()
phrase = re.split(r"[,。;:,:]", first_plain, maxsplit=1)[0].strip()
phrase = phrase[:14]
if len(phrase) >= 4 and phrase in first:
paragraphs[0] = first.replace(phrase, f"**{phrase}**", 1)
# 段首全角缩进:保持阅读习惯,避免顶格
out: list[str] = []
for p in paragraphs:
seg = p.strip()
if not seg:
continue
if seg.startswith("  "):
out.append(seg)
else:
out.append("  " + seg.lstrip())
return "\n\n".join(out).strip() + "\n"