A lightweight, extensible Markdown parser for .NET, built with a clean, modular architecture. It provides a simple way to convert Markdown source into HTML, supporting multiple dialects.
- Extensible Architecture: Easily add new Markdown dialects by inheriting from the
BaseMarkdown
class. - CommonMark Support: The default
CommonMarkdown
renderer handles standard Markdown syntax. - GitHub Flavored Markdown (GFM): A dedicated
GitHubFlavoredMarkdown
renderer adds GFM features like tables, task lists, and strikethrough. - Simple API: A static
OpenMarkDown
utility class provides a clean, user-friendly interface for rendering.
The library is pre-configured to use the CommonMarkdown
renderer by default.
using OpenMarkdown;
string markdown = "# Hello, Markdown!\nThis is a **bold** paragraph.";
string html = OpenMarkDown.Render(markdown);
Console.WriteLine(html);
// Output: <h1>Hello, Markdown!</h1><p>This is a <strong>bold</strong> paragraph.</p>
You can specify a different renderer for a one-off conversion using the generic Render<T>
method.
using OpenMarkdown;
using OpenMarkdown.Dialects;
string gfmMarkdown = "- [x] Task list item\n\n~~Strikethrough~~";
string html = OpenMarkDown.Render<GitHubFlavoredMarkdown>(gfmMarkdown);
Console.WriteLine(html);
// Output: <ul><li class="task-list-item"><input type="checkbox" disabled checked /> Task list item</li></ul><p><del>Strikethrough</del></p>
To change the default renderer for all subsequent OpenMarkDown.Render()
calls, use the UseRenderer
method.
using OpenMarkdown;
using OpenMarkdown.Dialects;
// Set GFM as the new default renderer
OpenMarkDown.UseRenderer<GitHubFlavoredMarkdown>();
string markdown = "A raw link: https://example.com";
string html = OpenMarkDown.Render(markdown); // Uses the new GFM default
Console.WriteLine(html);
// Output: <p>A raw link: <a href="https://example.com">https://example.com</a></p>
The project is designed to be modular and easy to navigate.
BaseMarkdown.cs
: The abstract base class that defines the core rendering contract.OpenMarkDown.cs
: The static entry point for the library.Dialects/
: A folder containing specific Markdown dialect implementations.CommonMarkdown.cs
: The standard CommonMark renderer.GitHubFlavoredMarkdown.cs
: ExtendsCommonMarkdown
to add GFM features.