2011-04-26 13:52:15 -04:00
|
|
|
(defpackage :coleslaw-mathjax
|
2012-09-15 17:39:00 -04:00
|
|
|
(:use :cl)
|
2012-09-20 18:33:29 -04:00
|
|
|
(:export #:enable)
|
2012-09-15 17:39:00 -04:00
|
|
|
(:import-from :coleslaw #:add-injection
|
2013-01-02 13:04:20 -05:00
|
|
|
#:content
|
2012-09-15 17:39:00 -04:00
|
|
|
#:index
|
2013-01-02 13:04:20 -05:00
|
|
|
#:content-tags
|
2013-04-21 14:27:08 -04:00
|
|
|
#:index-posts
|
|
|
|
#:make-tag
|
|
|
|
#:tag-slug=))
|
2011-04-19 13:36:17 -04:00
|
|
|
|
2011-04-26 13:52:15 -04:00
|
|
|
(in-package :coleslaw-mathjax)
|
|
|
|
|
2013-04-04 20:18:18 +02:00
|
|
|
(defvar *mathjax-header* "~@[<script type=\"text/x-mathjax-config\">
|
|
|
|
MathJax.Hub.Config({~A});
|
|
|
|
</script>~]
|
2013-04-04 09:55:23 -04:00
|
|
|
<script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
|
2011-04-26 13:52:15 -04:00
|
|
|
|
2013-04-04 09:55:23 -04:00
|
|
|
(defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
|
|
|
|
(location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
|
2013-01-02 13:04:20 -05:00
|
|
|
(labels ((math-post-p (obj)
|
2013-04-21 14:21:05 -04:00
|
|
|
(member (make-tag "math") (content-tags obj) :test #'tag-slug=))
|
2013-01-02 13:04:20 -05:00
|
|
|
(mathjax-p (obj)
|
2013-04-04 09:55:23 -04:00
|
|
|
(or force
|
|
|
|
(etypecase obj
|
|
|
|
(content (math-post-p obj))
|
|
|
|
(index (some #'math-post-p (index-posts obj)))))))
|
|
|
|
(let ((mathjax-header (format nil *mathjax-header* config location preset)))
|
2013-04-03 18:27:30 +02:00
|
|
|
(add-injection (list mathjax-header #'mathjax-p) :head))))
|