cmark is the C reference implementation of CommonMark. It provides libcmark to parse Markdown to an AST and render HTML, man, LaTeX, CommonMark, or XML, plus a cmark command-line tool.
Overview
cmark implements the CommonMark specification as a portable C99 library with no external dependencies. Applications link libcmark to parse documents into an abstract syntax tree, modify the tree, and emit several output formats.
Supported render targets include HTML, groff man, LaTeX, CommonMark, and a custom XML representation of the AST. The standalone cmark program offers the same parsing and rendering from the shell for scripting and batch use.
The parser is designed for speed, conformance to CommonMark tests, and predictable behavior matching other spec-compliant implementations such as commonmark.js for client-server preview pairs. By default it scrubs raw HTML and dangerous link schemes; an unsafe mode exists for trusted pipelines.
Wrappers and bindings exist for Python, Lua, Ruby, Go, Haskell, Perl, R, Scala, PHP, and other languages. Builds use CMake or GNU make on Unix-like systems and MSVC nmake on Windows, with optional cross-compile to Windows from Linux.
Key features
- CommonMark spec reference parser
- AST parse manipulate render pipeline
- HTML man LaTeX and XML output
- Command-line cmark program
- Default unsafe HTML and link scrubbing
- Language bindings via wrappers
- Fuzz-tested robust parsing
Use cases
- Spec-compliant Markdown rendering
- Server-side HTML from CommonMark
- Embedding Markdown in C applications
- Cross-language CommonMark consistency