ox: Correctly handle footnote section

* lisp/ox.el (org-export--collect-headline-numbering): Remove footnote
  section from TOC.
(org-export-collect-headlines): Do not count footnote section when
numbering a headline.
* testing/lisp/test-ox.el: Add tests.
This commit is contained in:
Nicolas Goaziou 2013-02-13 15:51:08 +01:00
parent a6ac2b5fed
commit 39ed70495c
2 changed files with 57 additions and 38 deletions

View File

@ -1795,10 +1795,12 @@ DATA is the parse tree. OPTIONS is the plist holding export
options. options.
Return an alist whose key is an headline and value is its Return an alist whose key is an headline and value is its
associated numbering \(in the shape of a list of numbers\)." associated numbering \(in the shape of a list of numbers\) or nil
for a footnotes section."
(let ((numbering (make-vector org-export-max-depth 0))) (let ((numbering (make-vector org-export-max-depth 0)))
(org-element-map data 'headline (org-element-map data 'headline
(lambda (headline) (lambda (headline)
(unless (org-element-property :footnote-section-p headline)
(let ((relative-level (let ((relative-level
(1- (org-export-get-relative-level headline options)))) (1- (org-export-get-relative-level headline options))))
(cons (cons
@ -1807,7 +1809,7 @@ associated numbering \(in the shape of a list of numbers\)."
for idx from 0 to org-export-max-depth for idx from 0 to org-export-max-depth
when (< idx relative-level) collect n when (< idx relative-level) collect n
when (= idx relative-level) collect (aset numbering idx (1+ n)) when (= idx relative-level) collect (aset numbering idx (1+ n))
when (> idx relative-level) do (aset numbering idx 0))))) when (> idx relative-level) do (aset numbering idx 0))))))
options))) options)))
(defun org-export--populate-ignore-list (data options) (defun org-export--populate-ignore-list (data options)
@ -4434,13 +4436,15 @@ the table of contents. Otherwise, it is set to the value of the
last headline level. See `org-export-headline-levels' for more last headline level. See `org-export-headline-levels' for more
information. information.
Return a list of all exportable headlines as parsed elements." 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))) (unless (wholenump n) (setq n (plist-get info :headline-levels)))
(org-element-map (plist-get info :parse-tree) 'headline (org-element-map (plist-get info :parse-tree) 'headline
(lambda (headline) (lambda (headline)
(unless (org-element-property :footnote-section-p headline)
;; Strip contents from HEADLINE. ;; Strip contents from HEADLINE.
(let ((relative-level (org-export-get-relative-level headline info))) (let ((relative-level (org-export-get-relative-level headline info)))
(unless (> relative-level n) headline))) (unless (> relative-level n) headline))))
info)) info))
(defun org-export-collect-elements (type info &optional predicate) (defun org-export-collect-elements (type info &optional predicate)

View File

@ -858,7 +858,22 @@ Paragraph[fn:1]"
(should (should
(org-test-with-parsed-data "[fn:1]" (org-test-with-parsed-data "[fn:1]"
(org-export-get-footnote-definition (org-export-get-footnote-definition
(org-element-map tree 'footnote-reference 'identity info t) info))))) (org-element-map tree 'footnote-reference 'identity info t) info)))
;; 7. Footnote section should be ignored in TOC and in headlines
;; numbering.
(should
(= 1 (let ((org-footnote-section "Footnotes"))
(length (org-test-with-parsed-data "* H1\n* Footnotes\n"
(org-export-collect-headlines info))))))
(should
(equal '(2)
(let ((org-footnote-section "Footnotes"))
(org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
(org-element-map tree 'headline
(lambda (hl)
(when (equal (org-element-property :raw-value hl) "H2")
(org-export-get-headline-number hl info)))
info t)))))))