-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Close #6241: html: Allow to add JS/CSS files to the specific page #8631
Conversation
Does this happen purely "under the hood" (AKA without any extra user configuration) as long as
Is that right? If so, I think this is awesome :-) Also - maybe this should be documented here: https://www.sphinx-doc.org/en/master/extdev/appapi.html#event-html-page-context ? |
Yes, you're right.
Thanks. I'll update it too. |
Should probably also be mentioned here:
(or cross-referenced). Otherwise I suspect users will be confused when there's different behavior based on context that isn't documented |
e3e9bda
to
b197bf0
Compare
We're using autodoc to build out document. So the docstrings are automatically applied to the docs. |
I have two considerations that may be relevant here:
|
A quick thought from me:
I think it would be possible with something like: def add_per_page_css(<html-page-context-args>):
if pagename in <[list-of-pagenames]>:
app.add_css_file(<my-css-file>)
def setup(app):
app.connect("html-page-context", add_per_page_css) IMO this would be a useful snippet in the documentation somewhere. Maybe somewhere around https://www.sphinx-doc.org/en/master/development/theming.html?highlight=%22add_css_file%22 ? |
I see, I didn't realize that one can add a setup function to
So it doesn't need a separate action then. |
At present, the order of JS/CSS is not mentioned in its specification at all. So it is not defined and not controllable. Please file another issue to control the order if important. For now, I don't have a plan to implement it because I don't know how worth for Sphinx. Of course, I understand it'ss important when building interactive website. But Sphinx is mainly used for the static pages. |
I don't know how many users would like to add JS/CSS conditionally. Additionally, it would be tough to design and implement a new "conditional" configuration. So I'd not like to support conditional JS/CSS via configurations. IMO, it's not difficult to create a custom event handler in |
With JS the order probably doesn't matter anyway because it's loaded asynchronously. The order of CSS is however important also in static pages and whenever an extension injects its CSS after user's
While the order of CSS is not documented (I'll open an issue about that), it is in practice controllable. The two issues I linked above show that documentation authors do in fact expect being able to override the extension or theme CSS. This PR would remove such ability. |
Absolutely. I perfectly understand why the order of CSS is important. We have to add a priority feature to CSS API first. |
Now I posted #8639 to control the order of JS/CSS. It helps that the JS/CSS files registered at the |
Yes. I thought this would be a breaking change. So it would be better to merge this into 4.0. But I'm debating now because it's a very minor change. |
88190bd
to
4d54a41
Compare
I think it’d be great if this were in 3.5. I feel like it is a quite “under the hood” change - the “breaking” effect would only affect people who were
I suspect that this is a pretty small group of people...perhaps we could just log an info statement saying that the behavior has changed or something? |
edb5a55
to
4d14317
Compare
Thank you for comment. Finally, I determined to merge this into the 3.x branch. |
…c page Allow to add JS/CSS files to the specific page when an extension calls `app.add_js_file()` or `app.add_css_file()` on `html-page-context` event.
4d14317
to
af4e615
Compare
Is there a way to configure this to behave as it was? I mean, including all the JS and CSS files in all the pages even if they "are not used" in that page? I'm asking because in my extension Example:
This is because the page Edit: Note that using Sphinx<3.5 my problem disappears. |
Sphinx 3.5.x includes a feature to only include the JS and CSS on the pages that they are used. This conflicts when we render content that uses MathJax, since the page that shows the tooltip does not has MathJax loaded, but the content rendered inside the tooltip requires it to work. See sphinx-doc/sphinx#8631
Sphinx 3.5.x includes a feature to only include the JS and CSS on the pages that they are used. This conflicts when we render content that uses MathJax, since the page that shows the tooltip does not has MathJax loaded, but the content rendered inside the tooltip requires it to work. See sphinx-doc/sphinx#8631
I think that I will have the same problem with other 3rd party extensions start using this feature as well. For example in https://sphinx-hoverxref.readthedocs.io/en/latest/usage.html#tooltip-with-sphinx-tabs if you hover "tooltip with Sphinx Tabs" you will see a bigger tooltip that renders tabs ("from PyPI" and "from GitHub") that won't work when |
@humitos Could you send a feature request, please? Then I'll consider it later. |
Great, thanks! I've created the issue at #9115 |
Feature or Bugfix
Purpose
app.add_js_file()
orapp.add_css_file()
onhtml-context-page
event.