Function: org-export-collect-headlines

org-export-collect-headlines is a byte-compiled function defined in ox.el.gz.

Signature

(org-export-collect-headlines INFO &optional N SCOPE)

Documentation

Collect headlines in order to build a table of contents.

INFO is a plist used as a communication channel.

When optional argument N is an integer, it specifies the depth of the table of contents. Otherwise, it is set to the value of the last headline level. See org-export-headline-levels for more information.

Optional argument SCOPE, when non-nil, is an element. If it is a headline, only children of SCOPE are collected. Otherwise, collect children of the headline containing provided element. If there is no such headline, collect all headlines. In any case, argument N becomes relative to the level of that headline.

Return a list of all exportable headlines as parsed elements. Footnote sections are ignored.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
;;;; For Tables of Contents
;;
;; `org-export-collect-headlines' builds a list of all exportable
;; headline elements, maybe limited to a certain depth.  One can then
;; easily parse it and transcode it.
;;
;; Building lists of tables, figures or listings is quite similar.
;; Once the generic function `org-export-collect-elements' is defined,
;; `org-export-collect-tables', `org-export-collect-figures' and
;; `org-export-collect-listings' can be derived from it.
;;
;; `org-export-toc-entry-backend' builds a special anonymous back-end
;; useful to export table of contents' entries.

(defun org-export-collect-headlines (info &optional n scope)
  "Collect headlines in order to build a table of contents.

INFO is a plist used as a communication channel.

When optional argument N is an integer, it specifies the depth of
the table of contents.  Otherwise, it is set to the value of the
last headline level.  See `org-export-headline-levels' for more
information.

Optional argument SCOPE, when non-nil, is an element.  If it is
a headline, only children of SCOPE are collected.  Otherwise,
collect children of the headline containing provided element.  If
there is no such headline, collect all headlines.  In any case,
argument N becomes relative to the level of that headline.

Return a list of all exportable headlines as parsed elements.
Footnote sections are ignored."
  (let* ((scope (cond ((not scope) (plist-get info :parse-tree))
		      ((eq (org-element-type scope) 'headline) scope)
		      ((org-export-get-parent-headline scope))
		      (t (plist-get info :parse-tree))))
	 (limit (plist-get info :headline-levels))
	 (n (if (not (wholenump n)) limit
	      (min (if (eq (org-element-type scope) 'org-data) n
		     (+ (org-export-get-relative-level scope info) n))
		   limit))))
    (org-element-map (org-element-contents scope) 'headline
      (lambda (h)
	(and (not (org-element-property :footnote-section-p h))
	     (not (equal "notoc"
			 (org-export-get-node-property :UNNUMBERED h t)))
	     (>= n (org-export-get-relative-level h info))
	     h))
      info)))