16 May 202516 minutes to read
This section explains the steps to create a simple Rich Text Editor and demonstrates the basic usage of the Rich Text Editor control using the Essential JS 2quickstart seed repository. This seed repository is pre-configured with the Essential JS 2 package.
This application is integrated with the
webpack.config.jsconfiguration and uses the latest version of thewebpack-cli. It requires nodev14.15.0or higher. For more information about webpack and its features, refer to thewebpack documentation.
The following minimum dependencies are required to use the Rich Text Editor.
|--@syncfusion/ej2-richtexteditor|--@syncfusion/ej2-base|--@syncfusion/ej2-buttons|--@syncfusion/ej2-data|--@syncfusion/ej2-inputs|--@syncfusion/ej2-lists|--@syncfusion/ej2-navigations|--@syncfusion/ej2-popups|--@syncfusion/ej2-splitbuttons|--@syncfusion/ej2-filemanagerOpen the command prompt from the required directory, and run the following command to clone the Syncfusion JavaScript (Essential JS 2) quickstart project fromGitHub.
git clone https://github.com/SyncfusionExamples/ej2-quickstart-webpack- ej2-quickstartAfter cloning the application in theej2-quickstart folder, run the following command line to navigate to theej2-quickstart folder.
cd ej2-quickstartSyncfusion JavaScript (Essential JS 2) packages are available on thenpmjs.com public registry. You can install all Syncfusion JavaScript (Essential JS 2) controls in a single@syncfusion/ej2 package or individual packages for each control.
The quickstart application is preconfigured with the dependent@syncfusion/ej2 package in the~/package.json file. Use the following command to install the dependent npm packages from the command prompt.
npm installSyncfusion JavaScript controls come withbuilt-in themes, which are available in the installed packages. It’s easy to adapt the Syncfusion JavaScript controls to match the style of your application by referring to one of the built-in themes.
The quickstart application is preconfigured to use theMaterial theme in the~/src/styles/styles.css file, as shown below:
@import'../../node_modules/@syncfusion/ej2-base/styles/material.css';@import'../../node_modules/@syncfusion/ej2-buttons/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-navigations/styles/material.css';@import'../../node_modules/@syncfusion/ej2-popups/styles/material.css';@import'../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';@import'../../node_modules/@syncfusion/ej2-richtexteditor/styles/material.css';;You can check out thethemes section to know more about built-in themes and CSS reference for individual controls.
To create Rich Text Editor with additional features, inject the required modules. The following modules are used to extend Rich Text Editor’s basic functionality.
Toolbar - Inject this module to use Toolbar feature.Link - Inject this module to use link feature in Rich Text Editor.Image- Inject this module to use image feature in Rich Text Editor.HtmlEditor - Inject this module to use Rich Text Editor as html editor.QuickToolbar - Inject this module to use quick toolbar feature for the target element.These modules should be injected into the Rich Text Editor using theRichTextEditor.Inject method.
Additional feature modules are availablehere
To get started, add the Rich Text Editor control in app.ts and index.html files. Rich Text Editor can be initialized through div element or textarea element.
Place the following Rich Text Editor code in theapp.ts file.
import{RichTextEditor,Toolbar,Link,Image,HtmlEditor,QuickToolbar}from'@syncfusion/ej2-richtexteditor';RichTextEditor.Inject(Toolbar,Link,Image,HtmlEditor,QuickToolbar);leteditor:RichTextEditor=newRichTextEditor({});editor.appendTo('#editor');Rich Text Editor can be initialized on div element as shown below
[src/index.html]
<!DOCTYPE html><htmllang="en"><head><title>Essential JS 2 Rich Text Editor</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0, user-scalable=no"/><metaname="description"content="Essential JS 2"/><metaname="author"content="Syncfusion"/><linkrel="shortcut icon"href="resources/favicon.ico"/><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"rel="stylesheet"/></head><body><!--Element which will render as RTE--><divid="editor"></div></body></html>Now import the Rich Text Editor control to your app.ts and initialize it to the element #editor as shown below.
[src/app/app.ts]
import{RichTextEditor,Toolbar,Link,Image,HtmlEditor,QuickToolbar}from'@syncfusion/ej2-richtexteditor';RichTextEditor.Inject(Toolbar,Link,Image,HtmlEditor,QuickToolbar);// initialize Rich Text Editor controlleteditor:RichTextEditor=newRichTextEditor({value:'<p>The Rich Text Editor control is WYSIWYG ("what you see is what you get" ) editor that provides the best user experience to create and update the content.Users can format their content using standard toolbar commands.</p><p><b> Key features: </b></p ><ul><li><p>Provides IFRAME and DIV modes < /p></li ><li><p>Capable of handling markdown editing.< /p></li ><li><p>Contains a modular library to load the necessary functionality on demand.< /p></li ><li><p>Provides a fully customizable toolbar.< /p></li ><li><p>Provides HTML view to edit the source directly for developers.< /p></li ><li><p>Supports third - party library integration.< /p></li ><li><p>Allows preview of modified content before saving it.< /p></li ><li><p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.< /p></li ></ul>'});// render initialized Rich Text Editoreditor.appendTo('#editor');Output will be displayed as follows
import{RichTextEditor,Toolbar,Link,Image,HtmlEditor,QuickToolbar}from'@syncfusion/ej2-richtexteditor';RichTextEditor.Inject(Toolbar,Link,Image,HtmlEditor,QuickToolbar);// initialize Rich Text Editor componentleteditor:RichTextEditor=newRichTextEditor({value:'<p>The Rich Text Editor control is WYSIWYG ("what you see is what you get" ) editor that provides the best user experience to create and update the content.Users can format their content using standard toolbar commands.</p><p>< b > Key features: </b></p ><ul><li><p>Provides IFRAME and DIV modes < /p></li ><li><p>Capable of handling markdown editing.< /p></li ><li><p>Contains a modular library to load the necessary functionality on demand.< /p></li ><li><p>Provides a fully customizable toolbar.< /p></li ><li><p>Provides HTML view to edit the source directly for developers.< /p></li ><li><p>Supports third - party library integration.< /p></li ><li><p>Allows preview of modified content before saving it.< /p></li ><li><p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.< /p></li ></ul>'});// render initialized Rich Text Editoreditor.appendTo('#editor');<!DOCTYPE html><htmllang="en"><head><title>Essential JS 2 Rich Text Editor</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-richtexteditor/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='editor'></div></div></body></html>Configure the toolbar with the tools using items field of thetoolbarSettings property as your application requires.
import{RichTextEditor,Toolbar,Link,Image,HtmlEditor,QuickToolbar}from'@syncfusion/ej2-richtexteditor';RichTextEditor.Inject(Toolbar,Link,Image,HtmlEditor,QuickToolbar);leteditor:RichTextEditor=newRichTextEditor({toolbarSettings:{items:['Bold','Italic','Underline','StrikeThrough','FontName','FontSize','FontColor','BackgroundColor','LowerCase','UpperCase','|','Formats','Alignments','OrderedList','UnorderedList','Outdent','Indent','|','CreateLink','Image','|','ClearFormat','Print','SourceCode','FullScreen','|','Undo','Redo']},value:`<p>The Syncfusion 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>`,});editor.appendTo('#editor');<!DOCTYPE html><htmllang="en"><head><title>Essential JS 2 Rich Text Editor</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-richtexteditor/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='editor'></div></div></body></html>
|and-can insert a vertical and horizontal separator lines in the toolbar.
The quickstart project is configured to compile and run the application in the browser. Use the following command to run the application.
npm startOutput will be displayed as follows
import{RichTextEditor,Toolbar,Link,Image,HtmlEditor,QuickToolbar}from'@syncfusion/ej2-richtexteditor';RichTextEditor.Inject(Toolbar,Link,Image,HtmlEditor,QuickToolbar);leteditor:RichTextEditor=newRichTextEditor({toolbarSettings:{items:['Bold','Italic','Underline','StrikeThrough','FontName','FontSize','FontColor','BackgroundColor','LowerCase','UpperCase','|','Formats','Alignments','OrderedList','UnorderedList','Outdent','Indent','|','CreateLink','Image','|','ClearFormat','Print','SourceCode','FullScreen','|','Undo','Redo']},value:`<p>The Syncfusion 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>`,});editor.appendTo('#editor');<!DOCTYPE html><htmllang="en"><head><title>Essential JS 2 Rich Text Editor</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-richtexteditor/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='editor'></div></div></body></html>You can refer to ourTypeScript Rich Text Editor feature tour page for its groundbreaking feature representations. You can also explore ourTypeScript Rich Text Editor example that shows how to render the Rich Text Editor tools.