Markdown

Markdown is a lightweight markup language with plain text formatting syntax. Its design allows it to be converted to many output formats, but the original tool by the same name only supports HTML. Markdown is often used to format README files, for writing messages in online discussion forums, and to create rich text using a plain text editor.

Wikipedia

Options

Here are the Markdown options we investigated.

Package Version
Markdig 0.16.0
Markdown 2.2.1
MarkdownSharp 2.0.5

Use Cases

Converting a Markdown file to html

Code

Copy

var markdownFile = "./facts/minimal.md";
var text = File.ReadAllText(markdownFile);
var html = Markdown.ToHtml(text);

Console.WriteLine(html);

Copy

var markdownFile = "./facts/minimal.md";
var text = File.ReadAllText(markdownFile);
var html = new Markdown().Transform(text);

Console.WriteLine(html);

Copy

var markdownFile = "./facts/minimal.md";
var text = File.ReadAllText(markdownFile);
var html = new Markdown().Transform(text);

Console.WriteLine(html);

Converting a Markdown string to html

Code

Copy

var markdownString = "# 3-Minute Markdown Overview\n\n"
    + "Markdown consists of two types of lexical constructs: inlines and blocks.\n";
var html = Markdown.ToHtml(markdownString);

Console.WriteLine(html);

Copy

var markdownString = "# 3-Minute Markdown Overview\n\n"
    + "Markdown consists of two types of lexical constructs: inlines and blocks.\n";
var html = new Markdown().Transform(markdownString);

Console.WriteLine(html);

Copy

var markdownString = "# 3-Minute Markdown Overview\n\n"
    + "Markdown consists of two types of lexical constructs: inlines and blocks.\n";
var html = new Markdown().Transform(markdownString);

Console.WriteLine(html);

Parsing markdown into a syntax tree

Code

Copy

var markdownFile = "./facts/minimal.md";
var text = File.ReadAllText(markdownFile);
MarkdownDocument doc = Markdown.Parse(text);
foreach (var block in doc) {
    Console.WriteLine($"Block type: {block.GetType().Name}");
}
Not available with this option
Not available with this option