Skip to content
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

MathJax asset file checksums #11659

Merged
merged 8 commits into from Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
-------
Expand Down
8 changes: 7 additions & 1 deletion sphinx/builders/html/__init__.py
Expand Up @@ -1085,7 +1085,13 @@ def js_tag(js: _JavaScript | str) -> str:
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>'
Expand Down
28 changes: 28 additions & 0 deletions tests/test_ext_math.py
Expand Up @@ -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):
Expand Down