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