Rust port of github's cmark-gfm.
Compliant with CommonMark 0.31.2 in default mode. GFM support synced with release 0.29.0.gfm.13.
Specify it as a requirement in Cargo.toml:
Comrak's library supports Rust 1.65+.
- Anywhere with a Rust toolchain:
- cargo install comrak
- Many Unix distributions:
- pacman -S comrak
- brew install comrak
- dnf install comrak
- nix run nixpkgs#comrak
You can also find builds I've published in GitHub Releases, but they're limited to machines I have access to at the time of making them! webinstall.dev offers curl | shell-style installation of the latest of these for your OS.
Click to expand the CLI --help output.And there's a Rust interface. You can use comrak::markdown_to_html directly:
Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter:
For a slightly more real-world example, see how I generate my GitHub user README from a base document with embedded YAML, which itself has embedded Markdown, or check out some of Comrak's dependents on crates.io or on GitHub.
As with cmark and cmark-gfm, Comrak will scrub raw HTML and potentially dangerous links. This change was introduced in Comrak 0.4.0 in support of a safe-by-default posture, and later adopted by our contemporaries. :)
To allow these, use the unsafe_ option (or --unsafe with the command line program). If doing so, we recommend the use of a sanitisation library like ammonia configured specific to your needs.
Comrak supports the five extensions to CommonMark defined in the GitHub Flavored Markdown Spec:
Comrak additionally supports its own extensions, which are yet to be specced out (PRs welcome!):
- Superscript
- Header IDs
- Footnotes
- Description lists
- Front matter
- Multi-line blockquotes
- Math
- Emoji shortcodes
- Wikilinks
- Underline
- Spoiler text
- "Greentext"
By default none are enabled; they are individually enabled with each parse by setting the appropriate values in the ExtensionOptions struct.
You can provide your own syntax highlighting engine.
Create an implementation of the SyntaxHighlighterAdapter trait, and then provide an instance of such adapter to Plugins.render.codefence_syntax_highlighter. For formatting a Markdown document with plugins, use the markdown_to_html_with_plugins function, which accepts your plugins object as a parameter.
See the syntax_highlighter.rs and syntect.rs examples for more details.
syntect is a syntax highlighting library for Rust. By default, comrak offers a plugin for it. In order to utilize it, create an instance of plugins::syntect::SyntectAdapter and use it in your Plugins option.
Comrak's design goal is to model the upstream cmark-gfm as closely as possible in terms of code structure. The upside of this is that a change in cmark-gfm has a very predictable change in Comrak. Likewise, any bug in cmark-gfm is likely to be reproduced in Comrak. This could be considered a pro or a con, depending on your use case.
The downside, of course, is that the code often diverges from idiomatic Rust, especially in the AST's extensive use of RefCell, and while contributors have made it as fast as possible, it simply won't be as fast as some other CommonMark parsers depending on your use-case. Here are some other projects to consider:
- Raph Levien's pulldown-cmark. It's very fast, uses a novel parsing algorithm, and doesn't construct an AST (but you can use it to make one if you want). cargo doc uses this, as do many other projects in the ecosystem.
- markdown-rs (1.x) looks worth watching.
- Know of another library? Please open a PR to add it!
As far as I know, Comrak is the only library to implement all of the GitHub Flavored Markdown extensions rigorously.
- comrak (Python package) — Python bindings for this library built with PyO3. Available on PyPI as comrak, benchmarked at 15-60x faster than pure Python alternatives.
- commonmarker - Ruby bindings for this library built with Magnus/rb-sys. Available on RubyGems as commonmarker.
You'll need to install hyperfine, and CMake if you want to compare against cmark-gfm.
If you want to just run the benchmark for the comrak binary itself, run:
This will build Comrak in release mode, and run benchmark on it. You will see the time measurements as reported by hyperfine in the console.
The Makefile also provides a way to run benchmarks for comrak current state (with your changes), comrak main branch, cmark-gfm, pulldown-cmark and markdown-it.rs. You'll need CMake, and ensure submodules are prepared.
This will build and run benchmarks across all, and report the time taken by each as well as relative time.
Contributions are highly encouraged; if you'd like to assist, consider checking out the good first issue label! I'm happy to help provide direction and guidance throughout, even if (especially if!) you're new to Rust or open source.
Where possible I practice Optimistic Merging as described by Peter Hintjens. Please keep the code of conduct in mind too.
Thank you to Comrak's many contributors for PRs and issues opened!
Become a financial contributor and help sustain Comrak's development. I'm self-employed — open-source software relies on the collective.
Asherah Connor <ashe kivikakk ee>
Copyright (c) 2017–2025, Comrak contributors. Licensed under the 2-Clause BSD License.
cmark itself is is copyright (c) 2014, John MacFarlane.
See COPYING for all the details.
.png)

