emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bastien <bzg@gnu.org>
To: emacs-orgmode@gnu.org
Subject: Rework org-export-html-preamble/postamble (again)
Date: Wed, 09 Mar 2011 17:17:21 +0100	[thread overview]
Message-ID: <87pqq08e0e.fsf@gnu.org> (raw)

[-- 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

             reply	other threads:[~2011-03-09 16:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 16:17 Bastien [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pqq08e0e.fsf@gnu.org \
    --to=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: Rework org-export-html-preamble/postamble (again)' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this 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).