Flexible Lisp Blogware. Fork for personal use. Mirrored from https://github.com/kingcons/coleslaw originally.

mathjax.lisp 1.0KB

12345678910111213141516171819202122232425262728
  1. (defpackage :coleslaw-mathjax
  2. (:use :cl)
  3. (:export #:enable)
  4. (:import-from :coleslaw #:add-injection
  5. #:content
  6. #:index
  7. #:content-tags
  8. #:index-posts))
  9. (in-package :coleslaw-mathjax)
  10. (defvar *mathjax-header* "~@[<script type=\"text/x-mathjax-config\">
  11. MathJax.Hub.Config({~A});
  12. </script>~]
  13. <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
  14. (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
  15. (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
  16. (labels ((math-post-p (obj)
  17. (member "math" (content-tags obj) :test #'string=))
  18. (mathjax-p (obj)
  19. (or force
  20. (etypecase obj
  21. (content (math-post-p obj))
  22. (index (some #'math-post-p (index-posts obj)))))))
  23. (let ((mathjax-header (format nil *mathjax-header* config location preset)))
  24. (add-injection (list mathjax-header #'mathjax-p) :head))))