package yocaml_cmarkit

  1. Overview
  2. Docs
On This Page
  1. API
Yocaml plugin for using Markdown (via Cmarkit package) as a Markup language

Install

dune-project
 Dependency

Authors

Maintainers

Sources

yocaml-2.3.0.tbz
sha256=216c47d4d954a1e210437101a46736a09fb2e198baf12657c13ade8f24aab7cb
sha512=3bef1e6e93644f860d5b4e72b392530eb0d5ba0ae2cabe198b85b90b92cfd2ad19ff0416d77d46760bcd63b9561c409ef1ecfb11ccacef8e474e7a231234b623

doc/yocaml_cmarkit/Yocaml_cmarkit/index.html

Module Yocaml_cmarkitSource

Describing documents using a Markup language is very common in the Blogosphere (rather than describing all the formatting of document content in HTML, using <p>, <strong> and co).

Common Mark is a specification (see RFC7763/RFC7764) of Markdown since 2016. As it is a very popular markup language, OCaml has several very good libraries for turning Common Mark into HTML. This library is a wrapper around cmarkit, an excellent Common Mark conversion library.

API

Sourceval to_html : ?strict:bool -> ?safe:bool -> unit -> (string, string) Yocaml.Task.t

to_html ~strict ~safe () is an arrow that produces an HTML (as a String) from a String in Common Mark.

The strict argument permits to follow only the Common Mark specification. If you attempt to use some extensions (see Cmarkit.Doc.of_string), you should set it to false.

The safe argument ensures that any HTML code written in your Common Mark document is escaped as an HTML comment. As most of the time, the markdown provided comes from the user, this functionnality is disabled by default. If you want to activate this feature, you should set it to true.

Sourceval to_html_with_toc : ?strict:bool -> ?safe:bool -> unit -> (string, string option * string) Yocaml.Task.t

Same as to_html but it returns a pair where the first argument is an HTML representation of the table of contents, and the second one is the document.

Sourceval content_to_html : ?strict:bool -> ?safe:bool -> unit -> ('a * string, 'a * string) Yocaml.Task.t

Since it is pretty common to deal with document and Metadata, which are generally a pair of Metadata and the content of the document, content_to_html is a function that produce an arrow which apply the Common Mark conversion on the second element (the content).

content_to_html () is equivalent of Yocaml.Task.second to_html.

Sourceval content_to_html_with_toc : ?strict:bool -> ?safe:bool -> ('a -> string option -> 'b) -> ('a * string, 'b * string) Yocaml.Task.t

Same as content_to_html but it returns a pair where the first argument is an HTML representation of the table of contents, and the second one is the document. The arrow takes also a f that can merge the metadata with the computed table of contents.