tiptap/packages/extension-blockquote/src/index.ts
2020-11-16 15:40:05 +01:00

68 lines
1.1 KiB
TypeScript

import { Command, Node } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
export interface BlockquoteOptions {
HTMLAttributes: {
[key: string]: any
},
}
export const inputRegex = /^\s*>\s$/gm
const Blockquote = Node.create({
name: 'blockquote',
defaultOptions: <BlockquoteOptions>{
HTMLAttributes: {},
},
content: 'block*',
group: 'block',
defining: true,
parseHTML() {
return [
{ tag: 'blockquote' },
]
},
renderHTML({ HTMLAttributes }) {
return ['blockquote', HTMLAttributes, 0]
},
addCommands() {
return {
/**
* Toggle a blockquote node
*/
blockquote: (): Command => ({ commands }) => {
return commands.toggleWrap('blockquote')
},
}
},
addKeyboardShortcuts() {
return {
'Shift-Mod-9': () => this.editor.commands.blockquote(),
}
},
addInputRules() {
return [
wrappingInputRule(inputRegex, this.type),
]
},
})
export default Blockquote
declare global {
namespace Tiptap {
interface AllExtensions {
Blockquote: typeof Blockquote,
}
}
}