Skip to content

Commit 4129ebe

Browse files
committed
rename directives jupyter-download:script -> jupyter-download-script, similar for nb and notebook
1 parent d427c79 commit 4129ebe

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

doc/source/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,16 @@ Downloading the code as a script
372372
--------------------------------
373373

374374
Jupyter Sphinx includes 2 roles that can be used to download the code embedded in a document:
375-
``:jupyter-download:script:`` (for a raw script file) and ``:jupyter-download:notebook:`` or ``:jupyter-download:nb:`` (for
375+
``:jupyter-download-script:`` (for a raw script file) and ``:jupyter-download-notebook:`` or ``:jupyter-download-nb:`` (for
376376
a Jupyter notebook).
377377

378378
These roles are equivalent to the standard sphinx `download role <https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-download>`__, **except** the extension of the file should not be given.
379379
For example, to download all the code from this document as a script we
380380
would use::
381381

382-
:jupyter-download:script:`click to download <index>`
382+
:jupyter-download-script:`click to download <index>`
383383

384-
Which produces a link like this: :jupyter-download:script:`click to download <index>`. The target that the role is
384+
Which produces a link like this: :jupyter-download-nb:`click to download <index>`. The target that the role is
385385
applied to (``index`` in this case) is the name of the document for which you wish to download
386386
the code. If a document contains ``jupyter-kernel`` directives with ``:id:`` specified, then
387387
the name provided to ``:id:`` can be used to get the code for the cells belonging to the

jupyter_sphinx/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,13 @@ def setup(app):
271271
app.add_directive("jupyter-input", CellInput)
272272
app.add_directive("jupyter-output", CellOutput)
273273
app.add_directive("thebe-button", ThebeButton)
274-
app.add_role("jupyter-download:notebook", JupyterDownloadRole())
275-
app.add_role("jupyter-download:nb", JupyterDownloadRole())
276-
app.add_role("jupyter-download:script", JupyterDownloadRole())
274+
for sep in [":", "-"]:
275+
# Since Sphinx 4.0.0 using ":" inside of a role/directive does not work.
276+
# Therefore, we add "-" as separator to get e.g., jupyter-download-notebook
277+
# We leave the ":" syntax for backward compatibility reasons.
278+
app.add_role(f"jupyter-download{sep}notebook", JupyterDownloadRole())
279+
app.add_role(f"jupyter-download{sep}nb", JupyterDownloadRole())
280+
app.add_role(f"jupyter-download{sep}script", JupyterDownloadRole())
277281
app.add_transform(CombineCellInputOutput)
278282
app.add_transform(ExecuteJupyterCells)
279283

jupyter_sphinx/ast.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ def apply_styling(node, thebe_config):
587587

588588
class JupyterDownloadRole(ReferenceRole):
589589
def run(self):
590-
_, filetype = self.name.split(":")
590+
sep = ":" if ":" in self.name else "-"
591+
_, filetype = self.name.rsplit(sep, maxsplit=1)
591592

592593
assert filetype in ("notebook", "nb", "script")
593594
ext = ".ipynb" if filetype in ("notebook", "nb") else ".py"

tests/test_execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def test_download_role(text, reftarget, caption, tmp_path):
610610
"reporter.get_source_and_line": lambda l: ("source", l),
611611
}
612612
mock_inliner.configure_mock(**config)
613-
ret, msg = role("jupyter-download:notebook", text, text, 0, mock_inliner)
613+
ret, msg = role("jupyter-download-notebook", text, text, 0, mock_inliner)
614614

615615
if os.name == "nt":
616616
# Get equivalent abs path for Windows

0 commit comments

Comments
 (0)