Module Cmarkit_renderer.Context

Rendering contexts.

Contexts

type renderer := t
type t = context

The type for rendering contexts.

val make : renderer -> Stdlib.Buffer.t -> t

make r b is a context using renderer r to render documents on buffer b.

The renderer r must be able to handle any inline, block and document values (i.e. its renderers should always return true) otherwise Invalid_argument may raise on renders.

This means the last renderer you compose with should always have catch all cases returning true; after possibly indicating in the output that something was missed. The built-in renderers Cmarkit_commonmark.renderer, Cmarkit_html.renderer and Cmarkit_latex.renderer do have these catch all cases.

val renderer : t -> renderer

renderer c is the renderer of c.

val buffer : t -> Stdlib.Buffer.t

buffer c is the buffer of c.

val get_doc : t -> Cmarkit.Doc.t

get_doc c is the document being rendered.

val get_defs : t -> Cmarkit.Label.defs

get_defs c is Doc.defs (get_doc c).

module State : sig ... end

Custom context state.

val init : t -> Cmarkit.Doc.t -> unit

init c calls the initialisation function of c's renderer. Note, this is done automatically by doc.

Rendering functions

These function append data to the buffer of the context. For more specialized rendering functions, see the corresponding rendering backends.

val byte : t -> char -> unit

byte c b renders byte b verbatim on c.

val utf_8_uchar : t -> Stdlib.Uchar.t -> unit

utf_8_uchar c u renders the UTF-8 encoding of u on c.

val string : t -> string -> unit

string c s renders string s verbatim on c.

val inline : t -> Cmarkit.Inline.t -> unit

inline c i renders inline i on c. This invokes the composition of inline renderers of c.

val block : t -> Cmarkit.Block.t -> unit

block c b renders block b on c. This invokes the composition of block renderers of c.

val doc : t -> Cmarkit.Doc.t -> unit

doc c d initializes c with init and renders document d on c. This invokes the composition of document renderers of c.