Toolbar configuration in Markdown Editor Control

16 May 202524 minutes to read

Default toolbar items

By default, the Markdown Editor displays the following toolbar items:

Bold , Italic , | , Formats , Blockquote, OrderedList , UnorderedList , | , CreateLink , Image , | , SourceCode , Undo , Redo

These default items cover Essential text editing features, such as text formatting, lists, and linking.

Type of toolbar

The Syncfusion Markdown Editor allows you to configure different type of toolbars using the type field in the toolbarSettings property.

The available toolbar types are:

  1. Expand
  2. MultiRow
  3. Scrollable

Expanding the Toolbar

The default toolbar mode is Expand, which is configured using toolbarSettings with type: Expand.

In this mode, any overflowing toolbar items are hidden in the next row. Users can reveal them by clicking the expand arrow.

var markdownRTE = new ej.richtexteditor.RichTextEditor({
    height: 340,
    width: 500,
    editorMode: 'Markdown',
    value: `In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.`,
    toolbarSettings: {
        type: 'Expand',
        items: ['Bold', 'Italic', 'StrikeThrough', 'InlineCode', 'SuperScript', 'SubScript', '|', 
            'Formats', 'Blockquote', '|', 'OrderedList', 'UnorderedList', 'CreateLink', 'Image', 'CreateTable', '|', 
            'Undo', 'Redo']
    }
});

markdownRTE.appendTo('#markdown-editor');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Rich Text Editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-richtexteditor/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-lists/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-navigations/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-popups/styles/material.css" rel="stylesheet">
     <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-splitbuttons/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="markdown-editor">
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Configuring a Multi-row Toolbar

By setting type: MultiRow in toolbarSettings, the toolbar items are arranged across multiple rows. This ensures that all configured toolbar items are always visible.

var markdownRTE = new ej.richtexteditor.RichTextEditor({
    height: 340,
    width: 500,
    editorMode: 'Markdown',
    value: `In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.`,
    toolbarSettings: {
        type: 'Multirow',
        items: ['Bold', 'Italic', 'StrikeThrough', 'InlineCode', 'SuperScript', 'SubScript', '|', 
            'Formats', 'Blockquote', '|', 'OrderedList', 'UnorderedList', 'CreateLink', 'Image', 'CreateTable', '|', 
            'Undo', 'Redo']
    }
});

markdownRTE.appendTo('#markdown-editor');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Rich Text Editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-richtexteditor/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-lists/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-navigations/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-popups/styles/material.css" rel="stylesheet">
     <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-splitbuttons/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="markdown-editor">
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Implementing a Scrollable Toolbar

Use type: 'Scrollable' in toolbarSettings to create a single-line toolbar with horizontal scrolling capability for overflow items.

var markdownRTE = new ej.richtexteditor.RichTextEditor({
    height: 340,
    width: 500,
    editorMode: 'Markdown',
    value: `In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.`,
    toolbarSettings: {
        type: 'Scrollable',
        items: ['Bold', 'Italic', 'StrikeThrough', 'InlineCode', 'SuperScript', 'SubScript', '|', 
            'Formats', 'Blockquote', '|', 'OrderedList', 'UnorderedList', 'CreateLink', 'Image', 'CreateTable', '|', 
            'Undo', 'Redo']
    }
});

markdownRTE.appendTo('#markdown-editor');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Rich Text Editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-richtexteditor/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-lists/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-navigations/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-popups/styles/material.css" rel="stylesheet">
     <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-splitbuttons/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="markdown-editor">
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Creating a Sticky Toolbar

By default, the toolbar remains fixed at the top of the Markdown editor when scrolling.

You can customize its position by setting floatingToolbarOffset to adjust the offset from the top of the document.

Additionally, you can enable or disable the floating toolbar using the enableFloating property.

var markdownRTE = new ej.richtexteditor.RichTextEditor({
    height: 340,
    editorMode: 'Markdown',
    toolbarSettings: {
        enableFloating: false,
        items: ['Bold', 'Italic', 'StrikeThrough', 'InlineCode', 'SuperScript', 'SubScript', '|', 
            'Formats', 'Blockquote', '|', 'OrderedList', 'UnorderedList', 'CreateLink', 'Image', 'CreateTable', '|', 
            'Undo', 'Redo']
    },
    value: "In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content."
});
markdownRTE.appendTo('#markdown-editor');

var float = new ej.buttons.CheckBox({
    // set false for enable the checked state at initial rendering
    checked: false,
    label: 'Enable Floating',
    // bind change event
    change: function (args) {
        markdownRTE.toolbarSettings.enableFloating = args.checked;
        markdownRTE.dataBind();
    }
});
float.appendTo('#float');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Rich Text Editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-richtexteditor/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-lists/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-navigations/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-popups/styles/material.css" rel="stylesheet">
     <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-splitbuttons/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="markdown-editor">
        </div>
        <input type="checkbox" id="float" checked="false">
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Custom Toolbar Items

The Markdown Editor allows you to add custom commands to the toolbar using the toolbarSettings property. These custom commands can be displayed as plain text, icons, or HTML templates. You can define their order and grouping, ensuring a structured and intuitive toolbar layout. Additionally, actions can be bound to these commands by retrieving their instances and handling events accordingly.

In this example, a custom toolbar item (Ω) is added to insert special characters into the editor. When users click the Ω button, a list of special characters appears, allowing them to select and insert a character into the content. This feature enhances the Markdown Editor by providing quick access to special symbols without manually entering character codes.

The following code snippet demonstrates how to configure a custom toolbar item with a tooltip. The item is added to the items field of the toolbarSettings property, ensuring seamless integration within the toolbar.

ej.base.enableRipple(true);
var dialog;

var selection = new ej.richtexteditor.NodeSelection();
var ranges;
// Initialization of Dialog
var dialog = new ej.popups.Dialog({
  header: 'Special Characters',
  content: document.getElementById('rteSpecial_char'),
  target: document.getElementById('container'),
  showCloseIcon: true,
  isModal: true,
  height: 'auto',
  visible: false,
  width: '500px',
  cssClass: 'e-rte-elements',
  overlayClick: dialogOverlay,
  created: onCreated,
  buttons: [
    { buttonModel: { content: 'Insert', isPrimary: true }, click: onInsert },
    { buttonModel: { content: 'Cancel' }, click: dialogOverlay },
  ],
});
// Render initialized Dialog
dialog.appendTo('#customTbarDialog');


var markdownRTE = new ej.richtexteditor.RichTextEditor({
  editorMode: 'Markdown',
  value: `The custom command \"insert special character\" is configured as the last item of the toolbar. Click on the command and choose the special character you want to include from the popup.`,
  toolbarSettings: {
    items: [
      'Bold',
      'Italic',
      '|',
      'Formats',
      'OrderedList',
      'UnorderedList',
      '|',
      'CreateLink',
      'Image',
      '|',
      'SourceCode',
      {
        tooltipText: 'Insert Symbol',
        undo: true,
        click: function () {
          dialog.element.style.display = '';

          // Get the textarea (Markdown editor)
          var markdownEditor = markdownRTE.contentModule.getEditPanel();

          // Save cursor position for later insertion
          selection = {
            start: markdownEditor.selectionStart,
            end: markdownEditor.selectionEnd,
          };

          dialog.show();
        },
        template:
          '<button class="e-tbar-btn e-btn" tabindex="-1" id="custom_tbar"  style="width:100%"><div class="e-tbar-btn-text" style="font-weight: 500;"> &#937;</div></button>',
      },
    ],
  },
});
markdownRTE.appendTo('#markdown-editor');

function dialogOverlay() {
  var activeEle = dialog.element.querySelector('.char_block.e-active');
  if (activeEle) {
    activeEle.classList.remove('e-active');
  }
  dialog.hide();
}

function onInsert() {
  var activeEle = dialog.element.querySelector('.char_block.e-active');
  if (activeEle) {
    var markdownEditor = markdownRTE.contentModule.getEditPanel();

    // Ensure selection data exists
    if (!selection || selection.start === undefined) {
      selection = {
        start: markdownEditor.selectionStart,
        end: markdownEditor.selectionEnd,
      };
    }

    var text = markdownEditor.value;
    var insertText = activeEle.textContent;

    // Insert the special character at the saved cursor position
    var newText =
      text.slice(0, selection.start) + insertText + text.slice(selection.end);
    markdownEditor.value = newText;

    // Set the cursor position after the inserted character
    var newCursorPosition = selection.start + insertText.length;
    markdownEditor.selectionStart = markdownEditor.selectionEnd =
      newCursorPosition;

    // Refocus the editor
    markdownEditor.focus();
  }
  dialogOverlay();
}

function onCreated() {
  var dialogCtn = document.getElementById('rteSpecial_char');
  dialogCtn.onclick = function (e) {
    var target = e.target;
    var activeEle = dialog.element.querySelector('.char_block.e-active');
    if (target.classList.contains('char_block')) {
      target.classList.add('e-active');
      if (activeEle) {
        activeEle.classList.remove('e-active');
      }
    }
  };
}
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Rich Text Editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-richtexteditor/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-lists/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-navigations/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-popups/styles/material.css" rel="stylesheet">
     <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-splitbuttons/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container" class="e-rte-custom-tbar-section">
        <div id="markdown-editor">
        </div>
        <div id="customTbarDialog" style="display: none">
            <div id="rteSpecial_char">
                <div class="char_block" title="^">^</div>
                <div class="char_block" title="_">_</div>
                <div class="char_block" title="`">`</div>
                <div class="char_block" title="{">{</div>
                <div class="char_block" title="|">|</div>
                <div class="char_block" title="}">}</div>
                <div class="char_block" title="~">~</div>
                <div class="char_block" title="&nbsp;">&nbsp;</div>
                <div class="char_block" title="¡">¡</div>
                <div class="char_block" title="¢">¢</div>
                <div class="char_block" title="£">£</div>
                <div class="char_block" title="¤">¤</div>
                <div class="char_block" title="¥">¥</div>
                <div class="char_block" title="₹"></div>
                <div class="char_block" title="¦">¦</div>
                <div class="char_block" title="§">§</div>
                <div class="char_block" title="¨">¨</div>
                <div class="char_block" title="©">©</div>
                <div class="char_block" title="ª">ª</div>
                <div class="char_block" title="«">«</div>
                <div class="char_block" title="¬">¬</div>
                <div class="char_block" title="­">­</div>
                <div class="char_block" title="®">®</div>
                <div class="char_block" title="¯">¯</div>
                <div class="char_block" title="°">°</div>
                <div class="char_block" title="±">±</div>
                <div class="char_block" title="²">²</div>
                <div class="char_block" title="³">³</div>
                <div class="char_block" title="´">´</div>
                <div class="char_block" title="µ">µ</div>
                <div class="char_block" title="¶"></div>
                <div class="char_block" title="·">·</div>
                <div class="char_block" title="¸">¸</div>
                <div class="char_block" title="¹">¹</div>
                <div class="char_block" title="º">º</div>
                <div class="char_block" title="»">»</div>
                <div class="char_block" title="¼">¼</div>
                <div class="char_block" title="½">½</div>
                <div class="char_block" title="¾">¾</div>
                <div class="char_block" title="¿">¿</div>
                <div class="char_block" title="À">À</div>
                <div class="char_block" title="Á">Á</div>
                <div class="char_block" title="Â">Â</div>
                <div class="char_block" title="Ã">Ã</div>
            </div>
        </div>
    </div>
<style>
    #special_char,
      .char_block {
        display: inline-block;
      }
      .char_block.e-active {
        /* box-shadow: inset 3px 3px 7px 0px; */
        outline: 1.5px solid;
      }
      .char_block {
        width: 30px;
        height: 30px;
        line-height: 30px;
        margin: 0 5px 5px 0;
        text-align: center;
        vertical-align: middle;
        border: 1px solid #dddddd;
        font-size: 20px;
        cursor: pointer;
        user-select: none;
      }
      #custom_tbar,
      #custom_tbar div {
        cursor: pointer;
      }
      #rteSection {
        height: 500px;
      }
      .e-rte-quick-popup .e-rte-quick-toolbar .e-roatate-left::before {
        content: '\e76e';
      }
      .e-rte-quick-popup .e-rte-quick-toolbar .e-roatate-right::before {
        content: '\e726';
      }
      .e-richtexteditor textarea.e-content {
        float: left;
      }
      .e-richtexteditor .e-rte-content {
        overflow: hidden;
      }
      .e-rte-content .e-content.e-pre-source {
        width: 100%;
      }
      .property-panel-content td {
        width: 50%;
      }
      .property-panel-content td div {
        padding-left: 10px;
        padding-top: 10px;
      }
      .e-icon-btn.e-active .e-md-preview::before {
        content: '\e350';
      }
      .e-icon-btn .e-md-preview.e-icons::before {
        content: '\e345';
      }
      .e-icon-btn.e-active .e-md-preview::before,
      #mdCustom .e-icon-btn.e-active .e-md-preview.e-icons::before {
        content: '\e350';
      }
      #mdCustom .e-icon-btn .e-md-preview.e-icons::before {
        content: '\e345';
      }
      #rteDialog.e-dialog .e-dlg-content {
        padding: 0px 0px 5px 16px;
      }
      #custom_tbar .e-tbar-btn-text {
        font-size: 16px;
      }
      .e-bigger #custom_tbar .e-tbar-btn-text {
        font-size: 18px;
      }
      @media (min-width: 320px) and (max-width: 480px) {
        .fabric.e-bigger #rteDialog {
          min-width: 281px;
        }
        .fabric #rteDialog {
          min-width: 241px;
        }
        .bootstrap.e-bigger #rteDialog,
        .bootstrap #rteDialog {
          min-width: 223px;
        }
        .highcontrast.e-bigger #rteDialog {
          min-width: 283px;
        }
        .highcontrast #rteDialog {
          min-width: 243px;
        }
        .material #rteDialog {
          min-width: 224px;
        }
        .material.e-bigger #rteDialog {
          min-width: 236px;
        }
      }
</style>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>