Merge branch 'maint'
This commit is contained in:
commit
bd921f0858
52
lisp/ox.el
52
lisp/ox.el
|
@ -2669,25 +2669,45 @@ The function assumes BUFFER's major mode is `org-mode'."
|
||||||
"Delete commented areas in the buffer.
|
"Delete commented areas in the buffer.
|
||||||
Commented areas are comments, comment blocks, commented trees and
|
Commented areas are comments, comment blocks, commented trees and
|
||||||
inlinetasks. Trailing blank lines after a comment or a comment
|
inlinetasks. Trailing blank lines after a comment or a comment
|
||||||
block are preserved. Narrowing, if any, is ignored."
|
block are removed, as long as it doesn't alter the structure of
|
||||||
|
the document. 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* ((case-fold-search t)
|
||||||
"\\|"
|
(comment-re "^[ \t]*#\\(?: \\|$\\|\\+end_comment\\)")
|
||||||
"^[ \t]*#\\(?: \\|$\\|\\+begin_comment\\)"))
|
(regexp (concat org-outline-regexp-bol ".*" org-comment-string "\\|"
|
||||||
(case-fold-search t))
|
comment-re)))
|
||||||
(while (re-search-forward regexp nil t)
|
(while (re-search-forward regexp nil t)
|
||||||
(let ((e (org-element-at-point)))
|
(let ((element (org-element-at-point)))
|
||||||
(cl-case (org-element-type e)
|
(pcase (org-element-type element)
|
||||||
((comment comment-block)
|
((or `headline `inlinetask)
|
||||||
(delete-region (org-element-property :begin e)
|
(when (org-element-property :commentedp element)
|
||||||
(progn (goto-char (org-element-property :end e))
|
(delete-region (org-element-property :begin element)
|
||||||
(skip-chars-backward " \r\t\n")
|
(org-element-property :end element))))
|
||||||
(line-beginning-position 2))))
|
((or `comment `comment-block)
|
||||||
((headline inlinetask)
|
(let* ((parent (org-element-property :parent element))
|
||||||
(when (org-element-property :commentedp e)
|
(start (org-element-property :begin element))
|
||||||
(delete-region (org-element-property :begin e)
|
(end (org-element-property :end element))
|
||||||
(org-element-property :end e))))))))))
|
;; We remove trailing blank lines. Doing so could
|
||||||
|
;; modify the structure of the document. Therefore
|
||||||
|
;; we ensure that any comment between elements is
|
||||||
|
;; replaced with one empty line, so as to keep them
|
||||||
|
;; separated.
|
||||||
|
(add-blank?
|
||||||
|
(save-excursion
|
||||||
|
(goto-char start)
|
||||||
|
(not (or (bobp)
|
||||||
|
(eq (org-element-property :contents-begin parent)
|
||||||
|
start)
|
||||||
|
(eq (org-element-property :contents-end parent)
|
||||||
|
end)
|
||||||
|
(progn
|
||||||
|
(forward-line -1)
|
||||||
|
(or (org-looking-at-p "^[ \t]*$")
|
||||||
|
(org-with-limited-levels
|
||||||
|
(org-at-heading-p)))))))))
|
||||||
|
(delete-region start end)
|
||||||
|
(when add-blank? (insert "\n"))))))))))
|
||||||
|
|
||||||
(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.
|
||||||
|
|
|
@ -1665,6 +1665,68 @@ Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote
|
||||||
'(:with-emphasize t)))))
|
'(:with-emphasize t)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;;; Comments
|
||||||
|
|
||||||
|
(ert-deftest test-org-export/comments ()
|
||||||
|
"Test comments handling during export.
|
||||||
|
In particular, structure of the document mustn't be altered after
|
||||||
|
comments removal."
|
||||||
|
(should
|
||||||
|
(equal (org-test-with-temp-text "
|
||||||
|
Para1
|
||||||
|
# Comment
|
||||||
|
|
||||||
|
# Comment
|
||||||
|
Para2"
|
||||||
|
(org-export-as (org-test-default-backend)))
|
||||||
|
"Para1\n\nPara2\n"))
|
||||||
|
(should
|
||||||
|
(equal (org-test-with-temp-text "
|
||||||
|
Para1
|
||||||
|
# Comment
|
||||||
|
Para2"
|
||||||
|
(org-export-as (org-test-default-backend)))
|
||||||
|
"Para1\n\nPara2\n"))
|
||||||
|
(should
|
||||||
|
(equal (org-test-with-temp-text "
|
||||||
|
\[fn:1] Para1
|
||||||
|
# Inside definition
|
||||||
|
|
||||||
|
|
||||||
|
# Outside definition
|
||||||
|
Para2"
|
||||||
|
(org-export-as (org-test-default-backend)))
|
||||||
|
"[fn:1] Para1\n\n\nPara2\n"))
|
||||||
|
(should
|
||||||
|
(equal (org-test-with-temp-text "
|
||||||
|
\[fn:1] Para1
|
||||||
|
|
||||||
|
# Inside definition
|
||||||
|
|
||||||
|
# Inside definition
|
||||||
|
|
||||||
|
Para2"
|
||||||
|
(org-export-as (org-test-default-backend)))
|
||||||
|
"[fn:1] Para1\n\nPara2\n"))
|
||||||
|
(should
|
||||||
|
(equal (org-test-with-temp-text "
|
||||||
|
\[fn:1] Para1
|
||||||
|
# Inside definition
|
||||||
|
|
||||||
|
Para2"
|
||||||
|
(org-export-as (org-test-default-backend)))
|
||||||
|
"[fn:1] Para1\n\nPara2\n"))
|
||||||
|
(should
|
||||||
|
(equal (org-test-with-temp-text "
|
||||||
|
\[fn:1] Para1
|
||||||
|
|
||||||
|
# Inside definition
|
||||||
|
Para2"
|
||||||
|
(org-export-as (org-test-default-backend)))
|
||||||
|
"[fn:1] Para1\n\nPara2\n")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Export Snippets
|
;;; Export Snippets
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue