summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-10-15 12:15:06 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-10-15 16:51:13 +0200
commitb401d3a44b49b075ea27c633c4b17beba2c477c8 (patch)
tree39c84db9f6a4bdcb0b480bd86c18ba01d6fe3181
parent9b13e44ad795792afabb0623b58653bbf35bf040 (diff)
downloadorg-mode-b401d3a44b49b075ea27c633c4b17beba2c477c8.tar.gz
Implement `org-export-excluded-from-toc-p'
* lisp/ox.el (org-export-excluded-from-toc-p): New function. * testing/lisp/test-ox.el (test-org-export/excluded-from-toc-p): New test.
-rw-r--r--etc/ORG-NEWS6
-rw-r--r--lisp/ox.el15
-rw-r--r--testing/lisp/test-ox.el17
3 files changed, 38 insertions, 0 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 86c253d..1076dd9 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -108,6 +108,12 @@ you should expect to see something like:
,#+STARTUP: shrink
#+END_EXAMPLE
+** New functions
+
+*** ~org-export-excluded-from-toc-p~
+
+See docstring for details.
+
** Miscellaneous
*** ~org-publish-resolve-external-link~ accepts a new optional argument.
diff --git a/lisp/ox.el b/lisp/ox.el
index 739c084..953a723 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -5288,6 +5288,21 @@ INFO is a plist used as a communication channel.
Return a list of src-block elements with a caption."
(org-export-collect-elements 'src-block info))
+(defun org-export-excluded-from-toc-p (headline info)
+ "Non-nil if HEADLINE should be excluded from tables of contents.
+
+INFO is a plist used as a communication channel.
+
+Note that such headlines are already excluded from
+`org-export-collect-headlines'. Therefore, this function is not
+necessary if you only need to list headlines in the table of
+contents. However, it is useful if some additional processing is
+required on headlines excluded from table of contents."
+ (or (org-element-property :footnote-section-p headline)
+ (org-export-low-level-p headline info)
+ (cl-some (lambda (h) (equal "notoc" (org-element-property :UNNUMBERED h)))
+ (org-element-lineage headline nil t))))
+
(defun org-export-toc-entry-backend (parent &rest transcoders)
"Return an export back-end appropriate for table of contents entries.
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 0906d18..fa5ee6a 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -4344,6 +4344,23 @@ Another text. (ref:text)
(mapcar (lambda (h) (org-element-property :raw-value h))
(org-export-collect-headlines info 1 scope)))))))
+(ert-deftest test-org-export/excluded-from-toc-p ()
+ "Test `org-export-excluded-from-toc-p' specifications."
+ (should-not
+ (org-test-with-parsed-data "* H1"
+ (org-element-map tree 'headline
+ (lambda (h) (org-export-excluded-from-toc-p h info)) info t)))
+ (should
+ (org-test-with-parsed-data "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
+ (org-element-map tree 'headline
+ (lambda (h) (org-export-excluded-from-toc-p h info)) info t)))
+ (should
+ (equal '(in out)
+ (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
+ (org-element-map tree 'headline
+ (lambda (h) (if (org-export-excluded-from-toc-p h info) 'out 'in))
+ info)))))
+
(ert-deftest test-org-export/toc-entry-backend ()
"Test `org-export-toc-entry-backend' specifications."
;; Ignore targets.