add basic task list and task item extension

This commit is contained in:
Philipp Kühn
2020-10-30 13:19:06 +01:00
parent f9089932ff
commit 3e00fadcaa
10 changed files with 232 additions and 5 deletions

View File

@@ -0,0 +1,45 @@
import { Command, createNode, mergeAttributes } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
const TaskList = createNode({
name: 'task_list',
group: 'block',
content: 'task_item+',
parseHTML() {
return [
{
tag: 'ul[data-type="task_list"]',
priority: 51,
},
]
},
renderHTML({ attributes }) {
return ['ul', mergeAttributes(attributes, { 'data-type': 'task_list' }), 0]
},
addCommands() {
return {
taskList: (): Command => ({ commands }) => {
return commands.toggleList('task_list', 'task_item')
},
}
},
addInputRules() {
return [
wrappingInputRule(/^\s*(\[ \])\s$/, this.type),
]
},
})
export default TaskList
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
TaskList: typeof TaskList,
}
}