Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

URL-encode the image paths in Markdown so that images with filenames (#41788)

aohanhongzhi146e754f7396
diff --git a/Cargo.lock b/Cargo.lock
index 4f4217ef152..4553c965950 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9680,6 +9680,7 @@ dependencies = [
"settings",
"theme",
"ui",
+ "urlencoding",
"util",
"workspace",
]
diff --git a/crates/markdown_preview/Cargo.toml b/crates/markdown_preview/Cargo.toml
index c351ad8634b..89e5ec5921a 100644
--- a/crates/markdown_preview/Cargo.toml
+++ b/crates/markdown_preview/Cargo.toml
@@ -31,6 +31,7 @@ pulldown-cmark.workspace = true
settings.workspace = true
theme.workspace = true
ui.workspace = true
+urlencoding.workspace = true
util.workspace = true
workspace.workspace = true
diff --git a/crates/markdown_preview/src/markdown_elements.rs b/crates/markdown_preview/src/markdown_elements.rs
index 17dec6c2194..9ed885f8765 100644
--- a/crates/markdown_preview/src/markdown_elements.rs
+++ b/crates/markdown_preview/src/markdown_elements.rs
@@ -4,6 +4,7 @@ use gpui::{
};
use language::HighlightId;
use std::{fmt::Display, ops::Range, path::PathBuf};
+use urlencoding;
#[derive(Debug)]
#[cfg_attr(test, derive(PartialEq))]
@@ -278,7 +279,12 @@ impl Link {
return Some(Link::Web { url: text });
}
- let path = PathBuf::from(&text);
+ // URL decode the text to handle spaces and other special characters
+ let decoded_text = urlencoding::decode(&text)
+ .map(|s| s.into_owned())
+ .unwrap_or(text);
+
+ let path = PathBuf::from(&decoded_text);
if path.is_absolute() && path.exists() {
return Some(Link::Path {
display_path: path.clone(),
@@ -288,7 +294,7 @@ impl Link {
if let Some(file_location_directory) = file_location_directory {
let display_path = path;
- let path = file_location_directory.join(text);
+ let path = file_location_directory.join(decoded_text);
if path.exists() {
return Some(Link::Path { display_path, path });
}