
As a C# developer, converting rich‑text content into lightweight formats is a common requirement. This article shows how to extract rich text and automatically transform it into Markdown syntax using the Conholdate.Total for .NET library. Follow the step‑by‑step guide to integrate this capability into any C# application.
User Story:
As a C# developer building a content‑management system, I need to let users enter rich text and then convert that content into Markdown. Markdown provides a simple, portable format that can be stored, displayed, or further processed with ease. The steps below demonstrate how to achieve this conversion with Conholdate.Total for .NET.
Step 1: Installing Conholdate.Total for .NET
Obtain the Conholdate.Total for .NET library. You can download it from the official Conholdate website or add it directly via NuGet:
Install-Package Conholdate.Total
Step 2: Initializing the Library
After the package is installed, add the necessary using directives and configure any required settings. This prepares the library for use in your project and ensures all dependencies are correctly referenced.
Step 3: Loading the Rich Text Document
Load the source document that contains the rich text you want to convert. The library supports a wide range of formats—including DOCX, RTF, HTML, and many others—so the source can be a file on disk, a database BLOB, or a dynamically generated stream. See the full list of supported formats in the supported file formats documentation.
Step 4: Extracting Rich Text Content
Use Conholdate.Total to read the document’s formatted content. The API provides methods to access paragraphs, headings, styles, and other structural elements.
To retrieve the formatted text, call the GetFormattedText method:
TextReader GetFormattedText(FormattedTextOptions options);
Step 5: Converting Rich Text to Markdown
Create a FormattedTextOptions instance and set its mode to FormattedTextMode.Markdown. This tells the parser to output Markdown instead of plain text or HTML.
FormattedTextOptions(FormattedTextMode.Markdown)
Implementation steps:
- Instantiate a Parser for the source document.
- Create a FormattedTextOptions object with
FormattedTextMode.Markdown. - Invoke
GetFormattedTextto receive a TextReader containing the Markdown. - Read the text from the reader if it is not
null.
Example code:
// Create an instance of Parser class
using (Parser parser = new Parser("sample.docx"))
{
// Extract formatted text into the reader
using (TextReader reader = parser.GetFormattedText(new FormattedTextOptions(FormattedTextMode.Markdown)))
{
// Output the formatted text or indicate unsupported extraction
Console.WriteLine(reader == null ? "Formatted text extraction isn't supported" : reader.ReadToEnd());
}
}
Step 6: Presenting the Converted Markdown
Once the conversion is complete, you can display the Markdown to the user in several ways:
- Show a live preview in a web view or desktop control.
- Save the output to a
.mdfile for later use. - Load the text into a Markdown editor for further editing.
Input:
Suppose the input file contains the following content:

Output:
The resulting Markdown will be:
**Rich Text**
Lorem ipsum **dolor sit amet**, consectetuer adipiscing elit. Maecenas porttitor congue massa. *Fusce posuere*, magna sed pulvinar ultricies, *purus lectus malesuada libero*, sit amet commodo magna eros quis urna.
1. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.
2. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
3. Proin pharetra nonummy pede. Mauris et orci.
Aenean nec lorem
* In porttitor. Donec laoreet nonummy augue.
* Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc.
* Mauris eget neque at sem venenatis eleifend. Ut nonummy.
Summing Up
You have now completed the user story of extracting rich text and converting it to Markdown syntax in C# with Conholdate.Total for .NET. The library abstracts the complexity of format handling, allowing you to focus on delivering rich‑text editing and Markdown output in your applications. Happy coding!
Conholdate.Total for .NET Resources:
Please refer to the following resources to further explore the library:
Get a Free License:
You can download a free temporary license to test the library without evaluation limitations.
Ask a Question:
Post your questions or comments about the library in this forum.