Skip to content

Commit 640d66b

Browse files
authored
📚 DOCS: updating docs for rst (#18)
* updating docs for rst * use docs * black
1 parent a989a65 commit 640d66b

4 files changed

Lines changed: 49 additions & 22 deletions

File tree

docs/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# Add any Sphinx extension module names here, as strings. They can be
3939
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4040
# ones.
41-
extensions = ["jupyter_sphinx", "sphinx_thebe", "myst_parser"]
41+
extensions = ["jupyter_sphinx", "sphinx_thebe", "myst_parser", "sphinx_panels"]
4242

4343
thebe_config = {
4444
"repository_url": "https://github.com/binder-examples/jupyter-stacks-datascience",
@@ -50,6 +50,8 @@
5050
# "codemirror-theme": "blackboard" # Doesn't currently work
5151
}
5252

53+
myst_admonition_enable = True
54+
5355
# Add any paths that contain templates here, relative to this directory.
5456
templates_path = ["_templates"]
5557

@@ -120,6 +122,7 @@
120122
# copybutton_image_path = "test/TEST_COPYBUTTON.png"
121123
# copybutton_selector = "div"
122124

125+
panels_add_bootstrap_css = False
123126

124127
# -- Options for HTMLHelp output ---------------------------------------------
125128

docs/configure.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ code and Thebe will detect it.
3535

3636
For example, the following code:
3737

38+
``````{tabbed} MyST Markdown
3839
`````
3940
````{container} thebe
4041
```{code-block} r
@@ -46,6 +47,18 @@ print("hi")
4647
```
4748
````
4849
`````
50+
``````
51+
52+
``````{tabbed} reStructuredText
53+
```{code-block} rst
54+
.. container:: thebe
55+
.. code-block:: r
56+
print("hi")
57+
58+
.. container:: output
59+
"hi"
60+
```
61+
``````
4962

5063
Defines a *parent container* in which we'll put both code and the output of the
5164
code. We'll use a `code-block` for the code, and another `container` node with our
@@ -132,12 +145,22 @@ qplot(hp, mpg, data=mtcars, shape=am, color=am,
132145
You can tag code blocks to run as soon as the kernel is ready (i.e., without any user input)
133146
by adding the `thebe-init` class to the code blocks. For example:
134147

148+
`````{tabbed} MyST Markdown
135149
````
136150
```{code-block}
137151
:class: thebe, thebe-init
138152
print("hi")
139153
```
140154
````
155+
`````
156+
`````{tabbed} reStructuredText
157+
```rst
158+
.. code-block::
159+
:class: thebe, thebe-init
160+
161+
print("hi")
162+
```
163+
`````
141164

142165
These code blocks will be run automatically once the kernel is ready, and their outputs
143166
will be displayed below.

docs/use.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,15 @@ There are two steps to using `sphinx-thebe`. First, you must mark certain
66
parts of your page as "ready for thebe". Next, you must insert a button onto
77
the page to tell Thebe to initialize.
88

9-
```{tip}
10-
The examples on this page use a flavor of markdown called [MyST Markdown](https://myst-parser.readthedocs.io/en/latest/).
11-
However you can also use reStructuredText with `sphinx-thebe` in the same way. See
12-
[](examples/rst) for some tips.
13-
```
9+
:::{admonition,tip} Using reStructuredText vs. MyST Markdown
10+
The examples on this page use **MyST Markdown syntax**, a form of markdown that works with Sphinx directives. You can also use reStructuredText if you wish. For information about reStructuredText vs. MyST Markdown, see [the MyST Parser documentation](https://myst-parser.readthedocs.io/en/latest/using/syntax.html) as well as [](examples/rst) for some tips.
11+
:::
1412

1513
### Mark elements for thebe
1614

1715
By default, thebe will be run on any elements in your documentation that contain
1816
the class `thebe` and that have a `<pre`> element underneath them.
1917

20-
```{note}
21-
This documentation is written in [MyST Markdown](https://myst-parser.readthedocs.io),
22-
so the syntax for writing directives looks different from reStructuredText. However,
23-
rST works just fine as well.
24-
```
25-
2618
You can add code blocks like so:
2719

2820
````
@@ -107,13 +99,15 @@ import matplotlib.pyplot as plt
10799
plt.scatter(*data, c=data[0], s=200)
108100
```
109101

110-
### Interactive outputs
102+
## Interactive outputs
111103

112-
Interactive outputs are still a little bit flaky, but please try out
113-
`sphinx-thebe` with the interactive visualization library of your choice,
114-
and report back how things work!
104+
Interactive outputs work with `sphinx-thebe` **if their web dependencies are loaded**.
105+
106+
Many interactive libraries assume that some javascript packages are pre-loaded in a notebook environment. For example, both Jupyter Lab and Notebook come bundled with `require.js`. To use visualization libraries that depend on this, **you must load these libraries on your own in Sphinx**. To do so, you can add the following to your `conf.py`:
107+
108+
```python
109+
def setup(app):
110+
app.add_js_file("url-of-package.js")
111+
```
115112

116-
As a general rule, `sphinx-thebe` will only work with interactive libraries
117-
that are able to output self-contained bundles of HTML/JS that work on their own.
118-
Many Jupyter environments have libraries pre-loaded, and that will not be the case
119-
with `sphinx-thebe`.
113+
Note that some visualization libraries output *bundles of JavaScript/HTML* that will work out-of-the-box. You should consult the documentation of the library you wish to use in order to figure out how to configure it properly. See [the `thebe` examples](https://thebe.readthedocs.io/en/latest/) for examples of some popular visualization libraries.

setup.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@
2323
url="https://github.com/executablebooks/sphinx-thebe",
2424
license="MIT License",
2525
packages=find_packages(),
26-
package_data={"sphinx_thebe": ["_static/sphinx-thebe.css", "_static/sphinx-thebe.js",]},
26+
package_data={
27+
"sphinx_thebe": ["_static/sphinx-thebe.css", "_static/sphinx-thebe.js",]
28+
},
2729
classifiers=["License :: OSI Approved :: MIT License"],
2830
install_requires=["sphinx>=1.8"],
2931
extras_require={
30-
"sphinx": ["myst-parser[sphinx]", "sphinx-book-theme", "jupyter-sphinx"],
32+
"sphinx": [
33+
"myst-parser[sphinx]",
34+
"sphinx-book-theme",
35+
"jupyter-sphinx",
36+
"sphinx-panels",
37+
],
3138
"testing": ["pytest", "pytest-regressions", "beautifulsoup4"],
3239
},
3340
)

0 commit comments

Comments
 (0)