Skip to content

Commit 0c9b138

Browse files
authored
feat: support GitHub flavored markdown paste (#5225)
Markdown paste now generate html elements. This unlocks us supporting more features: **strikethrough** `~~text~~` -> <del>text</del> **tables** ``` | Header 1 | Header 2 | |------------|------------| | Cell 1.1 | Cell 1.2 | | Cell 2.1 | Cell 2.2 | ``` *autolinks* ``` The link is https://github.com ``` is converted to ```html <p>This link is <a href="https://github.com">https://github.com</a></p> ``` <img width="559" alt="Screenshot 2025-05-20 at 16 44 53" src="https://github.com/user-attachments/assets/48508140-9791-47f6-b1c1-3b2946dd5583" /> <img width="514" alt="image" src="https://github.com/user-attachments/assets/dc19e67a-0067-458f-bf3c-64d9b73d02e3" />
1 parent fa875ab commit 0c9b138

File tree

9 files changed

+288
-1227
lines changed

9 files changed

+288
-1227
lines changed

apps/builder/app/shared/copy-paste/asset-upload.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ import { nanoid } from "nanoid";
44
import { produce, enablePatches, type Patch, applyPatches } from "immer";
55

66
enablePatches();
7-
8-
type StringProp = Extract<
9-
WebstudioFragment["props"][number],
10-
{ type: "string" }
11-
>;
12-
137
const extractSrcProps = (
148
data: WebstudioFragment
159
): [propId: string, href: string][] => {
@@ -22,17 +16,20 @@ const extractSrcProps = (
2216
.map((instance) => instance.id)
2317
);
2418

25-
const srcProps = data.props
26-
.filter(
27-
(prop): prop is StringProp =>
28-
prop.type === "string" &&
29-
prop.name === "src" &&
30-
imageComponentsSet.has(prop.instanceId)
31-
)
32-
.map(
33-
(prop) =>
34-
[prop.id, new URL(prop.value).href] as [propId: string, href: string]
35-
);
19+
const srcProps: [propId: string, href: string][] = [];
20+
for (const prop of data.props) {
21+
if (
22+
prop.type === "string" &&
23+
prop.name === "src" &&
24+
imageComponentsSet.has(prop.instanceId)
25+
) {
26+
try {
27+
srcProps.push([prop.id, new URL(prop.value).href]);
28+
} catch {
29+
// ignore when invalid url
30+
}
31+
}
32+
}
3633

3734
return srcProps;
3835
};

0 commit comments

Comments
 (0)