added pasteRules to marks

This commit is contained in:
Chrissi2812
2019-01-31 15:11:16 +01:00
parent e0fbea0734
commit 027a4db452
5 changed files with 31 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import { Mark } from 'tiptap' import { Mark } from 'tiptap'
import { toggleMark, markInputRule } from 'tiptap-commands' import { toggleMark, markInputRule, markPasteRule } from 'tiptap-commands'
export default class Bold extends Mark { export default class Bold extends Mark {
@@ -42,4 +42,10 @@ export default class Bold extends Mark {
] ]
} }
pasteRules({ type }) {
return [
markPasteRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)/g, type),
]
}
} }

View File

@@ -1,5 +1,5 @@
import { Mark } from 'tiptap' import { Mark } from 'tiptap'
import { toggleMark, markInputRule } from 'tiptap-commands' import { toggleMark, markInputRule, markPasteRule } from 'tiptap-commands'
export default class Code extends Mark { export default class Code extends Mark {
@@ -32,4 +32,10 @@ export default class Code extends Mark {
] ]
} }
pasteRules({ type }) {
return [
markPasteRule(/(?:`)([^`]+)(?:`)/g, type),
]
}
} }

View File

@@ -1,5 +1,5 @@
import { Mark } from 'tiptap' import { Mark } from 'tiptap'
import { toggleMark, markInputRule } from 'tiptap-commands' import { toggleMark, markInputRule, markPasteRule } from 'tiptap-commands'
export default class Italic extends Mark { export default class Italic extends Mark {
@@ -34,4 +34,10 @@ export default class Italic extends Mark {
] ]
} }
pasteRules({ type }) {
return [
markPasteRule(/(?:^|[^*_])(?:\*|_)([^*_]+)(?:\*|_)/g, type),
]
}
} }

View File

@@ -1,5 +1,5 @@
import { Mark } from 'tiptap' import { Mark } from 'tiptap'
import { toggleMark, markInputRule } from 'tiptap-commands' import { toggleMark, markInputRule, markPasteRule } from 'tiptap-commands'
export default class Strike extends Mark { export default class Strike extends Mark {
@@ -44,4 +44,10 @@ export default class Strike extends Mark {
] ]
} }
pasteRules({ type }) {
return [
markPasteRule(/~([^~]+)~/g, type),
]
}
} }

View File

@@ -31,6 +31,7 @@ export default class Editor {
onUpdate: () => {}, onUpdate: () => {},
onFocus: () => {}, onFocus: () => {},
onBlur: () => {}, onBlur: () => {},
onPaste: () => {},
} }
this.init(options) this.init(options)
@@ -198,6 +199,8 @@ export default class Editor {
createView() { createView() {
const view = new EditorView(this.element, { const view = new EditorView(this.element, {
state: this.state, state: this.state,
handlePaste: this.options.onPaste,
handleDrop: this.options.onPaste,
dispatchTransaction: this.dispatchTransaction.bind(this), dispatchTransaction: this.dispatchTransaction.bind(this),
}) })