Repository navigation
fix(markdown): center mermaid diagrams narrower than the content column - #470
Merged
Merged
Conversation
The diagram's <pre class="mermaid"> was meant to shrink to the diagram
and center itself with `width: fit-content` and `margin: auto`. flame's
global `pre { width: inherit !important }` overrides that width, so the
<pre> spans the column and every narrower diagram sat at the start.
- The <pre> now carries data-mermaid-align="center".
- styles.css centers the diagram's direct <svg> child as a block with
auto inline margins. Nested SVGs and the labels inside are untouched.
- No text-align, which Mermaid's HTML labels would inherit. No flex on
the <pre> either: Mermaid sizes a Gantt chart from a temporary element
inside it, and a flex item shrank that chart from 564px to 300px.
- The Mermaid docs note the alignment.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This review covers the fix that centers Mermaid diagrams that are narrower than the content column. It was a standard review with no findings. The fix sits in the stylesheet and does not touch Mermaid's layout or measurement.
- Centering hook: the
<pre class="mermaid">inMermaidMdxnow hasdata-mermaid-align="center". This works around flame's@layer utilities { pre { width: inherit !important } }, which beats the inlinewidth: fit-content. - Stylesheet rule:
pre[data-mermaid-align="center"] > svg { display: block; margin-inline: auto; }in@docubook/markdown/styles.css.- The
> svgcombinator is correct.mermaid.run({ nodes: [node] })replaces the contents of the<pre>, so the diagram SVG is a direct child of it. - Flame imports this sheet unlayered, so the rule wins over preflight's
svgdefaults. - The rule sets no
text-alignand does not make the<pre>a flex or grid container. That keeps Mermaid's HTML labels and its Gantt width measurement unchanged.
- The
- Regression test: the test reads the shipped stylesheet through
styles.css?raw, the same patternCodeBlockBleed.test.tsxuses (vitest.config.tsalready setscss.include). It checks that the rule matches the diagram's own SVG but not a nested one, and that the<pre>does not become flex or grid. - Docs and changeset: the Mermaid docs page has a note on alignment, and the changeset is an
@docubook/markdownpatch.
claude-opus-5-5 | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Mermaid diagrams narrower than the content column now render centered instead of flush left.
Cause
MermaidMdxgives its<pre class="mermaid">an inlinewidth: fit-contentandmargin: 1em auto, so the<pre>was meant to shrink to the diagram and center itself. flame'sglobals.csssetspre { width: inherit !important }, which overrides that width. The<pre>spans the column,margin: autodoes nothing, and the SVG sits at the start.Fix
<pre>now carriesdata-mermaid-align="center".@docubook/markdown/styles.csscenters the diagram's direct<svg>child:display: block; margin-inline: auto. Nested SVGs and the labels inside the diagram are untouched.text-align, which Mermaid's HTML labels would inherit.<pre>a flex container. I tried that first. Mermaid sizes a Gantt chart from a temporary element it adds inside the<pre>, and as a flex item that element shrank the chart from 564px to the SVG default of 300px.Verification
Built flame's docs and measured each diagram's SVG inside its
<pre>in Chromium. Gaps are left / right.MermaidMdx.test.tsxreads the rule from the shippedstyles.css. It checks that the rule matches the diagram's SVG but not a nested one, and that it uses neithertext-alignnor flex or grid on the<pre>.tsc,oxlintand the pre-push hook pass.