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'
|
2020-09-10 17:19:49 +08:00
|
|
|
|
|
|
|
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:32:06 +08:00
|
|
|
content: 'paragraph block*',
|
2020-10-22 18:34:49 +08:00
|
|
|
|
|
|
|
group: 'block',
|
|
|
|
|
|
|
|
defining: true,
|
|
|
|
|
|
|
|
parseHTML() {
|
|
|
|
return [
|
2020-09-10 17:19:49 +08:00
|
|
|
{ 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,
|
|
|
|
}
|
|
|
|
}
|