Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Fix local media markdown links (#3619)

Isaac Sanchez-Hawkins5a5832fd126f
diff --git a/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts b/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts
index ffb2eefd7..16fc5c8f9 100644
--- a/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/media-file-path.test.ts
@@ -66,4 +66,13 @@ describe("normalizeLocalMediaMarkdown", () => {
"- When you were talking: ![](<\/Users/ansh/.screenpipe/data/System Audio (output)_2026-05-25_11-27-00.mp4>)",
);
});
+
+ it("wraps local media links that contain spaces and parentheses", () => {
+ const markdown =
+ "[play clip](/Users/ansh/.screenpipe/data/System Audio (output)_2026-05-25_11-27-00.mp4)";
+
+ expect(normalizeLocalMediaMarkdown(markdown)).toBe(
+ "[play clip](</Users/ansh/.screenpipe/data/System Audio (output)_2026-05-25_11-27-00.mp4>)",
+ );
+ });
});
diff --git a/apps/screenpipe-app-tauri/lib/utils/media-file-path.ts b/apps/screenpipe-app-tauri/lib/utils/media-file-path.ts
index 23cf99f53..230581449 100644
--- a/apps/screenpipe-app-tauri/lib/utils/media-file-path.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/media-file-path.ts
@@ -43,13 +43,13 @@ export function isMediaFilePath(path: string): boolean {
export function normalizeLocalMediaMarkdown(text: string): string {
return text.replace(
- new RegExp(`!\\[([^\\]]*)\\]\\(((?:/[^\n\r]+?|[A-Z]:[\\\\/][^\n\r]+?)\\.(${MEDIA_EXTENSION_PATTERN}))\\)`, "gi"),
- (_match, alt: string, path: string) => {
+ new RegExp(`(!?)\\[([^\\]]*)\\]\\(((?:/[^\n\r]+?|[A-Z]:[\\\\/][^\n\r]+?)\\.(${MEDIA_EXTENSION_PATTERN}))\\)`, "gi"),
+ (_match, sigil: string, alt: string, path: string) => {
const trimmedPath = path.trim();
if (trimmedPath.startsWith("<") && trimmedPath.endsWith(">")) {
- return `![${alt}](${trimmedPath})`;
+ return `${sigil}[${alt}](${trimmedPath})`;
}
- return `![${alt}](<${trimmedPath.replace(/>/g, "%3E")}>)`;
+ return `${sigil}[${alt}](<${trimmedPath.replace(/>/g, "%3E")}>)`;
},
);
}