Skip to content

feat: Mermaid diagram rendering (#3)#22

Open
SyNeto wants to merge 1 commit into
devfrom
issue/3-mermaid
Open

feat: Mermaid diagram rendering (#3)#22
SyNeto wants to merge 1 commit into
devfrom
issue/3-mermaid

Conversation

@SyNeto
Copy link
Copy Markdown
Owner

@SyNeto SyNeto commented May 12, 2026

Summary

Renders ```mermaid fenced code blocks as SVG diagrams using Mermaid v11, fully offline.

  • New src/mermaid-renderer.ts — finds pre code.language-mermaid blocks, calls mermaid.render(), replaces each <pre> with the resulting SVG
  • Respects prefers-color-scheme — initializes Mermaid with theme: 'dark' or 'default'
  • content.ts skips hljs.highlightElement() on mermaid blocks
  • type-fest installed to satisfy Mermaid's type declarations (avoids skipLibCheck)
  • Rollup: inlineDynamicImports: true to produce a single IIFE (Mermaid has internal dynamic imports incompatible with IIFE code-splitting)
  • Browser targets bumped: chrome120 / firefox128

Bundle size

Before After
content.bundle.js 176 KB 3.2 MB

Size increase is expected — Mermaid is a large library. Lazy loading optimization tracked separately.

Diagram types tested

flowchart, sequenceDiagram, gitGraph, stateDiagram-v2, pie

Known limitation

gist.githubusercontent.com serves content in a sandboxed frame that blocks script execution — Mermaid (and the extension itself) cannot run there. file:// and raw.githubusercontent.com work correctly.

Closes #3

- Add src/mermaid-renderer.ts — initializes mermaid with light/dark theme,
  finds pre code.language-mermaid blocks and replaces them with SVG
- Import renderMermaidBlocks statically in content.ts; skip hljs on mermaid blocks
- Add type-fest dev dependency to satisfy mermaid's type declarations
- Rollup: inlineDynamicImports:true for IIFE format (mermaid has internal
  dynamic imports); bump targets to chrome120/firefox128
- tsconfig: remove skipLibCheck (type-fest satisfies the dependency properly)
- Manifests: remove type:module (not needed with IIFE format)

Lazy loading deferred to a future optimization — see issue for notes.

Closes #3
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