forked from mirrors/org-mode
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.
This commit is contained in:
parent
47bad1ee9b
commit
69dd4301ab
23
lisp/ox.el
23
lisp/ox.el
|
@ -2665,16 +2665,29 @@ The function assumes BUFFER's major mode is `org-mode'."
|
||||||
(overlays-in (point-min) (point-max)))
|
(overlays-in (point-min) (point-max)))
|
||||||
ov-set)))))
|
ov-set)))))
|
||||||
|
|
||||||
(defun org-export--delete-commented-subtrees ()
|
(defun org-export--delete-comments ()
|
||||||
"Delete commented subtrees or inlinetasks in the buffer."
|
"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
|
(org-with-wide-buffer
|
||||||
(goto-char (point-min))
|
(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)
|
(while (re-search-forward regexp nil t)
|
||||||
(let ((e (org-element-at-point)))
|
(let ((e (org-element-at-point)))
|
||||||
|
(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)
|
(when (org-element-property :commentedp e)
|
||||||
(delete-region (org-element-property :begin e)
|
(delete-region (org-element-property :begin e)
|
||||||
(org-element-property :end e))))))))
|
(org-element-property :end e))))))))))
|
||||||
|
|
||||||
(defun org-export--prune-tree (data info)
|
(defun org-export--prune-tree (data info)
|
||||||
"Prune non exportable elements from DATA.
|
"Prune non exportable elements from DATA.
|
||||||
|
@ -2866,7 +2879,7 @@ Return code as a string."
|
||||||
(run-hook-with-args 'org-export-before-processing-hook
|
(run-hook-with-args 'org-export-before-processing-hook
|
||||||
(org-export-backend-name backend))
|
(org-export-backend-name backend))
|
||||||
(org-export-expand-include-keyword)
|
(org-export-expand-include-keyword)
|
||||||
(org-export--delete-commented-subtrees)
|
(org-export--delete-comments)
|
||||||
;; Update macro templates since #+INCLUDE keywords might have
|
;; Update macro templates since #+INCLUDE keywords might have
|
||||||
;; added some new ones.
|
;; added some new ones.
|
||||||
(org-macro-initialize-templates)
|
(org-macro-initialize-templates)
|
||||||
|
|
|
@ -48,7 +48,7 @@ body to execute. Parse tree is available under the `tree'
|
||||||
variable, and communication channel under `info'."
|
variable, and communication channel under `info'."
|
||||||
(declare (debug (form body)) (indent 1))
|
(declare (debug (form body)) (indent 1))
|
||||||
`(org-test-with-temp-text ,data
|
`(org-test-with-temp-text ,data
|
||||||
(org-export--delete-commented-subtrees)
|
(org-export--delete-comments)
|
||||||
(let* ((tree (org-element-parse-buffer))
|
(let* ((tree (org-element-parse-buffer))
|
||||||
(info (org-export-get-environment)))
|
(info (org-export-get-environment)))
|
||||||
(org-export--prune-tree tree info)
|
(org-export--prune-tree tree info)
|
||||||
|
|
Loading…
Reference in a new issue