plugins/rst.lisp (1190 bytes)
1 (eval-when (:compile-toplevel :load-toplevel) 2 (ql:quickload 'docutils)) 3 4 (defpackage :coleslaw-rst 5 (:use :cl) 6 (:import-from :coleslaw #:render-text) 7 (:import-from :docutils #:read-rst #:write-part #:register-settings-spec 8 #:visit-node #:write-document #:document) 9 (:import-from :docutils.writer.html #:html-writer 10 #:body-pre-docinfo 11 #:body 12 #:parts) 13 (:export #:enable)) 14 15 (in-package :coleslaw-rst) 16 17 ;; XXX: This is not an ideal solution as it affects other uses of docutils in 18 ;; the same lisp image. 19 (defmethod visit-node :after ((writer html-writer) (document document)) 20 "This method removes unnecessary HTML elements, such as html, head, body 21 and make docutils output only html fragment with document itself." 22 (setf (slot-value writer 'parts) '(body-pre-docinfo 23 body))) 24 25 (defmethod render-text (text (format (eql :rst))) 26 (register-settings-spec '((:generator nil) 27 (:datestamp nil))) 28 (let ((writer (make-instance 'html-writer)) 29 (document (read-rst text))) 30 (write-document writer document 'string))) 31 32 (defun enable ())