diff --git a/news/changelog-1.12.md b/news/changelog-1.12.md index 862d32b463f..659175102bb 100644 --- a/news/changelog-1.12.md +++ b/news/changelog-1.12.md @@ -2,6 +2,10 @@ All changes included in 1.12: ## Formats +### All Formats + +- ([#15277](https://github.com/quarto-dev/quarto-cli/pull/15277)): Fix `out-width` being ignored for Mermaid diagrams rendered as `png` or `svg` images, so wide diagrams can be fitted to the text width in Typst and PDF output. (author: @faysou) + ### `pdf` - ([#15251](https://github.com/quarto-dev/quarto-cli/pull/15251)): Fix algorithm blocks (`#alg-`) being set in italics. Their body is now upright, like definitions, examples and exercises. (author: @mcanouil) diff --git a/src/core/handlers/mermaid.ts b/src/core/handlers/mermaid.ts index a88a5f70617..6c798c37e3a 100644 --- a/src/core/handlers/mermaid.ts +++ b/src/core/handlers/mermaid.ts @@ -30,6 +30,7 @@ import { } from "../svg.ts"; import { kCellFigAlt, + kCellOutWidth, kFigAlign, kFigHeight, kFigResponsive, @@ -218,10 +219,15 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)}); const idSpecifier = (cell.options?.label && includeCaption) ? ` #${cell.options?.label}` : ""; - const widthSpecifier = width + // out-width sets the displayed width, such as 75% of the text width, + // and drops the height so the image keeps its aspect ratio. + const outWidth = options[kCellOutWidth]; + const widthSpecifier = typeof outWidth === "string" + ? `width="${outWidth}"` + : width ? `width="${Math.round(width * 100) / 100}in"` : ""; - const heightSpecifier = height + const heightSpecifier = height && typeof outWidth !== "string" ? ` height="${Math.round(height * 100) / 100}in"` : ""; const captionSpecifier = includeCaption diff --git a/tests/docs/smoke-all/2026/11/03/mermaid-out-width.qmd b/tests/docs/smoke-all/2026/11/03/mermaid-out-width.qmd new file mode 100644 index 00000000000..ae355b44836 --- /dev/null +++ b/tests/docs/smoke-all/2026/11/03/mermaid-out-width.qmd @@ -0,0 +1,24 @@ +--- +title: "Mermaid out-width" +keep-typ: true +mermaid-format: png +format: + typst: default + latex: default +_quarto: + tests: + typst: + ensureTypstFileRegexMatches: + - ['image\("[^"]*mermaid-figure-1\.png", width: 50(\.0)?%\)'] + - ['mermaid-figure-1\.png", height:'] + latex: + ensureFileRegexMatches: + - ['\\includegraphics\[width=0\.5\\linewidth,[^\]]*\]\{[^}]*mermaid-figure-1\.png\}'] + - [] +--- + +```{mermaid} +%%| out-width: 50% +flowchart LR + A --> B +```