tiptap/packages/extension-bullet-list/index.ts

49 lines
882 B
TypeScript
Raw Normal View History

2020-10-22 18:34:49 +08:00
import { Command, createNode } from '@tiptap/core'
2020-09-11 04:29:15 +08:00
import { wrappingInputRule } from 'prosemirror-inputrules'
2020-10-22 18:34:49 +08:00
// export type BulletListCommand = () => Command
2020-09-22 15:08:08 +08:00
2020-10-22 18:34:49 +08:00
// declare module '@tiptap/core/src/Editor' {
// interface Commands {
// bulletList: BulletListCommand,
// }
// }
2020-09-11 04:29:15 +08:00
2020-10-22 18:34:49 +08:00
export default createNode({
name: 'bullet_list',
content: 'list_item+',
group: 'block',
parseHTML() {
return [
2020-09-11 04:29:15 +08:00
{ tag: 'ul' },
2020-10-22 18:34:49 +08:00
]
},
renderHTML({ attributes }) {
return ['ul', attributes, 0]
},
addCommands() {
return {
bulletList: () => ({ commands }) => {
return commands.toggleList('bullet_list', 'list_item')
},
}
},
addKeyboardShortcuts() {
return {
'Shift-Control-8': () => this.editor.bulletList(),
}
},
addInputRules() {
return [
wrappingInputRule(/^\s*([-+*])\s$/, this.type),
]
},
})