Explorar o código

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.
Nicolas Goaziou %!s(int64=13) %!d(string=hai) anos
pai
achega
5313dc9d09
Modificáronse 2 ficheiros con 24 adicións e 2 borrados
  1. 5 2
      contrib/lisp/org-export.el
  2. 19 0
      testing/contrib/lisp/test-org-export.el

+ 5 - 2
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

+ 19 - 0
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")))))))