Repository navigation
Conversation
Mermaid diagrams rendered as png or svg images are sized at their natural size at 96 dpi, so their 16px text prints at 12pt and wide diagrams can run past the page. fig-width scales each diagram by a different factor, which gives every diagram a different text size. mermaid-scale takes a percentage, such as 75%, and multiplies the natural width and height by it, so all diagrams keep the same text size. It can be set in the document front matter or on a single cell, where it overrides the document value. An explicit fig-width or fig-height still takes precedence. With mermaid-format: js the browser sizes the diagram, so the option has no effect there. Both the cell and front matter schemas validate the value, so a bare number or other string fails with a clear error instead of a crash.
faysou
force-pushed
the
feature/mermaid-scale
branch
from
October 23, 2026 20:50
5645620 to
085d029
Compare
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
Description
Adds a
mermaid-scaleoption that resizes Mermaid diagrams rendered as images by a percentage of their natural size. Proposed in #15069.With
mermaid-format: pngorsvg, Quarto sizes each diagram at its natural size at 96 dpi, so Mermaid's 16px text prints at 12pt and wide diagrams can run past the page in Typst and PDF output.fig-widthscales each diagram by a different factor, so every diagram ends up with a different text size.mermaid-scaleapplies one factor to every diagram's natural size, which keeps diagram text the same size across a document.fig-widthorfig-heightstill takes precedence, so explicit sizes are respected as discussed in Typst: Unable to fit mermaid diagram into columns #8543.pngandsvgoutputs, where Quarto computes the size inresolveSize. Withmermaid-format: js, mermaid.js sizes the diagram in the browser, so the option has no effect.document-mermaid.ymlboth validate the value. A bare number or another string fails with a validation error instead of aTypeError.mermaid-format.The editor tooling files under
src/resources/editor/tools/were regenerated withquarto dev-call build-artifacts.Tests
tests/smoke/render/render-mermaid-scale.test.tsrenders three copies of a diagram to Typst: one atmermaid-scale: 100%, one inheriting the document's50%, and one withfig-width: 3. It checks that the scaled image is half the size of the 100% one and thatfig-widthwins. It compares against the 100% copy instead of absolute sizes, so it does not depend on the fonts headless Chrome uses. With the scaling disabled the test fails (2.13in against an expected 1.065in).The existing Mermaid smoke-all documents (
mermaid-typst,mermaid-multi-diagram,mermaid-pdf-default,mermaid-svg-docx,13661,mermaid-gfm-svg,mermaid-gfm-default,mermaid/backticks,mermaid-themes/3328) still pass.Checklist
I have (if applicable):