Fix workspace-absolute paths in markdown images#52708
Fix workspace-absolute paths in markdown images#52708ConradIrwin merged 6 commits intozed-industries:mainfrom
Conversation
…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.
|
What markdown files (or other markdown renderers) resolve absolute paths (starting with |
|
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! |
|
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! |
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_directoryfn resolve_preview_image()(lines ~714-726): added workspace_directory variable, and a verification to create the full path when a path is workspace-absoluteOne test was added, covering a successful resolution (
resolves_workspace_absolute_preview_images). This test was implemented in the filecrates/markdown_preview/src/markdown_preview_view.rs.Self-Review Checklist:
Closes #46924
Release Notes: