소스 검색

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.
Nicolas Goaziou 10 년 전
부모
커밋
81906c52ae
3개의 변경된 파일35개의 추가작업 그리고 11개의 파일을 삭제
  1. 2 0
      etc/ORG-NEWS
  2. 13 10
      lisp/ox.el
  3. 20 1
      testing/lisp/test-ox.el

+ 2 - 0
etc/ORG-NEWS

@@ -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.,

+ 13 - 10
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)
-  "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-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-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 (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
 ;;;; For Keywords

+ 20 - 1
testing/lisp/test-ox.el

@@ -1719,10 +1719,23 @@ 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
       (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))))
+  (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.
   ;; Ignore headlines not exported.
   (should
   (should
    (equal
    (equal
@@ -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