package mdx

  1. Overview
  2. Docs

Module MdxSource

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.

Sourcemodule Lexer_mdx : sig ... end
Sourcemodule Output : sig ... end

Test outputs.

Sourcemodule Cram : sig ... end

Cram tests

Sourcemodule Deprecated : sig ... end
Sourcemodule Document : sig ... end
Sourcemodule Toplevel : sig ... end

Toplevel phrases.

Sourcemodule Ocaml_delimiter : sig ... end
Sourcemodule Part : sig ... end
Sourcemodule Block : sig ... end

Code blocks headers.

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

Block environments.

Sourcemodule 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

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

Sourceval pp_line : ?syntax:syntax -> line Fmt.t

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

Document

Sourcetype t = line list

The type for mdx documents.

Sourceval pp : ?syntax:syntax -> t Fmt.t

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

Sourceval to_string : t -> string

to_string t converts the document t to a string.

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

Document

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

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

parse_file s is of_string of s's contents.

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

parse_lexbuf l is of_string of l's contents.

Evaluation

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

Sourceval 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

Sourceval 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

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

section_of_line l is l's section.

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