diff --git a/docs/api/marks/link.md b/docs/api/marks/link.md index 1aad36b2f79..4182c72763f 100644 --- a/docs/api/marks/link.md +++ b/docs/api/marks/link.md @@ -20,6 +20,17 @@ npm install @tiptap/extension-link ## Settings +### protocols +Additional custom protocols you would like to be recognized as links. + +Default: `[]` + +```js +Link.configure({ + protocols: ['ftp', 'mailto'], +}) +``` + ### autolink If enabled, it adds links as you type. diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index 43d6c11f69f..2e5115e2054 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -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, /** * If enabled, links will be opened on click. */ @@ -57,6 +61,12 @@ export const Link = Mark.create({ 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({ openOnClick: true, linkOnPaste: true, autolink: true, + protocols: [], HTMLAttributes: { target: '_blank', rel: 'noopener noreferrer nofollow',