diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-01-14 09:31:24 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-01-14 09:40:43 +0100 |
commit | 7d0104f44933d924261ca254528557a4f10cdc76 (patch) | |
tree | 72fd27e4e49f467ed0370b1fe266d78d6274f225 | |
parent | 6c6b94e2747af3c45b37a4b050838ca4a422ca19 (diff) | |
download | org-mode-7d0104f44933d924261ca254528557a4f10cdc76.tar.gz |
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.
-rw-r--r-- | lisp/org-element.el | 44 | ||||
-rw-r--r-- | testing/lisp/test-org-element.el | 13 |
2 files changed, 41 insertions, 16 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el index e8fc6ea..33514ce 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -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) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 560d9cf..6347e87 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -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. |