org-element: Fix footnote definition parsing

* lisp/org-element.el (org-element-footnote-definition-parser): Fix
  value for :contents-begin when first line of footnote definition is
  empty besides the label.
* testing/lisp/test-org-element.el (test-org-element/footnote-definition-parser):
  Add test.
This commit is contained in:
Nicolas Goaziou 2013-09-11 17:07:09 +02:00
parent af9c0fbf91
commit 7b4d8bb614
2 changed files with 17 additions and 9 deletions

View File

@ -683,9 +683,12 @@ Assume point is at the beginning of the footnote definition."
"^\\([ \t]*\n\\)\\{2,\\}") limit 'move))
(match-beginning 0)
(point))))
(contents-begin (progn (search-forward "]")
(skip-chars-forward " \r\t\n" ending)
(and (/= (point) ending) (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)))))
(contents-end (and contents-begin ending))
(end (progn (goto-char ending)
(skip-chars-forward " \r\t\n" limit)

View File

@ -760,21 +760,26 @@ Some other text
"Test `footnote-definition' parser."
(should
(org-test-with-temp-text "[fn:1] Definition"
(org-element-map
(org-element-parse-buffer) 'footnote-definition 'identity nil t)))
(org-element-map (org-element-parse-buffer) 'footnote-definition
'identity nil t)))
;; Footnote with more contents
(should
(= 29
(org-element-property
:end
(org-test-with-temp-text "[fn:1] Definition\n\n| a | b |"
(org-element-map
(org-element-parse-buffer)
'footnote-definition 'identity nil t)))))
(org-element-map (org-element-parse-buffer) 'footnote-definition
'identity nil t)))))
;; Footnote starting with special syntax.
(should-not
(org-test-with-temp-text "[fn:1] - no item"
(org-element-map (org-element-parse-buffer) 'item 'identity))))
(org-element-map (org-element-parse-buffer) 'item 'identity)))
;; Correctly handle footnote starting with an empty line.
(should
(= 9
(org-test-with-temp-text "[fn:1]\n\n Body"
(org-element-property :contents-begin
(org-element-at-point))))))
;;;; Footnotes Reference.