Universal.OpenXml.Markdown 1.0.0

dotnet add package Universal.OpenXml.Markdown --version 1.0.0
                    
NuGet\Install-Package Universal.OpenXml.Markdown -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Universal.OpenXml.Markdown" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Universal.OpenXml.Markdown" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Universal.OpenXml.Markdown" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Universal.OpenXml.Markdown --version 1.0.0
                    
#r "nuget: Universal.OpenXml.Markdown, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Universal.OpenXml.Markdown@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Universal.OpenXml.Markdown&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Universal.OpenXml.Markdown&version=1.0.0
                    
Install as a Cake Tool

Universal.OpenXml.Markdown

A powerful .NET library that converts Markdown content directly into Microsoft Word OpenXML documents. Built on top of the Open XML SDK and Markdig, this library provides seamless integration between Markdown and Word document generation with support for all common Markdown elements including tables, lists, code blocks, and formatting.

Features

  • Complete Markdown Support - Headings, paragraphs, lists, tables, code blocks, quotes, links, emphasis, and horizontal rules
  • Smart List Integration - Automatically uses existing document bullet/numbering styles or creates Word-compatible defaults
  • Table Rendering - Full table support with proper borders, headers, and cell formatting
  • Extensible Architecture - Virtual methods allow customization of rendering behavior
  • Template-Friendly - Works seamlessly with existing Word templates and styles
  • Standards Compliant - Generates valid OpenXML that opens perfectly in Microsoft Word

Quick Start

Basic Usage with Extension Methods

using Universal.OpenXml.Markdown;
using DocumentFormat.OpenXml.Packaging;

// Render to main document body
using var doc = WordprocessingDocument.Create("output.docx", WordprocessingDocumentType.Document);
doc.AddMainDocumentPart().Document = new Document(new Body());

string markdown = @"
# My Document
This is a **bold** statement with *italic* text.

- Bullet item 1
- Bullet item 2

1. Numbered item
2. Another item

| Name | Age | City |
|------|-----|------|
| John | 30  | NYC  |
| Jane | 25  | LA   |
";

doc.RenderMarkdown(markdown);
doc.Save();

Using with Existing Templates

// Work with existing Word templates
using var template = WordprocessingDocument.CreateFromTemplate("template.docx");
var contentControl = template.MainDocumentPart.Document.Body
    .GetElementByTag("Content"); // Your custom content control

template.RenderMarkdown(contentControl, markdownContent);
template.SaveAs("output.docx");

Advanced Usage with Custom Renderer

public class CustomMarkdownRenderer : MarkdownRenderer
{
    protected override Paragraph RenderHeading(HeadingBlock heading)
    {
        var paragraph = base.RenderHeading(heading);
        
        // Add custom styling to headings
        if (heading.Level == 1)
        {
            // Custom H1 formatting
            var props = paragraph.ParagraphProperties;
            props.ParagraphStyleId.Val = "CustomHeading1";
        }
        
        return paragraph;
    }
    
    protected override Run RenderInlineCode(CodeInline code)
    {
        var run = base.RenderInlineCode(code);
        
        // Custom code formatting
        var props = run.RunProperties;
        props.Shading.Fill = "FFEB3B"; // Yellow background
        
        return run;
    }
}

// Use custom renderer
var renderer = new CustomMarkdownRenderer();
using var doc = WordprocessingDocument.Create("custom.docx", WordprocessingDocumentType.Document);
renderer.Render(doc, doc.MainDocumentPart.Document.Body, markdown);

Supported Markdown Elements

Element Markdown Syntax Word Output
Headings # H1 to ###### H6 Word heading styles (Heading1-Heading6)
Bold **bold** or __bold__ Bold formatting
Italic *italic* or _italic_ Italic formatting
Inline Code `code` Consolas font with gray background
Code Blocks code CodeBlock paragraph style
Links [text](url) Hyperlinks with blue underlined text
Bullet Lists - item or * item Word bullet lists with proper indentation
Numbered Lists 1. item Word numbered lists (1. a. i. pattern)
Tables \| col1 \| col2 \| Word tables with borders and header styling
Blockquotes > quote Quote paragraph style
Horizontal Rules --- Paragraph with top border

Smart List Handling

The library intelligently handles list formatting:

  1. Existing Styles First - Automatically detects and uses existing bullet/numbering definitions in your document
  2. Word-Compatible Defaults - Creates Word-standard list styles when none exist
  3. Multi-level Support - Full 9-level hierarchy matching Word's default patterns
  4. Proper Indentation - Correct hanging indents and spacing

Table Features

Tables are rendered with full Word compatibility:

  • Header Detection - First row automatically styled as table header
  • Border Support - Complete table and cell borders
  • Header Styling - Bold text and gray background for headers
  • Cell Content - Supports all Markdown formatting within cells
  • Auto-sizing - Tables automatically adjust to content width

API Reference

MarkdownRenderer Class

The core class for converting Markdown to OpenXML.

Constructors
// Default constructor with standard Markdig pipeline
public MarkdownRenderer()

// Custom constructor with specific Markdig pipeline
public MarkdownRenderer(MarkdownPipeline markdownPipeline)
Main Methods
// Render markdown into specified OpenXML element
public void Render(WordprocessingDocument document, OpenXmlElement container, string markdown)
Virtual Methods for Customization
protected virtual IEnumerable<OpenXmlElement> RenderBlock(Block block)
protected virtual Paragraph RenderHeading(HeadingBlock heading)
protected virtual Paragraph RenderParagraph(ParagraphBlock paragraph)
protected virtual IEnumerable<OpenXmlElement> RenderList(ListBlock list)
protected virtual Table RenderTable(Markdig.Extensions.Tables.Table table)
protected virtual IEnumerable<OpenXmlElement> RenderQuoteBlock(QuoteBlock quote)
protected virtual IEnumerable<Run> RenderEmphasis(EmphasisInline emphasis)
protected virtual IEnumerable<Run> RenderHyperlink(LinkInline link)
protected virtual Run RenderInlineCode(CodeInline code)
protected virtual Paragraph RenderCodeBlock(CodeBlock codeBlock)
protected virtual Paragraph RenderHorizontalRule()

Extension Methods

Convenient extension methods for WordprocessingDocument:

// Render to main document body
public static void RenderMarkdown(this WordprocessingDocument document, string markdown)

// Render to specific element
public static void RenderMarkdown(this WordprocessingDocument document, OpenXmlElement element, string markdown)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 248 9/19/2025

Initial release.