We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

Is RTE have syntax highlighter?

Platform: jQuery |
Control: ejRTE


Currently we haven’t provided with in-built support for syntax highlighter in RTE.  However, this can be achieved using some third party tools/plugins that will allow you to highlight the code blocks.


In below sample, we have used CodeMirror plugins to highlight HTML, Javascript and CSS using custom tool. Add the CodeMirror references to the script section as follows.



<script src="" type="text/javascript"></script>

    <script src="" type="text/javascript"></script>

    <script src="" type="text/javascript"></script>

    <script src="" type="text/javascript"></script>

    <script src="" type="text/javascript"></script>

    <link href="" rel="stylesheet" />


Render the RTE control, use “customTool” options to add the “div” in the Toolbar.



<textarea id="rteSample" rows="10" cols="30" style="width: 740px; height: 440px">


    The Rich Text Editor (RTE) control is an easy to render in

    client side. Customer easy to edit the contents and get the HTML content for

    the displayed content. A rich text editor control provides users with a toolbar

    that helps them to apply rich text formats to the text entered in the text



<div id="cutomSourceCode" title="Paste you code and inset to RTE">



            <td style="width: 100px">

                Select type :




                    <select id="languageList">

                        <option value="javascript">Java Script</option>

                        <option value="text/html">HTML</option>

                        <option value="css">CSS</option>






            <td colspan="2">

                <textarea id="srcCode" style="width: 550px; height: 250px">

                    <div id="srcArea"></div>





            <td colspan="2">

                <div class="e-rte-button e-fieldseparate">

             <button id="src_insert" class="e-rte-btn" tabindex="">Insert</button>

             <button id="src_cancel" class="e-rte-btn" tabindex="">Cancel</button>







<script type="text/javascript" class="jsScript">

    var rteObj;

$(function () {

    //Render the RTE control


        toolsList: ["customTools"],



        tools: {

            customTools: [{

                name: "codeInsert",

                tooltip: "Insert code snippets ",

                css: "codeInsert",

    text: "codeInsert",

                action: function () {








    //Add text for custom tool bar element.

    $("div.codeInsert").html("Insert code");

    //load the CodeMirror css in the iframe

    $("#rteSample_Iframe").contents().find("head").append($("<link href='../scripts/CodeMirror/codemirror.min.css' rel='stylesheet'></link>"));


    rteObj = $("#rteSample").data("ejRTE");



            enableResize: false,

            enableModal: true,

            showOnInit: false,

            width: "auto",

            position: { X: 218, Y: 38 }


  $("#languageList").ejDropDownList().ejDropDownList("option", "selectedItemIndex", 0);

  $("#cutomSourceCode").find(".e-rte-btn").ejButton({ click: "customBtnClick" });




Upon click to the “div” element, the “Dialog” control will be open. From that insert any HTML, CSS or JavaScript syntax to the RTE.


The syntax has been inserted to the RTE using “executeCommand” method.



function customBtnClick(args) {

    if (this._id == "src_insert") {

        var htmlEditor = CodeMirror.fromTextArea($("#srcCode")[0], {

            lineNumbers: false,

            mode: $("#languageList").val()


        var codeTags = $("#cutomSourceCode").find(".CodeMirror");


        rteObj.executeCommand("inserthtml", codeTags[0].outerHTML);






You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile