Skip to content

fix(ui): 修复回答代码围栏嵌套与 CRLF 解析 - #110

Open
Bluuok wants to merge 2 commits into
helsome:mainfrom
Bluuok:fix/answer-fence-boundaries
Open

Bluuok wants to merge 2 commits into
helsome:mainfrom
Bluuok:fix/answer-fence-boundaries

Conversation

@Bluuok

@Bluuok Bluuok commented Sep 16, 2026

Copy link
Copy Markdown

改动说明

What

  • folio-block 解析器识别反引号和波浪线围栏,并要求关闭围栏使用相同字符且长度不少于开启围栏。
  • 解析普通 Markdown 代码围栏的边界后再识别内部内容,避免代码示例中的 folio-block 被当成真实结构化回答块。
  • 对 CRLF 输入只在围栏判断时剥离 \r,保留返回文本和 block body 的原始内容,并补充边界和流式场景测试。

Why

原实现会在扫描文本时把普通代码围栏中的 folio-block 示例误识别为真实 block;同时只支持固定长度的反引号和 LF 形式的关闭行,导致嵌套示例、不同围栏长度和 CRLF 内容的呈现边界不稳定。

关联 Issue

Related to #31;follow-up to merged PR #81 的 typed folio-block 渲染路径。

测试报告(正式审核前必填)

环境

  • Bun:1.4.0
  • OS:Microsoft Windows 11 家庭版 中文版

实际执行命令与结果

bun test --isolate packages/ui/src/components/chat/blocks/parseAnswerSegments.test.ts packages/ui/src/components/chat/blocks/parseAnswerSegments.fences.test.ts
→ 16 pass / 0 fail,20 expect() calls

bun test packages/ui --isolate
→ 309 pass / 0 fail,51 files,1009 expect() calls

bun run typecheck
→ core / i18n / shared / ui / electron 全部 exit 0

git diff --check
→ exit 0,无输出

已知失败 / Baseline(如有)

  • 无已知测试失败;UI workspace 全量测试在本分支通过。

  • 仓库 CI 固定使用 Bun 1.4.2;本地实际使用 Bun 1.4.0,Bun 1.4.2 的 CI 结果待 GitHub Actions 复核。

  • 已提供实际测试命令与 pass/fail 结果

  • 已说明测试环境

  • 如果存在已知 baseline / 环境失败,已提供 main 对照或说明

  • 核心改动已有对应 focused test / smoke / integration 验证

UI 截图(仅可见 UI 变化时必填)

  • 本 PR 无可见 UI 变化(无需截图)
  • 本 PR 有可见 UI 变化,已提供修改后的 UI 截图
  • 已提供 Before / After 对比截图(适用时)

Before(适用时)

错误行为:普通代码围栏内的 folio-block 示例被误识别并渲染为 123.45 美元卡片。

Before:嵌套 folio-block 被错误渲染

After(适用时)

修复行为:嵌套示例保留为代码文本,真实顶层 folio-block 仍渲染为 182.31 美元结构化 block。

After:仅真实顶层 folio-block 被渲染

Scope / 后续

  • 本 PR 只调整回答分段器及其测试,不改 Markdown 渲染器、block schema 或 UI 样式。
  • PR 保持 Draft,正式审核前仍需补充真实 Electron Before / After 截图与一次实际 UI smoke 验证。

@Bluuok
Bluuok marked this pull request as ready for review September 16, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant