Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix(md): normalize Windows backslashes in inserted image URLs (#9504)

Kiran Gadhavec490624bec97
diff --git a/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts b/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts
index a1e13c462e..73dd8fbd82 100644
--- a/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts
+++ b/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts
@@ -385,6 +385,42 @@ describe("insertImage", () => {
);
});
+ test("normalizes Windows backslash paths to forward slashes in image URL", async () => {
+ view = createEditor("Hello, world!");
+ view.dispatch({
+ selection: { anchor: 7, head: 7 },
+ });
+
+ vi.spyOn(store, "get").mockImplementation((atom) => {
+ if (atom === filenameAtom) {
+ return "C:\\Users\\user\\project\\notebook.py";
+ }
+ if (atom === requestClientAtom) {
+ return mockRequestClient;
+ }
+ });
+
+ mockRequestClient.sendCreateFileOrFolder.mockResolvedValueOnce({
+ success: true,
+ message: null,
+ info: {
+ path: "C:\\Users\\user\\project\\public\\hello.png",
+ name: "hello.png",
+ children: [],
+ id: "",
+ isDirectory: false,
+ isMarimoFile: false,
+ lastModified: null,
+ },
+ });
+
+ await insertImage(view, mockPngFile());
+
+ expect(view.state.doc.toString()).toMatchInlineSnapshot(
+ `"Hello, ![alt](public/hello.png)world!"`,
+ );
+ });
+
test("saves image as file different extension", async () => {
view = createEditor("Hello, world!");
view.dispatch({
diff --git a/frontend/src/core/codemirror/markdown/commands.ts b/frontend/src/core/codemirror/markdown/commands.ts
index 6c22ba74ed..c66ccf73a4 100644
--- a/frontend/src/core/codemirror/markdown/commands.ts
+++ b/frontend/src/core/codemirror/markdown/commands.ts
@@ -360,7 +360,10 @@ export async function insertImage(view: EditorView, file: File) {
notebookDir &&
savedFilePath.startsWith(notebookDir)
) {
- savedFilePath = Paths.rest(savedFilePath, notebookDir);
+ savedFilePath = Paths.rest(savedFilePath, notebookDir).replaceAll(
+ "\\",
+ "/",
+ );
}
toast({