Browse Source

Load MathJax config without eval() (#735)

This allows stricter content security policies for 
`Content-Security-Policy` header.
Thom Wiggers 6 years ago
parent
commit
8d8cddfdb2
2 changed files with 9 additions and 8 deletions
  1. 6 0
      assets/js/mathjax-config.js
  2. 3 8
      layouts/partials/footer.html

+ 6 - 0
assets/js/mathjax-config.js

@@ -0,0 +1,6 @@
+window.MathJax = {
+  CommonHTML: { linebreaks: { automatic: true } },
+  tex2jax: { inlineMath: [ ['$', '$'], ['\\(','\\)'] ], displayMath: [ ['$$','$$'], ['\\[', '\\]'] ], processEscapes: false },
+  TeX: { noUndefined: { attributes: { mathcolor: 'red', mathbackground: '#FFEEEE', mathsize: '90%' } } },
+  messageStyle: 'none'
+};

+ 3 - 8
layouts/partials/footer.html

@@ -2,14 +2,9 @@
 
     {{/* Config LaTeX math rendering. */}}
     {{ if or .Params.math .Site.Params.math }}
-    <script type="text/x-mathjax-config">
-      MathJax.Hub.Config({
-        CommonHTML: { linebreaks: { automatic: true } },
-        tex2jax: { inlineMath: [ ['$', '$'], ['\\(','\\)'] ], displayMath: [ ['$$','$$'], ['\\[', '\\]'] ], processEscapes: false },
-        TeX: { noUndefined: { attributes: { mathcolor: 'red', mathbackground: '#FFEEEE', mathsize: '90%' } } },
-        messageStyle: 'none'
-      });
-    </script>
+    {{ $mathjax_config := resources.Get "js/mathjax-config.js" }}
+    {{ $secureJS := $mathjax_config | resources.Fingerprint "sha512" }}
+    <script src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
     {{ end }}
 
     {{/* Attempt to load local vendor JS, otherwise load from CDN. */}}