Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt the path convention of other directives like literalinclude #54

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from sphinx.application import Sphinx
from sphinx.util.docutils import SphinxDirective
from sphinx.parsers import RSTParser


CONTENT_DIR = "_contents"
Expand Down Expand Up @@ -184,12 +185,11 @@ def run(self):
)

if self.arguments:
notebook = self.arguments[0]

# If we didn't get an absolute path,
# try to find the Notebook relatively to the source
if not os.path.isabs(notebook):
notebook = os.path.join(source_location, notebook)
# As with other directives like literalinclude, an absolute path is
# assumed to be relative to the document root, and a relative path
# is assumed to be relative to the source file
rel_filename, notebook = self.env.relfn2path(self.arguments[0])
self.env.note_dependency(rel_filename)

notebook_name = os.path.basename(notebook)

Expand Down Expand Up @@ -226,7 +226,7 @@ class RetroLiteDirective(_LiteDirective):
iframe_cls = RetroLiteIframe


class RetroLiteParser(rst.Parser):
class RetroLiteParser(RSTParser):
"""Sphinx source parser for Jupyter notebooks.

Shows the Notebook using retrolite."""
Expand All @@ -235,8 +235,10 @@ class RetroLiteParser(rst.Parser):

def parse(self, inputstring, document):
title = os.path.splitext(os.path.basename(document.current_source))[0]
# Make the "absolute" filename relative to the source root
filename = "/" + os.path.relpath(document.current_source, self.env.app.srcdir)
super().parse(
f"{title}\n{'=' * len(title)}\n.. retrolite:: {document.current_source}",
f"{title}\n{'=' * len(title)}\n.. retrolite:: {filename}",
document,
)

Expand Down