Skip to content

Fix mermaid/katex/highlight not rendering for files on external drives - #410

Merged
Shpigford merged 2 commits into
mainfrom
issue-409
Aug 28, 2026
Merged

Shpigford merged 2 commits into
mainfrom
issue-409

Conversation

@Shpigford

Copy link
Copy Markdown
Owner

Fixes #409

The preview (Mac + iOS), PDF export, and iOS QuickLook extension loaded HTML with the document's directory as the WKWebView baseURL. When the document lives on a different volume (external drive, or a file provider on iOS), WebKit refuses to load the bundled file: JS/CSS subresources — mermaid, KaTeX, and highlight.js — so mermaid diagrams rendered as plain code blocks. Mac QuickLook already used the bundle resource directory as baseURL, which is why spacebar preview worked on the external drive.

Nothing actually needs the document-directory baseURL anymore: local images go through LocalImageSchemeHandler, and relative links resolve in Swift against fileURL. All four load sites now use MermaidSupport.resourceBaseURL.

Verification

  • Reproduced on a mounted APFS disk image (separate volume): diagram showed as a code block before the fix, renders after.
  • Regression check: a document with a relative local image (![red](red.png)) plus a mermaid block renders both correctly.
  • swift test --package-path Packages/ClearlyCore green; Mac and iOS targets build.

… drives

The preview and PDF export loaded HTML with the document's directory as
the WKWebView baseURL. When that directory is on a different volume
(external drive), WebKit refuses to load the bundled file: JS/CSS
subresources, so mermaid diagrams fell back to plain code blocks. Local
images go through LocalImageSchemeHandler and relative links resolve in
Swift, so nothing needs the document baseURL — use the bundle resource
directory like QuickLook already does.

Fixes #409
Same fix as the Mac preview: a document-directory baseURL on another
volume or file provider blocks the bundled file: JS/CSS subresources
(mermaid, katex, highlight).
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Deploying clearly with  Cloudflare Pages  Cloudflare Pages

Latest commit: 58939cb
Status: ✅  Deploy successful!
Preview URL: https://5f1ee1d5.clearly-cjz.pages.dev
Branch Preview URL: https://issue-409.clearly-cjz.pages.dev

View logs

@Shpigford
Shpigford merged commit 100fe6d into main Aug 28, 2026
3 checks passed
@Shpigford
Shpigford deleted the issue-409 branch August 28, 2026 18:13
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.

Mermaid diagram is not rendered if Markdown file is saved on external drive

1 participant