GitHub's fork of cmark, a CommonMark parsing and rendering library and program in C
Go to file
Bas Alberts 587a12bb54
Merge pull request #343 from github/anticomputer-bump-version-
Changelog and version bump for
2023-07-21 11:19:43 -04:00
.github/workflows Create codeql.yml 2023-06-21 08:04:26 -04:00
api_test Fix format specifier for printing a size_t 2023-07-14 11:42:25 +01:00
bench Added 'make newbench'. 2016-12-06 10:56:59 +01:00
data Update CaseFolding to latest (#168) 2016-12-03 22:18:48 +01:00
extensions Merge pull request #273 from waldyrious/marker-vs-delimiter 2023-07-20 12:15:27 -04:00
fuzz Add other output formats to the quadratic fuzzer. 2023-04-06 12:21:32 +01:00
man man: Switch --safe option for --unsafe in man page 2022-01-17 16:50:25 -08:00
src Merge pull request #336 from ioquatix/expose-footnote-def-literal 2023-07-20 12:14:55 -04:00
test Merge pull request #273 from waldyrious/marker-vs-delimiter 2023-07-20 12:15:27 -04:00
tools Use up-to-date clang-format. 2022-11-10 15:18:54 +00:00
wrappers Merge branch 'upstream-master' 2019-02-05 13:46:54 +11:00
.editorconfig Use clang-format, llvm style, for formatting. 2015-07-27 21:35:54 -07:00
.gitignore Remove bogus file 2022-11-01 17:45:53 +00:00
.travis.yml Add static-only build to Travis test matrix 2017-11-18 16:16:01 +01:00
CMakeLists.txt Changelog and version bump for 2023-07-20 12:19:53 -04:00
COPYING COPYING: Update file name and remove duplicate section 2016-08-21 12:00:00 -04:00
CheckFileOffsetBits.c Add automatic configuration of compiler to get large file support (#138) 2019-03-13 10:53:08 +11:00
CheckFileOffsetBits.cmake Add automatic configuration of compiler to get large file support (#138) 2019-03-13 10:53:08 +11:00
FindAsan.cmake Added 'Asan' build type. 2015-02-19 10:34:34 -08:00
Makefile Use up-to-date clang-format. 2022-11-10 15:18:54 +00:00
Makefile.nmake Normalise header and define names (#109) 2018-08-21 11:58:41 +10:00 Added Actions CI badge. 2021-08-23 14:35:47 -04:00
appveyor.yml Correct path to artifact (#173) 2019-09-05 11:21:42 +10:00 Updated benchmarks. 2015-07-14 16:04:49 -07:00
changelog.txt Changelog and version bump for 2023-07-20 12:19:53 -04:00
nmake.bat Add Makefile and wrapper for nmake 2014-11-16 22:42:27 +01:00
suppressions Table extension from c068469 reworked 2017-06-30 12:03:34 +10:00
toolchain-mingw32.cmake Strip extensions API down and separate from core 2017-06-30 12:03:34 +10:00 Documented another strange hoedown behavior. 2015-12-13 08:20:42 -08:00


Actions CI

cmark-gfm is an extended version of the C reference implementation of CommonMark, a rationalized version of Markdown syntax with a spec. This repository adds GitHub Flavored Markdown extensions to the upstream implementation, as defined in the spec.

The rest of the README is preserved as-is from the upstream source. Note that the library and binaries produced by this fork are suffixed with -gfm in order to distinguish them from the upstream.

It provides a shared library (libcmark) with functions for parsing CommonMark documents to an abstract syntax tree (AST), manipulating the AST, and rendering the document to HTML, groff man, LaTeX, CommonMark, or an XML representation of the AST. It also provides a command-line program (cmark) for parsing and rendering CommonMark documents.

Advantages of this library:

  • Portable. The library and program are written in standard C99 and have no external dependencies. They have been tested with MSVC, gcc, tcc, and clang.

  • Fast. cmark can render a Markdown version of War and Peace in the blink of an eye (127 milliseconds on a ten year old laptop, vs. 100-400 milliseconds for an eye blink). In our benchmarks, cmark is 10,000 times faster than the original, and on par with the very fastest available Markdown processors.

  • Accurate. The library passes all CommonMark conformance tests.

  • Standardized. The library can be expected to parse CommonMark the same way as any other conforming parser. So, for example, you can use commonmark.js on the client to preview content that will be rendered on the server using cmark.

  • Robust. The library has been extensively fuzz-tested using american fuzzy lop. The test suite includes pathological cases that bring many other Markdown parsers to a crawl (for example, thousands-deep nested bracketed text or block quotes).

  • Flexible. CommonMark input is parsed to an AST which can be manipulated programmatically prior to rendering.

  • 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.

  • Free. BSD2-licensed.

It is easy to use libcmark in python, lua, ruby, and other dynamic languages: see the wrappers/ subdirectory for some simple examples.

There are also libraries that wrap libcmark for Go, Haskell, Ruby, Lua, Perl, Python, R, Tcl, Scala and Node.js.


Building the C program (cmark) and shared library (libcmark) requires cmake. If you modify, then you will also need re2c >= 0.14.2, which is used to generate scanners.c from We have included a pre-generated scanners.c in the repository to reduce build dependencies.

If you have GNU make, you can simply make, make test, and make install. This calls cmake to create a Makefile in the build directory, then uses that Makefile to create the executable and library. The binaries can be found in build/src. The default installation prefix is /usr/local. To change the installation prefix, pass the INSTALL_PREFIX variable if you run make for the first time: make INSTALL_PREFIX=path.

For a more portable method, you can use cmake manually. cmake knows how to create build environments for many build systems. For example, on FreeBSD:

mkdir build
cd build
cmake ..  # optionally: -DCMAKE_INSTALL_PREFIX=path
make      # executable will be created as build/src/cmark
make test
make install

Or, to create Xcode project files on OSX:

mkdir build
cd build
cmake -G Xcode ..
open cmark.xcodeproj

The GNU Makefile also provides a few other targets for developers. To run a benchmark:

make bench

For more detailed benchmarks:

make newbench

To run a test for memory leaks using valgrind:

make leakcheck

To reformat source code using clang-format:

make format

To run a "fuzz test" against ten long randomly generated inputs:

make fuzztest

To do a more systematic fuzz test with american fuzzy lop:

AFL_PATH=/path/to/afl_directory make afl

Fuzzing with libFuzzer is also supported but, because libFuzzer is still under active development, may not work with your system-installed version of clang. Assuming LLVM has been built in $HOME/src/llvm/build the fuzzer can be run with:

CC="$HOME/src/llvm/build/bin/clang" LIB_FUZZER_PATH="$HOME/src/llvm/lib/Fuzzer/libFuzzer.a" make libFuzzer

To make a release tarball and zip archive:

make archive

Installing (Windows)

To compile with MSVC and NMAKE:


You can cross-compile a Windows binary and dll on linux if you have the mingw32 compiler:

make mingw

The binaries will be in build-mingw/windows/bin.


Instructions for the use of the command line program and library can be found in the man pages in the man subdirectory.


By default, the library will scrub raw HTML and potentially dangerous links (javascript:, vbscript:, data:, file:).

To allow these, use the option CMARK_OPT_UNSAFE (or --unsafe) with the command line program. If doing so, we recommend you use a HTML sanitizer specific to your needs to protect against XSS attacks.


There is a forum for discussing CommonMark; you should use it instead of github issues for questions and possibly open-ended discussions. Use the github issue tracker only for simple, clear, actionable issues.


John MacFarlane wrote the original library and program. The block parsing algorithm was worked out together with David Greenspan. Vicent Marti optimized the C implementation for performance, increasing its speed tenfold. Kārlis Gaņģis helped work out a better parsing algorithm for links and emphasis, eliminating several worst-case performance issues. Nick Wellnhofer contributed many improvements, including most of the C library's API and its test harness.