Razor component for Markdown rendering.
Online demo:
- Abbreviations
- Auto identifiers
- Citations
- Custom containers
- Definition lists
- Emphasis extras
- Figures
- Footers
- Footnotes
- GridTables
- Mathematics
- Media links
- Youtube
- Bilibili
- Netease music
- Pipe tables
- Task lists
- Diagrams, flowcharts
- Auto links
- Smarty pants
- Emoji
- Code highlighting
- Delay rendering for less CPU intensive
- HTML Sanitizing to prevent XSS
Add the newest package on NuGet.
dotnet add package StardustDL.RazorComponents.Markdown
This project is built on Modulight.
Here are the example codes, which based on the instructions from Usage and Use Razor Component Modules. See demo for details.
WebAssembly
// in Program.cs
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddModules(builder =>
{
builder.UseRazorComponentClientModules().AddMarkdownModule();
});
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// Attention: RunAsyncWithModules
await builder.Build().RunAsyncWithModules();
}
Razor Pages
// in App.razor
<Modulight.Modules.Client.RazorComponents.UI.ResourceDeclare />
// in Startup: void ConfigureServices(ISeviceCollection services)
using StardustDL.RazorComponents.Markdown;
services.AddModules(builder => {
builder.UseRazorComponentClientModules().AddMarkdownModule();
});
// Generic hosting. (provided by package Modulight.Modules.Hosting, need to add this package)
// in Program: Task Main(string[] args)
using Microsoft.Extensions.Hosting;
await CreateHostBuilder(args).Build().RunAsyncWithModules();
<StardustDL.RazorComponents.Markdown.MarkdownRenderer
Value="@MarkdownText"
Class="your class"
Style="your styles"
RenderInterval="@TimeSpan.FromSeconds(10)"/>
Parameters:
Value
Raw Markdown (String
)Class
class attributeStyle
style attributeRenderInterval
Delay rendering interval (TimeSpan
), defaultnull
for no delay.EnableCodeHighlighting
Highlighing code blocks, defaulttrue
.EnableDiagrams
Rendering diagrams, defaulttrue
.EnableMathematics
Rendering LaTex lines, defaulttrue
.EnableHtmlSanitizing
Sanitizing the final HTML to prevent XSS, defaulttrue
.
Here are some screenshots from the demo project.
Apache-2.0