Markdig is a fast, powerful, CommonMark compliant, extensible Markdown processor for .NET.
Rendering HTML with MarkDig To convert the Markdown into HTML, I used the superb MarkDig library. This not only makes it super easy to convert basic Markdown. Markdig 0.24.0 A fast, powerful, CommonMark compliant, extensible Markdown processor for.NET with 20+ builtin extensions (pipetables, footnotes, definition lists. Apr 15, 2021 MarkDig uses a configuration pipeline of support features that you can add on top of the base parser. The.UseAdvancedExtensions method adds a number of common extensions (like GitHub-Flavored Markdown, List Extensions, etc.), but you can also add each of the components you want and customize exactly how you want Markdown to be parsed.
NOTE: The repository is under construction. There will be a dedicated website and proper documentation at some point!
You can try Markdig online and compare it to other implementations on babelmark3
#
of a headers with @
)~~
,~
^
++
http://
or https://
or ftp://
or mailto:
or www.xxx.yyy
a.
b.
and roman bullet (i
, ii
...etc.)'...'
(inspired by this CommonMark discussion ):::
for generating a proper <div>...</div>
instead (inspired by this CommonMark discussion )$$
for block and $
for inline math (inspired from this CommonMark discussion)mermaid
and nomnoml
diagrams)0.20.0+
, Markdig is compatible only with NETStandard 2.0
, NETStandard 2.1
, NETCoreApp 2.1
and NETCoreApp 3.1
.If you are looking for support for an old .NET Framework 3.5 or 4.0, you can download Markdig 0.18.3
.
The repository is under construction. There will be a dedicated website and proper documentation at some point!
While there is not yet a dedicated documentation, you can find from the specs documentation how to use these extensions.
In the meantime, you can have a 'behind the scene' article about Markdig in my blog post 'Implementing a Markdown Engine for .NET'
Markdig is available as a NuGet package:
Also Markdig.Signed NuGet package provides signed assemblies.
The main entry point for the API is the Markdig.Markdown
class:
By default, without any options, Markdig is using the plain CommonMark parser:
In order to activate most of all advanced extensions (except Emoji, SoftLine as HardLine, Bootstrap, YAML Front Matter, JiraLinks and SmartyPants)
You can have a look at the MarkdownExtensions that describes all actionable extensions (by modifying the MarkdownPipeline)
In order to build Markdig, you need to install .NET Core RTM
This software is released under the BSD-Clause 2 license.
This is an early preview of the benchmarking against various implementations:
C implementations:
.NET implementations:
JavaScript/V8 implementations:
Because Marked.NET, MarkdownSharp and DocAsCode.MarkdownLite are way too slow, they are not included in the following charts:
If you are using this library and find it useful for your project, please consider a donation for it!
Thanks to the fantastic work done by John Mac Farlane for the CommonMark specs and all the people involved in making Markdown a better standard!
This project would not have been possible without this huge foundation.
Thanks also to the project BenchmarkDotNet that makes benchmarking so easy to setup!
Some decoding part (e.g HTML EntityHelper.cs) have been re-used from CommonMark.NET
Thanks to the work done by @clarkd on the JIRA Link extension (https://github.com/clarkd/MarkdigJiraLinker), now included with this project!
Alexandre MUTEL aka xoofx
There are the folks who write YAML, and then there are the folks required to parse it. Let me assure you that the former is more natural than the latter. YAML, which stands for YAML Ain’t Markup Language, is a tricky syntax which promotes itself as a human-friendly data serialization standard for all programming languages.
What makes YAML tricky? The first audience for YAML is humans, not computers. The syntax aims to support constructs that can be hell to program for, with my favorite example being values that can either be a single value or an array across documents. The ambiguity of the syntax has spurred on multiple “YAML sucks” factions all over the world.
While the syntax can cause headaches, I still like YAML. YAML serves its purpose well in simple scenarios. This blog contains all post metadata in a terse front matter block.
In this post, you’ll see how we can use YAML.NET and Markdig to parse a blog post’s front matter.
We’ll first need to install two packages: YAML.NET and Markdig.
We will use Markdig to parse our blog posts, although we could also parse our files based on the standard convention of ---
separators and forgo Markdig altogether. For this post, we’ll use it to handle slight discrepancies that might creep in between files.
Jekyll powers this blog, a blog engine written in Ruby. It has a flexible front matter format that can adapt to the needs of the author and the theme applied to the blog. This blog post’s front matter looks something like this.
We represent all the values as string
values, including the tags
(a particular quirk of a paging plugin).
The first step we need to take is to create a class that represents our blog’s front matter. Note that many blogs will have different keys, and could vary from this example.
Once we have our front matter, we can create an extension method for our the Markdig MarkdownDocument
class. The class will be where we pull our YAML front matter from in the form of a YamlFrontMatterBlock
.
We need to remove the ---
separators from our YAML block, or else YAML.NET will throw an exception. Another critical element of our code is the inclusion of MarkDig’s YAML frontmatter extension.
Without the extension, we won’t see the YAML block in our parsed document.
Finally, we can call our extension method after reading our files from disk.
Running our code, we see the results of our front matter parser.
I hope this helped! Enjoy!