Description
A relative-path image () shows "Load image failed" when the document's folder name contains # or ?, for example C# notes/note.md. The same document in a folder without those characters renders the image.
getImageSrc (packages/muya/src/utils/image.ts) resolves a relative image path against window.DIRNAME and puts the raw directory into a file:// URL. Chromium reads everything after # as a fragment and everything after ? as a query, so it requests a file that doesn't exist. A literal % followed by two hex digits in a folder name is percent-decoded the same way: getImageSrc turns a folder named 50%25 off into a URL for 50% off.
This is not new in 0.20: legacy muyajs built the URL as 'file://' + path.resolve(DIRNAME, src) too.
Measured on the published v0.20.0-rc.1 macOS arm64 build, opening note.md that contains  next to assets/image.jpg (a real JPEG):
| Document folder |
Image |
fixture/ |
loads |
with space/ |
loads |
中文 目录/ |
loads |
100% done/ |
loads |
C# notes/ |
Load image failed |
what? notes/ |
Load image failed |
This issue covers images in the editor. HTML/PDF export (packages/desktop/src/renderer/src/util/resolveImageSrc.ts) and local link resolution (resolveLinkHref.ts) join DIRNAME into file:// URLs the same way; that is not verified in the app and not covered here.
Found while investigating #5212, whose own steps don't reproduce.
Steps to Reproduce
- Create a folder named
C# notes with an assets subfolder, and save any JPEG in it as assets/image.jpg.
- In
C# notes, create note.md containing .
- Open
note.md in MarkText.
Expected Behavior
The image renders, as it does when the folder is named notes.
Actual Behavior
The image placeholder shows "Load image failed".
Operating System
macOS
MarkText Version
0.20.0-rc.1 (also develop @ 3ed697b8)
OS Version
macOS 27.0
Reproducibility
Description
A relative-path image (
) shows "Load image failed" when the document's folder name contains#or?, for exampleC# notes/note.md. The same document in a folder without those characters renders the image.getImageSrc(packages/muya/src/utils/image.ts) resolves a relative image path againstwindow.DIRNAMEand puts the raw directory into afile://URL. Chromium reads everything after#as a fragment and everything after?as a query, so it requests a file that doesn't exist. A literal%followed by two hex digits in a folder name is percent-decoded the same way:getImageSrcturns a folder named50%25 offinto a URL for50% off.This is not new in 0.20: legacy muyajs built the URL as
'file://' + path.resolve(DIRNAME, src)too.Measured on the published v0.20.0-rc.1 macOS arm64 build, opening
note.mdthat containsnext toassets/image.jpg(a real JPEG):fixture/with space/中文 目录/100% done/C# notes/what? notes/This issue covers images in the editor. HTML/PDF export (
packages/desktop/src/renderer/src/util/resolveImageSrc.ts) and local link resolution (resolveLinkHref.ts) joinDIRNAMEintofile://URLs the same way; that is not verified in the app and not covered here.Found while investigating #5212, whose own steps don't reproduce.
Steps to Reproduce
C# noteswith anassetssubfolder, and save any JPEG in it asassets/image.jpg.C# notes, createnote.mdcontaining.note.mdin MarkText.Expected Behavior
The image renders, as it does when the folder is named
notes.Actual Behavior
The image placeholder shows "Load image failed".
Operating System
macOS
MarkText Version
0.20.0-rc.1 (also
develop@3ed697b8)OS Version
macOS 27.0
Reproducibility