Skip to content

fix(frontend): render mermaid diagrams in wiki pages - #5082

Open
pcbeingused333 wants to merge 2 commits into
Tencent:mainfrom
pcbeingused333:fix/wiki-render-mermaid
Open

pcbeingused333 wants to merge 2 commits into
Tencent:mainfrom
pcbeingused333:fix/wiki-render-mermaid

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Description

Wiki pages are rendered with marked and injected with v-html, so a ```mermaid fence stayed as plain code in the wiki browser even though the same diagram renders in chat.

  • wiki/wikiMermaid.ts: a marked renderer that emits ```mermaid fences as a pending <pre class="mermaid" data-mermaid="false"> block and leaves every other code fence on marked's default rendering. renderWikiMermaid() runs the existing renderMermaidInContainer over a container, lazily, and only if it holds a pending diagram.
  • WikiBrowser.vue: renderMarkdown() uses that renderer, and the reader, index and graph-drawer bodies call renderWikiMermaid() after each render (next to the existing hydrateProtectedFileImages calls). A small style keeps the SVG centred and within the page width.

The chat block chrome (header, expand button) is not reused: its styles live inside the chat-only typography mixin, so this keeps the wiki change small.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

Fixes #5076

Testing

npx tsx --test src/views/knowledge/wiki/wikiMermaid.test.ts (2 passing): a mermaid fence becomes a pending block with its source escaped, and other fences render exactly as before. The rendered wiki page was not checked in a browser.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (for Go: golangci-lint run --new-from-rev=origin/main ./...)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.)
  • Breaking changes are clearly called out in the description above

This change was prepared with the help of an AI assistant (Claude Code), and the author is responsible for the change.

🤖 Generated with Claude Code

Wiki pages are rendered with marked and v-html, so a ```mermaid fence
showed up as plain code. Emit mermaid fences as pending mermaid blocks and
run the existing renderMermaidInContainer over the reader, index and graph
drawer bodies after each render.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@yixian12580

Copy link
Copy Markdown

修改重新构建镜像后可以渲染mermaid流程图,但是如果点击编辑wiki页面,再保存(或取消),又不能渲染了,需要刷新之后才可以正常渲染
image

image

The reader body is behind v-if="!editingPage", so saving or cancelling an
edit mounts a fresh element whose protected images and mermaid diagrams are
pending again, but no watcher fired (cancel leaves renderedContent unchanged).
Extract refreshReaderBody() and run it when editing ends.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the report. Cause: the wiki reader body is rendered under v-if="!editingPage", so saving or cancelling an edit mounts a fresh element whose protected images and mermaid diagrams are pending again, and nothing re-ran those passes (on cancel the rendered content does not change, so the existing watcher never fires). Pushed a follow-up commit that extracts the existing refresh logic into a refreshReaderBody() helper and also runs it when editing ends.

This comment was drafted with Claude Code.

This branch has not been deployed

No deployments
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.

[Bug]: Mermaid 流程图在wiki页面无法渲染

2 participants