Replies: 1 comment
-
The easiest way to do this is to write a local Sphinx extension. This can be a single Python file, e.g.
def config_initialised(app, config):
print(f"The current config is {config}")
def setup(app):
app.connect('config-inited', config_initialised) See https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx-core-events for more information on the Sphinx event system. Then, we need to configure JupyterBook to load this extension:
sphinx:
local_extensions:
test_extension: . where Right now this test app just prints the current configuration. We want to modify the JS file order. This can be done by changing the
def update_page_context(app, pagename, templatename, context, doctree):
...
def setup(app):
app.connect('html-page-context', update_page_context) Now we need to find our JS file, and tweak the ordering
def update_page_context(app, pagename, templatename, context, doctree):
# Look for file
for f in context['script_files']:
if f.filename == "some-js-file.js":
break
else:
return
# Set new priority, lower is more important
f.priority = 10
def setup(app):
app.connect('html-page-context', update_page_context) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
sphinxcontrib.mermaid
adds1 a JS file that conflicted withrequirejs
. I need to be able to change the order of extension loading to prevent this conflict, but this is controlled by Jupyter Book. Another approach is to manually re-order the added JS files, or modify the IPyWidgets configuration to change the JS priority.Of all of these options, it looks like the easiest will be to try and modify the priority of the loaded JS files.
How can I ask Sphinx to run my code to change order of the JS files?
Footnotes
This is no longer the case, but this Discussion is a case-study ↩
Beta Was this translation helpful? Give feedback.
All reactions