executablebooks / sphinx-thebe

A Sphinx extension to convert static code into interactive code cells with Jupyter, Thebe, and Binder.
https://sphinx-thebe.readthedocs.io/en/latest/
MIT License
28 stars 15 forks source link

Allow loading logic that doesn't depend on `ThebeButtonNode` #34

Closed choldgraf closed 2 years ago

choldgraf commented 3 years ago

Description / Summary

Right now sphinx-thebe will only load if it detects ThebeButtonNode on a page. However, if a theme is using sphinx-thebe to load thebe, but not the ThebeButtonNode, then thebe won't load for them. We should find some way around this and also determine how common of a use-case this is.

Value / benefit

This is useful for anyone that wants to piggy-back off of this extension but without using the directives provided by this theme. A good examples of this is the Sphinx Book Theme, which manually activates thebe:

https://github.com/executablebooks/sphinx-book-theme/blob/9a2da30342ace86978ddbd345eb69f5b4479b31c/sphinx_book_theme/topbar/launchbuttons.html#L29

and this logic is triggered here:

https://github.com/executablebooks/sphinx-book-theme/blob/e05def5b9a4fc777f702553a0bcaf7939440dbd3/sphinx_book_theme/launch.py#L118

Implementation details

A couple ideas:

Tasks to complete

choldgraf commented 3 years ago

cc @akhmerov - do you have any thoughts about how we could most-easily decide whether to load thebe in projects that aren't using the directive here?

akhmerov commented 3 years ago

I have refreshed my memory of how sphinx-thebe works, and indeed understand the problem now, with the selector being invisible as long as we only have the AST.

Would it make sense to change the sphinx-thebe configuration to take a node or a list of nodes instead, and add the class = 'thebe-container' attribute or something like that to those nodes?