diff --git a/docs/src/demos/Examples/Links/index.vue b/docs/src/demos/Examples/Links/index.vue index 6bb39c7d..d0a9be48 100644 --- a/docs/src/demos/Examples/Links/index.vue +++ b/docs/src/demos/Examples/Links/index.vue @@ -3,7 +3,7 @@ link - + remove @@ -55,7 +55,7 @@ export default { addLink() { const url = window.prompt('URL') - this.editor.chain().focus().link({ href: url }).run() + this.editor.chain().focus().addLink({ href: url }).run() }, }, diff --git a/docs/src/demos/Marks/Link/index.vue b/docs/src/demos/Marks/Link/index.vue index 296f6e8c..b3f13350 100644 --- a/docs/src/demos/Marks/Link/index.vue +++ b/docs/src/demos/Marks/Link/index.vue @@ -3,7 +3,7 @@ link - + remove @@ -52,7 +52,7 @@ export default { addLink() { const url = window.prompt('URL') - this.editor.chain().focus().link({ href: url }).run() + this.editor.chain().focus().addLink({ href: url }).run() }, }, diff --git a/packages/extension-link/src/index.ts b/packages/extension-link/src/index.ts index 2b89b4c6..829afd29 100644 --- a/packages/extension-link/src/index.ts +++ b/packages/extension-link/src/index.ts @@ -47,14 +47,22 @@ const Link = Mark.create({ addCommands() { return { /** - * Toggle or update a link mark + * Add a link mark */ - link: (options: { href?: string, target?: string } = {}): Command => ({ commands }) => { - if (!options.href) { - return commands.removeMark('link') - } - - return commands.addMark('link', options) + addLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { + return commands.addMark('link', attributes) + }, + /** + * Toggle a link mark + */ + toggleLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { + return commands.toggleMark('link', attributes) + }, + /** + * Remove a link mark + */ + removeLink: (): Command => ({ commands }) => { + return commands.removeMark('link') }, } },