From 54939c4044fb407b068c0666c258ccd01e59c2af Mon Sep 17 00:00:00 2001 Message-ID: <54939c4044fb407b068c0666c258ccd01e59c2af.1713703523.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sun, 21 Apr 2024 15:37:18 +0300 Subject: [PATCH 1/2] org-export-data: Handle trailing spaces when transcoder returns nil * lisp/ox.el (org-export-data): When transcoder returns nil, handle trailing spaces after an object the same way `org-export--prune-tree' does. Remove special handling of export snippets that unconditionally keep their trailing spaces. Link: https://orgmode.org/list/87h6fwmgkm.fsf@localhost --- lisp/ox.el | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index fc746950d..ccc4c94ce 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -1930,15 +1930,11 @@ (defun org-export-data (data info) (eq (plist-get info :with-archived-trees) 'headline) (org-element-property :archivedp data))) (let ((transcoder (org-export-transcoder data info))) - (or (and (functionp transcoder) - (if (eq type 'link) - (broken-link-handler - (funcall transcoder data nil info)) - (funcall transcoder data nil info))) - ;; Export snippets never return a nil value so - ;; that white spaces following them are never - ;; ignored. - (and (eq type 'export-snippet) "")))) + (and (functionp transcoder) + (if (eq type 'link) + (broken-link-handler + (funcall transcoder data nil info)) + (funcall transcoder data nil info))))) ;; Element/Object with contents. (t (let ((transcoder (org-export-transcoder data info))) @@ -1979,8 +1975,33 @@ (defun org-export-data (data info) (puthash data (cond - ((not results) "") - ((memq type '(nil org-data plain-text raw)) results) + ((not results) + ;; TRANSCODER returned nil. When DATA is an object, + ;; interpret this as if DATA should be ignored (see + ;; `org-export--prune-tree'). Keep spaces in place of + ;; removed element, if necessary. + ;; Example: "Foo.[10%] Bar" would become + ;; "Foo.Bar" if we do not keep spaces. + ;; Another example: "A space@@ascii:*@@ character." + ;; should become "A space character" in non-ASCII export. + (let ((post-blank (org-element-post-blank data))) + (or + (unless (or (not post-blank) + (zerop post-blank) + (eq 'element (org-element-class data))) + (let ((previous (org-export-get-previous-element data info))) + (unless (or (not previous) + (pcase (org-element-type previous) + (`plain-text + (string-match-p + (rx whitespace eos) previous)) + (_ (org-element-post-blank previous)))) + ;; When previous element does not have + ;; trailing spaces, keep the trailing + ;; spaces from DATA. + (make-string post-blank ?\s)))) + ""))) + ((memq type '(nil org-data plain-text raw)) results) ;; Append the same white space between elements or objects ;; as in the original buffer, and call appropriate filters. (t -- 2.44.0