Help us shape the future of Go! Take the 2026 Go Developer Survey

engine

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package engine runs a Go notebook in an interpreter: the playground's core, the same in the browser (compiled to WebAssembly) and in tests.

A notebook is a Markdown document whose ```go blocks are cells, as github.com/go-notebook/notebook/format reads it. The cells run in document order, in one yaegi interpreter, so that what a cell defines is visible to the cells after it. The packages a cell may import are those of github.com/go-notebook/playground/symbols; their code is compiled, not interpreted, so a call into go-statistics or go-plot runs at native (or WebAssembly) speed and only the notebook's own code is interpreted.

The conventions are go-notebook's: a cell's final expression is shown; a final call returning (value, error) shows the value, or fails the cell with the error; a value that draws itself as SVG — a go-plot figure — is shown as a figure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bundle

func Bundle(v any) map[string]string

Bundle returns the MIME bundle of a value. A figure is drawn as SVG only (Display would also rasterise it to PNG, which the page does not need); a displayer gives its own bundle, PNG in base64; anything else is its text. text/plain is always there.

Types

type Cell

type Cell struct {
	// Kind is "prose" (Markdown) or "code" (Go).
	Kind string `json:"kind"`
	// Source is the cell's text, without the fences of a code cell.
	Source string `json:"source"`
}

Cell is a cell of a notebook, as the page shows it.

func Cells

func Cells(markdown string) []Cell

Cells splits a notebook into its cells, as go-notebook does.

type Result

type Result struct {
	// Cell is the cell's index among the notebook's code cells.
	Cell int `json:"cell"`
	// Line is the line of the document where the cell's code starts.
	Line int `json:"line"`
	// Output is what the cell printed.
	Output string `json:"output,omitempty"`
	// Display holds what the cell showed, each value as a MIME bundle:
	// "text/plain", and "image/svg+xml" or "text/html" when the value has
	// that representation ("image/png" is base64).
	Display []map[string]string `json:"display,omitempty"`
	// Error is why the cell failed, with the line in the cell.
	Error string `json:"error,omitempty"`
	// Skipped reports a cell that did not run because one before it
	// failed.
	Skipped bool `json:"skipped,omitempty"`
	// Millis is how long the cell ran.
	Millis float64 `json:"ms"`
}

Result is what one code cell did.

func Run

func Run(markdown string) []Result

Run runs every code cell of a notebook in order and returns what each one did. A cell that fails stops the run: the cells after it are skipped, as their inputs may not be there.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL