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

mathjax.lisp 1.1KB

123456789101112131415161718192021222324252627282930
  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. #:make-tag
  10. #:tag-slug=))
  11. (in-package :coleslaw-mathjax)
  12. (defvar *mathjax-header* "~@[<script type=\"text/x-mathjax-config\">
  13. MathJax.Hub.Config({~A});
  14. </script>~]
  15. <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
  16. (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
  17. (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
  18. (labels ((math-post-p (obj)
  19. (member (make-tag "math") (content-tags obj) :test #'tag-slug=))
  20. (mathjax-p (obj)
  21. (or force
  22. (etypecase obj
  23. (content (math-post-p obj))
  24. (index (some #'math-post-p (index-posts obj)))))))
  25. (let ((mathjax-header (format nil *mathjax-header* config location preset)))
  26. (add-injection (list mathjax-header #'mathjax-p) :head))))