Skip to content

fix(desktop): keep diagram content when exporting with Header & Footer - #4805

Merged
Jocs merged 1 commit into
developfrom
fix/3359-header-footer-diagram-loss
Jul 2, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/3359-header-footer-diagram-loss

Conversation

@Jocs

@Jocs Jocs commented Jun 30, 2026

Copy link
Copy Markdown
Member

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

exportStyledHTML has two branches. The no-header/footer branch returns the rendered article as-is. The header/footer branch re-ran sanitize(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 for graph 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 diagram foreignObject label survives export when a header is present, and unsafe markup in the header text is still stripped. Existing exportHtml.spec.ts (19 tests) still pass.

Fixes #3359

🤖 Generated with Claude Code

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]>
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4805:

Run: https://github.com/marktext/marktext/actions/runs/28471458367

Artifact Size Link
marktext-windows-arm64 275.7 MB Download
marktext-linux 627.6 MB Download
marktext-macos-x64 293.0 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit d61df0c into develop Jul 2, 2026
12 of 16 checks passed
@Jocs
Jocs deleted the fix/3359-header-footer-diagram-loss branch July 2, 2026 13:54
@Jocs Jocs mentioned this pull request Sep 24, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

It can't export right content(such as mermaid) when modify the setting of export to pdf

1 participant