Skip to content

web: draw Mermaid diagrams in rendered Markdown - #8620

Merged
unknwon merged 5 commits into
flamego-serverfrom
markdown-mermaid
Nov 16, 2026
Merged

unknwon merged 5 commits into
flamego-serverfrom
markdown-mermaid

Conversation

@unknwon

@unknwon unknwon commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Stacked on #8542.

Moving the pages to React dropped Mermaid: the server-rendered pages loaded it in the footer, and #8539 removed it with the other old assets, so ```mermaid code blocks showed as code everywhere. The old pages also only drew diagrams in Markdown files, never in wiki pages.

The shared Markdown component now draws Mermaid code blocks as diagrams, so they work in READMEs, Markdown files, wiki pages, issues, comments and release notes.

  • Mermaid is loaded only on pages that have a diagram. The main bundle grows by 1.5 kB (0.8 kB gzipped).
  • Diagrams render with securityLevel: "strict" in Mermaid's neo look, with the neo or neo-dark theme to follow the page, and use the page font (Geist).
  • A diagram that fails to draw is shown as a code block. Mermaid's own error graphic is turned off, since it is added to the end of the page.

Fixes #7409

Before After
README with a flowchart, a broken diagram and a diagram with a script in a label 0 diagrams, 3 code blocks 2 diagrams, the broken one as a code block
Wiki page with a sequence diagram Code block Diagram
Issue with a pie chart Code block Diagram
Script in a label (<img onerror>) and a javascript: click link Neither runs: no onerror attribute, no javascript: link

As before with Mermaid's strict mode, an <img> in a label is kept without its event handlers, so it shows as a broken image.

Screenshots

Wiki, before Wiki, after Wiki, after (dark)
Wiki page showing the diagram source Wiki page with a sequence diagram Wiki page with a sequence diagram in dark mode
README, before README, after Issue, after
README showing diagram sources README with a flowchart Issue with a pie chart

README with diagrams in dark mode

README with diagrams at desktop width

Diagram types in light and dark mode:

Diagram Light Dark
Flowchart Flowchart in light mode Flowchart in dark mode
Sequence diagram Sequence diagram in light mode Sequence diagram in dark mode
Pie chart Pie chart in light mode Pie chart in dark mode
Git graph Git graph in light mode Git graph in dark mode

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan.
  • I have added an entry to CHANGELOG.

Test plan

  1. moon run web:lint and tsc -b pass, and vite build puts Mermaid in separate chunks.
  2. Ran the pages with Vite against a server built from this branch, signed in, at 375px in light and dark mode and at 1280px, and checked the DOM: diagrams drawn, code blocks, script markers, and no horizontal scrolling. Also checked a wiki page with a flowchart with a subgraph, a sequence diagram with a note and a loop, a six-slice pie chart and a git graph in both modes. The same pages with web: serve all requests from Flamego and remove Macaron #8542's frontend draw no diagrams.

@unknwon
unknwon merged commit 51f4180 into flamego-server Nov 16, 2026
2 checks passed
@unknwon
unknwon deleted the markdown-mermaid branch November 16, 2026 14:13
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