package yocaml_cmarkit

  1. Overview
  2. Docs
On This Page
  1. API
Legend:
Library
Module
Module type
Parameter
Class
Class type

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

val 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.

val 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.

val 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.

val 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.

OCaml

Innovation. Community. Security.