From 6587c080b78ad76956c361e0febd14819dc8fe84 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 8 May 2025 23:53:17 +0200 Subject: [PATCH 1/2] optionally allow adding a preamble --- jupyterlite_sphinx/jupyterlite_sphinx.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jupyterlite_sphinx/jupyterlite_sphinx.py b/jupyterlite_sphinx/jupyterlite_sphinx.py index 989a739..855d7c0 100644 --- a/jupyterlite_sphinx/jupyterlite_sphinx.py +++ b/jupyterlite_sphinx/jupyterlite_sphinx.py @@ -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("-", "_") From 35958d83026ebe627157167cfec064efea6e0584 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Fri, 9 May 2025 00:42:19 +0200 Subject: [PATCH 2/2] import `new_code_cell` --- jupyterlite_sphinx/jupyterlite_sphinx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlite_sphinx/jupyterlite_sphinx.py b/jupyterlite_sphinx/jupyterlite_sphinx.py index 855d7c0..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