Pre-render Mermaid diagrams to committed SVG so they display in Bitbucket Cloud, which has never supported ```mermaid fenced blocks natively. Use this skill whenever someone mentions Mermaid, .mmd or .mermaid files, or diagrams-as-code in the context of Bitbucket — including "my diagram shows as raw code in Bitbucket", "the README renders on GitHub but not Bitbucket", "our diagram labels are invisible/blank", "add a docs diagram check to Pipelines", or any migration of docs from GitHub/GitLab to Bitbucket. Also use it when converting a single .mmd file to SVG, since the naive `mmdc -i x.mmd -o x.svg` produces an SVG whose text disappears in Bitbucket.
Ships in mermaid-svg-bitbucket. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Bitbucket Cloud does not render Mermaid in Markdown. GitHub and GitLab do; Bitbucket does not, and the request has sat open as BCLOUD-21675 for years. A ```mermaid block in a Bitbucket README shows as raw source.
The workaround is to pre-render each diagram to an SVG, commit it, and reference it as
a normal Markdown image. The .mmd source stays in the repo as the thing you edit and
review; the SVG is a build product that happens to be committed.
There are browser extensions and Marketplace apps that render Mermaid in Bitbucket client-side. Mention them as an option if it fits (they're less work), but they only help people who install them — the diagram stays broken for everyone else, which is usually why someone is asking for this in the first place.
By default Mermaid puts label text inside <foreignObject> elements, which hold real
HTML. That works when Mermaid runs as JavaScript in a page. It does not work when
a browser loads the SVG through an <img> tag — which is exactly how Markdown embeds
images. Foreign content isn't painted in that context, so you get a diagram with
correct boxes and arrows and no text in any of them.
This is the single most common failure, and it is silent: mmdc reports success, the
SVG opens fine in a local viewer and in a browser tab, and it is blank-labelled only
in the README. Anyone who converts diagrams by hand hits it and concludes SVG doesn't
work in Bitbucket.
The fix is htmlLabels: false, which makes Mermaid emit real <text> elements.
assets/mermaid-config.json sets it. scripts/render_mermaid.py also greps the
output and hard-fails if a <foreignObject> survives — a diagram can re-enable
htmlLabels with an inline %%{init}%% directive.
--check actually verifiesThree separate claims, and only the first of them is green. A run exits 0 when every diagram's SVG was compared against a hash and matched — nothing weaker earns it.
| State | Meaning | Exit |
|---|---|---|
| up to date | source hash matches and the SVG's bytes match the svgHash recorded when it was rendered | 0 |
UNVERIFIED | source hash matches, but the manifest predates version: 2 so there is no svgHash to compare. The SVG passed a structural check only: non-empty, contains an <svg element, ends with a closing tag | 1 |
STALE / DAMAGED | the source moved, or the SVG is missing, corrupt, truncated or empty | 1 |
UNVERIFIED and DAMAGED share an exit code and are not the same finding. DAMAGED
says the SVG is provably not the one that was rendered. UNVERIFIED says nothing about
the SVG at all — there is no recorded hash to judge it by. The output keeps them in
separate sections and says so in as many words, so nobody goes hunting a corruption
that is not there.
Until manifest version 2 this check did not open the SVG at all. current was
manifest hash == digest(source) and svg.exists() — both halves about the source and
the file's presence. A committed SVG truncated or emptied after rendering passed as
up to date. That was measured, not theorised: a real 15,902-byte render cut in half
mid-attribute, and a zero-byte file, each printed All 1 diagram(s) up to date. and
exited 0. skills/mermaid-svg-bitbucket/tests/ damages a genuine render and asserts
both now fail.
Upgrading is not automatic, and it turns your build red once. A manifest predating
version: 2 reports UNVERIFIED for every diagram and exits 1. Run
render_mermaid.py --force once, commit the re-rendered SVGs and the rewritten
manifest, and it is green from then on. --force is not optional here: the source
hash already matches, so a plain run counts those diagrams as unchanged and never
reaches the code that records a hash.
That red replaced an exit 0 in 1.2.2, and the reason is the one this whole check exists for. A structurally-intact SVG with no recorded hash is the strongest claim the tool can honestly make — which is an argument for saying so loudly, not for passing. A green CI line that means less than its reader assumes is exactly the defect 1.2.0 fixed; shipping a weaker green under the same name reintroduces it in the fix. The summary still never says "All N up to date" while anything is unverified, and now the exit code agrees with it.
Rendering needs mmdc (@mermaid-js/mermaid-cli), which drives headless Chromium:
npm install -g @mermaid-js/mermaid-cli
The script falls back to npx --yes @mermaid-js/mermaid-cli if mmdc isn't on PATH.
Only rendering needs it — --check runs on bare Python: it compares hashes and
reads the committed SVGs, but never invokes mermaid.
On Windows the launcher is mmdc.cmd, and the script invokes it by absolute path.
That is not cosmetic. shutil.which finds mmdc.cmd because it consults PATHEXT;
subprocess without a shell does not, because CreateProcess searches PATH for the
literal name and name + .exe only. Passing the bare string mmdc therefore died
with WinError 2 on machines where mermaid-cli was installed — and the install
message above never printed, because which had already succeeded. resolve_mmdc()
now returns the path which resolved, for the npx fallback as well, and a launcher
that resolves but cannot be spawned reports as a missing tool with that message rather
than as a traceback.
Copy these into the target repo and commit them, so the pipeline and every developer run the same renderer:
scripts/render_mermaid.py
scripts/puppeteer-config.json
assets/mermaid-config.json
The config is what makes the output Bitbucket-safe, so it has to travel with the
script. The script finds it automatically in assets/, .mermaid/, or the repo root;
anywhere else needs --config.
From the repo root:
python3 scripts/render_mermaid.py .
This walks the tree and:
.mmd / .mermaid files in place (docs/topology.mmd → docs/topology.svg).md files, writes each block out to a sidecar .mmd
under docs/diagrams/, and replaces the block with .mermaid-svg.json,
so re-runs skip unchanged sources and --check can tell whether the committed
SVG is still the one that was rendered
diagramsUseful flags: --out-dir (where extracted sources land), --no-rewrite (render only,
never touch Markdown), --force (ignore hashes), --check (verify, write nothing),
--background (defaults to #ffffff).
Point it at specific files instead of . when working incrementally:
python3 scripts/render_mermaid.py README.md docs/runbooks/
The rewrite is lossy in one specific way that matters, so say it out loud rather than
letting them discover it in a diff: the fenced block is removed from the .md and
the source of truth moves to the sidecar .mmd file. Editing the diagram means
editing the .mmd and re-running the script.
This is deliberate. The alternative — keeping the fenced block and adding an image
next to it — makes Bitbucket display the raw source and the picture, which is worse
than what they started with. Bitbucket also strips raw HTML in Markdown, so the usual
<details> collapse trick isn't available.
Consequence worth flagging: it's a one-way move for that file. If the repo is mirrored
to GitHub, or might migrate back, the diagrams will no longer be live Mermaid there —
they'll be images. If that's a real concern, --no-rewrite plus keeping the sidecar
.mmd files as the only diagram home is the cleaner shape.
The rewrite is idempotent: after the first pass there are no fenced blocks left to match, so re-runs only re-render changed sources.
assets/bitbucket-pipelines.snippet.yml has two strategies. Default to verify
(--check on PRs, fails if a committed SVG is stale) unless they specifically want
auto-commit. Verify needs no credentials, can't loop, and puts the rendered diff in
front of a reviewer. Auto-commit needs a write-capable access key and a [skip ci]
guard, and hides diagram changes from review.
A local SVG viewer will not reproduce the <img> sandbox. The only real check is
pushing to a branch and looking at the file in Bitbucket's UI. Tell them to confirm
label text is visible before closing this out.
Bitbucket has a dark UI. An SVG loaded via <img> can't see the page theme, and a
transparent background with dark text renders as dark-on-dark — invisible.
So the default is an opaque white background (--background '#ffffff') with the fixed
light palette in assets/mermaid-config.json. On a dark Bitbucket the diagram reads
as a white card. That's slightly less elegant than a theme-aware diagram and it is
reliably legible for everyone, which is the tradeoff worth making for docs.
Don't reach for @media (prefers-color-scheme: dark) inside the SVG. It does
evaluate in modern browsers, but against the OS setting, not Bitbucket's theme
setting — so anyone running a light Bitbucket on a dark OS gets a dark diagram on a
white page. references/bitbucket-gotchas.md covers the dual-render alternative if
they insist.
assets/mermaid-config.json uses theme: base with explicit themeVariables, tuned
to Atlassian's palette so diagrams don't clash with Bitbucket's chrome. Roughly six
variables carry the look: primaryColor, primaryTextColor, primaryBorderColor,
lineColor, fontFamily, fontSize. Change those first.
Keep fontFamily to a websafe stack. Mermaid measures text in Chromium at render
time to size the boxes, but the viewer's browser paints it — if the font isn't
present on both sides, text overflows its box. The default
Helvetica Neue, Helvetica, Arial, sans-serif is near-universal and matches
Liberation Sans metrics in CI containers.
Any config edit changes the fingerprint in the manifest, so the next run re-renders everything. That's intended.
references/bitbucket-gotchas.md — the full list of Bitbucket Cloud Markdown/SVG
quirks: image path rules, <image> href stripping, encoding failures that break
README rendering entirely, sizing, and the dual-render dark mode option. Read it when
a diagram renders wrong in Bitbucket but looks fine locally, or when the README won't
render at all.
assets/bitbucket-pipelines.snippet.yml (opens in a new tab)assets/mermaid-config.json (opens in a new tab)references/bitbucket-gotchas.md (opens in a new tab)scripts/puppeteer-config.json (opens in a new tab)scripts/render_mermaid.py (opens in a new tab)tests/fixtures/sample.mmd (opens in a new tab)tests/fixtures/sample.svg (opens in a new tab)tests/test_check_reads_the_svg.py (opens in a new tab)tests/test_resolve_mmdc_uses_the_resolved_path.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/mermaid-svg-bitbucket:mermaid-svg-bitbucketfrom mermaid-svg-bitbucket
npx claudepluginhub mbadali25/useful-claude-add-ons --plugin mermaid-svg-bitbucket