1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

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.
This commit is contained in:
Nicolas Goaziou 2012-09-13 16:51:54 +02:00
parent 0b13ec8c1b
commit fe140488aa
4 changed files with 54 additions and 7 deletions

View File

@ -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
;;

View File

@ -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.

View File

@ -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."

View File

@ -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