diff --git a/lisp/org-html.el b/lisp/org-html.el
index 67ef545e2..7fa5e1445 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1342,23 +1342,30 @@ PUB-DIR is set, use this as the publishing directory."
;; insert html preamble
(when (plist-get opt-plist :html-preamble)
- (let ((html-pre (plist-get opt-plist :html-preamble)))
- (insert "
\n")
+ (let ((html-pre (plist-get opt-plist :html-preamble))
+ html-pre-real-contents)
(cond ((stringp html-pre)
- (insert
- (format-spec html-pre `((?t . ,title) (?a . ,author)
- (?d . ,date) (?e . ,email)))))
+ (setq html-pre-real-contents
+ (format-spec html-pre `((?t . ,title) (?a . ,author)
+ (?d . ,date) (?e . ,email)))))
((functionp html-pre)
- (funcall html-pre))
+ (insert "
\n")
+ (funcall html-pre)
+ (insert "\n
\n"))
(t
- (insert
+ (setq html-pre-real-contents
(format-spec
(or (cadr (assoc (nth 0 lang-words)
org-export-html-preamble-format))
(cadr (assoc "en" org-export-html-preamble-format)))
`((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email))))))
- (insert "\n
\n")))
+ ;; don't output an empty preamble DIV
+ (unless (and (functionp html-pre)
+ (equal html-pre-real-contents ""))
+ (insert "