-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sphinx_rtd_theme.css disappears if html_context['css_files'] is used #2116
Comments
So, this is something that we could protect against in https://github.com/rtfd/readthedocs-sphinx-ext, but the fact that you are overriding the context passed into the template is the real culprit. If you are trying to add a css_file, this isn't the prescribed method. You can add to def setup(app):
app.add_stylesheet('file.css')
app.add_javascript('file.js') |
Thanks, that works! But this cannot be the proper solution, that's clearly a work-around. Why should I not be allowed to use html_context? I've read readthedocs/sphinx_rtd_theme#117 (comment), but that doesn't give any reasons ... And why whould it work locally but not on RTD? Can you please point me to the code that is supposed to add the CSS file on RTD? I'm not saying that there's a bug in RTD, it might as well be a bug in Sphinx or somewhere else, but a bug it definitely is! |
I don't think this is a bug anywhere, as the outcome is exactly as I'd expect. You are explicitly redefining You can still use It's working locally for you because you aren't building docs using our extension and related build overrides. |
I disagree. Using a The standard configuration pattern is to assign values to the options mentioned in http://www.sphinx-doc.org/en/stable/config.html. It's the extensions that should honor the user settings and append (or rather prepend) to and not redefine those. I had a look at the RTD extension, and I found this (around line 75): app.builder.css_files.insert(0, theme_css) I don't know exactly what's happening, but this looks like the intention was to insert the CSS file in the beginning of the list (which seems to make sense), but somehow this has no effect if Can anyone explain why this happens? Interestingly, the same thing (which is IMHO the wrong thing) happens when using app.add_stylesheet(). |
I've created a Sphinx issue to find out about the intended behavior: sphinx-doc/sphinx#2442 |
I've described why above: you are overriding the context variable passed into the template processor -- at the very last point before templating. Normally, Sphinx does not imply you should override The option to override is there nonetheless, and you are free to use it, but the outcome is exactly what you describe -- you are overriding other attempts to add to |
Changed config based on suggestion in: readthedocs/readthedocs.org#2116 Approved-by: Michel Steuwer
I agree with @mgeier : Locally, the RTD theme builds correctly: on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = ['.', sphinx_rtd_theme.get_html_theme_path()]
html_context = {
'css_files': [
'_static/theme_overrides.css', # override wide tables in RTD theme
],
} This will create a nice, functional local build - and then break on the RTD server. I think my configuration is intuitive and to the point. |
…d theme_overrides.css without overriding the entire theme when on remote RTD server See: readthedocs/readthedocs.org#2116 readthedocs/sphinx_rtd_theme#432
@benjaoming Thanks for your support! Can you please also add your opinion to sphinx-doc/sphinx#2442? Because if I'm not mistaken, that should solve the issue here. |
@mgeier sounds like sphinx-doc/sphinx#2442 is the root cause? |
@benjaoming Yes, I think so. But it looks like my issue didn't convince the Sphinx people to do something about it ... |
Instead of performing theme corrections using the 'css_files' options, use the application instance's `add_stylesheet` instead. This prevents issues where overriding the theme affects ReadTheDoc's theme [1]. [1]: readthedocs/readthedocs.org#2116 Signed-off-by: James Knight <[email protected]>
Seems like the issue was solved in the sphinx side sphinx-doc/sphinx#2442 (comment) |
I'm using this in my
conf.py
:This looks harmless, but it somehow causes RTD not to include this into the HTML pages:
Here's an example: http://nbsphinx.readthedocs.org/en/readthedocs-theme/
[Note for future readers: in the future the problem will be hopefully gone!]
For comparison, here's a version without
css_files
, wheresphinx_rtd_theme.css
is included correctly: http://nbsphinx.readthedocs.org/en/0.2.5/IIRC, all this was still working fine one or two weeks ago ...
Here's a screenshot how a broken page looks like: jupyter/notebook#1305
The text was updated successfully, but these errors were encountered: