Search results

Markdown

In RichTextEditor, 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 RichTextEditor supports markdown editing when the editorMode set as markdown and using both keyboard interaction and toolbar action, you can apply the formatting to text.

Supported Tools

The editor’s toolbar contains commands to format the markdown content. The toolbar consists of:

Tools Description
Lists Ordered and unordered list types.
Links A hyperlink can be inserted into the editor for quick access to related information.
Image Inserts and manages images.
Alignment Aligns the content with left, center, and right margins.
Format Formats the sentence in different ways such as heading level, quotation, and code snippet.
Styles Allows you to apply inline styles to the selected content like bold, italic, and more.

Markdown to HTML

The rich text editor allows you to preview markdown changes immediately using preview. The third-party library Marked is used in this sample to convert markdown into HTML content.

This sample demonstrates how to preview markdown changes in rich text editor. Type or edit the display text and apply format to view the preview of markdown.

tagHelper
<div class="control-wrapper">
    <div class="control-section">
        <ejs-richtexteditor id="image" value="@ViewBag.value" created="created">
            <e-richtexteditor-toolbarsettings items="@ViewBag.items"></e-richtexteditor-toolbarsettings>
        </ejs-richtexteditor>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script type="text/javascript">
     var mdsource, defaultRTE, textArea;
     function created() {
         defaultRTE = this;
         textArea = defaultRTE.contentModule.getEditPanel();
         textArea.addEventListener('keyup', (event) => { markDownConversion(); });
         var rteObj = defaultRTE;
         mdsource = document.getElementById('preview-code');
         mdsource.addEventListener('click', (event) => {
             fullPreview({ mode: true, type: 'preview' });
             if ((event.currentTarget).classList.contains('e-active')) {
                 defaultRTE.disableToolbarItem(['Bold', 'Italic', 'StrikeThrough', '|',
                     'Formats', 'OrderedList', 'UnorderedList', '|',
                     'CreateLink', 'Image', 'Undo', 'Redo']);
             } else {
                 defaultRTE.enableToolbarItem(['Bold', 'Italic', 'StrikeThrough', '|',
                     'Formats', 'OrderedList', 'UnorderedList', '|',
                     'CreateLink', 'Image', 'Undo', 'Redo']);
             }
         });
     };
     function markDownConversion() {
         if (mdsource.classList.contains('e-active')) {
             var id = defaultRTE.getID() + 'html-preview';
             var htmlPreview = defaultRTE.element.querySelector('#' + id);
             var rteElement = defaultRTE.contentModule.getEditPanel();
             var rteValue = rteElement.value;
             htmlPreview.innerHTML = marked(defaultRTE.value);
         }
     };
     function fullPreview(event) {
         var id = defaultRTE.getID() + 'html-preview';
         htmlPreview = defaultRTE.element.querySelector('#' + id);
         if (mdsource.classList.contains('e-active')) {
             mdsource.classList.remove('e-active');
             mdsource.parentElement.title = 'Preview';
             textArea.style.display = 'block';
             textArea.style.width = '100%';
             htmlPreview.style.display = 'none';
         } else {
             mdsource.classList.add('e-active');
             if (!htmlPreview) {
                 htmlPreview = ej.base.createElement('div', { className: 'e-content' });
                 htmlPreview.id = id;
                 textArea.parentNode.appendChild(htmlPreview);
             }
             if (event.type === 'preview') {
                 textArea.style.display = 'none'; htmlPreview.classList.add('e-pre-source');
             } else {
                 htmlPreview.classList.remove('e-pre-source');
                 textArea.style.width = '50%';
             }
             htmlPreview.style.display = 'block';
             markDownConversion();
             mdsource.parentElement.title = 'Code View';
         }
     }
</script>
<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;
        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;
    }
</style>