Merge branch 'master' of orgmode.org:org-mode

This commit is contained in:
Bastien Guerry 2012-09-26 00:44:22 +02:00
commit ea7baa82c2
1 changed files with 193 additions and 203 deletions

View File

@ -157,9 +157,32 @@ Intended to be locally bound around a call to `org-export-as-html'." )
("\\.\\.\\." . "…")) ("\\.\\.\\." . "…"))
"Regular expressions for special string conversion.") "Regular expressions for special string conversion.")
(defconst org-e-html-scripts (defconst org-e-html-scripts
"<script type=\"text/javascript\"> "<script type=\"text/javascript\">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/ <!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id) function CodeHighlightOn(elem, id)
{ {
@ -181,8 +204,7 @@ Intended to be locally bound around a call to `org-export-as-html'." )
} }
/*]]>*///--> /*]]>*///-->
</script>" </script>"
"Basic JavaScript that is needed by HTML files produced by Org-mode.") "Basic JavaScript that is needed by HTML files produced by Org mode.")
(defconst org-e-html-style-default (defconst org-e-html-style-default
"<style type=\"text/css\"> "<style type=\"text/css\">
@ -241,14 +263,6 @@ have the default style included, customize the variable
`org-e-html-style-include-default'.") `org-e-html-style-include-default'.")
(defvar org-e-html-content-div "content"
"The name of the container DIV that holds all the page contents.
This variable is obsolete since Org version 7.7.
Please set `org-e-html-divs' instead.")
;;; User Configuration Variables ;;; User Configuration Variables
@ -353,7 +367,7 @@ and outline-text-1. If this is 2, all of these will get a 2 instead.
The default for this variable is 2, because we use <h1> for formatting the The default for this variable is 2, because we use <h1> for formatting the
document title." document title."
:group 'org-export-e-html :group 'org-export-e-html
:type 'string) :type 'integer)
(defcustom org-e-html-format-headline-function nil (defcustom org-e-html-format-headline-function nil
"Function to format headline text. "Function to format headline text.
@ -802,9 +816,14 @@ precedence over this variable."
'(("en" "<p class=\"author\">Author: %a (%e)</p> '(("en" "<p class=\"author\">Author: %a (%e)</p>
<p class=\"date\">Date: %d</p> <p class=\"date\">Date: %d</p>
<p class=\"creator\">Generated by %c</p> <p class=\"creator\">Generated by %c</p>
<p class=\"xhtml-validation\">%v</p> <p class=\"xhtml-validation\">%v</p>"))
")) "Alist of languages and format strings for the HTML postamble.
"The format for the HTML postamble.
The first element of each list is the language code, as used for
the #+LANGUAGE keyword.
The second element of each list is a format string to format the
postamble itself. This format string can contain these elements:
%a stands for the author's name. %a stands for the author's name.
%e stands for the author's email. %e stands for the author's email.
@ -815,7 +834,8 @@ precedence over this variable."
If you need to use a \"%\" character, you need to escape it If you need to use a \"%\" character, you need to escape it
like that: \"%%\"." like that: \"%%\"."
:group 'org-export-e-html :group 'org-export-e-html
:type 'string) :type '(alist :key-type (string :tag "Language")
:value-type (string :tag "Format string")))
(defcustom org-e-html-validation-link (defcustom org-e-html-validation-link
"<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>" "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
@ -853,7 +873,13 @@ precedence over this variable."
(function :tag "Function (must return a string)"))) (function :tag "Function (must return a string)")))
(defcustom org-e-html-preamble-format '(("en" "")) (defcustom org-e-html-preamble-format '(("en" ""))
"The format for the HTML preamble. "Alist of languages and format strings for the HTML preamble.
The first element of each list is the language code, as used for
the #+LANGUAGE keyword.
The second element of each list is a format string to format the
preamble itself. This format string can contain these elements:
%t stands for the title. %t stands for the title.
%a stands for the author's name. %a stands for the author's name.
@ -863,7 +889,8 @@ precedence over this variable."
If you need to use a \"%\" character, you need to escape it If you need to use a \"%\" character, you need to escape it
like that: \"%%\"." like that: \"%%\"."
:group 'org-export-e-html :group 'org-export-e-html
:type 'string) :type '(alist :key-type (string :tag "Language")
:value-type (string :tag "Format string")))
(defcustom org-e-html-link-up "" (defcustom org-e-html-link-up ""
"Where should the \"UP\" link of exported HTML pages lead?" "Where should the \"UP\" link of exported HTML pages lead?"
@ -1220,7 +1247,9 @@ is a plist used as a communication channel."
;;; Template ;;; Template
(defun org-e-html-meta-info (info) (defun org-e-html--build-meta-info (info)
"Return meta tags for exported document.
INFO is a plist used as a communication channel."
(let* ((title (org-export-data (plist-get info :title) info)) (let* ((title (org-export-data (plist-get info :title) info))
(author (and (plist-get info :with-author) (author (and (plist-get info :with-author)
(let ((auth (plist-get info :author))) (let ((auth (plist-get info :author)))
@ -1228,33 +1257,35 @@ is a plist used as a communication channel."
(description (plist-get info :description)) (description (plist-get info :description))
(keywords (plist-get info :keywords))) (keywords (plist-get info :keywords)))
(concat (concat
(format "\n<title>%s</title>\n" title) (format "<title>%s</title>\n" title)
(format (format
"\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>" "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
(or (and org-e-html-coding-system (or (and org-e-html-coding-system
(fboundp 'coding-system-get) (fboundp 'coding-system-get)
(coding-system-get org-e-html-coding-system (coding-system-get org-e-html-coding-system
'mime-charset)) 'mime-charset))
"iso-8859-1")) "iso-8859-1"))
(format "\n<meta name=\"title\" content=\"%s\"/>" title) (format "<meta name=\"title\" content=\"%s\"/>\n" title)
(format "\n<meta name=\"generator\" content=\"Org-mode\"/>") (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
(format "\n<meta name=\"generated\" content=\"%s\"/>" (format "<meta name=\"generated\" content=\"%s\"/>\n"
(org-e-html-format-date info)) (org-e-html-format-date info))
(format "\n<meta name=\"author\" content=\"%s\"/>" author) (format "<meta name=\"author\" content=\"%s\"/>\n" author)
(format "\n<meta name=\"description\" content=\"%s\"/>" description) (format "<meta name=\"description\" content=\"%s\"/>\n" description)
(format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords)))) (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords))))
(defun org-e-html-style (info) (defun org-e-html--build-style (info)
"Return style information for exported document.
INFO is a plist used as a communication channel."
(org-element-normalize-string
(concat (concat
"\n" (when (plist-get info :style-include-default) org-e-html-style-default) (when (plist-get info :style-include-default) org-e-html-style-default)
(plist-get info :style) (org-element-normalize-string (plist-get info :style))
(plist-get info :style-extra) (org-element-normalize-string (plist-get info :style-extra))
"\n" (when (plist-get info :style-include-scripts) org-e-html-scripts))))
(when (plist-get info :style-include-scripts)
org-e-html-scripts)))
(defun org-e-html-mathjax-config (info) (defun org-e-html--build-mathjax-config (info)
"Insert the user setup into the matchjax template." "Insert the user setup into the mathjax template.
INFO is a plist used as a communication channel."
(when (member (plist-get info :LaTeX-fragments) '(mathjax t)) (when (member (plist-get info :LaTeX-fragments) '(mathjax t))
(let ((template org-e-html-mathjax-template) (let ((template org-e-html-mathjax-template)
(options org-e-html-mathjax-options) (options org-e-html-mathjax-options)
@ -1274,115 +1305,99 @@ is a plist used as a communication channel."
(if (string-match (concat "\\<mathml:") in-buffer) (if (string-match (concat "\\<mathml:") in-buffer)
(setq val (car (read-from-string (setq val (car (read-from-string
(substring in-buffer (match-end 0)))))) (substring in-buffer (match-end 0))))))
;; Exchange prefixes depending on mathml setting ;; Exchange prefixes depending on mathml setting.
(if (not val) (setq x yes yes no no x)) (if (not val) (setq x yes yes no no x))
;; Replace cookies to turn on or off the config/jax lines ;; Replace cookies to turn on or off the config/jax lines.
(if (string-match ":MMLYES:" template) (if (string-match ":MMLYES:" template)
(setq template (replace-match yes t t template))) (setq template (replace-match yes t t template)))
(if (string-match ":MMLNO:" template) (if (string-match ":MMLNO:" template)
(setq template (replace-match no t t template))) (setq template (replace-match no t t template)))
;; Return the modified template ;; Return the modified template.
template))) (org-element-normalize-string template))))
(defun org-e-html-preamble (info) (defun org-e-html--build-preamble (info)
(when (plist-get info :html-preamble) "Return document preamble as a string, or nil.
(let* ((title (org-export-data (plist-get info :title) info)) INFO is a plist used as a communication channel."
(let ((preamble (plist-get info :html-preamble)))
(when preamble
(let ((preamble-contents
(if (functionp preamble) (funcall preamble info)
(let ((title (org-export-data (plist-get info :title) info))
(date (org-e-html-format-date info)) (date (org-e-html-format-date info))
(author (org-export-data (plist-get info :author) info)) (author (if (not (plist-get info :with-author)) ""
(email (plist-get info :email)) (org-export-data (plist-get info :author) info)))
(html-pre-real-contents (email (if (not (plist-get info :with-email)) ""
(cond (plist-get info :email))))
((functionp (plist-get info :html-preamble)) (if (stringp preamble)
(with-temp-buffer (format-spec preamble
(funcall (plist-get info :html-preamble))
(buffer-string)))
((stringp (plist-get info :html-preamble))
(format-spec (plist-get info :html-preamble)
`((?t . ,title) (?a . ,author) `((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email)))) (?d . ,date) (?e . ,email)))
(t
(format-spec (format-spec
(or (cadr (assoc (plist-get info :language) (or (cadr (assoc (plist-get info :language)
org-e-html-preamble-format)) org-e-html-preamble-format))
(cadr (assoc "en" org-e-html-preamble-format))) (cadr (assoc "en" org-e-html-preamble-format)))
`((?t . ,title) (?a . ,author) `((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email))))))) (?d . ,date) (?e . ,email))))))))
(when (not (equal html-pre-real-contents "")) (when (org-string-nw-p preamble-contents)
(concat (concat (format "<div id=\"%s\">\n" (nth 0 org-e-html-divs))
(format " (org-element-normalize-string preamble-contents)
<div id=\"%s\"> " (nth 0 org-e-html-divs)) "</div>\n"))))))
"
"
html-pre-real-contents
"
</div>")))))
(defun org-e-html-postamble (info) (defun org-e-html--build-postamble (info)
(concat "Return document postamble as a string, or nil.
(when (and (not body-only) INFO is a plist used as a communication channel."
(plist-get info :html-postamble)) (let ((postamble (plist-get info :html-postamble)))
(let* ((html-post (plist-get info :html-postamble)) (when postamble
(date (org-e-html-format-date info)) (let ((postamble-contents
(if (functionp postamble) (funcall postamble info)
(let ((date (org-e-html-format-date info))
(author (let ((author (plist-get info :author))) (author (let ((author (plist-get info :author)))
(and author (org-export-data author info)))) (and author (org-export-data author info))))
(email (email (mapconcat
(mapconcat (lambda(e) (lambda (e)
(format "<a href=\"mailto:%s\">%s</a>" e e)) (format "<a href=\"mailto:%s\">%s</a>" e e))
(split-string (plist-get info :email) ",+ *") (split-string (plist-get info :email) ",+ *")
", ")) ", "))
(html-validation-link (or org-e-html-validation-link "")) (html-validation-link (or org-e-html-validation-link ""))
(creator-info org-export-creator-string)) (creator-info (plist-get info :creator)))
(concat (cond ((stringp postamble)
;; begin postamble (format-spec postamble
"
<div id=\"" (nth 2 org-e-html-divs) "\">"
(cond
;; auto postamble
((eq (plist-get info :html-postamble) 'auto)
(concat
(when (plist-get info :time-stamp-file)
(format "
<p class=\"date\"> %s: %s </p> " (org-e-html--translate "Date" info) date))
(when (and (plist-get info :with-author) author)
(format "
<p class=\"author\"> %s : %s</p>" (org-e-html--translate "Author" info) author))
(when (and (plist-get info :with-email) email)
(format "
<p class=\"email\"> %s </p>" email))
(when (plist-get info :with-creator)
(format "
<p class=\"creator\"> %s </p>" creator-info))
html-validation-link "\n"))
;; postamble from a string
((stringp (plist-get info :html-postamble))
(format-spec (plist-get info :html-postamble)
`((?a . ,author) (?e . ,email) `((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info) (?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link)))) (?v . ,html-validation-link))))
((eq postamble 'auto)
;; postamble from a function (concat
((functionp (plist-get info :html-postamble)) (when (plist-get info :time-stamp-file)
(with-temp-buffer (format "<p class=\"date\">%s: %s</p>\n"
(funcall (plist-get info :html-postamble)) (org-e-html--translate "Date" info)
(buffer-string))) date))
;; default postamble (when (and (plist-get info :with-author) author)
(t (format "<p class=\"author\">%s : %s</p>\n"
(format-spec (org-e-html--translate "Author" info)
author))
(when (and (plist-get info :with-email) email)
(format "<p class=\"email\">%s </p>\n" email))
(when (plist-get info :with-creator)
(format "<p class=\"creator\">%s</p>\n"
creator-info))
html-validation-link "\n"))
(t (format-spec
(or (cadr (assoc (plist-get info :language) (or (cadr (assoc (plist-get info :language)
org-e-html-postamble-format)) org-e-html-postamble-format))
(cadr (assoc "en" org-e-html-postamble-format))) (cadr (assoc "en" org-e-html-postamble-format)))
`((?a . ,author) (?e . ,email) `((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info) (?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link))))) (?v . ,html-validation-link)))))))))
" (when (org-string-nw-p postamble-contents)
</div>"))) (concat
;; org-e-html-html-helper-timestamp (format "<div id=\"%s\">\n" (nth 2 org-e-html-divs))
)) (org-element-normalize-string postamble-contents)
"</div>\n"))))))
(defun org-e-html-template (contents info) (defun org-e-html-template (contents info)
"Return complete document string after HTML conversion. "Return complete document string after HTML conversion.
CONTENTS is the transcoded contents string. RAW-DATA is the CONTENTS is the transcoded contents string. INFO is a plist
original parsed data. INFO is a plist holding export options." holding export options."
(concat (concat
(format (format
(or (and (stringp org-e-html-xml-declaration) (or (and (stringp org-e-html-xml-declaration)
@ -1394,77 +1409,52 @@ original parsed data. INFO is a plist holding export options."
"") "")
(or (and org-e-html-coding-system (or (and org-e-html-coding-system
(fboundp 'coding-system-get) (fboundp 'coding-system-get)
(coding-system-get org-e-html-coding-system (coding-system-get org-e-html-coding-system 'mime-charset))
'mime-charset))
"iso-8859-1")) "iso-8859-1"))
" "\n"
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
(format " (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
(plist-get info :language) (plist-get info :language)) (plist-get info :language) (plist-get info :language))
" "<head>\n"
<head>" (org-e-html--build-meta-info info)
(org-e-html-meta-info info) ; meta (org-e-html--build-style info)
(org-e-html-style info) ; style (org-e-html--build-mathjax-config info)
(org-e-html-mathjax-config info) ; mathjax "</head>\n"
" "<body>\n"
</head>"
"
<body>"
(let ((link-up (org-trim (plist-get info :link-up))) (let ((link-up (org-trim (plist-get info :link-up)))
(link-home (org-trim (plist-get info :link-home)))) (link-home (org-trim (plist-get info :link-home))))
(unless (and (string= link-up "") (string= link-up "")) (unless (and (string= link-up "") (string= link-up ""))
(format org-e-html-home/up-format (format org-e-html-home/up-format
(or link-up link-home) (or link-up link-home)
(or link-home link-up)))) (or link-home link-up))))
;; preamble ;; Preamble.
(org-e-html-preamble info) (org-e-html--build-preamble info)
;; begin content ;; Begin content.
(format " (format "<div id=\"%s\">\n" (nth 1 org-e-html-divs))
<div id=\"%s\">" (or org-e-html-content-div ;; Document title.
(nth 1 org-e-html-divs))) (format "<h1 class=\"title\">%s</h1>\n"
;; document title (org-export-data (plist-get info :title) info))
(format " ;; Table of contents.
<h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info :title) info))
;; table of contents
(let ((depth (plist-get info :with-toc))) (let ((depth (plist-get info :with-toc)))
(when depth (org-e-html-toc depth info))) (when depth (org-e-html-toc depth info)))
;; document contents ;; Document contents.
contents contents
;; footnotes section ;; Footnotes section.
(org-e-html-footnote-section info) (org-e-html-footnote-section info)
;; bibliography ;; Bibliography.
(org-e-html-bibliography) (org-e-html-bibliography)
;; end content ;; End content.
(unless body-only "\n</div>"
" ;; Postamble.
</div>") (org-e-html--build-postamble info)
;; Closing document.
;; postamble "</body>\n</html>"))
(org-e-html-postamble info)
(unless body-only
"
</body>")
"
</html>"))
(defun org-e-html--translate (s info) (defun org-e-html--translate (s info)
"Transcode string S in to HTML. "Translate string S according to specified language.
INFO is a plist used as a communication channel. INFO is a plist used as a communication channel."
(org-export-translate s :html info))
Lookup utf-8 equivalent of S in `org-export-dictionary' and
replace all non-ascii characters with its numeric reference."
(let ((s (org-export-translate s :utf-8 info)))
;; Protect HTML metacharacters.
(setq s (org-e-html-encode-plain-text s))
;; Replace non-ascii characters with their numeric equivalents.
(replace-regexp-in-string
"[[:nonascii:]]"
(lambda (m) (format "&#%d;" (encode-char (string-to-char m) 'ucs)))
s t t)))
;;;; Anchor ;;;; Anchor