@@ -86,12 +86,7 @@ def run(self):
8686 return [RepliteIframe (width = width , height = height , replite_options = self .options )]
8787
8888
89- class RetroliteIframe (Element ):
90- """Appended to the doctree by the RetroliteDirective directive
91-
92- Renders an iframe that shows a Notebook with RetroLite.
93- """
94-
89+ class _LiteIframe (Element ):
9590 def __init__ (
9691 self ,
9792 rawsource = "" ,
@@ -107,9 +102,9 @@ def html(self):
107102 notebook = self ["notebook" ]
108103
109104 src = (
110- f"{ JUPYTERLITE_DIR } /retro/notebooks/ ?path={ notebook } "
105+ f"{ JUPYTERLITE_DIR } /{ self . lite_app } / { self . notebooks_path } ?path={ notebook } "
111106 if notebook is not None
112- else f"{ JUPYTERLITE_DIR } /retro "
107+ else f"{ JUPYTERLITE_DIR } /{ self . lite_app } "
113108 )
114109
115110 return (
@@ -118,12 +113,28 @@ def html(self):
118113 )
119114
120115
121- class RetroliteDirective ( SphinxDirective ):
122- """The ``.. retrolite::`` directive.
116+ class JupyterLiteIframe ( _LiteIframe ):
117+ """Appended to the doctree by the JupyterliteDirective directive
123118
124- Renders a Notebook with RetroLite in the docs.
119+ Renders an iframe that shows a Notebook with JupyterLite.
120+ """
121+
122+ lite_app = "lab"
123+ notebooks_path = ""
124+
125+
126+ class RetroLiteIframe (_LiteIframe ):
127+ """Appended to the doctree by the RetroliteDirective directive
128+
129+ Renders an iframe that shows a Notebook with RetroLite.
125130 """
126131
132+ lite_app = "retro"
133+ notebooks_path = "notebooks/"
134+
135+
136+ class _LiteDirective (SphinxDirective ):
137+
127138 has_content = False
128139 optional_arguments = 1
129140 option_spec = {
@@ -154,7 +165,25 @@ def run(self):
154165 else :
155166 notebook_name = None
156167
157- return [RetroliteIframe (notebook = notebook_name , width = width , height = height )]
168+ return [self .iframe_cls (notebook = notebook_name , width = width , height = height )]
169+
170+
171+ class JupyterLiteDirective (_LiteDirective ):
172+ """The ``.. jupyterlite::`` directive.
173+
174+ Renders a Notebook with JupyterLite in the docs.
175+ """
176+
177+ iframe_cls = JupyterLiteIframe
178+
179+
180+ class RetroLiteDirective (_LiteDirective ):
181+ """The ``.. retrolite::`` directive.
182+
183+ Renders a Notebook with RetroLite in the docs.
184+ """
185+
186+ iframe_cls = RetroLiteIframe
158187
159188
160189class RetroLiteParser (rst .Parser ):
@@ -213,25 +242,34 @@ def jupyterlite_build(app: Sphinx, error):
213242
214243
215244def setup (app ):
216- # Build the JupyterLite output
217245 app .connect ("config-inited" , inited )
218246 # We need to build JupyterLite at the end, when all the content was created
219247 app .connect ("build-finished" , jupyterlite_build )
220248
221249 # Config options
222250 app .add_config_value ("jupyterlite_config" , None , rebuild = "html" )
223251
224- # Initialize RetroLite directive and parser
252+ # Initialize RetroLite and JupyterLite directives
253+ app .add_node (
254+ RetroLiteIframe ,
255+ html = (visit_element_html , None ),
256+ latex = (skip , None ),
257+ textinfo = (skip , None ),
258+ text = (skip , None ),
259+ man = (skip , None ),
260+ )
261+ app .add_directive ("retrolite" , RetroLiteDirective )
225262 app .add_node (
226- RetroliteIframe ,
263+ JupyterLiteIframe ,
227264 html = (visit_element_html , None ),
228265 latex = (skip , None ),
229266 textinfo = (skip , None ),
230267 text = (skip , None ),
231268 man = (skip , None ),
232269 )
233- app .add_directive ("retrolite " , RetroliteDirective )
270+ app .add_directive ("jupyterlite " , JupyterLiteDirective )
234271
272+ # Initialize RetroLite parser
235273 app .add_source_parser (RetroLiteParser )
236274 app .add_source_suffix (".ipynb" , "jupyterlite_notebook" )
237275
0 commit comments