package mdx

  1. Overview
  2. Docs

Mdx is a library to manipulate markdown code blocks.

mdx allows to execute code blocks inside markdown files. The supported code blocks are either cram-like tests, raw OCaml fragments or toplevel phrases.

Cram tests and toplevel phrases are sequences of commands and outputs.

module Lexer_mdx : sig ... end
module Output : sig ... end

Test outputs.

module Cram : sig ... end

Cram tests

module Deprecated : sig ... end
module Document : sig ... end
module Toplevel : sig ... end

Toplevel phrases.

module Part : sig ... end
module Block : sig ... end

Code blocks headers.

module Mli_parser : sig ... end
module Compat : sig ... end
module Util : sig ... end
module Prelude : sig ... end
module Syntax : sig ... end
module Label : sig ... end
module Dep : sig ... end
module Ocaml_env : sig ... end

Block environments.

module Stable_printer : sig ... end

Stable printing functions built on top of compiler-libs types Use this for user facing part of the code so that mdx's output does not depend on the ocaml version it was built with.

include module type of Document


type line = Document.line =
  1. | Section of int * string
  2. | Text of string
  3. | Block of Block.t

The type for the lines of a markdown or cram file.

val pp_line : ?syntax:Syntax.t -> line Fmt.t

pp_line is the pretty-printer for markdown or cram lines.


type t = line list

The type for mdx documents.

val pp : ?syntax:Syntax.t -> t Fmt.t

pp is the pretty printer for mdx documents. Should be idempotent with of_string.

val to_string : t -> string

to_string t converts the document t to a string.

val envs : t -> Mdx__.Ocaml_env.Set.t
val dump : line list Fmt.t


val of_string : Syntax.t -> string -> (t, [ `Msg of string ] list) Stdlib.result

of_string syntax s is the document t such that to_string ~syntax t = s.

val parse_file : Syntax.t -> string -> (t, [ `Msg of string ] list) Stdlib.result

parse_file s is of_string of s's contents.


val run_to_stdout : ?syntax:Syntax.t -> f:(string -> t -> string) -> string -> (unit, [ `Msg of string ] list) Stdlib.result

run_to_stdout ?syntax ~f file runs the callback f on the raw and structured content of file, as specified by syntax (defaults to Markdown). The returned corrected version is then written to stdout.

val run_to_file : ?syntax:Syntax.t -> f:(string -> t -> string) -> outfile:string -> string -> (unit, [ `Msg of string ] list) Stdlib.result

Same as run_to_stdout but writes the corrected version to outfile

val run : ?syntax:Syntax.t -> ?force_output:bool -> f:(string -> t -> string) -> string -> (unit, [ `Msg of string ] list) Stdlib.result

run_to_file ?syntax ?force_output ~f ~outfile file runs the callback f similarly to run_to_stdout to generate its corrected version. If force_output is true (defaults to false) or if the corrected version differs from the original file content, it writes it to <file>.corrected. Otherwise, if <file>.corrected already exists, it removes it.


val section_of_line : line -> (int * string) option

section_of_line l is l's section.

val filter_section : -> t -> t option

section re t is the subset of t such that their section matches with re.