tiptap/packages/extension-blockquote/index.ts

38 lines
871 B
TypeScript
Raw Normal View History

2020-09-22 15:15:04 +08:00
import { Command, Node } from '@tiptap/core'
import { textblockTypeInputRule } 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(() => ({
content: 'inline*',
group: 'block',
defining: true,
draggable: false,
parseDOM: [
{ tag: 'blockquote' },
],
toDOM: () => ['blockquote', 0],
}))
2020-09-22 15:15:04 +08:00
.commands(({ name }) => ({
[name]: attrs => ({ commands }) => {
2020-09-25 04:27:17 +08:00
return commands.toggleBlockType(name, 'paragraph', attrs)
2020-09-22 15:15:04 +08:00
},
}))
.keys(({ editor }) => ({
'Shift-Mod-9': () => editor.blockquote(),
}))
.inputRules(({ type }) => [
textblockTypeInputRule(inputRegex, type),
])
.create()