Skip to content
Merged
Show file tree
Hide file tree
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A Sphinx extension that provides utilities for embedding JupyterLite in your doc
:caption: Usage
:maxdepth: 2

jupyterlite
retrolite
replite
directives/jupyterlite
directives/retrolite
directives/replite
full
32 changes: 26 additions & 6 deletions src/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
self,
rawsource="",
*children,
prefix=JUPYTERLITE_DIR,
width="100%",
height="100%",
content=[],
Expand All @@ -51,6 +52,7 @@ def __init__(
):
super().__init__(
"",
prefix=prefix,
width=width,
height=height,
content=content,
Expand All @@ -71,7 +73,7 @@ def html(self):
)

return (
f'<iframe src="{JUPYTERLITE_DIR}/repl/index.html?{options}"'
f'<iframe src="{self["prefix"]}/repl/index.html?{options}"'
f'width="{self["width"]}" height="{self["height"]}" style="{IFRAME_STYLE}"></iframe>'
)

Expand All @@ -96,8 +98,14 @@ def run(self):
width = self.options.pop("width", "100%")
height = self.options.pop("height", "100%")

prefix = os.path.relpath(
os.path.join(self.env.app.srcdir, JUPYTERLITE_DIR),
os.path.dirname(self.get_source_info()[0]),
)

return [
RepliteIframe(
prefix=prefix,
width=width,
height=height,
content=self.content,
Expand All @@ -111,20 +119,23 @@ def __init__(
self,
rawsource="",
*children,
prefix=JUPYTERLITE_DIR,
width="100%",
height="1000px",
notebook=None,
**attributes,
):
super().__init__("", notebook=notebook, width=width, height=height)
super().__init__(
"", prefix=prefix, notebook=notebook, width=width, height=height
)

def html(self):
notebook = self["notebook"]

src = (
f"{JUPYTERLITE_DIR}/{self.lite_app}/{self.notebooks_path}?path={notebook}"
f'{self["prefix"]}/{self.lite_app}/{self.notebooks_path}?path={notebook}'
if notebook is not None
else f"{JUPYTERLITE_DIR}/{self.lite_app}"
else f'{self["prefix"]}/{self.lite_app}'
)

return (
Expand Down Expand Up @@ -166,13 +177,18 @@ def run(self):
width = self.options.get("width", "100%")
height = self.options.get("height", "1000px")

source_location = os.path.dirname(self.get_source_info()[0])

prefix = os.path.relpath(
os.path.join(self.env.app.srcdir, JUPYTERLITE_DIR), source_location
)

if self.arguments:
notebook = self.arguments[0]

# If we didn't get an absolute path,
# try to find the Notebook relatively to the source
if not os.path.isabs(notebook):
source_location = os.path.dirname(self.get_source_info()[0])
notebook = os.path.join(source_location, notebook)

notebook_name = os.path.basename(notebook)
Expand All @@ -185,7 +201,11 @@ def run(self):
else:
notebook_name = None

return [self.iframe_cls(notebook=notebook_name, width=width, height=height)]
return [
self.iframe_cls(
prefix=prefix, notebook=notebook_name, width=width, height=height
)
]


class JupyterLiteDirective(_LiteDirective):
Expand Down