From a9714f6a4ae6274cb6dc88a1c38ddbdf35de6460 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 13 Jun 2025 11:05:08 +0200 Subject: [PATCH] fix: improve markdown paste detection (#939) --- frontend/src/components/input/editor/TipTap.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/input/editor/TipTap.vue b/frontend/src/components/input/editor/TipTap.vue index b343a1be6..cabd2f31f 100644 --- a/frontend/src/components/input/editor/TipTap.vue +++ b/frontend/src/components/input/editor/TipTap.vue @@ -348,7 +348,6 @@ const PasteHandler = Extension.create({ if (typeof props.uploadCallback !== 'undefined' && event.clipboardData?.items?.length > 0) { for (const item of event.clipboardData.items) { - console.log({item}) if (item.kind === 'file' && item.type.startsWith('image/')) { const file = item.getAsFile() if (file) { @@ -359,15 +358,19 @@ const PasteHandler = Extension.create({ } } - // Handle markdown text - const text = event.clipboardData?.getData('text/plain') - if (!text) return false + const text = event.clipboardData?.getData('text/plain') || '' + if (!text) { + return false + } + + const hasMarkdownSyntax = new RegExp('[*`_\\[\\]#-]').test(text) + if (!hasMarkdownSyntax) { + return false + } const html = marked.parse(text) - // It is fine to paste the content without sanitizing because it will be sanitized later by TipTap this.editor.commands.insertContent(html) - // https://github.com/ueberdosis/tiptap/discussions/4118#discussioncomment-8931999 return true }, },