Repository navigation
fix(desktop): keep diagram content when exporting with Header & Footer - #4805
Merged
Merged
Conversation
The Header & Footer export branch re-sanitized the whole assembled document with the export DOMPurify config. That config strips the <foreignObject> mermaid renders its node labels into, so enabling Header & Footer silently dropped diagram content; exporting the same document without Header & Footer was fine because that branch never re-sanitized. The article is already sanitized by the engine during render, so re-sanitizing it is both redundant and lossy. Sanitize only the user-supplied header/footer text fields instead, and leave the rendered article untouched. Fixes #3359 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 task done
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.
Problem
Exporting a document that contains a Mermaid (or other) diagram to PDF/HTML with Header & Footer enabled silently dropped the diagram's content. Exporting the same document without Header & Footer worked fine.
Root cause
exportStyledHTMLhas two branches. The no-header/footer branch returns the rendered article as-is. The header/footer branch re-ransanitize(output, EXPORT_DOMPURIFY_CONFIG)over the whole assembled document — including the already-rendered article. The export DOMPurify config strips the<foreignObject>element that Mermaid 11 renders its node labels into (htmlLabels are on by default forgraph LR), so every diagram label was removed.Fix
The article is already sanitized by the engine during render, so re-sanitizing it is redundant and lossy. Sanitize only the user-supplied header/footer text fields (
left/center/right) and leave the rendered article untouched — matching the no-header/footer branch. Also trims the header/footer class strings (the whole-output sanitize had been incidentally collapsing their whitespace).Test
packages/desktop/test/unit/specs/export-header-footer-diagram.spec.ts: a diagramforeignObjectlabel survives export when a header is present, and unsafe markup in the header text is still stripped. ExistingexportHtml.spec.ts(19 tests) still pass.Fixes #3359
🤖 Generated with Claude Code