Skip to content
Merged
Changes from 4 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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be an external file really?

Could we make it an option in the config, passing a string "jupyterlite_sphinx_try_examples_preamble" or something like this?

Copy link
Contributor Author

@keewis keewis Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I remember correctly, the only reason was that that was the first thing I could think of this has somewhat of a precedent in try_examples.json, but I'm not particularly attached to that.

try_examples settings are currently just try_examples_*, so I'll keep that convention.

The most recent commits should contain the requested changes.

self.content = None
notebooks_dir = Path(self.env.app.srcdir) / CONTENT_DIR
notebook_unique_name = f"{uuid4()}.ipynb".replace("-", "_")
Expand Down
Loading