Skip to content

Adds configurable mathjax cdn - #23

Merged
zerolab merged 6 commits into
wagtail-nest:mainfrom
kevinhowbrook:feat/configurable-mathjax-cdn
Jul 17, 2026
Merged

Adds configurable mathjax cdn#23
zerolab merged 6 commits into
wagtail-nest:mainfrom
kevinhowbrook:feat/configurable-mathjax-cdn

Conversation

@kevinhowbrook

@kevinhowbrook kevinhowbrook commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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_POLYMATH setting with:

  • mathjax_url full URL to the MathJax script. Defaults to the existing pinned jsdelivr URL if unset.
  • mathjax_sri optional Subresource Integrity hash to pair with a custom URL. Only has an effect alongside WAGTAILPOLYMATH_MATHJAX_URL; the default URL always uses its own pinned hash.
  • If a custom URL is set without a matching SRI hash, the integrity/crossorigin attributes are omitted.

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.
Comment thread src/wagtail_polymath/settings.py Outdated
Comment thread README.md
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).
@kevinhowbrook
kevinhowbrook force-pushed the feat/configurable-mathjax-cdn branch from 9a16096 to 694751f Compare July 16, 2026 11:24
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.
@kevinhowbrook
kevinhowbrook marked this pull request as ready for review July 16, 2026 13:41
Comment thread README.md
```python
# settings.py
WAGTAIL_POLYMATH = {
"mathjax_url": "https://example.com/path/to/tex-mml-chtml.js",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 resolve mathjax_url / mathjax_sri from Django settings.
  • Updated MathJaxWidget media and the mathjax_script template 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.

Comment thread src/wagtail_polymath/settings.py
Comment thread src/wagtail_polymath/settings.py Outdated
Comment thread README.md
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@zerolab
zerolab merged commit 4176f02 into wagtail-nest:main Jul 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants