Skip to content
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c2b18d0
WIP: design doc for sphinxcontrib-jquery
benjaoming Oct 17, 2022
d0160d2
First draft of sphinxcontrib-jquery design doc
benjaoming Oct 17, 2022
170822f
Updates to clarify add_jquery_if_sphinx_lt_6
benjaoming Oct 17, 2022
7b32111
Wrong year
benjaoming Oct 17, 2022
020e8cb
Move comment deadline to dl
benjaoming Oct 17, 2022
e3abead
Adds further references
benjaoming Oct 17, 2022
970d54d
Update docs/dev/design/sphinx-jquery.rst
benjaoming Oct 17, 2022
9094143
First iteration on comments from @humitos
benjaoming Oct 17, 2022
56287af
Update docs/dev/design/sphinx-jquery.rst
benjaoming Oct 17, 2022
0452b1b
Adds 2 @humitos suggestions manually after GitHub suggestions stopped…
benjaoming Oct 17, 2022
22eeafc
Merge branch 'sphinxcontrib-jquery' of github.com:benjaoming/readthed…
benjaoming Oct 17, 2022
3b16ca2
Add force=False kwarg and have only one function ``add_jquery``.
benjaoming Oct 17, 2022
1762cb3
Use `setup_extension` + add config value for forcing jquery inclusion
benjaoming Oct 18, 2022
093c873
Adds dependencies, Python 2.7 and Sphinx 1.8, cc: @AA-Turner
benjaoming Oct 18, 2022
76e8a55
Change dependencies to read Python 3+ and Sphinx 1.8+ for now, let's …
benjaoming Oct 18, 2022
c9eb6a8
Update docs/dev/design/sphinx-jquery.rst
benjaoming Oct 24, 2022
9e36fee
Merge branch 'main' of github.com:readthedocs/readthedocs.org into sp…
benjaoming Oct 24, 2022
86c6c3f
Remove release cycle proposal, it's up to @AA-Turner :)
benjaoming Oct 24, 2022
c361683
Merge branch 'sphinxcontrib-jquery' of github.com:benjaoming/readthed…
benjaoming Oct 24, 2022
02a53ed
Update docs/dev/design/sphinx-jquery.rst
benjaoming Oct 24, 2022
8e84d00
Update docs/dev/design/sphinx-jquery.rst
benjaoming Oct 24, 2022
039606e
Remove specific mentioning of jQuery versions, add a note about bundl…
benjaoming Oct 24, 2022
36ff76e
Merge branch 'sphinxcontrib-jquery' of github.com:benjaoming/readthed…
benjaoming Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions docs/dev/design/sphinx-jquery.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
sphinxcontrib-jquery
====================

jQuery will be removed from Sphinx 6.0.0. We can expect 6.0.0 to ship in late 2022.

.. seealso::

* https://github.com/sphinx-doc/sphinx/issues/7405
* https://github.com/sphinx-doc/sphinx/issues/10070
* https://github.com/readthedocs/sphinx-hoverxref/issues/160
* https://github.com/readthedocs/sphinx_rtd_theme/issues/1253
* https://github.com/pydata/pydata-sphinx-theme/issues/764

This is a "request for comments" for a community-owned Sphinx extension that bundles jQuery.


Overview
--------

Comment deadline:
November 1st, 2022

Package-name:
``sphinxcontrib-jquery``

Python package:
``sphinxcontrib.jquery``

Dependencies:
Python 3+, Sphinx 1.8+ (or perhaps no lower bound?)

Ownership:
Read the Docs core team will implement the initial releases of an otherwise community-owned package that lives in https://github.com/sphinx-contrib/jquery

Functionality:
sphinxcontrib-jquery is a Sphinx extension that provides a simple mechanism for other Sphinx extensions and themes to ensure that jQuery is included into the HTML build outputs and loaded in the HTML DOM itself.
More specifically, the extension ensures that jQuery is loaded exactly once no matter how many themes and extensions that request to include jQuery nor the version of Sphinx.

Scope:
This extension assumes that it's enough to provide a single version of jQuery for all of its dependent extensions and themes.
As the name implies, this extension is built to handle jQuery only.
It's not a general asset manager and it's not looking to do dependency resolution of jQuery versions.

Usage
-----

The primary users of this package are
**theme and extension developers** and
**documentation project owners**.


Theme and extension developers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following 2 steps need to be completed:

#. A Sphinx theme or extension should depend on the python package ``sphinxcontrib-jquery``.
#. In your extension's or theme's ``setup(app)``, call ``app.setup_extension("sphinxcontrib.jquery")``.

In addition to this, we recommend extension and theme developers to log to the browser's ``console.error`` in case jQuery isn't found. The log message could for instance say::

if (typeof $ == "undefined") console.error("<package-name> depends on sphinxcontrib-jquery. Please ensure that <package-name>.setup(app) is called or add 'sphinxcontrib-jquery' to your conf.py extensions setting.")


Documentation project owners
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are depending on a theme or extension that did not itself address the removal of jQuery from Sphinx 6, you can patch up your project like this:

#. Add ``sphinxcontrib-jquery`` to your installed dependencies.
#. Add ``sphinxcontrib.jquery`` to your ``extensions`` setting in ``conf.py``.


Calling ``app.setup_extension("sphinxcontrib.jquery")``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When a Sphinx theme or extension calls `setup_extension() <https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.setup_extension>`_, a call to ``sphinxcontrib.jquery.setup(app)`` will happen. Adding ``sphinxcontrib.jquery`` to a documentation project's ``conf.extensions`` will also call ``sphinxcontrib.jquery.setup(app)`` (at most once).

In ``sphinxcontrib.jquery.setup(app)``, jQuery is added. The default behaviour is to detect the Sphinx version and include jQuery via `app.add_js_file <https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_js_file>`__ when Sphinx is from version 6 and up. jQuery is added at most once.


Config value: ``jquery_force_enable``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When setting ``jquery_force_enable=True``, jQuery is added no matter the Sphinx version, but at most once. This is useful if you want to handle alternative conditions for adding jQuery.

.. warning::

If you set ``jquery_force_enable=True``, you most likely should also add ``Sphinx>=6`` to your theme's/extension's dependencies since versions before this already bundles jQuery!


jQuery version and inclusion
----------------------------

jQuery should be be shipped together with the Python package and not be referenced from a CDN.

Sphinx has kept relatively up to date with jQuery, and this package intends to follow.
The most recently bundled jQuery version was v3.5.1 and only two releases have happened since: 3.6.0 and 3.6.1.
The 3.6.0 release had a very small backwards incompatibility which illustrates how harmless these upgrades are for the general purpose Sphinx package.

Therefore, we propose to start the release of ``sphinxcontrib-jquery`` at 3.5.1 (the currently shipped version) and subsequently release 3.6.1 in an update. This will give users that need 3.5.1 a choice of a lower version.

The bundled jQuery version will be NPM pre-minified and distributed together with the PyPI package.

The minified jQuery JS file is ultimately included by calling `app.add_js_file <https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_js_file>`__, which is passed the following arguments:

.. code:: python

app.add_js_file(
get_jquery_url_path(),
loading_method="defer",
priority=200,
integrity="sha256-{}".format(get_jquery_sha256_checksum())
)


.. note:: It's possible to include jQuery in other ways, but this ultimately doesn't require this extension and is therefore not supported.