From 4a7c99134c3c43e036f75cb3b9826a95e3a5b6fc Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 13 Sep 2012 13:03:55 +0200 Subject: [PATCH] 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. --- lisp/org-element.el | 4 ++-- testing/lisp/test-org-element.el | 36 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 3c6bbe578..d753f2589 100644 --- a/lisp/org-element.el +++ b/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. diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 8aa24b200..1318e86fe 100644 --- a/testing/lisp/test-org-element.el +++ b/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