MD4C, the fast CommonMark / GFM Markdown parser for C, through C++23 modules.
English · 简体中文 · Upstream · Releases · mcpp · Index
The upstream C API is unchanged: md_parse, MD_PARSER, MD_BLOCK_*, md_html
are the upstream globals. The parser is compat.md4c 0.5.3; this package adds
upstream's second library, the md4c-html renderer, and maps the MD_FLAG_*
macros to constants. Upstream's own test suites (CommonMark 0.31.2 spec, GFM
extensions, regressions: 808 examples) pass through the module on every CI run.
import mcpplibs.mwrap.md4c;: the parser API (md_parse, callbacks, details), re-exporting the two belowimport mcpplibs.mwrap.md4c.html;:md_html, Markdown straight to HTMLimport mcpplibs.mwrap.md4c.macros;:MD_FLAG_*,MD_DIALECT_*,MD_HTML_FLAG_*inmcpplibs::mwrap::md4c::macros
More Modules API -> Usage and API
mcpp new notes --template mcpplibs.mwrap.md4c@0.5.3
cd notes
mcpp runThe default template renders a document with GitHub's extensions to HTML and
prints the outline of its headings from the md_parse callbacks.
[dependencies]
"mcpplibs.mwrap.md4c" = "0.5.3"import std;
import mcpplibs.mwrap.md4c;
namespace macros = mcpplibs::mwrap::md4c::macros;
int main() {
std::string_view md = "# Hello\n\n- [x] *modules*\n";
std::string html;
md_html(md.data(), static_cast<MD_SIZE>(md.size()),
[](const MD_CHAR* s, MD_SIZE n, void* out) { static_cast<std::string*>(out)->append(s, n); },
&html, macros::MD_DIALECT_GITHUB, 0);
std::print("{}", html);
}A named module cannot export a macro; the object-like ones are
inline constexpr unsigned under their original names:
macros::MD_FLAG_TABLES, macros::MD_DIALECT_GITHUB, macros::MD_HTML_FLAG_XHTML.
A translation unit that also includes <md4c.h> has the macros active, and they
expand even inside macros::MD_FLAG_TABLES; use the plain macro there (see
tests/header_mix_test.cpp).
- examples/md2html: upstream's
md2htmloptions over stdin or a file; the program tools/run_conformance.py drives through upstream'stest/run-testsuite.py.
Linux, macOS and Windows CI build the modules, run the tests, the export audit (tools/check_exports.py: every public name of both headers is exported) and the upstream conformance suites; a separate job scaffolds the default template as an installed package and runs it.
Apache-2.0 for the wrapper, by mcpp-community; MD4C remains MIT. Original upstream README and license, the vendored md4c-html sources and their checksums (upstream/documents.json).