效果优化

This commit is contained in:
董宏凯 committed 2026-05-19 18:10:15 +08:00
1 parent 2402a84c71
commit ab85e4df72
15 files changed
+548 -35

No files matched your search

@@ -58,6 +58,37 @@ function SectionThinking({ thinkingText, isDone }: { thinkingText: string; isDon
);
}
/** 章节正文:把 `### 要点` 行渲染成小标题,其余按段落显示(流式纯文本,非完整 markdown 解析) */
function SectionBody({ text, showCursor }: { text: string; showCursor: boolean }) {
const lines = text.split('\n');
return (
<div className="m-0">
{lines.map((line, i) => {
// 严格模式下作家声明素材不足的哨兵行,不展示给用户
if (line.includes('[[SECTION_BLOCKED]]')) return null;
const heading = /^[ \t]*#{1,6}[ \t]+/.exec(line);
if (heading) {
return (
<p key={i} className="text-xs font-semibold text-foreground mt-2 mb-1">
{line.slice(heading[0].length)}
</p>
);
}
if (!line.trim()) return null; // 跳过空行,避免大段空白
return (
<p
key={i}
className="text-xs leading-relaxed text-foreground/90 whitespace-pre-wrap m-0 mb-1"
>
{line}
</p>
);
})}
{showCursor && <TypewriterCursor />}
</div>
);
}
export function DraftStreamingView({ title, sections }: DraftStreamingViewProps) {
const bottomRef = useRef<HTMLDivElement>(null);
@@ -91,11 +122,11 @@ export function DraftStreamingView({ title, sections }: DraftStreamingViewProps)
{/* 该章节的思考过程(可折叠) */}
<SectionThinking thinkingText={sec.thinkingText} isDone={sec.isDone} />
{/* 正文内容 */}
<p className="text-xs leading-relaxed text-foreground/90 whitespace-pre-wrap m-0">
{sec.text}
{sec.sectionIndex === activeSectionIdx && !sec.isDone && <TypewriterCursor />}
</p>
{/* 正文内容(### 要点行渲染为小标题) */}
<SectionBody
text={sec.text}
showCursor={sec.sectionIndex === activeSectionIdx && !sec.isDone}
/>
</div>
))}