MarkdownSpecialised needs
Markdown is a popular text markup format, used on Stackoverflow, Github, and in many other places (including this guide). Markdown doesn't have a strict specification, and all libraries implement it differently; to see how listed libraries (well, some of them) work on various outputs, use Babelmark.
Code highlighting
Unless noted otherwise, all libraries support code blocks with attributes, which makes code highlighting possible if used like this:
~~~ haskell
import Control.Monad
~~~
Some libraries (e.g. cheapskate) actually let you highlight the code in generated HTML, while others simply use the name of the language as a <div>
class (and then you have to use a library like highlight.js to highlight code blocks at the client side).
Recommendations
pandoc is very often used as a standalone Markdown converter (in Hakyll, for instance). It's very customisable and has tons of features. However, it's slower than other libraries, and shouldn't be used on untrustworthy input (because there are some inputs that take exponential time).
cheapskate is a smaller library, is often used for sites, and has a small ecosystem around it. cmark is another small library that implements a standardised version of Markdown – it's newer and thus used less often, but likely to become the standard Markdown library in the future, and so you might just as well start using it now. Anyway, both cheapskate and cmark are fine.
markdown can actually be fine too. It suffers from the same problem as pandoc (takes exponential time on some inputs), but it has a more customisable parser than cheapskate or cmark and sometimes it's useful.
If you want non-HTML output (e.g. LaTeX), then cmark and pandoc are your only options. If you want a really fast library, use cmark. If you want to modify the parser to suit your own needs, fork cheapskate or markdown.
A document converter that supports about 15 input formats (including Markdown). Has the most feature-rich Markdown dialect and can convert to the most number of formats. Not recommended for web (when Markdown is written by users and not by you), but very good for blogs, articles, slides/presentations, generating documentation, and so on.
-
Can convert to the most number of formats (including EPUB, docx, ODT, LaTeX, and other markup formats like Haddock, DocBook, MediaWiki markup, etc).
-
Has the most number of features – superscript/subscript/strikethrough, footnotes, tables, definition lists, math rendering, citations, code highlighting, table of contents generation, and so on.
-
The implementation doesn't use advanced Haskell features and can easily be modified (if you want to add features to your dialect of Markdown).
-
Scholdoc – a fork of Pandoc for academic writing
-
Filters: pandoc-include (for including contents of referenced files), pandoc-csv2table (for rendering CSV tables), pandoc-crossref (for numbering figures/tables and cross-referencing), pandoc-citeproc. A bigger list is on the Pandoc wiki.
A lightweight Markdown library from the author of Pandoc, implementing the CommonMark standard (which is just a more precisely specified version of Markdown). Can parse Markdown and convert it to various formats (including HTML).
Binds to a C library (libcmark), but doesn't require it to be installed – the sources are shipped with the Haskell package.
-
Very fast (the author's benchmarks: 82× faster than cheapskate, 59× faster than markdown, 105× faster than pandoc, 3× faster than discount).
-
Can deal with any input, including garbage, with linear performance. (Some Markdown parsers have quadratic complexity on some inputs, which gives an attacker an opportunity to slow down your site.)
-
Can render to several formats: apart from HTML, it also supports LaTeX, groff man, and a custom XML format.
-
The only library here that lets you get position info for parsed blocks.
-
Has a sibling Javascript library that implements the same specification (so that the results of client-side and server-side rendering would fully match).
-
Can't automatically recognise links (i.e. if you write
go to https://google.com
, the link won't be highlighted). -
Doesn't sanitize HTML output by default (you have to use xss-sanitize if you want that).
cmark-highlight (highlights code blocks)
Another lightweight Markdown library from the author of Pandoc. Unlike cmark, it's implemented in pure Haskell. Can parse Markdown and convert it to HTML.
-
Can deal with any input with linear performance.
-
HTML output is sanitized by default (to protect against XSS attacks).
cheapskate-terminal (renders to console), cheapskate-highlight (highlights code blocks), cheapskate-lucid
A library from Michael Snoyman (the author of Yesod). Can parse Markdown and convert it to HTML. Has additional features that make it good for publishing (you can customise the parser, for instance) but simultaneously can get stuck on some inputs and that's pretty bad (unless you explicitly implement a timeout or something like that).
-
Sanitizes input by default.
-
The parser can be customised to add new kinds of fencing in addition to
```
and~~~
– for instance,@@@
. Moreover, the contents can be parsed as Markdown as well (so you could set it up so that e.g.@@@
would mean “spoiler” or “important note”). -
Has an option for adding
target=_blank
to all links so that they'd open in new tabs.
<notes are empty>
Bindings to Github's (former) Markdown library, sundown. (The sources are bundled with the package, so the library doesn't need to be installed separately.) Can convert Markdown to HTML, but doesn't give access to parsed Markdown.
<notes are empty>
-
Supports tables, superscripts, strikethrough, footnotes.
-
Has some non-standard extensions too: definition lists, paragraph centering, specifying image sizes, and styling text (e.g.
[foo](class:bar)
would wrap “foo” into a<span>
tag withclass="bar"
and then you could apply CSS styling to it). -
Seems to be able to deal with any input with linear performance (since it renders this stress-test just fine).
-
Supports math in pages (with MathJax).
-
Can generate table of contents.
<notes are empty>