Skip to content
Newer
Older
100644 57 lines (44 sloc) 2.23 KB
d3e78ff @archimag added registration and authentication
archimag authored
1 ;;;; markup.lisp
2
3 (in-package #:cliki2)
4
5
6 (defun generate-html-from-markup (markup)
7 (let ((doc (docutils:read-rst (ppcre:regex-replace-all "\\r\\n" markup (string #\Newline) )))
8 (writer (make-instance 'docutils.writer.html:html-writer)))
9 (docutils:visit-node writer doc)
10 (with-output-to-string (out)
11 (iter (for part in '(docutils.writer.html:body-pre-docinfo
12 docutils.writer.html:docinfo
13 docutils.writer.html:body))
14 (docutils:write-part writer part out))
15 (format out "</div>"))))
5606e43 @archimag added to markup: hyperspec-ref and code-block
archimag authored
16
17 ;;;; hypespec-ref
18
19 (defclass hyperspec-ref (docutils.nodes:raw)
20 ((spec :initarg :spec :reader hyperspec-ref-spec)))
21
22 (defmethod docutils:visit-node ((write docutils.writer.html:html-writer) (node hyperspec-ref))
23 (docutils:part-append
24 (docutils.writer.html::start-tag node
25 "a"
26 (list :href (clhs-lookup:spec-lookup (hyperspec-ref-spec node))
27 :class "common-lisp-entity"))
28 (hyperspec-ref-spec node)
29 "</a>"))
30
31 (docutils.parser.rst:def-role hs (spec)
32 (make-instance 'hyperspec-ref
33 :spec spec))
34
35
36 ;;;; code-block
37
38 (defclass code-block (docutils.nodes:raw)
39 ((lang :initarg :lang :initform nil :reader code-block-lang)
40 (code :initarg :code :initform nil :reader code-block-code)))
41
42 (defmethod docutils:visit-node ((writer docutils.writer.html:html-writer) (node code-block))
43 (docutils:part-append (docutils.writer.html::start-tag node
44 "div"
45 '(:class "code")))
46 (docutils:part-append (colorize::html-colorization :common-lisp
47 (code-block-code node)))
48 (docutils:part-append "</div>"))
49
50 (docutils.parser.rst:def-directive code-block (parent lang &content content)
51 (let ((node (docutils:make-node 'docutils.nodes:paragraph)))
52 (docutils:add-child node
53 (make-instance 'code-block
54 :lang lang
55 :code (docutils::join-strings content #\Newline)))
56 (docutils:add-child parent node)))
Something went wrong with that request. Please try again.