package cmarkit

  1. Overview
  2. Docs

Cmarkit v0.3.0

Cmarkit parses the CommonMark specification. It provides:

  • A CommonMark parser for UTF-8 encoded documents. Link label resolution can be customized and a non-strict parsing mode can be activated to add: strikethrough, LATEX math, footnotes, task items and tables.
  • An extensible abstract syntax tree for CommonMark documents with source location tracking and best effort source layout preservation.
  • Abstract syntax tree mapper and folder abstractions for quick and concise tree transformations.
  • Extensible renderers for HTML, LATEX and CommonMark with source layout preservation.

See the quick start.

Library cmarkit

Quick start

The following functions render CommonMark snippets using the built-in renderers. The parsing bit via Cmarkit.Doc.of_string is always the same except for CommonMark rendering where we make sure to keep the layout for source layout preservation.

If strict is true the CommonMark specification is strictly followed otherwise the built-in extensions are enabled.

let cmark_to_html : strict:bool -> safe:bool -> string -> string =
fun ~strict ~safe md ->
  let doc = Cmarkit.Doc.of_string ~strict md in
  Cmarkit_html.of_doc ~safe doc

let cmark_to_latex : strict:bool -> string -> string =
fun ~strict md ->
  let doc = Cmarkit.Doc.of_string ~strict md in
  Cmarkit_latex.of_doc doc

let cmark_to_commonmark : strict:bool -> string -> string =
fun ~strict md ->
  let doc = Cmarkit.Doc.of_string ~layout:true ~strict md in
  Cmarkit_commonmark.of_doc doc

If you want to:

OCaml

Innovation. Community. Security.