From 20fd286756c2b957850c8ab84394bf0e4116452e Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Mon, 22 Aug 2022 17:45:23 -0700 Subject: [PATCH] Fix link classes duplicating on paste (#788) --- web/components/editor.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/components/editor.tsx b/web/components/editor.tsx index f4166f27..6af58caa 100644 --- a/web/components/editor.tsx +++ b/web/components/editor.tsx @@ -6,6 +6,7 @@ import { JSONContent, Content, Editor, + mergeAttributes, } from '@tiptap/react' import StarterKit from '@tiptap/starter-kit' import { Image } from '@tiptap/extension-image' @@ -38,7 +39,16 @@ const DisplayImage = Image.configure({ }, }) -const DisplayLink = Link.configure({ +const DisplayLink = Link.extend({ + renderHTML({ HTMLAttributes }) { + delete HTMLAttributes.class // only use our classes (don't duplicate on paste) + return [ + 'a', + mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), + 0, + ] + }, +}).configure({ HTMLAttributes: { class: clsx('no-underline !text-indigo-700', linkClass), },