remove verbal expressions

This commit is contained in:
Philipp Kühn
2020-09-09 18:47:47 +02:00
parent fab2fce671
commit ba744cf6d8
6 changed files with 38 additions and 110 deletions

View File

@@ -1,5 +1,4 @@
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
import VerEx from 'verbal-expressions'
declare module '@tiptap/core/src/Editor' {
interface Editor {
@@ -7,6 +6,9 @@ declare module '@tiptap/core/src/Editor' {
}
}
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
export default new Mark()
.name('code')
.schema(() => ({
@@ -25,31 +27,10 @@ export default new Mark()
.keys(({ editor }) => ({
'Mod-`': () => editor.code()
}))
.inputRules(({ type }) => {
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find('`')
.beginCapture()
.somethingBut('`')
.endCapture()
.find('`')
.endCapture()
.endOfLine()
return [markInputRule(regex, type)]
})
.pasteRules(({ type }) => {
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find('`')
.beginCapture()
.somethingBut('`')
.endCapture()
.find('`')
.endCapture()
return [markPasteRule(regex, type)]
})
.inputRules(({ type }) => [
markInputRule(inputRegex, type)
])
.pasteRules(({ type }) => [
markPasteRule(inputRegex, type)
])
.create()