From 657d9cbd864ad0728fb3e90e28fb7556d61517eb Mon Sep 17 00:00:00 2001 From: LIlGG <1103069291@qq.com> Date: Fri, 8 Mar 2024 17:26:01 +0800 Subject: [PATCH] fix: error occurs when the link is purely numerical --- .../editor/src/extensions/link/index.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ui/packages/editor/src/extensions/link/index.ts b/ui/packages/editor/src/extensions/link/index.ts index 843557b1b3..6c3d0d7feb 100644 --- a/ui/packages/editor/src/extensions/link/index.ts +++ b/ui/packages/editor/src/extensions/link/index.ts @@ -1,7 +1,30 @@ import TiptapLink from "@tiptap/extension-link"; import type { LinkOptions } from "@tiptap/extension-link"; import type { ExtensionOptions } from "@/types"; +import { mergeAttributes } from "@/tiptap/vue-3"; -const Link = TiptapLink.extend(); +const Link = TiptapLink.extend({ + renderHTML({ HTMLAttributes }) { + const href = HTMLAttributes.href; + // False positive; we're explicitly checking for javascript: links to ignore them + // eslint-disable-next-line no-script-url + if (href?.toString().startsWith("javascript:")) { + // strip out the href + return [ + "a", + mergeAttributes(this.options.HTMLAttributes, { + ...HTMLAttributes, + href: "", + }), + 0, + ]; + } + return [ + "a", + mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), + 0, + ]; + }, +}); export default Link;