@@ -39,7 +39,7 @@ import { convertFromYaml } from "../lib/yaml-schema/from-yaml.ts";
3939import { readYamlFromString } from "../yaml.ts" ;
4040import { pandocHtmlBlock , pandocRawStr } from "../pandoc/codegen.ts" ;
4141import { LocalizedError } from "../lib/located-error.ts" ;
42- import { warning } from "../../deno_ral/log.ts" ;
42+ import { info , warning } from "../../deno_ral/log.ts" ;
4343import { FormatDependency } from "../../config/types.ts" ;
4444import { mappedDiff } from "../mapped-text.ts" ;
4545import { escape } from "../../core/lodash.ts" ;
@@ -228,7 +228,7 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
228228 ?. [ kFigResponsive ] ;
229229
230230 const makeSvg = async ( ) => {
231- setupMermaidSvgJsRuntime ( ) ;
231+ // Extract and process SVG
232232 let svg = asMappedString (
233233 ( await handlerContext . extractHtml ( {
234234 html : content ,
@@ -306,7 +306,22 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
306306 svg = mappedDiff ( svg , oldSvgSrc ) ;
307307 }
308308
309- if ( isMarkdownOutput ( handlerContext . options . format , [ "gfm" ] ) ) {
309+ // For formats that don't support JavaScript runtime (LaTeX/PDF, DOCX, Typst, etc.),
310+ // write SVG file directly without postprocess script. This avoids LaTeX compilation
311+ // errors from HTML script tags but may result in text clipping in diagrams with
312+ // multi-line labels (see https://github.com/quarto-dev/quarto-cli/issues/1622).
313+ if (
314+ isMarkdownOutput ( handlerContext . options . format , [ "gfm" ] ) ||
315+ ! isJavascriptCompatible ( handlerContext . options . format )
316+ ) {
317+ // Emit info message for non-JS formats (excluding GFM which doesn't have the issue)
318+ if ( ! isMarkdownOutput ( handlerContext . options . format , [ "gfm" ] ) ) {
319+ info (
320+ `Using mermaid-format: svg with ${
321+ handlerContext . options . format . pandoc . to ?? "non-HTML"
322+ } format. Note: diagrams with multi-line text labels may experience clipping. Consider using mermaid-format: png if issues occur.`,
323+ ) ;
324+ }
310325 const { sourceName, fullName } = handlerContext
311326 . uniqueFigureName (
312327 "mermaid-figure-" ,
@@ -323,6 +338,8 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
323338 makeFigLink ( sourceName , widthInInches , heightInInches , true ) ,
324339 ) ;
325340 } else {
341+ // For JavaScript-compatible formats, use runtime postprocessing
342+ setupMermaidSvgJsRuntime ( ) ;
326343 return this . build (
327344 handlerContext ,
328345 cell ,
0 commit comments