diff --git a/jupyterlite_sphinx/jupyterlite_sphinx.py b/jupyterlite_sphinx/jupyterlite_sphinx.py index 989a739..fe96bdf 100644 --- a/jupyterlite_sphinx/jupyterlite_sphinx.py +++ b/jupyterlite_sphinx/jupyterlite_sphinx.py @@ -22,7 +22,7 @@ from sphinx.util.fileutil import copy_asset from sphinx.parsers import RSTParser -from ._try_examples import examples_to_notebook, insert_try_examples_directive +from ._try_examples import examples_to_notebook, insert_try_examples_directive, new_code_cell import jupytext import nbformat @@ -816,6 +816,13 @@ def run(self): if notebook_unique_name is None: nb = examples_to_notebook(self.content, warning_text=warning_text) + preamble_path = Path("try_examples_preamble.py") + if preamble_path.is_file(): + preamble = preamble_path.read_text() + # or raise an error if `preamble` is empty + if preamble: + # insert after the "experimental" warning + nb.cells.insert(1, new_code_cell(preamble)) self.content = None notebooks_dir = Path(self.env.app.srcdir) / CONTENT_DIR notebook_unique_name = f"{uuid4()}.ipynb".replace("-", "_")