diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-06-07 23:45:17 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-06-07 23:45:17 +0200 |
commit | 84cfa58d4adefd04ffde9708dd4d7f175ee1c381 (patch) | |
tree | cee28d3854d175338884c172bf8ac193cca0f4f0 | |
parent | 1c71172c54a3d00143aeee32c7c3cc54144a743c (diff) | |
download | org-mode-84cfa58d4adefd04ffde9708dd4d7f175ee1c381.tar.gz |
org-element: Fix footnote definition parser
* lisp/org-element.el (org-element-footnote-definition-parser):
* testing/lisp/test-org-element.el (test-org-element/footnote-definition-parser):
Add tests.
-rw-r--r-- | lisp/org-element.el | 31 | ||||
-rw-r--r-- | testing/lisp/test-org-element.el | 31 |
2 files changed, 35 insertions, 27 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el index 004ef5b..f4b2a39 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -879,14 +879,14 @@ Assume point is at the beginning of the footnote definition." (match-string-no-properties 1))) (begin (car affiliated)) (post-affiliated (point)) - (ending + (end (save-excursion (end-of-line) (cond ((not (re-search-forward org-element--footnote-separator limit t)) limit) - ((eq (char-after (match-beginning 0)) ?\[) + ((eq ?\[ (char-after (match-beginning 0))) ;; At a new footnote definition, make sure we end ;; before any affiliated keyword above. (forward-line -1) @@ -894,26 +894,27 @@ Assume point is at the beginning of the footnote definition." (looking-at-p org-element--affiliated-re)) (forward-line -1)) (line-beginning-position 2)) - (t (match-beginning 0))))) + ((eq ?* (char-after (match-beginning 0))) (match-beginning 0)) + (t (skip-chars-forward " \r\t\n" limit) + (if (= limit (point)) limit (line-beginning-position)))))) (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) - (if (eobp) (point) (line-beginning-position))))) + (progn (search-forward "]") + (skip-chars-forward " \r\t\n" end) + (cond ((= (point) end) nil) + ((= (line-beginning-position) post-affiliated) (point)) + (t (line-beginning-position))))) + (contents-end + (progn (goto-char end) + (skip-chars-backward " \r\t\n") + (line-beginning-position 2)))) (list 'footnote-definition (nconc (list :label label :begin begin :end end :contents-begin contents-begin - :contents-end contents-end - :post-blank (count-lines ending end) + :contents-end (and contents-begin contents-end) + :post-blank (count-lines contents-end end) :post-affiliated post-affiliated) (cdr affiliated)))))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index cea02ab..f3f6868 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -920,20 +920,21 @@ 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))) - ;; Footnote with more contents + (eq (org-element-type (org-element-at-point)) 'footnote-definition))) + ;; 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))))) + (= 29 (org-test-with-temp-text "[fn:1] Definition\n\n| a | b |" + (org-element-property :end (org-element-at-point))))) + ;; Test difference between :contents-end and :end property + (should + (< (org-test-with-temp-text "[fn:1] Definition\n\n\n" + (org-element-property :contents-end (org-element-at-point))) + (org-test-with-temp-text "[fn:1] Definition\n\n\n" + (org-element-property :end (org-element-at-point))))) ;; 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-test-with-temp-text "[fn:1] <point>- no item" + (eq (org-element-type (org-element-at-point)) 'item))) ;; Correctly handle footnote starting with an empty line. (should (= 9 @@ -953,7 +954,13 @@ Some other text (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 "#")))) + (looking-at "#"))) + ;; An empty footnote has no contents. + (should-not + (org-test-with-temp-text "[fn:1]\n\n" + (let ((footnote (org-element-at-point))) + (or (org-element-property :contents-begin footnote) + (org-element-property :contents-end footnote)))))) ;;;; Footnotes Reference. |