summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-02-25 13:08:40 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2012-02-25 14:55:21 +0100
commit5313dc9d091ad7d8c26f17eb5d0f09be9a596f3b (patch)
tree011f81f0dd330618f62e0ab3fff66d18d1bb6111
parent9f7965a80ea46f509f7b00787d9f7287871e291f (diff)
downloadorg-mode-5313dc9d091ad7d8c26f17eb5d0f09be9a596f3b.tar.gz
org-export: Allow user to explicitely ignore parts of parse tree
* contrib/lisp/org-export.el (org-export-collect-tree-properties): Do not overwrite any user's ignore list. * testing/contrib/lisp/test-org-export.el: Add test. A good way to populate `:ignore-list' is through the use of `org-export-filter-parse-tree-functions', with the help of `org-element-map' and `org-export-ignore-element'. As an example, the following code will skip every headline containing the word "note" in its title during a LaTeX export: (defun user-skip-note-headlines (data backend info) ;; For now LaTeX back-end is called `e-latex'. (when (eq backend 'test) ;; Traverse the parse tree, adding to ignore list any headline ;; matching criteria. (org-element-map data 'headline (lambda (headline) (when (string-match "\\<note\\>" (org-element-property :raw-value headline)) (org-export-ignore-element headline info))) info)) ;; Return original DATA. data) Then install it in parse-tree filters: (add-to-list 'user-skip-note-headlines org-export-filter-parse-tree-functions) Back-end delevopers will install it via `org-BACKEND-filters-alist' where BACKEND stands for the name of the back-end considered. Se `org-export-filters-alist' for more information.
-rw-r--r--contrib/lisp/org-export.el7
-rw-r--r--testing/contrib/lisp/test-org-export.el19
2 files changed, 24 insertions, 2 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 57a94f6..8d5204c 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -1271,10 +1271,13 @@ Following tree properties are set:
`:target-list' List of all targets in the parse tree."
;; First, get the list of elements and objects to ignore, and put it
- ;; into `:ignore-list'.
+ ;; into `:ignore-list'. Do not overwrite any user ignore that might
+ ;; have been done during parse tree filtering.
(setq info
(plist-put info
- :ignore-list (org-export-populate-ignore-list data info)))
+ :ignore-list
+ (append (org-export-populate-ignore-list data info)
+ (plist-get info :ignore-list))))
;; Then compute `:headline-offset' in order to be able to use
;; `org-export-get-relative-level'.
(setq info
diff --git a/testing/contrib/lisp/test-org-export.el b/testing/contrib/lisp/test-org-export.el
index 9edc9c4..6d05d54 100644
--- a/testing/contrib/lisp/test-org-export.el
+++ b/testing/contrib/lisp/test-org-export.el
@@ -296,3 +296,22 @@ body\n")))
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
+
+(ert-deftest test-org-export/user-ignore-list ()
+ "Test if `:ignore-list' accepts user input."
+ (org-test-with-backend "test"
+ (flet ((skip-note-head
+ (data backend info)
+ ;; Ignore headlines with the word "note" in their title.
+ (org-element-map
+ data 'headline
+ (lambda (headline)
+ (when (string-match "\\<note\\>"
+ (org-element-property :raw-value headline))
+ (org-export-ignore-element headline info)))
+ info)
+ data))
+ ;; Install function in parse tree filters.
+ (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
+ (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
+ (should (equal (org-export-as 'test) "* Head1\n")))))))