Skip to content

fix(desktop): keep exported images working from folders named with #, ? or % (#5335) - #5337

Merged
Jocs merged 2 commits into
developfrom
fix/5335-export-image-dirname-url-chars
Sep 14, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/5335-export-image-dirname-url-chars

Conversation

@Jocs

@Jocs Jocs commented Sep 14, 2026

Copy link
Copy Markdown
Member

Fixes #5335

Summary

Exporting to styled HTML or PDF dropped relative images when the document's folder name contained #, ? or %. resolveLocalImageSrc joined the raw window.DIRNAME into a file:// URL, so C# notes/assets/cat.png became a URL for C with a fragment. This is the image twin of #5320, which fixed exported links the same way.

  • refactor: localPathToFileUrl (from resolveImageSrc.ts) and encodeDirnameForUrl (from resolveLinkHref.ts) move into util/fileUrl.ts, so the image and link resolvers use the same helpers instead of a copy each. No behavior change.
  • fix: resolveLocalImageSrc escapes %, ? and # in the directory only. The markdown image path is already URL-form, so its own %20 and ?v=2 are left alone. The PDF / print path is covered too: the exporter rewrites the src first, and printService leaves a file:// src alone.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests in printService-image.spec.ts cover: an escaped directory; an image path that keeps its own %20 and ?v=2; and that new URL() on the result gives back the real path with no hash or query. All three fail on develop and pass with the fix. Desktop unit suite 809/809; pnpm run lint and pnpm run typecheck clean.

  • Manually tested on macOS with the built app (build:unpack). The test used File › Export › HTML and PDF through the real export dialog, with only the save dialog stubbed. note.md contained ![cat](assets/cat.png) next to a 1×1 PNG:

    Document folder develop @ b267efb8 this PR
    plain-dir/ HTML image loads; PDF embeds the 1×1 image same
    C# 100%25 what?/ HTML <img> broken in Chrome (naturalWidth 0); PDF embeds Chromium's 28×32 broken-image icon HTML image loads; PDF embeds the 1×1 image

Notes for reviewers

#4789 also edits resolveImageSrc.ts, but it was written against an older version of the file that has since gained localPathToFileUrl, so it needs a rebase either way.

🤖 Generated with Claude Code

https://claude.ai/code/session_019p11VSo6R74VD94ezRFNGb

Jocs and others added 2 commits September 14, 2026 13:02
Move `localPathToFileUrl` (from resolveImageSrc) and `encodeDirnameForUrl`
(from resolveLinkHref) into util/fileUrl.ts so the image and link
resolvers build `file://` URLs from the same helpers. No behavior change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019p11VSo6R74VD94ezRFNGb
… ? or % (#5335)

resolveLocalImageSrc joined the raw window.DIRNAME into a file:// URL, so
a `#` or `?` in the document's folder name started a fragment or query in
the exported HTML / PDF image, and a literal `%xx` in the name was
percent-decoded. Escape those characters in the directory only, as
resolveLocalLinkHref does since #5320: the markdown image path is already
URL-form and keeps its own query and escapes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019p11VSo6R74VD94ezRFNGb
@Jocs
Jocs added this pull request to stack #5339 September 14, 2026 05:13
@github-actions

Copy link
Copy Markdown

Build artifacts for PR #5337:

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

Artifact Size Link
marktext-macos-x64 297.6 MB Download
marktext-macos-arm64 287.3 MB Download
marktext-linux 637.9 MB Download
marktext-windows-x64 287.6 MB Download
marktext-windows-arm64 279.4 MB Download

@Jocs
Jocs removed this pull request from stack #5339 September 14, 2026 05:28
@Jocs
Jocs merged commit 7d2250f into develop Sep 14, 2026
10 checks passed
@Jocs
Jocs deleted the fix/5335-export-image-dirname-url-chars branch September 14, 2026 05:29
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.

[Bug] Exported HTML/PDF drops relative images when the document's folder name contains #, ? or %

1 participant