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
<PackageReference Include="Universal.OpenXml.Markdown" Version="1.0.0" />
<PackageVersion Include="Universal.OpenXml.Markdown" Version="1.0.0" />
<PackageReference Include="Universal.OpenXml.Markdown" />
paket add Universal.OpenXml.Markdown --version 1.0.0
#r "nuget: Universal.OpenXml.Markdown, 1.0.0"
#:package Universal.OpenXml.Markdown@1.0.0
#addin nuget:?package=Universal.OpenXml.Markdown&version=1.0.0
#tool nuget:?package=Universal.OpenXml.Markdown&version=1.0.0
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:
- Existing Styles First - Automatically detects and uses existing bullet/numbering definitions in your document
- Word-Compatible Defaults - Creates Word-standard list styles when none exist
- Multi-level Support - Full 9-level hierarchy matching Word's default patterns
- 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 | Versions 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. |
-
.NETStandard 2.0
- Markdig (>= 0.42.0)
- Universal.OpenXml (>= 4.0.1)
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.