Skip to content

Mermaid renders as black boxes #3506

Closed
Closed

Description

@Omnieboer

Description

Whenever I export a mermaid graph with headers enabled, the content is replaced by black boxes without arrows.
image
When I turn the header above it off, the rendering works perfectly again.

  • Can you reproduce the issue?

Steps to reproduce

  1. Make a mermaid graph in MarkText
  2. Export to PDF menu
  3. Add a header
  4. Finish export

Expected behavior:

Render the Mermaid graph in its location.

Actual behavior:

Black boxes and shown above. I'm also not sure, but it seems some text might also disappear:
image
The buffer headers don't end up in the final PDF at all. I feel, especially with the header being part of the issue, this is related to the page break.

This is a minimal reproduction file for me:
Reproduce.md containing only:

flowchart LR
    example --> example
Loading

resulting in:
image
and without adding an export header resulting in:
image

Versions

  • MarkText version: v0.17.1
  • Operating system: Win10 Pro 21H2

Activity

  1. Omnieboer commented on Nov 15, 2022

    @Omnieboer
    Author

    I think #3359 might be the same issue, but the description wasn't clear enough to be sure.

  2. added
    🐛 bug
    🪲 pri/major
    🐿️ markdown/extension
    🕊️ export/pdf
    on May 16, 2026
  3. 4lpMeunier commented on Jun 30, 2026

    @4lpMeunier

    I do experience the same issue on v0.17.1 on Linux version.

  4. Jocs commented on Sep 24, 2026

    @Jocs
    Member

    Fixed on the current develop (upcoming 0.20.0) by #4805 — this is the same defect as #3359, which you correctly suspected in your first comment.

    Root cause. The Header & Footer branch of the exporter re-sanitized the whole already-rendered document with DOMPurify. That config strips the <foreignObject> elements mermaid draws its node labels into, so enabling a header mangled every diagram; the branch without a header never re-sanitized, which is exactly the asymmetry you described. #4805 sanitizes only the user-supplied header/footer text fields and leaves the rendered article untouched.

    Verified on today's build (macOS, Electron 42), driving the real export pipeline end to end:

    • Your Reproduce.md verbatim, exported to PDF with a three-cell header: the flowchart renders with its example label and its arrow, pixel-identical to the same export without a header.
    • A larger document (flowchart + sequence + class diagram) that spans two pages: the header repeats on both pages and all three diagrams render intact, including the one after the page break.
    • Counter-proof: putting the pre-fix(desktop): keep diagram content when exporting with Header & Footer #4805 sanitize(...) call back into exportHtml.ts and rebuilding reproduces the defect on today's code — the <foreignObject> count in the exported HTML drops from 12 to 0 and the node renders as an empty box.

    Regression coverage lives in packages/desktop/test/unit/specs/export-header-footer-diagram.spec.ts.

    Closing as fixed. If you still hit this on 0.20.0, please reopen with the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🪲 pri/major🐿️ markdown/extension🕊️ export/pdf🐛 bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions