From 9e8bf5e4c9c4092e80f47d1b412fab124478dbe4 Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Sun, 16 Oct 2016 12:20:01 -0500 Subject: [PATCH 1/3] rst.lisp: Fix conflicting symbol imports WRITE-PART should be imported from docutils where it is defined. --- plugins/rst.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/rst.lisp b/plugins/rst.lisp index a18ec10..255932e 100644 --- a/plugins/rst.lisp +++ b/plugins/rst.lisp @@ -6,7 +6,7 @@ (:import-from :coleslaw #:render-text) (:import-from :docutils #:read-rst #:write-part #:register-settings-spec #:visit-node #:write-document) - (:import-from :docutils.writer.html #:html-writer #:write-part) + (:import-from :docutils.writer.html #:html-writer) (:export #:enable)) (in-package :coleslaw-rst) From 678ea7fe4a02c3009a8c25a27857b37591f06b3a Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Sun, 16 Oct 2016 12:28:00 -0500 Subject: [PATCH 2/3] RST.lisp: Remove call to VISIT-NODE WRITE-DOCUMENT method for all writers already calls VISIT-NODE. --- plugins/rst.lisp | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/rst.lisp b/plugins/rst.lisp index 255932e..6019f31 100644 --- a/plugins/rst.lisp +++ b/plugins/rst.lisp @@ -17,7 +17,6 @@ (with-output-to-string (str) (let ((writer (make-instance 'html-writer)) (document (read-rst text))) - (visit-node writer document) (write-document writer document str)))) (defun enable ()) From a856f0284db98dd52bd49b60311c0c60aa58847a Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Sun, 16 Oct 2016 17:00:08 -0500 Subject: [PATCH 3/3] rst.lisp: Generate the BODY of the HTML document --- plugins/rst.lisp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/rst.lisp b/plugins/rst.lisp index 6019f31..43e98c0 100644 --- a/plugins/rst.lisp +++ b/plugins/rst.lisp @@ -5,18 +5,28 @@ (:use :cl) (:import-from :coleslaw #:render-text) (:import-from :docutils #:read-rst #:write-part #:register-settings-spec - #:visit-node #:write-document) - (:import-from :docutils.writer.html #:html-writer) + #:visit-node #:write-document #:document) + (:import-from :docutils.writer.html #:html-writer + #:body-pre-docinfo + #:body + #:parts) (:export #:enable)) (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))) (register-settings-spec '((:generator nil) (:datestamp nil))) - (with-output-to-string (str) - (let ((writer (make-instance 'html-writer)) - (document (read-rst text))) - (write-document writer document str)))) + (let ((writer (make-instance 'html-writer)) + (document (read-rst text))) + (write-document writer document 'string))) (defun enable ())