diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-06-12 10:25:00 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-06-12 10:25:00 +0200 |
commit | 68a595ce9dd1ca03ce9c90e8474d2b11ad493022 (patch) | |
tree | f013ebf89774c84255819ee0e0c1774ca37aa976 | |
parent | 168c83e6d44d425d57d30d15b48980c9032be5b9 (diff) | |
download | org-mode-68a595ce9dd1ca03ce9c90e8474d2b11ad493022.tar.gz |
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.
-rw-r--r-- | contrib/lisp/org-export.el | 14 | ||||
-rw-r--r-- | testing/lisp/test-org-export.el | 21 |
2 files changed, 34 insertions, 1 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index 43cfce6..272594e 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -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 diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el index bfbb304..cb60db6 100644 --- a/testing/lisp/test-org-export.el +++ b/testing/lisp/test-org-export.el @@ -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) @@ -387,6 +387,25 @@ body\n"))) +;;; 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 (ert-deftest test-org-export/footnotes () |