summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-09-13 16:51:54 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-09-13 17:33:46 +0200
commitfe140488aa31fdc902624758765c20c2eba9119a (patch)
tree8d4b45ffeb6c56f01e5b06cdd642db2d24ee8b99
parent0b13ec8c1b5a7aceaa7a2a40a5a93194f023626b (diff)
downloadorg-mode-fe140488aa31fdc902624758765c20c2eba9119a.tar.gz
org-element: Allow multiple caption keywords
* lisp/org-element.el (org-element-multiple-keywords): Allow multiple caption keywords. * contrib/lisp/org-export.el (org-export-get-caption): New function. * testing/lisp/test-org-element.el: Add tests. * testing/lisp/test-org-export.el: Add tests.
-rw-r--r--contrib/lisp/org-export.el13
-rw-r--r--lisp/org-element.el4
-rw-r--r--testing/lisp/test-org-element.el23
-rw-r--r--testing/lisp/test-org-export.el21
4 files changed, 54 insertions, 7 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 41e7a38..bbaf995 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -2900,6 +2900,19 @@ properties."
(read (format "(%s)" (mapconcat 'identity value " ")))))))
(if property (plist-get attributes property) attributes)))
+(defun org-export-get-caption (element &optional shortp)
+ "Return caption from ELEMENT as a secondary string.
+
+When optional argument SHORTP is non-nil, return short caption,
+as a secondary string, instead.
+
+Caption lines are separated by a white space."
+ (let ((full-caption (org-element-property :caption element)) caption)
+ (dolist (line full-caption (cdr caption))
+ (let ((cap (funcall (if shortp 'cdr 'car) line)))
+ (when cap
+ (setq caption (nconc caption (list " ") (copy-sequence cap))))))))
+
;;;; For Export Snippets
;;
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 47628c7..bcdd336 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -248,8 +248,8 @@ Don't modify it, set `org-element-affiliated-keywords' instead.")
The key is the old name and the value the new one. The property
holding their value will be named after the translated name.")
-(defconst org-element-multiple-keywords '("HEADER")
- "List of affiliated keywords that can occur more that once in an element.
+(defconst org-element-multiple-keywords '("CAPTION" "HEADER")
+ "List of affiliated keywords that can occur more than once in an element.
Their value will be consed into a list of strings, which will be
returned as the value of the property.
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index d6cbbbd..a044e65 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -177,14 +177,20 @@ Some other text
;; Parse "parsed" keywords.
(should
(equal
- '("caption")
+ '(("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")
+ '((("long") "short"))
(org-test-with-temp-text "#+CAPTION[short]: long\nParagraph"
+ (org-element-property :caption (org-element-at-point)))))
+ ;; Allow multiple caption keywords.
+ (should
+ (equal
+ '((("l1") "s1") (("l2") "s2"))
+ (org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
(org-element-property :caption (org-element-at-point))))))
@@ -1688,14 +1694,21 @@ Outside list"
(should
(equal
(org-element-interpret-data
- '(org-data nil (paragraph (:caption ("caption")) "Paragraph")))
+ '(org-data nil (paragraph (:caption (("caption"))) "Paragraph")))
"#+CAPTION: caption\nParagraph\n"))
;; Interpret dual keywords.
(should
(equal
(org-element-interpret-data
- '(org-data nil (paragraph (:caption (("long") "short")) "Paragraph")))
- "#+CAPTION[short]: long\nParagraph\n")))
+ '(org-data nil (paragraph (:caption ((("long") "short"))) "Paragraph")))
+ "#+CAPTION[short]: long\nParagraph\n"))
+ ;; Interpret multiple parsed dual keywords.
+ (should
+ (equal
+ (org-element-interpret-data
+ '(org-data nil (paragraph
+ (:caption ((("l1") "s1") (("l2") "s2"))) "Paragraph")))
+ "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph\n")))
(ert-deftest test-org-element/center-block-interpreter ()
"Test center block interpreter."
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index 59987a0..3d3c846 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -479,6 +479,27 @@ body\n")))
:attr_html
(org-test-with-temp-text "Paragraph" (org-element-at-point)))))
+(ert-deftest test-org-export/get-caption ()
+ "Test `org-export-get-caption' specifications."
+ ;; Without optional argument, return long caption
+ (should
+ (equal
+ '("l")
+ (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
+ (org-export-get-caption (org-element-at-point)))))
+ ;; With optional argument, return short caption.
+ (should
+ (equal
+ '("s")
+ (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
+ (org-export-get-caption (org-element-at-point) t))))
+ ;; Multiple lines are separated by white spaces.
+ (should
+ (equal
+ '("a" " " "b")
+ (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
+ (org-export-get-caption (org-element-at-point))))))
+
;;; Export Snippets