tiptap/packages/extension-blockquote/index.ts

53 lines
908 B
TypeScript
Raw Normal View History

2020-10-22 18:34:49 +08:00
import { Command, createNode } from '@tiptap/core'
2020-09-27 02:50:01 +08:00
import { wrappingInputRule } from 'prosemirror-inputrules'
export const inputRegex = /^\s*>\s$/gm
2020-10-23 04:40:40 +08:00
const Blockquote = createNode({
2020-10-22 18:34:49 +08:00
name: 'blockquote',
2020-10-28 23:49:37 +08:00
content: 'block*',
2020-10-22 18:34:49 +08:00
group: 'block',
defining: true,
parseHTML() {
return [
{ tag: 'blockquote' },
2020-10-22 18:34:49 +08:00
]
},
renderHTML({ attributes }) {
return ['blockquote', attributes, 0]
},
addCommands() {
return {
2020-10-23 04:40:40 +08:00
blockquote: (): Command => ({ commands }) => {
2020-10-22 18:34:49 +08:00
return commands.toggleWrap('blockquote')
},
}
},
addKeyboardShortcuts() {
return {
'Shift-Mod-9': () => this.editor.blockquote(),
}
},
addInputRules() {
return [
wrappingInputRule(inputRegex, this.type),
]
},
})
2020-10-23 04:40:40 +08:00
export default Blockquote
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
Blockquote: typeof Blockquote,
}
}