Repository navigation
fix(desktop): keep exported images working from folders named with #, ? or % (#5335) - #5337
Merged
Merged
Conversation
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
3 of 7 tasks
Jocs
added this pull request to stack #5339
September 14, 2026 05:13
|
Build artifacts for PR #5337: Run: https://github.com/marktext/marktext/actions/runs/34808304019
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5335
Summary
Exporting to styled HTML or PDF dropped relative images when the document's folder name contained
#,?or%.resolveLocalImageSrcjoined the rawwindow.DIRNAMEinto afile://URL, soC# notes/assets/cat.pngbecame a URL forCwith a fragment. This is the image twin of #5320, which fixed exported links the same way.localPathToFileUrl(fromresolveImageSrc.ts) andencodeDirnameForUrl(fromresolveLinkHref.ts) move intoutil/fileUrl.ts, so the image and link resolvers use the same helpers instead of a copy each. No behavior change.resolveLocalImageSrcescapes%,?and#in the directory only. The markdown image path is already URL-form, so its own%20and?v=2are left alone. The PDF / print path is covered too: the exporter rewrites the src first, andprintServiceleaves afile://src alone.Type of change
Test plan
New tests in
printService-image.spec.tscover: an escaped directory; an image path that keeps its own%20and?v=2; and thatnew URL()on the result gives back the real path with no hash or query. All three fail ondevelopand pass with the fix. Desktop unit suite 809/809;pnpm run lintandpnpm run typecheckclean.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.mdcontainednext to a 1×1 PNG:develop@b267efb8plain-dir/C# 100%25 what?/<img>broken in Chrome (naturalWidth0); PDF embeds Chromium's 28×32 broken-image iconNotes for reviewers
#4789 also edits
resolveImageSrc.ts, but it was written against an older version of the file that has since gainedlocalPathToFileUrl, so it needs a rebase either way.🤖 Generated with Claude Code
https://claude.ai/code/session_019p11VSo6R74VD94ezRFNGb