1414
1515from sphinx .application import Sphinx
1616from sphinx .util .docutils import SphinxDirective
17+ from sphinx .parsers import RSTParser
1718
1819
1920CONTENT_DIR = "_contents"
@@ -185,12 +186,11 @@ def run(self):
185186 )
186187
187188 if self .arguments :
188- notebook = self .arguments [0 ]
189-
190- # If we didn't get an absolute path,
191- # try to find the Notebook relatively to the source
192- if not os .path .isabs (notebook ):
193- notebook = os .path .join (source_location , notebook )
189+ # As with other directives like literalinclude, an absolute path is
190+ # assumed to be relative to the document root, and a relative path
191+ # is assumed to be relative to the source file
192+ rel_filename , notebook = self .env .relfn2path (self .arguments [0 ])
193+ self .env .note_dependency (rel_filename )
194194
195195 notebook_name = os .path .basename (notebook )
196196
@@ -227,7 +227,7 @@ class RetroLiteDirective(_LiteDirective):
227227 iframe_cls = RetroLiteIframe
228228
229229
230- class RetroLiteParser (rst . Parser ):
230+ class RetroLiteParser (RSTParser ):
231231 """Sphinx source parser for Jupyter notebooks.
232232
233233 Shows the Notebook using retrolite."""
@@ -236,8 +236,10 @@ class RetroLiteParser(rst.Parser):
236236
237237 def parse (self , inputstring , document ):
238238 title = os .path .splitext (os .path .basename (document .current_source ))[0 ]
239+ # Make the "absolute" filename relative to the source root
240+ filename = "/" + os .path .relpath (document .current_source , self .env .app .srcdir )
239241 super ().parse (
240- f"{ title } \n { '=' * len (title )} \n .. retrolite:: { document . current_source } " ,
242+ f"{ title } \n { '=' * len (title )} \n .. retrolite:: { filename } " ,
241243 document ,
242244 )
243245
0 commit comments