Using MarkdownFormatProvider
The MarkdownFormatProvider allows you to import and export RadFlowDocument instances to and from the Markdown (.md and .markdown) format. RadWordsProcessing includes a built-in Markdown parser and writer that supports the most common Markdown elements used in documentation and content authoring workflows.
To use the
MarkdownFormatProvider, install theTelerik.Documents.FlowNuGet package for .NET Standard and .NET (Target OS: None) orTelerik.Windows.Documents.Flowfor .NET Framework and .NET (Target OS: Windows).
Supported Document Elements
The MarkdownFormatProvider supports the following document elements during import and export:
Block-level Elements
| Element | Notes |
|---|---|
| Headings (H1–H6) | ATX (# Heading) and Setext (=== / ---) styles configurable via ExportSettings.HeadingStyle |
| Paragraphs | Standard CommonMark paragraphs |
| Thematic break / horizontal rule | ---, ***, ___ |
| Fenced code blocks | With optional language info string; fence char configurable via ExportSettings.CodeFenceStyle |
| Indented code blocks | Four-space or tab-indented content |
| Block quotes | Nested block quotes supported up to 21 levels |
| Bullet lists | Tight and loose lists |
| Ordered lists | Both . and ) terminators |
| Task lists (GFM) | [ ] unchecked / [x] checked |
| GFM pipe tables | With column alignment; configurable via ExportSettings.TableExport (GfmPipe or Skip) |
| Raw HTML blocks | Preserved verbatim on round-trip |
| YAML frontmatter | Delimited by --- at document start; preserved verbatim |
Inline Elements
| Element | Notes |
|---|---|
| Plain text | text |
| Bold | **text** |
| Italic | *text* |
| Bold italic | ***text*** |
~~text~~ | |
Inline code span | Backtick delimited; also applied to Runs using monospace fonts (configurable via ExportSettings.MonospaceFontNames) |
| Hyperlinks | [text](url) inline links |
| Inline images |  configurable via ExportSettings.ImageExport (Inline or Skip) |
| Floating images | Exported as inline  |
| Hard line break | Two trailing spaces or \ at end of line |
Markdown is a plain-text format. Document elements with no Markdown equivalent, such as fonts, colors, page size, margins, and headers and footers, are not preserved during export.
Import
To import a Markdown file, create a MarkdownFormatProvider instance and call its Import method with a Stream to the .md file.
Example 1: Import from a File
Telerik.Windows.Documents.Flow.Model.RadFlowDocument document;
Telerik.Windows.Documents.Flow.FormatProviders.Md.MarkdownFormatProvider provider = new Telerik.Windows.Documents.Flow.FormatProviders.Md.MarkdownFormatProvider();
using (Stream input = File.OpenRead("input.md"))
{
document = provider.Import(input, TimeSpan.FromSeconds(10));
}
The provider parses the Markdown content and builds a RadFlowDocument with the corresponding paragraphs, headings, tables, and inline formatting. Inline elements such as bold, italic, code, and strikethrough are mapped to the equivalent character properties in the document model.
Export
To export a RadFlowDocument to Markdown, create a MarkdownFormatProvider instance and call Export, passing the document and an output stream.
Example 2: Export to a File
Telerik.Windows.Documents.Flow.FormatProviders.Md.MarkdownFormatProvider provider = new Telerik.Windows.Documents.Flow.FormatProviders.Md.MarkdownFormatProvider();
RadFlowDocument document = CreateRadFlowDocument(); // CreateRadFlowDocument() is a custom method that creates a simple instance of RadFlowDocument. You can replace it with the instance you would like to export.
using (Stream output = File.OpenWrite("output.md"))
{
provider.Export(document, output, TimeSpan.FromSeconds(10));
}
The exporter traverses the document structure and writes the equivalent Markdown constructs. Heading styles are mapped to ATX-style heading markers (#–######), tables are rendered as GitHub-Flavored Markdown pipe tables, and lists are written with the appropriate indentation.