Add support for custom protocols in extension-link (#2832)
This commit is contained in:
@@ -20,6 +20,17 @@ npm install @tiptap/extension-link
|
|||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
|
### protocols
|
||||||
|
Additional custom protocols you would like to be recognized as links.
|
||||||
|
|
||||||
|
Default: `[]`
|
||||||
|
|
||||||
|
```js
|
||||||
|
Link.configure({
|
||||||
|
protocols: ['ftp', 'mailto'],
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### autolink
|
### autolink
|
||||||
If enabled, it adds links as you type.
|
If enabled, it adds links as you type.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { find } from 'linkifyjs'
|
import { find, registerCustomProtocol } from 'linkifyjs'
|
||||||
|
|
||||||
import { Mark, markPasteRule, mergeAttributes } from '@tiptap/core'
|
import { Mark, markPasteRule, mergeAttributes } from '@tiptap/core'
|
||||||
|
|
||||||
@@ -11,6 +11,10 @@ export interface LinkOptions {
|
|||||||
* If enabled, it adds links as you type.
|
* If enabled, it adds links as you type.
|
||||||
*/
|
*/
|
||||||
autolink: boolean,
|
autolink: boolean,
|
||||||
|
/**
|
||||||
|
* An array of custom protocols to be registered with linkifyjs.
|
||||||
|
*/
|
||||||
|
protocols: Array<string>,
|
||||||
/**
|
/**
|
||||||
* If enabled, links will be opened on click.
|
* If enabled, links will be opened on click.
|
||||||
*/
|
*/
|
||||||
@@ -57,6 +61,12 @@ export const Link = Mark.create<LinkOptions>({
|
|||||||
|
|
||||||
keepOnSplit: false,
|
keepOnSplit: false,
|
||||||
|
|
||||||
|
onCreate() {
|
||||||
|
for (const protocol of this.options.protocols) {
|
||||||
|
registerCustomProtocol(protocol)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
inclusive() {
|
inclusive() {
|
||||||
return this.options.autolink
|
return this.options.autolink
|
||||||
},
|
},
|
||||||
@@ -66,6 +76,7 @@ export const Link = Mark.create<LinkOptions>({
|
|||||||
openOnClick: true,
|
openOnClick: true,
|
||||||
linkOnPaste: true,
|
linkOnPaste: true,
|
||||||
autolink: true,
|
autolink: true,
|
||||||
|
protocols: [],
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
rel: 'noopener noreferrer nofollow',
|
rel: 'noopener noreferrer nofollow',
|
||||||
|
|||||||
Reference in New Issue
Block a user