mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix link paste rule
This commit is contained in:
parent
7a1c33242d
commit
40b0467650
@ -14,14 +14,15 @@ export default function (regexp: RegExp, type: MarkType, getAttrs?: Function) {
|
||||
|
||||
// eslint-disable-next-line
|
||||
while ((match = regexp.exec(text)) !== null) {
|
||||
const m = match.length - 1
|
||||
const outerMatch = Math.max(match.length - 2, 0)
|
||||
const innerMatch = Math.max(match.length - 1, 0)
|
||||
|
||||
if (parent.type.allowsMarkType(type) && match[1]) {
|
||||
if (parent.type.allowsMarkType(type)) {
|
||||
const start = match.index
|
||||
const matchStart = start + match[0].indexOf(match[m - 1])
|
||||
const matchEnd = matchStart + match[m - 1].length // TODO: why is there no -1
|
||||
const textStart = matchStart + match[m - 1].lastIndexOf(match[m])
|
||||
const textEnd = textStart + match[m].length
|
||||
const matchStart = start + match[0].indexOf(match[outerMatch])
|
||||
const matchEnd = matchStart + match[outerMatch].length
|
||||
const textStart = matchStart + match[outerMatch].lastIndexOf(match[innerMatch])
|
||||
const textEnd = textStart + match[innerMatch].length
|
||||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
||||
|
||||
// adding text before markdown to nodes
|
||||
|
@ -16,7 +16,7 @@ declare module '@tiptap/core/src/Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const pasteRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/gi
|
||||
export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%_+.~#?&//=]*)/gi
|
||||
|
||||
export default new Mark<LinkOptions>()
|
||||
.name('link')
|
||||
@ -55,7 +55,7 @@ export default new Mark<LinkOptions>()
|
||||
},
|
||||
}))
|
||||
.pasteRules(({ type }) => [
|
||||
markPasteRule(pasteRegex, type),
|
||||
markPasteRule(pasteRegex, type, (url: string) => ({ href: url })),
|
||||
])
|
||||
.plugins(({ options }) => {
|
||||
if (!options.openOnClick) {
|
||||
|
Loading…
Reference in New Issue
Block a user