forked from mirrors/org-mode
org-export: New function to return a node property, even inherited
* contrib/lisp/org-export.el (org-export-get-node-property): New function. * testing/lisp/test-org-export.el: Add tests.
This commit is contained in:
parent
b60445cfd4
commit
66fe322120
|
@ -3148,6 +3148,26 @@ Any tag belonging to this list will also be removed."
|
|||
(member tag tags)))
|
||||
(org-element-property :tags element)))
|
||||
|
||||
(defun org-export-get-node-property (property blob &optional inherited)
|
||||
"Return node PROPERTY value for BLOB.
|
||||
|
||||
PROPERTY is normalized symbol (i.e. `:cookie-data'). BLOB is an
|
||||
element or object.
|
||||
|
||||
If optional argument INHERITED is non-nil, the value can be
|
||||
inherited from a parent headline.
|
||||
|
||||
Return value is a string or nil."
|
||||
(let ((headline (if (eq (org-element-type blob) 'headline) blob
|
||||
(org-export-get-parent-headline blob))))
|
||||
(if (not inherited) (org-element-property property blob)
|
||||
(let ((parent headline) value)
|
||||
(catch 'found
|
||||
(while parent
|
||||
(when (plist-member (nth 1 parent) property)
|
||||
(throw 'found (org-element-property property parent)))
|
||||
(setq parent (org-element-property :parent parent))))))))
|
||||
|
||||
(defun org-export-first-sibling-p (headline info)
|
||||
"Non-nil when HEADLINE is the first sibling in its sub-tree.
|
||||
INFO is a plist used as a communication channel."
|
||||
|
|
|
@ -716,6 +716,38 @@ Paragraph[fn:1]"
|
|||
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
|
||||
info '("ignore"))))))
|
||||
|
||||
(ert-deftest test-org-export/get-node-property ()
|
||||
"Test`org-export-get-node-property' specifications."
|
||||
;; Standard test.
|
||||
(should
|
||||
(equal "value"
|
||||
(org-test-with-parsed-data "* Headline
|
||||
:PROPERTIES:
|
||||
:prop: value
|
||||
:END:"
|
||||
(org-export-get-node-property
|
||||
:prop (org-element-map tree 'headline 'identity nil t)))))
|
||||
;; Test inheritance.
|
||||
(should
|
||||
(equal "value"
|
||||
(org-test-with-parsed-data "* Parent
|
||||
:PROPERTIES:
|
||||
:prop: value
|
||||
:END:
|
||||
** Headline
|
||||
Paragraph"
|
||||
(org-export-get-node-property
|
||||
:prop (org-element-map tree 'paragraph 'identity nil t) t))))
|
||||
;; Cannot return a value before the first headline.
|
||||
(should-not
|
||||
(org-test-with-parsed-data "Paragraph
|
||||
* Headline
|
||||
:PROPERTIES:
|
||||
:prop: value
|
||||
:END:"
|
||||
(org-export-get-node-property
|
||||
:prop (org-element-map tree 'paragraph 'identity nil t)))))
|
||||
|
||||
(ert-deftest test-org-export/first-sibling-p ()
|
||||
"Test `org-export-first-sibling-p' specifications."
|
||||
;; Standard test.
|
||||
|
|
Loading…
Reference in New Issue