Summary
The HTML-export path has the same coupling that #533 fixed for the live preview: Mermaid and Graphviz diagram scripts are emitted only when highlighting is included, so exporting HTML with "include highlighting" unchecked produces a document where diagram fences stay as plain code blocks — no SVG, no error.
This is the follow-up deliberately scoped out of #533 / #540 (which fixed only the live-preview path in -[MPRenderer scripts]).
Root cause
In -[MPRenderer HTMLForExportWithStyles:highlighting:] (MacDown/Code/Document/MPRenderer.m), the Mermaid/Graphviz script inclusion is nested inside the if (withHighlighting) block:
if (withHighlighting)
{
// ... prism scripts ...
// mermaid
if ([d rendererHasMermaid:self]) { ...mermaidScripts... }
// graphviz
if ([d rendererHasGraphviz:self]) { ...graphvizScripts... }
}
When withHighlighting is NO, the mermaid/graphviz scripts are never added to the exported page, so the diagrams never render.
Note this path is reachable independently of the live-preview setting: withHighlighting comes from the export panel's "include highlighting" checkbox (controller.highlightingIncluded in -[MPDocument exportHtml:]), which is only initialized from htmlSyntaxHighlighting and can be toggled per-export.
Why it's a separate change from #533
Unlike -[MPRenderer scripts], this method also uses withHighlighting to drive scriptsOption = MPAssetEmbedded (asset-embedding vs. linking) for a self-contained exported file. So hoisting the mermaid/graphviz blocks out of the gate needs to preserve the correct asset-embedding behavior for those scripts, which is why it wasn't folded into the focused live-preview fix.
Expected behavior
Exported HTML renders Mermaid and Graphviz diagrams based on their own toggles, regardless of whether "include highlighting" is selected at export time.
Notes on testing
The existing export-path tests in MacDownTests/MPRendererEdgeCaseTests.m (testRendererWithMermaidEnabled / testRendererWithGraphvizEnabled) only assert the produced HTML is non-nil — they don't check for script presence/absence, so they wouldn't currently catch this. A fix should add assertions that the diagram scripts are present in the exported HTML with withHighlighting = NO.
Summary
The HTML-export path has the same coupling that #533 fixed for the live preview: Mermaid and Graphviz diagram scripts are emitted only when highlighting is included, so exporting HTML with "include highlighting" unchecked produces a document where diagram fences stay as plain code blocks — no SVG, no error.
This is the follow-up deliberately scoped out of #533 / #540 (which fixed only the live-preview path in
-[MPRenderer scripts]).Root cause
In
-[MPRenderer HTMLForExportWithStyles:highlighting:](MacDown/Code/Document/MPRenderer.m), the Mermaid/Graphviz script inclusion is nested inside theif (withHighlighting)block:When
withHighlightingisNO, the mermaid/graphviz scripts are never added to the exported page, so the diagrams never render.Note this path is reachable independently of the live-preview setting:
withHighlightingcomes from the export panel's "include highlighting" checkbox (controller.highlightingIncludedin-[MPDocument exportHtml:]), which is only initialized fromhtmlSyntaxHighlightingand can be toggled per-export.Why it's a separate change from #533
Unlike
-[MPRenderer scripts], this method also useswithHighlightingto drivescriptsOption = MPAssetEmbedded(asset-embedding vs. linking) for a self-contained exported file. So hoisting the mermaid/graphviz blocks out of the gate needs to preserve the correct asset-embedding behavior for those scripts, which is why it wasn't folded into the focused live-preview fix.Expected behavior
Exported HTML renders Mermaid and Graphviz diagrams based on their own toggles, regardless of whether "include highlighting" is selected at export time.
Notes on testing
The existing export-path tests in
MacDownTests/MPRendererEdgeCaseTests.m(testRendererWithMermaidEnabled/testRendererWithGraphvizEnabled) only assert the produced HTML is non-nil — they don't check for script presence/absence, so they wouldn't currently catch this. A fix should add assertions that the diagram scripts are present in the exported HTML withwithHighlighting = NO.