This repository contains scripts to manage Jupyter notebooks and NBConvert templates. The main scripts are toc.py, compose.py, and generate_auto_theme.py.
The toc.py script generates a Table of Contents (ToC) for a Jupyter notebook.
python toc.py <input_notebook> [output_notebook]input_notebook: The path to the input Jupyter notebook file.output_notebook(optional): The path to save the output Jupyter notebook file with the ToC. If not provided, the ToC will be printed to the console.
python toc.py notebook.ipynb notebook_with_toc.ipynbThe compose.py script allows you to compose or extract sections from Jupyter notebooks.
python compose.py -nb <notebook> [-s <selection>] [-o <output>] [--create-selection]
python compose.py -t <template> [-s <selection>] [-o <output>] [--create-selection]-nb, --notebook: Path to the input notebook (.ipynb). Used to either extract sections or compose a notebook.-t, --template: Path to JSON template file (sections.json).-s, --selection: Path to user dictionary with selected sections' structure (required for composition).-o, --output: Path to save the composed notebook or sections JSON (default:output.ipynb).--create-selection: Create aselection.jsonfrom the template or notebook.
-
Extract sections from a notebook:
python compose.py -nb notebook.ipynb
This will extract sections from
notebook.ipynband save them tonotebook.json. -
Compose a notebook using a template and selection:
python compose.py -t template.json -s selection.json -o composed_notebook.ipynb
This will compose a new notebook based on
template.jsonandselection.json, and save it tocomposed_notebook.ipynb. -
Create a selection file from a template:
python compose.py -t template.json --create-selection
This will create a
template_selection.jsonfile based ontemplate.json. -
Create a selection file from a notebook:
python compose.py -nb notebook.ipynb --create-selection
This will create a
notebook_selection.jsonfile based onnotebook.ipynb.
The generate_auto_theme.py script generates a CSS file that automatically switches between light and dark themes based on the user's system preferences for the NBConvert "Lab" template.
Run the script to generate the theme-auto.css file and update the necessary template files.
python generate_auto_theme.pyThis will generate the theme-auto.css file and update the index.html.j2 and conf.json files in the JupyterLab template directory.