I’m pleased to announce as the first post on INN the release of MarkdownKit - a fully cross-platform CommonMark compliant Markdown parser for Xojo.
What does it do?
MarkdownKit essentially does one thing and does it well. It takes as input Markdown as a String
and returns HTML. It does this quickly and reliably. It’s 100% compliant with the 0.29 CommonMark specification.
Why might I use it?
Writing in Markdown has become incredibly popular, thanks to sites like GitHub, Ghost and even this forum’s software - Discourse. Perhaps you’d like to write a Markdown editor or you’d like to offer Markdown as a supported text format?
Example usage
Using MarkdownKit is very easy. Everything is contained within a single module named MarkdownKit
. Paste or drag the MarkdownKit
module into your project and use it like so:
Var md As String = "Some **bold** text and `code`"
Var html As String = MarkdownKit.ToHTML(md)
// `html` now contains:
// <p>Some <strong>bold</strong> text and <code>code</code></p>
Advanced usage
Out of the box, MarkdownKit
supports conversion of Markdown to HTML. However, I’ve designed MarkdownKit
in such a way as to make it output-agnostic by giving you access to the abstract syntax tree (AST) created during parsing:
Var ast As New MarkdownKit.Document("Some **bold** text")
// Parsing Markdown is done in two phases. First the block structure is
// determined and then inlines are parsed.
ast.ParseBlockStructure
ast.ParseInlines
// `ast` now contains the Abstract Syntax Tree and can be manipulated.
Why might you want to access the AST? Well, maybe you want to do something as simple as render every soft linebreak in a document as a hard linebreak. Perhaps you want to output the Markdown source as something other than HTML.
MarkdownKit
provides a class interface called IRenderer
which must be implemented by any custom renderer you write. The built-in MarkdownKit.HTMLRenderer
and MarkdownKit.ASTRenderer
classes are examples of renderers which implement this interface. Take a look at their well-documented methods to learn how to write your own renderer.
License
MarkdownKit is provided under the permissive MIT License and is therefore open source and you are free to use it in commercial applications.
Where can I find it?
As with all my open source projects, MarkdownKit has it’s own repository on GitHub.