]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-html.el
2009-11-20 Carsten Dominik <carsten.dominik@gmail.com>
[gnu-emacs] / lisp / org / org-html.el
index 3170f3ae07ceb387d0387d70eabc5ecdaf612586..d59f16a0c7f55fcb1057142b0230d35f68939902 100644 (file)
@@ -6,7 +6,7 @@
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 6.29c
+;; Version: 6.33x
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -27,6 +27,7 @@
 ;;; Commentary:
 
 (require 'org-exp)
+(eval-when-compile (require 'cl))
 
 (declare-function org-id-find-id-file "org-id" (id))
 (declare-function htmlize-region "ext:htmlize" (beg end))
@@ -228,7 +229,7 @@ CSS classes, then this prefic can be very useful."
   :type 'string)
 
 (defcustom org-export-html-home/up-format
-  "<div style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
+  "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  <a accesskey=\"h\" href=\"%s\"> UP </a>
  |
  <a accesskey=\"H\" href=\"%s\"> HOME </a>
@@ -418,6 +419,9 @@ This may also be a function, building and inserting the postamble.")
 (defvar org-export-html-after-blockquotes-hook nil
   "Hook run during HTML export, after blockquote, verse, center are done.")
 
+(defvar org-export-html-final-hook nil
+  "Hook run during HTML export, after blockquote, verse, center are done.")
+
 ;;; HTML export
 
 (defun org-export-html-preprocess (parameters)
@@ -503,7 +507,7 @@ in a window.  A non-interactive call will only return the buffer."
     (setq buffer "*Org HTML Export*"))
   (let ((transient-mark-mode t) (zmacs-regions t)
        ext-plist rtn)
-    (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
+    (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
     (goto-char end)
     (set-mark (point)) ;; to activate the region
     (goto-char beg)
@@ -543,7 +547,7 @@ PUB-DIR is set, use this as the publishing directory."
        (org-set-local 'buffer-file-name
                       (with-current-buffer (buffer-base-buffer)
                         buffer-file-name))
-      (error "Need a file name to be able to export.")))
+      (error "Need a file name to be able to export")))
 
   (message "Exporting...")
   (setq-default org-todo-line-regexp org-todo-line-regexp)
@@ -571,7 +575,7 @@ PUB-DIR is set, use this as the publishing directory."
         (rbeg (and region-p (region-beginning)))
         (rend (and region-p (region-end)))
         (subtree-p
-         (if (plist-get opt-plist :ignore-subree-p)
+         (if (plist-get opt-plist :ignore-subtree-p)
              nil
            (when region-p
              (save-excursion
@@ -749,7 +753,6 @@ PUB-DIR is set, use this as the publishing directory."
 <html xmlns=\"http://www.w3.org/1999/xhtml\"
 lang=\"%s\" xml:lang=\"%s\">
 <head>
-%s
 <title>%s</title>
 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
 <meta name=\"generator\" content=\"Org-mode\"/>
@@ -761,6 +764,7 @@ lang=\"%s\" xml:lang=\"%s\">
 </head>
 <body>
 <div id=\"content\">
+%s
 "
                 (format
                  (or (and (stringp org-export-html-xml-declaration)
@@ -771,17 +775,17 @@ lang=\"%s\" xml:lang=\"%s\">
                      "")
                  (or charset "iso-8859-1"))
                 language language
+                (org-html-expand title)
+                (or charset "iso-8859-1")
+                date author description keywords
+                style
                 (if (or link-up link-home)
                     (concat
                      (format org-export-html-home/up-format
                              (or link-up link-home)
                              (or link-home link-up))
                      "\n")
-                  "")
-                (org-html-expand title)
-                (or charset "iso-8859-1")
-                date author description keywords
-                style))
+                  "")))
 
         (org-export-html-insert-plist-item opt-plist :preamble opt-plist)
 
@@ -968,9 +972,12 @@ lang=\"%s\" xml:lang=\"%s\">
                (setq line (concat line "\\\\")))))
 
          ;; make targets to anchors
+         (setq start 0)
          (while (string-match
-                 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
+                 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
            (cond
+            ((get-text-property (match-beginning 1) 'org-protected line)
+             (setq start (match-end 1)))
             ((match-end 2)
              (setq line (replace-match
                          (format
@@ -981,16 +988,18 @@ lang=\"%s\" xml:lang=\"%s\">
             ((and org-export-with-toc (equal (string-to-char line) ?*))
              ;; FIXME: NOT DEPENDENT on TOC?????????????????????
              (setq line (replace-match
-                         (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
-;                        (concat "@<i>" (match-string 1 line) "@</i> ")
+                         (concat "@<span class=\"target\">"
+                                 (match-string 1 line) "@</span> ")
+                         ;; (concat "@<i>" (match-string 1 line) "@</i> ")
                          t t line)))
             (t
              (setq line (replace-match
                          (concat "@<a name=\""
                                  (org-solidify-link-text (match-string 1 line))
-                                 "\" class=\"target\">" (match-string 1 line) "@</a> ")
+                                 "\" class=\"target\">" (match-string 1 line)
+                                 "@</a> ")
                          t t line)))))
-
+           
          (setq line (org-html-handle-time-stamps line))
 
          ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
@@ -1161,7 +1170,7 @@ lang=\"%s\" xml:lang=\"%s\">
          ;; Does this contain a reference to a footnote?
          (when org-export-with-footnotes
            (setq start 0)
-           (while (string-match "\\([^* \t].*\\)?\\[\\([0-9]+\\)\\]" line start)
+           (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
              (if (get-text-property (match-beginning 2) 'org-protected line)
                  (setq start (match-end 2))
                (let ((n (match-string 2 line)) extra a)
@@ -1174,10 +1183,10 @@ lang=\"%s\" xml:lang=\"%s\">
                  (setq line
                        (replace-match
                         (format
-                         (concat (if (match-string 1 line) "%s" "")
+                         (concat "%s"
                                  (format org-export-html-footnote-format
                                          "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
-                         (match-string 1 line) n extra n n)
+                         (or (match-string 1 line) "") n extra n n)
                         t t line))))))
 
          (cond
@@ -1331,10 +1340,11 @@ lang=\"%s\" xml:lang=\"%s\">
                (let ((n (match-string 1 line)))
                  (setq org-par-open t
                        line (replace-match
-                             (concat "<p class=\"footnote\">"
-                                     (format org-export-html-footnote-format
-                                             "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"
-                                             n n n) t t line))))))
+                             (format
+                              (concat "<p class=\"footnote\">"
+                                      (format org-export-html-footnote-format
+                                              "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
+                              n n n) t t line)))))
            ;; Check if the line break needs to be conserved
            (cond
             ((string-match "\\\\\\\\[ \t]*$" line)
@@ -1419,7 +1429,8 @@ lang=\"%s\" xml:lang=\"%s\">
 
       (unless (plist-get opt-plist :buffer-will-be-killed)
        (normal-mode)
-       (if (eq major-mode (default-value 'major-mode)) (html-mode)))
+       (if (eq major-mode (default-value 'major-mode))
+           (html-mode)))
 
       ;; insert the table of contents
       (goto-char (point-min))
@@ -1458,6 +1469,7 @@ lang=\"%s\" xml:lang=\"%s\">
          (delete-region beg end)
          (insert (format "<span style=\"visibility:hidden;\">%s</span>"
                          (make-string n ?x)))))
+      (run-hooks 'org-export-html-final-hook)
       (or to-buffer (save-buffer))
       (goto-char (point-min))
       (or (org-export-push-to-kill-ring "HTML")
@@ -1498,17 +1510,22 @@ lang=\"%s\" xml:lang=\"%s\">
       (let* ((caption (org-find-text-property-in-string 'org-caption src))
             (attr (org-find-text-property-in-string 'org-attributes src))
             (label (org-find-text-property-in-string 'org-label src)))
-       (format "%s<div %sclass=\"figure\">
-<p><img src=\"%s\"%s /></p>%s
-</div>%s"
-               (if org-par-open "</p>\n" "")
-               (if label (format "id=\"%s\" " label) "")
+       (concat
+       (if caption
+           (format "%s<div %sclass=\"figure\">
+<p>"
+                   (if org-par-open "</p>\n" "")
+                   (if label (format "id=\"%s\" " label) "")))
+       (format "<img src=\"%s\"%s />"
                src
                (if (string-match "\\<alt=" (or attr ""))
                    (concat " " attr )
-                 (concat " " attr " alt=\"" src "\""))
-               (if caption (concat "\n<p>" caption "</p>") "")
-               (if org-par-open "\n<p>" ""))))))
+                 (concat " " attr " alt=\"" src "\"")))
+       (if caption
+           (format "</p>%s
+</div>%s"
+               (concat "\n<p>" caption "</p>")
+               (if org-par-open "\n<p>" ""))))))))
 
 (defun org-export-html-get-bibliography ()
   "Find bibliography, cut it out and return it."
@@ -1634,14 +1651,14 @@ lang=\"%s\" xml:lang=\"%s\">
     (unless splice (push "</table>\n" html))
     (setq html (nreverse html))
     (unless splice
-      ;; Put in col tags with the alignment (unfortuntely often ignored...)
+      ;; Put in col tags with the alignment (unfortunately often ignored...)
       (unless (car org-table-colgroup-info)
        (setq org-table-colgroup-info
              (cons :start (cdr org-table-colgroup-info))))
       (push (mapconcat
             (lambda (x)
               (setq gr (pop org-table-colgroup-info))
-              (format "%s<col align=\"%s\"></col>%s"
+              (format "%s<col align=\"%s\" />%s"
                       (if (memq gr '(:start :startend))
                           (prog1
                               (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
@@ -1883,13 +1900,6 @@ If there are links in the string, don't modify these."
              (setq start (+ start (length wd))))))))
   s)
 
-(defconst org-export-html-special-string-regexps
-  '(("\\\\-" . "&shy;")
-    ("---\\([^-]\\)" . "&mdash;\\1")
-    ("--\\([^-]\\)" . "&ndash;\\1")
-    ("\\.\\.\\." . "&hellip;"))
-  "Regular expressions for special string conversion.")
-
 (defun org-export-html-convert-special-strings (string)
   "Convert special characters in STRING to HTML."
   (let ((all org-export-html-special-string-regexps)