jupyter / jupyter-sphinx

Sphinx extension for rendering of Jupyter interactive widgets.
https://jupyter-sphinx.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
188 stars 65 forks source link

Thebe assets added to html head but not added to _static #163

Open jorisvandenbossche opened 4 years ago

jorisvandenbossche commented 4 years ago

Using jupyter-sphinx pydata-sphinx-theme docs (https://pydata-sphinx-theme.readthedocs.io/en/latest/), I noticed that it gives errors in the browser console related to thebe css/js:

/_static/thebelab.css(127.0.0.1) | Failed to load resource: the server responded with a status of 404 (Not Found)
...

This seems to be caused because it is added to the html output of sphinx. From the source of the html of the url linked above:

...
    <link rel="stylesheet" type="text/css" href="_static/jupyter-sphinx.css" />
    <link rel="stylesheet" type="text/css" href="_static/thebelab.css" />
....

But this thebelab.css is not actually to the _static dir of the build html. And thus giving a 404 error.

Based on a quick look, I think this is because here the thebelab css is only copied if there is a configuration active:

https://github.com/jupyter/jupyter-sphinx/blob/43280f89b1558b043aa51e7b3b007db2fe834b89/jupyter_sphinx/__init__.py#L122-L132

but it gets always registered to sphinx regardless of that configuration option:

https://github.com/jupyter/jupyter-sphinx/blob/43280f89b1558b043aa51e7b3b007db2fe834b89/jupyter_sphinx/__init__.py#L284-L287

chrisjsewell commented 4 years ago

This is timely, given the comment I just made in https://github.com/executablebooks/meta/issues/119#issuecomment-683670162.

You should probably use the mathjax approach to only add JS (but CSS in this case) given an env value you set when you copy the CSS: https://github.com/sphinx-doc/sphinx/blob/a16cca27ef1415ff271084f156e0fb33ccfbefae/sphinx/ext/mathjax.py#L84

akhmerov commented 4 years ago

Tricky: injecting css during build prevents users from overriding it since it is then inserted after the user-provided css.

This change is due to fixing #149

jorisvandenbossche commented 4 years ago

The original issue report was about jupyter-sphinx.css, which could still be kept in the app setup. Of course the same issue applies to thebelab.css, but that is maybe less common to want to override?

akhmerov commented 4 years ago

This comment https://github.com/sphinx-doc/sphinx/issues/6241#issuecomment-705070598 contains an implementation of conditional js/css inclusion, however I believe the proper way to address this issue is to switch to sphinx-thebe #137

Still, we may want to use the same logic for widgets code.