Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Markdown to HTML in .NET

How can I convert markdown into html in .NET?

var markdown = "Some **bold** text";
var output = ConvertMarkdownToHtml(markdown)
// Output: <p>Some <strong>bold</strong> text</p>

I have Markdown text stored in a database that needs to be converted to html when it is displayed.

I know about StackOverflow's WMD Editor (now PageDown), but that only converts client-side.

like image 434
Spoike Avatar asked Jan 20 '09 08:01

Spoike


People also ask

How do I convert Markdown to HTML?

To convert Markdown to HTML using Typora, click File —> Export —> HTML. Then save the file in your preferred location. The image below shows that the HTML output looks exactly as how the Markdown is displayed inside Typora.

Can I use Markdown in HTML?

Originally created to make writing XHTML/HTML easier by converting plain-text files into structurally valid HTML or XHTML, Markdown can be used for almost any type of writing: manuscripts, tutorials, notes, web content and more.

Is Markdown same as HTML?

Markdown is easier to write than HTML, and it's easier for most humans to read Markdown source than HTML source. However, HTML is more expressive (particularly regarding semantic tagging) and can achieve some specific effects that might be difficult or impossible in Markdown.

Do web browsers support Markdown?

Despite their visual differences, all of the applications do the same thing. Like Dillinger, they all convert Markdown-formatted text to HTML so it can be displayed in web browsers.


2 Answers

TL;DR: now it's 2021 use markdig

I just came across this questions and the answers are all quite old. It appears that implementations based on commonmark are the suggested way to go now. Implementations for lots of languages (including C#) can be found here

like image 195
Matt Keen Avatar answered Sep 22 '22 15:09

Matt Keen


Another implementation that seems to be gaining ground is MarkdownDeep

This is a full implementation for both C# and JavaScript. The MarkdownHelper on Nuget is using MarkdownDeep now instead of MarkdownSharp.

I've used both and MarkdownDeep seems to be more fully functional and having the JavaScript version is great for quick client side setups.

like image 25
Bil Simser Avatar answered Sep 20 '22 15:09

Bil Simser