Skip to content

Fix workspace-absolute paths in markdown images#52178

Closed
danielaalves01 wants to merge 1 commit intozed-industries:mainfrom
danielaalves01:fix-#46924
Closed

Fix workspace-absolute paths in markdown images#52178
danielaalves01 wants to merge 1 commit intozed-industries:mainfrom
danielaalves01:fix-#46924

Conversation

@danielaalves01
Copy link
Copy Markdown
Contributor

Context

Previously, markdown images failed to load workspace-absolute paths. This fix updates the parser, making it able to identify the active workspace root directory. Paths which are workspace absolute are correctly resolved and rendered.

Closes #46924

How to Review

Small PR - focus on three changes in three different files:

  • In crates/markdown_preview/src/markdown_elements.rs - identify() (~line 296-337): added workplace_directory variable, and a verification to create the full path when a path is workplace-absolute
  • In crates/markdown_preview/src/markdown_parser.rs - parse_markdown() (~line 22): added workplace_directory variable to function's arguments
  • In crates/markdown_preview/src/markdown_preview_view.rs - parse_markdown_in_background() (~line 344-359): added logic to determine the worplace_directory

Two tests were added, one covering a successful resolution (test_workspace_absolute_path_resolution) and another testing the fallback behaviour when given a path of a file that does not exist within the workspace (test_workspace_absolute_path_missing_file_fallback). Both tests are implemented in the file crates/markdown_preview/src/markdown_parser.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

Release Notes:

  • Added workspace-absolute path detection in markdown files

Previously, markdown images failed to load workspace-absolute paths.
This updates the parser to identify the active workspace root directory.
Paths which are workspace absolute are correctly resolved and rendered.
The added tests cover a successful resolution and fallback behaviour.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 23, 2026
@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 23, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, Anthony-Eid and nathansobo and removed request for a team March 23, 2026 09:14
@bennetbo
Copy link
Copy Markdown
Member

Hey, thank you for working on this. We are refactoring how the markdown preview works in #52008, so that we don't have to maintain two markdown parsers. To make this easier to manage for us, I'm going to close this PR until we land the refactor (we plan to merge it at the end of the week). Please open a new PR once that has landed if the issue still persists.

@bennetbo bennetbo closed this Mar 23, 2026
ConradIrwin pushed a commit that referenced this pull request Apr 1, 2026
## 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


https://github.com/user-attachments/assets/d69644ea-06cc-4638-b4ee-ec9f3abbb1ed

## 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:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #46924 

Release Notes:

- Added workspace-absolute path detection in markdown files
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

3 participants