Skip to content

Commit

Permalink
add optionalSlashSlash to protocol options (#3675)
Browse files Browse the repository at this point in the history
* add optionalSlashSlash to protocol options

* Update documentation

* rename optionalSlashSlash to optionalSlashes

* regenerate package-lock.json with node v16
  • Loading branch information
taras-turchenko-moc authored Feb 27, 2023
1 parent 8262564 commit 1ac3070
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
12 changes: 12 additions & 0 deletions docs/api/marks/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ Link.configure({
})
```

By default, [linkify](https://linkify.js.org/docs/) adds `//` to the end of a protocol however this behavior can be changed by passing `optionalSlashes` option
```js
Link.configure({
protocols: [
{
scheme: 'tel',
optionalSlashes: true
}
]
})
```

### autolink
If enabled, it adds links as you type.

Expand Down
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/extension-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@tiptap/pm": "^2.0.0-beta.218"
},
"dependencies": {
"linkifyjs": "^3.0.5"
"linkifyjs": "^4.1.0"
},
"repository": {
"type": "git",
Expand Down
15 changes: 13 additions & 2 deletions packages/extension-link/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { autolink } from './helpers/autolink'
import { clickHandler } from './helpers/clickHandler'
import { pasteHandler } from './helpers/pasteHandler'

export interface LinkProtocolOptions {
scheme: string;
optionalSlashes?: boolean;
}

export interface LinkOptions {
/**
* If enabled, it adds links as you type.
Expand All @@ -14,7 +19,7 @@ export interface LinkOptions {
/**
* An array of custom protocols to be registered with linkifyjs.
*/
protocols: Array<string>
protocols: Array<LinkProtocolOptions | string>
/**
* If enabled, links will be opened on click.
*/
Expand Down Expand Up @@ -62,7 +67,13 @@ export const Link = Mark.create<LinkOptions>({
keepOnSplit: false,

onCreate() {
this.options.protocols.forEach(registerCustomProtocol)
this.options.protocols.forEach(protocol => {
if (typeof protocol === 'string') {
registerCustomProtocol(protocol)
return
}
registerCustomProtocol(protocol.scheme, protocol.optionalSlashes)
})
},

onDestroy() {
Expand Down

0 comments on commit 1ac3070

Please sign in to comment.