Bladeren bron

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.
Bruno BARBIER 2 jaren geleden
bovenliggende
commit
7d1e3dc38e
2 gewijzigde bestanden met toevoegingen van 11 en 3 verwijderingen
  1. 1 1
      lisp/org-element.el
  2. 10 2
      testing/lisp/test-org-element.el

+ 1 - 1
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)))
 
 
 

+ 10 - 2
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."