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 Output : sig ... end

Test outputs.

module Cram : sig ... end

Cram tests

module Toplevel : sig ... end

Toplevel phrases.

module Block : sig ... end

Code blocks.

module Migrate_ast : sig ... end
module Compat : sig ... end

Lines

type syntax =
  1. | Normal
  2. | Cram
type 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 of_string : syntax -> string -> t

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

val parse_file : syntax -> string -> t

parse_file s is of_string of s's contents.

val parse_lexbuf : syntax -> Lexing.lexbuf -> t

parse_lexbuf l is of_string of l's contents.

Evaluation

val run : ?syntax:syntax -> ?force_output:bool -> f:(string -> t -> string) -> string -> unit

run ?syntax ~f n runs the expect callback f over the file named n. f is called with the raw contents of n and its structured contents; it returns the new file contents. If the result of f is different from the initial contents or if force_output was set to true, then $n.corrected is created with the new contents.

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.