Links and Anchors in the Vue 3 Editor
In Vue 3, link and anchor tools are switched on through the :init binding of <Editor>. Adding link and anchor to plugins gives users a dialog for creating, editing, and unlinking hyperlinks, plus an Insert → Anchor action that drops a bookmark with a generated ID. The resulting <a> markup flows back into your v-model value.
For video, audio, and iframe URLs, use the separate dialog described in media and embeds.
Toolbar and Menubar Configuration
Add link and anchor controls to your configuration:
const editorConfig: EditorInit = {
plugins: ['link', 'anchor'],
menubar: ['insert'],
toolbar: 'undo redo | blocks | bold italic | link removeformat',
};Inside a single-file component, define the same object in <script setup> and bind it with :init:
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Editor, type EditorInit } from '@erag/text-editor-vue';
const content = shallowRef(
'<p>Read the <a href="https://example.com">guide</a>.</p>',
);
const editorConfig: EditorInit = {
plugins: ['link', 'anchor'],
menubar: ['insert'],
toolbar: 'undo redo | blocks | bold italic | link removeformat',
};
</script>
<template>
<Editor v-model="content" :init="editorConfig" />
</template>Link Insertion and Edit Dialog
Clicking the Link icon in the toolbar or navigating to Insert → Link opens the Link Modal Dialog with the following options:
- URL (
href): Target hyperlink web address or mailto URL. - Text to Display: Text label inserted inside
<a href="...">Text</a>. - Title Attribute: Accessibility tooltip title attribute.
- Open in New Tab (
target="_blank"): Addstarget="_blank"andrel="noopener noreferrer"for external links.
Links with unsafe protocols are not kept; see security and sanitization for the full rules.
Modifying Existing Links
Positioning your caret inside an existing link and clicking the Link button re-populates the dialog with existing values for quick editing. Click Unlink in the dialog or toolbar to strip the <a> tag while keeping the text intact.
Anchors (anchor)
Anchors create an empty bookmark element with a generated ID. anchor is an Insert-menu action rather than a toolbar keyword.
- Place the caret where the bookmark should live.
- Select Insert → Anchor from the menubar.
- Read the generated
idfrom the HTML source when creating a matching#idlink.
<a id="generated-id" name="anchor"></a>