Hello, Org-mode maintainers,

When exporting a file containing many timestamps, I noticed while
inspecting the HTML code that the timestamps inside <span> elements have
an extra space. Here's a minimal example:

(org-export-string-as "Hello [2025-05-05] world" 'html t) ;;=>
"<p>
Hello <span class=\"timestamp-wrapper\"><span
class=\"timestamp\">[2025-05-05 Mon] </span></span> world</p>
"

You can notice that there is a space after `Mon]' and also after the
final `</span>'. By briefly looking through the functions called by
`org-html-timestamp', namely `org-timestamp-translate' and
`org-element-interpret-data', I found that `org-element-interpret-data'
adds spaces corresponding to the original object's :post-blank property.

It seems clear that `org-element-interpret-data' is designed to produce
output that can be directly inserted into the final result, preserving
the object's structure, including its trailing space. However,
`org-html-timestamp' wraps its return value directly in two <span> tags,
which results in the extra space being included inside the tag.

Here is a possible fix:

1 file changed, 1 insertion(+), 1 deletion(-)
lisp/org/ox-html.el | 2 +-

modified   lisp/org/ox-html.el
@@ -3920,7 +3920,7 @@ org-html-timestamp
   "Transcode a TIMESTAMP object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
-  (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
+  (let ((value (org-trim (org-html-plain-text
(org-timestamp-translate timestamp) info))))
     (format "<span class=\"timestamp-wrapper\"><span
class=\"timestamp\">%s</span></span>"
      (replace-regexp-in-string "--" "&#x2013;" value))))

Reply via email to