Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optionalSlashSlash to protocol options #3675

Merged
merged 7 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
taras-turchenko-moc marked this conversation as resolved.
Show resolved Hide resolved
},
"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
2 changes: 1 addition & 1 deletion packages/react/src/EditorContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class PureEditorContent extends React.Component<EditorContentProps, Edito
// a lifecycle method.
if (this.initialized) {
queueMicrotask(() => {
flushSync(fn)
flushSync(fn)
})
} else {
fn()
Expand Down