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.

Preserve whitespaces & new lines when inferring parts during rendering outputs (#8116)

Shahmir Varqha892a44d6cfd1
diff --git a/frontend/src/utils/__tests__/url-parser.test.ts b/frontend/src/utils/__tests__/url-parser.test.ts
index 1aaffc868f..2d3b8456b2 100644
--- a/frontend/src/utils/__tests__/url-parser.test.ts
+++ b/frontend/src/utils/__tests__/url-parser.test.ts
@@ -76,4 +76,26 @@ describe("parseContent", () => {
url: "https://avatars.githubusercontent.com/u/123",
});
});
+
+ it("preserves newlines between URLs", () => {
+ const parts = parseContent("https://marimo.io\nhttps://github.com\n");
+ expect(parts).toEqual([
+ { type: "url", url: "https://marimo.io" },
+ { type: "text", value: "\n" },
+ { type: "url", url: "https://github.com" },
+ { type: "text", value: "\n" },
+ ]);
+ });
+
+ it("preserves whitespace in mixed content", () => {
+ const parts = parseContent(
+ "Line 1: https://marimo.io\nLine 2: https://github.com",
+ );
+ expect(parts).toEqual([
+ { type: "text", value: "Line 1: " },
+ { type: "url", url: "https://marimo.io" },
+ { type: "text", value: "\nLine 2: " },
+ { type: "url", url: "https://github.com" },
+ ]);
+ });
});
diff --git a/frontend/src/utils/url-parser.ts b/frontend/src/utils/url-parser.ts
index d6413baa13..8bffad8ecf 100644
--- a/frontend/src/utils/url-parser.ts
+++ b/frontend/src/utils/url-parser.ts
@@ -19,7 +19,7 @@ export function parseContent(text: string): ContentPart[] {
return [{ type: "image", url: text }];
}
- const parts = text.split(urlRegex).filter((part) => part.trim() !== "");
+ const parts = text.split(urlRegex).filter((part) => part !== "");
return parts.map((part) => {
const isUrl = urlRegex.test(part);
if (isUrl) {