Jelajahi Sumber

HTML export: More flexibility for preamble and postamble

Andreas Rottmann writes:

> Well, the subject says it all -- attached is a rough patch to
> allow more flexibility with the HTML export; I use it like this:
>
>    (defun rotty/homepage-preamble (opt-plist)
>      (insert "<div id=\"header\">")
>      (insert
>       "
>    <div id=\"navbar\">
>    <a class=\"menu\" href=\"/\">Home</a>
>    | <a class=\"menu\" href=\"/Writings.html\">Writings</a>
>    | <a class=\"menu\" href=\"/Software.html\">Software</a>
>    | <a class=\"menu\" href=\"/blog/\">Blog</a>
>    </div>
>    ")
>      (insert (format
>               "<h1 class=\"title\"><a href=\"/\">rotty</a> &gt; %s</h1>\n"
>               (plist-get opt-plist :title)))
>      (insert "</div>\n")
>      (insert "<div id=\"inner\">\n"))
Carsten Dominik 16 tahun lalu
induk
melakukan
30d448b2e1
2 mengubah file dengan 19 tambahan dan 4 penghapusan
  1. 5 0
      lisp/ChangeLog
  2. 14 4
      lisp/org-html.el

+ 5 - 0
lisp/ChangeLog

@@ -1,5 +1,10 @@
 2009-07-06  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-html.el (org-export-as-html): Insert the title into the
+	option plist.
+	(org-export-html-insert-plist-item): New function.
+	(org-export-as-html): Call `org-export-html-insert-plist-item'.
+
 	* org-macs.el (org-set-local): Make a local variable, do not make
 	the variable buffer-local!
 

+ 14 - 4
lisp/org-html.el

@@ -384,9 +384,11 @@ with a link to this URL."
 ;;; Variables, constants, and parameter plists
 
 (defvar org-export-html-preamble nil
-  "Preamble, to be inserted just before <body>.  Set by publishing functions.")
+  "Preamble, to be inserted just before <body>.  Set by publishing functions.
+This may also be a function, building and inserting the preamble.")
 (defvar org-export-html-postamble nil
-  "Preamble, to be inserted just after </body>.  Set by publishing functions.")
+  "Preamble, to be inserted just after </body>.  Set by publishing functions.
+This may also be a function, building and inserting the postamble.")
 (defvar org-export-html-auto-preamble t
   "Should default preamble be inserted?  Set by publishing functions.")
 (defvar org-export-html-auto-postamble t
@@ -606,6 +608,7 @@ PUB-DIR is set, use this as the publishing directory."
 			       (file-name-sans-extension
 				(file-name-nondirectory buffer-file-name)))
 			  "UNTITLED"))
+	 (dummy (setq opt-plist (plist-put opt-plist :title title)))
 	 (html-table-tag (plist-get opt-plist :html-table-tag))
 	 (quote-re0   (concat "^[ \t]*" org-quote-string "\\>"))
 	 (quote-re    (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
@@ -746,7 +749,7 @@ lang=\"%s\" xml:lang=\"%s\">
 		 date author description keywords
 		 style))
 
-	(insert (or (plist-get opt-plist :preamble) ""))
+        (org-export-html-insert-plist-item opt-plist :preamble opt-plist)
 
 	(when (plist-get opt-plist :auto-preamble)
 	  (if title (insert (format org-export-html-title-format
@@ -1373,7 +1376,7 @@ lang=\"%s\" xml:lang=\"%s\">
 
 	(if org-export-html-with-timestamp
 	    (insert org-export-html-html-helper-timestamp))
-	(insert (or (plist-get opt-plist :postamble) ""))
+        (org-export-html-insert-plist-item opt-plist :postamble opt-plist)
 	(insert "\n</div>\n</body>\n</html>\n"))
 
       (unless (plist-get opt-plist :buffer-will-be-killed)
@@ -1426,6 +1429,13 @@ 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