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