add basic highlight extension
This commit is contained in:
31
packages/extension-highlight/index.ts
Normal file
31
packages/extension-highlight/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
Command, Mark,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export type HighlightCommand = () => Command
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Commands {
|
||||
highlight: HighlightCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default new Mark()
|
||||
.name('highlight')
|
||||
.schema(() => ({
|
||||
parseDOM: [
|
||||
{
|
||||
tag: 'mark',
|
||||
},
|
||||
],
|
||||
toDOM: () => ['mark', 0],
|
||||
}))
|
||||
.commands(({ name }) => ({
|
||||
highlight: () => ({ commands }) => {
|
||||
return commands.toggleMark(name)
|
||||
},
|
||||
}))
|
||||
.keys(({ editor }) => ({
|
||||
'Mod-e': () => editor.highlight(),
|
||||
}))
|
||||
.create()
|
||||
Reference in New Issue
Block a user