Example of Custom Format in ASP.NET MVC Markdown Editor Control
This sample demonstrates how to customize tags of markdown formatting. Type or edit the text and apply the format to view customized markdown syntax. For example, apply “+” to Unordered list.
@* The editor's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiMarkdownEditor(new UiMarkdownEditorOptions
{
Id = "customFormat",
Height = "150px",
Placeholder = "Enter your text here...",
Value = (string)ViewData["MDValue"],
ToolbarSettings = new UiMarkdownToolbar { Items = (List<string>)ViewData["Tools"] },
Formatter = new UiMarkdownFormatter
{
SelectionTags = new UiMarkdownSelectionTags { Bold = "__" },
ListTags = new UiMarkdownListTags { UL = "+ " }
}
})
@Html.UiMarkdownEditor(new UiMarkdownEditorOptions
{
Id = "customFormat",
Height = "150px",
Placeholder = "Enter your text here...",
Value = (string)ViewData["MDValue"],
ToolbarSettings = new UiMarkdownToolbar { Items = (List<string>)ViewData["Tools"] },
Formatter = new UiMarkdownFormatter
{
SelectionTags = new UiMarkdownSelectionTags { Bold = "__" },
ListTags = new UiMarkdownListTags { UL = "+ " }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MarkdownEditorController : Controller
{
// The page is Views/MarkdownEditor/CustomFormat.cshtml; it draws what ViewData holds.
public ActionResult CustomFormat()
{
ViewData["MDValue"] = "The sample is configured with customized markdown syntax using the __formatter__ property. Type the content and click the toolbar item to view customized markdown syntax. For an unordered list, you need to add a plus sign before the word (e.g., + list1). Or To make a phrase bold, you need to add two underscores before and after the phrase (e.g., __this text is bold__).";
ViewData["Tools"] = new List<string>
{
"Bold", "Italic", "StrikeThrough", "|", "Formats", "Blockquote", "OrderedList", "UnorderedList", "|", "CreateLink", "Image", "|", "Preview", "Undo", "Redo"
};
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Markdown Editor allows you to customize the markdown syntax by overriding its default syntax. Configure the customized markdown syntax using
the Formatter property: here bold is written as __text__ (SelectionTags) and an unordered list starts with
+ (ListTags).