org-odt: Simplify org-odt-format-org-entity
[org-mode.git] / contrib / lisp / org-xhtml.el
blobf3d8079bb9b5dc6c537e36c235b03075a8c9eac0
1 ;;; org-xhtml.el --- XHTML export for Org-mode (uses org-lparse)
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 0.8
11 ;; This file is not (yet) part of GNU Emacs.
12 ;; However, it is distributed under the same license.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;;; Code:
32 (require 'org-exp)
33 (require 'format-spec)
35 (require 'org-lparse)
37 (eval-when-compile (require 'cl) (require 'table) (require 'browse-url))
39 (declare-function org-id-find-id-file "org-id" (id))
40 (declare-function htmlize-region "ext:htmlize" (beg end))
42 (defgroup org-export-xhtml nil
43 "Options specific for HTML export of Org-mode files."
44 :tag "Org Export HTML"
45 :group 'org-export)
47 (defconst org-export-xhtml-special-string-regexps
48 '(("\\\\-" . "&shy;")
49 ("---\\([^-]\\)" . "&mdash;\\1")
50 ("--\\([^-]\\)" . "&ndash;\\1")
51 ("\\.\\.\\." . "&hellip;"))
52 "Regular expressions for special string conversion.")
54 (defcustom org-export-xhtml-footnotes-section "<div id=\"footnotes\">
55 <h2 class=\"footnotes\">%s: </h2>
56 <div id=\"text-footnotes\">
58 </div>
59 </div>"
60 "Format for the footnotes section.
61 Should contain a two instances of %s. The first will be replaced with the
62 language-specific word for \"Footnotes\", the second one will be replaced
63 by the footnotes themselves."
64 :group 'org-export-xhtml
65 :type 'string)
67 (defcustom org-export-xhtml-footnote-format "<sup>%s</sup>"
68 "The format for the footnote reference.
69 %s will be replaced by the footnote reference itself."
70 :group 'org-export-xhtml
71 :type 'string)
74 (defcustom org-export-xhtml-footnote-separator "<sup>, </sup>"
75 "Text used to separate footnotes."
76 :group 'org-export-xhtml
77 :type 'string)
79 (defcustom org-export-xhtml-coding-system nil
80 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
81 :group 'org-export-xhtml
82 :type 'coding-system)
84 (defcustom org-export-xhtml-extension "html"
85 "The extension for exported HTML files."
86 :group 'org-export-xhtml
87 :type 'string)
89 (defcustom org-export-xhtml-xml-declaration
90 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
91 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
92 "The extension for exported HTML files.
93 %s will be replaced with the charset of the exported file.
94 This may be a string, or an alist with export extensions
95 and corresponding declarations."
96 :group 'org-export-xhtml
97 :type '(choice
98 (string :tag "Single declaration")
99 (repeat :tag "Dependent on extension"
100 (cons (string :tag "Extension")
101 (string :tag "Declaration")))))
103 (defcustom org-export-xhtml-style-include-scripts t
104 "Non-nil means include the JavaScript snippets in exported HTML files.
105 The actual script is defined in `org-export-xhtml-scripts' and should
106 not be modified."
107 :group 'org-export-xhtml
108 :type 'boolean)
110 (defconst org-export-xhtml-scripts
111 "<script type=\"text/javascript\">
112 <!--/*--><![CDATA[/*><!--*/
113 function CodeHighlightOn(elem, id)
115 var target = document.getElementById(id);
116 if(null != target) {
117 elem.cacheClassElem = elem.className;
118 elem.cacheClassTarget = target.className;
119 target.className = \"code-highlighted\";
120 elem.className = \"code-highlighted\";
123 function CodeHighlightOff(elem, id)
125 var target = document.getElementById(id);
126 if(elem.cacheClassElem)
127 elem.className = elem.cacheClassElem;
128 if(elem.cacheClassTarget)
129 target.className = elem.cacheClassTarget;
131 /*]]>*///-->
132 </script>"
133 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
135 (defconst org-export-xhtml-style-default
136 "<style type=\"text/css\">
137 <!--/*--><![CDATA[/*><!--*/
138 html { font-family: Times, serif; font-size: 12pt; }
139 .title { text-align: center; }
140 .todo { color: red; }
141 .done { color: green; }
142 .tag { background-color: #add8e6; font-weight:normal }
143 .target { }
144 .timestamp { color: #bebebe; }
145 .timestamp-kwd { color: #5f9ea0; }
146 .right {margin-left:auto; margin-right:0px; text-align:right;}
147 .left {margin-left:0px; margin-right:auto; text-align:left;}
148 .center {margin-left:auto; margin-right:auto; text-align:center;}
149 p.verse { margin-left: 3% }
150 pre {
151 border: 1pt solid #AEBDCC;
152 background-color: #F3F5F7;
153 padding: 5pt;
154 font-family: courier, monospace;
155 font-size: 90%;
156 overflow:auto;
158 table { border-collapse: collapse; }
159 td, th { vertical-align: top; }
160 th.right { text-align:center; }
161 th.left { text-align:center; }
162 th.center { text-align:center; }
163 td.right { text-align:right; }
164 td.left { text-align:left; }
165 td.center { text-align:center; }
166 dt { font-weight: bold; }
167 div.figure { padding: 0.5em; }
168 div.figure p { text-align: center; }
169 textarea { overflow-x: auto; }
170 .linenr { font-size:smaller }
171 .code-highlighted {background-color:#ffff00;}
172 .org-info-js_info-navigation { border-style:none; }
173 #org-info-js_console-label { font-size:10px; font-weight:bold;
174 white-space:nowrap; }
175 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
176 font-weight:bold; }
177 /*]]>*/-->
178 </style>"
179 "The default style specification for exported HTML files.
180 Please use the variables `org-export-xhtml-style' and
181 `org-export-xhtml-style-extra' to add to this style. If you wish to not
182 have the default style included, customize the variable
183 `org-export-xhtml-style-include-default'.")
185 (defcustom org-export-xhtml-style-include-default t
186 "Non-nil means include the default style in exported HTML files.
187 The actual style is defined in `org-export-xhtml-style-default' and should
188 not be modified. Use the variables `org-export-xhtml-style' to add
189 your own style information."
190 :group 'org-export-xhtml
191 :type 'boolean)
192 ;;;###autoload
193 (put 'org-export-xhtml-style-include-default 'safe-local-variable 'booleanp)
195 (defcustom org-export-xhtml-style ""
196 "Org-wide style definitions for exported HTML files.
198 This variable needs to contain the full HTML structure to provide a style,
199 including the surrounding HTML tags. If you set the value of this variable,
200 you should consider to include definitions for the following classes:
201 title, todo, done, timestamp, timestamp-kwd, tag, target.
203 For example, a valid value would be:
205 <style type=\"text/css\">
206 <![CDATA[
207 p { font-weight: normal; color: gray; }
208 h1 { color: black; }
209 .title { text-align: center; }
210 .todo, .timestamp-kwd { color: red; }
211 .done { color: green; }
213 </style>
215 If you'd like to refer to an external style file, use something like
217 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
219 As the value of this option simply gets inserted into the HTML <head> header,
220 you can \"misuse\" it to add arbitrary text to the header.
221 See also the variable `org-export-xhtml-style-extra'."
222 :group 'org-export-xhtml
223 :type 'string)
224 ;;;###autoload
225 (put 'org-export-xhtml-style 'safe-local-variable 'stringp)
227 (defcustom org-export-xhtml-style-extra ""
228 "Additional style information for HTML export.
229 The value of this variable is inserted into the HTML buffer right after
230 the value of `org-export-xhtml-style'. Use this variable for per-file
231 settings of style information, and do not forget to surround the style
232 settings with <style>...</style> tags."
233 :group 'org-export-xhtml
234 :type 'string)
235 ;;;###autoload
236 (put 'org-export-xhtml-style-extra 'safe-local-variable 'stringp)
238 (defcustom org-export-xhtml-mathjax-options
239 '((path "http://orgmode.org/mathjax/MathJax.js")
240 (scale "100")
241 (align "center")
242 (indent "2em")
243 (mathml nil))
244 "Options for MathJax setup.
246 path The path where to find MathJax
247 scale Scaling for the HTML-CSS backend, usually between 100 and 133
248 align How to align display math: left, center, or right
249 indent If align is not center, how far from the left/right side?
250 mathml Should a MathML player be used if available?
251 This is faster and reduces bandwidth use, but currently
252 sometimes has lower spacing quality. Therefore, the default is
253 nil. When browsers get better, this switch can be flipped.
255 You can also customize this for each buffer, using something like
257 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
258 :group 'org-export-xhtml
259 :type '(list :greedy t
260 (list :tag "path (the path from where to load MathJax.js)"
261 (const :format " " path) (string))
262 (list :tag "scale (scaling for the displayed math)"
263 (const :format " " scale) (string))
264 (list :tag "align (alignment of displayed equations)"
265 (const :format " " align) (string))
266 (list :tag "indent (indentation with left or right alignment)"
267 (const :format " " indent) (string))
268 (list :tag "mathml (should MathML display be used is possible)"
269 (const :format " " mathml) (boolean))))
271 (defun org-export-xhtml-mathjax-config (template options in-buffer)
272 "Insert the user setup into the matchjax template."
273 (let (name val (yes " ") (no "// ") x)
274 (mapc
275 (lambda (e)
276 (setq name (car e) val (nth 1 e))
277 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
278 (setq val (car (read-from-string
279 (substring in-buffer (match-end 0))))))
280 (if (not (stringp val)) (setq val (format "%s" val)))
281 (if (string-match (concat "%" (upcase (symbol-name name))) template)
282 (setq template (replace-match val t t template))))
283 options)
284 (setq val (nth 1 (assq 'mathml options)))
285 (if (string-match (concat "\\<mathml:") in-buffer)
286 (setq val (car (read-from-string
287 (substring in-buffer (match-end 0))))))
288 ;; Exchange prefixes depending on mathml setting
289 (if (not val) (setq x yes yes no no x))
290 ;; Replace cookies to turn on or off the config/jax lines
291 (if (string-match ":MMLYES:" template)
292 (setq template (replace-match yes t t template)))
293 (if (string-match ":MMLNO:" template)
294 (setq template (replace-match no t t template)))
295 ;; Return the modified template
296 template))
298 (defcustom org-export-xhtml-mathjax-template
299 "<script type=\"text/javascript\" src=\"%PATH\">
300 <!--/*--><![CDATA[/*><!--*/
301 MathJax.Hub.Config({
302 // Only one of the two following lines, depending on user settings
303 // First allows browser-native MathML display, second forces HTML/CSS
304 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
305 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
306 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
307 \"TeX/noUndefined.js\"],
308 tex2jax: {
309 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
310 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
311 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
312 ignoreClass: \"tex2jax_ignore\",
313 processEscapes: false,
314 processEnvironments: true,
315 preview: \"TeX\"
317 showProcessingMessages: true,
318 displayAlign: \"%ALIGN\",
319 displayIndent: \"%INDENT\",
321 \"HTML-CSS\": {
322 scale: %SCALE,
323 availableFonts: [\"STIX\",\"TeX\"],
324 preferredFont: \"TeX\",
325 webFont: \"TeX\",
326 imageFont: \"TeX\",
327 showMathMenu: true,
329 MMLorHTML: {
330 prefer: {
331 MSIE: \"MML\",
332 Firefox: \"MML\",
333 Opera: \"HTML\",
334 other: \"HTML\"
338 /*]]>*///-->
339 </script>"
340 "The MathJax setup for XHTML files."
341 :group 'org-export-xhtml
342 :type 'string)
344 (defcustom org-export-xhtml-tag-class-prefix ""
345 "Prefix to class names for TODO keywords.
346 Each tag gets a class given by the tag itself, with this prefix.
347 The default prefix is empty because it is nice to just use the keyword
348 as a class name. But if you get into conflicts with other, existing
349 CSS classes, then this prefix can be very useful."
350 :group 'org-export-xhtml
351 :type 'string)
353 (defcustom org-export-xhtml-todo-kwd-class-prefix ""
354 "Prefix to class names for TODO keywords.
355 Each TODO keyword gets a class given by the keyword itself, with this prefix.
356 The default prefix is empty because it is nice to just use the keyword
357 as a class name. But if you get into conflicts with other, existing
358 CSS classes, then this prefix can be very useful."
359 :group 'org-export-xhtml
360 :type 'string)
362 (defcustom org-export-xhtml-preamble t
363 "Non-nil means insert a preamble in HTML export.
365 When `t', insert a string as defined by one of the formatting
366 strings in `org-export-xhtml-preamble-format'. When set to a
367 string, this string overrides `org-export-xhtml-preamble-format'.
368 When set to a function, apply this function and insert the
369 returned string. The function takes the property list of export
370 options as its only argument.
372 Setting :html-preamble in publishing projects will take
373 precedence over this variable."
374 :group 'org-export-xhtml
375 :type '(choice (const :tag "No preamble" nil)
376 (const :tag "Default preamble" t)
377 (string :tag "Custom formatting string")
378 (function :tag "Function (must return a string)")))
380 (defcustom org-export-xhtml-preamble-format
381 '(("en" "<h1 class=\"title\">%t</h1>"))
382 "The format for the HTML preamble.
384 %t stands for the title.
386 If you need to use a \"%\" character, you need to escape it
387 like that: \"%%\"."
388 :group 'org-export-xhtml
389 :type 'string)
391 (defcustom org-export-xhtml-postamble 'auto
392 "Non-nil means insert a postamble in HTML export.
394 When `t', insert a string as defined by the formatting string in
395 `org-export-xhtml-postamble-format'. When set to a string, this
396 string overrides `org-export-xhtml-postamble-format'. When set to
397 'auto, discard `org-export-xhtml-postamble-format' and honor
398 `org-export-author/email/creator-info' variables. When set to a
399 function, apply this function and insert the returned string.
400 The function takes the property list of export options as its
401 only argument.
403 Setting :html-postamble in publishing projects will take
404 precedence over this variable."
405 :group 'org-export-xhtml
406 :type '(choice (const :tag "No postamble" nil)
407 (const :tag "Auto preamble" 'auto)
408 (const :tag "Default formatting string" t)
409 (string :tag "Custom formatting string")
410 (function :tag "Function (must return a string)")))
412 (defcustom org-export-xhtml-postamble-format
413 '(("en" "<p class=\"author\">Author: %a (%e)</p>
414 <p class=\"date\">Date: %d</p>
415 <p class=\"creator\">Generated by %c</p>
416 <p class=\"xhtml-validation\">%v</p>
418 "The format for the HTML postamble.
420 %a stands for the author.
421 %e stands for the email(s).
422 %d stands for the date.
423 %c will be replaced by information about Org/Emacs.
424 %v will be replaced by `org-export-xhtml-validation-link'.
426 If you need to use a \"%\" character, you need to escape it
427 like that: \"%%\"."
428 :group 'org-export-xhtml
429 :type 'string)
431 (defcustom org-export-xhtml-home/up-format
432 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
433 <a accesskey=\"h\" href=\"%s\"> UP </a>
435 <a accesskey=\"H\" href=\"%s\"> HOME </a>
436 </div>"
437 "Snippet used to insert the HOME and UP links.
438 This is a format string, the first %s will receive the UP link,
439 the second the HOME link. If both `org-export-xhtml-link-up' and
440 `org-export-xhtml-link-home' are empty, the entire snippet will be
441 ignored."
442 :group 'org-export-xhtml
443 :type 'string)
445 (defcustom org-export-xhtml-toplevel-hlevel 2
446 "The <H> level for level 1 headings in HTML export.
447 This is also important for the classes that will be wrapped around headlines
448 and outline structure. If this variable is 1, the top-level headlines will
449 be <h1>, and the corresponding classes will be outline-1, section-number-1,
450 and outline-text-1. If this is 2, all of these will get a 2 instead.
451 The default for this variable is 2, because we use <h1> for formatting the
452 document title."
453 :group 'org-export-xhtml
454 :type 'string)
456 (defcustom org-export-xhtml-link-org-files-as-html t
457 "Non-nil means make file links to `file.org' point to `file.html'.
458 When org-mode is exporting an org-mode file to HTML, links to
459 non-html files are directly put into a href tag in HTML.
460 However, links to other Org-mode files (recognized by the
461 extension `.org.) should become links to the corresponding html
462 file, assuming that the linked org-mode file will also be
463 converted to HTML.
464 When nil, the links still point to the plain `.org' file."
465 :group 'org-export-xhtml
466 :type 'boolean)
468 (defcustom org-export-xhtml-inline-images 'maybe
469 "Non-nil means inline images into exported HTML pages.
470 This is done using an <img> tag. When nil, an anchor with href is used to
471 link to the image. If this option is `maybe', then images in links with
472 an empty description will be inlined, while images with a description will
473 be linked only."
474 :group 'org-export-xhtml
475 :type '(choice (const :tag "Never" nil)
476 (const :tag "Always" t)
477 (const :tag "When there is no description" maybe)))
479 (defcustom org-export-xhtml-inline-image-extensions
480 '("png" "jpeg" "jpg" "gif" "svg")
481 "Extensions of image files that can be inlined into HTML."
482 :group 'org-export-xhtml
483 :type '(repeat (string :tag "Extension")))
485 (defcustom org-export-xhtml-table-tag
486 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
487 "The HTML tag that is used to start a table.
488 This must be a <table> tag, but you may change the options like
489 borders and spacing."
490 :group 'org-export-xhtml
491 :type 'string)
493 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
494 "The opening tag for table header fields.
495 This is customizable so that alignment options can be specified.
496 The first %s will be filled with the scope of the field, either row or col.
497 The second %s will be replaced by a style entry to align the field.
498 See also the variable `org-export-xhtml-table-use-header-tags-for-first-column'.
499 See also the variable `org-export-xhtml-table-align-individual-fields'."
500 :group 'org-export-tables
501 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
503 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
504 "The opening tag for table data fields.
505 This is customizable so that alignment options can be specified.
506 The first %s will be filled with the scope of the field, either row or col.
507 The second %s will be replaced by a style entry to align the field.
508 See also the variable `org-export-xhtml-table-align-individual-fields'."
509 :group 'org-export-tables
510 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
512 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
513 "The opening tag for table data fields.
514 This is customizable so that alignment options can be specified.
515 Instead of strings, these can be Lisp forms that will be evaluated
516 for each row in order to construct the table row tags. During evaluation,
517 the variable `head' will be true when this is a header line, nil when this
518 is a body line. And the variable `nline' will contain the line number,
519 starting from 1 in the first header line. For example
521 (setq org-export-table-row-tags
522 (cons '(if head
523 \"<tr>\"
524 (if (= (mod nline 2) 1)
525 \"<tr class=\\\"tr-odd\\\">\"
526 \"<tr class=\\\"tr-even\\\">\"))
527 \"</tr>\"))
529 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
530 :group 'org-export-tables
531 :type '(cons
532 (choice :tag "Opening tag"
533 (string :tag "Specify")
534 (sexp))
535 (choice :tag "Closing tag"
536 (string :tag "Specify")
537 (sexp))))
539 (defcustom org-export-xhtml-table-align-individual-fields t
540 "Non-nil means attach style attributes for alignment to each table field.
541 When nil, alignment will only be specified in the column tags, but this
542 is ignored by some browsers (like Firefox, Safari). Opera does it right
543 though."
544 :group 'org-export-tables
545 :type 'boolean)
547 (defcustom org-export-xhtml-table-use-header-tags-for-first-column nil
548 "Non-nil means format column one in tables with header tags.
549 When nil, also column one will use data tags."
550 :group 'org-export-tables
551 :type 'boolean)
553 (defcustom org-export-xhtml-validation-link
554 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
555 "Link to HTML validation service."
556 :group 'org-export-xhtml
557 :type 'string)
559 (defcustom org-export-xhtml-with-timestamp nil
560 "If non-nil, write timestamp into the exported HTML text.
561 If non-nil, write `org-export-xhtml-html-helper-timestamp' into the
562 exported HTML text. Otherwise, the buffer will just be saved to
563 a file."
564 :group 'org-export-xhtml
565 :type 'boolean)
567 (defcustom org-export-xhtml-html-helper-timestamp
568 "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
569 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
570 :group 'org-export-xhtml
571 :type 'string)
573 (defcustom org-export-xhtml-protect-char-alist
574 '(("&" . "&amp;")
575 ("<" . "&lt;")
576 (">" . "&gt;"))
577 "Alist of characters to be converted by `org-html-protect'."
578 :type '(repeat (cons (string :tag "Character")
579 (string :tag "HTML equivalent"))))
581 (defgroup org-export-xhtmlize nil
582 "Options for processing examples with htmlize.el."
583 :tag "Org Export Htmlize"
584 :group 'org-export-xhtml)
586 (defcustom org-export-xhtmlize-output-type 'inline-css
587 "Output type to be used by htmlize when formatting code snippets.
588 Choices are `css', to export the CSS selectors only, or `inline-css', to
589 export the CSS attribute values inline in the HTML. We use as default
590 `inline-css', in order to make the resulting HTML self-containing.
592 However, this will fail when using Emacs in batch mode for export, because
593 then no rich font definitions are in place. It will also not be good if
594 people with different Emacs setup contribute HTML files to a website,
595 because the fonts will represent the individual setups. In these cases,
596 it is much better to let Org/Htmlize assign classes only, and to use
597 a style file to define the look of these classes.
598 To get a start for your css file, start Emacs session and make sure that
599 all the faces you are interested in are defined, for example by loading files
600 in all modes you want. Then, use the command
601 \\[org-export-xhtmlize-generate-css] to extract class definitions."
602 :group 'org-export-xhtmlize
603 :type '(choice (const css) (const inline-css)))
605 (defcustom org-export-xhtmlize-css-font-prefix "org-"
606 "The prefix for CSS class names for htmlize font specifications."
607 :group 'org-export-xhtmlize
608 :type 'string)
610 (defcustom org-export-xhtmlized-org-css-url nil
611 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
612 Normally when creating an htmlized version of an Org buffer, htmlize will
613 create CSS to define the font colors. However, this does not work when
614 converting in batch mode, and it also can look bad if different people
615 with different fontification setup work on the same website.
616 When this variable is non-nil, creating an htmlized version of an Org buffer
617 using `org-export-as-org' will remove the internal CSS section and replace it
618 with a link to this URL."
619 :group 'org-export-xhtmlize
620 :type '(choice
621 (const :tag "Keep internal css" nil)
622 (string :tag "URL or local href")))
624 ;;; Hooks
626 (defvar org-export-xhtml-after-blockquotes-hook nil
627 "Hook run during HTML export, after blockquote, verse, center are done.")
629 (defvar org-export-xhtml-final-hook nil
630 "Hook run at the end of HTML export, in the new buffer.")
632 ;;; HTML export
634 (defun org-export-xhtml-preprocess (parameters)
635 "Convert LaTeX fragments to images."
636 (when (and org-current-export-file
637 (plist-get parameters :LaTeX-fragments))
638 (org-format-latex
639 (concat "ltxpng/" (file-name-sans-extension
640 (file-name-nondirectory
641 org-current-export-file)))
642 org-current-export-dir nil "Creating LaTeX image %s"
643 nil nil
644 (cond
645 ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
646 ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
647 ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
648 ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
649 (t nil))))
650 (goto-char (point-min))
651 (let (label l1)
652 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
653 (org-if-unprotected-at (match-beginning 1)
654 (setq label (match-string 1))
655 (save-match-data
656 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
657 (setq l1 (substring label (match-beginning 1)))
658 (setq l1 label)))
659 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
661 (defvar html-table-tag nil) ; dynamically scoped into this.
664 ;; FIXME: it already exists in org-html.el
665 (defconst org-html-cvt-link-fn
667 "Function to convert link URLs to exportable URLs.
668 Takes two arguments, TYPE and PATH.
669 Returns exportable url as (TYPE PATH), or nil to signal that it
670 didn't handle this case.
671 Intended to be locally bound around a call to `org-export-as-html'." )
674 ;; FIXME: it already exists in org-html.el
675 (defun org-html-cvt-org-as-html (opt-plist type path)
676 "Convert an org filename to an equivalent html filename.
677 If TYPE is not file, just return `nil'.
678 See variable `org-export-xhtml-link-org-files-as-html'"
680 (save-match-data
681 (and
682 org-export-xhtml-link-org-files-as-html
683 (string= type "file")
684 (string-match "\\.org$" path)
685 (progn
686 (list
687 "file"
688 (concat
689 (substring path 0 (match-beginning 0))
691 (plist-get opt-plist :html-extension)))))))
693 ;;; org-xhtml-format-org-link
694 (defun org-xhtml-format-org-link (opt-plist type-1 path fragment desc attr
695 descp)
696 "Make an HTML link.
697 OPT-PLIST is an options list.
698 TYPE is the device-type of the link (THIS://foo.html)
699 PATH is the path of the link (http://THIS#locationx)
700 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
701 DESC is the link description, if any.
702 ATTR is a string of other attributes of the a element.
703 MAY-INLINE-P allows inlining it as an image."
704 (declare (special org-lparse-par-open))
705 (when (string= type-1 "coderef")
706 (setq attr
707 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
708 fragment fragment)))
709 (save-match-data
710 (let* ((may-inline-p
711 (and (member type-1 '("http" "https" "file"))
712 (org-lparse-should-inline-p path descp)
713 (not fragment)))
714 (type (if (equal type-1 "id") "file" type-1))
715 (filename path)
716 ;;First pass. Just sanity stuff.
717 (components-1
718 (cond
719 ((string= type "file")
720 (list
721 type
722 ;;Substitute just if original path was absolute.
723 ;;(Otherwise path must remain relative)
724 (if (file-name-absolute-p path)
725 (concat "file://" (expand-file-name path))
726 path)))
727 ((string= type "")
728 (list nil path))
729 (t (list type path))))
731 ;;Second pass. Components converted so they can refer
732 ;;to a remote site.
733 (components-2
735 (and org-html-cvt-link-fn
736 (apply org-html-cvt-link-fn
737 opt-plist components-1))
738 (apply #'org-html-cvt-org-as-html
739 opt-plist components-1)
740 components-1))
741 (type (first components-2))
742 (thefile (second components-2)))
745 ;;Third pass. Build final link except for leading type
746 ;;spec.
747 (cond
748 ((or
749 (not type)
750 (string= type "http")
751 (string= type "https")
752 (string= type "file")
753 (string= type "coderef"))
754 (if fragment
755 (setq thefile (concat thefile "#" fragment))))
757 (t))
759 ;;Final URL-build, for all types.
760 (setq thefile
761 (let
762 ((str (org-xml-format-href thefile)))
763 (if (and type (not (or (string= "file" type)
764 (string= "coderef" type))))
765 (concat type ":" str)
766 str)))
768 (if may-inline-p
769 (org-xhtml-format-image thefile)
770 (org-lparse-format
771 'LINK (org-xml-format-desc desc) thefile attr)))))
773 (defun org-xhtml-format-inline-image (desc)
774 ;; FIXME: alt text missing here?
775 (org-xhtml-format-tags "<img src=\"%s\" alt=\"\"/>" "" desc))
778 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
779 (defvar org-lparse-link-description-is-image)
781 (defun org-xhtml-format-image (src)
782 "Create image tag with source and attributes."
783 (save-match-data
784 (if (string-match "^ltxpng/" src)
785 (format "<img src=\"%s\" alt=\"%s\"/>"
786 src (org-find-text-property-in-string 'org-latex-src src))
787 (let* ((caption (org-find-text-property-in-string 'org-caption src))
788 (attr (org-find-text-property-in-string 'org-attributes src))
789 (label (org-find-text-property-in-string 'org-label src))
790 (caption (and caption (org-xml-encode-org-text caption)))
791 (img (format "<img src=\"%s\"%s />"
793 (if (string-match "\\<alt=" (or attr ""))
794 (concat " " attr )
795 (concat " " attr " alt=\"" src "\""))))
796 (extra (concat
797 (and label
798 (format "id=\"%s\" " (org-solidify-link-text label)))
799 "class=\"figure\"")))
800 (if caption
801 (with-temp-buffer
802 (with-org-lparse-preserve-paragraph-state
803 (insert
804 (org-lparse-format
805 '("<div %s>" . "\n</div>")
806 (concat
807 (org-lparse-format '("\n<p>" . "</p>") img)
808 (org-lparse-format '("\n<p>" . "</p>") caption))
809 extra)))
810 (buffer-string))
811 img)))))
813 (defun org-export-xhtml-get-bibliography ()
814 "Find bibliography, cut it out and return it."
815 (catch 'exit
816 (let (beg end (cnt 1) bib)
817 (save-excursion
818 (goto-char (point-min))
819 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
820 (setq beg (match-beginning 0))
821 (while (re-search-forward "</?div\\>" nil t)
822 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
823 (when (= cnt 0)
824 (and (looking-at ">") (forward-char 1))
825 (setq bib (buffer-substring beg (point)))
826 (delete-region beg (point))
827 (throw 'exit bib))))
828 nil))))
830 (defun org-xhtml-format-table (lines olines)
831 (let ((org-xhtml-format-table-no-css nil))
832 (org-lparse-format-table lines olines)))
834 ;; Following variable is defined for native tables i.e., when
835 ;; `org-lparse-table-is-styled' evals to t.
836 (defvar org-xhtml-format-table-no-css)
837 (defvar org-table-number-regexp) ; defined in org-table.el
839 ;; FIXME: This function is called from other modules. Use xhtml suffix
840 ;; to avoid conflict
841 (defun org-format-table-xhtml (lines olines &optional no-css)
842 "Find out which HTML converter to use and return the HTML code.
843 NO-CSS is passed to the exporter."
844 (let* ((org-lparse-backend 'xhtml)
845 (org-lparse-entity-control-callbacks-alist
846 (org-lparse-get 'ENTITY-CONTROL))
847 (org-lparse-entity-format-callbacks-alist
848 (org-lparse-get 'ENTITY-FORMAT))
849 (org-xhtml-format-table-no-css no-css))
850 (org-lparse-format-table lines olines)))
852 ;; FIXME: This function is called from other modules. Use xhtml suffix
853 ;; to avoid conflict
854 (defun org-format-org-table-xhtml (lines &optional splice no-css)
855 ;; This routine might get called outside of org-export-as-html. For
856 ;; example, this could happen as part of org-table-export or as part
857 ;; of org-export-as-docbook. Explicitly bind the parser callback to
858 ;; the html ones for the duration of the call.
859 (let* ((org-lparse-backend 'xhtml)
860 (org-lparse-entity-control-callbacks-alist
861 (org-lparse-get 'ENTITY-CONTROL))
862 (org-lparse-entity-format-callbacks-alist
863 (org-lparse-get 'ENTITY-FORMAT))
864 (org-xhtml-format-table-no-css no-css))
865 (org-lparse-format-org-table lines splice)))
868 ;; FIXME: it already exists in org-html.el
869 (defun org-export-splice-attributes (tag attributes)
870 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
871 (if (not attributes)
873 (let (oldatt newatt)
874 (setq oldatt (org-extract-attributes-from-string tag)
875 tag (pop oldatt)
876 newatt (cdr (org-extract-attributes-from-string attributes)))
877 (while newatt
878 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
879 (if (string-match ">" tag)
880 (setq tag
881 (replace-match (concat (org-attributes-to-string oldatt) ">")
882 t t tag)))
883 tag)))
885 ;; FIXME: This function is called from other modules. Use xhtml suffix
886 ;; to avoid conflict
887 (defun org-format-table-table-xhtml (lines)
888 (let* ((org-lparse-get 'html)
889 (org-lparse-entity-control-callbacks-alist
890 (org-lparse-get 'ENTITY-CONTROL))
891 (org-lparse-entity-format-callbacks-alist
892 (org-lparse-get 'ENTITY-FORMAT)))
893 (org-lparse-format-table-table lines)))
896 ;; FIXME: it already exists in org-html.el
897 (defun org-export-splice-style (style extra)
898 "Splice EXTRA into STYLE, just before \"</style>\"."
899 (if (and (stringp extra)
900 (string-match "\\S-" extra)
901 (string-match "</style>" style))
902 (concat (substring style 0 (match-beginning 0))
903 "\n" extra "\n"
904 (substring style (match-beginning 0)))
905 style))
907 (defvar htmlize-buffer-places) ; from htmlize.el
908 (defun org-export-xhtmlize-region-for-paste (beg end)
909 "Convert the region to HTML, using htmlize.el.
910 This is much like `htmlize-region-for-paste', only that it uses
911 the settings define in the org-... variables."
912 (let* ((htmlize-output-type org-export-xhtmlize-output-type)
913 (htmlize-css-name-prefix org-export-xhtmlize-css-font-prefix)
914 (htmlbuf (htmlize-region beg end)))
915 (unwind-protect
916 (with-current-buffer htmlbuf
917 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
918 (plist-get htmlize-buffer-places 'content-end)))
919 (kill-buffer htmlbuf))))
921 ;;;###autoload
922 (defun org-export-xhtmlize-generate-css ()
923 "Create the CSS for all font definitions in the current Emacs session.
924 Use this to create face definitions in your CSS style file that can then
925 be used by code snippets transformed by htmlize.
926 This command just produces a buffer that contains class definitions for all
927 faces used in the current Emacs session. You can copy and paste the ones you
928 need into your CSS file.
930 If you then set `org-export-xhtmlize-output-type' to `css', calls to
931 the function `org-export-xhtmlize-region-for-paste' will produce code
932 that uses these same face definitions."
933 (interactive)
934 (require 'htmlize)
935 (and (get-buffer "*html*") (kill-buffer "*html*"))
936 (with-temp-buffer
937 (let ((fl (face-list))
938 (htmlize-css-name-prefix "org-")
939 (htmlize-output-type 'css)
940 f i)
941 (while (setq f (pop fl)
942 i (and f (face-attribute f :inherit)))
943 (when (and (symbolp f) (or (not i) (not (listp i))))
944 (insert (org-add-props (copy-sequence "1") nil 'face f))))
945 (htmlize-region (point-min) (point-max))))
946 (org-pop-to-buffer-same-window "*html*")
947 (goto-char (point-min))
948 (if (re-search-forward "<style" nil t)
949 (delete-region (point-min) (match-beginning 0)))
950 (if (re-search-forward "</style>" nil t)
951 (delete-region (1+ (match-end 0)) (point-max)))
952 (beginning-of-line 1)
953 (if (looking-at " +") (replace-match ""))
954 (goto-char (point-min)))
956 (defvar body-only) ; dynamically scoped into this.
958 ;; Following variable is let bound when `org-do-lparse' is in
959 ;; progress. See org-lparse.el.
961 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
962 (defvar org-lparse-toc)
963 (defvar org-lparse-footnote-buffer)
964 (defvar org-lparse-footnote-definitions)
965 (defvar org-lparse-dyn-first-heading-pos)
967 (defun org-xhtml-end-export ()
968 ;; insert the table of contents
969 (when (and org-export-with-toc (not body-only) org-lparse-toc)
970 (org-xhtml-insert-toc org-lparse-toc))
972 ;; remove empty paragraphs
973 (goto-char (point-min))
974 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
975 (replace-match ""))
977 ;; Convert whitespace place holders
978 (goto-char (point-min))
979 (let (beg end n)
980 (while (setq beg (next-single-property-change (point) 'org-whitespace))
981 (setq n (get-text-property beg 'org-whitespace)
982 end (next-single-property-change beg 'org-whitespace))
983 (goto-char beg)
984 (delete-region beg end)
985 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
986 (make-string n ?x)))))
988 ;; Remove empty lines at the beginning of the file.
989 (goto-char (point-min))
990 (when (looking-at "\\s-+\n") (replace-match ""))
992 ;; Remove display properties
993 (remove-text-properties (point-min) (point-max) '(display t))
995 ;; kill temporary buffers
996 (when org-lparse-footnote-buffer
997 (kill-buffer org-lparse-footnote-buffer))
999 ;; Run the hook
1000 (run-hooks 'org-export-xhtml-final-hook))
1002 (defun org-xhtml-format-toc-entry (snumber todo headline tags href)
1003 (setq headline (concat
1004 (and org-export-with-section-numbers
1005 (concat snumber " "))
1006 headline
1007 (and tags
1008 (concat
1009 (org-lparse-format 'SPACES 3)
1010 (org-lparse-format 'FONTIFY tags "tag")))))
1011 (when todo
1012 (setq headline (org-lparse-format 'FONTIFY headline "todo")))
1013 (org-lparse-format 'LINK headline (concat "#" href)))
1015 (defun org-xhtml-format-toc-item (toc-entry level org-last-level)
1016 (when (> level org-last-level)
1017 (let ((cnt (- level org-last-level)))
1018 (while (>= (setq cnt (1- cnt)) 0)
1019 (org-lparse-begin 'LIST 'unordered)
1020 (org-lparse-begin 'LIST-ITEM 'unordered))))
1021 (when (< level org-last-level)
1022 (let ((cnt (- org-last-level level)))
1023 (while (>= (setq cnt (1- cnt)) 0)
1024 (org-lparse-end-list-item)
1025 (org-lparse-end 'LIST 'unordered))))
1027 (org-lparse-end-list-item)
1028 (org-lparse-begin 'LIST-ITEM 'unordered)
1029 (insert toc-entry))
1031 (defun org-xhtml-begin-toc (lang-specific-heading)
1032 (org-lparse-insert-tag "<div id=\"table-of-contents\">")
1033 (insert
1034 (org-lparse-format 'HEADING lang-specific-heading
1035 (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
1036 (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
1037 (org-lparse-begin 'LIST 'unordered)
1038 (org-lparse-begin 'LIST-ITEM 'unordered))
1040 (defun org-xhtml-end-toc ()
1041 (while (> org-last-level (1- org-min-level))
1042 (setq org-last-level (1- org-last-level))
1043 (org-lparse-end-list-item)
1044 (org-lparse-end 'LIST 'unordered))
1045 (org-lparse-insert-tag "</div>")
1046 (org-lparse-insert-tag "</div>")
1048 ;; cleanup empty list items in toc
1049 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
1050 (replace-match "")))
1052 ;;;###autoload
1053 (defun org-export-as-xhtml-and-open (arg)
1054 "Export the outline as HTML and immediately open it with a browser.
1055 If there is an active region, export only the region.
1056 The prefix ARG specifies how many levels of the outline should become
1057 headlines. The default is 3. Lower levels will become bulleted lists."
1058 (interactive "P")
1059 (org-lparse-and-open "xhtml" "xhtml" arg))
1061 ;;;###autoload
1062 (defun org-export-as-xhtml-batch ()
1063 "Call the function `org-lparse-batch'.
1064 This function can be used in batch processing as:
1065 emacs --batch
1066 --load=$HOME/lib/emacs/org.el
1067 --eval \"(setq org-export-headline-levels 2)\"
1068 --visit=MyFile --funcall org-export-as-html-batch"
1069 (org-lparse-batch "xhtml"))
1071 ;;;###autoload
1072 (defun org-export-as-xhtml-to-buffer (arg)
1073 "Call `org-lparse-to-buffer` with output to a temporary buffer.
1074 No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
1075 (interactive "P")
1076 (org-lparse-to-buffer "xhtml" arg))
1078 ;;;###autoload
1079 (defun org-replace-region-by-xhtml (beg end)
1080 "Assume the current region has org-mode syntax, and convert it to HTML.
1081 This can be used in any buffer. For example, you could write an
1082 itemized list in org-mode syntax in an HTML buffer and then use this
1083 command to convert it."
1084 (interactive "r")
1085 (org-replace-region-by "xhtml" beg end))
1087 ;;;###autoload
1088 (defun org-export-region-as-xhtml (beg end &optional body-only buffer)
1089 "Convert region from BEG to END in `org-mode' buffer to HTML.
1090 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
1091 contents, and only produce the region of converted text, useful for
1092 cut-and-paste operations.
1093 If BUFFER is a buffer or a string, use/create that buffer as a target
1094 of the converted HTML. If BUFFER is the symbol `string', return the
1095 produced HTML as a string and leave not buffer behind. For example,
1096 a Lisp program could call this function in the following way:
1098 (setq html (org-export-region-as-html beg end t 'string))
1100 When called interactively, the output buffer is selected, and shown
1101 in a window. A non-interactive call will only return the buffer."
1102 (interactive "r\nP")
1103 (org-lparse-region "xhtml" beg end body-only buffer))
1105 ;;; org-export-as-xhtml
1106 ;;;###autoload
1107 (defun org-export-as-xhtml (arg &optional hidden ext-plist
1108 to-buffer body-only pub-dir)
1109 "Export the outline as a pretty HTML file.
1110 Use `org-lparse' internally to perform the actual export. This
1111 routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
1112 of `org-lparse' to \"html\"."
1113 (interactive "P")
1114 (org-lparse "xhtml" "xhtml" arg hidden ext-plist to-buffer body-only pub-dir))
1116 (defvar org-xhtml-entity-control-callbacks-alist
1117 `((EXPORT
1118 . (org-xhtml-begin-export org-xhtml-end-export))
1119 (DOCUMENT-CONTENT
1120 . (org-xhtml-begin-document-content org-xhtml-end-document-content))
1121 (DOCUMENT-BODY
1122 . (org-xhtml-begin-document-body org-xhtml-end-document-body))
1123 (TOC
1124 . (org-xhtml-begin-toc org-xhtml-end-toc))
1125 (ENVIRONMENT
1126 . (org-xhtml-begin-environment org-xhtml-end-environment))
1127 (FOOTNOTE-DEFINITION
1128 . (org-xhtml-begin-footnote-definition org-xhtml-end-footnote-definition))
1129 (TABLE
1130 . (org-xhtml-begin-table org-xhtml-end-table))
1131 (TABLE-ROWGROUP
1132 . (org-xhtml-begin-table-rowgroup org-xhtml-end-table-rowgroup))
1133 (LIST
1134 . (org-xhtml-begin-list org-xhtml-end-list))
1135 (LIST-ITEM
1136 . (org-xhtml-begin-list-item org-xhtml-end-list-item))
1137 (OUTLINE
1138 . (org-xhtml-begin-outline org-xhtml-end-outline))
1139 (OUTLINE-TEXT
1140 . (org-xhtml-begin-outline-text org-xhtml-end-outline-text))
1141 (PARAGRAPH
1142 . (org-xhtml-begin-paragraph org-xhtml-end-paragraph)))
1143 "Alist of control callbacks registered with the exporter.
1144 Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
1145 END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
1146 seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
1147 functions that get called when the exporter needs to begin or end
1148 an entity in the currently exported file. The signatures of
1149 these callbacks are specific to the ENTITY being emitted. These
1150 callbacks always get called with exported file as the current
1151 buffer and need to insert the appropriate tags into the current
1152 buffer. For example, `org-xhtml-begin-paragraph' inserts <p> and
1153 `org-xhtml-end-paragraph' inserts </p> in to the current buffer.
1154 These callbacks are invoked via `org-lparse-begin' and
1155 `org-lparse-end'.")
1157 (defvar org-xhtml-entity-format-callbacks-alist
1158 `((EXTRA-TARGETS . org-lparse-format-extra-targets)
1159 (ORG-TAGS . org-lparse-format-org-tags)
1160 (SECTION-NUMBER . org-lparse-format-section-number)
1161 (HEADLINE . org-xhtml-format-headline)
1162 (TOC-ENTRY . org-xhtml-format-toc-entry)
1163 (TOC-ITEM . org-xhtml-format-toc-item)
1164 (TAGS . org-xhtml-format-tags)
1165 (SPACES . org-xhtml-format-spaces)
1166 (TABS . org-xhtml-format-tabs)
1167 (LINE-BREAK . org-xhtml-format-line-break)
1168 (FONTIFY . org-xhtml-format-fontify)
1169 (TODO . org-lparse-format-todo)
1170 (ORG-LINK . org-xhtml-format-org-link)
1171 (LINK . org-xhtml-format-link)
1172 (INLINE-IMAGE . org-xhtml-format-inline-image)
1173 (HEADING . org-xhtml-format-heading)
1174 (ANCHOR . org-xhtml-format-anchor)
1175 (TABLE . org-xhtml-format-table)
1176 (TABLE-ROW . org-xhtml-format-table-row)
1177 (TABLE-CELL . org-xhtml-format-table-cell)
1178 (FOOTNOTES-SECTION . org-xhtml-format-footnotes-section)
1179 (FOOTNOTE-REFERENCE . org-xhtml-format-footnote-reference)
1180 (HORIZONTAL-LINE . org-xhtml-format-horizontal-line)
1181 (LINE . org-xhtml-format-line)
1182 (COMMENT . org-xhtml-format-comment)
1183 (ORG-ENTITY . org-xhtml-format-org-entity))
1184 "Alist of format callbacks registered with the exporter.
1185 Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
1186 ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
1187 seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
1188 called when the exporter needs to format a string in `org-mode'
1189 buffer in a backend specific way. The signatures of the
1190 formatting callback is specific to the ENTITY being passed in.
1191 These callbacks always need to encode the incoming entity in
1192 backend specific way and return the same. These callbacks do not
1193 make any modifications to the exporter file. For example,
1194 `org-xhtml-format-table-row' encloses incoming entity in <tr>
1195 </tr> tags and returns it. See also `org-lparse-format'.")
1197 ;; register the xhtml exporter with org-lparse library
1198 (org-lparse-register-backend 'xhtml)
1200 (defun org-xhtml-begin-document-body (opt-plist)
1201 (let ((link-up (and (plist-get opt-plist :link-up)
1202 (string-match "\\S-" (plist-get opt-plist :link-up))
1203 (plist-get opt-plist :link-up)))
1204 (link-home (and (plist-get opt-plist :link-home)
1205 (string-match "\\S-" (plist-get opt-plist :link-home))
1206 (plist-get opt-plist :link-home))))
1207 (insert "\n<body>")
1208 (org-lparse-insert-tag "<div id=\"content\">")
1209 (insert "\n"
1210 (or (and (or link-up link-home)
1211 (format org-export-xhtml-home/up-format
1212 (or link-up link-home)
1213 (or link-home link-up))) "")
1214 "\n"))
1215 (org-xhtml-insert-preamble opt-plist))
1217 (defun org-xhtml-end-document-body (opt-plist)
1218 (org-xhtml-insert-postamble opt-plist)
1219 (unless body-only
1220 (org-lparse-insert-tag "</div>")
1221 (insert "\n</body>")))
1223 (defun org-xhtml-begin-document-content (opt-plist)
1224 (let* ((language (plist-get opt-plist :language))
1225 (charset (or (and coding-system-for-write
1226 (fboundp 'coding-system-get)
1227 (coding-system-get coding-system-for-write
1228 'mime-charset))
1229 "iso-8859-1"))
1230 (style (concat (if (plist-get opt-plist :style-include-default)
1231 org-export-xhtml-style-default)
1232 (plist-get opt-plist :style)
1233 (plist-get opt-plist :style-extra)
1234 "\n"
1235 (if (plist-get opt-plist :style-include-scripts)
1236 org-export-xhtml-scripts)))
1237 (mathjax
1238 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
1239 (and org-export-have-math
1240 (eq (plist-get opt-plist :LaTeX-fragments) t)))
1242 (org-export-xhtml-mathjax-config
1243 org-export-xhtml-mathjax-template
1244 org-export-xhtml-mathjax-options
1245 (or (plist-get opt-plist :mathjax) "")) "")))
1246 (insert (format
1248 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1249 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1250 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1251 lang=\"%s\" xml:lang=\"%s\">
1252 <head>
1253 <title>%s</title>
1254 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1255 <meta name=\"generator\" content=\"Org-mode\"/>
1256 <meta name=\"generated\" content=\"%s\"/>
1257 <meta name=\"author\" content=\"%s\"/>
1258 <meta name=\"description\" content=\"%s\"/>
1259 <meta name=\"keywords\" content=\"%s\"/>
1262 </head>
1264 (format
1265 (or (and (stringp org-export-xhtml-xml-declaration)
1266 org-export-xhtml-xml-declaration)
1267 (cdr (assoc (plist-get opt-plist :html-extension)
1268 org-export-xhtml-xml-declaration))
1269 (cdr (assoc "html" org-export-xhtml-xml-declaration))
1272 charset)
1273 language language
1274 (plist-get opt-plist :title)
1275 charset
1276 (plist-get opt-plist :effective-date)
1277 (plist-get opt-plist :author)
1278 (plist-get opt-plist :description)
1279 (plist-get opt-plist :keywords)
1280 style
1281 mathjax))))
1283 (defun org-xhtml-end-document-content ()
1284 (insert "\n</html>\n"))
1286 (defun org-xhtml-begin-outline (level1 snumber title tags
1287 target extra-targets extra-class)
1288 (let* ((class (format "outline-%d" level1))
1289 (class (if extra-class (concat class " " extra-class) class))
1290 (id (format "outline-container-%s"
1291 (org-lparse-suffix-from-snumber snumber)))
1292 (extra (concat (when id (format " id=\"%s\"" id))
1293 (when class (format " class=\"%s\"" class)))))
1294 (org-lparse-insert-tag "<div%s>" extra)
1295 (insert
1296 (org-lparse-format 'HEADING
1297 (org-lparse-format
1298 'HEADLINE title extra-targets tags snumber level1)
1299 level1 target))))
1301 (defun org-xhtml-end-outline ()
1302 (org-lparse-insert-tag "</div>"))
1304 (defun org-xhtml-begin-outline-text (level1 snumber extra-class)
1305 (let* ((class (format "outline-text-%d" level1))
1306 (class (if extra-class (concat class " " extra-class) class))
1307 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
1308 (extra (concat (when id (format " id=\"%s\"" id))
1309 (when class (format " class=\"%s\"" class)))))
1310 (org-lparse-insert-tag "<div%s>" extra)))
1312 (defun org-xhtml-end-outline-text ()
1313 (org-lparse-insert-tag "</div>"))
1315 (defun org-xhtml-begin-paragraph (&optional style)
1316 (let* ((class (cdr (assoc style '((footnote . "footnote")
1317 (verse . nil)))))
1318 (extra (if class (format " class=\"%s\"" class) "")))
1319 (org-lparse-insert-tag "<p%s>" extra)))
1321 (defun org-xhtml-end-paragraph ()
1322 (insert "</p>"))
1324 (defun org-xhtml-format-environment (style beg-end)
1325 (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
1326 (case style
1327 (blockquote
1328 (case beg-end
1329 (BEGIN
1330 (org-lparse-end-paragraph)
1331 (insert "<blockquote>\n")
1332 (org-lparse-begin-paragraph))
1333 (END
1334 (org-lparse-end-paragraph)
1335 (insert "\n</blockquote>\n")
1336 (org-lparse-begin-paragraph))))
1337 (verse
1338 (case beg-end
1339 (BEGIN
1340 (org-lparse-end-paragraph)
1341 (insert "\n<p class=\"verse\">\n")
1342 (setq org-lparse-par-open t))
1343 (END
1344 (insert "</p>\n")
1345 (setq org-lparse-par-open nil)
1346 (org-lparse-begin-paragraph))))
1347 (center
1348 (case beg-end
1349 (BEGIN
1350 (org-lparse-end-paragraph)
1351 (insert "\n<div style=\"text-align: center\">")
1352 (org-lparse-begin-paragraph))
1353 (END
1354 (org-lparse-end-paragraph)
1355 (insert "\n</div>")
1356 (org-lparse-begin-paragraph))))
1357 (fixedwidth
1358 (case beg-end
1359 (BEGIN
1360 (org-lparse-end-paragraph)
1361 (insert "<pre class=\"example\">\n"))
1362 (END
1363 (insert "</pre>\n")
1364 (org-lparse-begin-paragraph))))
1365 (quote
1366 (case beg-end
1367 (BEGIN
1368 (org-lparse-end-paragraph)
1369 (insert "<pre>"))
1370 (END
1371 (insert "</pre>\n")
1372 (org-lparse-begin-paragraph))))
1373 (native
1374 (case beg-end
1375 (BEGIN (org-lparse-end-paragraph))
1376 (END (org-lparse-begin-paragraph))))
1377 (t (error "Unknown environment %s" style))))
1379 (defun org-xhtml-begin-environment (style)
1380 (org-xhtml-format-environment style 'BEGIN))
1382 (defun org-xhtml-end-environment (style)
1383 (org-xhtml-format-environment style 'END))
1385 (defun org-xhtml-begin-list (ltype &optional arg1)
1386 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1387 ltype))
1389 (case ltype
1390 (ordered (let ((extra (if arg1 (format " start=\"%d\"" arg1) "")))
1391 (org-lparse-insert-tag "<ol%s>" extra)))
1392 (unordered (org-lparse-insert-tag "<ul>"))
1393 (description (org-lparse-insert-tag "<dl>"))
1394 (t (error "Unknown list type: %s" ltype))))
1396 (defun org-xhtml-end-list (ltype)
1397 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1398 ltype))
1400 (org-lparse-insert-tag
1401 (case ltype
1402 (ordered "</ol>")
1403 (unordered "</ul>")
1404 (description "</dl>")
1405 (t (error "Unknown list type: %s" ltype)))))
1407 (defun org-xhtml-begin-list-item (ltype &optional arg headline)
1408 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1409 ltype))
1410 (case ltype
1411 (ordered
1412 (assert (not headline) t)
1413 (let* ((counter arg)
1414 (extra (if counter (format " value=\"%s\"" counter) "")))
1415 (org-lparse-insert-tag "<li%s>" extra)))
1416 (unordered
1417 (let* ((id arg)
1418 (extra (if id (format " id=\"%s\"" id) "")))
1419 (org-lparse-insert-tag "<li%s>" extra)
1420 (when headline
1421 (insert headline (org-lparse-format 'LINE-BREAK) "\n"))))
1422 (description
1423 (assert (not headline) t)
1424 (let* ((desc-tag (or arg "(no term)")))
1425 (insert
1426 (org-xhtml-format-tags '("<dt>" . "</dt>") desc-tag))
1427 (org-lparse-insert-tag "<dd>")))
1428 (t (error "Unknown list type"))))
1430 (defun org-xhtml-end-list-item (ltype)
1431 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1432 ltype))
1433 (case ltype
1434 (ordered (org-lparse-insert-tag "</li>"))
1435 (unordered (org-lparse-insert-tag "</li>"))
1436 (description (org-lparse-insert-tag "</dd>"))
1437 (t (error "Unknown list type"))))
1439 ;; Following variables are let bound when table emission is in
1440 ;; progress. See org-lparse.el.
1442 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1443 (defvar org-lparse-table-begin-marker)
1444 (defvar org-lparse-table-ncols)
1445 (defvar org-lparse-table-rowgrp-open)
1446 (defvar org-lparse-table-rownum)
1447 (defvar org-lparse-table-cur-rowgrp-is-hdr)
1448 (defvar org-lparse-table-is-styled)
1449 (defvar org-lparse-table-rowgrp-info)
1450 (defvar org-lparse-table-colalign-vector)
1451 (defvar org-lparse-table-num-numeric-items-per-column)
1453 (defun org-xhtml-begin-table-rowgroup (&optional is-header-row)
1454 (when org-lparse-table-rowgrp-open
1455 (org-lparse-end 'TABLE-ROWGROUP))
1456 (org-lparse-insert-tag (if is-header-row "<thead>" "<tbody>"))
1457 (setq org-lparse-table-rowgrp-open t)
1458 (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row))
1460 (defun org-xhtml-end-table-rowgroup ()
1461 (when org-lparse-table-rowgrp-open
1462 (setq org-lparse-table-rowgrp-open nil)
1463 (org-lparse-insert-tag
1464 (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>"))))
1466 (defun org-xhtml-begin-table (caption label attributes)
1467 (let ((html-table-tag
1468 (org-export-splice-attributes html-table-tag attributes)))
1469 (when label
1470 (setq html-table-tag
1471 (org-export-splice-attributes
1472 html-table-tag
1473 (format "id=\"%s\"" (org-solidify-link-text label)))))
1474 (org-lparse-insert-tag html-table-tag))
1476 ;; Since the output of HTML table formatter can also be used in
1477 ;; DocBook document, we want to always include the caption to make
1478 ;; DocBook XML file valid.
1479 (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
1481 (defun org-xhtml-end-table ()
1482 (when org-lparse-table-is-styled
1483 (goto-char org-lparse-table-begin-marker)
1484 (setq org-lparse-table-begin-marker nil)
1486 (let ((c -1) gr colgropen)
1487 (insert
1488 (mapconcat
1489 (lambda (x)
1490 (incf c)
1491 (setq gr (pop org-table-colgroup-info))
1493 (concat
1494 (if (memq gr '(:start :startend))
1495 (prog1
1496 (if colgropen
1497 "</colgroup>\n<colgroup>"
1498 "<colgroup>")
1499 (setq colgropen t))
1502 (let* ((align (aref org-lparse-table-colalign-vector c))
1503 (alignspec (if org-xhtml-format-table-no-css
1504 " align=\"%s\"" " class=\"%s\""))
1505 (extra (format alignspec align)))
1506 (format "<col%s />" extra))
1508 (if (memq gr '(:end :startend))
1509 (progn (setq colgropen nil) "</colgroup>")
1510 "")))
1511 org-lparse-table-num-numeric-items-per-column ""))
1513 (if colgropen (insert "</colgroup>")))
1515 ;; fill style attributes for table cells
1516 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
1517 (let ((c (string-to-number (match-string 1))))
1518 (replace-match
1519 (if org-export-xhtml-table-align-individual-fields
1520 (format (if org-xhtml-format-table-no-css " align=\"%s\""
1521 " class=\"%s\"")
1522 (or (aref org-lparse-table-colalign-vector c) "left")) "")
1523 t t)))
1524 (goto-char (point-max)))
1525 (org-lparse-insert-tag "</table>\n"))
1527 (defun org-xhtml-format-table-row (row)
1528 (org-xhtml-format-tags
1529 (cons (eval (car org-export-table-row-tags))
1530 (eval (cdr org-export-table-row-tags))) row))
1532 (defun org-xhtml-format-table-cell (text r c)
1533 (let ((cell-style-cookie (or (and org-lparse-table-is-styled
1534 (format "@@class%03d@@" c)) "")))
1535 (cond
1536 (org-lparse-table-cur-rowgrp-is-hdr
1537 (org-xhtml-format-tags
1538 org-export-table-header-tags text "col" cell-style-cookie))
1539 ((and (= c 0) org-export-xhtml-table-use-header-tags-for-first-column)
1540 (org-xhtml-format-tags
1541 org-export-table-header-tags text "row" cell-style-cookie))
1543 (org-xhtml-format-tags
1544 org-export-table-data-tags text cell-style-cookie)))))
1546 (defun org-xhtml-begin-footnote-definition (n)
1547 (org-lparse-begin-paragraph 'footnote)
1548 (insert
1549 (format
1550 (format org-export-xhtml-footnote-format
1551 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1552 n n n)))
1554 (defun org-xhtml-end-footnote-definition (n)
1555 (org-lparse-end-paragraph))
1557 (defun org-xhtml-format-spaces (n)
1558 (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
1559 (while (> n 0)
1560 (setq out (concat out space))
1561 (setq n (1- n))) out))
1563 (defun org-xhtml-format-tabs (&optional n)
1564 (ignore))
1566 (defun org-xhtml-format-line-break ()
1567 (org-xhtml-format-tags "<br/>" ""))
1569 (defun org-xhtml-format-horizontal-line ()
1570 (concat "\n" "<hr/>" "\n"))
1572 (defun org-xhtml-format-line (line)
1573 (case org-lparse-dyn-current-environment
1574 ((quote fixedwidth) (concat (org-xml-encode-plain-text line) "\n"))
1575 (t (concat line "\n"))))
1577 (defun org-xhtml-format-comment (fmt &rest args)
1578 (let ((comment (apply 'format fmt args)))
1579 (format "\n<!-- %s -->\n" comment)))
1581 (defun org-xhtml-format-fontify (text style &optional id)
1582 (let (class extra how)
1583 (cond
1584 ((eq style 'underline)
1585 (setq extra " style=\"text-decoration:underline;\"" ))
1586 ((setq how (cdr (assoc style
1587 '((bold . ("<b>" . "</b>"))
1588 (emphasis . ("<i>" . "</i>"))
1589 (code . ("<code>" . "</code>"))
1590 (verbatim . ("<code>" . "</code>"))
1591 (strike . ("<del>" . "</del>"))
1592 (subscript . ("<sub>" . "</sub>"))
1593 (superscript . ("<sup>" . "</sup>")))))))
1594 ((listp style)
1595 (setq class (mapconcat 'identity style " ")))
1596 ((stringp style)
1597 (setq class style))
1598 (t (error "Unknown style %S" style)))
1600 (setq extra (concat (when class (format " class=\"%s\"" class))
1601 (when id (format " id=\"%s\"" id))
1602 extra))
1603 (org-xhtml-format-tags
1604 (or how '("<span%s>" . "</span>")) text extra)))
1606 (defun org-xhtml-format-link (text href &optional extra)
1607 (let ((extra (concat (format " href=\"%s\"" href)
1608 (and extra (concat " " extra)))))
1609 (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
1611 (defun org-xhtml-format-heading (text level &optional id)
1612 (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1613 (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
1615 (defun org-xhtml-format-headline (title extra-targets tags
1616 &optional snumber level)
1617 (concat
1618 (org-lparse-format 'EXTRA-TARGETS extra-targets)
1619 (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
1620 title
1621 (and tags (concat (org-lparse-format 'SPACES 3)
1622 (org-lparse-format 'ORG-TAGS tags)))))
1624 (defun org-xhtml-format-anchor (text name &optional class)
1625 (let* ((id name)
1626 (extra (concat
1627 (when name (format " name=\"%s\"" name))
1628 (when id (format " id=\"%s\"" id))
1629 (when class (format " class=\"%s\"" class)))))
1630 (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
1632 (defun org-xhtml-format-footnote-reference (n def refcnt)
1633 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1634 (format org-export-xhtml-footnote-format
1635 (format
1636 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1637 n extra n n))))
1639 (defun org-xhtml-format-footnotes-section (section-name definitions)
1640 (if (not definitions) ""
1641 (format org-export-xhtml-footnotes-section section-name definitions)))
1643 (defun org-xhtml-format-org-entity (wd)
1644 (org-entity-get-representation wd 'html))
1646 (defun org-xhtml-format-tags (tag text &rest args)
1647 (let ((prefix (when org-lparse-encode-pending "@"))
1648 (suffix (when org-lparse-encode-pending "@")))
1649 (apply 'org-lparse-format-tags tag text prefix suffix args)))
1651 (defun org-xhtml-get (what &optional opt-plist)
1652 (case what
1653 (BACKEND 'html)
1654 (INIT-METHOD nil)
1655 (SAVE-METHOD nil)
1656 (CLEANUP-METHOD nil)
1657 (OTHER-BACKENDS
1658 '("xhtml" "etext" "html" "html10" "mediawiki" "pdf" "sdw" "sdw3" "sdw4"
1659 "text" "text10" "odt" "vor" "vor4"))
1660 (CONVERT-METHOD org-lparse-convert-process)
1661 (EXPORT-DIR (org-export-directory :html opt-plist))
1662 (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
1663 (EXPORT-BUFFER-NAME "*Org HTML Export*")
1664 (ENTITY-CONTROL org-xhtml-entity-control-callbacks-alist)
1665 (ENTITY-FORMAT org-xhtml-entity-format-callbacks-alist)
1666 (TOPLEVEL-HLEVEL org-export-xhtml-toplevel-hlevel)
1667 (SPECIAL-STRING-REGEXPS org-export-xhtml-special-string-regexps)
1668 (CODING-SYSTEM-FOR-WRITE org-export-xhtml-coding-system)
1669 (CODING-SYSTEM-FOR-SAVE org-export-xhtml-coding-system)
1670 (INLINE-IMAGES org-export-xhtml-inline-images)
1671 (INLINE-IMAGE-EXTENSIONS org-export-xhtml-inline-image-extensions)
1672 (PLAIN-TEXT-MAP org-export-xhtml-protect-char-alist)
1673 (TABLE-FIRST-COLUMN-AS-LABELS
1674 org-export-xhtml-table-use-header-tags-for-first-column)
1675 (TODO-KWD-CLASS-PREFIX org-export-xhtml-todo-kwd-class-prefix)
1676 (TAG-CLASS-PREFIX org-export-xhtml-tag-class-prefix)
1677 (FOOTNOTE-SEPARATOR org-export-xhtml-footnote-separator)
1678 (t (error "Unknown property: %s" what))))
1680 (defun org-xhtml-get-coding-system-for-write ()
1681 (or org-export-xhtml-coding-system
1682 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1684 (defun org-xhtml-get-coding-system-for-save ()
1685 (or org-export-xhtml-coding-system
1686 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1688 (defun org-xhtml-insert-toc (toc)
1689 ;; locate where toc needs to be inserted
1690 (goto-char (point-min))
1691 (cond
1692 ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1693 (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t))
1694 (goto-char (match-beginning 0))
1695 (replace-match "")
1696 (insert toc))
1697 (org-lparse-dyn-first-heading-pos
1698 (goto-char org-lparse-dyn-first-heading-pos)
1699 (when (looking-at "\\s-*</p>")
1700 (goto-char (match-end 0))
1701 (insert "\n"))
1702 (insert toc))
1703 (t (ignore))))
1705 (defun org-xhtml-insert-preamble (opt-plist)
1706 (when (plist-get opt-plist :html-preamble)
1707 (let ((html-pre (plist-get opt-plist :html-preamble))
1708 (title (plist-get opt-plist :title))
1709 (date (plist-get opt-plist :effective-date))
1710 (author (plist-get opt-plist :author))
1711 (lang-words (plist-get opt-plist :lang-words))
1712 (email (plist-get opt-plist :email)))
1713 (cond ((stringp html-pre)
1714 (insert
1715 (format-spec html-pre `((?t . ,title) (?a . ,author)
1716 (?d . ,date) (?e . ,email)))))
1717 ((functionp html-pre)
1718 (funcall html-pre opt-plist))
1720 (insert
1721 (format-spec
1722 (or (cadr (assoc (nth 0 lang-words)
1723 org-export-xhtml-preamble-format))
1724 (cadr (assoc "en" org-export-xhtml-preamble-format)))
1725 `((?t . ,title) (?a . ,author)
1726 (?d . ,date) (?e . ,email)))))))))
1728 (defun org-xhtml-insert-postamble (opt-plist)
1729 (when org-lparse-footnote-definitions
1730 (insert
1731 (org-lparse-format
1732 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
1733 (mapconcat (lambda (x) (cdr x))
1734 (nreverse org-lparse-footnote-definitions) "\n"))))
1735 (let ((bib (org-export-xhtml-get-bibliography)))
1736 (when bib
1737 (insert "\n" bib "\n")))
1739 ;; export html postamble
1740 (unless body-only
1741 (let* ((html-post (plist-get opt-plist :html-postamble))
1742 (date (plist-get opt-plist :effective-date))
1743 (author (plist-get opt-plist :author))
1744 (email (plist-get opt-plist :email))
1745 (lang-words (plist-get opt-plist :lang-words))
1746 (html-validation-link (or org-export-xhtml-validation-link ""))
1747 (email
1748 (mapconcat (lambda(e)
1749 (format "<a href=\"mailto:%s\">%s</a>" e e))
1750 (split-string email ",+ *")
1751 ", "))
1752 (creator-info
1753 (concat "Org version " org-version " with Emacs version "
1754 (number-to-string emacs-major-version))))
1755 (when (plist-get opt-plist :html-postamble)
1756 (cond ((stringp html-post)
1757 (insert "<div id=\"postamble\">\n")
1758 (insert (format-spec html-post
1759 `((?a . ,author) (?e . ,email)
1760 (?d . ,date) (?c . ,creator-info)
1761 (?v . ,html-validation-link))))
1762 (insert "</div>"))
1763 ((functionp html-post)
1764 (funcall html-post opt-plist))
1765 ((eq html-post 'auto)
1766 ;; fall back on default postamble
1767 (insert "<div id=\"postamble\">\n")
1768 (when (plist-get opt-plist :time-stamp-file)
1769 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
1770 (when (and (plist-get opt-plist :author-info) author)
1771 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1772 (when (and (plist-get opt-plist :email-info) email)
1773 (insert "<p class=\"email\">" email "</p>\n"))
1774 (when (plist-get opt-plist :creator-info)
1775 (insert "<p class=\"creator\">"
1776 (concat "Org version " org-version " with Emacs version "
1777 (number-to-string emacs-major-version) "</p>\n")))
1778 (insert html-validation-link "\n</div>"))
1780 (insert "<div id=\"postamble\">\n")
1781 (insert (format-spec
1782 (or (cadr (assoc (nth 0 lang-words)
1783 org-export-xhtml-postamble-format))
1784 (cadr (assoc "en" org-export-xhtml-postamble-format)))
1785 `((?a . ,author) (?e . ,email)
1786 (?d . ,date) (?c . ,creator-info)
1787 (?v . ,html-validation-link))))
1788 (insert "</div>"))))))
1790 (if org-export-xhtml-with-timestamp
1791 (insert org-export-xhtml-html-helper-timestamp)))
1793 ;; There are references to org-html-expand, org-html-protect and
1794 ;; org-html-do-expand outside of org-html.el. For now provide a
1795 ;; migration path. Ultimately these functions have to be removed.
1797 ;; (defun org-html-expand (string)
1798 ;; "A simple wrapper around `org-xml-encode-org-text-skip-links'."
1799 ;; (org-xml-encode-org-text-skip-links string))
1801 ;; (defun org-html-protect (s)
1802 ;; "A simple wrapper around `org-xml-encode-plain-text'."
1803 ;; (org-xml-encode-plain-text s))
1805 ;; (defun org-html-do-expand (s)
1806 ;; "A simple wrapper around `org-xml-encode-org-text'."
1807 ;; (org-xml-encode-org-text s))
1809 ;; (defun org-export-xhtml-format-href (s)
1810 ;; "A simple wrapper around `org-xml-format-href'."
1811 ;; (org-xml-format-href s))
1813 ;; (defun org-export-xhtml-format-desc (s)
1814 ;; "A simple wrapper around `org-xml-format-desc'."
1815 ;; (org-xml-format-desc s))
1817 (provide 'org-xhtml)
1819 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
1820 ;;; org-xhtml.el ends here