Merge pull request #118 from PuercoPop/rst-plugin-fix

Closes #113: Miscellaneous bugfixes for the ReST plugin
This commit is contained in:
Javier Olaechea 2016-10-16 17:05:40 -05:00 committed by GitHub
commit 808bdb50c3

View file

@ -5,19 +5,28 @@
(:use :cl) (:use :cl)
(:import-from :coleslaw #:render-text) (:import-from :coleslaw #:render-text)
(:import-from :docutils #:read-rst #:write-part #:register-settings-spec (:import-from :docutils #:read-rst #:write-part #:register-settings-spec
#:visit-node #:write-document) #:visit-node #:write-document #:document)
(:import-from :docutils.writer.html #:html-writer #:write-part) (:import-from :docutils.writer.html #:html-writer
#:body-pre-docinfo
#:body
#:parts)
(:export #:enable)) (:export #:enable))
(in-package :coleslaw-rst) (in-package :coleslaw-rst)
;; XXX: This is not an ideal solution as it affects other uses of docutils in
;; the same lisp image.
(defmethod visit-node :after ((writer html-writer) (document document))
"This method removes unnecessary HTML elements, such as html, head, body
and make docutils output only html fragment with document itself."
(setf (slot-value writer 'parts) '(body-pre-docinfo
body)))
(defmethod render-text (text (format (eql :rst))) (defmethod render-text (text (format (eql :rst)))
(register-settings-spec '((:generator nil) (register-settings-spec '((:generator nil)
(:datestamp nil))) (:datestamp nil)))
(with-output-to-string (str) (let ((writer (make-instance 'html-writer))
(let ((writer (make-instance 'html-writer)) (document (read-rst text)))
(document (read-rst text))) (write-document writer document 'string)))
(visit-node writer document)
(write-document writer document str))))
(defun enable ()) (defun enable ())