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 Library : sig ... end
module Ocaml_delimiter : sig ... end
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

Lines

type syntax = Syntax.t =
  1. | Normal
  2. | Cram
  3. | Mli
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 -> line Fmt.t

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

Document

type t = line list

The type for mdx documents.

val pp : ?syntax:syntax -> 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 -> Ocaml_env.Set.t
val dump : line list Fmt.t

Document

val of_string : syntax -> string -> (t, [ `Msg of string ]) Result.result

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

val parse_file : syntax -> string -> (t, [ `Msg of string ]) Result.result

parse_file s is of_string of s's contents.

val parse_lexbuf : string -> syntax -> Lexing.lexbuf -> (t, [ `Msg of string ]) Result.result

parse_lexbuf l is of_string of l's contents.

Evaluation

val run_to_stdout : ?syntax:syntax -> f:(string -> t -> string) -> string -> (unit, [ `Msg of string ]) Result.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 Normal). The returned corrected version is then written to stdout.

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

Same as run_to_stdout but writes the corrected version to outfile

val run : ?syntax:syntax -> ?force_output:bool -> f:(string -> t -> string) -> string -> (unit, [ `Msg of string ]) Result.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.

Filtering

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

section_of_line l is l's section.

val filter_section : Re.re -> t -> t option

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

OCaml

Innovation. Community. Security.