Having trouble getting help?
Contact Support
Contact Support
Customizing Markdown Syntax in ASP.NET CORE Markdown Editor Control
17 Mar 202512 minutes to read
The ASP.NET Core 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:
<ejs-richtexteditor id="markdown" value="@ViewBag.value" editorMode="Markdown" created="created">
<e-richtexteditor-toolbarsettings items="@ViewBag.items"></e-richtexteditor-toolbarsettings>
</ejs-richtexteditor>
<script type="text/javascript">
var rteObj, textArea, mdsource;
function created() {
rteObj = this;
rteObj.formatter = new ej.richtexteditor.MarkdownFormatter({
listTags: { 'OL': '1., 2., 3.', 'UL': '+ ' },
formatTags: {
'Blockquote': '> '
},
selectionTags: { 'Bold': '__', 'Italic': '_' }
});
rteObj.dataBind();
textArea = rteObj.contentModule.getEditPanel();
textArea.addEventListener('keyup', function (e) {
markdownConversion();
});
mdsource = document.getElementById('preview-code');
mdsource.addEventListener('click', function (e) {
fullPreview();
if (e.currentTarget.classList.contains('e-active')) {
rteObj.disableToolbarItem(["Bold", "Italic", "StrikeThrough", "|", "SuperScript",
"SubScript", "Formats", "OrderedList", "UnorderedList" , "|", "CreateLink", "Image", "CreateTable", "|",
"Undo", "Redo"]);
}
else {
rteObj.enableToolbarItem(["Bold", "Italic", "StrikeThrough", "|", "SuperScript",
"SubScript", "Formats", "OrderedList", "UnorderedList" , "|", "CreateLink", "Image", "CreateTable", "|",
"Undo", "Redo"]);
}
});
}
loadExternalFile();
function loadExternalFile() {
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.19/marked.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
function markdownConversion() {
if (mdsource.classList.contains('e-active')) {
var id = rteObj.getID() + 'html-preview';
var htmlPreview = rteObj.element.querySelector('#' + id);
htmlPreview.innerHTML = marked(rteObj.contentModule.getEditPanel().value);
}
}
function fullPreview() {
var id = rteObj.getID() + 'html-preview';
var htmlPreview = rteObj.element.querySelector('#' + id);
var previewTextArea = rteObj.element.querySelector('.e-rte-content');
if (mdsource.classList.contains('e-active')) {
mdsource.classList.remove('e-active');
mdsource.parentElement.title = 'Preview';
textArea.style.display = 'block';
htmlPreview.style.display = 'none';
previewTextArea.style.overflow = 'hidden';
}
else {
mdsource.classList.add('e-active');
if (!htmlPreview) {
htmlPreview = ej.base.createElement('div', { className: 'e-content e-pre-source' });
htmlPreview.id = id;
textArea.parentNode.appendChild(htmlPreview);
previewTextArea.style.overflow = 'auto';
}
if (previewTextArea.style.overflow === 'hidden') {
previewTextArea.style.overflow = 'auto';
}
textArea.style.display = 'none';
htmlPreview.style.display = 'block';
htmlPreview.innerHTML = marked(rteObj.contentModule.getEditPanel().value);
mdsource.parentElement.title = 'Code View';
}
}
</script>
<style>
.e-richtexteditor textarea.e-content {
float: left;
}
.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';
}
.bootstrap4 .e-icon-btn.e-active .e-md-preview::before {
content: '\e790';
}
.bootstrap4 .e-icon-btn .e-md-preview::before {
content: '\e787';
}
.fluent .e-icon-btn.e-active .e-md-preview::before,
.fluent-dark .e-icon-btn.e-active .e-md-preview::before,
.fluent2 .e-icon-btn.e-active .e-md-preview::before,
.fluent2-dark .e-icon-btn.e-active .e-md-preview::before,
.fluent2-highcontrast .e-icon-btn.e-active .e-md-preview::before,
.tailwind .e-icon-btn.e-active .e-md-preview::before,
.tailwind-dark .e-icon-btn.e-active .e-md-preview::before,
.tailwind3 .e-icon-btn.e-active .e-md-preview::before,
.tailwind3-dark .e-icon-btn.e-active .e-md-preview::before,
.bootstrap5 .e-icon-btn.e-active .e-md-preview::before,
.bootstrap5-dark .e-icon-btn.e-active .e-md-preview::before,
.bootstrap5\.3 .e-icon-btn.e-active .e-md-preview::before,
.bootstrap5\.3-dark .e-icon-btn.e-active .e-md-preview::before,
.material3 .e-icon-btn.e-active .e-md-preview::before,
.material3-dark .e-icon-btn.e-active .e-md-preview::before {
content: '\e80e';
}
.tailwind .e-icon-btn .e-md-preview::before,
.tailwind-dark .e-icon-btn .e-md-preview::before,
.tailwind3 .e-icon-btn .e-md-preview::before,
.tailwind3-dark .e-icon-btn .e-md-preview::before,
.bootstrap5 .e-icon-btn .e-md-preview::before,
.bootstrap5-dark .e-icon-btn .e-md-preview::before,
.bootstrap5\.3 .e-icon-btn .e-md-preview::before,
.bootstrap5\.3-dark .e-icon-btn .e-md-preview::before,
.fluent .e-icon-btn .e-md-preview::before,
.fluent-dark .e-icon-btn .e-md-preview::before,
.fluent2 .e-icon-btn .e-md-preview::before,
.fluent2-dark .e-icon-btn .e-md-preview::before,
.fluent2-highcontrast .e-icon-btn .e-md-preview::before,
.material3 .e-icon-btn .e-md-preview::before,
.material3-dark .e-icon-btn .e-md-preview::before {
content: '\e7de';
}
</style>
public class HomeController : Controller
{
public ActionResult Index()
{
object tools1 = new
{
tooltipText = "Preview",
template = "<button id='preview-code' class='e-tbar-btn e-control e-btn e-icon-btn'>" +
"<span class='e-btn-icon e-md-preview e-icons'></span></button>"
};
ViewBag.items = new[]
{
"Bold", "Italic", "StrikeThrough", "|", "SuperScript",
"SubScript", "Formats", "OrderedList", "UnorderedList" , "|", tools1 , "CreateLink", "Image", "CreateTable", "|",
"Undo", "Redo"
};
ViewBag.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.
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.
We can add our own custom formation syntax for the Markdown formation.
The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content";
return View();
}
}