SpatialFocus.Blazor.Micromark
0.1.0
See the version list below for details.
dotnet add package SpatialFocus.Blazor.Micromark --version 0.1.0
NuGet\Install-Package SpatialFocus.Blazor.Micromark -Version 0.1.0
<PackageReference Include="SpatialFocus.Blazor.Micromark" Version="0.1.0" />
<PackageVersion Include="SpatialFocus.Blazor.Micromark" Version="0.1.0" />
<PackageReference Include="SpatialFocus.Blazor.Micromark" />
paket add SpatialFocus.Blazor.Micromark --version 0.1.0
#r "nuget: SpatialFocus.Blazor.Micromark, 0.1.0"
#:package SpatialFocus.Blazor.Micromark@0.1.0
#addin nuget:?package=SpatialFocus.Blazor.Micromark&version=0.1.0
#tool nuget:?package=SpatialFocus.Blazor.Micromark&version=0.1.0
SpatialFocus.Blazor.Micromark
A Blazor component that renders markdown in the browser with micromark.
It renders CommonMark and GitHub Flavored Markdown (tables, strikethrough, task lists, autolinks and footnotes), and escapes HTML in the markdown by default. micromark comes inside the package as one JavaScript file of about 20 KB compressed.
Installation
dotnet add package SpatialFocus.Blazor.Micromark
The package targets .NET 10 and .NET 11.
Usage
Register the renderer in Program.cs:
using SpatialFocus.Blazor.Micromark;
builder.Services.AddMicromark();
Show markdown with the component. Attributes such as class go to the div it renders:
@using SpatialFocus.Blazor.Micromark
<Markdown Value="@text" class="notes" />
Or inject IMarkdownRenderer and render in code:
string html = await renderer.RenderAsync("# Hello *world*");
Options
MarkdownOptions goes to the component's Options parameter or to RenderAsync.
| Option | Default | Effect |
|---|---|---|
Gfm |
on | Renders GitHub Flavored Markdown on top of CommonMark. |
AllowDangerousHtml |
off | HTML in the markdown reaches the output as HTML. Off, it is escaped. |
AllowDangerousProtocol |
off | Links and images keep URLs of any protocol, such as javascript:. Off, such a URL is dropped. |
AllowDangerousHtml and AllowDangerousProtocol pass the markdown's HTML and URLs on unsanitized. Switch them on for
markdown from a trusted source alone.
<Markdown Value="@text" Options="@(new MarkdownOptions { Gfm = false })" />
Hosting models
A JavaScript initializer in the package loads micromark before Blazor starts. On WebAssembly the component then renders synchronously, and the HTML is there with its first render. Where the initializer did not run, the renderer loads micromark on first use and the component shows the HTML once it arrives.
| Hosting model | With this package | With a server package | Tested |
|---|---|---|---|
| Standalone WebAssembly | HTML with the first render | ✅ | |
| Blazor Web App, Interactive WebAssembly | HTML with the first render | the same | ✅ |
| Blazor Web App, Interactive Server | HTML after the first render, rendered in the browser | the same | ✅ |
| Blazor Web App, Interactive Auto | As Interactive Server on the first visit, as Interactive WebAssembly after it | the same | ✅ |
| Prerendering | Empty in the prerendered page, filled once the component is interactive | HTML in the prerendered page, kept when the component becomes interactive | ✅ |
| Static server rendering | Stays empty | HTML | ✅ |
| Blazor Hybrid | HTML after the first render | (:white_check_mark:)* |
* untested
On Interactive Server the HTML comes back from the browser over SignalR, whose incoming messages are limited to 32 KB by default. Markdown that renders to more needs a higher limit:
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddHubOptions(options => options.MaximumReceiveMessageSize = 64 * 1024);
Rendering on the server
Two packages run the same micromark on the server. Static server rendering and prerendering then show the HTML, and it is the HTML the browser renders.
| Package | Engine | For |
|---|---|---|
SpatialFocus.Blazor.Micromark.Server.Jint |
Jint, a JavaScript interpreter in managed code | Short texts, on every platform .NET runs on |
SpatialFocus.Blazor.Micromark.Server.V8 |
V8 through ClearScript | Long texts and many renderings, where its conditions are met |
dotnet add package SpatialFocus.Blazor.Micromark.Server.Jint
// Server project, AddMicromarkV8() with the V8 package
builder.Services.AddMicromarkJint();
// Client project
builder.Services.AddMicromark();
The engine renders the passes without interactivity, the browser the interactive ones. An interactive component on the
server starts with the HTML of its prerender pass, so nothing flickers, and asks the browser only once the markdown
changes. That HTML travels in the page, compressed and up to 6 KB for all its components. A component beyond that is
rendered again once it is interactive. interactive: true in either call renders the interactive passes on the server
as well, without the trip to the browser.
Neither package caches the HTML. micromark takes quadratic time for some texts, which matters where users write the
markdown, so a rendering ends with a TimeoutException after five seconds. Both calls take another limit:
AddMicromarkJint(configure: options => options.Timeout = TimeSpan.FromSeconds(1)).
JintMarkdownRenderer, V8MarkdownRenderer and BrowserMarkdownRenderer are public, so an IMarkdownRenderer of your
own can wrap them, to cache the HTML for instance. Registered after AddMicromarkJint() or AddMicromarkV8(), it
replaces the package's.
Jint
Jint is managed code and needs nothing beside .NET. It interprets JavaScript, so a rendering takes significantly longer than in a browser, which shows mostly with long texts.
V8
V8 compiles micromark to machine code, and a long text renders in a fraction of the time Jint takes. It comes with conditions:
- Platforms: the package brings V8 for Windows x64 and Linux x64. An app on another platform references
ClearScript's package for it, such as
Microsoft.ClearScript.V8.Native.linux-arm64orMicrosoft.ClearScript.V8.Native.osx-arm64, in the version ofMicrosoft.ClearScript.V8. On Linux V8 needs glibc: ClearScript has no package for Alpine. - Size: V8 is a native library of tens of megabytes per platform. A publish for one runtime identifier holds that platform's alone.
- Trimming and Native AOT: ClearScript works with neither.
- Threads: a rendering runs on a thread of the renderer's own while its caller waits for it. The renderer keeps up
to
MaximumConcurrentRenderingsof them. - Memory: V8 keeps a heap of its own beside .NET's.
MaximumHeapSize, 128 MB by default, limits it for one rendering, which ends with anInsufficientMemoryExceptionbeyond it.MaximumConcurrentRenderings, one per processor by default, limits how many run at the same time. Further renderings wait, and the wait counts towards the timeout. The heap size is watched from the thread pool: in an app whose other work keeps every thread of the pool busy the watch comes late, and V8 ends the process where it runs out of memory.
The engines stay loaded for the next renderings. In a container, MaximumConcurrentRenderings times MaximumHeapSize
has to fit its memory limit beside the app's own memory, with room to spare, since a rendering passes the heap size a
little before it ends.
builder.Services.AddMicromarkV8(configure: options =>
{
options.MaximumConcurrentRenderings = 2;
options.MaximumHeapSize = 64 * 1024 * 1024;
});
Third-party notices
The JavaScript file bundles micromark and its dependencies, all under the MIT license. Their versions and license texts
are in THIRD-PARTY-NOTICES.txt, which comes with the package and which an app serves beside the file at
_content/SpatialFocus.Blazor.Micromark/THIRD-PARTY-NOTICES.txt. Each server package holds the notices of its
own bundle.
License
The package is released under the MIT license.
Made with ❤️ by Spatial Focus
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.0)
-
net11.0
- Microsoft.AspNetCore.Components.Web (>= 11.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SpatialFocus.Blazor.Micromark:
| Package | Downloads |
|---|---|
|
SpatialFocus.Blazor.Micromark.Server.Jint
Renders markdown on the server with micromark in Jint, for static server rendering and prerendering with SpatialFocus.Blazor.Micromark. |
|
|
SpatialFocus.Blazor.Micromark.Server.V8
Renders markdown on the server with micromark in V8, for static server rendering and prerendering with SpatialFocus.Blazor.Micromark. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.1 | 63 | 11/30/2026 |
| 0.1.0 | 77 | 11/30/2026 |
| 0.1.0-beta.1 | 54 | 11/30/2026 |