Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

### Updates

- `sphinx-thebe` now uses the correct and latest version of thebe, since it has been renamed from `thebelab` to `thebe`.
- `sphinx-thebe` now uses the correct and latest version of thebe, since it has been renamed from `thebelab` to `thebe`.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# "codemirror-theme": "blackboard" # Doesn't currently work
}

myst_admonition_enable = True
myst_enable_extensions = ["colon_fence"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
3 changes: 2 additions & 1 deletion docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ There are two steps to using `sphinx-thebe`. First, you must mark certain
parts of your page as "ready for thebe". Next, you must insert a button onto
the page to tell Thebe to initialize.

:::{admonition,tip} Using reStructuredText vs. MyST Markdown
:::{admonition} Using reStructuredText vs. MyST Markdown
:class: tip
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.
:::

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"sphinx_thebe": ["_static/sphinx-thebe.css", "_static/sphinx-thebe.js",]
},
classifiers=["License :: OSI Approved :: MIT License"],
install_requires=["sphinx>=1.8"],
install_requires=["sphinx>=3.5,<5"],
extras_require={
"sphinx": [
"myst-parser[sphinx]",
Expand Down
24 changes: 19 additions & 5 deletions sphinx_thebe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@ def init_thebe_default_config(app, env, docnames):
thebe_config[key] = val


def init_thebe_core(app, env):
config_thebe = app.config["thebe_config"]
def _check_if_load_thebe(doctree, config_thebe):
"""Decide whether to load thebe based on the page's context."""
# Only load `thebe` if there is a thebe button somewhere
if not doctree or (not doctree.traverse(ThebeButtonNode)):
return

if not config_thebe:
logger.warning("Didn't find `thebe_config` in conf.py, add to use thebe")
return

return True


def init_thebe_core(app, pagename, templatename, context, doctree):
"""Load thebe assets if there's a thebe button on this page."""
config_thebe = app.config["thebe_config"]
if not _check_if_load_thebe(doctree, config_thebe):
return

# Add core libraries
opts = {"async": "async"}
app.add_js_file(filename="https://unpkg.com/thebe@latest/lib/index.js", **opts)
Expand All @@ -53,7 +66,7 @@ def init_thebe_core(app, env):
def update_thebe_context(app, doctree, docname):
"""Add thebe config nodes to this doctree."""
config_thebe = app.config["thebe_config"]
if not config_thebe:
if not _check_if_load_thebe(doctree, config_thebe):
return

# Thebe configuration
Expand Down Expand Up @@ -191,9 +204,10 @@ def setup(app):
# Set default values for the configuration
app.connect("env-before-read-docs", init_thebe_default_config)

# Include Thebe core docs
# Update the doctree with thebe-specific information if needed
app.connect("doctree-resolved", update_thebe_context)
app.connect("env-updated", init_thebe_core)
# Load the JS/CSS assets for thebe if needed
app.connect("html-page-context", init_thebe_core)

# configuration for this tool
app.add_config_value("thebe_config", {}, "html")
Expand Down