tiptap/packages/extension-blockquote/index.ts

38 lines
832 B
TypeScript
Raw Normal View History

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-22 15:15:04 +08:00
export type BlockquoteCommand = () => Command
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,
}
}
export const inputRegex = /^\s*>\s$/gm
export default new Node()
.name('blockquote')
.schema(() => ({
2020-09-27 02:50:01 +08:00
content: 'block*',
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
},
}))
.keys(({ editor }) => ({
'Shift-Mod-9': () => editor.blockquote(),
}))
.inputRules(({ type }) => [
2020-09-27 02:50:01 +08:00
wrappingInputRule(inputRegex, type),
])
.create()