emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Rework org-export-html-preamble/postamble (again)
@ 2011-03-09 16:17 Bastien
  2011-03-09 20:21 ` Jason Dunsmore
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2011-03-09 16:17 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 768 bytes --]

Hopefully this patch will solve a few issues that have just been raised
about the new behavior of org-export-html-preamble/postamble.

`org-export-html-preamble' defaults back to `t', to reproduce the
previous default behavior.

`org-export-html-postamble' default to 'auto -- which mean that
org-export-email/author/creator-info will be honored by default.
When this is set to `t', the postamble will be inserted from the
formatting string in `org-export-html-postamble-format'.  When 
set to a string, this formatting string will be replaced by this
string.

Both variables also support functions, as org-export-html-preamble 
and org-export-html-postamble used to (but that wasn't documented).

Please test carefully and tell me if this is okay to apply.

Thanks!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Rework-org-export-html-preamble-postamble-again.patch --]
[-- Type: text/x-patch, Size: 8674 bytes --]

From 990063c31f1f365667017b4780a347ff9dbdeb1c Mon Sep 17 00:00:00 2001
From: Bastien Guerry <bzg@altern.org>
Date: Wed, 9 Mar 2011 17:13:40 +0100
Subject: [PATCH] Rework org-export-html-preamble/postamble (again).

* org-html.el (org-export-html-insert-plist-item): Remove.
(org-export-html-preamble): Default to `t'.  Accept functions.
(org-export-html-postamble): Default to `auto'.  Accept
functions and distinguish between 'auto (no formatting string)
and `t' (default formatting string).
(org-export-as-html): Handle org-export-html-preamble and
org-export-html-postamble new defaults/allowed values.
---
 lisp/org-html.el |  158 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 93 insertions(+), 65 deletions(-)

diff --git a/lisp/org-html.el b/lisp/org-html.el
index c60c90d..d5ea1a3 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -343,13 +343,22 @@ CSS classes, then this prefix can be very useful."
   :group 'org-export-html
   :type 'string)
 
-(defcustom org-export-html-preamble nil
+(defcustom org-export-html-preamble t
   "Non-nil means insert a preamble in HTML export.
-If this is a string, use it as a formatting string it instead of
-`org-export-html-preamble-format'.  Setting :html-preamble in
-publishing projects will override this."
+When `t', insert a string as defined by
+`org-export-html-preamble-format'.  When set to a string, this
+string overrides `org-export-html-preamble-format'.  When set to
+a function, apply this function and insert the returned string.
+The function takes the property list of export options as its
+only argument.
+
+Setting :html-preamble in publishing projects will take
+precedence over this variable."
   :group 'org-export-html
-  :type 'boolean)
+  :type '(choice (const :tag "No preamble" nil)
+		 (const :tag "Default preamble" t)
+		 (string :tag "Custom formatting string")
+		 (function :tag "Function (must return a string)")))
 
 (defcustom org-export-html-preamble-format
   '(("en" "<h1 class=\"title\">%t</h1>"))
@@ -362,13 +371,26 @@ like that: \"%%\"."
   :group 'org-export-html
   :type 'string)
 
-(defcustom org-export-html-postamble nil
+(defcustom org-export-html-postamble 'auto
   "Non-nil means insert a postamble in HTML export.
-If this is a string, use it as a formatting string it instead of
-`org-export-html-postamble-format'.  Setting :html-postamble in
-publishing projects will override this."
+
+When `t', insert a string as defined by
+`org-export-html-postamble-format'.  When set to a string, this
+string overrides `org-export-html-postamble-format'.  When set to
+'auto, discard `org-export-html-postamble-format' and honor
+`org-export-author/email/creator-info' variables.  When set to a
+function, apply this function and insert the returned string.
+The function takes the property list of export options as its
+only argument.
+
+Setting :html-postamble in publishing projects will take
+precedence over this variable."
   :group 'org-export-html
-  :type 'boolean)
+  :type '(choice (const :tag "No postamble" nil)
+		 (const :tag "Auto preamble" 'auto)
+		 (const :tag "Default formatting string" t)
+		 (string :tag "Custom formatting string")
+		 (function :tag "Function (must return a string)")))
 
 (defcustom org-export-html-postamble-format
   '(("en" "<p class=\"author\">Author: %a (%e)</p>
@@ -1277,19 +1299,23 @@ lang=\"%s\" xml:lang=\"%s\">
 		   "")))
 
 	;; insert html preamble
-	(if (plist-get opt-plist :html-preamble)
-	    (let* ((html-preamble (plist-get opt-plist :html-preamble))
-		   (html-preamble-format
-		    (if (stringp html-preamble)
-			html-preamble
-		      (cadr (or (assoc (nth 0 lang-words)
-				       org-export-html-preamble-format)
-				(assoc "en" org-export-html-preamble-format))))))
-	      (insert (format-spec html-preamble-format
-				   `((?t . ,title)
-				     (?a . ,author) (?d . ,date) (?e . ,email)))))
-	  (insert  "<h1 class=\"title\">" title "</h1>")))
-      
+	(when (plist-get opt-plist :html-preamble)
+	  (let ((html-pre (plist-get opt-plist :html-preamble)))
+	    (cond ((stringp html-pre)
+		   (insert
+		    (format-spec html-pre `((?t . ,title) (?a . ,author) 
+					    (?d . ,date) (?e . ,email)))))
+		  ((functionp html-pre)
+		   (funcall html-pre opt-plist))
+		  (t
+		   (insert 
+		    (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)))))))))
+
       (if (and org-export-with-toc (not body-only))
 	  (progn
 	    (push (format "<h%d>%s</h%d>\n"
@@ -1676,42 +1702,51 @@ lang=\"%s\" xml:lang=\"%s\">
 	(when bib
 	  (insert "\n" bib "\n")))
 
-      ;; export html postamble
+      ;; Export html postamble
       (unless body-only
-	(if (plist-get opt-plist :html-postamble)
-	    (let* ((html-postamble (plist-get opt-plist :html-postamble))
-		   (html-postamble-format
-		    (if (stringp html-postamble)
-			html-postamble
-		      (or (cadr (assoc (nth 0 lang-words)
-				       org-export-html-postamble-format))
-			  (cadr (assoc "en" org-export-html-postamble-format)))))
-		   (email
-		    (mapconcat (lambda(e)
-				 (format "<a href=\"mailto:%s\">%s</a>" e e))
-			       (split-string email ",+ *")
-			       ", "))
-		   (creator-info
-		    (concat "Org version " org-version " with Emacs version "
-			    (number-to-string emacs-major-version))))
-	      (insert "<div id=\"postamble\">\n")
-	      (insert (format-spec html-postamble-format
-				   `((?a . ,author) (?e . ,email)
-				     (?d . ,date)   (?c . ,creator-info)
-				     (?v . ,html-validation-link))))
-	      (insert "</div>"))
-	  ;; fall back on default postamble
-	  (insert "<div id=\"postamble\">\n")
-	  (when (and (plist-get opt-plist :author-info) author)
-	    (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
-	  (when (and (plist-get opt-plist :email-info) email)
-	    (insert "<p class=\"mailto:" email "\">&lt;" email "&gt;</p>\n"))
-	  (when (plist-get opt-plist :creator-info)
-	    (insert "<p class=\"creator\">"
-		    (concat "Org version " org-version " with Emacs version "
-			    (number-to-string emacs-major-version) "</p>\n")))
-	  (insert html-validation-link "\n</div>")))
-
+	(let ((html-post (plist-get opt-plist :html-postamble)))
+	  (when (plist-get opt-plist :html-postamble)
+	    (cond ((stringp html-post)
+		   (insert "<div id=\"postamble\">\n")
+		   (insert (format-spec html-post
+					`((?a . ,author) (?e . ,email)
+					  (?d . ,date)   (?c . ,creator-info)
+					  (?v . ,html-validation-link))))
+		   (insert "</div>"))
+		  ((functionp html-post)
+		   (funcall html-post opt-plist))
+		  ((eq html-post 'auto)
+		   ;; fall back on default postamble
+		   (let 
+		       ((email
+			 (mapconcat (lambda(e)
+				      (format "<a href=\"mailto:%s\">%s</a>" e e))
+				    (split-string email ",+ *")
+				    ", "))
+			(creator-info
+			 (concat "Org version " org-version " with Emacs version "
+				 (number-to-string emacs-major-version))))
+		     (insert "<div id=\"postamble\">\n")
+		     (when (and (plist-get opt-plist :author-info) author)
+		       (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
+		     (when (and (plist-get opt-plist :email-info) email)
+		       (insert "<p class=\"mailto:" email "\">&lt;" email "&gt;</p>\n"))
+		     (when (plist-get opt-plist :creator-info)
+		       (insert "<p class=\"creator\">"
+			       (concat "Org version " org-version " with Emacs version "
+				       (number-to-string emacs-major-version) "</p>\n")))
+		     (insert html-validation-link "\n</div>")))
+		  (t 
+		   (insert "<div id=\"postamble\">\n")
+		   (insert (format-spec
+			    (or (cadr (assoc (nth 0 lang-words)
+					     org-export-html-postamble-format))
+				(cadr (assoc "en" org-export-html-postamble-format)))
+			    `((?a . ,author) (?e . ,email)
+			      (?d . ,date)   (?c . ,creator-info)
+			      (?v . ,html-validation-link))))
+		   (insert "</div>"))))))
+      
       (if org-export-html-with-timestamp
 	  (insert org-export-html-html-helper-timestamp))
 
@@ -1773,13 +1808,6 @@ lang=\"%s\" xml:lang=\"%s\">
 	    (kill-buffer (current-buffer)))
 	(current-buffer)))))
 
-(defun org-export-html-insert-plist-item (plist key &rest args)
-  (let ((item (plist-get plist key)))
-    (cond ((functionp item)
-           (apply item args))
-          (item
-           (insert item)))))
-
 (defun org-export-html-format-href (s)
   "Make sure the S is valid as a href reference in an XHTML document."
   (save-match-data
-- 
1.7.4.1


[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-03-17  8:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-09 16:17 Rework org-export-html-preamble/postamble (again) Bastien
2011-03-09 20:21 ` Jason Dunsmore
2011-03-10  9:27   ` Bastien
2011-03-10 14:46     ` Jason Dunsmore
2011-03-10 18:29       ` Bastien
2011-03-15 15:55         ` Jason Dunsmore
2011-03-15 18:11           ` Bastien
2011-03-15 20:26             ` Jason Dunsmore
2011-03-17  7:08               ` Bastien
2011-03-15 15:25       ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).