Hi,

To be sure that CSS rules don't apply to missing contents, there's no need to
output DIV preamble opening and closing tags if there is nothing in between.

Best regards,
  Seb

-- 
Sebastien Vauban
>From 9bb3959f8ca978e7486ba7bde11cd407a40e653b Mon Sep 17 00:00:00 2001
From: Sebastien Vauban <s...@mygooglest.com>
Date: Thu, 29 Sep 2011 21:49:11 +0200
Subject: [PATCH 2/2] Don't output DIV preamble tags when contents is empty.

---
 lisp/org-html.el |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/lisp/org-html.el b/lisp/org-html.el
index fde563b..0139c16 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1337,23 +1337,30 @@ lang=\"%s\" xml:lang=\"%s\">
 
 	;; insert html preamble
 	(when (plist-get opt-plist :html-preamble)
-	  (let ((html-pre (plist-get opt-plist :html-preamble)))
-	    (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\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 "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
+		   (funcall html-pre)
+		   (insert "\n</div>\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</div>\n")))
+	    ;; don't output an empty preamble DIV
+	    (unless (and (functionp html-pre)
+			 (equal html-pre-real-contents ""))
+	      (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
+	      (insert html-pre-real-contents)
+	      (insert "\n</div>\n"))))
 
 	;; begin wrap around body
 	(insert (format "\n<div id=\"%s\">"
-- 
1.7.5.1

Reply via email to