add verbal expressions

This commit is contained in:
Philipp Kühn
2020-04-02 12:41:52 +02:00
parent a914786f46
commit 434d77a664
5 changed files with 138 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
import { toggleMark } from 'prosemirror-commands'
import { MarkSpec } from 'prosemirror-model'
import VerEx from 'verbal-expressions'
declare module '@tiptap/core/src/Editor' {
interface Editor {
@@ -37,17 +38,69 @@ export default class Italic extends Mark {
}
inputRules() {
return [
markInputRule(/(?:^|[^_])(_([^_]+)_)$/, this.schemaType),
// markInputRule(/(?:^|[^*])(\*([^*]+)\*)$/, this.schemaType),
]
return ['*', '_'].map(character => ([
// match start of line
markInputRule(
VerEx()
.startOfLine()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.schemaType,
),
// match before whitespace
markInputRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.schemaType,
),
]))
.flat(1)
}
pasteRules() {
return [
markPasteRule(/_([^_]+)_/g, this.schemaType),
// markPasteRule(/\*([^*]+)\*/g, this.schemaType),
]
return ['*', '_'].map(character => ([
// match start of line
markPasteRule(
VerEx()
.startOfLine()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.schemaType,
),
// match before whitespace
markPasteRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.schemaType,
),
]))
.flat(1)
}
}