pub struct Notebook {
pub cells: Vec<Cell>,
pub metadata: NotebookMetadata,
pub nbformat: u8,
pub nbformat_minor: u8,
}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.
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.
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Notebook
impl<'a> IntoIterator for &'a Notebook
Source§impl IntoIterator for Notebook
impl IntoIterator for Notebook
impl StructuralPartialEq for Notebook
Auto Trait Implementations§
impl Freeze for Notebook
impl RefUnwindSafe for Notebook
impl Send for Notebook
impl Sync for Notebook
impl Unpin for Notebook
impl UnwindSafe for Notebook
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more