DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

feat: support Mermaid diagram rendering in chat messages

Open ttmouse opened this issue 5 months ago • 3 comments

在对话消息中支持 ```mermaid fenced block 自动渲染为交互式 SVG 图表。

  • MermaidDiagram 组件(懒加载 mermaid、暗/亮主题自适应、三态渲染)
  • Markdown.tsx 集成,拦截 language-mermaid
  • SVG 内 <a> 链接通过 openExternal 打开
  • 对齐现有设计规范(CSS 变量、lucide-react 图标)

ttmouse avatar Jun 17 '26 10:06 ttmouse

image

ttmouse avatar Jun 17 '26 10:06 ttmouse

@codex review

ttmouse avatar Jun 17 '26 11:06 ttmouse

@codex review

ttmouse avatar Jun 18 '26 07:06 ttmouse

Resolved the merge conflicts by merging the latest main-v2 into this PR.

Conflict resolution notes:

  • Kept the current main-v2 MarkdownRenderer plain-status-block flow.
  • Re-applied Mermaid fenced-block rendering on top of that flow.
  • Kept the current main-v2 frontend dependency versions and preserved [email protected] in the lockfile.

Verified:

  • wails generate module passed
  • pnpm --dir desktop/frontend check:css passed
  • pnpm --dir desktop/frontend typecheck passed
  • pnpm --dir desktop/frontend exec tsx src/__tests__/math-golden.test.ts passed
  • pnpm --dir desktop/frontend exec tsx src/__tests__/typography-overflow-contract.test.ts passed
  • pnpm --dir desktop/frontend build passed

SivanCola avatar Jun 29 '26 06:06 SivanCola

Thanks @ttmouse. I consolidated this PR into #5554 so the Mermaid work can land through one integration branch instead of merging the overlapping Mermaid PRs independently.

What was kept/adapted from this PR:

  • scoped mermaid fenced-block routing from MarkdownRenderer
  • lazy Mermaid loading
  • serialized Mermaid render queue
  • theme re-rendering
  • SVG sanitization and external-link routing
  • keeping Mermaid bindFunctions disabled for untrusted chat content

#5554 also adds the source/preview, zoom/pan, fullscreen UX from the related PR and dedicated Mermaid regression/browser DOM coverage.

Verified on #5554:

  • pnpm --dir desktop/frontend check:css
  • pnpm --dir desktop/frontend typecheck
  • pnpm --dir desktop/frontend exec tsx src/__tests__/mermaid-rendering.test.tsx
  • pnpm --dir desktop/frontend test
  • pnpm --dir desktop/frontend build
  • GitHub CI is green

Closing this PR as superseded by #5554. Your contribution is credited there.

SivanCola avatar Jun 29 '26 07:06 SivanCola