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.")
(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[/*><!--*/
function CodeHighlightOn(elem, id)
{
@ -181,11 +204,10 @@ Intended to be locally bound around a call to `org-export-as-html'." )
}
/*]]>*///-->
</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
"<style type=\"text/css\">
"<style type=\"text/css\">
<!--/*--><![CDATA[/*><!--*/
html { font-family: Times, serif; font-size: 12pt; }
.title { text-align: center; }
@ -241,14 +263,6 @@ have the default style included, customize the variable
`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
@ -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
document title."
:group 'org-export-e-html
:type 'string)
:type 'integer)
(defcustom org-e-html-format-headline-function nil
"Function to format headline text.
@ -802,20 +816,26 @@ precedence over this variable."
'(("en" "<p class=\"author\">Author: %a (%e)</p>
<p class=\"date\">Date: %d</p>
<p class=\"creator\">Generated by %c</p>
<p class=\"xhtml-validation\">%v</p>
"))
"The format for the HTML postamble.
<p class=\"xhtml-validation\">%v</p>"))
"Alist of languages and format strings for the HTML postamble.
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
%c will be replaced by information about Org/Emacs versions.
%v will be replaced by `org-e-html-validation-link'.
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.
%e stands for the author's email.
%d stands for the date.
%c will be replaced by information about Org/Emacs versions.
%v will be replaced by `org-e-html-validation-link'.
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
: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
"<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
@ -853,17 +873,24 @@ precedence over this variable."
(function :tag "Function (must return a string)")))
(defcustom org-e-html-preamble-format '(("en" ""))
"The format for the HTML preamble.
"Alist of languages and format strings for the HTML preamble.
%t stands for the title.
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
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.
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
: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 ""
"Where should the \"UP\" link of exported HTML pages lead?"
@ -1220,7 +1247,9 @@ is a plist used as a communication channel."
;;; 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))
(author (and (plist-get info :with-author)
(let ((auth (plist-get info :author)))
@ -1228,33 +1257,35 @@ is a plist used as a communication channel."
(description (plist-get info :description))
(keywords (plist-get info :keywords)))
(concat
(format "\n<title>%s</title>\n" title)
(format "<title>%s</title>\n" title)
(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
(fboundp 'coding-system-get)
(coding-system-get org-e-html-coding-system
'mime-charset))
"iso-8859-1"))
(format "\n<meta name=\"title\" content=\"%s\"/>" title)
(format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
(format "\n<meta name=\"generated\" content=\"%s\"/>"
(format "<meta name=\"title\" content=\"%s\"/>\n" title)
(format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
(format "<meta name=\"generated\" content=\"%s\"/>\n"
(org-e-html-format-date info))
(format "\n<meta name=\"author\" content=\"%s\"/>" author)
(format "\n<meta name=\"description\" content=\"%s\"/>" description)
(format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords))))
(format "<meta name=\"author\" content=\"%s\"/>\n" author)
(format "<meta name=\"description\" content=\"%s\"/>\n" description)
(format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords))))
(defun org-e-html-style (info)
(concat
"\n" (when (plist-get info :style-include-default) org-e-html-style-default)
(plist-get info :style)
(plist-get info :style-extra)
"\n"
(when (plist-get info :style-include-scripts)
org-e-html-scripts)))
(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
(when (plist-get info :style-include-default) org-e-html-style-default)
(org-element-normalize-string (plist-get info :style))
(org-element-normalize-string (plist-get info :style-extra))
(when (plist-get info :style-include-scripts) org-e-html-scripts))))
(defun org-e-html-mathjax-config (info)
"Insert the user setup into the matchjax template."
(defun org-e-html--build-mathjax-config (info)
"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))
(let ((template org-e-html-mathjax-template)
(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)
(setq val (car (read-from-string
(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))
;; 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)
(setq template (replace-match yes t t template)))
(if (string-match ":MMLNO:" template)
(setq template (replace-match no t t template)))
;; Return the modified template
template)))
;; Return the modified template.
(org-element-normalize-string template))))
(defun org-e-html-preamble (info)
(when (plist-get info :html-preamble)
(let* ((title (org-export-data (plist-get info :title) info))
(date (org-e-html-format-date info))
(author (org-export-data (plist-get info :author) info))
(email (plist-get info :email))
(html-pre-real-contents
(cond
((functionp (plist-get info :html-preamble))
(with-temp-buffer
(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)
(?d . ,date) (?e . ,email))))
(t
(format-spec
(or (cadr (assoc (plist-get info :language)
org-e-html-preamble-format))
(cadr (assoc "en" org-e-html-preamble-format)))
`((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email)))))))
(when (not (equal html-pre-real-contents ""))
(concat
(format "
<div id=\"%s\"> " (nth 0 org-e-html-divs))
"
"
html-pre-real-contents
"
</div>")))))
(defun org-e-html--build-preamble (info)
"Return document preamble as a string, or nil.
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))
(author (if (not (plist-get info :with-author)) ""
(org-export-data (plist-get info :author) info)))
(email (if (not (plist-get info :with-email)) ""
(plist-get info :email))))
(if (stringp preamble)
(format-spec preamble
`((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email)))
(format-spec
(or (cadr (assoc (plist-get info :language)
org-e-html-preamble-format))
(cadr (assoc "en" org-e-html-preamble-format)))
`((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email))))))))
(when (org-string-nw-p preamble-contents)
(concat (format "<div id=\"%s\">\n" (nth 0 org-e-html-divs))
(org-element-normalize-string preamble-contents)
"</div>\n"))))))
(defun org-e-html-postamble (info)
(concat
(when (and (not body-only)
(plist-get info :html-postamble))
(let* ((html-post (plist-get info :html-postamble))
(date (org-e-html-format-date info))
(author (let ((author (plist-get info :author)))
(and author (org-export-data author info))))
(email
(mapconcat (lambda(e)
(format "<a href=\"mailto:%s\">%s</a>" e e))
(split-string (plist-get info :email) ",+ *")
", "))
(html-validation-link (or org-e-html-validation-link ""))
(creator-info org-export-creator-string))
(concat
;; begin postamble
"
<div id=\"" (nth 2 org-e-html-divs) "\">"
(cond
;; auto postamble
((eq (plist-get info :html-postamble) 'auto)
(defun org-e-html--build-postamble (info)
"Return document postamble as a string, or nil.
INFO is a plist used as a communication channel."
(let ((postamble (plist-get info :html-postamble)))
(when postamble
(let ((postamble-contents
(if (functionp postamble) (funcall postamble info)
(let ((date (org-e-html-format-date info))
(author (let ((author (plist-get info :author)))
(and author (org-export-data author info))))
(email (mapconcat
(lambda (e)
(format "<a href=\"mailto:%s\">%s</a>" e e))
(split-string (plist-get info :email) ",+ *")
", "))
(html-validation-link (or org-e-html-validation-link ""))
(creator-info (plist-get info :creator)))
(cond ((stringp postamble)
(format-spec postamble
`((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link))))
((eq postamble 'auto)
(concat
(when (plist-get info :time-stamp-file)
(format "<p class=\"date\">%s: %s</p>\n"
(org-e-html--translate "Date" info)
date))
(when (and (plist-get info :with-author) author)
(format "<p class=\"author\">%s : %s</p>\n"
(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)
org-e-html-postamble-format))
(cadr (assoc "en" org-e-html-postamble-format)))
`((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link)))))))))
(when (org-string-nw-p postamble-contents)
(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)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link))))
;; postamble from a function
((functionp (plist-get info :html-postamble))
(with-temp-buffer
(funcall (plist-get info :html-postamble))
(buffer-string)))
;; default postamble
(t
(format-spec
(or (cadr (assoc (plist-get info :language)
org-e-html-postamble-format))
(cadr (assoc "en" org-e-html-postamble-format)))
`((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link)))))
"
</div>")))
;; 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)
"Return complete document string after HTML conversion.
CONTENTS is the transcoded contents string. RAW-DATA is the
original parsed data. INFO is a plist holding export options."
CONTENTS is the transcoded contents string. INFO is a plist
holding export options."
(concat
(format
(or (and (stringp org-e-html-xml-declaration)
@ -1393,78 +1408,53 @@ original parsed data. INFO is a plist holding export options."
"")
(or (and org-e-html-coding-system
(fboundp 'coding-system-get)
(coding-system-get org-e-html-coding-system
'mime-charset))
(fboundp 'coding-system-get)
(coding-system-get org-e-html-coding-system 'mime-charset))
"iso-8859-1"))
"
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
(format "
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
"\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
(format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
(plist-get info :language) (plist-get info :language))
"
<head>"
(org-e-html-meta-info info) ; meta
(org-e-html-style info) ; style
(org-e-html-mathjax-config info) ; mathjax
"
</head>"
"
<body>"
"<head>\n"
(org-e-html--build-meta-info info)
(org-e-html--build-style info)
(org-e-html--build-mathjax-config info)
"</head>\n"
"<body>\n"
(let ((link-up (org-trim (plist-get info :link-up)))
(link-home (org-trim (plist-get info :link-home))))
(unless (and (string= link-up "") (string= link-up ""))
(format org-e-html-home/up-format
(or link-up link-home)
(or link-home link-up))))
;; preamble
(org-e-html-preamble info)
;; begin content
(format "
<div id=\"%s\">" (or org-e-html-content-div
(nth 1 org-e-html-divs)))
;; document title
(format "
<h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info :title) info))
;; table of contents
;; Preamble.
(org-e-html--build-preamble info)
;; Begin content.
(format "<div id=\"%s\">\n" (nth 1 org-e-html-divs))
;; Document title.
(format "<h1 class=\"title\">%s</h1>\n"
(org-export-data (plist-get info :title) info))
;; Table of contents.
(let ((depth (plist-get info :with-toc)))
(when depth (org-e-html-toc depth info)))
;; document contents
;; Document contents.
contents
;; footnotes section
;; Footnotes section.
(org-e-html-footnote-section info)
;; bibliography
;; Bibliography.
(org-e-html-bibliography)
;; end content
(unless body-only
"
</div>")
;; postamble
(org-e-html-postamble info)
(unless body-only
"
</body>")
"
</html>"))
;; End content.
"\n</div>"
;; Postamble.
(org-e-html--build-postamble info)
;; Closing document.
"</body>\n</html>"))
(defun org-e-html--translate (s info)
"Transcode string S in to HTML.
INFO is a plist used as a communication channel.
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)))
"Translate string S according to specified language.
INFO is a plist used as a communication channel."
(org-export-translate s :html info))
;;;; Anchor