Allow `?config=... in mathjax_path` (#11659)

This commit is contained in:
Adam Turner 2023-08-30 19:35:29 +01:00 committed by GitHub
parent 4692208fde
commit 7d046a862f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -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
-------

View File

@ -1085,7 +1085,13 @@ class StandaloneHTMLBuilder(Builder):
return f'<script>{body}</script>'
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'<script {" ".join(sorted(attrs))} src="{uri}"></script>'

View File

@ -283,6 +283,34 @@ def test_mathjax_options_defer_for_mathjax2(app, status, warning):
assert ('<script defer="defer" src="%s">' % MATHJAX_URL in content)
@pytest.mark.sphinx(
'html', testroot='ext-math',
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax_path': 'MathJax.js',
},
)
def test_mathjax_path(app):
app.builder.build_all()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<script async="async" src="_static/MathJax.js"></script>' 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 '<script async="async" src="_static/MathJax.js?config=scipy-mathjax"></script>' 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):