diff --git a/packages/editor/src/extensions/link/link.ts b/packages/editor/src/extensions/link/link.ts index dbf1859c7..5211c9e16 100644 --- a/packages/editor/src/extensions/link/link.ts +++ b/packages/editor/src/extensions/link/link.ts @@ -232,9 +232,10 @@ export const Link = Mark.create({ } }), markPasteRule({ - find: (text) => { + find: (text, ev) => { const foundLinks: PasteRuleMatch[] = []; - + const html = ev?.clipboardData?.getData("text/html"); + if (html && html.includes(" item.isLink); diff --git a/packages/editor/src/extensions/link/tests/__snapshots__/link.test.ts.snap b/packages/editor/src/extensions/link/tests/__snapshots__/link.test.ts.snap index e925b288e..ac550f0a7 100644 --- a/packages/editor/src/extensions/link/tests/__snapshots__/link.test.ts.snap +++ b/packages/editor/src/extensions/link/tests/__snapshots__/link.test.ts.snap @@ -1,5 +1,7 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`paste text > with html link 1`] = `"
"`; + exports[`paste text > with markdown link 1`] = `"
"`; exports[`paste text > with multiple markdown links 1`] = `"

test some text test2

"`; diff --git a/packages/editor/src/extensions/link/tests/link.test.ts b/packages/editor/src/extensions/link/tests/link.test.ts index d198b7697..449ba2d99 100644 --- a/packages/editor/src/extensions/link/tests/link.test.ts +++ b/packages/editor/src/extensions/link/tests/link.test.ts @@ -114,4 +114,33 @@ describe("paste text", () => { expect(editorElement.outerHTML).toMatchSnapshot(); }); + + test("with html link", async () => { + const editorElement = h("div"); + const { editor } = createEditor({ + element: editorElement, + extensions: { + link: Link + } + }); + + const clipboardEvent = new Event("paste", { + bubbles: true, + cancelable: true, + composed: true + }); + + (clipboardEvent as unknown as any)["clipboardData"] = { + getData: (type: string) => + type === "text/html" + ? `example.py` + : "" + }; + + editor.view.dom.dispatchEvent(clipboardEvent); + + await new Promise((resolve) => setTimeout(resolve, 100)); + + expect(editorElement.outerHTML).toMatchSnapshot(); + }); });