Ver código fonte

Add Markdown plugin with 3mbd's code highlighting support.

Brit Butler 13 anos atrás
pai
commit
221ea46288
3 arquivos alterados com 17 adições e 12 exclusões
  1. 1 2
      TODO
  2. 5 2
      plugins/markdown.lisp
  3. 11 8
      src/posts.lisp

+ 1 - 2
TODO

@@ -13,8 +13,7 @@ Plugins? Injection support for HEAD and BODY. What about predicate-based injecti
13 13
 How is it served? Hunchentoot, Lighttpd, S3, whomever!
14 14
 
15 15
 TODO:
16
-; after that, focus on markdown support, injections for code highlighting and latex
17
-
16
+; test mathjax+markdown
18 17
 ; doc themes and plugins
19 18
 ; fix plugins: s3
20 19
 ;; Incremental compile: only "touched" posts+tags+months. By-20 must be redone, of course.

+ 5 - 2
plugins/markdown.lisp

@@ -1,9 +1,12 @@
1 1
 (eval-when (:compile-toplevel)
2
-  (ql:quickload '3mbd))
2
+  (ql:quickload '(3bmd 3bmd-ext-code-blocks)))
3 3
 
4 4
 (defpackage :coleslaw-md
5 5
   (:use :cl :coleslaw))
6 6
 
7 7
 (in-package :coleslaw-md)
8 8
 
9
-
9
+(defmethod render-content (text (format (eql :md)))
10
+  (let ((3mbd-code-blocks:*code-blocks* t))
11
+    (with-output-to-string (str)
12
+      (3bmd:parse-string-and-print-to-stream text str))))

+ 11 - 8
src/posts.lisp

@@ -48,19 +48,22 @@
48 48
            (unless (string= (read-line in) ";;;;;")
49 49
              (error "The provided file lacks the expected header.")))
50 50
          (parse-field (str)
51
-           (nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str))))
51
+           (nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str)))
52
+         (slurp-remainder ()
53
+           (read-sequence (make-string (- (file-length in) (file-position in)))
54
+                          in :start (file-position in))))
52 55
     (check-header)
53 56
     (let ((args (loop for field in '("title" "tags" "date" "format")
54 57
                    for line = (read-line in nil)
55 58
                    appending (list (make-keyword (string-upcase field))
56 59
                                    (aref (parse-field line) 0)))))
57
-    (check-header)
58
-    (setf (getf args :tags) (cl-ppcre:split ", " (getf args :tags))
59
-          (getf args :format) (make-keyword (string-upcase (getf args :format))))
60
-    (apply 'make-instance 'post
61
-           (append args (list :content (render-content (read-line in nil)
62
-                                                       (getf args :format))
63
-                              :slug (slugify (getf args :title))))))))
60
+      (check-header)
61
+      (setf (getf args :tags) (cl-ppcre:split ", " (getf args :tags))
62
+            (getf args :format) (make-keyword (string-upcase (getf args :format))))
63
+      (apply 'make-instance 'post
64
+             (append args (list :content (render-content (slurp-remainder)
65
+                                                         (getf args :format))
66
+                                :slug (slugify (getf args :title))))))))
64 67
 
65 68
 (defun write-post (post &key prev next)
66 69
   "Write out the HTML for POST in SLUG.html."