Skip to content

Commit 7e8bb9a

Browse files
committed
docs: document how to generate a custom mathjax_sri hash
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.
1 parent 694751f commit 7e8bb9a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ WAGTAIL_POLYMATH = {
116116
`mathjax_sri` has no effect unless `mathjax_url` is also set — the built-in
117117
default URL always uses its own pinned hash.
118118

119+
To generate the hash for your chosen file, download it and use `openssl`.
120+
Note that the `integrity` attribute requires a **base64**-encoded digest —
121+
`sha256sum`/`shasum` produce a hex digest instead, which will not work:
122+
123+
```sh
124+
openssl dgst -sha256 -binary tex-mml-chtml.js | openssl base64 -A
125+
```
126+
127+
Prefix the output with `sha256-` to get the full `mathjax_sri` value:
128+
129+
```python
130+
WAGTAIL_POLYMATH = {
131+
"mathjax_url": "https://example.com/path/to/tex-mml-chtml.js",
132+
"mathjax_sri": "sha256-dPV35kaoLq1rg+JbYf8p1kTrZamwMY+XIwaWUPwqtpU=",
133+
}
134+
```
135+
119136
Both settings apply to the MathJax script loaded in the Wagtail admin (for
120137
the `MathBlock` live preview) and the one loaded by the `mathjax_script`
121138
template tag. Note that the bundled preview JS assumes MathJax's combined

0 commit comments

Comments
 (0)