A Confluence Cloud macro for rendering Mermaid diagrams, built on Atlassian Forge. Side-project skeleton — not a published app.
manifest.yml— Forge app manifest. Declares one macro module + one resolver function.src/index.js— serverless resolvers (getMacroData/saveMacroData). Persist per-instance source + height in Forge KVS, keyed by the macro'slocalId.static/macro/— the React Custom UI that renders inside the macro iframe.src/index.jsx— entry; readscontext.extensionforisEditing+localId, callsgetMacroDatafor saved state, bootstraps the React tree with defaults if nothing is saved yet.src/App.jsx— view mode renders the diagram at the saved height; edit mode shows a Code/Split/Preview toolbar, a vertical splitter between editor and preview, a horizontal splitter for height, and Save/Revert actions.src/styles.css— Atlassian-aligned light theme (tokens, segmented control, primary/secondary buttons, error toast).
package.json(root) —@forge/resolver+@forge/kvs+ scripts for tunnel/deploy.static/macro/package.json— deps for the UI bundle (React + mermaid + Forge bridge).
- User inserts the macro on a Confluence page (
/Mermaid (custom)). - The iframe loads the React app.
view.getContext()returns the macro context —extension.isEditingtells us whether we're in view mode or edit mode, andextension.localIdis a stable per-instance key. - View mode — bootstrap calls
invoke('getMacroData', { localId })to load saved source + height (or falls back to defaults), then renders the SVG into the iframe. - Edit mode — a toolbar exposes a Code / Split / Preview toggle. The split layout has a vertical splitter to drag the editor/preview ratio and a horizontal splitter to resize total height. Every keystroke (debounced) re-renders the preview. Save calls
invoke('saveMacroData', { source, height, localId }), which writes to Forge KVS. Revert restores the last saved values. - We don't use
view.submit({ config })because the main view resource isn't submittable — that API only works from a Forge config resource (gear-icon dialog). KVS keyed bylocalIdgives us per-instance persistence without a config dialog.
- Live preview while editing — the official Mermaid macro renders only on save. Round trip is the main pain point.
- Code / Split / Preview toggle — pick the layout that fits the diagram you're editing instead of being locked into a fixed split.
- Resizable height and split ratio — saved per macro instance. Christian's specific complaint about Eraser.
- Errors don't blank the diagram — invalid syntax keeps the previous valid render visible alongside the error.
- No external service — the SVG is rendered in-browser by mermaid. Nothing leaves Atlassian's iframe.
Prereqs: Node 20+, an Atlassian account with permission to install private Forge apps.
npm install -g @forge/cli
forge login
forge register # writes the app id back to manifest.yml
cd static/macro && npm install && cd ../..
npm install
npm run tunnel # builds UI in watch mode + opens Forge tunnel
forge install --site <your-site>.atlassian.net --product confluenceOpen any Confluence page, type /Mermaid (custom), paste a diagram. Toggle between Code / Split / Preview, drag the splitters to resize, hit Save.
- Distribution —
forge installputs this on one site. Wider rollout means an org-level install (admin approval) or marketplace publication (review process). Fine for personal/team use. - Forge KVS quotas — generous for diagrams (per-key and per-app limits documented by Atlassian). Not a concern at human scale, but don't dump megabytes into a single macro.
- Mermaid version — pinned in
static/macro/package.json. Bump deliberately; Mermaid major versions occasionally break syntax. - Edit-mode lifecycle — Confluence's editor controls when the iframe mounts/unmounts; some keyboard shortcuts (e.g. Ctrl+S to save the page) may steal focus from the textarea. Workable, not perfect.
- Not a Markdown extension — Confluence does not expose its Markdown→ADF pipeline. A
\``mermaid` fence in a regular code block still renders as a code block. To get a diagram you insert this macro.
- D2 backend instead of (or alongside) Mermaid —
D2produces Eraser-quality output but requires server-side rendering. - Theme switch (dark/light) bound to Confluence's theme.
- Export to SVG/PNG button in view mode.
- Configurable default source per space.