From 5313dc9d091ad7d8c26f17eb5d0f09be9a596f3b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 25 Feb 2012 13:08:40 +0100 Subject: [PATCH] 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 "\\" (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. --- contrib/lisp/org-export.el | 7 +++++-- testing/contrib/lisp/test-org-export.el | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index 57a94f6d4..8d5204c4c 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 9edc9c44a..6d05d54bf 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 "\\" + (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")))))))