Having trouble getting help?
Contact Support
Contact Support
Insert Images in ASP.NET CORE Markdown Editor Control
17 Mar 20259 minutes to read
The Markdown Editor allows users to insert images using the toolbar. This feature enables embedding images from online sources into the editor content.
Steps to Insert an Image
Follow these steps to add an image in the Markdown editor:
- Click the Insert Image icon in the toolbar.
- Enter the URL of the image from an online source.
- Click the Insert button in the image dialog.
The image will be added to the editor content at the cursor position.
The following example demonstrates how to enable image insertion in the Markdown 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.' } });
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(['Image']);
}
else {
rteObj.enableToolbarItem(['Image']);
}
});
}
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[] { "Image", tools1 };
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();
}
}