Skip to content

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

Description

@Jocs

Description

Exporting to styled HTML or PDF drops relative images (![](assets/cat.png)) when the document's folder name contains #, ? or %, for example C# notes/note.md. The editor shows the image (fixed in #5302), but the exported file does not.

resolveLocalImageSrc (packages/desktop/src/renderer/src/util/resolveImageSrc.ts) joins the raw window.DIRNAME into a file:// URL. Chromium reads everything after # as a fragment and everything after ? as a query, and decodes a literal %xx in the folder name, so the exported <img> points at a file that doesn't exist. The PDF path goes through the same function (the exporter rewrites the src first, and printService leaves an existing file:// src alone).

#5320 fixed the same problem for exported links (resolveLinkHref.ts); it left images out because #4789 was touching resolveImageSrc.ts.

Measured on develop @ b267efb8 (macOS, built app, File › Export) with note.md containing ![cat](assets/cat.png) next to a 1×1 assets/cat.png:

Document folder Styled HTML <img src> Image in Chrome Image in PDF
plain-dir/ file://…/plain-dir/assets/cat.png loads the 1×1 image
C# 100%25 what?/ file://…/C# 100%25 what?/assets/cat.png broken Chromium's broken-image icon

Steps to Reproduce

  1. Create a folder named C# notes with an assets subfolder, and save any PNG in it as assets/cat.png.
  2. In C# notes, create note.md containing ![cat](assets/cat.png).
  3. Open note.md in MarkText and use File › Export › HTML (or PDF).
  4. Open the exported file.

Expected Behavior

The image shows in the exported document, as it does when the folder is named notes.

Actual Behavior

The exported HTML shows a broken image, and the PDF contains the broken-image icon.

Operating System

macOS

MarkText Version

develop @ b267efb8

OS Version

macOS 27.0

Reproducibility

  • I can reliably reproduce this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🕊️ export/pdfIssue about exporting to PDF or printing🐾export/htmlIssue about exporting to HTML🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions