commonmark/cmark logo

commonmark/cmark

Free

CommonMark parsing and rendering library and program in C

FreeFree tier
Type
Open Source

About commonmark/cmark

cmark is the C reference implementation of CommonMark, a standardized version of Markdown syntax. It provides a shared library (libcmark) for parsing CommonMark documents into an abstract syntax tree (AST), manipulating the AST, and rendering to HTML, groff man, LaTeX, CommonMark, or XML. It also includes a command-line program (cmark). The library is written in standard C99 with no external dependencies, making it highly portable. cmark is extremely fast, passing all CommonMark conformance tests, and has been extensively fuzz-tested for robustness. It supports multiple renderers and is BSD2-licensed. Wrappers exist for Python, Lua, Ruby, and other languages, with additional libraries for Go, Haskell, Ruby, and more.

Key Features

Parses CommonMark documents to an abstract syntax tree (AST)
Renders to HTML, groff man, LaTeX, CommonMark, and XML
Command-line program for parsing and rendering
Portable: written in standard C99 with no external dependencies
Fast: benchmarks show 127ms for War and Peace on a ten-year-old laptop
Accurate: passes all CommonMark conformance tests
Standardized: parses CommonMark consistently with other conforming parsers
Robust: extensively fuzz-tested with american fuzzy lop
Flexible: AST can be manipulated programmatically before rendering
Multiple output formats supported via renderers

Pros & Cons

Pros
  • Extremely fast performance (comparable to fastest Markdown processors)
  • High accuracy (passes all CommonMark conformance tests)
  • Portable across platforms and compilers (MSVC, gcc, tcc, clang)
  • Robust and well-tested (fuzzing and pathological cases)
  • Flexible AST manipulation enables custom processing
  • Multiple output formats built-in (HTML, man, LaTeX, CommonMark, XML)
  • BSD2 license allows unrestricted use and modification
Cons
  • Only supports CommonMark specification, not other Markdown flavors
  • C library may be less accessible for web developers compared to JavaScript alternatives
  • Requires C knowledge for extending or building custom renderers
  • Command-line tool lacks some user-friendly features of higher-level tools

Best For

Embedding CommonMark parsing and rendering in C programsBuilding static site generators or documentation tools that convert Markdown to HTMLServer-side Markdown rendering with consistent output for client-side preview using commonmark.jsConverting CommonMark documents to LaTeX for academic publishingGenerating groff man pages from Markdown sourceCreating custom renderers for additional output formatsTesting other CommonMark implementations for conformanceBuilding command-line tools for Markdown processing

FAQ

What is cmark?
cmark is the C reference implementation of CommonMark, a rationalized version of Markdown syntax with a spec.
What output formats does cmark support?
cmark can render CommonMark documents to HTML, groff man, LaTeX, CommonMark, and XML.
Is cmark portable?
Yes, cmark is written in standard C99 and has no external dependencies. It has been tested with MSVC, gcc, tcc, and clang.
How fast is cmark?
cmark can render a Markdown version of War and Peace in 127 milliseconds on a ten-year-old laptop, making it 10,000 times faster than original Markdown.pl and on par with the fastest Markdown processors.
Does cmark pass the CommonMark spec?
Yes, cmark passes all CommonMark conformance tests.
What license does cmark use?
cmark is BSD2-licensed (free and open source).
Can I use cmark from other programming languages?
Yes, there are wrappers for Python, Lua, Ruby, and other dynamic languages in the wrappers subdirectory, and third-party libraries for Go, Haskell, Ruby, Lua, Perl, Python, R, Scala, and PHP.