ox-org: Fix missing footnote definitions

* lisp/ox-org.el (org-org-headline): Ignore footnote sections.
(org-org-section): New function.

Some footnote definitions may be outside of the scope of the export
and, therefore, do not appear in the generated output.  This patch
ensures that all footnote definitions appear at the end of the section
they belong to.

Thanks to Leonard Randall for reporting it.
http://permalink.gmane.org/gmane.emacs.orgmode/86558
This commit is contained in:
Nicolas Goaziou 2014-05-21 18:33:53 +02:00
parent 7d6cc7f0bf
commit 844a6494c3
1 changed files with 39 additions and 11 deletions

View File

@ -65,7 +65,7 @@ setting of `org-html-htmlize-output-type' is 'css."
(entity . org-org-identity)
(example-block . org-org-identity)
(fixed-width . org-org-identity)
(footnote-definition . org-org-identity)
(footnote-definition . ignore)
(footnote-reference . org-org-identity)
(headline . org-org-headline)
(horizontal-rule . org-org-identity)
@ -87,7 +87,7 @@ setting of `org-html-htmlize-output-type' is 'css."
(quote-block . org-org-identity)
(quote-section . org-org-identity)
(radio-target . org-org-identity)
(section . org-org-identity)
(section . org-org-section)
(special-block . org-org-identity)
(src-block . org-org-identity)
(statistics-cookie . org-org-identity)
@ -122,15 +122,16 @@ CONTENTS is its contents, as a string or nil. INFO is ignored."
(defun org-org-headline (headline contents info)
"Transcode HEADLINE element back into Org syntax.
CONTENTS is its contents, as a string or nil. INFO is ignored."
(unless (plist-get info :with-todo-keywords)
(org-element-put-property headline :todo-keyword nil))
(unless (plist-get info :with-tags)
(org-element-put-property headline :tags nil))
(unless (plist-get info :with-priority)
(org-element-put-property headline :priority nil))
(org-element-put-property headline :level
(org-export-get-relative-level headline info))
(org-element-headline-interpreter headline contents))
(unless (org-element-property :footnote-section-p headline)
(unless (plist-get info :with-todo-keywords)
(org-element-put-property headline :todo-keyword nil))
(unless (plist-get info :with-tags)
(org-element-put-property headline :tags nil))
(unless (plist-get info :with-priority)
(org-element-put-property headline :priority nil))
(org-element-put-property headline :level
(org-export-get-relative-level headline info))
(org-element-headline-interpreter headline contents)))
(defun org-org-keyword (keyword contents info)
"Transcode KEYWORD element back into Org syntax.
@ -144,6 +145,33 @@ keywords targeted at other export back-ends."
org-element-block-name-alist))
(org-element-keyword-interpreter keyword nil)))
(defun org-org-section (section contents info)
"Transcode SECTION element back into Org syntax.
CONTENTS is the contents of the section. INFO is a plist used as
a communication channel."
(concat
(org-element-normalize-string contents)
;; Insert footnote definitions appearing for the first time in this
;; section. Indeed, some of them may not be available to narrowing
;; so we make sure all of them are included in the result.
(let ((footnotes-alist
(org-element-map section 'footnote-reference
(lambda (fn)
(and (not (org-element-property :inline-definition fn))
(org-export-footnote-first-reference-p fn info)
(cons (org-element-property :label fn)
(org-export-get-footnote-definition fn info))))
info)))
(and footnotes-alist
(concat "\n"
(mapconcat
(lambda (d)
(org-element-normalize-string
(concat (format "[%s] "(car d))
(org-export-data (cdr d) info))))
footnotes-alist "\n"))))
(make-string (or (org-element-property :post-blank section) 0) ?\n)))
;;;###autoload
(defun org-org-export-as-org (&optional async subtreep visible-only ext-plist)
"Export current buffer to an Org buffer.