package cmarkit
CommonMark parser and renderer for OCaml
Install
Dune Dependency
Authors
Maintainers
Sources
cmarkit-0.3.0.tbz
sha512=42fa920e84f2b7d45f5cf1251d3308daa7becff2590f7ce84186cb22335415b02cc9bc44179095bf0d37624fb5a0e66d1c96fcc1b12f1106f567247a71c79039
doc/index.html
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
Cmarkit
CommonMark parser and abstract syntax tree.Cmarkit_renderer
Renderer abstraction.Cmarkit_commonmark
Rendering CommonMark to CommonMark.Cmarkit_html
Rendering CommonMark to HTML.Cmarkit_latex
Rendering CommonMark to LATEX.
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:
- Extend the abstract syntax tree or the renderers, see this example.
- Map parts of an abstract syntax, see
Cmarkit.Mapper
. - Fold over parts of an abstract syntax, see
Cmarkit.Folder
. - Interfere with link label definition and resolution, see labels and their resolvers.
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page