add verbal expressions
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
"prosemirror-state": "^1.3.3",
|
"prosemirror-state": "^1.3.3",
|
||||||
"prosemirror-tables": "^1.0.0",
|
"prosemirror-tables": "^1.0.0",
|
||||||
"prosemirror-utils": "^0.9.6",
|
"prosemirror-utils": "^0.9.6",
|
||||||
"prosemirror-view": "^1.14.6"
|
"prosemirror-view": "^1.14.6",
|
||||||
|
"verbal-expressions": "^1.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,19 @@ export default function (regexp: RegExp, type: MarkType, getAttrs?: Function) {
|
|||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
while ((match = regexp.exec(text)) !== null) {
|
while ((match = regexp.exec(text)) !== null) {
|
||||||
|
const m = match.length - 1
|
||||||
|
|
||||||
if (parent.type.allowsMarkType(type) && match[1]) {
|
if (parent.type.allowsMarkType(type) && match[1]) {
|
||||||
const start = match.index
|
const start = match.index
|
||||||
const end = start + match[0].length
|
const matchStart = start + match[0].indexOf(match[m - 1])
|
||||||
const textStart = start + match[0].indexOf(match[1])
|
const matchEnd = matchStart + match[m - 1].length // TODO: why is there no -1
|
||||||
const textEnd = textStart + match[1].length
|
const textStart = matchStart + match[m - 1].lastIndexOf(match[m])
|
||||||
|
const textEnd = textStart + match[m].length
|
||||||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
||||||
|
|
||||||
// adding text before markdown to nodes
|
// adding text before markdown to nodes
|
||||||
if (start > 0) {
|
if (matchStart > 0) {
|
||||||
nodes.push(child.cut(pos, start))
|
nodes.push(child.cut(pos, matchStart))
|
||||||
}
|
}
|
||||||
|
|
||||||
// adding the markdown part to nodes
|
// adding the markdown part to nodes
|
||||||
@@ -32,7 +35,7 @@ export default function (regexp: RegExp, type: MarkType, getAttrs?: Function) {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mark(type.create(attrs).addToSet(child.marks)))
|
.mark(type.create(attrs).addToSet(child.marks)))
|
||||||
|
|
||||||
pos = end
|
pos = matchEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
||||||
import { toggleMark } from 'prosemirror-commands'
|
import { toggleMark } from 'prosemirror-commands'
|
||||||
import { MarkSpec } from 'prosemirror-model'
|
import { MarkSpec } from 'prosemirror-model'
|
||||||
|
import VerEx from 'verbal-expressions'
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Editor {
|
||||||
@@ -45,15 +46,69 @@ export default class Bold extends Mark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inputRules() {
|
inputRules() {
|
||||||
return [
|
return ['**', '__'].map(character => ([
|
||||||
markInputRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, this.schemaType),
|
// 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() {
|
pasteRules() {
|
||||||
return [
|
return ['**', '__'].map(character => ([
|
||||||
markPasteRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)/g, this.schemaType),
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
||||||
import { toggleMark } from 'prosemirror-commands'
|
import { toggleMark } from 'prosemirror-commands'
|
||||||
import { MarkSpec } from 'prosemirror-model'
|
import { MarkSpec } from 'prosemirror-model'
|
||||||
|
import VerEx from 'verbal-expressions'
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Editor {
|
||||||
@@ -37,17 +38,69 @@ export default class Italic extends Mark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inputRules() {
|
inputRules() {
|
||||||
return [
|
return ['*', '_'].map(character => ([
|
||||||
markInputRule(/(?:^|[^_])(_([^_]+)_)$/, this.schemaType),
|
// match start of line
|
||||||
// markInputRule(/(?:^|[^*])(\*([^*]+)\*)$/, this.schemaType),
|
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() {
|
pasteRules() {
|
||||||
return [
|
return ['*', '_'].map(character => ([
|
||||||
markPasteRule(/_([^_]+)_/g, this.schemaType),
|
// match start of line
|
||||||
// markPasteRule(/\*([^*]+)\*/g, this.schemaType),
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14282,6 +14282,11 @@ vendors@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/vendors/-/vendors-1.0.4.tgz#e2b800a53e7a29b93506c3cf41100d16c4c4ad8e"
|
resolved "https://registry.yarnpkg.com/vendors/-/vendors-1.0.4.tgz#e2b800a53e7a29b93506c3cf41100d16c4c4ad8e"
|
||||||
integrity sha512-/juG65kTL4Cy2su4P8HjtkTxk6VmJDiOPBufWniqQ6wknac6jNiXS9vU+hO3wgusiyqWlzTbVHi0dyJqRONg3w==
|
integrity sha512-/juG65kTL4Cy2su4P8HjtkTxk6VmJDiOPBufWniqQ6wknac6jNiXS9vU+hO3wgusiyqWlzTbVHi0dyJqRONg3w==
|
||||||
|
|
||||||
|
verbal-expressions@^1.0.2:
|
||||||
|
version "1.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/verbal-expressions/-/verbal-expressions-1.0.2.tgz#1f2d28fdcf7169be270777ff5fadcdb2b3b905c5"
|
||||||
|
integrity sha512-LV8eG4ckcg1iIhGjOF+j1jb0b58m1DgGywce+2U8kbRrB5wZnGe4XCyUyOujZR9D/+rJGXTmxnL30o3zAgmC4w==
|
||||||
|
|
||||||
verror@1.10.0:
|
verror@1.10.0:
|
||||||
version "1.10.0"
|
version "1.10.0"
|
||||||
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
|
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
|
||||||
|
|||||||
Reference in New Issue
Block a user