Skip to content

Commit 71f050b

Browse files
Abstract away the tab-based Notebook/Lab interface
1 parent b2f6264 commit 71f050b

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,15 @@ class JupyterLiteIframe(_LiteIframe):
204204
notebooks_path = ""
205205

206206

207-
class JupyterLiteTab(_InTab):
207+
class BaseNotebookTab(_InTab):
208+
"""Base class for notebook tab implementations. We subclass this
209+
to create more specific configurations around how tabs are rendered."""
210+
211+
lite_app = None
212+
notebooks_path = None
213+
214+
215+
class JupyterLiteTab(BaseNotebookTab):
208216
"""Appended to the doctree by the JupyterliteDirective directive
209217
210218
Renders a button that opens a Notebook with JupyterLite in a new tab.
@@ -214,6 +222,16 @@ class JupyterLiteTab(_InTab):
214222
notebooks_path = ""
215223

216224

225+
class NotebookLiteTab(BaseNotebookTab):
226+
"""Appended to the doctree by the NotebookliteDirective directive
227+
228+
Renders a button that opens a Notebook with NotebookLite in a new tab.
229+
"""
230+
231+
lite_app = "tree/"
232+
notebooks_path = "../notebooks/"
233+
234+
217235
class NotebookLiteIframe(_LiteIframe):
218236
"""Appended to the doctree by the NotebookliteDirective directive
219237
@@ -400,7 +418,24 @@ def run(self):
400418
]
401419

402420

403-
class JupyterLiteDirective(_LiteDirective):
421+
class BaseNotebookDirective(_LiteDirective):
422+
"""Base class for notebook directives."""
423+
424+
iframe_cls = None # to be defined by subclasses
425+
newtab_cls = None # to be defined by subclasses
426+
427+
option_spec = {
428+
"width": directives.unchanged,
429+
"height": directives.unchanged,
430+
"theme": directives.unchanged,
431+
"prompt": directives.unchanged,
432+
"prompt_color": directives.unchanged,
433+
"search_params": directives.unchanged,
434+
"new_tab": directives.unchanged,
435+
}
436+
437+
438+
class JupyterLiteDirective(BaseNotebookDirective):
404439
"""The ``.. jupyterlite::`` directive.
405440
406441
Renders a Notebook with JupyterLite in the docs.
@@ -410,13 +445,14 @@ class JupyterLiteDirective(_LiteDirective):
410445
newtab_cls = JupyterLiteTab
411446

412447

413-
class NotebookLiteDirective(_LiteDirective):
448+
class NotebookLiteDirective(BaseNotebookDirective):
414449
"""The ``.. notebooklite::`` directive.
415450
416451
Renders a Notebook with NotebookLite in the docs.
417452
"""
418453

419454
iframe_cls = NotebookLiteIframe
455+
newtab_cls = NotebookLiteTab
420456

421457

422458
class VoiciDirective(_LiteDirective):
@@ -810,14 +846,15 @@ def setup(app):
810846
text=(skip, None),
811847
man=(skip, None),
812848
)
813-
app.add_node(
814-
JupyterLiteTab,
815-
html=(visit_element_html, None),
816-
latex=(skip, None),
817-
textinfo=(skip, None),
818-
text=(skip, None),
819-
man=(skip, None),
820-
)
849+
for node_class in [NotebookLiteTab, JupyterLiteTab]:
850+
app.add_node(
851+
node_class,
852+
html=(visit_element_html, None),
853+
latex=(skip, None),
854+
textinfo=(skip, None),
855+
text=(skip, None),
856+
man=(skip, None),
857+
)
821858
app.add_directive("jupyterlite", JupyterLiteDirective)
822859

823860
# Initialize Replite directive

0 commit comments

Comments
 (0)