* lisp/ox.el (org-export--skip-p): Skip property drawers when
:with-properties is a list and none of the drawer's properties are selected.
* testing/lisp/test-ox.el (test-org-export/handle-options): Test that
property drawer is skipped if :with-properties is a list and none of the
drawer's properties are selected.

When `org-export-with-properties' is a list, property drawers where none
of the listed properties are present were still exported, with literal
`nil' in place of drawer contents.  Skip such drawers entirely.

TINYCHANGE
---
 lisp/ox.el              | 13 ++++++++++++-
 testing/lisp/test-ox.el |  6 ++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 182aefc1b..6674bf98a 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1869,7 +1869,18 @@ not exported."
              (not (member-ignore-case (org-element-property :key datum)
                                     properties-set))))))
     (planning (not (plist-get options :with-planning)))
-    (property-drawer (not (plist-get options :with-properties)))
+    (property-drawer
+     (let ((properties (plist-get options :with-properties)))
+       (cond
+       ((null properties) t)
+       ((eq properties t) nil)
+       ((consp properties)
+        (not
+         (org-element-map (org-element-contents datum) 'node-property
+           (lambda (p)
+             (member-ignore-case (org-element-property :key p)
+                                 properties))
+           nil t))))))
     (statistics-cookie (not (plist-get options :with-statistics-cookies)))
     (table (not (plist-get options :with-tables)))
     (table-cell
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index e58c776e9..bc89729db 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -889,6 +889,12 @@ Paragraph"
              "* H1\n  :PROPERTIES:\n  :A: 1\n  :B: 2\n:END:"
            (org-export-as (org-test-default-backend)
                           nil nil nil '(:with-properties ("B"))))))
+  (should
+   (equal "* H1\n"
+         (org-test-with-temp-text
+             "* H1\n  :PROPERTIES:\n  :A: 1\n  :B: 2\n:END:"
+           (org-export-as (org-test-default-backend)
+                          nil nil nil '(:with-properties ("C"))))))
   ;; Statistics cookies.
   (should
    (equal "* Stats"
-- 
2.54.0


Reply via email to