org-export: Add `org-export-read-attribute' for normalized attr lines

* contrib/lisp/org-export.el (org-export-read-attribute): New function.
* testing/lisp/test-org-export.el: Add test.
This commit is contained in:
Nicolas Goaziou 2012-06-12 10:25:00 +02:00
parent 168c83e6d4
commit 68a595ce9d
2 changed files with 34 additions and 1 deletions

View File

@ -2649,6 +2649,20 @@ file should have."
;; macros, references, src-blocks, tables and tables of contents are
;; implemented.
;;;; For Affiliated Keywords
;;
;; `org-export-read-attribute' is a tool
(defun org-export-read-attribute (attribute element)
"Turn ATTRIBUTE property from ELEMENT into a plist.
This function assumes attributes are defined as \":keyword
value\" pairs. It is appropriate for `:attr_html' like
properties."
(let ((value (org-element-property attribute element)))
(and value
(read (format "(%s)" (mapconcat 'identity value " "))))))
;;;; For Export Snippets
;;
;; Every export snippet is transmitted to the back-end. Though, the

View File

@ -370,7 +370,7 @@ body\n")))
(should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
(ert-deftest test-org-export/set-element ()
"Test `org-export-set-element' property."
"Test `org-export-set-element' specifications."
(org-test-with-parsed-data "* Headline\n*a*"
(org-export-set-element
(org-element-map tree 'bold 'identity nil t)
@ -386,6 +386,25 @@ body\n")))
(org-element-map tree 'paragraph 'identity nil t)))))
;;; Affiliated Keywords
(ert-deftest test-org-export/read-attribute ()
"Test `org-export-read-attribute' specifications."
;; Standard test.
(should
(equal
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
(org-element-current-element)))
'(:a 1 :b 2)))
;; Return nil on empty attribute.
(should-not
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "Paragraph" (org-element-current-element)))))
;;; Footnotes