mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
feat(front): add MarkdownPaste extension for enhanced paste functionality in Tiptap editor
This commit is contained in:
@@ -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<Editor | undefined>(undefined)
|
||||
onMounted(() => {
|
||||
editor.value = new Editor({
|
||||
content: props.modelValue,
|
||||
extensions: [StarterKit, Markdown, Placeholder.configure({
|
||||
extensions: [StarterKit, Markdown, MarkdownPaste, Placeholder.configure({
|
||||
placeholder: props.placeholder ?? ''
|
||||
})],
|
||||
onUpdate: () => {
|
||||
|
||||
25
front/components/Tiptap/ MarkdownPaste.ts
Normal file
25
front/components/Tiptap/ MarkdownPaste.ts
Normal file
@@ -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
|
||||
},
|
||||
},
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user