Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

forge-mermaid-macro

A Confluence Cloud macro for rendering Mermaid diagrams, built on Atlassian Forge. Side-project skeleton — not a published app.

What's in here

  • 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's localId.
  • static/macro/ — the React Custom UI that renders inside the macro iframe.
    • src/index.jsx — entry; reads context.extension for isEditing + localId, calls getMacroData for 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).

How it works

  1. User inserts the macro on a Confluence page (/Mermaid (custom)).
  2. The iframe loads the React app. view.getContext() returns the macro context — extension.isEditing tells us whether we're in view mode or edit mode, and extension.localId is a stable per-instance key.
  3. View mode — bootstrap calls invoke('getMacroData', { localId }) to load saved source + height (or falls back to defaults), then renders the SVG into the iframe.
  4. 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.
  5. 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 by localId gives us per-instance persistence without a config dialog.

Why this should be less clumsy than the existing macros

  • 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.

Run it locally

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 confluence

Open any Confluence page, type /Mermaid (custom), paste a diagram. Toggle between Code / Split / Preview, drag the splitters to resize, hit Save.

Caveats / known limits

  • Distribution — forge install puts 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.

Possible follow-ups

  • D2 backend instead of (or alongside) Mermaid — D2 produces 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages