1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-24 10:38:41 +00:00

ox: Ignore text before first headline with an :export: tag

* lisp/ox.el (org-export--populate-ignore-list): Ignore text before
  first headline if an :export: tag (or a select tag) is found within
  the buffer.
* testing/lisp/test-ox.el: Add tests.
This commit is contained in:
Nicolas Goaziou 2013-09-25 18:49:39 +02:00
parent f688b6cc63
commit 7cf4406088
2 changed files with 23 additions and 4 deletions

View File

@ -1955,10 +1955,15 @@ for a footnotes section."
"Return list of elements and objects to ignore during export.
DATA is the parse tree to traverse. OPTIONS is the plist holding
export options."
(let* (ignore
walk-data
(let* (walk-data
;; First find trees containing a select tag, if any.
(selected (org-export--selected-trees data options))
;; If a select tag is active, also ignore the section before
;; the first headline, if any.
(ignore (and selected
(let ((first-element (car (org-element-contents data))))
(and (eq (org-element-type first-element) 'section)
first-element))))
(walk-data
(lambda (data)
;; Collect ignored elements or objects into IGNORE-LIST.
@ -1969,8 +1974,8 @@ export options."
(org-element-property :archivedp data))
;; If headline is archived but tree below has
;; to be skipped, add it to ignore list.
(mapc (lambda (e) (push e ignore))
(org-element-contents data))
(dolist (element (org-element-contents data))
(push element ignore))
;; Move into secondary string, if any.
(let ((sec-prop
(cdr (assq type org-element-secondary-value-alist))))

View File

@ -338,6 +338,20 @@ Paragraph"
(let ((org-tags-column 0))
(org-export-as (org-test-default-backend)
nil nil nil '(:select-tags ("exp")))))))
;; If there is an include tag, ignore the section before the first
;; headline, if any.
(should
(equal "* H1 :exp:\nBody\n"
(org-test-with-temp-text "First section\n* H1 :exp:\nBody"
(let ((org-tags-column 0))
(org-export-as (org-test-default-backend)
nil nil nil '(:select-tags ("exp")))))))
(should-not
(equal "* H1 :exp:\n"
(org-test-with-temp-text "* H1 :exp:\nBody"
(let ((org-tags-column 0))
(org-export-as (org-test-default-backend)
nil nil nil '(:select-tags ("exp")))))))
;; Test mixing include tags and exclude tags.
(should
(string-match