Fast, accurate GitHub Flavored Markdown parser and renderer

Version on this page:0.1.8
LTS Haskell 13.25:0.1.8
Stackage Nightly 2019-06-12:0.2.0
Latest on Hackage:0.2.0

See all snapshots cmark-gfm appears in

BSD-3-Clause licensed by Ashe Connor
Maintained by

Module documentation for 0.1.8


This package provides Haskell bindings for libcmark-gfm, the reference parser for GitHub Flavored Markdown, a fully specified variant of Markdown. It includes sources for libcmark-gfm and does not require prior installation of the C library.

cmark provides the following advantages over existing Markdown libraries for Haskell:

  • Speed: cmark can render a Markdown version of War and Peace in the blink of an eye. Conversion speed is on par with the sundown library, though we were unable to benchmark precisely, because sundown raised a malloc error when compiled into our benchmark suite. Relative to other Haskell Markdown libraries: cmark was 82 times faster than cheapskate, 59 times faster than markdown, 105 times faster than pandoc, and 3 times faster than discount.

  • Memory footprint: Memory footprint is on par with sundown. On one sample, the library uses a fourth the memory that markdown uses, and less than a tenth the memory that pandoc uses.

  • Robustness: cmark can handle whatever is thrown at it, without the exponential blowups in parsing time that sometimes afflict other libraries. (The input bench/, for example, causes both pandoc and markdown to grind to a halt.) libcmark-gfm has been extensively fuzz-tested.

  • Accuracy: cmark passes the CommonMark spec’s suite of over 600 conformance tests.

  • Standardization: Since there is a spec and a comprehensive suite of tests, we can have a high degree of confidence that any two CommonMark implementations will behave the same. Thus, for example, one could use this library for server-side rendering and commonmark.js for client-side previewing.

  • Multiple renderers. Output in HTML, groff man, LaTeX, CommonMark, and a custom XML format is supported. And it is easy to write new renderers to support other formats.

  • Ease of installation: cmark is portable and has minimal dependencies.

cmark-gfm does not provide Haskell versions of the whole libcmark-gfm API, which is built around mutable cmark_node objects. Instead, it provides functions for converting CommonMark to HTML (and other formats), and a function for converting CommonMark to a Node tree that can be processed further using Haskell.

A note on stability: There is a good chance the API will change significantly after this early release.


cmark-gfm 0.2.0 (8 Apr 2019)

* Pull in upstream changes.

cmark 0.6 (08 Apr 2019)

* Update to cmark 0.29.0.
* Export optUnsafe. Note that the default is now to suppress
potentially unsafe HTML; set optUnsafe to return to the old behavior.

cmark-gfm 0.1.8 (14 Mar 2019)

* Pull in upstream changes.

cmark (13 Mar 2019)

* Use snoc instead of <> to add the null terminator.

cmark (13 Mar 2019)

* Ensure that withtext adds a null terminator (#14).
This fixes a regression due to PR #13, which caused
random content to appear in rendered TEXT nodes.

cmark-gfm 0.1.7 (13 Mar 2019)

* Update to cmark-gfm 0.28.3.gfm.20.

cmark (11 Mar 2019)

* Fix CString memory leaks (Anders Kaseorg). The renderer functions return
a malloc’d string which the caller is expected to free.

* Fix use-after-free bugs (Anders Kaseorg). `useAsCString` frees the
CString after the IO action finishes executing, so passing `return` as
that action can never be correct. To make sure the CString gets freed
at the right time, we need a “with”-style abstraction, not just a
conversion function. While we’re here replace this with
`withCStringLen`, which also makes fewer copies.

* Show node type on error for unknown node type.

cmark-gfm 0.1.6 (17 Oct 2018)

* Update to cmark-gfm 0.28.3.gfm.18.
* `optUnsafe` is now exposed, instead of `optSafe`.

cmark-gfm 0.1.5 (21 Aug 2018)

* Update to cmark-gfm 0.28.3.gfm.15.
* Fix build with system cmark-gfm (Felix Yan, #9).

cmark-gfm 0.1.4 (2 Jul 2018)

* Extensions work correctly on big-endian systems (Ilias Tsitsimpis).

cmark-gfm 0.1.3 (10 Aug 2017)

* Update to cmark-gfm 0.28.0.gfm.6.

cmark-gfm 0.1.2 (09 Aug 2017)

* Update to cmark-gfm 0.28.0.gfm.5.

cmark-gfm 0.1.1 (03 Aug 2017)

* Automatically register plugins.
* Rename alignment values to not clash with `None`, `Left`.
* Fix a potential use-after-free.

cmark-gfm 0.1.0 (03 Aug 2017)

* Update to cmark-gfm (between revisions).
* Add extension support.

cmark 0.5.6 (02 Aug 2017)

* Update to cmark 0.28.0.

cmark (20 Mar 2017)

* Update version bound for HUnit.

cmark 0.5.5 (31 Jan 2017)

* Update to cmark 0.27.1.
* Update version bounds for dependencies.

cmark 0.5.4 (18 Nov 2016)

* Update to cmark 0.27.0.

cmark (16 Jul 2016)

* Remove unnecessary typedef that caused problems with the build
(patch from upstream).

cmark 0.5.3 (15 Jul 2016)

* Update to cmark 0.26.0.
* Added appveyor CI.

cmark (22 May 2016)

* New .travis.yml - test with stack, cabal on many versions.
* Increase upper bound of base (Utku Demir).

cmark 0.5.2 (26 Mar 2016)

* Add flag to allow building with an installed libcmark (Jens Petersen).
* Updated to libcmark 0.25.2.

cmark 0.5.1 (21 Jan 2016)

* Updated to libcmark 0.24.1.

cmark 0.5 (29 Dec 2015)

* Updated to libcmark 0.23.0.
* API changes:
+ Added `OnEnter` and `OnExit` types.
+ In `NodeType`, `HRULE` is now `THEMATIC_BREAK`,
constructors: `CUSTOM_INLINE`, `CUSTOM_BLOCK`.

cmark 0.4.1 (23 Aug 2015)

* Updated to libcmark 0.22.0.
* Bumped version bounds for HUnit.

cmark (14 Jul 2015)

* API changes:
+ Added `commonmarkToLaTeX`, `nodeToLaTeX`, `optSafe`.
+ Changed type of `commonmarkToMan` and `nodeToMan`,
adding `Maybe Int` param for width.
+ Changed type of `nodeToCommonMark`, changing the `Int` width
parameter to a `Maybe Int`.
* Updated to cmark 0.21 sources.

cmark 0.3.4 (08 Jun 2015)

* Updated to libcmark 0.20.0.

cmark (28 May 2015)

* Changed name Bench.hs -> bench-cmark.hs.
* Benchmark: don't benchmark pandoc (circular dependency).

cmark 0.3.3 (26 May 2015)

* Added `nodeToHtml`, `nodeToMan`, `nodeToXml`.
* Added version bounds for text (Albert Krewinkel).

cmark 0.3.2 (28 Apr 2015)

* Updated libcmark C sources to 0.19.0.
* Fixes to avoid warning for earlier ghc versions.
* Refactored, removing the `io` convenience function.
* Removed unnecessary `unsafePerformIO` on `fromtext`.
* `fromtext`: use `ByteString.useAsCString` + explicit `encodeUtf8`.

cmark 0.3.1 (29 Mar 2015)

* Added nodeToCommonmark.
* Removed mtl from build-depends.
* Updated source info in README, cabal.
* Updated C sources.
* Put all the C functions in the IO monad, and ensure
that memory allocated by the C library is freed
at the right time.
* Added a rudimentary test suite.
* Properly free c-allocated resources.
* Removed bindings to nonexistent setters for source pos
Depends on 3 packages:
Used by 3 packages:
comments powered byDisqus