2020-10-23 04:40:40 +08:00
|
|
|
import { Command, createNode } 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-10-23 04:40:40 +08:00
|
|
|
const Paragraph = createNode({
|
2020-10-21 21:17:05 +08:00
|
|
|
name: 'paragraph',
|
|
|
|
|
2020-11-13 23:44:22 +08:00
|
|
|
// defaultOptions: <ParagraphOptions>{
|
|
|
|
// HTMLAttributes: {},
|
|
|
|
// },
|
|
|
|
|
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-10-23 04:40:40 +08:00
|
|
|
paragraph: (): 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-13 18:42:04 +08:00
|
|
|
'Mod-Alt-0': () => this.editor.commands.paragraph(),
|
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-11 04:18:22 +08:00
|
|
|
declare module '@tiptap/core' {
|
2020-10-23 04:40:40 +08:00
|
|
|
interface AllExtensions {
|
|
|
|
Paragraph: typeof Paragraph,
|
|
|
|
}
|
|
|
|
}
|