Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 117 lines (90 sloc) 4.308 kb
d3e78ff @archimag added registration and authentication
archimag authored
1 ;;;; markup.lisp
2
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
3 (in-package #:cliki2.markup)
4
5 (defvar *cliki2-rules* (alexandria:copy-hash-table esrap::*rules*))
6
7 (defmacro with-cliki2-rules (&body body)
8 `(let ((esrap::*rules* *cliki2-rules*))
9 ,@body))
10
11 (defmacro define-rule (symbol expression &body options)
12 `(with-cliki2-rules
13 (defrule ,symbol ,expression ,@options)))
14
15 (defun parse-cliki2-markup (symbol text &key (start 0) end junk-allowed)
16 (with-cliki2-rules
17 (parse symbol text
18 :start start
19 :end end
20 :junk-allowed junk-allowed)))
21
22
23 (defun parse-cliki2-doc (markup &aux (curpos 0))
24 (iter (multiple-value-bind (block pos)
25 (parse-cliki2-markup '3bmd-grammar::block markup :start curpos :junk-allowed t)
26 (while block)
27 (collect block)
28 (while pos)
29 (setf curpos pos))))
d3e78ff @archimag added registration and authentication
archimag authored
30
31 (defun generate-html-from-markup (markup)
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
32 (let ((input (3bmd::expand-tabs markup :add-newlines t)))
33 (with-output-to-string (s)
34 (3bmd:print-doc-to-stream (parse-cliki2-doc input) s))))
35
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;; cliki2 markup extensions
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39
40 (define-rule article-link (and (and (? #\\) "_(") (+ (and (! #\)) character)) #\))
41 (:destructure (start article end)
42 (declare (ignore start end))
43 (cons :article-link (concat article))))
44
45 (defmethod 3bmd::print-tagged-element ((tag (eql :article-link)) stream title)
46 (write-string (cliki2.view:article-link
47 (list :title title
48 :href (restas:genurl 'cliki2:view-article :title title)))
49 stream))
50
51 (define-rule person-link (and "_P(" (+ (and (! #\)) character)) #\))
52 (:destructure (start name end)
53 (declare (ignore start end))
54 (cons :person-link (concat name))))
55
56 (defmethod 3bmd::print-tagged-element ((tag (eql :person-link)) stream name)
57 (write-string (cliki2.view:person-link
58 (list :name name
59 :href (restas:genurl 'cliki2:view-person :name name)))
60 stream))
61
62 (define-rule hyperspec-link (and "_H(" (+ (and (! #\)) character)) #\))
63 (:destructure (start symbol end)
64 (declare (ignore start end))
65 (cons :hyperspec-link (concat symbol))))
5606e43 @archimag added to markup: hyperspec-ref and code-block
archimag authored
66
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
67 (defmethod 3bmd::print-tagged-element ((tag (eql :hyperspec-link)) stream symbol)
68 (write-string (cliki2.view:hyperspec-link
69 (list :symbol symbol
70 :href (clhs-lookup:spec-lookup symbol)))
71 stream))
5606e43 @archimag added to markup: hyperspec-ref and code-block
archimag authored
72
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
73 (define-rule 3bmd-grammar::link
74 (or 3bmd-grammar::explicit-link
75 3bmd-grammar::reference-link
76 3bmd-grammar::auto-link
77 article-link
78 person-link
79 hyperspec-link))
5606e43 @archimag added to markup: hyperspec-ref and code-block
archimag authored
80
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
81 (define-rule empty-lines
82 (* (and (* (or #\Space #\Tab)) (? #\Return) #\Newline)))
5606e43 @archimag added to markup: hyperspec-ref and code-block
archimag authored
83
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
84 (define-rule code-block (and "<code>"
85 empty-lines
86 (+ (and (! (and empty-lines "</code>")) character))
87 empty-lines
88 "</code>")
89 (:destructure (start w1 code w2 end)
90 (declare (ignore start w1 w2 end))
91 (cons :lisp-code-block (concat code))))
17416b2 @archimag added markup: article-ref and person-ref
archimag authored
92
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
93 (defmethod 3bmd::print-tagged-element ((tag (eql :lisp-code-block)) stream code)
94 (write-string (cliki2.view:code-block
95 (list :code (colorize::html-colorization :common-lisp code)))
96 stream))
97
98 (define-rule 3bmdcode (or 3bmd-grammar::code1 3bmd-grammar::code2 3bmd-grammar::code3 3bmd-grammar::code4 3bmd-grammar::code5)
99 (:lambda (a)
100 (list :code a)))
5606e43 @archimag added to markup: hyperspec-ref and code-block
archimag authored
101
57013f5 @archimag added cliki2 markup extensions: article-link, person-link, hyperspec-…
archimag authored
102 (define-rule 3bmd-grammar::code (or 3bmdcode code-block))
9873a6f @archimag added categories
archimag authored
103
6d6413b @vsedach Replaced cl-docutils with 3bmd, changed the way categories work.
authored
104 ;;;; category *()
9873a6f @archimag added categories
archimag authored
105
6d6413b @vsedach Replaced cl-docutils with 3bmd, changed the way categories work.
authored
106 ;;;; category list /()
9873a6f @archimag added categories
archimag authored
107
6d6413b @vsedach Replaced cl-docutils with 3bmd, changed the way categories work.
authored
108 ;; (defmethod docutils:visit-node ((writer docutils.writer.html:html-writer) (node category-content))
109 ;; (append-template 'cliki2.view:category-content
110 ;; :items (iter (for article in (articles-with-category (category-content-title node)))
111 ;; (collect
112 ;; (list :title (article-title article)
113 ;; :href (restas:genurl 'view-article
114 ;; :title (article-title article)))))))
9873a6f @archimag added categories
archimag authored
115
116
Something went wrong with that request. Please try again.