Skip to content

Commit 8dcf591

Browse files
authored
Merge pull request #3164 from ianhi/binder-on-page
Add a binder link to the top of notebooks in the docs
2 parents d35010f + 0afabb2 commit 8dcf591

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/source/conf.py

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@
2929
'jupyter': ('https://jupyter.readthedocs.io/en/latest/', None),
3030
}
3131

32+
33+
# prolog based on https://github.com/spatialaudio/nbsphinx/blob/98005a9d6b331b7d6d14221539154df69f7ae51a/doc/conf.py#L38
34+
nbsphinx_prolog = r"""
35+
{% set docname_link = env.doc2path(env.docname, base=None).replace(' ', '%20') %}
36+
{% set docname_display = env.doc2path(env.docname, base=None) %}
37+
38+
.. raw:: html
39+
40+
<div class="admonition note">
41+
This page was generated from
42+
<a class="reference external" href="https://github.com/jupyter-widgets/ipywidgets/blob/{{ env.config.release|e }}/docs/source/{{ docname_link|e }}">{{ docname_display|e }}</a>.<br>
43+
Interactive online version:
44+
<span style="white-space: nowrap;"><a href="https://mybinder.org/v2/gh/jupyter-widgets/ipywidgets/{{ env.config.release|e }}?urlpath=lab/tree/docs/source/{{ docname_link|e }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"></a>.</span>
45+
</div>
46+
47+
.. raw:: latex
48+
49+
\nbsphinxstartnotebook{\scriptsize\noindent\strut
50+
\textcolor{gray}{The following section was generated from
51+
\sphinxcode{\sphinxupquote{\strut {{ docname | escape_latex }}}} \dotfill}}
52+
"""
53+
3254
nbsphinx_execute = 'always'
3355

3456
# -- General information -------

0 commit comments

Comments
 (0)