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

View File

@ -338,6 +338,20 @@ Paragraph"
(let ((org-tags-column 0)) (let ((org-tags-column 0))
(org-export-as (org-test-default-backend) (org-export-as (org-test-default-backend)
nil nil nil '(:select-tags ("exp"))))))) 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. ;; Test mixing include tags and exclude tags.
(should (should
(string-match (string-match