From ff36f0259a66e2be3a185d1c1765d4591a9f65da Mon Sep 17 00:00:00 2001 From: Muhammad Ali Date: Mon, 18 Dec 2023 16:23:56 +0500 Subject: [PATCH] editor: add support for converting md link syntax to link on paste (#3919) --- packages/editor/src/extensions/link/link.ts | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/extensions/link/link.ts b/packages/editor/src/extensions/link/link.ts index 49db86316b..74ea2c5a8a 100644 --- a/packages/editor/src/extensions/link/link.ts +++ b/packages/editor/src/extensions/link/link.ts @@ -16,11 +16,11 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { markInputRule } from "@tiptap/core"; +import { markInputRule, markPasteRule } from "@tiptap/core"; import TiptapLink from "@tiptap/extension-link"; const linkRegex = /(?:__|[*#])|\[(.*?)\]\(.*?\)/gm; -const regExp = /\((.*?)\)/; +const regExp = /\((.*?)\)/gm; export const Link = TiptapLink.extend({ addInputRules() { @@ -28,9 +28,24 @@ export const Link = TiptapLink.extend({ markInputRule({ find: linkRegex, type: this.type, - getAttributes: (match) => ({ - href: regExp.exec(match[0])?.[1] - }) + getAttributes: (match) => { + return { + href: regExp.exec(match[0])?.[1] + }; + } + }) + ]; + }, + addPasteRules() { + return [ + markPasteRule({ + find: linkRegex, + type: this.type, + getAttributes(match) { + return { + href: regExp.exec(match[0])?.[1] + }; + } }) ]; }