Immutable Jupyter and DIB notebooks with shared navigation and traversal
Dependencies
| Package | Purpose |
|---|---|
| moonrockz/notebooks | Open node contract, common node kinds, typed cursors, paths, walks and folds |
| moonrockz/notebooks/nbformat | Jupyter v4 JSON, cells, outputs, attachments and metadata |
| moonrockz/notebooks/dib | .NET Interactive source notebooks, kernels, metadata and directives |
import {
"moonrockz/notebooks" @notebooks,
"moonrockz/notebooks/nbformat" @nbformat,
"moonrockz/notebooks/dib" @dib,
}| Guide | Recipes |
|---|---|
| Shared navigation | Cross-format queries, cursor moves, saved paths, prune/stop callbacks, folds, subtree roots and consumer-defined formats |
| Jupyter notebooks | Reading, construction, rich outputs, attachments, immutable metadata, ID lookup, errors, extensions and edits |
| DIB notebooks | Selectors, aliases, construction, custom environments, metadata, directive navigation, errors and empty-cell normalization |
mise exec -- moon test pkgs/notebooks pkgs/notebooks/nbformat pkgs/notebooks/dib --target js --deny-warnfn[N : @notebooks.Node] cell_sources(root : N) -> ReadOnlyArray[String] {
let sources = []
@notebooks.walk(root, node => {
if node.kind() is Cell(_) {
if node.source() is Some(source) { sources.push(source) }
}
Continue
})
ReadOnlyArray::from_array(sources[:])
}
let jupyter = @nbformat.parse(jupyter_json)
let interactive = @dib.parse(dib_source)
let jupyter_sources = cell_sources(jupyter.root())
let dib_sources = cell_sources(interactive.root())| Node | Common metadata |
|---|---|
| Jupyter notebook and every cell type | Some, including empty objects |
| Jupyter display_data and execute_result outputs | Some, including empty objects |
| Jupyter stream, error and unknown output types; attachments | None |
| DIB notebook | Some, including an absent or empty #!meta section |
| DIB cell and directive | None |
type Cursor[N]test "doc: describe a child path" {
let path = @notebooks.NodePath([1, 0])
@expect.expect_all(s => {
s.expect(path.indices()).to_equal([1, 0])
s.expect(path.to_string()).to_equal("$[1][0]")
s.expect(@notebooks.NodePath([]).to_string()).to_equal("$")
})
}Install
Download zipImmutable Jupyter and DIB notebooks with shared navigation and traversal
Dependencies