Adds configurable mathjax cdn - #23
Conversation
Introduces WAGTAILPOLYMATH_MATHJAX_URL and WAGTAILPOLYMATH_MATHJAX_SRI settings so users can point at a different CDN or self-hosted copy of MathJax instead of the pinned jsdelivr default. Centralises URL/SRI resolution in a new wagtail_polymath.settings module, used by both the admin widget preview and the mathjax_script template tag, removing the previously duplicated URL-building logic. Overriding the URL without a matching SRI hash simply omits the integrity/crossorigin attributes rather than erroring; the default (no override) behaviour is unchanged.
Exercises the default, custom-URL-only, and custom-URL-with-SRI resolution states against both MathJaxWidget.media and the mathjax_script template tag, plus direct unit tests of get_mathjax_url/get_mathjax_integrity.
Adds a Configuration section to the README covering WAGTAILPOLYMATH_MATHJAX_URL/WAGTAILPOLYMATH_MATHJAX_SRI, and notes the change plus the MATHJAX_VERSION/MATHJAX_SRI relocation in the changelog.
All wagtail-polymath settings are now defined in a single WAGTAIL_POLYMATH dict, with a WagtailPolymathSettings class exposed as wagtail_polymath_settings for reading the resolved values (mathjax_url / mathjax_sri).
9a16096 to
694751f
Compare
Adds an openssl recipe for generating the SRI hash for a custom mathjax_url, noting that sha256sum/shasum output hex rather than the base64 encoding the integrity attribute requires.
| ```python | ||
| # settings.py | ||
| WAGTAIL_POLYMATH = { | ||
| "mathjax_url": "https://example.com/path/to/tex-mml-chtml.js", |
There was a problem hiding this comment.
my last item for pause is whether we use the full URL to the library, or the URL base (i.e. https://example.com/path/to/), thus hard-coding tex-mml-chtml.js as that is what we account for in the initialisation script 🤔
On one hand the full library URL gives extra flexibility, on the other we don't have much control.
I say let's go with the full URL for now, but leave the option open to change things if we want to
There was a problem hiding this comment.
Pull request overview
This PR makes MathJax script loading configurable by introducing a centralized WAGTAIL_POLYMATH settings wrapper and using it from both the Wagtail admin widget and the mathjax_script template tag, while documenting and testing the new behavior.
Changes:
- Added
wagtail_polymath_settings(with defaults) to resolvemathjax_url/mathjax_srifrom Django settings. - Updated
MathJaxWidgetmedia and themathjax_scripttemplate tag to use the resolved URL/SRI (omitting SRI attributes when not provided for custom URLs). - Added documentation and tests covering default, custom-URL-only, and custom-URL+SRI scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/wagtail_polymath/settings.py |
Introduces defaults + settings wrapper used by other components. |
src/wagtail_polymath/widgets.py |
Loads MathJax in the admin widget via resolved settings and conditional SRI attributes. |
src/wagtail_polymath/templatetags/wagtail_polymath.py |
Loads MathJax in templates via resolved settings and conditional SRI attributes. |
tests/test_settings.py |
Verifies default/custom URL/SRI behavior for both widget media and template tag output. |
README.md |
Documents the new WAGTAIL_POLYMATH configuration surface and SRI guidance. |
CHANGELOG.md |
Announces the new configuration mechanism and notes upgrade considerations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Some users need to point at a different CDN, an internal mirror, or a self-hosted copy of MathJax...
This adds support for configuring the MathJax CDN URL (and its SRI hash) via settings, instead of always loading MathJax from the pinned jsdelivr URL.
Added the
WAGTAIL_POLYMATHsetting with:mathjax_urlfull URL to the MathJax script. Defaults to the existing pinned jsdelivr URL if unset.mathjax_srioptional Subresource Integrity hash to pair with a custom URL. Only has an effect alongsideWAGTAILPOLYMATH_MATHJAX_URL; the default URL always uses its own pinned hash.integrity/crossoriginattributes are omitted.