forked from mirrors/org-mode
ox: Extend first and last sibling predicates to all elements
* lisp/ox.el (org-export-first-sibling-p, org-export-first-sibling-p): Extend to all elements and objects. * testing/lisp/test-ox.el (test-org-export/first-sibling-p, test-org-export/last-sibling-p): Add tests. * etc/ORG-NEWS: Document change.
This commit is contained in:
parent
9a34a13c07
commit
81906c52ae
|
@ -108,6 +108,8 @@ increased. See manual for details.
|
|||
Inline source code was used to be removed upon exporting. They are
|
||||
now handled as standard code blocks, i.e., the source code can appear
|
||||
in the output, depending on the parameters.
|
||||
*** Extend ~org-export-first-sibling-p~ and ~org-export-last-sibling-p~
|
||||
These functions now support any element or object, not only headlines.
|
||||
** Miscellaneous
|
||||
*** File names in links accept are now compatible with URI syntax
|
||||
Absolute file names can now start with =///= in addition to =/=. E.g.,
|
||||
|
|
21
lisp/ox.el
21
lisp/ox.el
|
@ -3887,16 +3887,19 @@ title is defined, fall-back to the regular title."
|
|||
(or (org-element-property :alt-title headline)
|
||||
(org-element-property :title headline)))
|
||||
|
||||
(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."
|
||||
(not (eq (org-element-type (org-export-get-previous-element headline info))
|
||||
'headline)))
|
||||
(defun org-export-first-sibling-p (blob info)
|
||||
"Non-nil when BLOB is the first sibling in its parent.
|
||||
BLOB is an element or an object. If BLOB is a headline, non-nil
|
||||
means it is the first sibling in the sub-tree. INFO is a plist
|
||||
used as a communication channel."
|
||||
(memq (org-element-type (org-export-get-previous-element blob info))
|
||||
'(nil section)))
|
||||
|
||||
(defun org-export-last-sibling-p (headline info)
|
||||
"Non-nil when HEADLINE is the last sibling in its sub-tree.
|
||||
INFO is a plist used as a communication channel."
|
||||
(not (org-export-get-next-element headline info)))
|
||||
(defun org-export-last-sibling-p (blob info)
|
||||
"Non-nil when BLOB is the last sibling in its parent.
|
||||
BLOB is an element or an object. INFO is a plist used as
|
||||
a communication channel."
|
||||
(not (org-export-get-next-element blob info)))
|
||||
|
||||
|
||||
;;;; For Keywords
|
||||
|
|
|
@ -1719,10 +1719,23 @@ Paragraph[fn:1]"
|
|||
(should
|
||||
(equal
|
||||
'(yes yes no)
|
||||
(org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
|
||||
(org-test-with-parsed-data "* H\n** H 2\n** H 3"
|
||||
(org-element-map tree 'headline
|
||||
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
|
||||
info))))
|
||||
(should
|
||||
(equal '(yes no)
|
||||
(org-test-with-parsed-data "- item\n\n para"
|
||||
(org-element-map tree 'paragraph
|
||||
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
|
||||
info))))
|
||||
;; Ignore sections for headlines.
|
||||
(should
|
||||
(equal '(yes yes)
|
||||
(org-test-with-parsed-data "* H\nSection\n** H 2"
|
||||
(org-element-map tree 'headline
|
||||
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
|
||||
info))))
|
||||
;; Ignore headlines not exported.
|
||||
(should
|
||||
(equal
|
||||
|
@ -1743,6 +1756,12 @@ Paragraph[fn:1]"
|
|||
(org-element-map tree 'headline
|
||||
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
|
||||
info))))
|
||||
(should
|
||||
(equal '(no yes)
|
||||
(org-test-with-parsed-data "- item\n\n para"
|
||||
(org-element-map tree 'paragraph
|
||||
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
|
||||
info))))
|
||||
;; Ignore headlines not exported.
|
||||
(should
|
||||
(equal
|
||||
|
|
Loading…
Reference in New Issue