Browse Source

Merge pull request #169 from barrysteyn/master

Add ability to specify SSL protocol
Justin Mayer 11 years ago
parent
commit
0b69e1bdb2
3 changed files with 18 additions and 4 deletions
  1. 6 0
      render_math/Readme.md
  2. 11 1
      render_math/math.py
  3. 1 3
      render_math/mathjax_script.txt

+ 6 - 0
render_math/Readme.md

@@ -106,6 +106,12 @@ sequences. **Default Value**: True
 rendering LaTex. If set to `Tex`, then the TeX code is used as the preview 
 (which will be visible until it is processed by MathJax). **Default Value**: `Tex`
  * `color`: controls the color of the mathjax rendered font. **Default Value**: `black`
+ * `ssl`: specifies if ssl should be used to load MathJax engine. Can be set to one
+of three things
+  * `auto`: **Default Value** will automatically determine what protodol to use 
+based on current protocol of the site. 
+  * `force`: will force ssl to be used.
+  * `off`: will ensure that ssl is not used
 
 For example, in settings.py, the following would make math render in blue and
 displaymath align to the left:

+ 11 - 1
render_math/math.py

@@ -167,7 +167,6 @@ def process_summary(instance, ignore_within):
         return match.group(1) + match.group(4)
 
     # check for partial math tags at end. These must be removed
-
     summary = _MATH_INCOMPLETE_TAG_REGEX.sub(incomplete_end_latex_tag, summary)
 
     if process_summary.altered_summary or insert_mathjax:
@@ -199,6 +198,11 @@ def process_settings(settings):
     _MATHJAX_SETTINGS['latex_preview'] = 'TeX'  # controls what user sees while waiting for LaTex to render
     _MATHJAX_SETTINGS['color'] = 'black'  # controls color math is rendered in
 
+    # Source for MathJax: default (below) is to automatically determine what protocol to use
+    _MATHJAX_SETTINGS['source'] = """'https:' == document.location.protocol
+                ? 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
+                : 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'"""
+
     # This next setting controls whether the mathjax script should be automatically
     # inserted into the content. The mathjax script will not be inserted into
     # the content if no math is detected. For summaries that are present in the
@@ -239,6 +243,12 @@ def process_settings(settings):
         if key == 'color' and isinstance(value, str):
             _MATHJAX_SETTINGS[key] = value
 
+        if key == 'ssl' and isinstance(value, str):
+            if value == 'off':
+                _MATHJAX_SETTINGS['source'] = "'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'"
+
+            if value == 'force':
+                _MATHJAX_SETTINGS['source'] = "'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'"
 
 def process_content(instance):
     """Processes content, with logic to ensure that typogrify does not clash

+ 1 - 3
render_math/mathjax_script.txt

@@ -3,9 +3,7 @@
         var mathjaxscript = document.createElement('script');
         mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
         mathjaxscript.type = 'text/javascript';
-        mathjaxscript.src = 'https:' == document.location.protocol
-		? 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js'
-		: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
+        mathjaxscript.src = {source};
         mathjaxscript[(window.opera ? "innerHTML" : "text")] =
             "MathJax.Hub.Config({{" +
             "    config: ['MMLorHTML.js']," +