Skip to content

Commit a75d98e

Browse files
committed
fix wrong encoding for paths in rendered wiki-links
1 parent ea69f44 commit a75d98e

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

obsidian.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,16 @@ function postprocessFragments(html) {
877877
return document.body.innerHTML;
878878
}
879879

880+
function encodePathPreservingSlashes(rawPath) {
881+
if (typeof rawPath !== "string" || rawPath.length === 0) {
882+
return rawPath ?? "";
883+
}
884+
return rawPath
885+
.split("/")
886+
.map((segment) => encodeURIComponent(segment))
887+
.join("/");
888+
}
889+
880890
function preReplaceObsidianFileLinks(html, req) {
881891
const regex = /(?<!\!)\[\[([^\]\n]+)\]\]/g;
882892

@@ -915,7 +925,8 @@ function preReplaceObsidianFileLinks(html, req) {
915925
}
916926
console.log(f);
917927
const serverUrl = `${req.protocol}://${req.get("host")}`;
918-
const url = `${serverUrl}/${encodeURIComponent(dirPrefix + f)}`;
928+
const encodedPath = encodePathPreservingSlashes(dirPrefix + f);
929+
const url = `${serverUrl}/${encodedPath}`;
919930
return `[${alt ? alt : fileName}](${url})`;
920931
} else {
921932
return match;

0 commit comments

Comments
 (0)