Mathjax plugin cleanups.

This commit is contained in:
Brit Butler 2013-04-04 09:55:23 -04:00
parent cd8b9f8d2c
commit 09d54e4863
3 changed files with 15 additions and 37 deletions

View file

@ -24,13 +24,13 @@
### Options ### Options
`:force`, when specified with a true value, will force the inclusion of MathJax, even if no posts are tagged "math". Default value is `nil`. `:force`, when non-nil, will force the inclusion of MathJax on all posts. Default value is `nil`.
`:mathjax-url` specifies the location of the `MathJax.js`. The default value is `"http://cdn.mathjax.org/mathjax/latest/MathJax.js"`. This is useful if you want to force a specific value of MathJax, or if you have a local copy of MathJax and want to use that version. `:location` specifies the location of the `MathJax.js` file. The default value is `"http://cdn.mathjax.org/mathjax/latest/MathJax.js"`. This is useful if you have a local copy of MathJax and want to use that version.
`:config` allows the specification of the config parameter of `MathJax.js`. The default value is `"TeX-AMS-MML_HTMLorMML"`. `:preset` allows the specification of the config parameter of `MathJax.js`. The default value is `"TeX-AMS-MML_HTMLorMML"`.
`:mathjax-config` allows specifying the content of the `...` in a `MathJax.Hub.Config ({ ... });` section. The default is `tex2jax: {inlineMath: [['$$','$$']]}`, which allows display equations to be enclosed in `$$`. If a `nil` argument is supplied the whole `<script>` section containing the `MathJax.Hub.Config` will be omitted. `:config` is used as supplementary inline configuration to the `MathJax.Hub.Config ({ ... });`. It is unused by default.
## ReStructuredText ## ReStructuredText

View file

@ -9,41 +9,19 @@
(in-package :coleslaw-mathjax) (in-package :coleslaw-mathjax)
(defvar *mathjax-config-header* "<script type=\"text/x-mathjax-config\"> (defvar *mathjax-header* "<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({ MathJax.Hub.Config({~@[~A~]});
~A
});
</script> </script>
") <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
(defvar *default-mathjax-config* "tex2jax: {inlineMath: [['$$','$$']]}") (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
(location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
(defvar *mathjax-load-header-no-config* "<script type=\"text/javascript\"
src=\"~A\">
</script>
")
(defvar *mathjax-load-header-with-config* "<script type=\"text/javascript\"
src=\"~A?config=~A\">
</script>
")
(defun enable (&key force
(mathjax-url "http://cdn.mathjax.org/mathjax/latest/MathJax.js")
(config "TeX-AMS-MML_HTMLorMML")
(mathjax-config *default-mathjax-config*))
(labels ((math-post-p (obj) (labels ((math-post-p (obj)
(member "math" (content-tags obj) :test #'string=)) (member "math" (content-tags obj) :test #'string=))
(mathjax-p (obj) (mathjax-p (obj)
(or force (or force
(etypecase obj (etypecase obj
(content (math-post-p obj)) (content (math-post-p obj))
(index (some #'math-post-p (index-posts obj))))))) (index (some #'math-post-p (index-posts obj)))))))
(let ((mathjax-header (format nil *mathjax-header* config location preset)))
(let ((mathjax-header
(concatenate 'string
(if mathjax-config (format nil *mathjax-config-header* mathjax-config) "")
(if config
(format nil *mathjax-load-header-with-config* mathjax-url config)
(format nil *mathjax-load-header-no-config* mathjax-url)))))
(add-injection (list mathjax-header #'mathjax-p) :head)))) (add-injection (list mathjax-header #'mathjax-p) :head))))