Skip to content

Commit 0f00307

Browse files
committed
增加对 Markdown 图片输入和粘贴的支持
1 parent 14451e3 commit 0f00307

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/extensions/image/index.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { nodeInputRule, nodePasteRule } from '@tiptap/core'
12
import Image from '@tiptap/extension-image'
23
import { type CommandProps, VueNodeViewRenderer } from '@tiptap/vue-3'
34

@@ -102,4 +103,30 @@ export default Image.extend({
102103
},
103104
}
104105
},
106+
addPasteRules() {
107+
return [
108+
...(this.parent?.() ?? []),
109+
nodePasteRule({
110+
find: /!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]+)"?)?\)/g,
111+
type: this.type,
112+
getAttributes: (match) => {
113+
const [, alt, src, title] = match
114+
return { src, alt, title }
115+
},
116+
}),
117+
]
118+
},
119+
addInputRules() {
120+
return [
121+
...(this.parent?.() ?? []),
122+
nodeInputRule({
123+
find: /!\[([\S]+)\]\(([^)\s]+)(?:\s+"([\S]+)"?)?\)/g,
124+
type: this.type,
125+
getAttributes: (match) => {
126+
const [, alt, src, title] = match
127+
return { src, alt, title }
128+
},
129+
}),
130+
]
131+
},
105132
})

0 commit comments

Comments
 (0)