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,39 +1,56 @@
import {
Command, Mark, markInputRule, markPasteRule,
Command, createMark, markInputRule, markPasteRule,
} from '@tiptap/core'
export type CodeCommand = () => Command
// export type CodeCommand = () => Command
declare module '@tiptap/core/src/Editor' {
interface Commands {
code: CodeCommand,
}
}
// declare module '@tiptap/core/src/Editor' {
// interface Commands {
// code: CodeCommand,
// }
// }
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
export default new Mark()
.name('code')
.schema(() => ({
excludes: '_',
parseDOM: [
export default createMark({
name: 'code',
excludes: '_',
parseHTML() {
return [
{ tag: 'code' },
],
toDOM: () => ['code', 0],
}))
.commands(({ name }) => ({
code: () => ({ commands }) => {
return commands.toggleMark(name)
},
}))
.keys(({ editor }) => ({
'Mod-`': () => editor.code(),
}))
.inputRules(({ type }) => [
markInputRule(inputRegex, type),
])
.pasteRules(({ type }) => [
markPasteRule(inputRegex, type),
])
.create()
]
},
renderHTML({ attributes }) {
return ['strong', attributes, 0]
},
addCommands() {
return {
code: () => ({ commands }) => {
return commands.toggleMark('code')
},
}
},
addKeyboardShortcuts() {
return {
'Mod-`': () => this.editor.code(),
}
},
addInputRules() {
return [
markInputRule(inputRegex, this.type),
]
},
addPasteRules() {
return [
markPasteRule(inputRegex, this.type),
]
},
})