Customizing Markdown Syntax in EJ2 JavaScript Markdown Editor Component

5 Apr 20257 minutes to read

The Markdown Editor allows you to modify the default Markdown syntax to match your preferred formatting style. You can override the default syntax using the formatter property, enabling a customized Markdown experience.

Defining Custom Markdown Formatting

You can define custom symbols for different Markdown formatting options:

  • Use + for unordered lists instead of -.
  • Use __text__ for bold text instead of **text**.
  • Use _text_ for italic text instead of *text*.

The following example demonstrates how to customize Markdown tags in the editor:

// initialize Rich Text Editor component
var editor = new ej.richtexteditor.RichTextEditor({
    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.`,
    height: 340,
    toolbarSettings: {
        items: ['Bold', 'Italic', 'StrikeThrough', '|',
            'Formats', 'OrderedList', 'UnorderedList', '|',
            'CreateLink', 'Image', '|', 'Undo', 'Redo']
    },
    editorMode: 'Markdown',
    formatter: new ej.richtexteditor.MarkdownFormatter({
        listTags: { 'OL': '2. ', 'UL': '+ ' },
        formatTags: {
            'Blockquote': '> '
        },
        selectionTags: { 'Bold': '__', 'Italic': '_' }
    })
});
editor.appendTo('#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/30.1.37/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-richtexteditor/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-lists/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet">
     <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet">
    
    
   
<script src="https://cdn.syncfusion.com/ej2/30.1.37/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">
        <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
        <div id="editor"></div>
    </div>
    <style>
        .e-richtexteditor textarea.e-content {
            float: left;
            border-right: 1px solid rgba(0, 0, 0, 0.12);
        }
        .e-richtexteditor .e-rte-content .e-content{
            min-height: 150px;
        }
    
        .e-richtexteditor .e-rte-content {
            overflow: hidden;
        }
    
        .e-icon-btn.e-active .e-md-preview::before {
            content: '\e350';
        }
    
        .e-icon-btn .e-md-preview::before {
            content: '\e345';
        }
    
        .e-rte-content .e-content {
            float: right;
            width: 50%;
            overflow: auto;
            height: inherit;
            padding: 8px;
            height: 100%;
        }
    
        .e-rte-content .e-content.e-pre-source {
            width: 100%;
        }
    
        .highcontrast .e-richtexteditor textarea.e-content {
            border-right: 1px solid #fff;
        }
    
        .sb-header {
            z-index: 100;
        }
    </style>


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