branch: externals/org
commit 7d1e3dc38ea7fcd9ff57ace883370de1d5f902d8
Author: Bruno BARBIER <brubar...@gmail.com>
Commit: Ihor Radchenko <yanta...@posteo.net>

    org-element-special-block-interpreter: Fix when no content
    
    * lisp/org-element.el (org-element-special-block-interpreter): Use
    empty string when content is nil.
    
    *
    testing/lisp/test-org-element.el 
(test-org-element/special-block-interpreter):
    Test the case with no content.
---
 lisp/org-element.el              |  2 +-
 testing/lisp/test-org-element.el | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 7b26e877e3..ca3b61b49f 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -1910,7 +1910,7 @@ Assume point is at the beginning of the block."
   "Interpret SPECIAL-BLOCK element as Org syntax.
 CONTENTS is the contents of the element."
   (let ((block-type (org-element-property :type special-block)))
-    (format "#+begin_%s\n%s#+end_%s" block-type contents block-type)))
+    (format "#+begin_%s\n%s#+end_%s" block-type (or contents "") block-type)))
 
 
 
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 187cadf7a6..985108e375 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -2425,7 +2425,11 @@ Outside list"
   ;; Handle non-empty blank line at the end of buffer.
   (should
    (org-test-with-temp-text "#+BEGIN_SPECIAL\nC\n#+END_SPECIAL\n "
-     (= (org-element-property :end (org-element-at-point)) (point-max)))))
+     (= (org-element-property :end (org-element-at-point)) (point-max))))
+  ;; When contents is empty, the parsed contents is nil.
+  (should
+   (org-test-with-temp-text "#+BEGIN_SPECIAL\n#+END_SPECIAL"
+     (eq nil (org-element-contents (org-element-at-point))))))
 
 
 ;;;; Src Block
@@ -2943,7 +2947,11 @@ Outside list"
   "Test special block interpreter."
   (should (equal (org-test-parse-and-interpret
                  "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
-                "#+begin_SPECIAL\nTest\n#+end_SPECIAL\n")))
+                "#+begin_SPECIAL\nTest\n#+end_SPECIAL\n"))
+  ;; No content
+  (should (equal (org-test-parse-and-interpret
+                 "#+BEGIN_SPECIAL\n#+END_SPECIAL")
+                "#+begin_SPECIAL\n#+end_SPECIAL\n")))
 
 (ert-deftest test-org-element/babel-call-interpreter ()
   "Test Babel call interpreter."

Reply via email to