forked from mirrors/org-mode
ox: Fix export of empty footnote definitions outside scope
* lisp/ox.el (org-export-get-footnote-definition): When a definition is empty, but does exist, return the empty string instead of raising an error. * testing/lisp/test-ox.el (test-org-export/get-footnote-definition): New test. Reported-by: Mark Edgington <edgimar@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/107873>
This commit is contained in:
parent
0279d84cd7
commit
85dd02b0dd
18
lisp/ox.el
18
lisp/ox.el
|
@ -3666,13 +3666,25 @@ definition can be found, raise an error."
|
||||||
(let ((hash (make-hash-table :test #'equal)))
|
(let ((hash (make-hash-table :test #'equal)))
|
||||||
(plist-put info :footnote-definition-cache hash)
|
(plist-put info :footnote-definition-cache hash)
|
||||||
hash))))
|
hash))))
|
||||||
(or (gethash label cache)
|
(or
|
||||||
|
(gethash label cache)
|
||||||
(puthash label
|
(puthash label
|
||||||
(org-element-map (plist-get info :parse-tree)
|
(org-element-map (plist-get info :parse-tree)
|
||||||
'(footnote-definition footnote-reference)
|
'(footnote-definition footnote-reference)
|
||||||
(lambda (f)
|
(lambda (f)
|
||||||
(and (equal (org-element-property :label f) label)
|
(cond
|
||||||
(org-element-contents f)))
|
;; Skip any footnote with a different
|
||||||
|
;; label. Also skip any standard footnote
|
||||||
|
;; reference with the same label since those
|
||||||
|
;; cannot contain a definition.
|
||||||
|
((not (equal (org-element-property :label f) label)) nil)
|
||||||
|
((eq (org-element-property :type f) 'standard) nil)
|
||||||
|
((org-element-contents f))
|
||||||
|
;; Even if the contents are empty, we can not
|
||||||
|
;; return nil since that would eventually raise
|
||||||
|
;; the error. Instead, return the equivalent
|
||||||
|
;; empty string.
|
||||||
|
(t "")))
|
||||||
info t)
|
info t)
|
||||||
cache)
|
cache)
|
||||||
(error "Definition not found for footnote %s" label))))))
|
(error "Definition not found for footnote %s" label))))))
|
||||||
|
|
|
@ -1887,6 +1887,61 @@ Para2"
|
||||||
(org-export-get-footnote-number ref info nil)))
|
(org-export-get-footnote-number ref info nil)))
|
||||||
info)))))
|
info)))))
|
||||||
|
|
||||||
|
(ert-deftest test-org-export/get-footnote-definition ()
|
||||||
|
"Test `org-export-get-footnote-definition' specifications."
|
||||||
|
;; Standard test.
|
||||||
|
(should
|
||||||
|
(equal "A\n"
|
||||||
|
(org-element-interpret-data
|
||||||
|
(org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info)))))
|
||||||
|
;; Raise an error if no definition is found.
|
||||||
|
(should-error
|
||||||
|
(org-test-with-parsed-data "Text[fn:1]"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info)))
|
||||||
|
;; Find inline definitions.
|
||||||
|
(should
|
||||||
|
(equal "A"
|
||||||
|
(org-element-interpret-data
|
||||||
|
(org-test-with-parsed-data "Text[fn:1:A]"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info)))))
|
||||||
|
;; Find anonymous definitions.
|
||||||
|
(should
|
||||||
|
(equal "A"
|
||||||
|
(org-element-interpret-data
|
||||||
|
(org-test-with-parsed-data "Text[fn::A]"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info)))))
|
||||||
|
;; Find empty definitions.
|
||||||
|
(should
|
||||||
|
(equal ""
|
||||||
|
(org-element-interpret-data
|
||||||
|
(org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info)))))
|
||||||
|
(should
|
||||||
|
(equal ""
|
||||||
|
(org-element-interpret-data
|
||||||
|
(org-test-with-parsed-data "Text[fn:1:]"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info)))))
|
||||||
|
(should
|
||||||
|
(equal ""
|
||||||
|
(org-element-interpret-data
|
||||||
|
(org-test-with-parsed-data "Text[fn::]"
|
||||||
|
(org-export-get-footnote-definition
|
||||||
|
(org-element-map tree 'footnote-reference #'identity nil t)
|
||||||
|
info))))))
|
||||||
|
|
||||||
(ert-deftest test-org-export/collect-footnote-definitions ()
|
(ert-deftest test-org-export/collect-footnote-definitions ()
|
||||||
"Test `org-export-collect-footnote-definitions' specifications."
|
"Test `org-export-collect-footnote-definitions' specifications."
|
||||||
(should
|
(should
|
||||||
|
|
Loading…
Reference in New Issue