Module Quill.CellSource

Notebook cells.

A cell is the atomic unit of a notebook: either a block of text or an executable code block with outputs.

Cell identifiers

Sourcetype id = string

The type for cell identifiers. Stable across serialization.

Sourceval fresh_id : unit -> id

fresh_id () is a fresh unique identifier.

Execution outputs

Sourcetype output =
  1. | Stdout of string
  2. | Stderr of string
  3. | Error of string
  4. | Display of {
    1. mime : string;
    2. data : string;
    }
    (*

    The type for cell execution outputs. A single execution may produce multiple outputs (e.g. stdout text followed by a displayed image).

    • Stdout s is captured standard output.
    • Stderr s is captured standard error.
    • Error s is an execution error message.
    • Display {mime; data} is rich content identified by MIME type (e.g. "text/html", "image/png"). Binary data is base64-encoded in data.
    *)
Sourcetype Format.stag +=
  1. | Display_tag of {
    1. mime : string;
    2. data : string;
    }
    (*

    Semantic tag for rich display output. When a pretty-printer opens this tag on a formatter configured by the notebook kernel, the payload is emitted as a Display output. On other formatters the tag is silently ignored and only the text content between the open/close tags is printed.

    *)

Cell attributes

Sourcetype attrs = {
  1. collapsed : bool;
    (*

    When true, the cell renders as a compact one-line bar. Source and outputs are hidden until the user expands the cell. Purely presentational — execution is unaffected.

    *)
  2. hide_source : bool;
    (*

    When true, the code editor is folded away and only outputs are visible. Clicking the placeholder reveals the source. Only meaningful for code cells. Purely presentational — execution is unaffected.

    *)
}

The type for cell display attributes. All attributes are purely presentational and never affect execution semantics.

Sourceval default_attrs : attrs

default_attrs is {collapsed = false; hide_source = false}.

Cells

Sourcetype t = private
  1. | Code of {
    1. id : id;
    2. source : string;
    3. language : string;
    4. outputs : output list;
    5. execution_count : int;
    6. attrs : attrs;
    }
  2. | Text of {
    1. id : id;
    2. source : string;
    3. attrs : attrs;
    }
    (*

    The type for notebook cells.

    • Code is an executable code cell. language identifies the kernel (e.g. "ocaml"). execution_count tracks how many times this cell has been executed (starts at 0).
    • Text is a text cell whose source is markdown.

    The type is private: pattern matching is allowed, but cells must be constructed via code and text.

    *)

Constructors

Sourceval code : ?id:id -> ?language:string -> ?attrs:attrs -> string -> t

code ?id ?language ?attrs source is a code cell with the given source. language defaults to "ocaml". attrs defaults to default_attrs. A fresh identifier is generated when id is not provided.

Sourceval text : ?id:id -> ?attrs:attrs -> string -> t

text ?id ?attrs source is a text cell with the given source. attrs defaults to default_attrs. A fresh identifier is generated when id is not provided.

Accessors

Sourceval id : t -> id

id c is the unique identifier of cell c.

Sourceval source : t -> string

source c is the source text of cell c.

Sourceval attrs : t -> attrs

attrs c is the display attributes of cell c.

Transformations

Sourceval set_source : string -> t -> t

set_source s c is c with source replaced by s.

Sourceval set_attrs : attrs -> t -> t

set_attrs a c is c with display attributes replaced by a.

Sourceval set_outputs : output list -> t -> t

set_outputs os c is c with outputs replaced by os. Text cells are returned unchanged.

Sourceval append_output : output -> t -> t

append_output o c appends o to the outputs of c. Text cells are returned unchanged.

Sourceval clear_outputs : t -> t

clear_outputs c is c with an empty output list. Text cells are returned unchanged.

Sourceval increment_execution_count : t -> t

increment_execution_count c increments the execution count of a code cell. Text cells are returned unchanged.