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

format

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package format reads and writes notebooks.

A notebook is a Markdown document. Its fenced code blocks whose info string's first word is "go" are code cells; everything between them is prose, kept byte for byte. GitHub and any Markdown viewer show a notebook as a document, diffs are diffs of text, and no output is ever stored in the file: results live in the kernel's value store and in exports.

# Spectrum

```go
x := ndarray.Linspace(0, 1, 1024)
```

Fences follow CommonMark: three or more backticks or tildes, indented by at most three spaces, closed by a fence of the same character at least as long. A code block in another language is prose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Kind Kind

	// Source is the cell's text: the Markdown of a prose cell, the Go code of
	// a code cell (without its fences, ending in a newline unless empty).
	Source string

	// Line is the 1-based line of the document where Source starts.
	Line int

	// Info is a code cell's info string after "go" (its options), trimmed.
	Info string
	// contains filtered or unexported fields
}

Cell is one cell of a notebook.

func NewCode

func NewCode(src string) Cell

NewCode returns a code cell holding src, for building a notebook in code.

type Kind

type Kind uint8

Kind tells prose from code.

const (
	// Prose is Markdown text.
	Prose Kind = iota
	// Code is a Go cell.
	Code
)

type Notebook

type Notebook struct {
	Cells []Cell
}

Notebook is a parsed notebook.

func Parse

func Parse(src string) *Notebook

Parse splits a Markdown document into cells. It never fails: any text is a notebook, perhaps of prose only. An unclosed go fence runs to the end of the document, as CommonMark says.

func (*Notebook) String

func (nb *Notebook) String() string

String writes the notebook back as Markdown. For a parsed notebook it is the original text, byte for byte. A code cell made by NewCode gets a backtick fence long enough for its source.

Jump to

Keyboard shortcuts

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