Skip to content

Port upstream Mermaid export resilience fix#63

Open
Renakoni wants to merge 1 commit into
mainfrom
sync/upstream-4840-mermaid-export-resilience
Open

Port upstream Mermaid export resilience fix#63
Renakoni wants to merge 1 commit into
mainfrom
sync/upstream-4840-mermaid-export-resilience

Conversation

@Renakoni

@Renakoni Renakoni commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Port upstream MarkText PR #4840 into the Android Muya copy.
  • Isolate Mermaid export rendering failures per diagram instead of letting one invalid Mermaid block abort the whole HTML export path.
  • Add a regression test for invalid Mermaid export resilience.

Upstream Source

Android Relevance

The Android repo carries Muya's MarkdownToHtml export implementation and its export tests. This bug is in that shared Muya path: MarkdownToHtml._renderMermaid() batched all Mermaid nodes into one mermaid.run() call, so a syntax error in one diagram rejected the entire render operation. Even though Android's current user-facing export surface is limited, keeping the embedded Muya export path correct avoids shipping a known upstream Muya failure in the codebase.

Change Details

  • Convert Mermaid export rendering from one batched mermaid.run({ nodes }) call to one isolated run per Mermaid node.
  • Catch per-diagram Mermaid failures and replace only the failed diagram with < Invalid Diagram >, matching the existing non-Mermaid diagram export fallback.
  • Skip loading the Mermaid renderer when the document contains no Mermaid blocks.
  • Add mermaidExportResilience.spec.ts covering:
    • invalid Mermaid does not reject renderHtml();
    • one invalid Mermaid block does not stop a later valid Mermaid block;
    • no-Mermaid documents do not load/run Mermaid.

Verification

  • pnpm --dir third_party/muya exec vitest run src/state/__tests__/mermaidExportResilience.spec.ts passed.
  • pnpm build passed.

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.

1 participant