ox: Do not build TOC for headlines below H value

* lisp/ox.el (org-export-collect-headlines): Do not build TOC for
  headlines below H value.
* testing/lisp/test-ox.el: Add test.

Reported-by: Jambunathan K <kjambunathan@gmail.com>
This commit is contained in:
Nicolas Goaziou 2013-08-31 14:30:25 +02:00
parent cb35032641
commit 22b4473fcc
2 changed files with 38 additions and 8 deletions

View File

@ -4829,14 +4829,14 @@ information.
Return a list of all exportable headlines as parsed elements.
Footnote sections, if any, will be ignored."
(unless (wholenump n) (setq n (plist-get info :headline-levels)))
(org-element-map (plist-get info :parse-tree) 'headline
(lambda (headline)
(unless (org-element-property :footnote-section-p headline)
;; Strip contents from HEADLINE.
(let ((relative-level (org-export-get-relative-level headline info)))
(unless (> relative-level n) headline))))
info))
(let ((limit (plist-get info :headline-levels)))
(setq n (if (wholenump n) (min n limit) limit))
(org-element-map (plist-get info :parse-tree) 'headline
#'(lambda (headline)
(unless (org-element-property :footnote-section-p headline)
(let ((level (org-export-get-relative-level headline info)))
(and (<= level n) headline))))
info)))
(defun org-export-collect-elements (type info &optional predicate)
"Collect referenceable elements of a determined type.

View File

@ -2485,6 +2485,36 @@ Another text. (ref:text)
info))))
;;; Tables of Contents
(ert-deftest test-org-export/collect-headlines ()
"Test `org-export-collect-headlines' specifications."
;; Standard test.
(should
(= 2
(length
(org-test-with-parsed-data "* H1\n** H2"
(org-export-collect-headlines info)))))
;; Do not collect headlines below optional argument.
(should
(= 1
(length
(org-test-with-parsed-data "* H1\n** H2"
(org-export-collect-headlines info 1)))))
;; Never collect headlines below maximum headline level.
(should
(= 1
(length
(org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
(org-export-collect-headlines info)))))
(should
(= 1
(length
(org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
(org-export-collect-headlines info 2))))))
;;; Templates