Skip to content

feat(editor): render Mermaid diagrams in code blocks with live preview - #9787

Open
Liewzheng wants to merge 2 commits into
makeplane:masterfrom
Liewzheng:feat/editor-mermaid
Open

feat(editor): render Mermaid diagrams in code blocks with live preview#9787
Liewzheng wants to merge 2 commits into
makeplane:masterfrom
Liewzheng:feat/editor-mermaid

Conversation

@Liewzheng

Copy link
Copy Markdown

Description

Renders Mermaid diagrams in the editor: a code block with language mermaid gets a live diagram preview below the (still editable) code — GitHub/Notion-style UX. Works in work item descriptions, comments, and pages; read-only surfaces (peek overview, space pages) render automatically via the same node view.

Implementation:

  • Zero schema change — detection on the existing code-block node (language-mermaid), so Markdown round-trip, HTML export and yjs collaboration are untouched; server-side nh3 sanitization already allows language-* classes.
  • mermaid is loaded via dynamic import() only when a mermaid block is visible (~350KB gzip stays out of the main bundle; SSR-safe since node views are client-only).
  • Theme-following via data-theme attribute + MutationObserver; render errors show source + parser message; source changes (including remote collaboration edits) re-render debounced at 400ms.
  • New slash command "Diagram" inserts a mermaid code block. Pure helpers (isMermaidLanguage / getMermaidTheme / formatMermaidError) live in @plane/utils with 10 unit tests.

Note: the slash-menu label is hardcoded English like every other label in command-items-list.tsx (the editor package has zero i18n wiring and is imported by the Node live server); i18n keys are staged in editor.json for a future wiring PR.

Type of Change

  • Feature (non-breaking change which adds functionality)

Test Scenarios

  • check:types for editor/utils/i18n/web; builds for editor/utils; new vitest suite 10/10; lint clean on touched files.
  • Verified that the built editor bundle keeps import("mermaid") external (code-split chunk, loaded on demand).

References

- New MermaidDiagram component: lazy dynamic import of mermaid, theme-aware
  rendering following the editor's data-theme attribute, debounced re-render
  on source/theme changes, graceful error state showing source + message
- Code block NodeView renders the diagram below the editable code when
  language is mermaid
- Slash commands: new Diagram item that inserts a mermaid code block
- Pure helpers (isMermaidLanguage, getMermaidTheme, formatMermaidError) in
  @plane/utils with vitest coverage
- i18n: slash_commands.diagram keys in editor.json for all locales (en and
  zh-CN translated, others fall back to English)
- Styles for the mermaid container, loading and error states

Note: committed with --no-verify because the pre-commit lint-staged oxfmt
step was SIGKILLed by the environment (tmpfs/inode pressure in /tmp), not
because of a formatting failure — oxfmt --check passes on all changed files.
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 8, 2026

Copy link
Copy Markdown

◈ PR Lens

🟢 +3 new · 🟠 ~5 changed · 🔴 -0 removed · 1 flow · 15 files · commit 5ed7a76


Architecture

Architecture diagram for makeplane/plane at 5ed7a76

8 components touched across 2 lanes.

Open the interactive canvas


Inside the changed components — 1 view

Component view — Editor Diagram Extensions

Components and helpers that power Mermaid diagram insertion and live rendering in the editor.

Architecture view of Component view — Editor Diagram Extensions in makeplane/plane

Data flow

Data flow diagram for makeplane/plane at 5ed7a76

Inserting and rendering a Mermaid diagram

Open the interactive canvas


Drill down
Client Applications — 7 components
🟡 CHANGED Editor Core (@⁠plane/editor)

Core TipTap-based rich text editor package powering document editing across Plane applications.

🟡 CHANGED I18n Localization (@⁠plane/i18n)

Internationalization package providing translations across 20 languages for the /diagram slash command.

🟡 CHANGED Utility Helpers (@⁠plane/utils)

Shared helper package containing editor utilities, language checking, and Mermaid theme mappers.

🟡 CHANGED Slash Commands Menu

Command palette extension offering the /diagram option with localized titles and search terms.

🟡 CHANGED Code Block Node View

Custom TipTap NodeView for code blocks that mounts the Mermaid diagram preview when language is mermaid.

🟢 NEW Mermaid Diagram Component

React component managing debounced SVG rendering, dark/light theme switching, and syntax error alerts.

🟢 NEW Mermaid Helpers

Helper functions that check language tags, map DOM data-theme to Mermaid themes, and format parser errors.

External Dependencies — 1 component
🟢 NEW Mermaid.js

JavaScript diagramming library loaded dynamically on demand to render flowcharts and diagrams.


View

  • Architecture lens
  • Data flow lens
  • Expand every detail
  • Show unchanged neighbours

Tip

GitHub will not let you zoom an image in a comment. The link under each diagram opens it on an interactive canvas, where you can zoom, pan and step through the flow.

🪧 More tips
  • Run PR Lens on your own machine: npx skills add coldteadotai/pr-lens installs the agent skill. Then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Draw a diff before it is even a pull request: npx @coldtea/pr-lens-cli analyze --base origin/main reads the diff with your own model key, and npx @coldtea/pr-lens-cli render .pr-lens/graph.json draws the same lenses on your machine.
  • The boxes under View are live. Tick Architecture lens or Data flow lens to choose which diagrams appear, or Expand every detail to open every drill-down at once. The comment redraws in place a few seconds later.
  • Show unchanged neighbours lists the components this change did not touch alongside the ones it did, so the drill-down shows what the changed code sits next to.
  • The CLI's render picks up .github/pr-lens.yml automatically and applies your corrections (renames, exclusions, lane pins) at draw time.
  • Would you rather run it from CI on a key of your own? Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and a model key in your repository secrets, say GEMINI_API_KEY. The Action asks Gemini by default, or OpenAI and any endpoint speaking /chat/completions through its provider input.
  • PR Lens is free for open source. A star on the repository is what keeps it going.
  • Push a new commit and the whole comment re-renders for the new head. An older run never overwrites a newer one, so a slow render cannot put a stale diagram back.
  • The diagrams follow your GitHub theme, so dark mode gets the dark render and light mode the light one, and the moving dots show this pull request's data in motion.

◈ Rendered by PR Lens · crafted with ❤️ by the Coldtea team · Come say hi on Discord

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 79992ed9-7c36-4e0c-8bb3-36ee8a4d66e1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…errors (PLANE-7)

The error branch unmounted the canvas div, leaving containerRef null on the
next render pass — the effect bailed out before it could clear the error,
so a diagram that failed once could never re-render until the whole code
block was recreated.
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