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

@ -27,8 +27,7 @@
"prosemirror-state": "^1.3.3", "prosemirror-state": "^1.3.3",
"prosemirror-tables": "^1.1.1", "prosemirror-tables": "^1.1.1",
"prosemirror-utils": "^0.9.6", "prosemirror-utils": "^0.9.6",
"prosemirror-view": "^1.15.6", "prosemirror-view": "^1.15.6"
"verbal-expressions": "^1.0.2"
}, },
"scripts": { "scripts": {
"build": "microbundle" "build": "microbundle"

View File

@ -1,5 +1,4 @@
import { Mark, markInputRule, markPasteRule } from '@tiptap/core' import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
import VerEx from 'verbal-expressions'
declare module '@tiptap/core/src/Editor' { declare module '@tiptap/core/src/Editor' {
interface Editor { interface Editor {
@ -7,6 +6,11 @@ declare module '@tiptap/core/src/Editor' {
} }
} }
export const starInputRegex = /(?:^|\s)((?:\*\*)((?:[^\*\*]+))(?:\*\*))$/gm
export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^\*\*]+))(?:\*\*))/gm
export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm
export const underscorePasteRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))/gm
export default new Mark() export default new Mark()
.name('bold') .name('bold')
.schema(() => ({ .schema(() => ({
@ -34,35 +38,12 @@ export default new Mark()
.keys(({ editor }) => ({ .keys(({ editor }) => ({
'Mod-b': () => editor.bold() 'Mod-b': () => editor.bold()
})) }))
.inputRules(({ type }) => { .inputRules(({ type }) => [
return ['**', '__'].map(character => { markInputRule(starInputRegex, type),
const regex = VerEx() markInputRule(underscoreInputRegex, type),
.add('(?:^|\\s)') ])
.beginCapture() .pasteRules(({ type }) => [
.find(character) markPasteRule(starPasteRegex, type),
.beginCapture() markPasteRule(underscorePasteRegex, type),
.somethingBut(character) ])
.endCapture()
.find(character)
.endCapture()
.endOfLine()
return markInputRule(regex, type)
})
})
.pasteRules(({ type }) => {
return ['**', '__'].map(character => {
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
return markPasteRule(regex, type)
})
})
.create() .create()

View File

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

View File

@ -1,6 +1,4 @@
import { Node, CommandSpec } from '@tiptap/core' import { Node } from '@tiptap/core'
import { NodeSpec } from 'prosemirror-model'
import VerEx from 'verbal-expressions'
import { textblockTypeInputRule } from 'prosemirror-inputrules' import { textblockTypeInputRule } from 'prosemirror-inputrules'
type Level = 1 | 2 | 3 | 4 | 5 | 6 type Level = 1 | 2 | 3 | 4 | 5 | 6
@ -45,14 +43,7 @@ export default new Node<HeadingOptions>()
})) }))
.inputRules(({ options, type }) => { .inputRules(({ options, type }) => {
return options.levels.map((level: Level) => { return options.levels.map((level: Level) => {
const regex = VerEx() return textblockTypeInputRule(new RegExp(`^(?:#){${level}}\s$/gm`), type, { level })
.startOfLine()
.find('#')
.repeatPrevious(level)
.whitespace()
.endOfLine()
return textblockTypeInputRule(regex, type, { level })
}) })
}) })
.create() .create()

View File

@ -1,5 +1,4 @@
import { Mark, markInputRule, markPasteRule } from '@tiptap/core' import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
import VerEx from 'verbal-expressions'
declare module '@tiptap/core/src/Editor' { declare module '@tiptap/core/src/Editor' {
interface Editor { interface Editor {
@ -7,6 +6,11 @@ declare module '@tiptap/core/src/Editor' {
} }
} }
export const starInputRegex = /(?:^|\s)((?:\*)((?:[^\*]+))(?:\*))$/gm
export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^\*]+))(?:\*))/gm
export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm
export const underscorePasteRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/gm
export default new Mark() export default new Mark()
.name('italic') .name('italic')
.schema(() => ({ .schema(() => ({
@ -26,35 +30,12 @@ export default new Mark()
.keys(({ editor }) => ({ .keys(({ editor }) => ({
'Mod-i': () => editor.italic() 'Mod-i': () => editor.italic()
})) }))
.inputRules(({ type }) => { .inputRules(({ type }) => [
return ['*', '_'].map(character => { markInputRule(starInputRegex, type),
const regex = VerEx() markInputRule(underscoreInputRegex, type),
.add('(?:^|\\s)') ])
.beginCapture() .pasteRules(({ type }) => [
.find(character) markPasteRule(starPasteRegex, type),
.beginCapture() markPasteRule(underscorePasteRegex, type),
.somethingBut(character) ])
.endCapture()
.find(character)
.endCapture()
.endOfLine()
return markInputRule(regex, type)
})
})
.pasteRules(({ type }) => {
return ['*', '_'].map(character => {
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
return markPasteRule(regex, type)
})
})
.create() .create()

View File

@ -13476,11 +13476,6 @@ 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"