Files
tiptap/packages/extension-list-item/src/list-item.ts
Dominik 8c6751f0c6 add precommit hook for linting and automatic eslint fixes + update eslint packages (#2862)
* chore: add precommit hook for eslint fixes, fix linting issues
* chore: add eslint import sort plugin
2022-06-08 14:10:25 +02:00

40 lines
781 B
TypeScript

import { mergeAttributes, Node } from '@tiptap/core'
export interface ListItemOptions {
HTMLAttributes: Record<string, any>,
}
export const ListItem = Node.create<ListItemOptions>({
name: 'listItem',
addOptions() {
return {
HTMLAttributes: {},
}
},
content: 'paragraph block*',
defining: true,
parseHTML() {
return [
{
tag: 'li',
},
]
},
renderHTML({ HTMLAttributes }) {
return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
},
addKeyboardShortcuts() {
return {
Enter: () => this.editor.commands.splitListItem(this.name),
Tab: () => this.editor.commands.sinkListItem(this.name),
'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
}
},
})