Browse Source

org-element: Fix caption parsing

* lisp/org-element.el (org-element--collect-affiliated-keywords): Fix
  caption parsing.
* testing/lisp/test-org-element.el: Add tests.
Nicolas Goaziou 7 years ago
parent
commit
4a7c99134c
2 changed files with 37 additions and 3 deletions
  1. 2 2
      lisp/org-element.el
  2. 35 1
      testing/lisp/test-org-element.el

+ 2 - 2
lisp/org-element.el

@@ -3492,7 +3492,7 @@ CDR a plist of keywords and values."
 	  output)
       (unless (bobp)
 	(while (and (not (bobp)) (progn (forward-line -1) (looking-at key-re)))
-	  (let* ((raw-kwd (upcase (or (match-string 2) (match-string 1))))
+	  (let* ((raw-kwd (upcase (match-string 1)))
 		 ;; Apply translation to RAW-KWD.  From there, KWD is
 		 ;; the official keyword.
 		 (kwd (or (cdr (assoc raw-kwd trans-list)) raw-kwd))
@@ -3506,7 +3506,7 @@ CDR a plist of keywords and values."
 		 ;; value.  Maybe parse it.
 		 (dual-value
 		  (and (member kwd duals)
-		       (let ((sec (org-match-string-no-properties 3)))
+		       (let ((sec (org-match-string-no-properties 2)))
 			 (if (or (not sec) (not (member kwd parsed))) sec
 			   (org-element-parse-secondary-string sec restrict)))))
 		 ;; Attribute a property name to KWD.

+ 35 - 1
testing/lisp/test-org-element.el

@@ -154,6 +154,40 @@ Some other text
 
 ;;; Test Parsers
 
+;;;; Affiliated Keywords
+
+(ert-deftest test-org-element/affiliated-keywords-parser ()
+  "Test affiliated keywords parsing."
+  ;; Read simple keywords.
+  (should
+   (equal "para"
+	  (org-element-property
+	   :name
+	   (org-test-with-temp-text "#+NAME: para\nParagraph"
+	     (org-element-at-point)))))
+  ;; Parse multiple keywords.
+  (should
+   (equal
+    '("line1" "line2")
+    (org-element-property
+     :attr_ascii
+     (org-test-with-temp-text
+	 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph"
+       (org-element-at-point)))))
+  ;; Parse "parsed" keywords.
+  (should
+   (equal
+    '("caption")
+    (org-test-with-temp-text "#+CAPTION: caption\nParagraph"
+      (car (org-element-property :caption (org-element-at-point))))))
+  ;; Parse dual keywords.
+  (should
+   (equal
+    '(("long") "short")
+    (org-test-with-temp-text "#+CAPTION[short]: long\nParagraph"
+      (org-element-property :caption (org-element-at-point))))))
+
+
 ;;;; Babel Call
 
 (ert-deftest test-org-element/babel-call-parser ()
@@ -1616,7 +1650,7 @@ Outside list"
 
 ;;; Test Interpreters.
 
-(ert-deftest test-org-element/interpret-affiliated-keywords ()
+(ert-deftest test-org-element/affiliated-keywords-interpreter ()
   "Test if affiliated keywords are correctly interpreted."
   ;; Interpret simple keywords.
   (should