Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion jupyterlite_sphinx/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
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
Expand Down Expand Up @@ -816,6 +820,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("-", "_")
Expand Down
Loading