From 68a595ce9dd1ca03ce9c90e8474d2b11ad493022 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 12 Jun 2012 10:25:00 +0200 Subject: [PATCH] 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. --- contrib/lisp/org-export.el | 14 ++++++++++++++ testing/lisp/test-org-export.el | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index 43cfce623..272594e0d 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 bfbb3041a..cb60db66e 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) @@ -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