Add support for custom protocols in extension-link (#2832)

This commit is contained in:
Shengchen Zhang
2022-06-06 23:33:45 +08:00
committed by GitHub
parent d85444c310
commit 50083f3be1
2 changed files with 23 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { find } from 'linkifyjs'
import { find, registerCustomProtocol } from 'linkifyjs'
import { Mark, markPasteRule, mergeAttributes } from '@tiptap/core'
@@ -11,6 +11,10 @@ export interface LinkOptions {
* If enabled, it adds links as you type.
*/
autolink: boolean,
/**
* An array of custom protocols to be registered with linkifyjs.
*/
protocols: Array<string>,
/**
* If enabled, links will be opened on click.
*/
@@ -57,6 +61,12 @@ export const Link = Mark.create<LinkOptions>({
keepOnSplit: false,
onCreate() {
for (const protocol of this.options.protocols) {
registerCustomProtocol(protocol)
}
},
inclusive() {
return this.options.autolink
},
@@ -66,6 +76,7 @@ export const Link = Mark.create<LinkOptions>({
openOnClick: true,
linkOnPaste: true,
autolink: true,
protocols: [],
HTMLAttributes: {
target: '_blank',
rel: 'noopener noreferrer nofollow',