Insert dividers and dates in the Vue 3 editor
In the Vue 3 editor, the horizontal-rule plugin puts an <hr> divider at the caret and the date-time plugin inserts the current date or time from the Insert menu. Both are switched on through the init object you bind with :init.
Configuration
Include horizontal-rule and date-time plugins:
const editorConfig: EditorInit = {
plugins: ['horizontal-rule', 'date-time'],
menubar: ['insert'],
toolbar: 'undo redo | blocks | bold italic | hr removeformat',
};Horizontal Rules (hr)
Clicking the Horizontal Rule (hr) button inserts a thematic section break line (<hr> element) at the cursor position.
<hr />
<p><br /></p>The trailing paragraph gives the caret a valid place to continue typing after the divider.
Date and Time Stamps (date-time)
Open Insert → Date/time and choose a configured value. Date and time values are generated when the menu opens, so they do not become stale. date-time is a plugin name, not a toolbar keyword.
const editorConfig: EditorInit = {
dateFormats: [
{
label: 'Long date',
type: 'date',
options: { year: 'numeric', month: 'long', day: 'numeric' },
},
],
timeFormats: [
{
label: '24-hour time',
type: 'time',
options: { hour: '2-digit', minute: '2-digit', hour12: false },
},
],
};The same options in a single-file component:
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Editor, type EditorInit } from '@erag/text-editor-vue';
const notes = shallowRef('');
const editorConfig: EditorInit = {
toolbar: 'undo redo | bold italic | hr',
timeFormats: [
{
label: '12-hour time',
type: 'time',
options: { hour: 'numeric', minute: '2-digit', hour12: true },
},
],
};
</script>
<template>
<Editor v-model="notes" :init="editorConfig" />
</template>The configuration reference lists the defaults for both format lists.