@@ -204,7 +204,15 @@ class JupyterLiteIframe(_LiteIframe):
204
204
notebooks_path = ""
205
205
206
206
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 ):
208
216
"""Appended to the doctree by the JupyterliteDirective directive
209
217
210
218
Renders a button that opens a Notebook with JupyterLite in a new tab.
@@ -214,6 +222,16 @@ class JupyterLiteTab(_InTab):
214
222
notebooks_path = ""
215
223
216
224
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
+
217
235
class NotebookLiteIframe (_LiteIframe ):
218
236
"""Appended to the doctree by the NotebookliteDirective directive
219
237
@@ -400,7 +418,24 @@ def run(self):
400
418
]
401
419
402
420
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 ):
404
439
"""The ``.. jupyterlite::`` directive.
405
440
406
441
Renders a Notebook with JupyterLite in the docs.
@@ -410,13 +445,14 @@ class JupyterLiteDirective(_LiteDirective):
410
445
newtab_cls = JupyterLiteTab
411
446
412
447
413
- class NotebookLiteDirective (_LiteDirective ):
448
+ class NotebookLiteDirective (BaseNotebookDirective ):
414
449
"""The ``.. notebooklite::`` directive.
415
450
416
451
Renders a Notebook with NotebookLite in the docs.
417
452
"""
418
453
419
454
iframe_cls = NotebookLiteIframe
455
+ newtab_cls = NotebookLiteTab
420
456
421
457
422
458
class VoiciDirective (_LiteDirective ):
@@ -810,14 +846,15 @@ def setup(app):
810
846
text = (skip , None ),
811
847
man = (skip , None ),
812
848
)
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
+ )
821
858
app .add_directive ("jupyterlite" , JupyterLiteDirective )
822
859
823
860
# Initialize Replite directive
0 commit comments