mity/md4c
FreeC Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
FreeFree tier
About mity/md4c
MD4C is a C Markdown parser library compliant with the CommonMark specification (version 0.31). It features a fast, compact, single-file implementation with a SAX-like callback interface (push model) for processing blocks, spans, and text. It supports commonly requested Markdown extensions, UTF-8 (and UTF-16 on Windows) encoding, and portability across Windows and POSIX systems. The library has no dependencies beyond the C standard library and is licensed under the MIT license. For HTML conversion, the companion md4c-html library provides an md_html() function that outputs HTML via callbacks.
Key Features
Compliant to CommonMark specification (version 0.31)
Supports commonly requested Markdown extensions
Very fast performance
Compact: implemented in one source file and one header file
No dependencies other than standard C library
Easy to embed with a single main function md_parse()
SAX-like push model: callback functions for blocks, spans, and text
Portable: builds on Windows and POSIX systems
UTF-8 encoding by default; can be compiled for ASCII-only or UTF-16 (Windows)
Permissive MIT license
Pros & Cons
Pros
- Fully compliant to CommonMark 0.31 ensuring standard Markdown behavior
- Very fast parse speed compared to other C Markdown parsers
- Minimal footprint: single source and header file with no external dependencies
- Easy integration via the straightforward md_parse() API and callback mechanism
- Supports UTF-8 and UTF-16 encodings for international text
- Portable across major operating systems
- Permissive MIT license allows use in proprietary projects
- Includes a dedicated HTML conversion helper (md4c-html)
Cons
- Requires a C compiler and C standard library to build and use
- Not a standalone application; must be integrated into a larger program
- HTML conversion relies on the separate md4c-html library (though included in the source)
- Callback-based interface may require more boilerplate code for simple use cases
Best For
Parsing Markdown documents in C/C++ applicationsConverting Markdown to HTML for static site generators or documentation toolsEmbedding Markdown parsing in software with custom rendering needsBuilding custom Markdown renderers or editors
FAQ
What is MD4C?
MD4C stands for 'Markdown for C'. It is a C library for parsing Markdown documents, compliant with the CommonMark specification and supporting several extensions.
How do I convert Markdown to HTML using MD4C?
You can use the md_html() function from the md4c-html library. It takes the Markdown input and a callback, and feeds chunks of HTML output to that callback.
What license does MD4C use?
MD4C is available under the MIT license, which is permissive and allows reuse in both open source and proprietary projects.
Does MD4C support UTF-8?
Yes, by default MD4C expects UTF-8 encoding. It can also be compiled to support UTF-16 (on Windows) or ASCII-only control characters.