pub struct Notebook {
pub cells: Vec<Cell>,
pub metadata: NotebookMetadata,
pub nbformat: u8,
pub nbformat_minor: u8,
pub sort_keys: bool,
}Expand description
A Jupyter notebook.
This is the central representation of a notebook in notebookx.
It closely mirrors the structure of the Jupyter .ipynb format
(nbformat version 4).
§Example
use notebookx::{Notebook, Cell};
let mut notebook = Notebook::new();
notebook.cells.push(Cell::markdown("# Hello World"));
notebook.cells.push(Cell::code("print('Hello!')"));Fields§
§cells: Vec<Cell>The cells in this notebook.
metadata: NotebookMetadataNotebook-level metadata.
nbformat: u8Major version of the notebook format (always 4).
nbformat_minor: u8Minor version of the notebook format.
sort_keys: boolWhether to sort keys alphabetically when serializing to JSON. This is useful for VCS to produce consistent diffs.
Implementations§
Source§impl Notebook
impl Notebook
Sourcepub fn clean(&self, options: &CleanOptions) -> Notebook
pub fn clean(&self, options: &CleanOptions) -> Notebook
Clean the notebook according to the specified options.
This method returns a new notebook with the requested content removed. The original notebook is not modified.
§Example
use notebookx::{Notebook, Cell, CleanOptions};
let mut notebook = Notebook::new();
notebook.cells.push(Cell::code("x = 1"));
let options = CleanOptions {
remove_outputs: true,
..Default::default()
};
let cleaned = notebook.clean(&options);
assert_eq!(notebook.len(), cleaned.len()); // Original unchangedSource§impl Notebook
impl Notebook
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty notebook.
The notebook is created with nbformat version 4.5 (the current version with cell ID support) and empty metadata.
Sourcepub fn with_cells(cells: Vec<Cell>) -> Self
pub fn with_cells(cells: Vec<Cell>) -> Self
Create a notebook with the specified cells.
Sourcepub fn code_cells(&self) -> impl Iterator<Item = &Cell>
pub fn code_cells(&self) -> impl Iterator<Item = &Cell>
Get only the code cells.
Sourcepub fn markdown_cells(&self) -> impl Iterator<Item = &Cell>
pub fn markdown_cells(&self) -> impl Iterator<Item = &Cell>
Get only the markdown cells.