tiptap/packages/extension-paragraph/src/index.ts

57 lines
908 B
TypeScript
Raw Normal View History

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
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-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 {
'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-16 22:40:05 +08:00
declare global {
namespace Tiptap {
interface AllExtensions {
Paragraph: typeof Paragraph,
}
2020-10-23 04:40:40 +08:00
}
}