forked from mirrors/org-mode
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:
parent
168c83e6d4
commit
68a595ce9d
|
@ -2649,6 +2649,20 @@ file should have."
|
||||||
;; macros, references, src-blocks, tables and tables of contents are
|
;; macros, references, src-blocks, tables and tables of contents are
|
||||||
;; implemented.
|
;; 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
|
;;;; For Export Snippets
|
||||||
;;
|
;;
|
||||||
;; Every export snippet is transmitted to the back-end. Though, the
|
;; Every export snippet is transmitted to the back-end. Though, the
|
||||||
|
|
|
@ -370,7 +370,7 @@ body\n")))
|
||||||
(should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
|
(should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
|
||||||
|
|
||||||
(ert-deftest test-org-export/set-element ()
|
(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-test-with-parsed-data "* Headline\n*a*"
|
||||||
(org-export-set-element
|
(org-export-set-element
|
||||||
(org-element-map tree 'bold 'identity nil t)
|
(org-element-map tree 'bold 'identity nil t)
|
||||||
|
@ -386,6 +386,25 @@ body\n")))
|
||||||
(org-element-map tree 'paragraph 'identity nil t)))))
|
(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
|
;;; Footnotes
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue