;;; org-html.el --- HTML export for Org-mode
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
-;; Free Software Foundation, Inc.
+;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
-;; Version: 7.7
;;
;; This file is part of GNU Emacs.
;;
(declare-function org-id-find-id-file "org-id" (id))
(declare-function htmlize-region "ext:htmlize" (beg end))
-(declare-function org-pop-to-buffer-same-window
+(declare-function org-pop-to-buffer-same-window
"org-compat" (&optional buffer-or-name norecord label))
(defgroup org-export-html nil
(defcustom org-export-html-footnote-separator "<sup>, </sup>"
"Text used to separate footnotes."
:group 'org-export-html
+ :version "24.1"
:type 'string)
(defcustom org-export-html-coding-system nil
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
+ div.inlinetask {
+ padding:10px;
+ border:2px solid gray;
+ margin:10px;
+ background: #ffffcc;
+ }
textarea { overflow-x: auto; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
#+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
:group 'org-export-html
+ :version "24.1"
:type '(list :greedy t
(list :tag "path (the path from where to load MathJax.js)"
(const :format " " path) (string))
</script>"
"The MathJax setup for XHTML files."
:group 'org-export-html
+ :version "24.1"
:type 'string)
(defcustom org-export-html-tag-class-prefix ""
:group 'org-export-html
:type 'string)
+(defcustom org-export-html-headline-anchor-format "<a name=\"%s\" id=\"%s\"></a>"
+ "Format for anchors in HTML headlines.
+It requires to %s: both will be replaced by the anchor referring
+to the headline (e.g. \"sec-2\"). When set to `nil', don't insert
+HTML anchors in headlines."
+ :group 'org-export-html
+ :version "24.1"
+ :type 'string)
+
(defcustom org-export-html-preamble t
"Non-nil means insert a preamble in HTML export.
strings in `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.
+returned string. The function takes no argument, but you can
+use `opt-plist' to access the current export options.
Setting :html-preamble in publishing projects will take
precedence over this variable."
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
:group 'org-export-html
+ :version "24.1"
:type 'string)
(defcustom org-export-html-postamble 'auto
'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.
+The function takes no argument, but you can use `opt-plist' to
+access the current export options.
Setting :html-postamble in publishing projects will take
precedence over this variable."
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
:group 'org-export-html
+ :version "24.1"
:type 'string)
(defcustom org-export-html-home/up-format
is ignored by some browsers (like Firefox, Safari). Opera does it right
though."
:group 'org-export-tables
+ :version "24.1"
:type 'boolean)
(defcustom org-export-html-table-use-header-tags-for-first-column nil
(">" . ">"))
"Alist of characters to be converted by `org-html-protect'."
:group 'org-export-html
+ :version "24.1"
:type '(repeat (cons (string :tag "Character")
(string :tag "HTML equivalent"))))
Please set `org-export-html-divs' instead.")
(defcustom org-export-html-divs '("preamble" "content" "postamble")
- "The name of the main divs for HTML export."
+ "The name of the main divs for HTML export.
+This is a list of three strings, the first one for the preamble
+DIV, the second one for the content DIV and the third one for the
+postamble DIV."
:group 'org-export-html
+ :version "24.1"
:type '(list
(string :tag " Div for the preamble:")
(string :tag " Div for the content:")
(interactive "r")
(let (reg html buf pop-up-frames)
(save-window-excursion
- (if (org-mode-p)
+ (if (eq major-mode 'org-mode)
(setq html (org-export-region-as-html
beg end t 'string))
(setq reg (buffer-substring beg end)
may-inline-p)
"Make an HTML link.
OPT-PLIST is an options list.
-TYPE is the device-type of the link (THIS://foo.html)
-PATH is the path of the link (http://THIS#locationx)
-FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
+TYPE is the device-type of the link (THIS://foo.html).
+PATH is the path of the link (http://THIS#location).
+FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
DESC is the link description, if any.
-ATTR is a string of other attributes of the a element.
+ATTR is a string of other attributes of the \"a\" element.
MAY-INLINE-P allows inlining it as an image."
(declare (special org-par-open))
(string-match "^\\.\\.?/" path)))
"file")
(t "internal")))
- (setq path (org-extract-attributes (org-link-unescape path)))
+ (setq path (org-extract-attributes path))
(setq attr (get-text-property 0 'org-attributes path))
(setq desc1 (if (match-end 5) (match-string 5 line))
desc2 (if (match-end 2) (concat type ":" path) path)
(if (string-match "^file:" desc)
(setq desc (substring desc (match-end 0)))))
(setq desc (org-add-props
- (concat "<img src=\"" desc "\" alt=\""
+ (concat "<img src=\"" desc "\" alt=\""
(file-name-nondirectory desc) "\"/>")
'(org-protected t))))
(cond
(t
;; just publish the path, as default
- (setq rpl (concat "@<i><" type ":"
+ (setq rpl (concat "<i><" type ":"
(save-match-data (org-link-unescape path))
- ">@</i>"))))
+ "></i>"))))
(setq line (replace-match rpl t t line)
start (+ start (length rpl))))
line))
;;; org-export-as-html
+
+(defvar org-heading-keyword-regexp-format) ; defined in org.el
+
;;;###autoload
(defun org-export-as-html (arg &optional hidden ext-plist
to-buffer body-only pub-dir)
(current-dir (if buffer-file-name
(file-name-directory buffer-file-name)
default-directory))
+ (auto-insert nil); Avoid any auto-insert stuff for the new file
(buffer (if to-buffer
(cond
((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
(t (get-buffer-create to-buffer)))
(find-file-noselect filename)))
(org-levels-open (make-vector org-level-max nil))
- (date (plist-get opt-plist :date))
- (author (plist-get opt-plist :author))
+ (date (org-html-expand (plist-get opt-plist :date)))
+ (author (org-html-expand (plist-get opt-plist :author)))
(html-validation-link (or org-export-html-validation-link ""))
(title (org-html-expand
(or (and subtree-p (org-export-get-title-from-subtree))
(plist-get opt-plist :link-home)))
(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 "\\>\\)"))
+ (quote-re0 (concat "^ *" org-quote-string "\\( +\\|[ \t]*$\\)"))
+ (quote-re (format org-heading-keyword-regexp-format
+ org-quote-string))
(inquote nil)
(infixed nil)
(inverse nil)
(email (plist-get opt-plist :email))
(language (plist-get opt-plist :language))
- (keywords (plist-get opt-plist :keywords))
- (description (plist-get opt-plist :description))
+ (keywords (org-html-expand (plist-get opt-plist :keywords)))
+ (description (org-html-expand (plist-get opt-plist :description)))
(num (plist-get opt-plist :section-numbers))
(lang-words nil)
(head-count 0) cnt
"%s
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
-<html xmlns=\"http://www.w3.org/1999/xhtml\"
-lang=\"%s\" xml:lang=\"%s\">
+<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
<head>
<title>%s</title>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
+<meta name=\"title\" content=\"%s\"/>
<meta name=\"generator\" content=\"Org-mode\"/>
<meta name=\"generated\" content=\"%s\"/>
<meta name=\"author\" content=\"%s\"/>
language language
title
(or charset "iso-8859-1")
- date author description keywords
+ title date author description keywords
style
mathjax
(if (or link-up link-home)
;; insert html preamble
(when (plist-get opt-plist :html-preamble)
- (let ((html-pre (plist-get opt-plist :html-preamble)))
- (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
+ (let ((html-pre (plist-get opt-plist :html-preamble))
+ (html-pre-real-contents ""))
(cond ((stringp html-pre)
- (insert
- (format-spec html-pre `((?t . ,title) (?a . ,author)
- (?d . ,date) (?e . ,email)))))
+ (setq html-pre-real-contents
+ (format-spec html-pre `((?t . ,title) (?a . ,author)
+ (?d . ,date) (?e . ,email)))))
((functionp html-pre)
- (funcall html-pre))
+ (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
+ (if (stringp (funcall html-pre)) (insert (funcall html-pre)))
+ (insert "\n</div>\n"))
(t
- (insert
+ (setq html-pre-real-contents
(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))))))
- (insert "\n</div>\n")))
+ ;; don't output an empty preamble DIV
+ (unless (and (functionp html-pre)
+ (equal html-pre-real-contents ""))
+ (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
+ (insert html-pre-real-contents)
+ (insert "\n</div>\n"))))
;; begin wrap around body
- (insert (format "\n<div id=\"%s\">"
+ (insert (format "\n<div id=\"%s\">"
;; FIXME org-export-html-content-div is obsolete since 7.7
- (or org-export-html-content-div
+ (or org-export-html-content-div
(nth 1 org-export-html-divs)))
;; FIXME this should go in the preamble but is here so
;; that org-infojs can still find it
(push "<div id=\"text-table-of-contents\">\n" thetoc)
(push "<ul>\n<li>" thetoc)
(setq lines
- (mapcar
+ (mapcar
#'(lambda (line)
(if (and (string-match org-todo-line-regexp line)
(not (get-text-property 0 'org-protected line)))
line lines level))))
(if (string-match
(org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
- (setq txt (replace-match
- " <span class=\"tag\"> \\1</span>" t nil txt)))
+ (setq txt (replace-match
+ " <span class=\"tag\">\\1</span>" t nil txt)))
(if (string-match quote-re0 txt)
(setq txt (replace-match "" t t txt)))
(setq snumber (org-section-number level))
;; Check for targets
(while (string-match org-any-target-regexp line)
(setq line (replace-match
- (concat "@<span class=\"target\">"
+ (concat "@<span class=\"target\">"
(match-string 1 line) "@</span> ")
t t line)))
(while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt)
(setq href
(replace-regexp-in-string
"\\." "-" (format "sec-%s" snumber)))
- (setq href (org-solidify-link-text
- (or (cdr (assoc href
+ (setq href (org-solidify-link-text
+ (or (cdr (assoc href
org-export-preferred-target-alist)) href)))
(push
(format
"</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
"</li>\n<li><a href=\"#%s\">%s</a>")
href txt) thetoc)
-
+
(setq org-last-level level)))))
line)
lines))
(push "</li>\n</ul>\n" thetoc))
(push "</div>\n" thetoc)
(setq thetoc (if have-headings (nreverse thetoc) nil))))
-
+
(setq head-count 0)
(org-init-section-numbers)
-
+
(org-open-par)
-
+
(while (setq line (pop lines) origline line)
(catch 'nextline
-
+
;; end of quote section?
(when (and inquote (string-match org-outline-regexp-bol line))
(insert "</pre>\n")
(setq line (org-html-handle-links line opt-plist))
;; TODO items
- (if (and (string-match org-todo-line-regexp line)
+ (if (and org-todo-line-regexp
+ (string-match org-todo-line-regexp line)
(match-beginning 2))
(setq line
(if (member (match-string 2 line)
org-done-keywords)
"done" "todo")
- " " (match-string 2 line)
- "\"> " (org-export-html-get-todo-kwd-class-name
- (match-string 2 line))
+ " " (org-export-html-get-todo-kwd-class-name
+ (match-string 2 line))
+ "\">" (match-string 2 line)
"</span>" (substring line (match-end 2)))))
;; Does this contain a reference to a footnote?
t t line))))))
(cond
- ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
+ ((string-match "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" line)
;; This is a headline
(setq level (org-tr-level (- (match-end 1) (match-beginning 1)
level-offset))
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link)))))
((functionp html-post)
- (funcall html-post))
+ (if (stringp (funcall html-post)) (insert (funcall html-post))))
((eq html-post 'auto)
;; fall back on default postamble
(when (plist-get opt-plist :time-stamp-file)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link))))))
(insert "\n</div>"))))
-
+
;; FIXME `org-export-html-with-timestamp' has been declared
;; obsolete since Org 7.7 -- don't forget to remove this.
(if org-export-html-with-timestamp
(if (string-match "^[ \t]*|" (car lines))
;; A normal org table
(org-format-org-table-html lines nil no-css)
- ;; Table made by table.el
+ ;; Table made by table.el
(or (org-format-table-table-html-using-table-generate-source
olines (not org-export-prefer-native-exporter-for-tables))
;; We are here only when table.el table has NO col or row
(let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
(label (org-find-text-property-in-string 'org-label (car lines)))
- (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
- (car lines)))
+ (col-cookies (org-find-text-property-in-string 'org-col-cookies
+ (car lines)))
(attributes (org-find-text-property-in-string 'org-attributes
(car lines)))
(html-table-tag (org-export-splice-attributes
tbopen line fields html gr colgropen rowstart rowend
ali align aligns n)
(setq caption (and caption (org-html-do-expand caption)))
- (when (and forced-aligns org-table-clean-did-remove-column)
- (setq forced-aligns
- (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
+ (when (and col-cookies org-table-clean-did-remove-column)
+ (setq col-cookies
+ (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
(if splice (setq head nil))
(unless splice (push (if head "<thead>" "<tbody>") html))
(setq tbopen t)
(lambda (x)
(setq gr (pop org-table-colgroup-info)
i (1+ i)
- align (if (assoc i forced-aligns)
- (cdr (assoc (cdr (assoc i forced-aligns))
+ align (if (nth 1 (assoc i col-cookies))
+ (cdr (assoc (nth 1 (assoc i col-cookies))
'(("l" . "left") ("r" . "right")
("c" . "center"))))
(if (> (/ (float x) nline)
"Format time stamps in string S, or remove them."
(catch 'exit
(let (r b)
- (while (string-match org-maybe-keyword-time-regexp s)
- (or b (setq b (substring s 0 (match-beginning 0))))
- (setq r (concat
- r (substring s 0 (match-beginning 0))
- " @<span class=\"timestamp-wrapper\">"
- (if (match-end 1)
- (format "@<span class=\"timestamp-kwd\">%s @</span>"
- (match-string 1 s)))
- (format " @<span class=\"timestamp\">%s@</span>"
- (substring
- (org-translate-time (match-string 3 s)) 1 -1))
- "@</span>")
- s (substring s (match-end 0))))
+ (when org-maybe-keyword-time-regexp
+ (while (string-match org-maybe-keyword-time-regexp s)
+ (or b (setq b (substring s 0 (match-beginning 0))))
+ (setq r (concat
+ r (substring s 0 (match-beginning 0))
+ " @<span class=\"timestamp-wrapper\">"
+ (if (match-end 1)
+ (format "@<span class=\"timestamp-kwd\">%s @</span>"
+ (match-string 1 s)))
+ (format " @<span class=\"timestamp\">%s@</span>"
+ (substring
+ (org-translate-time (match-string 3 s)) 1 -1))
+ "@</span>")
+ s (substring s (match-end 0)))))
;; Line break if line started and ended with time stamp stuff
(if (not r)
s
(defun org-html-expand (string)
"Prepare STRING for HTML export. Apply all active conversions.
-If there are links in the string, don't modify these."
- (let* ((re (concat org-bracket-link-regexp "\\|"
- (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
- m s l res)
- (while (setq m (string-match re string))
- (setq s (substring string 0 m)
- l (match-string 0 string)
- string (substring string (match-end 0)))
- (push (org-html-do-expand s) res)
+If there are links in the string, don't modify these. If STRING
+is nil, return nil."
+ (when string
+ (let* ((re (concat org-bracket-link-regexp "\\|"
+ (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
+ m s l res)
+ (while (setq m (string-match re string))
+ (setq s (substring string 0 m)
+ l (match-string 0 string)
+ string (substring string (match-end 0)))
+ (push (org-html-do-expand s) res)
(push l res))
- (push (org-html-do-expand string) res)
- (apply 'concat (nreverse res))))
+ (push (org-html-do-expand string) res)
+ (apply 'concat (nreverse res)))))
(defun org-html-do-expand (s)
"Apply all active conversions to translate special ASCII to HTML."
(mapconcat (lambda (x)
(setq x (org-solidify-link-text
(if (org-uuidgen-p x) (concat "ID-" x) x)))
- (format "<a name=\"%s\" id=\"%s\"></a>"
- x x))
+ (if (stringp org-export-html-headline-anchor-format)
+ (format org-export-html-headline-anchor-format x x)
+ ""))
extra-targets
""))
(while (>= l level)
(provide 'org-html)
-;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
;;; org-html.el ends here