1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-29 07:58:21 +00:00

org-element: Fix footnote definition parsing

* lisp/org-element.el (org-element--footnote-separator): New variable.
(org-element-footnote-definition-parser): Handle footnotes with
affiliated keywords.

* testing/lisp/test-org-element.el (test-org-element/footnote-definition-parser):
Add test.
This commit is contained in:
Nicolas Goaziou 2016-01-14 09:31:24 +01:00
parent 6c6b94e274
commit 7d0104f449
2 changed files with 41 additions and 16 deletions

View File

@ -796,6 +796,12 @@ CONTENTS is the contents of the element."
;;;; Footnote Definition
(defconst org-element--footnote-separator
(concat org-outline-regexp-bol "\\|"
org-footnote-definition-re "\\|"
"^\\([ \t]*\n\\)\\{2,\\}")
"Regexp used as a footnote definition separator.")
(defun org-element-footnote-definition-parser (limit affiliated)
"Parse a footnote definition.
@ -814,21 +820,29 @@ Assume point is at the beginning of the footnote definition."
(org-match-string-no-properties 1)))
(begin (car affiliated))
(post-affiliated (point))
(ending (save-excursion
(if (progn
(end-of-line)
(re-search-forward
(concat org-outline-regexp-bol "\\|"
org-footnote-definition-re "\\|"
"^\\([ \t]*\n\\)\\{2,\\}") limit 'move))
(match-beginning 0)
(point))))
(contents-begin (progn
(search-forward "]")
(skip-chars-forward " \r\t\n" ending)
(cond ((= (point) ending) nil)
((= (line-beginning-position) begin) (point))
(t (line-beginning-position)))))
(ending
(save-excursion
(end-of-line)
(cond
((not
(re-search-forward org-element--footnote-separator limit t))
limit)
((eq (char-after (match-beginning 0)) ?\[)
;; At a new footnote definition, make sure we end
;; before any affiliated keyword above.
(forward-line -1)
(while (and (> (point) post-affiliated)
(org-looking-at-p org-element--affiliated-re))
(forward-line -1))
(line-beginning-position 2))
(t (match-beginning 0)))))
(contents-begin
(progn
(search-forward "]")
(skip-chars-forward " \r\t\n" ending)
(cond ((= (point) ending) nil)
((= (line-beginning-position) post-affiliated) (point))
(t (line-beginning-position)))))
(contents-end (and contents-begin ending))
(end (progn (goto-char ending)
(skip-chars-forward " \r\t\n" limit)

View File

@ -930,7 +930,18 @@ Some other text
;; Handle non-empty blank line at the end of buffer.
(should
(org-test-with-temp-text "[fn:1] Definition\n "
(= (org-element-property :end (org-element-at-point)) (point-max)))))
(= (org-element-property :end (org-element-at-point)) (point-max))))
;; Footnote with attributes.
(should
(= 1
(org-test-with-temp-text "#+attr_latex: :offset 0in\n[fn:1] A footnote."
(length
(org-element-map (org-element-parse-buffer) 'footnote-definition
#'identity)))))
(should
(org-test-with-temp-text "[fn:1] 1\n\n#+attr_latex: :offset 0in\n[fn:2] 2"
(goto-char (org-element-property :end (org-element-at-point)))
(looking-at "#"))))
;;;; Footnotes Reference.