@@ -106,8 +106,14 @@ def __init__(
106106 def html (self ):
107107 notebook = self ["notebook" ]
108108
109+ src = (
110+ f"{ JUPYTERLITE_DIR } /retro/notebooks/?path={ notebook } "
111+ if notebook is not None
112+ else f"{ JUPYTERLITE_DIR } /retro"
113+ )
114+
109115 return (
110- f'<iframe src="{ JUPYTERLITE_DIR } /retro/notebooks/?path= { notebook } "'
116+ f'<iframe src="{ src } "'
111117 f'width="{ self ["width" ]} " height="{ self ["height" ]} " style="{ IFRAME_STYLE } "></iframe>'
112118 )
113119
@@ -119,31 +125,34 @@ class RetroliteDirective(SphinxDirective):
119125 """
120126
121127 has_content = False
122- required_arguments = 1
128+ optional_arguments = 1
123129 option_spec = {
124130 "width" : directives .unchanged ,
125131 "height" : directives .unchanged ,
126132 }
127133
128134 def run (self ):
129- notebook = self .arguments [0 ]
135+ width = self .options .get ("width" , "100%" )
136+ height = self .options .get ("height" , "1000px" )
130137
131- # If we didn't get an absolute path,
132- # try to find the Notebook relatively to the source
133- if not os .path .isabs (notebook ):
134- source_location = os .path .dirname (self .get_source_info ()[0 ])
135- notebook = os .path .join (source_location , notebook )
138+ if self .arguments :
139+ notebook = self .arguments [0 ]
136140
137- notebook_name = os .path .basename (notebook )
141+ # If we didn't get an absolute path,
142+ # try to find the Notebook relatively to the source
143+ if not os .path .isabs (notebook ):
144+ source_location = os .path .dirname (self .get_source_info ()[0 ])
145+ notebook = os .path .join (source_location , notebook )
138146
139- width = self .options .get ("width" , "100%" )
140- height = self .options .get ("height" , "1000px" )
147+ notebook_name = os .path .basename (notebook )
141148
142- notebooks_dir = Path (self .env .app .srcdir ) / CONTENT_DIR / notebook_name
149+ notebooks_dir = Path (self .env .app .srcdir ) / CONTENT_DIR / notebook_name
143150
144- # Copy the Notebook for RetroLite to find
145- os .makedirs (os .path .dirname (notebooks_dir ), exist_ok = True )
146- shutil .copyfile (notebook , str (notebooks_dir ))
151+ # Copy the Notebook for RetroLite to find
152+ os .makedirs (os .path .dirname (notebooks_dir ), exist_ok = True )
153+ shutil .copyfile (notebook , str (notebooks_dir ))
154+ else :
155+ notebook_name = None
147156
148157 return [RetroliteIframe (notebook = notebook_name , width = width , height = height )]
149158
0 commit comments