Skip to main content

insert_cell

Function insert_cell 

Source
pub fn insert_cell(
    path: &Path,
    source: &str,
    index: Option<usize>,
    cell_type: CellType,
) -> Result<usize>
Expand description

Build a fresh nbformat cell from source and insert it into the notebook at path, proposing it without executing (Phase 21.4 notebook_insert_cell).

index is the zero-based position to insert at; None appends. An index past the end clamps to an append (so the cell is never dropped). A code cell is inserted with execution_count: null and outputs: [] — it has not run, and a reviewer can tell at a glance. If path does not yet exist, a minimal valid nbformat-4 notebook is created first. The write is atomic.

Returns the index the cell actually landed at.