What is Markdown?

Markdown is a popular way to create content on the web. It is a very simple set of formatting rules to format words as bold or italic, adding images and to create lists. Many developers use Markdown for documentation files for repositories like in GitHub, Gists and readme files.

The popular NuGet package Markdig is able to parse Markdown content in order to create clean HTML. The project is also hosted on GitHub:

Markdig

In this sample, we utilize this package to convert the plain text Markdown content of a TextControl TX Text Control .NET for Windows Forms
TXTextControl Namespace
TextControl Class
The TextControl class implements a Windows Forms control with high-level text editing features.
to convert it to HTML that is loaded into a second TextControl.

Markdown in TX Text Control

Thanks to the clean output of the Markdown parser, it is very easy to style the various stylesheet elements within TX Text Control. This way, you can create pixel-perfect documents such as Adobe PDF from your Markdown content.

LoadMarkdown Extension Method

The sample implements the extension method LoadMarkdown for TX Text Control to load Markdown directly:

textControl2.LoadMarkdown(textControl1.Text);
view raw startup.cs hosted with ❤ by GitHub

The implementation of this method is shown below:

public static class TextControlExtensions
{
public static void LoadMarkdown(this TXTextControl.TextControl textControl,
string markdown)
{
textControl.Load(ParseMarkdown(markdown), TXTextControl.StringStreamType.HTMLFormat);
}
private static string ParseMarkdown(string markdownInput)
{
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
return Markdown.ToHtml(markdownInput, pipeline);
}
}
view raw api.cs hosted with ❤ by GitHub

You can download the Windows Forms sample from our GitHub repository below. This concept is not limited to Windows Forms, but can be used with all TX Text Control versions.