2020-09-22 15:15:04 +08:00
|
|
|
import { Command, Node } from '@tiptap/core'
|
2020-09-27 02:50:01 +08:00
|
|
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
2020-09-10 17:19:49 +08:00
|
|
|
|
2020-09-22 15:15:04 +08:00
|
|
|
export type BlockquoteCommand = () => Command
|
|
|
|
|
2020-09-10 17:19:49 +08:00
|
|
|
declare module '@tiptap/core/src/Editor' {
|
2020-09-22 16:49:38 +08:00
|
|
|
interface Commands {
|
2020-09-22 15:15:04 +08:00
|
|
|
blockquote: BlockquoteCommand,
|
2020-09-10 17:19:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const inputRegex = /^\s*>\s$/gm
|
|
|
|
|
|
|
|
export default new Node()
|
|
|
|
.name('blockquote')
|
|
|
|
.schema(() => ({
|
2020-09-27 02:50:01 +08:00
|
|
|
content: 'block*',
|
2020-09-10 17:19:49 +08:00
|
|
|
group: 'block',
|
|
|
|
defining: true,
|
|
|
|
draggable: false,
|
|
|
|
parseDOM: [
|
|
|
|
{ tag: 'blockquote' },
|
|
|
|
],
|
|
|
|
toDOM: () => ['blockquote', 0],
|
|
|
|
}))
|
2020-09-22 15:15:04 +08:00
|
|
|
.commands(({ name }) => ({
|
2020-09-27 02:50:01 +08:00
|
|
|
[name]: () => ({ commands }) => {
|
|
|
|
return commands.toggleWrap(name)
|
2020-09-22 15:15:04 +08:00
|
|
|
},
|
|
|
|
}))
|
2020-09-10 17:19:49 +08:00
|
|
|
.keys(({ editor }) => ({
|
|
|
|
'Shift-Mod-9': () => editor.blockquote(),
|
|
|
|
}))
|
|
|
|
.inputRules(({ type }) => [
|
2020-09-27 02:50:01 +08:00
|
|
|
wrappingInputRule(inputRegex, type),
|
2020-09-10 17:19:49 +08:00
|
|
|
])
|
|
|
|
.create()
|