Third party Integration

21 Dec 202219 minutes to read

The Rich Text Editor can be integrated with third-party to suite the application scenario.

Code-Mirror Integration

Rich Text Editor comes with a basic HTML source editor through view-source property. Code mirror plugin can be used to highlight the syntax of HTML. CodeMirror plugin for Rich Text Editor makes editing of HTML source code with a pleasant experience.

Import necessary CSS and JS files of CodeMirror to the HTML page.

Required JS files of code mirror.

 <script src="scripts/CodeMirror/codemirror.js" type="text/javascript"></script>
 <script src="scripts/CodeMirror/javascript.js" type="text/javascript"></script>
 <script src="scripts/CodeMirror/css.js" type="text/javascript"></script>
 <script src="scripts/CodeMirror/htmlmixed.js" type="text/javascript"></script>

Required CSS file of code mirror.

 <link href="scripts/CodeMirror/codemirror.min.css" rel="stylesheet" />

Add a custom icon for HTML source editor in the toolbar of Rich Text Editor using template option of toolbarSettings and define the code mirror plugins, and then pass the Rich Text Editor content as argument in actionComplete event.

<div class="control-section">
    <ejs-richtexteditor id="defaultRTE" showCharCount="true" actionComplete="actionCompleteHandler" maxLength="2000" created="created">
        <e-content-template>
            <div> <p>The Rich Text Editor is WYSIWYG ('what you see is what you get') editor useful to create and edit content, and return the valid <a href='https://ej2.syncfusion.com/aspnetcore/RichTextEditor/Overview'>HTML markup</a> or <a href='https://ej2.syncfusion.com/aspnetcore/RichTextEditor/DefaultMode'>markdown</a> of the content</p>
            <p><b> Toolbar </b></p>
            <ol>
                <li>
                    <p> Toolbar contains commands to align the text, insert link, insert image, insert list, undo / redo operations, HTML view, etc </p>
                </li>
                <li>
                    <p> Toolbar is fully customizable </p>
                </li>
            </ol>
            <p><b> Links </b></p>
            <ol>
                <li>
                    <p> You can insert a hyperlink with its corresponding dialog</p>
                </li>
                <li>
                    <p> Attach a hyperlink to the displayed text. </p>
                </li>
                <li>
                    <p> Customize the quick toolbar based on the hyperlink </p>
                </li>
            </ol>
            <p><b> Image.</b></p>
            <ol>
                <li>
                    <p> Allows you to insert images from an online source as well as the local computer</p>
                </li>
                <li>
                    <p> You can upload an image</p>
                </li>
                <li>
                    <p> Provides an option to customize quick toolbar for an image </p>
                </li>
            </ol>
            <img alt='Logo' src='images/RichTextEditor/RTEImage-Feather.png' style='width: 300px' />
</div>
</e-content-template>
<e-richtexteditor-toolbarsettings items="@ViewBag.tools">
</e-richtexteditor-toolbarsettings>
</ejs-richtexteditor>
</div>
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0/codemirror.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/mode/css/css.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/mode/xml/xml.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/mode/htmlmixed/htmlmixed.js" type="text/javascript"></script>
<style>
.e-code-mirror::before {
    content: '\e345';
}

.e-html-preview::before {
    content: '\e350';
}

.CodeMirror-linenumber,
.CodeMirror-gutters {
    display: none;
}

.sb-header {
    z-index: 100;
}
</style>
<script type="text/javascript">
var defaultRTE;
var divPreview;
var myCodeMirror;
var textArea
divPreview = document.getElementById('DIV_Preview');
function created() {
    defaultRTE = this;
    textArea = defaultRTE.contentModule.getEditPanel();

}
function mirrorConversion(e) {
    var id = defaultRTE.getID() + 'mirror-view';
    var mirrorView = defaultRTE.element.querySelector('#' + id);
    var charCount = defaultRTE.element.querySelector('.e-rte-character-count');
    if (e.targetItem === 'Preview') {
        textArea.style.display = 'block';
        mirrorView.style.display = 'none';
        textArea.innerHTML = myCodeMirror.getValue();
        charCount.style.display = 'block';
    }
    else {
        if (!mirrorView) {
            mirrorView = ej.base.createElement('div', { className: 'e-content' });
            mirrorView.id = id;
            textArea.parentNode.appendChild(mirrorView);
        }
        else {
            mirrorView.innerHTML = '';
        }
        textArea.style.display = 'none';
        mirrorView.style.display = 'block';
        renderCodeMirror(mirrorView, defaultRTE.value);
        charCount.style.display = 'none';
    }
}
function renderCodeMirror(mirrorView, content) {
    myCodeMirror = CodeMirror(mirrorView, {
        value: content,
        lineNumbers: true,
        mode: 'text/html',
        lineWrapping: true,
    });
}
function actionCompleteHandler(e) {
    if (e.targetItem && (e.targetItem === 'SourceCode' || e.targetItem === 'Preview')) {
        this.sourceCodeModule.getPanel().style.display = 'none';
        mirrorConversion(e);
    }
    else {
        setTimeout(function () { defaultRTE.toolbarModule.refreshToolbarOverflow(); }, 400);
    }
}
</script>
public class HomeController : Controller
{
    public ActionResult Index()
    {

        ViewBag.items = new[] { "SourceCode" };
        return View();
    }
}

At.js Integration

Rich Text Editor can easily be integrated with At.js library. To display the autocomplete list, type ‘@’.

Include At.JS style.

 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/at.js/1.4.0/css/jquery.atwho.min.css">

Include At.JS javascript.

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/at.js/1.4.0/js/jquery.atwho.min.js"></script>

Define the At.js configuration

NOTE

In below configuration, email id of employees list - email id of employees from the data source.

var config = {
    at: "@",
    data: [email id of employees list],
    displayTpl: '<li>${name} <small>${email}</small></li>',
    limit: 200
  }

Populate the employee’s email id from local or remote data and set the result to the data of At.js configuration.

<ejs-richtexteditor id="at-integration" created="created" >
    <e-richtexteditor-toolbarsettings items="@ViewBag.items"></e-richtexteditor-toolbarsettings>
    <e-content-template>
        <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 & lt; IFRAME & gt; and & lt; DIV & gt; 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>

            <li><p> Contains undo / redo manager.</p></li>

            <li><p> Creates bulleted and numbered lists.</p></li>

        </ul>
    </e-content-template>
</ejs-richtexteditor>
<script src="//cdn.syncfusion.com/js/assets/external/jquery-1.11.3.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/at.js/1.4.0/css/jquery.atwho.min.css">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/at.js/1.4.0/js/jquery.atwho.min.js"></script>
<script>
    // Build data to be used in At.JS config.
    var employeeList = [
        { id: 'emp01', name: 'Jacob', email: 'jacob@mail.com' },
        { id: 'emp02', name: 'Isabella', email: 'isabella@mail.com' },
        { id: 'emp03', name: 'Ethan', email: 'ethan@mail.com' },
        { id: 'emp04', name: 'Emma', email: 'emma@mail.com' },
        { id: 'emp05', name: 'Michael', email: 'michael@mail.com' },
        { id: 'emp06', name: 'Olivia', email: 'olivia@mail.com' },
        { id: 'emp07', name: 'Jeniffer', email: 'jeniffer@mail.com' }
    ];
    var config = {
        at: "@@",
        data: employeeList,
        displayTpl: '<li>${name} <small>${email}</small></li>',
        limit: 200
    };
    function created(args) {
        var textArea = this.contentModule.getEditPanel();
        $(textArea).atwho(config);
        $(textArea).on('keydown', function (e) {
            if (e.keyCode == 13 && $(textArea).atwho('isSelecting'))
                return false;
        });
    }
</script>
public class HomeController : Controller
{

    public ActionResult Index()
    {
        ViewBag.items = new object[] {"|", "Undo", "Redo", "|",
        "Bold", "Italic", "Underline", "StrikeThrough", "|",
        "FontName", "FontSize", "FontColor", "BackgroundColor", "|",
        "SubScript", "SuperScript", "|",
        "LowerCase", "UpperCase", "|",
        "Formats", "Alignments", "|", "OrderedList", "UnorderedList", "|",
        "Outdent", "Indent", "|", "CreateLink", "CreateTable", "Image", "|", "SourceCode"};
        return View();
    }
}

Embed.ly Integration

Rich Text Editor easily integrate with Embed.ly which is probably the best service when it comes to embed the rich content such as Twitter, Facebook, Instagram and lots of other publishing platform embeds.

<script src="https://cdn.embedly.com/widgets/platform.js" charset="UTF-8"></script>

In the following sample, the Embed.ly class embedly-card has been added to <a> tag in actionComplete event.

<ejs-richtexteditor id="embedly" actionComplete="actionComplete" >
    <e-richtexteditor-toolbarsettings items="@ViewBag.items"></e-richtexteditor-toolbarsettings>
    <e-content-template>
        <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 &lt; IFRAME &gt; and &lt; DIV &gt; 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>

            <li><p> Contains undo / redo manager.</p></li>

            <li><p> Creates bulleted and numbered lists.</p></li>

        </ul>
    </e-content-template>
</ejs-richtexteditor>
<script async src="https://cdn.embedly.com/widgets/platform.js" charset="UTF-8"></script>
<script>
    function actionComplete(args) {
        if (args.requestType === 'Links') {
            if (args.elements[0].parentNode && args.elements[0].parentNode.tagName === 'A') {
                var emberEle = document.createElement('blockquote');
                emberEle.setAttribute('class', 'embedly-card');
                emberEle.appendChild(args.elements[0].parentElement);
                emberEle.appendChild(document.createElement('p'));
                args.range.insertNode(emberEle);
            }
        }
    }
</script>
public class HomeController : Controller
{

    public ActionResult Index()
    {
        ViewBag.items = new object[] { "CreateLink" };
        return View();
    }
}