Internal file paths are now Markdown image paths

In the last commit, file paths were implemented to be the full path for the API, however that is not necessary.
Before this change: /data/assets/filename.svg
After: assets/filename.svg
The new method is what SiYuan uses for Markdown images, like ![Drawing](assets/filename.svg)
This commit is contained in:
MassiveBox 2025-04-03 00:12:36 +02:00
parent a2503d5def
commit 5e51589ffa
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
8 changed files with 66 additions and 14 deletions

View file

@ -74,15 +74,20 @@ export function findImgSrc(element: HTMLElement): string | null {
return null;
}
export function imgSrcToAbsolutePath(imgSrc: string | null): string | null {
export function imgSrcToPath(imgSrc: string | null): string | null {
if (!imgSrc) return null;
const url = new URL(imgSrc);
imgSrc = decodeURIComponent(url.pathname);
if(imgSrc.startsWith('/assets/')) {
return "/data" + imgSrc;
return imgSrc.substring(1);
}
return null
}
// Helper to safely escape regex special characters
export function escapeRegExp(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}