فهرست منبع

ox: Remove comments and comment blocks prior to export

* lisp/ox.el (org-export--delete-comments): Renamed from
  `org-export--delete-commented-subtrees'.  Also remove comments and
  comment blocks.
(org-export-as): Apply renaming.

* testing/lisp/test-ox.el (org-test-with-parsed-data): Apply renaming.

From the export point of view COMMENTed subtrees and regular comments
are expected to be treated in the same way.
Nicolas Goaziou 10 سال پیش
والد
کامیت
69dd4301ab
2فایلهای تغییر یافته به همراه21 افزوده شده و 8 حذف شده
  1. 20 7
      lisp/ox.el
  2. 1 1
      testing/lisp/test-ox.el

+ 20 - 7
lisp/ox.el

@@ -2665,16 +2665,29 @@ The function assumes BUFFER's major mode is `org-mode'."
 	      (overlays-in (point-min) (point-max)))
 	     ov-set)))))
 
-(defun org-export--delete-commented-subtrees ()
-  "Delete commented subtrees or inlinetasks in the buffer."
+(defun org-export--delete-comments ()
+  "Delete commented areas in the buffer.
+Commented areas are comments, comment blocks, commented trees and
+inlinetasks.  Trailing blank lines after a comment or a comment
+block are preserved.  Narrowing, if any, is ignored."
   (org-with-wide-buffer
    (goto-char (point-min))
-   (let ((regexp (concat org-outline-regexp-bol ".*" org-comment-string)))
+   (let ((regexp (concat org-outline-regexp-bol ".*" org-comment-string
+			 "\\|"
+			 "^[ \t]*#\\(?: \\|$\\|\\+begin_comment\\)"))
+	 (case-fold-search t))
      (while (re-search-forward regexp nil t)
        (let ((e (org-element-at-point)))
-	 (when (org-element-property :commentedp e)
-	   (delete-region (org-element-property :begin e)
-			  (org-element-property :end e))))))))
+	 (case (org-element-type e)
+	   ((comment comment-block)
+	    (delete-region (org-element-property :begin e)
+			   (progn (goto-char (org-element-property :end e))
+				  (skip-chars-backward " \r\t\n")
+				  (line-beginning-position 2))))
+	   ((headline inlinetask)
+	    (when (org-element-property :commentedp e)
+	      (delete-region (org-element-property :begin e)
+			     (org-element-property :end e))))))))))
 
 (defun org-export--prune-tree (data info)
   "Prune non exportable elements from DATA.
@@ -2866,7 +2879,7 @@ Return code as a string."
 	 (run-hook-with-args 'org-export-before-processing-hook
 			     (org-export-backend-name backend))
 	 (org-export-expand-include-keyword)
-	 (org-export--delete-commented-subtrees)
+	 (org-export--delete-comments)
 	 ;; Update macro templates since #+INCLUDE keywords might have
 	 ;; added some new ones.
 	 (org-macro-initialize-templates)

+ 1 - 1
testing/lisp/test-ox.el

@@ -48,7 +48,7 @@ body to execute.  Parse tree is available under the `tree'
 variable, and communication channel under `info'."
   (declare (debug (form body)) (indent 1))
   `(org-test-with-temp-text ,data
-     (org-export--delete-commented-subtrees)
+     (org-export--delete-comments)
      (let* ((tree (org-element-parse-buffer))
 	    (info (org-export-get-environment)))
        (org-export--prune-tree tree info)