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