diff --git a/front/components/Tiptap.vue b/front/components/Tiptap.vue index 0844948..a0f5b48 100644 --- a/front/components/Tiptap.vue +++ b/front/components/Tiptap.vue @@ -3,6 +3,7 @@ import { Editor, EditorContent } from '@tiptap/vue-3' import StarterKit from '@tiptap/starter-kit' import { Markdown } from 'tiptap-markdown'; import Placeholder from '@tiptap/extension-placeholder' +import { MarkdownPaste } from './Tiptap/ MarkdownPaste'; const props = defineProps<{ modelValue: string placeholder?: string @@ -15,7 +16,7 @@ const editor = ref(undefined) onMounted(() => { editor.value = new Editor({ content: props.modelValue, - extensions: [StarterKit, Markdown, Placeholder.configure({ + extensions: [StarterKit, Markdown, MarkdownPaste, Placeholder.configure({ placeholder: props.placeholder ?? '' })], onUpdate: () => { diff --git a/front/components/Tiptap/ MarkdownPaste.ts b/front/components/Tiptap/ MarkdownPaste.ts new file mode 100644 index 0000000..abd8aaf --- /dev/null +++ b/front/components/Tiptap/ MarkdownPaste.ts @@ -0,0 +1,25 @@ +import { Extension } from '@tiptap/core' +import { Plugin, PluginKey } from 'prosemirror-state' +import { marked } from 'marked' + +export const MarkdownPaste = Extension.create({ + name: 'markdownPaste', + addProseMirrorPlugins() { + return [ + new Plugin({ + key: new PluginKey('markdownPaste'), + props: { + handlePaste: (view, event) => { + const clipboardText = event.clipboardData?.getData('text/plain') + if (clipboardText) { + const html = marked(clipboardText) + this.editor.commands.insertContent(html) + return true + } + return false + }, + }, + }), + ] + }, +}) \ No newline at end of file