- HTML Editor
- Markdown Editor
Contact Support
Editor mode in Vue Rich text editor component
26 Feb 202520 minutes to read
The Rich Text Editor component used to create, edit and return the content in valid HTML markup or markdown (MD) of the content. It supports following two editing formation.
- HTML Editor
- Markdown Editor
HTML Editor
Rich Text Editor is a WYSIWYG editing control for formatting the word content as HTML.
The HTML editing mode is the default mode of Rich Text Editor. Which is used for format the content through the available toolbar items and returns the valid HTML markup. Set the editorMode property as HTML
.
To use HTML editing feature, inject
HtmlEditor
in the provider section.
<template>
<ejs-richtexteditor ref="defaultRTE" :height="340" :value="rteValue">
</ejs-richtexteditor>
</template>
<script setup>
import { provide } from "vue";
import { RichTextEditorComponent as EjsRichtexteditor, Toolbar, Link, Image, HtmlEditor, QuickToolbar } from '@syncfusion/ej2-vue-richtexteditor';
const rteValue = `<p>The Syncfudion Rich Text Editor, a WYSIWYG (what you see is what you get) editor, is a user interface that allows you to create, edit, and format rich text content. You can try out a demo of this editor here.</p><p><b>Key features:</b></p><ul><li><p>Provides <IFRAME> and <DIV> modes.</p></li><li><p>Bulleted and numbered lists.</p></li><li><p>Handles images, hyperlinks, videos, hyperlinks, uploads, etc.</p></li><li><p>Contains undo/redo manager. </p></li></ul><div style='display: inline-block; width: 60%; vertical-align: top; cursor: auto;'><img alt='Sky with sun' src='https://cdn.syncfusion.com/ej2/richtexteditor-resources/RTE-Overview.png' width='309' style='min-width: 10px; min-height: 10px; width: 309px; height: 174px;' class='e-rte-image e-imginline e-rte-drag-image' height='174' /></div>`,
provide('richtexteditor', [Toolbar, Link, Image, HtmlEditor, QuickToolbar]);
</script>
<style>
@import "https://ej2.syncfusion.com/vue/documentation/../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-vue-richtexteditor/styles/material.css";
</style>
<template>
<ejs-richtexteditor ref="defaultRTE" :height="340" :value="rteValue">
</ejs-richtexteditor>
</template>
<script>
import { RichTextEditorComponent, Toolbar, Link, Image, HtmlEditor, QuickToolbar } from '@syncfusion/ej2-vue-richtexteditor';
export default {
name: "App",
components: {
"ejs-richtexteditor":RichTextEditorComponent
},
data() {
return {
rteValue: `<p>The Syncfudion Rich Text Editor, a WYSIWYG (what you see is what you get) editor, is a user interface that allows you to create, edit, and format rich text content. You can try out a demo of this editor here.</p><p><b>Key features:</b></p><ul><li><p>Provides <IFRAME> and <DIV> modes.</p></li><li><p>Bulleted and numbered lists.</p></li><li><p>Handles images, hyperlinks, videos, hyperlinks, uploads, etc.</p></li><li><p>Contains undo/redo manager. </p></li></ul><div style='display: inline-block; width: 60%; vertical-align: top; cursor: auto;'><img alt='Sky with sun' src='https://cdn.syncfusion.com/ej2/richtexteditor-resources/RTE-Overview.png' width='309' style='min-width: 10px; min-height: 10px; width: 309px; height: 174px;' class='e-rte-image e-imginline e-rte-drag-image' height='174' /></div>`,
}
},
provide: {
richtexteditor: [Toolbar, Link, Image, HtmlEditor, QuickToolbar]
}
}
</script>
<style>
@import "https://ej2.syncfusion.com/vue/documentation/../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-vue-richtexteditor/styles/material.css";
</style>
Markdown Editor
Set the editorMode property value as Markdown
to create or edit the content and apply formatting to view markdown formatted content.
The third-party library such as Marked
or any other library is used to convert markdown into HTML content.
- The Supported Tags are
h6
,h5
,h4
,h3
,h2
,h1
,blockquote
,pre
,p
,ol
,ul
. - The Supported Selection Tags are
Bold
,Italic
,StrikeThrough
,InlineCode
,SubScript
,SuperScript
,UpperCase
,LowerCase
. - The supported insert commands are
Image
,Link
andTable
.
To use Markdown editing feature, inject
MarkdownEditor
in the provider section.
<template>
<ejs-richtexteditor ref="rteInstance" :height="350" editorMode="Markdown" :value="value"
:toolbarSettings="toolbarConfig" :created="created">
</ejs-richtexteditor>
</template>
<style>
.e-richtexteditor .e-rte-content .e-content {
min-height: 150px;
}
.e-richtexteditor .e-rte-content textarea.e-content {
float: left;
border-right: 1px solid rgba(0, 0, 0, 0.12);
}
.e-richtexteditor .e-rte-content {
overflow: hidden;
}
.e-md-preview::before {
content: '\e345';
}
.e-rte-content .e-content.e-pre-source {
width: 100%;
}
.e-icon-btn.e-active .e-md-preview.e-icons::before {
content: '\e350';
}
</style>
<script setup>
import { provide, ref } from "vue";
import { createElement, KeyboardEventArgs } from "@syncfusion/ej2-base";
import { marked } from 'marked';
import { RichTextEditorComponent as EjsRichtexteditor, Toolbar, Link, Image, MarkdownEditor } from '@syncfusion/ej2-vue-richtexteditor';
const rteInstance = ref(null);
const value = `***Overview***
The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor used to create and edit the content and return valid HTML markup or markdown (MD) of the content. The editor provides a standard toolbar to format content using its commands. Modular library features to load the necessary functionality on demand. The toolbar contains commands to align the text, insert link, insert image, insert list, undo/redo operation, HTML view, and more.
***Key features***
- *Mode*: Provides IFRAME and DIV mode.
- *Module*: Modular library to load the necessary functionality on demand.
- *Toolbar*: Provide a fully customizable toolbar.
- *Editing*: HTML view to edit the source directly for developers.
- *Third-party Integration*: Supports to integrate third-party library.
- *Preview*: Preview the modified content before saving it.
- *Tools*: Handling images, hyperlinks, video, uploads and more.
- *Undo and Redo*: Undo/redo manager.
- *Lists*:Creates bulleted and numbered list.`;
const toolbarConfig = {
items: [
'Bold', 'Italic', 'StrikeThrough', '|',
'Formats', 'OrderedList', 'UnorderedList', '|',
'CreateLink', 'Image', '|',
{
tooltipText: 'Preview',
template: '<button id="preview-code" class="e-tbar-btn e-control e-btn e-icon-btn">' +
'<span class="e-btn-icon e-md-preview e-icons"></span></button>'
},
'|', 'Undo', 'Redo'
]
};
const created = function () {
const textArea = rteInstance.value.ej2Instances.element.querySelector('.e-content');
textArea.onkeyup = (Event) => {
markDownConversion();
};
document.getElementById('preview-code').onclick = () => {
fullPreview({ mode: true, type: 'preview' });
if (event.target.parentElement.classList.contains('e-active')) {
rteInstance.value.ej2Instances.disableToolbarItem([
'Bold', 'Italic', 'StrikeThrough', 'Formats', 'OrderedList',
'UnorderedList', 'CreateLink', 'Image'
]);
event.target.parentElement.parentElement.nextElementSibling.classList.add('e-overlay');
} else {
rteInstance.value.ej2Instances.enableToolbarItem([
'Bold', 'Italic', 'StrikeThrough', 'Formats', 'OrderedList',
'UnorderedList', 'CreateLink', 'Image'
]);
event.target.parentElement.parentElement.nextElementSibling.classList.remove('e-overlay');
}
};
};
const markDownConversion = function () {
if (document.getElementById('preview-code').classList.contains('e-active')) {
const id = rteInstance.value.ej2Instance.getID() + 'html-view';
const htmlPreview = rteInstance.value.ej2Instances.element.querySelector('#' + id);
htmlPreview.innerHTML = marked.parse(textArea.value);
}
};
const fullPreview = function (event) {
const mdSource = document.getElementById('preview-code');
const id = rteInstance.value.ej2Instance.getID() + 'html-view';
const htmlPreview = rteInstance.value.ej2Instances.element.querySelector('#' + id);
if ((mdSource.classList.contains('e-active')) && event.mode) {
mdSource.classList.remove('e-active');
textArea.style.display = 'block';
textArea.style.width = '100%';
htmlPreview.style.display = 'none';
} else {
mdSource.classList.add('e-active');
if (!htmlPreview) {
htmlPreview = document.createElement('div');
htmlPreview.id = id;
htmlPreview.setAttribute('class', 'e-content');
textArea.parentNode.appendChild(htmlPreview);
}
if (event.type === 'preview') {
textArea.style.display = 'none';
htmlPreview.classList.add('e-pre-source');
} else {
htmlPreview.classList.remove('e-pre-source');
textArea.style.width = '50%';
}
htmlPreview.style.display = 'block';
htmlPreview.innerHTML = marked.parse(rteInstance.value.ej2Instances.contentModule.getEditPanel().value);
mdSource.parentElement.title = 'Code View';
}
};
provide('richtexteditor', [Toolbar, Link, Image, MarkdownEditor]);
</script>
<style>
@import "../../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-vue-richtexteditor/styles/material.css";
</style>
<template>
<ejs-richtexteditor ref="rteInstance" :height="350" editorMode="Markdown" :value="value"
:toolbarSettings="toolbarConfig" :created="created">
</ejs-richtexteditor>
</template>
<style>
.e-richtexteditor .e-rte-content .e-content {
min-height: 150px;
}
.e-richtexteditor .e-rte-content textarea.e-content {
float: left;
border-right: 1px solid rgba(0, 0, 0, 0.12);
}
.e-richtexteditor .e-rte-content {
overflow: hidden;
}
.e-md-preview::before {
content: '\\e345';
}
.e-rte-content .e-content.e-pre-source {
width: 100%;
}
.e-icon-btn.e-active .e-md-preview.e-icons::before {
content: '\\e350';
}
</style>
<script>
import { createElement, KeyboardEventArgs } from "@syncfusion/ej2-base";
import { RichTextEditorComponent, Toolbar, Link, Image, MarkdownEditor } from '@syncfusion/ej2-vue-richtexteditor';
import { marked } from 'marked';
export default {
name: "App",
components: {
"ejs-richtexteditor": RichTextEditorComponent
},
data() {
return {
value: `***Overview***
The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor used to create and edit the content and return valid HTML markup or markdown (MD) of the content. The editor provides a standard toolbar to format content using its commands. Modular library features to load the necessary functionality on demand. The toolbar contains commands to align the text, insert link, insert image, insert list, undo/redo operation, HTML view, and more.
***Key features***
- *Mode*: Provides IFRAME and DIV mode.
- *Module*: Modular library to load the necessary functionality on demand.
- *Toolbar*: Provide a fully customizable toolbar.
- *Editing*: HTML view to edit the source directly for developers.
- *Third-party Integration*: Supports to integrate third-party library.
- *Preview*: Preview the modified content before saving it.
- *Tools*: Handling images, hyperlinks, video, uploads and more.
- *Undo and Redo*: Undo/redo manager.
- *Lists*:Creates bulleted and numbered list.`,
toolbarConfig: {
items: [
'Bold', 'Italic', 'StrikeThrough', '|',
'Formats', 'OrderedList', 'UnorderedList', '|',
'CreateLink', 'Image', '|',
{
tooltipText: 'Preview',
template: '<button id="preview-code" class="e-tbar-btn e-control e-btn e-icon-btn">' +
'<span class="e-btn-icon e-md-preview e-icons"></span></button>'
},
'|', 'Undo', 'Redo'
]
}
}
},
methods: {
created: function () {
this.textArea = this.$refs.rteInstance.$el.ej2_instances[0].element.querySelector('.e-content');
this.textArea.onkeyup = (Event) => {
this.markDownConversion();
};
document.getElementById('preview-code').onclick = () => {
this.fullPreview({ mode: true, type: 'preview' });
if (event.target.parentElement.classList.contains('e-active')) {
this.$refs.rteInstance.ej2Instances.disableToolbarItem([
'Bold', 'Italic', 'StrikeThrough', 'Formats', 'OrderedList',
'UnorderedList', 'CreateLink', 'Image'
]);
event.target.parentElement.parentElement.nextElementSibling.classList.add('e-overlay');
} else {
this.$refs.rteInstance.ej2Instances.enableToolbarItem([
'Bold', 'Italic', 'StrikeThrough', 'Formats', 'OrderedList',
'UnorderedList', 'CreateLink', 'Image'
]);
event.target.parentElement.parentElement.nextElementSibling.classList.remove('e-overlay');
}
};
},
markDownConversion: function () {
if (document.getElementById('preview-code').classList.contains('e-active')) {
var id = this.$refs.rteInstance.ej2Instances.getID() + 'html-view';
var htmlPreview = this.$refs.rteInstance.$el.ej2_instances[0].element.querySelector('#' + id);
htmlPreview.innerHTML = marked.parse(this.textArea.value);
}
},
fullPreview: function (event) {
var mdSource = document.getElementById('preview-code');
var id = this.$refs.rteInstance.ej2Instances.getID() + 'html-view';
var htmlPreview = this.$refs.rteInstance.$el.ej2_instances[0].element.querySelector('#' + id);
if ((mdSource.classList.contains('e-active')) && event.mode) {
mdSource.classList.remove('e-active');
this.textArea.style.display = 'block';
this.textArea.style.width = '100%';
htmlPreview.style.display = 'none';
} else {
mdSource.classList.add('e-active');
if (!htmlPreview) {
htmlPreview = document.createElement('div');
htmlPreview.id = id;
htmlPreview.setAttribute('class', 'e-content');
this.textArea.parentNode.appendChild(htmlPreview);
}
if (event.type === 'preview') {
this.textArea.style.display = 'none';
htmlPreview.classList.add('e-pre-source');
} else {
htmlPreview.classList.remove('e-pre-source');
this.textArea.style.width = '50%';
}
htmlPreview.style.display = 'block';
htmlPreview.innerHTML = marked.parse(this.$refs.rteInstance.ej2Instances.contentModule.getEditPanel().value);
mdSource.parentElement.title = 'Code View';
}
}
},
provide: {
richtexteditor: [Toolbar, Link, Image, MarkdownEditor]
}
}
</script>
<style>
@import "../../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../../node_modules/@syncfusion/ej2-vue-richtexteditor/styles/material.css";
</style>
For further details on Markdown editing, refer to the Markdown