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
|
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
|
now handled as standard code blocks, i.e., the source code can appear
|
||||||
in the output, depending on the parameters.
|
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
|
** Miscellaneous
|
||||||
*** File names in links accept are now compatible with URI syntax
|
*** File names in links accept are now compatible with URI syntax
|
||||||
Absolute file names can now start with =///= in addition to =/=. E.g.,
|
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)
|
(or (org-element-property :alt-title headline)
|
||||||
(org-element-property :title headline)))
|
(org-element-property :title headline)))
|
||||||
|
|
||||||
(defun org-export-first-sibling-p (headline info)
|
(defun org-export-first-sibling-p (blob info)
|
||||||
"Non-nil when HEADLINE is the first sibling in its sub-tree.
|
"Non-nil when BLOB is the first sibling in its parent.
|
||||||
INFO is a plist used as a communication channel."
|
BLOB is an element or an object. If BLOB is a headline, non-nil
|
||||||
(not (eq (org-element-type (org-export-get-previous-element headline info))
|
means it is the first sibling in the sub-tree. INFO is a plist
|
||||||
'headline)))
|
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)
|
(defun org-export-last-sibling-p (blob info)
|
||||||
"Non-nil when HEADLINE is the last sibling in its sub-tree.
|
"Non-nil when BLOB is the last sibling in its parent.
|
||||||
INFO is a plist used as a communication channel."
|
BLOB is an element or an object. INFO is a plist used as
|
||||||
(not (org-export-get-next-element headline info)))
|
a communication channel."
|
||||||
|
(not (org-export-get-next-element blob info)))
|
||||||
|
|
||||||
|
|
||||||
;;;; For Keywords
|
;;;; For Keywords
|
||||||
|
|
|
@ -1719,7 +1719,20 @@ Paragraph[fn:1]"
|
||||||
(should
|
(should
|
||||||
(equal
|
(equal
|
||||||
'(yes yes no)
|
'(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
|
(org-element-map tree 'headline
|
||||||
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
|
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
|
||||||
info))))
|
info))))
|
||||||
|
@ -1743,6 +1756,12 @@ Paragraph[fn:1]"
|
||||||
(org-element-map tree 'headline
|
(org-element-map tree 'headline
|
||||||
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
|
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
|
||||||
info))))
|
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.
|
;; Ignore headlines not exported.
|
||||||
(should
|
(should
|
||||||
(equal
|
(equal
|
||||||
|
|
Loading…
Reference in New Issue