2020-11-16 18:19:43 +08:00
|
|
|
import { Command, Node } from '@tiptap/core'
|
2020-11-13 23:44:22 +08:00
|
|
|
|
|
|
|
export interface ParagraphOptions {
|
|
|
|
HTMLAttributes: {
|
|
|
|
[key: string]: any
|
|
|
|
},
|
|
|
|
}
|
2020-03-06 03:30:58 +08:00
|
|
|
|
2020-11-16 18:19:43 +08:00
|
|
|
const Paragraph = Node.create({
|
2020-10-21 21:17:05 +08:00
|
|
|
name: 'paragraph',
|
|
|
|
|
2020-11-14 16:23:47 +08:00
|
|
|
defaultOptions: <ParagraphOptions>{
|
|
|
|
HTMLAttributes: {},
|
|
|
|
},
|
2020-11-13 23:44:22 +08:00
|
|
|
|
2020-10-21 21:17:05 +08:00
|
|
|
group: 'block',
|
|
|
|
|
|
|
|
content: 'inline*',
|
2020-10-12 16:32:54 +08:00
|
|
|
|
2020-10-10 04:59:25 +08:00
|
|
|
parseHTML() {
|
|
|
|
return [
|
|
|
|
{ tag: 'p' },
|
|
|
|
]
|
2020-10-21 21:17:05 +08:00
|
|
|
},
|
2020-10-10 04:59:25 +08:00
|
|
|
|
2020-11-13 23:07:20 +08:00
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
return ['p', HTMLAttributes, 0]
|
2020-10-21 21:17:05 +08:00
|
|
|
},
|
2020-10-22 15:42:28 +08:00
|
|
|
|
2020-10-22 17:14:44 +08:00
|
|
|
addCommands() {
|
2020-10-22 15:42:28 +08:00
|
|
|
return {
|
2020-11-13 22:08:30 +08:00
|
|
|
/**
|
|
|
|
* Toggle a paragraph
|
|
|
|
*/
|
2020-11-18 19:29:24 +08:00
|
|
|
setParagraph: (): Command => ({ commands }) => {
|
2020-10-22 15:42:28 +08:00
|
|
|
return commands.toggleBlockType('paragraph', 'paragraph')
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-22 17:14:44 +08:00
|
|
|
addKeyboardShortcuts() {
|
2020-10-22 15:42:28 +08:00
|
|
|
return {
|
2020-11-18 19:29:24 +08:00
|
|
|
'Mod-Alt-0': () => this.editor.commands.setParagraph(),
|
2020-10-22 15:42:28 +08:00
|
|
|
}
|
|
|
|
},
|
2020-10-21 21:17:05 +08:00
|
|
|
})
|
2020-10-23 04:40:40 +08:00
|
|
|
|
|
|
|
export default Paragraph
|
|
|
|
|
2020-11-16 23:58:30 +08:00
|
|
|
declare module '@tiptap/core' {
|
|
|
|
interface AllExtensions {
|
|
|
|
Paragraph: typeof Paragraph,
|
2020-10-23 04:40:40 +08:00
|
|
|
}
|
|
|
|
}
|