add new syntax to all extensions

This commit is contained in:
Philipp Kühn
2020-10-22 12:34:49 +02:00
parent e442b5a8fe
commit 79172753ef
22 changed files with 873 additions and 703 deletions

View File

@@ -1,37 +1,52 @@
import { Command, Node } from '@tiptap/core'
import { Command, createNode } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
export type BlockquoteCommand = () => Command
// export type BlockquoteCommand = () => Command
declare module '@tiptap/core/src/Editor' {
interface Commands {
blockquote: BlockquoteCommand,
}
}
// declare module '@tiptap/core/src/Editor' {
// interface Commands {
// blockquote: BlockquoteCommand,
// }
// }
export const inputRegex = /^\s*>\s$/gm
export default new Node()
.name('blockquote')
.schema(() => ({
content: 'block*',
group: 'block',
defining: true,
draggable: false,
parseDOM: [
export default createNode({
name: 'blockquote',
content: 'block*',
group: 'block',
defining: true,
parseHTML() {
return [
{ tag: 'blockquote' },
],
toDOM: () => ['blockquote', 0],
}))
.commands(({ name }) => ({
[name]: () => ({ commands }) => {
return commands.toggleWrap(name)
},
}))
.keys(({ editor }) => ({
'Shift-Mod-9': () => editor.blockquote(),
}))
.inputRules(({ type }) => [
wrappingInputRule(inputRegex, type),
])
.create()
]
},
renderHTML({ attributes }) {
return ['blockquote', attributes, 0]
},
addCommands() {
return {
blockquote: () => ({ commands }) => {
return commands.toggleWrap('blockquote')
},
}
},
addKeyboardShortcuts() {
return {
'Shift-Mod-9': () => this.editor.blockquote(),
}
},
addInputRules() {
return [
wrappingInputRule(inputRegex, this.type),
]
},
})