How do I access:
- a list of open notebooks;
- a list of cells in a specific notebook
in JupyterLab 4?
I can generate a reference to the currently active cell in an active notebook:
const plugin: JupyterFrontEndPlugin<void> = {
id: '@jupyterlab-examples/toolbar-button:plugin',
description:
'A JupyterLab extension adding a button to the Notebook toolbar.',
requires: [INotebookTracker],
autoStart: true,
activate: (app: JupyterFrontEnd, notebookTracker: INotebookTracker) => {
activeCell = notebookTracker.activeCell
// Perform operations on active cell,
// eg get/set metadata, set node class attributes
})
};
export default plugin;
and then use the activeCell
reference to get/set cell metadata (e.g. activeCell.model.getMetadata("tags") as string[]
) and manipulate cell node class attributes in the rendered UI (e.g. activeCell.node.classList.add('myclass')
).
I thought I might be able to capture "on-the-fly" references to notebooks as they are selected using:
notebookTracker.currentChanged.connect((tracker, panel) => {
})
but I can't find lists of cells on tracker
or panel
?
In pseudo code, what I would like to do is:
- when a notebook is opened (or rendered, eg if Lab starts with opened notebooks in view):
- iterate the cells;
Cell references should support getting/setting cell metadata and manipulation of cell node class attributes.