From 7d046a862f06631367984b87c1e8c2acb518de4f Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:35:29 +0100 Subject: [PATCH] Allow ``?config=...`` in ``mathjax_path`` (#11659) --- CHANGES | 1 + sphinx/builders/html/__init__.py | 8 +++++++- tests/test_ext_math.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 8465a6bf7d3..64aa161dfe2 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Bugs fixed * #11634: Fixed inheritance diagram relative link resolution for sibling files in a subdirectory. Patch by Albert Shih. +* #11659: Allow ``?config=...`` in :confval:`mathjax_path`. Testing ------- diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 3515edd44aa..85067be0178 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -1085,7 +1085,13 @@ def js_tag(js: _JavaScript | str) -> str: return f'' uri = pathto(os.fspath(js.filename), resource=True) - if checksum := _file_checksum(outdir, js.filename): + if 'MathJax.js?' in os.fspath(js.filename): + # MathJax v2 reads a ``?config=...`` query parameter, + # special case this and just skip adding the checksum. + # https://docs.mathjax.org/en/v2.7-latest/configuration.html#considerations-for-using-combined-configuration-files + # https://github.com/sphinx-doc/sphinx/issues/11658 + pass + elif checksum := _file_checksum(outdir, js.filename): uri += f'?v={checksum}' if attrs: return f'' diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 9e2367fe3fd..d5331f839bf 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -283,6 +283,34 @@ def test_mathjax_options_defer_for_mathjax2(app, status, warning): assert ('' in content + + +@pytest.mark.sphinx( + 'html', testroot='ext-math', + confoverrides={ + 'extensions': ['sphinx.ext.mathjax'], + 'mathjax_path': 'MathJax.js?config=scipy-mathjax', + }, +) +def test_mathjax_path_config(app): + app.builder.build_all() + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + assert '' in content + + @pytest.mark.sphinx('html', testroot='ext-math', confoverrides={'extensions': ['sphinx.ext.mathjax']}) def test_mathjax_is_installed_only_if_document_having_math(app, status, warning):