mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +08:00
docs: improve the link mark example, fix #1277
This commit is contained in:
parent
63d8e84451
commit
b901669803
@ -1,10 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="editor">
|
<div v-if="editor">
|
||||||
<button @click="setLink" :class="{ 'is-active': editor.isActive('link') }">
|
<button @click="setLink" :class="{ 'is-active': editor.isActive('link') }">
|
||||||
link
|
setLink
|
||||||
</button>
|
</button>
|
||||||
<button @click="editor.chain().focus().unsetLink().run()" v-if="editor.isActive('link')">
|
<button @click="editor.chain().focus().unsetLink().run()" v-if="editor.isActive('link')">
|
||||||
remove
|
unsetLink
|
||||||
</button>
|
</button>
|
||||||
<editor-content :editor="editor" />
|
<editor-content :editor="editor" />
|
||||||
</div>
|
</div>
|
||||||
@ -36,7 +36,9 @@ export default {
|
|||||||
Paragraph,
|
Paragraph,
|
||||||
Text,
|
Text,
|
||||||
Bold,
|
Bold,
|
||||||
Link,
|
Link.configure({
|
||||||
|
openOnClick: false,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
<p>
|
<p>
|
||||||
@ -51,8 +53,27 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
setLink() {
|
setLink() {
|
||||||
const url = window.prompt('URL')
|
const previousUrl = this.editor.getAttributes('link').href
|
||||||
|
const url = window.prompt('URL', previousUrl)
|
||||||
|
|
||||||
|
// cancelled
|
||||||
|
if (url === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// empty
|
||||||
|
if (url === '') {
|
||||||
|
this.editor
|
||||||
|
.chain()
|
||||||
|
.focus()
|
||||||
|
.extendMarkRange('link')
|
||||||
|
.unsetLink()
|
||||||
|
.run()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// update link
|
||||||
this.editor
|
this.editor
|
||||||
.chain()
|
.chain()
|
||||||
.focus()
|
.focus()
|
||||||
|
@ -36,6 +36,13 @@ yarn add @tiptap/extension-link
|
|||||||
This extension doesn’t bind a specific keyboard shortcut. You would probably open your custom UI on `Mod-k` though.
|
This extension doesn’t bind a specific keyboard shortcut. You would probably open your custom UI on `Mod-k` though.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
## Get the current value
|
||||||
|
Did you know that you can use [`getAttributes`](/api/editor#methods) to find out which attributes, for example which href, is currently set? Don’t confuse it with a [command](/api/commands) (which changes the state), it’s just a method. Here is how that could look like:
|
||||||
|
|
||||||
|
```js
|
||||||
|
this.editor.getAttributes('link').href
|
||||||
|
```
|
||||||
|
|
||||||
## Source code
|
## Source code
|
||||||
[packages/extension-link/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-link/)
|
[packages/extension-link/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-link/)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user