Browse Source

org-element: Allow duals keywords with only secondary value

* lisp/org-element.el (org-element--collect-affiliated-keywords):
  Allow duals keywords with only secondary value.
* testing/lisp/test-org-element.el: Add test.

This patch allows to parse correctly the following:

    #+CAPTION[short caption]:
    #+CAPTION: Very long caption
    Some paragraph.
Nicolas Goaziou 5 years ago
parent
commit
98d5666bac
2 changed files with 7 additions and 1 deletions
  1. 2 1
      lisp/org-element.el
  2. 5 0
      testing/lisp/test-org-element.el

+ 2 - 1
lisp/org-element.el

@@ -3822,7 +3822,8 @@ position of point and CDR is nil."
 	  ;; Now set final shape for VALUE.
 	  (when parsedp
 	    (setq value (org-element-parse-secondary-string value restrict)))
-	  (when dualp (setq value (and value (cons value dual-value))))
+	  (when dualp
+	    (setq value (and (or value dual-value) (cons value dual-value))))
 	  (when (or (member kwd org-element-multiple-keywords)
 		    ;; Attributes can always appear on multiple lines.
 		    (string-match "^ATTR_" kwd))

+ 5 - 0
testing/lisp/test-org-element.el

@@ -208,6 +208,11 @@ Some other text
    (equal
     '((("l2") "s2") (("l1") "s1"))
     (org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
+      (org-element-property :caption (org-element-at-point)))))
+  (should
+   (equal
+    '((("l1")) (nil "s1"))
+    (org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
       (org-element-property :caption (org-element-at-point))))))