Skip to content

Fix workspace-absolute paths in markdown images#52708

Merged
ConradIrwin merged 6 commits intozed-industries:mainfrom
danielaalves01:fix-46924
Apr 1, 2026
Merged

Fix workspace-absolute paths in markdown images#52708
ConradIrwin merged 6 commits intozed-industries:mainfrom
danielaalves01:fix-46924

Conversation

@danielaalves01
Copy link
Copy Markdown
Contributor

Context

Previously, markdown images failed to load workspace-absolute paths. This updates the image resolver to identify the active workspace root directory. Paths which are workspace absolute are correctly resolved and rendered. The added test covers a successful resolution.

This PR re-implements the fix that was originally proposed in my previous PR, #52178.

Fix

FixWorkspaceAbsoluteImageRendering.mp4

How to Review

Small PR - focus on two changes in the file crates/markdown_preview/src/markdown_preview_view.rs:

  • fn render_markdown_element() (lines ~583-590): added the logic to determine the workspace_directory
  • fn resolve_preview_image() (lines ~714-726): added workspace_directory variable, and a verification to create the full path when a path is workspace-absolute

One test was added, covering a successful resolution (resolves_workspace_absolute_preview_images). This test was implemented in the file crates/markdown_preview/src/markdown_preview_view.rs.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #46924

Release Notes:

  • Added workspace-absolute path detection in markdown files

…ages

Previously, markdown images failed to load workspace-absolute paths.
This updates the image resolver to identify the active workspace
root directory. Paths which are workspace absolute are correctly
resolved and rendered. The added test covers a successful resolution.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 30, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, ConradIrwin and osiewicz and removed request for a team March 30, 2026 08:02
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 30, 2026
@maxdeviant maxdeviant changed the title Fix #46924: Fix workspace-absolute paths in markdown images Fix workspace-absolute paths in markdown images Mar 30, 2026
@ConradIrwin
Copy link
Copy Markdown
Member

What markdown files (or other markdown renderers) resolve absolute paths (starting with /) relative to the corktree root?. That seems like a bug to me.

@danielaalves01
Copy link
Copy Markdown
Contributor Author

Hi! My intention with this pull request was to add the ability to render absolute paths relative to the project's root, since I have seen that both GitHub and VSCode have that feature.

In the issue #46924, the fact that VSCode and Github accept workspace-absolute paths was discussed, and I believed it was a helpful fix to work on. Here is the link to the specific comment in the issue: #46924 (comment)

However, I do understand the possible issues with implementing this feature, since it could break the ability to link to literal OS absolute paths. With this in mind, is it preferable to stick strictly to standard OS absolute paths? I'm happy to adapt this PR if there is a different preferred approach!

@ConradIrwin
Copy link
Copy Markdown
Member

Weird! Yeah, it's surprising, but it makes some sense I suppose (and rendering images from outside the worktree really doesn't). Thanks for this!

@ConradIrwin ConradIrwin enabled auto-merge (squash) April 1, 2026 02:09
@ConradIrwin ConradIrwin merged commit a9dd7e9 into zed-industries:main Apr 1, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Images broken in markdown preview if you use an absolute path

4 participants