mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-11 14:48:04 +08:00
68 lines
1.1 KiB
TypeScript
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,
|
|
}
|
|
}
|
|
}
|