From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Rework org-export-html-preamble/postamble (again) Date: Wed, 09 Mar 2011 17:17:21 +0100 Message-ID: <87pqq08e0e.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=46819 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxM92-0006Bz-Dc for emacs-orgmode@gnu.org; Wed, 09 Mar 2011 11:21:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxM90-0000um-HY for emacs-orgmode@gnu.org; Wed, 09 Mar 2011 11:21:52 -0500 Received: from mail-wy0-f169.google.com ([74.125.82.169]:52341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxM90-0000ue-76 for emacs-orgmode@gnu.org; Wed, 09 Mar 2011 11:21:50 -0500 Received: by wyf19 with SMTP id 19so708322wyf.0 for ; Wed, 09 Mar 2011 08:21:49 -0800 (PST) Resent-To: emacs-orgmode@gnu.org Resent-Message-ID: <87aah48dtg.fsf@altern.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Rework-org-export-html-preamble-postamble-again.patch >From 990063c31f1f365667017b4780a347ff9dbdeb1c Mon Sep 17 00:00:00 2001 From: Bastien Guerry 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" "

%t

")) @@ -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" "

Author: %a (%e)

@@ -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 "

" title "

"))) - + (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 "%s\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 "%s" e e)) - (split-string email ",+ *") - ", ")) - (creator-info - (concat "Org version " org-version " with Emacs version " - (number-to-string emacs-major-version)))) - (insert "
\n") - (insert (format-spec html-postamble-format - `((?a . ,author) (?e . ,email) - (?d . ,date) (?c . ,creator-info) - (?v . ,html-validation-link)))) - (insert "
")) - ;; fall back on default postamble - (insert "
\n") - (when (and (plist-get opt-plist :author-info) author) - (insert "

" (nth 1 lang-words) ": " author "

\n")) - (when (and (plist-get opt-plist :email-info) email) - (insert "

<" email ">

\n")) - (when (plist-get opt-plist :creator-info) - (insert "

" - (concat "Org version " org-version " with Emacs version " - (number-to-string emacs-major-version) "

\n"))) - (insert html-validation-link "\n
"))) - + (let ((html-post (plist-get opt-plist :html-postamble))) + (when (plist-get opt-plist :html-postamble) + (cond ((stringp html-post) + (insert "
\n") + (insert (format-spec html-post + `((?a . ,author) (?e . ,email) + (?d . ,date) (?c . ,creator-info) + (?v . ,html-validation-link)))) + (insert "
")) + ((functionp html-post) + (funcall html-post opt-plist)) + ((eq html-post 'auto) + ;; fall back on default postamble + (let + ((email + (mapconcat (lambda(e) + (format "%s" e e)) + (split-string email ",+ *") + ", ")) + (creator-info + (concat "Org version " org-version " with Emacs version " + (number-to-string emacs-major-version)))) + (insert "
\n") + (when (and (plist-get opt-plist :author-info) author) + (insert "

" (nth 1 lang-words) ": " author "

\n")) + (when (and (plist-get opt-plist :email-info) email) + (insert "

<" email ">

\n")) + (when (plist-get opt-plist :creator-info) + (insert "

" + (concat "Org version " org-version " with Emacs version " + (number-to-string emacs-major-version) "

\n"))) + (insert html-validation-link "\n
"))) + (t + (insert "
\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 "
")))))) + (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 --=-=-= Content-Type: text/plain -- Bastien --=-=-=--