Skip to content

fix: centre mermaid diagrams in their container - #64

Merged
oto-macenauer-absa merged 1 commit into
masterfrom
fix/centre-mermaid-diagrams
Aug 14, 2026
Merged

fix: centre mermaid diagrams in their container#64
oto-macenauer-absa merged 1 commit into
masterfrom
fix/centre-mermaid-diagrams

Conversation

@oto-macenauer-absa

@oto-macenauer-absa oto-macenauer-absa commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #62. It touches the same DOC_CSS block and the regenerated fixture doc.css, so branching off master would have conflicted. The diff narrows once #62 merges.

What

.mp-doc pre.mermaid already sets text-align: center. It never worked for narrow diagrams, because mermaid gives the <svg> it swaps in display: block — and a block box ignores its parent's text-align. Wide diagrams filled the column so it looked fine; narrow ones sat flush left.

Measured in the browser, 800px reading column, before:

diagram svg width space left space right
flowchart (wide) 758px 21px 21px
second diagram 228px 21px 551px

After: left: 275px, right: 275px.

Changes

One line, in actions/publish-single-page-docs/src/template.js (DOC_CSS):

.mp-doc pre.mermaid svg { max-width: 100%; height: auto; display: block; margin-inline: auto; }

plus the regenerated test fixture doc.css that mirrors it.

Docs published by an earlier version of the action keep their existing stylesheet until they re-publish.

Verification

npm run build:headless               → 8 apps integrated
npx playwright test build-integrity  → 29 passed

Centring itself is verified by browser measurement (the table above), not by a test: the committed fixture stubs mermaid with a no-op — the real bundle is 2.5 MB and is deliberately not committed — so a fixture-based layout assertion would pass without ever rendering an SVG.

Closes #63

pre.mermaid already sets text-align:center, but mermaid gives the <svg>
it swaps in display:block, and a block box ignores text-align. A diagram
narrower than the reading column therefore sat flush left: measured at
21px from the left edge with 551px of space on the right.

Centred with margin-inline:auto instead.

The rule lives in the action's doc.css, so it applies to bundles
published from here on. Docs published by an earlier version of the
action keep their existing stylesheet until they re-publish.

Closes #63

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QqFK6yffibtCBTF8xZ4hXW
@oto-macenauer-absa
oto-macenauer-absa force-pushed the fix/centre-mermaid-diagrams branch from bf6a52f to 039f091 Compare August 14, 2026 12:32
@oto-macenauer-absa
oto-macenauer-absa merged commit 28ad539 into master Aug 14, 2026
8 checks passed
@oto-macenauer-absa
oto-macenauer-absa deleted the fix/centre-mermaid-diagrams branch August 14, 2026 12:44
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.

Mermaid diagrams are left-aligned, not centred, in their container

1 participant