Skip to main content

OfficeIMO.Markdown

Build, parse, and render Markdown with a typed AST and fluent API. Multiple reader profiles, HTML rendering, and zero dependencies.

dotnet add package OfficeIMO.Markdown

Why OfficeIMO.Markdown?

OfficeIMO.Markdown is a purpose-built Markdown engine for .NET. It gives you a strongly typed AST, a fluent builder for document construction, and multiple reader profiles so you can parse CommonMark, GFM, or OfficeIMO-flavored Markdown with one library. Every node carries source span information, which makes it a practical fit for tooling, linters, and editor integrations.

Features

  • Fluent document builder -- construct Markdown documents programmatically with a chainable API
  • Typed block & inline AST model -- headings, paragraphs, lists, tables, code blocks, emphasis, links, and images as strongly typed objects
  • Source spans for every node -- line, column, and offset tracking for diagnostics and editor support
  • Multiple reader profiles -- OfficeIMO, CommonMark, GFM, and Portable profiles with configurable strictness
  • HTML rendering -- emit fragment or full-page HTML with customizable templates
  • Front matter support -- parse YAML and TOML front matter into typed dictionaries
  • TOC helpers & callouts -- generate table of contents from headings and render note/warning/tip callouts
  • Tables from objects -- build Markdown tables directly from collections with column selectors
  • Input normalization presets -- normalize line endings, whitespace, and encoding before parsing
  • Post-parse document transforms -- rewrite, filter, or augment the AST after parsing
  • Extension API -- register custom block and inline parsers for domain-specific syntax
  • Zero external dependencies -- ships as a single assembly with no third-party references

Quick start

using OfficeIMO.Markdown;

var doc = MarkdownDoc.Create()
    .FrontMatter(new { title = "Release Notes", tags = new[] { "docs", "release" } })
    .H1("Release Notes")
    .P("Version 3.0 introduces several improvements.")
    .H2("New Features")
    .Ul(ul => ul
        .Item("Fluent document builder")
        .Item("Typed AST and traversal helpers")
        .Item("HTML fragment and full-page rendering"))
    .H2("Performance")
    .Table(t => t
        .Headers("Benchmark", "v2.4", "v3.0")
        .Row("Parse 10K lines", "48 ms", "21 ms")
        .Row("Render to HTML", "35 ms", "14 ms")
        .Row("Round-trip fidelity", "97%", "100%")
        .AlignNumericRight())
    .Code("powershell", "dotnet add package OfficeIMO.Markdown");

string markdown = doc.ToMarkdown();
string html = doc.ToHtmlFragment();

var parsed = MarkdownReader.Parse(
    markdown,
    MarkdownReaderOptions.CreateGitHubFlavoredMarkdownProfile());

// Inspect the AST
foreach (var block in parsed.DescendantsAndSelf())
{
    Console.WriteLine(block.GetType().Name);
}

Compatibility

Target FrameworkSupported
.NET 10.0Yes
.NET 8.0Yes
.NET Standard 2.0Yes
.NET Framework 4.7.2Yes

OfficeIMO.Markdown runs on Windows, Linux, and macOS. It is one of the lower-risk packages in the repo for trimming- or AOT-sensitive deployments, but you should still validate your own publish configuration and runtime targets.

GuideDescription
Markdown documentationStart with the package overview and document model.
Builder APICompose documents fluently with headings, tables, and callouts.
PSWriteOffice Markdown cmdletsGenerate Markdown from PowerShell objects and scripts.
Word to MarkdownConvert between Word documents and Markdown workflows.