Mdazor 0.0.0-alpha.0.10
dotnet add package Mdazor --version 0.0.0-alpha.0.10
NuGet\Install-Package Mdazor -Version 0.0.0-alpha.0.10
<PackageReference Include="Mdazor" Version="0.0.0-alpha.0.10" />
<PackageVersion Include="Mdazor" Version="0.0.0-alpha.0.10" />
<PackageReference Include="Mdazor" />
paket add Mdazor --version 0.0.0-alpha.0.10
#r "nuget: Mdazor, 0.0.0-alpha.0.10"
#:package Mdazor@0.0.0-alpha.0.10
#addin nuget:?package=Mdazor&version=0.0.0-alpha.0.10&prerelease
#tool nuget:?package=Mdazor&version=0.0.0-alpha.0.10&prerelease
Mdazor
A Markdig extension that lets you embed Blazor components directly in Markdown.
What is this?
Ever wanted to write Markdown like this:
# My Documentation
Here's some regular markdown content.
<AlertCard type="warning">
This is a **real Blazor component** with Markdown content inside!
- It supports lists
- And *formatting*
- And even nested components!
<Button variant="primary">Click me!</Button>
</AlertCard>
More regular markdown continues here...
And have it actually render real Blazor components? That's what this does.
Why does this exist?
Writing documentation with static Markdown is fine, but sometimes you want to:
- Generate content programmatically
- Embed actual UI components in your docs
How it works
This is a custom Markdig extension that:
- Parses component tags - Recognizes
<ComponentName prop="value">content</ComponentName>
syntax in your Markdown - Uses Blazor's HtmlRenderer - Actually renders real Blazor components server-side
- Handles nested content - Markdown inside components gets processed recursively
- Graceful fallback - Unknown components just render as regular HTML tags
The magic happens in the parsing phase - we intercept component-looking tags before they get processed as regular HTML, instantiate actual Blazor components, and render them using Blazor's server-side rendering.
Example Components
Your components just need to be normal Blazor components:
@{
var alertClass = Type switch
{
"success" => "alert-success",
"warning" => "alert-warning",
"danger" => "alert-danger",
"info" => "alert-info",
_ => "alert-primary"
};
}
<div class="alert @alertClass" role="alert">
@ChildContent
</div>
@code {
[Parameter] public string Type { get; set; } = "primary";
[Parameter] public RenderFragment? ChildContent { get; set; }
}
The ChildContent
parameter gets populated with the processed Markdown content from inside the component tags.
Features
Component Syntax
<Icon name="star" size="24" />
<Card title="Hello World">
This content becomes the component's ChildContent parameter.
</Card>
<AlertBox type="info">
## This is a heading inside a component
And here's a nested component:
<Button onclick="alert('hi')">Click me</Button>
- Lists work too
- **Bold text**
- Everything you'd expect
</AlertBox>
Fallback for unknown components
If a component isn't registered, it just renders as HTML:
<SomeUnknownWidget foo="bar">content</SomeUnknownWidget>
Becomes: <someunknownwidget foo="bar">content</someunknownwidget>
with the error message as an HTML comment.
Setup
- Register your components:
services.AddMdazor()
.AddMdazorComponent<AlertCard>()
.AddMdazorComponent<Button>()
.AddMdazorComponent<Icon>();
- Use it:
Create your own pipeline, ensuring to inject your service provider so we can find the components:
var pipeline = new MarkdownPipelineBuilder()
.UseMdazor(serviceProvider)
.Build();
var html = Markdown.ToHtml(markdownContent, pipeline);
For advanced scenarios, you can still use the renderer directly:
var document = Markdown.Parse(markdownContent, pipeline);
using var writer = new StringWriter();
var renderer = new BlazorRenderer(writer, componentRegistry, serviceProvider);
renderer.Render(document);
var html = writer.ToString();
Technical Notes
- Uses Blazor's
HtmlRenderer
for actual server-side component rendering - Component parameters are mapped using reflection with case-insensitive matching
- Nested Markdown content is processed recursively using the same pipeline
- Async rendering is fully supported
@inject
works inside components, so you can inject services as usual
Limitations
It doesn't handle whitespace all that great. If you are using a markdown element that relies on precise whitespace such as a code element or blockquote, don't indent your tags e.g.
Do this:
<Card> ```csharp var i = 2 + 2; ``` </Card>
Not this:
<Card> ```csharp var i = 2 + 2; ``` </Card>
Server-side rendering only (no client-side Blazor support yet)
Components need to be registered ahead of time
No support for complex parameter types (just strings, numbers, bools for now)
Component names must start with a capital letter (follows HTML custom element rules)
Project Structure
Mdazor/
- The main library with the Markdig extensionMdazor.Demo/
- A Blazor Server app showing it in actionMdazor.Tests/
- Unit and integration tests
Running the Demo
cd Mdazor.Demo
dotnet run
Then check out the demo pages to see components embedded in Markdown.
Contributing
This is a skunkworks project, so don't expect enterprise-level polish. But if you find bugs or have ideas, PRs welcome!
The main areas that could use work:
- Support for more complex parameter types
- Fixing the aforementioned whitespace problems
- Client-side Blazor support
- Better error handling and diagnostics
- Performance optimizations
- More comprehensive documentation
License
MIT - do whatever you want with it.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- Markdig (>= 0.41.2)
- Microsoft.AspNetCore.Components.Web (>= 9.0.6)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Mdazor:
Package | Downloads |
---|---|
MyLittleContentEngine
A powerful content engine for building static sites with Blazor and ASP.NET Core |
|
MyLittleContentEngine.DocSite
A full site using the MyLittleContentEngine |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.0.0-alpha.0.10 | 99 | 7/16/2025 |
0.0.0-alpha.0.9 | 464 | 7/3/2025 |
0.0.0-alpha.0.8 | 114 | 6/23/2025 |
0.0.0-alpha.0.7 | 168 | 6/16/2025 |
0.0.0-alpha.0.6 | 119 | 6/16/2025 |
0.0.0-alpha.0.5 | 115 | 6/16/2025 |
0.0.0-alpha.0.4 | 118 | 6/16/2025 |
0.0.0-alpha.0.3 | 113 | 6/16/2025 |
0.0.0-alpha.0.1 | 136 | 6/16/2025 |
0.0.0-alpha.0 | 116 | 6/16/2025 |