Fix more copyright years.
[org-mode.git] / contrib / lisp / org-xhtml.el
blob56c8b4b0c15fb4c47103f3d0395bedd6332c7a2a
1 ;;; org-xhtml.el --- XHTML export for Org-mode (uses org-lparse)
3 ;; Copyright (C) 2004-2012 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 ;;
9 ;; This file is not (yet) part of GNU Emacs.
10 ;; However, it is distributed under the same license.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 ;;; Code:
30 (require 'org-exp)
31 (require 'org-html) ; FIXME; remove during merge
32 (require 'format-spec)
33 (require 'org-lparse)
34 (eval-when-compile (require 'cl) (require 'table) (require 'browse-url))
36 (declare-function org-id-find-id-file "org-id" (id))
37 (declare-function htmlize-region "ext:htmlize" (beg end))
38 (declare-function org-pop-to-buffer-same-window
39 "org-compat" (&optional buffer-or-name norecord label))
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 div.inlinetask {
169 padding:10px;
170 border:2px solid gray;
171 margin:10px;
172 background: #ffffcc;
174 textarea { overflow-x: auto; }
175 .linenr { font-size:smaller }
176 .code-highlighted {background-color:#ffff00;}
177 .org-info-js_info-navigation { border-style:none; }
178 #org-info-js_console-label { font-size:10px; font-weight:bold;
179 white-space:nowrap; }
180 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
181 font-weight:bold; }
182 /*]]>*/-->
183 </style>"
184 "The default style specification for exported HTML files.
185 Please use the variables `org-export-xhtml-style' and
186 `org-export-xhtml-style-extra' to add to this style. If you wish to not
187 have the default style included, customize the variable
188 `org-export-xhtml-style-include-default'.")
190 (defcustom org-export-xhtml-style-include-default t
191 "Non-nil means include the default style in exported HTML files.
192 The actual style is defined in `org-export-xhtml-style-default' and should
193 not be modified. Use the variables `org-export-xhtml-style' to add
194 your own style information."
195 :group 'org-export-xhtml
196 :type 'boolean)
197 ;;;###autoload
198 (put 'org-export-xhtml-style-include-default 'safe-local-variable 'booleanp)
200 (defcustom org-export-xhtml-style ""
201 "Org-wide style definitions for exported HTML files.
203 This variable needs to contain the full HTML structure to provide a style,
204 including the surrounding HTML tags. If you set the value of this variable,
205 you should consider to include definitions for the following classes:
206 title, todo, done, timestamp, timestamp-kwd, tag, target.
208 For example, a valid value would be:
210 <style type=\"text/css\">
211 <![CDATA[
212 p { font-weight: normal; color: gray; }
213 h1 { color: black; }
214 .title { text-align: center; }
215 .todo, .timestamp-kwd { color: red; }
216 .done { color: green; }
218 </style>
220 If you'd like to refer to an external style file, use something like
222 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
224 As the value of this option simply gets inserted into the HTML <head> header,
225 you can \"misuse\" it to add arbitrary text to the header.
226 See also the variable `org-export-xhtml-style-extra'."
227 :group 'org-export-xhtml
228 :type 'string)
229 ;;;###autoload
230 (put 'org-export-xhtml-style 'safe-local-variable 'stringp)
232 (defcustom org-export-xhtml-style-extra ""
233 "Additional style information for HTML export.
234 The value of this variable is inserted into the HTML buffer right after
235 the value of `org-export-xhtml-style'. Use this variable for per-file
236 settings of style information, and do not forget to surround the style
237 settings with <style>...</style> tags."
238 :group 'org-export-xhtml
239 :type 'string)
240 ;;;###autoload
241 (put 'org-export-xhtml-style-extra 'safe-local-variable 'stringp)
243 (defcustom org-export-xhtml-mathjax-options
244 '((path "http://orgmode.org/mathjax/MathJax.js")
245 (scale "100")
246 (align "center")
247 (indent "2em")
248 (mathml nil))
249 "Options for MathJax setup.
251 path The path where to find MathJax
252 scale Scaling for the HTML-CSS backend, usually between 100 and 133
253 align How to align display math: left, center, or right
254 indent If align is not center, how far from the left/right side?
255 mathml Should a MathML player be used if available?
256 This is faster and reduces bandwidth use, but currently
257 sometimes has lower spacing quality. Therefore, the default is
258 nil. When browsers get better, this switch can be flipped.
260 You can also customize this for each buffer, using something like
262 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
263 :group 'org-export-xhtml
264 :type '(list :greedy t
265 (list :tag "path (the path from where to load MathJax.js)"
266 (const :format " " path) (string))
267 (list :tag "scale (scaling for the displayed math)"
268 (const :format " " scale) (string))
269 (list :tag "align (alignment of displayed equations)"
270 (const :format " " align) (string))
271 (list :tag "indent (indentation with left or right alignment)"
272 (const :format " " indent) (string))
273 (list :tag "mathml (should MathML display be used is possible)"
274 (const :format " " mathml) (boolean))))
276 (defun org-export-xhtml-mathjax-config (template options in-buffer)
277 "Insert the user setup into the matchjax template."
278 (let (name val (yes " ") (no "// ") x)
279 (mapc
280 (lambda (e)
281 (setq name (car e) val (nth 1 e))
282 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
283 (setq val (car (read-from-string
284 (substring in-buffer (match-end 0))))))
285 (if (not (stringp val)) (setq val (format "%s" val)))
286 (if (string-match (concat "%" (upcase (symbol-name name))) template)
287 (setq template (replace-match val t t template))))
288 options)
289 (setq val (nth 1 (assq 'mathml options)))
290 (if (string-match (concat "\\<mathml:") in-buffer)
291 (setq val (car (read-from-string
292 (substring in-buffer (match-end 0))))))
293 ;; Exchange prefixes depending on mathml setting
294 (if (not val) (setq x yes yes no no x))
295 ;; Replace cookies to turn on or off the config/jax lines
296 (if (string-match ":MMLYES:" template)
297 (setq template (replace-match yes t t template)))
298 (if (string-match ":MMLNO:" template)
299 (setq template (replace-match no t t template)))
300 ;; Return the modified template
301 template))
303 (defcustom org-export-xhtml-mathjax-template
304 "<script type=\"text/javascript\" src=\"%PATH\">
305 <!--/*--><![CDATA[/*><!--*/
306 MathJax.Hub.Config({
307 // Only one of the two following lines, depending on user settings
308 // First allows browser-native MathML display, second forces HTML/CSS
309 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
310 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
311 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
312 \"TeX/noUndefined.js\"],
313 tex2jax: {
314 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
315 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
316 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
317 ignoreClass: \"tex2jax_ignore\",
318 processEscapes: false,
319 processEnvironments: true,
320 preview: \"TeX\"
322 showProcessingMessages: true,
323 displayAlign: \"%ALIGN\",
324 displayIndent: \"%INDENT\",
326 \"HTML-CSS\": {
327 scale: %SCALE,
328 availableFonts: [\"STIX\",\"TeX\"],
329 preferredFont: \"TeX\",
330 webFont: \"TeX\",
331 imageFont: \"TeX\",
332 showMathMenu: true,
334 MMLorHTML: {
335 prefer: {
336 MSIE: \"MML\",
337 Firefox: \"MML\",
338 Opera: \"HTML\",
339 other: \"HTML\"
343 /*]]>*///-->
344 </script>"
345 "The MathJax setup for XHTML files."
346 :group 'org-export-xhtml
347 :type 'string)
349 (defcustom org-export-xhtml-tag-class-prefix ""
350 "Prefix to class names for TODO keywords.
351 Each tag gets a class given by the tag itself, with this prefix.
352 The default prefix is empty because it is nice to just use the keyword
353 as a class name. But if you get into conflicts with other, existing
354 CSS classes, then this prefix can be very useful."
355 :group 'org-export-xhtml
356 :type 'string)
358 (defcustom org-export-xhtml-todo-kwd-class-prefix ""
359 "Prefix to class names for TODO keywords.
360 Each TODO keyword gets a class given by the keyword itself, with this prefix.
361 The default prefix is empty because it is nice to just use the keyword
362 as a class name. But if you get into conflicts with other, existing
363 CSS classes, then this prefix can be very useful."
364 :group 'org-export-xhtml
365 :type 'string)
367 (defcustom org-export-xhtml-preamble t
368 "Non-nil means insert a preamble in HTML export.
370 When `t', insert a string as defined by one of the formatting
371 strings in `org-export-xhtml-preamble-format'. When set to a
372 string, this string overrides `org-export-xhtml-preamble-format'.
373 When set to a function, apply this function and insert the
374 returned string. The function takes the property list of export
375 options as its only argument.
377 Setting :html-preamble in publishing projects will take
378 precedence over this variable."
379 :group 'org-export-xhtml
380 :type '(choice (const :tag "No preamble" nil)
381 (const :tag "Default preamble" t)
382 (string :tag "Custom formatting string")
383 (function :tag "Function (must return a string)")))
385 (defcustom org-export-xhtml-preamble-format '(("en" ""))
386 "The format for the HTML preamble.
388 %t stands for the title.
389 %a stands for the author's name.
390 %e stands for the author's email.
391 %d stands for the date.
393 If you need to use a \"%\" character, you need to escape it
394 like that: \"%%\"."
395 :group 'org-export-xhtml
396 :type 'string)
398 (defcustom org-export-xhtml-postamble 'auto
399 "Non-nil means insert a postamble in HTML export.
401 When `t', insert a string as defined by the formatting string in
402 `org-export-xhtml-postamble-format'. When set to a string, this
403 string overrides `org-export-xhtml-postamble-format'. When set to
404 'auto, discard `org-export-xhtml-postamble-format' and honor
405 `org-export-author/email/creator-info' variables. When set to a
406 function, apply this function and insert the returned string.
407 The function takes the property list of export options as its
408 only argument.
410 Setting :html-postamble in publishing projects will take
411 precedence over this variable."
412 :group 'org-export-xhtml
413 :type '(choice (const :tag "No postamble" nil)
414 (const :tag "Auto preamble" 'auto)
415 (const :tag "Default formatting string" t)
416 (string :tag "Custom formatting string")
417 (function :tag "Function (must return a string)")))
419 (defcustom org-export-xhtml-postamble-format
420 '(("en" "<p class=\"author\">Author: %a (%e)</p>
421 <p class=\"date\">Date: %d</p>
422 <p class=\"creator\">Generated by %c</p>
423 <p class=\"xhtml-validation\">%v</p>
425 "The format for the HTML postamble.
427 %a stands for the author's name.
428 %e stands for the author's email.
429 %d stands for the date.
430 %c will be replaced by information about Org/Emacs versions.
431 %v will be replaced by `org-export-xhtml-validation-link'.
433 If you need to use a \"%\" character, you need to escape it
434 like that: \"%%\"."
435 :group 'org-export-xhtml
436 :type 'string)
438 (defcustom org-export-xhtml-home/up-format
439 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
440 <a accesskey=\"h\" href=\"%s\"> UP </a>
442 <a accesskey=\"H\" href=\"%s\"> HOME </a>
443 </div>"
444 "Snippet used to insert the HOME and UP links.
445 This is a format string, the first %s will receive the UP link,
446 the second the HOME link. If both `org-export-xhtml-link-up' and
447 `org-export-xhtml-link-home' are empty, the entire snippet will be
448 ignored."
449 :group 'org-export-xhtml
450 :type 'string)
452 (defcustom org-export-xhtml-toplevel-hlevel 2
453 "The <H> level for level 1 headings in HTML export.
454 This is also important for the classes that will be wrapped around headlines
455 and outline structure. If this variable is 1, the top-level headlines will
456 be <h1>, and the corresponding classes will be outline-1, section-number-1,
457 and outline-text-1. If this is 2, all of these will get a 2 instead.
458 The default for this variable is 2, because we use <h1> for formatting the
459 document title."
460 :group 'org-export-xhtml
461 :type 'string)
463 (defcustom org-export-xhtml-link-org-files-as-html t
464 "Non-nil means make file links to `file.org' point to `file.html'.
465 When org-mode is exporting an org-mode file to HTML, links to
466 non-html files are directly put into a href tag in HTML.
467 However, links to other Org-mode files (recognized by the
468 extension `.org.) should become links to the corresponding html
469 file, assuming that the linked org-mode file will also be
470 converted to HTML.
471 When nil, the links still point to the plain `.org' file."
472 :group 'org-export-xhtml
473 :type 'boolean)
475 (defcustom org-export-xhtml-inline-images 'maybe
476 "Non-nil means inline images into exported HTML pages.
477 This is done using an <img> tag. When nil, an anchor with href is used to
478 link to the image. If this option is `maybe', then images in links with
479 an empty description will be inlined, while images with a description will
480 be linked only."
481 :group 'org-export-xhtml
482 :type '(choice (const :tag "Never" nil)
483 (const :tag "Always" t)
484 (const :tag "When there is no description" maybe)))
486 (defcustom org-export-xhtml-inline-image-extensions
487 '("png" "jpeg" "jpg" "gif" "svg")
488 "Extensions of image files that can be inlined into HTML."
489 :group 'org-export-xhtml
490 :type '(repeat (string :tag "Extension")))
492 (defcustom org-export-xhtml-table-tag
493 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
494 "The HTML tag that is used to start a table.
495 This must be a <table> tag, but you may change the options like
496 borders and spacing."
497 :group 'org-export-xhtml
498 :type 'string)
500 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
501 "The opening tag for table header fields.
502 This is customizable so that alignment options can be specified.
503 The first %s will be filled with the scope of the field, either row or col.
504 The second %s will be replaced by a style entry to align the field.
505 See also the variable `org-export-xhtml-table-use-header-tags-for-first-column'.
506 See also the variable `org-export-xhtml-table-align-individual-fields'."
507 :group 'org-export-tables
508 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
510 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
511 "The opening tag for table data fields.
512 This is customizable so that alignment options can be specified.
513 The first %s will be filled with the scope of the field, either row or col.
514 The second %s will be replaced by a style entry to align the field.
515 See also the variable `org-export-xhtml-table-align-individual-fields'."
516 :group 'org-export-tables
517 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
519 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
520 "The opening tag for table data fields.
521 This is customizable so that alignment options can be specified.
522 Instead of strings, these can be Lisp forms that will be evaluated
523 for each row in order to construct the table row tags. During evaluation,
524 the variable `head' will be true when this is a header line, nil when this
525 is a body line. And the variable `nline' will contain the line number,
526 starting from 1 in the first header line. For example
528 (setq org-export-table-row-tags
529 (cons '(if head
530 \"<tr>\"
531 (if (= (mod nline 2) 1)
532 \"<tr class=\\\"tr-odd\\\">\"
533 \"<tr class=\\\"tr-even\\\">\"))
534 \"</tr>\"))
536 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
537 :group 'org-export-tables
538 :type '(cons
539 (choice :tag "Opening tag"
540 (string :tag "Specify")
541 (sexp))
542 (choice :tag "Closing tag"
543 (string :tag "Specify")
544 (sexp))))
546 (defcustom org-export-xhtml-table-align-individual-fields t
547 "Non-nil means attach style attributes for alignment to each table field.
548 When nil, alignment will only be specified in the column tags, but this
549 is ignored by some browsers (like Firefox, Safari). Opera does it right
550 though."
551 :group 'org-export-tables
552 :type 'boolean)
554 (defcustom org-export-xhtml-table-use-header-tags-for-first-column nil
555 "Non-nil means format column one in tables with header tags.
556 When nil, also column one will use data tags."
557 :group 'org-export-tables
558 :type 'boolean)
560 (defcustom org-export-xhtml-validation-link
561 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
562 "Link to HTML validation service."
563 :group 'org-export-xhtml
564 :type 'string)
566 ;; FIXME Obsolete since Org 7.7
567 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
568 (defvar org-export-xhtml-with-timestamp nil
569 "If non-nil, write container for HTML-helper-mode timestamp.")
571 ;; FIXME Obsolete since Org 7.7
572 (defvar org-export-xhtml-html-helper-timestamp
573 "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
574 "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
576 (defcustom org-export-xhtml-protect-char-alist
577 '(("&" . "&amp;")
578 ("<" . "&lt;")
579 (">" . "&gt;"))
580 "Alist of characters to be converted by `org-html-protect'."
581 :group 'org-export-xhtml
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 ;; FIXME: The following variable is obsolete since Org 7.7 but is
629 ;; still declared and checked within code for compatibility reasons.
630 ;; Use the custom variables `org-export-xhtml-divs' instead.
631 (defvar org-export-xhtml-content-div "content"
632 "The name of the container DIV that holds all the page contents.
634 This variable is obsolete since Org version 7.7.
635 Please set `org-export-xhtml-divs' instead.")
637 (defcustom org-export-xhtml-divs '("preamble" "content" "postamble")
638 "The name of the main divs for HTML export.
639 This is a list of three strings, the first one for the preamble
640 DIV, the second one for the content DIV and the third one for the
641 postamble DIV."
642 :group 'org-export-xhtml
643 :type '(list
644 (string :tag " Div for the preamble:")
645 (string :tag " Div for the content:")
646 (string :tag "Div for the postamble:")))
648 ;;; Hooks
650 (defvar org-export-xhtml-after-blockquotes-hook nil
651 "Hook run during HTML export, after blockquote, verse, center are done.")
653 (defvar org-export-xhtml-final-hook nil
654 "Hook run at the end of HTML export, in the new buffer.")
656 (defun org-export-xhtml-preprocess-latex-fragments ()
657 (when (equal org-lparse-backend 'xhtml)
658 (org-export-xhtml-do-preprocess-latex-fragments)))
660 (defvar org-lparse-opt-plist) ; bound during org-do-lparse
661 (defun org-export-xhtml-do-preprocess-latex-fragments ()
662 "Convert LaTeX fragments to images."
663 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist :LaTeX-fragments))
664 (latex-frag-opt-1 ; massage the options
665 (cond
666 ((eq latex-frag-opt 'verbatim) 'verbatim)
667 ((eq latex-frag-opt 'mathjax ) 'mathjax)
668 ((eq latex-frag-opt t ) 'mathjax)
669 ((eq latex-frag-opt 'dvipng ) 'dvipng)
670 (t nil))))
671 (when (and org-current-export-file latex-frag-opt)
672 (org-format-latex
673 (concat "ltxpng/" (file-name-sans-extension
674 (file-name-nondirectory
675 org-current-export-file)))
676 org-current-export-dir nil "Creating LaTeX image %s"
677 nil nil latex-frag-opt-1))))
679 (defun org-export-xhtml-preprocess-label-references ()
680 (goto-char (point-min))
681 (let (label l1)
682 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
683 (org-if-unprotected-at (match-beginning 1)
684 (setq label (match-string 1))
685 (save-match-data
686 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
687 (setq l1 (substring label (match-beginning 1)))
688 (setq l1 label)))
689 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
691 (defun org-export-xhtml-preprocess (parameters)
692 (org-export-xhtml-preprocess-label-references))
694 ;; Process latex fragments as part of
695 ;; `org-export-preprocess-after-blockquote-hook'. Note that this hook
696 ;; is the one that is closest and well before the call to
697 ;; `org-export-attach-captions-and-attributes' in
698 ;; `org-export-preprocess-stirng'. The above arrangement permits
699 ;; captions, labels and attributes to be attached to png images
700 ;; generated out of latex equations.
701 (add-hook 'org-export-preprocess-after-blockquote-hook
702 'org-export-xhtml-preprocess-latex-fragments)
704 (defvar html-table-tag nil) ; dynamically scoped into this.
707 ;; FIXME: it already exists in org-html.el
708 (defconst org-html-cvt-link-fn
710 "Function to convert link URLs to exportable URLs.
711 Takes two arguments, TYPE and PATH.
712 Returns exportable url as (TYPE PATH), or nil to signal that it
713 didn't handle this case.
714 Intended to be locally bound around a call to `org-export-as-html'." )
717 ;; FIXME: it already exists in org-html.el
718 (defun org-html-cvt-org-as-html (opt-plist type path)
719 "Convert an org filename to an equivalent html filename.
720 If TYPE is not file, just return `nil'.
721 See variable `org-export-xhtml-link-org-files-as-html'"
723 (save-match-data
724 (and
725 org-export-xhtml-link-org-files-as-html
726 (string= type "file")
727 (string-match "\\.org$" path)
728 (progn
729 (list
730 "file"
731 (concat
732 (substring path 0 (match-beginning 0))
734 (plist-get opt-plist :html-extension)))))))
736 (defun org-xhtml-format-org-link (opt-plist type-1 path fragment desc attr
737 descp)
738 "Make an HTML link.
739 OPT-PLIST is an options list.
740 TYPE is the device-type of the link (THIS://foo.html).
741 PATH is the path of the link (http://THIS#location).
742 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
743 DESC is the link description, if any.
744 ATTR is a string of other attributes of the \"a\" element."
745 (declare (special org-lparse-par-open))
746 (save-match-data
747 (when (string= type-1 "coderef")
748 (let ((ref fragment))
749 (setq desc (format (org-export-get-coderef-format ref (and descp desc))
750 (cdr (assoc ref org-export-code-refs)))
751 fragment (concat "coderef-" ref)
752 attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
753 fragment fragment))))
754 (let* ((may-inline-p
755 (and (member type-1 '("http" "https" "file"))
756 (org-lparse-should-inline-p path descp)
757 (not fragment)))
758 (type (if (equal type-1 "id") "file" type-1))
759 (filename path)
760 ;;First pass. Just sanity stuff.
761 (components-1
762 (cond
763 ((string= type "file")
764 (list
765 type
766 ;;Substitute just if original path was absolute.
767 ;;(Otherwise path must remain relative)
768 (if (file-name-absolute-p path)
769 (concat "file://" (expand-file-name path))
770 path)))
771 ((string= type "")
772 (list nil path))
773 (t (list type path))))
775 ;;Second pass. Components converted so they can refer
776 ;;to a remote site.
777 (components-2
779 (and org-html-cvt-link-fn
780 (apply org-html-cvt-link-fn
781 opt-plist components-1))
782 (apply #'org-html-cvt-org-as-html
783 opt-plist components-1)
784 components-1))
785 (type (first components-2))
786 (thefile (second components-2)))
789 ;;Third pass. Build final link except for leading type
790 ;;spec.
791 (cond
792 ((or
793 (not type)
794 (string= type "http")
795 (string= type "https")
796 (string= type "file")
797 (string= type "coderef"))
798 (if fragment
799 (setq thefile (concat thefile "#" fragment))))
801 (t))
803 ;;Final URL-build, for all types.
804 (setq thefile
805 (let
806 ((str (org-xml-format-href thefile)))
807 (if (and type (not (or (string= "file" type)
808 (string= "coderef" type))))
809 (concat type ":" str)
810 str)))
812 (if may-inline-p
813 (org-xhtml-format-image thefile)
814 (org-lparse-format
815 'LINK (org-xml-format-desc desc) thefile attr)))))
817 (defun org-xhtml-format-inline-image (desc)
818 ;; FIXME: alt text missing here?
819 (org-xhtml-format-tags
820 "<img src=\"%s\" alt=\"%s\"/>" "" desc (file-name-nondirectory desc)))
822 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
823 (defvar org-lparse-link-description-is-image)
825 (defun org-xhtml-format-image (src)
826 "Create image tag with source and attributes."
827 (save-match-data
828 (let* ((caption (org-find-text-property-in-string 'org-caption src))
829 (attr (org-find-text-property-in-string 'org-attributes src))
830 (label (org-find-text-property-in-string 'org-label src))
831 (caption (and caption (org-xml-encode-org-text caption)))
832 (img-extras (if (string-match "^ltxpng/" src)
833 (format " alt=\"%s\""
834 (org-find-text-property-in-string
835 'org-latex-src src))
836 (if (string-match "\\<alt=" (or attr ""))
837 (concat " " attr )
838 (concat " " attr " alt=\"" src "\""))))
839 (img (format "<img src=\"%s\"%s />" src img-extras))
840 (extra (concat
841 (and label
842 (format "id=\"%s\" " (org-solidify-link-text label)))
843 "class=\"figure\"")))
844 (if caption
845 (with-temp-buffer
846 (with-org-lparse-preserve-paragraph-state
847 (insert
848 (org-lparse-format
849 '("<div %s>" . "\n</div>")
850 (concat
851 (org-lparse-format '("\n<p>" . "</p>") img)
852 (org-lparse-format '("\n<p>" . "</p>") caption))
853 extra)))
854 (buffer-string))
855 img))))
857 (defun org-export-xhtml-get-bibliography ()
858 "Find bibliography, cut it out and return it."
859 (catch 'exit
860 (let (beg end (cnt 1) bib)
861 (save-excursion
862 (goto-char (point-min))
863 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
864 (setq beg (match-beginning 0))
865 (while (re-search-forward "</?div\\>" nil t)
866 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
867 (when (= cnt 0)
868 (and (looking-at ">") (forward-char 1))
869 (setq bib (buffer-substring beg (point)))
870 (delete-region beg (point))
871 (throw 'exit bib))))
872 nil))))
874 (defun org-xhtml-format-table (lines olines)
875 (let ((org-xhtml-format-table-no-css nil))
876 (org-lparse-format-table lines olines)))
878 ;; Following variable is defined for native tables i.e., when
879 ;; `org-lparse-table-is-styled' evals to t.
880 (defvar org-xhtml-format-table-no-css)
881 (defvar org-table-number-regexp) ; defined in org-table.el
883 ;; FIXME: This function is called from other modules. Use xhtml suffix
884 ;; to avoid conflict
885 (defun org-format-table-xhtml (lines olines &optional no-css)
886 "Find out which HTML converter to use and return the HTML code.
887 NO-CSS is passed to the exporter."
888 (let* ((org-lparse-backend 'xhtml)
889 (org-lparse-entity-control-callbacks-alist
890 (org-lparse-get 'ENTITY-CONTROL))
891 (org-lparse-entity-format-callbacks-alist
892 (org-lparse-get 'ENTITY-FORMAT))
893 (org-xhtml-format-table-no-css no-css))
894 (org-lparse-format-table lines olines)))
896 ;; FIXME: This function is called from other modules. Use xhtml suffix
897 ;; to avoid conflict
898 (defun org-format-org-table-xhtml (lines &optional splice no-css)
899 ;; This routine might get called outside of org-export-as-html. For
900 ;; example, this could happen as part of org-table-export or as part
901 ;; of org-export-as-docbook. Explicitly bind the parser callback to
902 ;; the html ones for the duration of the call.
903 (let* ((org-lparse-backend 'xhtml)
904 (org-lparse-entity-control-callbacks-alist
905 (org-lparse-get 'ENTITY-CONTROL))
906 (org-lparse-entity-format-callbacks-alist
907 (org-lparse-get 'ENTITY-FORMAT))
908 (org-xhtml-format-table-no-css no-css))
909 (org-lparse-format-org-table lines splice)))
912 ;; FIXME: it already exists in org-html.el
913 (defun org-export-splice-attributes (tag attributes)
914 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
915 (if (not attributes)
917 (let (oldatt newatt)
918 (setq oldatt (org-extract-attributes-from-string tag)
919 tag (pop oldatt)
920 newatt (cdr (org-extract-attributes-from-string attributes)))
921 (while newatt
922 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
923 (if (string-match ">" tag)
924 (setq tag
925 (replace-match (concat (org-attributes-to-string oldatt) ">")
926 t t tag)))
927 tag)))
929 ;; FIXME: This function is called from other modules. Use xhtml suffix
930 ;; to avoid conflict
931 (defun org-format-table-table-xhtml (lines)
932 (let* ((org-lparse-get 'html)
933 (org-lparse-entity-control-callbacks-alist
934 (org-lparse-get 'ENTITY-CONTROL))
935 (org-lparse-entity-format-callbacks-alist
936 (org-lparse-get 'ENTITY-FORMAT)))
937 (org-lparse-format-table-table lines)))
940 ;; FIXME: it already exists in org-html.el
941 (defun org-export-splice-style (style extra)
942 "Splice EXTRA into STYLE, just before \"</style>\"."
943 (if (and (stringp extra)
944 (string-match "\\S-" extra)
945 (string-match "</style>" style))
946 (concat (substring style 0 (match-beginning 0))
947 "\n" extra "\n"
948 (substring style (match-beginning 0)))
949 style))
951 (defvar htmlize-buffer-places) ; from htmlize.el
952 (defun org-export-xhtmlize-region-for-paste (beg end)
953 "Convert the region to HTML, using htmlize.el.
954 This is much like `htmlize-region-for-paste', only that it uses
955 the settings define in the org-... variables."
956 (let* ((htmlize-output-type org-export-xhtmlize-output-type)
957 (htmlize-css-name-prefix org-export-xhtmlize-css-font-prefix)
958 (htmlbuf (htmlize-region beg end)))
959 (unwind-protect
960 (with-current-buffer htmlbuf
961 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
962 (plist-get htmlize-buffer-places 'content-end)))
963 (kill-buffer htmlbuf))))
965 ;;;###autoload
966 (defun org-export-xhtmlize-generate-css ()
967 "Create the CSS for all font definitions in the current Emacs session.
968 Use this to create face definitions in your CSS style file that can then
969 be used by code snippets transformed by htmlize.
970 This command just produces a buffer that contains class definitions for all
971 faces used in the current Emacs session. You can copy and paste the ones you
972 need into your CSS file.
974 If you then set `org-export-xhtmlize-output-type' to `css', calls to
975 the function `org-export-xhtmlize-region-for-paste' will produce code
976 that uses these same face definitions."
977 (interactive)
978 (require 'htmlize)
979 (and (get-buffer "*html*") (kill-buffer "*html*"))
980 (with-temp-buffer
981 (let ((fl (face-list))
982 (htmlize-css-name-prefix "org-")
983 (htmlize-output-type 'css)
984 f i)
985 (while (setq f (pop fl)
986 i (and f (face-attribute f :inherit)))
987 (when (and (symbolp f) (or (not i) (not (listp i))))
988 (insert (org-add-props (copy-sequence "1") nil 'face f))))
989 (htmlize-region (point-min) (point-max))))
990 (org-pop-to-buffer-same-window "*html*")
991 (goto-char (point-min))
992 (if (re-search-forward "<style" nil t)
993 (delete-region (point-min) (match-beginning 0)))
994 (if (re-search-forward "</style>" nil t)
995 (delete-region (1+ (match-end 0)) (point-max)))
996 (beginning-of-line 1)
997 (if (looking-at " +") (replace-match ""))
998 (goto-char (point-min)))
1000 (defvar body-only) ; dynamically scoped into this.
1002 ;; Following variable is let bound when `org-do-lparse' is in
1003 ;; progress. See org-lparse.el.
1005 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1006 (defvar org-lparse-toc)
1007 (defvar org-lparse-footnote-definitions)
1008 (defvar org-lparse-dyn-first-heading-pos)
1010 (defun org-xhtml-end-export ()
1011 ;; insert the table of contents
1012 (when (and org-export-with-toc (not body-only) org-lparse-toc)
1013 (org-xhtml-insert-toc org-lparse-toc))
1015 ;; remove empty paragraphs
1016 (goto-char (point-min))
1017 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
1018 (replace-match ""))
1020 ;; Convert whitespace place holders
1021 (goto-char (point-min))
1022 (let (beg end n)
1023 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1024 (setq n (get-text-property beg 'org-whitespace)
1025 end (next-single-property-change beg 'org-whitespace))
1026 (goto-char beg)
1027 (delete-region beg end)
1028 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1029 (make-string n ?x)))))
1031 ;; Remove empty lines at the beginning of the file.
1032 (goto-char (point-min))
1033 (when (looking-at "\\s-+\n") (replace-match ""))
1035 ;; Remove display properties
1036 (remove-text-properties (point-min) (point-max) '(display t))
1038 ;; Run the hook
1039 (run-hooks 'org-export-xhtml-final-hook))
1041 (defun org-xhtml-format-toc-entry (snumber todo headline tags href)
1042 (setq headline (concat
1043 (and org-export-with-section-numbers
1044 (concat snumber " "))
1045 headline
1046 (and tags
1047 (concat
1048 (org-lparse-format 'SPACES 3)
1049 (org-lparse-format 'FONTIFY tags "tag")))))
1050 (when todo
1051 (setq headline (org-lparse-format 'FONTIFY headline "todo")))
1052 (org-lparse-format 'LINK headline (concat "#" href)))
1054 (defun org-xhtml-format-toc-item (toc-entry level org-last-level)
1055 (when (> level org-last-level)
1056 (let ((cnt (- level org-last-level)))
1057 (while (>= (setq cnt (1- cnt)) 0)
1058 (org-lparse-begin-list 'unordered)
1059 (org-lparse-begin-list-item 'unordered))))
1060 (when (< level org-last-level)
1061 (let ((cnt (- org-last-level level)))
1062 (while (>= (setq cnt (1- cnt)) 0)
1063 (org-lparse-end-list-item-1)
1064 (org-lparse-end-list 'unordered))))
1066 (org-lparse-end-list-item-1)
1067 (org-lparse-begin-list-item 'unordered)
1068 (insert toc-entry))
1070 (defun org-xhtml-begin-toc (lang-specific-heading max-level)
1071 (org-lparse-insert-tag "<div id=\"table-of-contents\">")
1072 (insert
1073 (org-lparse-format 'HEADING lang-specific-heading
1074 (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
1075 (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
1076 (org-lparse-begin-list 'unordered)
1077 (org-lparse-begin-list-item 'unordered))
1079 (defun org-xhtml-end-toc ()
1080 (while (> org-last-level (1- org-min-level))
1081 (setq org-last-level (1- org-last-level))
1082 (org-lparse-end-list-item-1)
1083 (org-lparse-end-list 'unordered))
1084 (org-lparse-insert-tag "</div>")
1085 (org-lparse-insert-tag "</div>")
1087 ;; cleanup empty list items in toc
1088 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
1089 (replace-match "")))
1091 ;;;###autoload
1092 (defun org-export-as-xhtml-and-open (arg)
1093 "Export the outline as HTML and immediately open it with a browser.
1094 If there is an active region, export only the region.
1095 The prefix ARG specifies how many levels of the outline should become
1096 headlines. The default is 3. Lower levels will become bulleted lists."
1097 (interactive "P")
1098 (org-lparse-and-open "xhtml" "xhtml" arg))
1100 ;;;###autoload
1101 (defun org-export-as-xhtml-batch ()
1102 "Call the function `org-lparse-batch'.
1103 This function can be used in batch processing as:
1104 emacs --batch
1105 --load=$HOME/lib/emacs/org.el
1106 --eval \"(setq org-export-headline-levels 2)\"
1107 --visit=MyFile --funcall org-export-as-html-batch"
1108 (org-lparse-batch "xhtml"))
1110 ;;;###autoload
1111 (defun org-export-as-xhtml-to-buffer (arg)
1112 "Call `org-lparse-to-buffer` with output to a temporary buffer.
1113 No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
1114 (interactive "P")
1115 (org-lparse-to-buffer "xhtml" arg))
1117 ;;;###autoload
1118 (defun org-replace-region-by-xhtml (beg end)
1119 "Assume the current region has org-mode syntax, and convert it to HTML.
1120 This can be used in any buffer. For example, you could write an
1121 itemized list in org-mode syntax in an HTML buffer and then use this
1122 command to convert it."
1123 (interactive "r")
1124 (org-replace-region-by "xhtml" beg end))
1126 ;;;###autoload
1127 (defun org-export-region-as-xhtml (beg end &optional body-only buffer)
1128 "Convert region from BEG to END in `org-mode' buffer to HTML.
1129 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
1130 contents, and only produce the region of converted text, useful for
1131 cut-and-paste operations.
1132 If BUFFER is a buffer or a string, use/create that buffer as a target
1133 of the converted HTML. If BUFFER is the symbol `string', return the
1134 produced HTML as a string and leave not buffer behind. For example,
1135 a Lisp program could call this function in the following way:
1137 (setq html (org-export-region-as-html beg end t 'string))
1139 When called interactively, the output buffer is selected, and shown
1140 in a window. A non-interactive call will only return the buffer."
1141 (interactive "r\nP")
1142 (org-lparse-region "xhtml" beg end body-only buffer))
1144 ;;; org-export-as-xhtml
1145 ;;;###autoload
1146 (defun org-export-as-xhtml (arg &optional hidden ext-plist
1147 to-buffer body-only pub-dir)
1148 "Export the outline as a pretty HTML file.
1149 Use `org-lparse' internally to perform the actual export. This
1150 routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
1151 of `org-lparse' to \"html\"."
1152 (interactive "P")
1153 (org-lparse "xhtml" "xhtml" arg hidden ext-plist to-buffer body-only pub-dir))
1155 (defvar org-xhtml-entity-control-callbacks-alist
1156 `((EXPORT
1157 . (org-xhtml-begin-export org-xhtml-end-export))
1158 (DOCUMENT-CONTENT
1159 . (org-xhtml-begin-document-content org-xhtml-end-document-content))
1160 (DOCUMENT-BODY
1161 . (org-xhtml-begin-document-body org-xhtml-end-document-body))
1162 (TOC
1163 . (org-xhtml-begin-toc org-xhtml-end-toc))
1164 (ENVIRONMENT
1165 . (org-xhtml-begin-environment org-xhtml-end-environment))
1166 (FOOTNOTE-DEFINITION
1167 . (org-xhtml-begin-footnote-definition org-xhtml-end-footnote-definition))
1168 (TABLE
1169 . (org-xhtml-begin-table org-xhtml-end-table))
1170 (TABLE-ROWGROUP
1171 . (org-xhtml-begin-table-rowgroup org-xhtml-end-table-rowgroup))
1172 (LIST
1173 . (org-xhtml-begin-list org-xhtml-end-list))
1174 (LIST-ITEM
1175 . (org-xhtml-begin-list-item org-xhtml-end-list-item))
1176 (OUTLINE
1177 . (org-xhtml-begin-outline org-xhtml-end-outline))
1178 (OUTLINE-TEXT
1179 . (org-xhtml-begin-outline-text org-xhtml-end-outline-text))
1180 (PARAGRAPH
1181 . (org-xhtml-begin-paragraph org-xhtml-end-paragraph)))
1182 "Alist of control callbacks registered with the exporter.
1183 Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
1184 END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
1185 seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
1186 functions that get called when the exporter needs to begin or end
1187 an entity in the currently exported file. The signatures of
1188 these callbacks are specific to the ENTITY being emitted. These
1189 callbacks always get called with exported file as the current
1190 buffer and need to insert the appropriate tags into the current
1191 buffer. For example, `org-xhtml-begin-paragraph' inserts <p> and
1192 `org-xhtml-end-paragraph' inserts </p> in to the current buffer.
1193 These callbacks are invoked via `org-lparse-begin' and
1194 `org-lparse-end'.")
1196 (defvar org-xhtml-entity-format-callbacks-alist
1197 `((EXTRA-TARGETS . org-lparse-format-extra-targets)
1198 (ORG-TAGS . org-lparse-format-org-tags)
1199 (SECTION-NUMBER . org-lparse-format-section-number)
1200 (HEADLINE . org-xhtml-format-headline)
1201 (TOC-ENTRY . org-xhtml-format-toc-entry)
1202 (TOC-ITEM . org-xhtml-format-toc-item)
1203 (TAGS . org-xhtml-format-tags)
1204 (SPACES . org-xhtml-format-spaces)
1205 (TABS . org-xhtml-format-tabs)
1206 (LINE-BREAK . org-xhtml-format-line-break)
1207 (FONTIFY . org-xhtml-format-fontify)
1208 (TODO . org-lparse-format-todo)
1209 (ORG-LINK . org-xhtml-format-org-link)
1210 (LINK . org-xhtml-format-link)
1211 (INLINE-IMAGE . org-xhtml-format-inline-image)
1212 (HEADING . org-xhtml-format-heading)
1213 (ANCHOR . org-xhtml-format-anchor)
1214 (TABLE . org-xhtml-format-table)
1215 (TABLE-ROW . org-xhtml-format-table-row)
1216 (TABLE-CELL . org-xhtml-format-table-cell)
1217 (FOOTNOTES-SECTION . org-xhtml-format-footnotes-section)
1218 (FOOTNOTE-REFERENCE . org-xhtml-format-footnote-reference)
1219 (HORIZONTAL-LINE . org-xhtml-format-horizontal-line)
1220 (LINE . org-xhtml-format-line)
1221 (COMMENT . org-xhtml-format-comment)
1222 (ORG-ENTITY . org-xhtml-format-org-entity))
1223 "Alist of format callbacks registered with the exporter.
1224 Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
1225 ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
1226 seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
1227 called when the exporter needs to format a string in `org-mode'
1228 buffer in a backend specific way. The signatures of the
1229 formatting callback is specific to the ENTITY being passed in.
1230 These callbacks always need to encode the incoming entity in
1231 backend specific way and return the same. These callbacks do not
1232 make any modifications to the exporter file. For example,
1233 `org-xhtml-format-table-row' encloses incoming entity in <tr>
1234 </tr> tags and returns it. See also `org-lparse-format'.")
1236 ;; register the xhtml exporter with org-lparse library
1237 (org-lparse-register-backend 'xhtml)
1239 (defun org-xhtml-unload-function ()
1240 (org-lparse-unregister-backend 'xhtml)
1241 (remove-hook 'org-export-preprocess-after-blockquote-hook
1242 'org-export-xhtml-preprocess-latex-fragments)
1243 nil)
1245 (defun org-xhtml-begin-document-body (opt-plist)
1246 (let ((link-up (and (plist-get opt-plist :link-up)
1247 (string-match "\\S-" (plist-get opt-plist :link-up))
1248 (plist-get opt-plist :link-up)))
1249 (link-home (and (plist-get opt-plist :link-home)
1250 (string-match "\\S-" (plist-get opt-plist :link-home))
1251 (plist-get opt-plist :link-home))))
1252 (insert "\n<body>")
1253 (insert "\n"
1254 (or (and (or link-up link-home)
1255 (format org-export-xhtml-home/up-format
1256 (or link-up link-home)
1257 (or link-home link-up))) "")
1258 "\n"))
1259 (org-xhtml-insert-preamble opt-plist)
1261 (org-lparse-insert-tag
1262 "<div id=\"%s\">" (or org-export-xhtml-content-div
1263 (nth 1 org-export-xhtml-divs)))
1265 (org-lparse-insert-tag "\n<h1 class=\"title\"> %s </h1>\n"
1266 (plist-get opt-plist :title)))
1268 (defun org-xhtml-end-document-body (opt-plist)
1269 (org-xhtml-insert-postamble opt-plist)
1270 (unless body-only
1271 (insert "\n</body>")))
1273 (defun org-xhtml-begin-document-content (opt-plist)
1274 (let* ((language (plist-get opt-plist :language))
1275 (charset (or (and coding-system-for-write
1276 (fboundp 'coding-system-get)
1277 (coding-system-get coding-system-for-write
1278 'mime-charset))
1279 "iso-8859-1"))
1280 (style (concat (if (plist-get opt-plist :style-include-default)
1281 org-export-xhtml-style-default)
1282 (plist-get opt-plist :style)
1283 (plist-get opt-plist :style-extra)
1284 "\n"
1285 (if (plist-get opt-plist :style-include-scripts)
1286 org-export-xhtml-scripts)))
1287 (mathjax
1288 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
1289 (and org-export-have-math
1290 (eq (plist-get opt-plist :LaTeX-fragments) t)))
1292 (org-export-xhtml-mathjax-config
1293 org-export-xhtml-mathjax-template
1294 org-export-xhtml-mathjax-options
1295 (or (plist-get opt-plist :mathjax) "")) "")))
1296 (insert (format
1298 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1299 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1300 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
1301 <head>
1302 <title>%s</title>
1303 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1304 <meta name=\"title\" content=\"%s\"/>
1305 <meta name=\"generator\" content=\"Org-mode\"/>
1306 <meta name=\"generated\" content=\"%s\"/>
1307 <meta name=\"author\" content=\"%s\"/>
1308 <meta name=\"description\" content=\"%s\"/>
1309 <meta name=\"keywords\" content=\"%s\"/>
1312 </head>
1314 (format
1315 (or (and (stringp org-export-xhtml-xml-declaration)
1316 org-export-xhtml-xml-declaration)
1317 (cdr (assoc (plist-get opt-plist :html-extension)
1318 org-export-xhtml-xml-declaration))
1319 (cdr (assoc "html" org-export-xhtml-xml-declaration))
1322 charset)
1323 language language
1324 (plist-get opt-plist :title)
1325 charset
1326 (plist-get opt-plist :title)
1327 (plist-get opt-plist :effective-date)
1328 (plist-get opt-plist :author)
1329 (plist-get opt-plist :description)
1330 (plist-get opt-plist :keywords)
1331 style
1332 mathjax))))
1334 (defun org-xhtml-end-document-content ()
1335 (insert "\n</html>\n"))
1337 (defun org-xhtml-begin-outline (level1 snumber title tags
1338 target extra-targets extra-class)
1339 (let* ((class (format "outline-%d" level1))
1340 (class (if extra-class (concat class " " extra-class) class))
1341 (id (format "outline-container-%s"
1342 (org-lparse-suffix-from-snumber snumber)))
1343 (extra (concat (when id (format " id=\"%s\"" id))
1344 (when class (format " class=\"%s\"" class)))))
1345 (org-lparse-insert-tag "<div%s>" extra)
1346 (insert
1347 (org-lparse-format 'HEADING
1348 (org-lparse-format
1349 'HEADLINE title extra-targets tags snumber level1)
1350 level1 target))))
1352 (defun org-xhtml-end-outline ()
1353 (org-lparse-insert-tag "</div>"))
1355 (defun org-xhtml-begin-outline-text (level1 snumber extra-class)
1356 (let* ((class (format "outline-text-%d" level1))
1357 (class (if extra-class (concat class " " extra-class) class))
1358 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
1359 (extra (concat (when id (format " id=\"%s\"" id))
1360 (when class (format " class=\"%s\"" class)))))
1361 (org-lparse-insert-tag "<div%s>" extra)))
1363 (defun org-xhtml-end-outline-text ()
1364 (org-lparse-insert-tag "</div>"))
1366 (defun org-xhtml-begin-paragraph (&optional style)
1367 (let* ((class (cdr (assoc style '((footnote . "footnote")
1368 (verse . nil)))))
1369 (extra (if class (format " class=\"%s\"" class) "")))
1370 (org-lparse-insert-tag "<p%s>" extra)))
1372 (defun org-xhtml-end-paragraph ()
1373 (insert "</p>"))
1375 (defun org-xhtml-format-environment (style beg-end)
1376 (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
1377 (case style
1378 (blockquote
1379 (case beg-end
1380 (BEGIN
1381 (org-lparse-end-paragraph)
1382 (insert "<blockquote>\n")
1383 (org-lparse-begin-paragraph))
1384 (END
1385 (org-lparse-end-paragraph)
1386 (insert "\n</blockquote>\n")
1387 (org-lparse-begin-paragraph))))
1388 (verse
1389 (case beg-end
1390 (BEGIN
1391 (org-lparse-end-paragraph)
1392 (insert "\n<p class=\"verse\">\n")
1393 (setq org-lparse-par-open t))
1394 (END
1395 (insert "</p>\n")
1396 (setq org-lparse-par-open nil)
1397 (org-lparse-begin-paragraph))))
1398 (center
1399 (case beg-end
1400 (BEGIN
1401 (org-lparse-end-paragraph)
1402 (insert "\n<div style=\"text-align: center\">")
1403 (org-lparse-begin-paragraph))
1404 (END
1405 (org-lparse-end-paragraph)
1406 (insert "\n</div>")
1407 (org-lparse-begin-paragraph))))
1408 (fixedwidth
1409 (case beg-end
1410 (BEGIN
1411 (org-lparse-end-paragraph)
1412 (insert "<pre class=\"example\">\n"))
1413 (END
1414 (insert "</pre>\n")
1415 (org-lparse-begin-paragraph))))
1416 (quote
1417 (case beg-end
1418 (BEGIN
1419 (org-lparse-end-paragraph)
1420 (insert "<pre>"))
1421 (END
1422 (insert "</pre>\n")
1423 (org-lparse-begin-paragraph))))
1424 (native
1425 (case beg-end
1426 (BEGIN (org-lparse-end-paragraph))
1427 (END (org-lparse-begin-paragraph))))
1428 (t (error "Unknown environment %s" style))))
1430 (defun org-xhtml-begin-environment (style env-options-plist)
1431 (org-xhtml-format-environment style 'BEGIN))
1433 (defun org-xhtml-end-environment (style env-options-plist)
1434 (org-xhtml-format-environment style 'END))
1436 (defun org-xhtml-begin-list (ltype)
1437 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1438 ltype))
1439 (case ltype
1440 (ordered (let* ((arg1 nil)
1441 (extra (if arg1 (format " start=\"%d\"" arg1) "")))
1442 (org-lparse-insert-tag "<ol%s>" extra)))
1443 (unordered (org-lparse-insert-tag "<ul>"))
1444 (description (org-lparse-insert-tag "<dl>"))
1445 (t (error "Unknown list type: %s" ltype))))
1447 (defun org-xhtml-end-list (ltype)
1448 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1449 ltype))
1451 (org-lparse-insert-tag
1452 (case ltype
1453 (ordered "</ol>")
1454 (unordered "</ul>")
1455 (description "</dl>")
1456 (t (error "Unknown list type: %s" ltype)))))
1458 (defun org-xhtml-begin-list-item (ltype &optional arg headline)
1459 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1460 ltype))
1461 (case ltype
1462 (ordered
1463 (assert (not headline) t)
1464 (let* ((counter arg)
1465 (extra (if counter (format " value=\"%s\"" counter) "")))
1466 (org-lparse-insert-tag "<li%s>" extra)))
1467 (unordered
1468 (let* ((id arg)
1469 (extra (if id (format " id=\"%s\"" id) "")))
1470 (org-lparse-insert-tag "<li%s>" extra)
1471 (when headline
1472 (insert headline (org-lparse-format 'LINE-BREAK) "\n"))))
1473 (description
1474 (assert (not headline) t)
1475 (let* ((desc-tag (or arg "(no term)")))
1476 (insert
1477 (org-xhtml-format-tags '("<dt>" . "</dt>") desc-tag))
1478 (org-lparse-insert-tag "<dd>")))
1479 (t (error "Unknown list type"))))
1481 (defun org-xhtml-end-list-item (ltype)
1482 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1483 ltype))
1484 (case ltype
1485 (ordered (org-lparse-insert-tag "</li>"))
1486 (unordered (org-lparse-insert-tag "</li>"))
1487 (description (org-lparse-insert-tag "</dd>"))
1488 (t (error "Unknown list type"))))
1490 ;; Following variables are let bound when table emission is in
1491 ;; progress. See org-lparse.el.
1493 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1494 (defvar org-lparse-table-begin-marker)
1495 (defvar org-lparse-table-ncols)
1496 (defvar org-lparse-table-rowgrp-open)
1497 (defvar org-lparse-table-rownum)
1498 (defvar org-lparse-table-cur-rowgrp-is-hdr)
1499 (defvar org-lparse-table-is-styled)
1500 (defvar org-lparse-table-rowgrp-info)
1501 (defvar org-lparse-table-colalign-vector)
1502 (defvar org-lparse-table-num-numeric-items-per-column)
1504 (defun org-xhtml-begin-table-rowgroup (&optional is-header-row)
1505 (when org-lparse-table-rowgrp-open
1506 (org-lparse-end 'TABLE-ROWGROUP))
1507 (org-lparse-insert-tag (if is-header-row "<thead>" "<tbody>"))
1508 (setq org-lparse-table-rowgrp-open t)
1509 (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row))
1511 (defun org-xhtml-end-table-rowgroup ()
1512 (when org-lparse-table-rowgrp-open
1513 (setq org-lparse-table-rowgrp-open nil)
1514 (org-lparse-insert-tag
1515 (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>"))))
1517 (defun org-xhtml-begin-table (caption label attributes)
1518 (let ((html-table-tag
1519 (org-export-splice-attributes html-table-tag attributes)))
1520 (when label
1521 (setq html-table-tag
1522 (org-export-splice-attributes
1523 html-table-tag
1524 (format "id=\"%s\"" (org-solidify-link-text label)))))
1525 (org-lparse-insert-tag html-table-tag))
1527 ;; Since the output of HTML table formatter can also be used in
1528 ;; DocBook document, we want to always include the caption to make
1529 ;; DocBook XML file valid.
1530 (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
1532 (defun org-xhtml-end-table ()
1533 (when org-lparse-table-is-styled
1534 (goto-char org-lparse-table-begin-marker)
1535 (setq org-lparse-table-begin-marker nil)
1537 (let ((c -1) gr colgropen)
1538 (insert
1539 (mapconcat
1540 (lambda (x)
1541 (incf c)
1542 (setq gr (pop org-table-colgroup-info))
1544 (concat
1545 (if (memq gr '(:start :startend))
1546 (prog1
1547 (if colgropen
1548 "</colgroup>\n<colgroup>"
1549 "<colgroup>")
1550 (setq colgropen t))
1553 (let* ((align (aref org-lparse-table-colalign-vector c))
1554 (alignspec (if (and (boundp 'org-xhtml-format-table-no-css)
1555 org-xhtml-format-table-no-css)
1556 " align=\"%s\"" " class=\"%s\""))
1557 (extra (format alignspec align)))
1558 (format "<col%s />" extra))
1560 (if (memq gr '(:end :startend))
1561 (progn (setq colgropen nil) "</colgroup>")
1562 "")))
1563 org-lparse-table-num-numeric-items-per-column ""))
1565 (if colgropen (insert "</colgroup>")))
1567 ;; fill style attributes for table cells
1568 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
1569 (let ((c (string-to-number (match-string 1))))
1570 (replace-match
1571 (if org-export-xhtml-table-align-individual-fields
1572 (format (if (and (boundp 'org-xhtml-format-table-no-css)
1573 org-xhtml-format-table-no-css)
1574 " align=\"%s\"" " class=\"%s\"")
1575 (or (aref org-lparse-table-colalign-vector c) "left")) "")
1576 t t)))
1577 (goto-char (point-max)))
1578 (org-lparse-insert-tag "</table>\n"))
1580 (defun org-xhtml-format-table-row (row)
1581 (org-xhtml-format-tags
1582 (cons (eval (car org-export-table-row-tags))
1583 (eval (cdr org-export-table-row-tags))) row))
1585 (defun org-xhtml-format-table-cell (text r c horiz-span)
1586 (let ((cell-style-cookie (or (and org-lparse-table-is-styled
1587 (format "@@class%03d@@" c)) "")))
1588 (cond
1589 (org-lparse-table-cur-rowgrp-is-hdr
1590 (org-xhtml-format-tags
1591 org-export-table-header-tags text "col" cell-style-cookie))
1592 ((and (= c 0) org-export-xhtml-table-use-header-tags-for-first-column)
1593 (org-xhtml-format-tags
1594 org-export-table-header-tags text "row" cell-style-cookie))
1596 (org-xhtml-format-tags
1597 org-export-table-data-tags text cell-style-cookie)))))
1599 (defun org-xhtml-begin-footnote-definition (n)
1600 (org-lparse-begin-paragraph 'footnote)
1601 (insert
1602 (format
1603 (format org-export-xhtml-footnote-format
1604 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1605 n n n)))
1607 (defun org-xhtml-end-footnote-definition (n)
1608 (org-lparse-end-paragraph))
1610 (defun org-xhtml-format-spaces (n)
1611 (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
1612 (while (> n 0)
1613 (setq out (concat out space))
1614 (setq n (1- n))) out))
1616 (defun org-xhtml-format-tabs (&optional n)
1617 (ignore))
1619 (defun org-xhtml-format-line-break ()
1620 (org-xhtml-format-tags "<br/>" ""))
1622 (defun org-xhtml-format-horizontal-line ()
1623 (concat "\n" "<hr/>" "\n"))
1625 (defun org-xhtml-format-line (line)
1626 (case org-lparse-dyn-current-environment
1627 ((quote fixedwidth) (concat (org-xml-encode-plain-text line) "\n"))
1628 (t (concat line "\n"))))
1630 (defun org-xhtml-format-comment (fmt &rest args)
1631 (let ((comment (apply 'format fmt args)))
1632 (format "\n<!-- %s -->\n" comment)))
1634 (defun org-xhtml-format-fontify (text style &optional id)
1635 (let (class extra how)
1636 (cond
1637 ((eq style 'underline)
1638 (setq extra " style=\"text-decoration:underline;\"" ))
1639 ((setq how (cdr (assoc style
1640 '((bold . ("<b>" . "</b>"))
1641 (emphasis . ("<i>" . "</i>"))
1642 (code . ("<code>" . "</code>"))
1643 (verbatim . ("<code>" . "</code>"))
1644 (strike . ("<del>" . "</del>"))
1645 (subscript . ("<sub>" . "</sub>"))
1646 (superscript . ("<sup>" . "</sup>")))))))
1647 ((listp style)
1648 (setq class (mapconcat 'identity style " ")))
1649 ((stringp style)
1650 (setq class style))
1651 (t (error "Unknown style %S" style)))
1653 (setq extra (concat (when class (format " class=\"%s\"" class))
1654 (when id (format " id=\"%s\"" id))
1655 extra))
1656 (org-xhtml-format-tags
1657 (or how '("<span%s>" . "</span>")) text extra)))
1659 (defun org-xhtml-format-link (text href &optional extra)
1660 (let ((extra (concat (format " href=\"%s\"" href)
1661 (and extra (concat " " extra)))))
1662 (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
1664 (defun org-xhtml-format-heading (text level &optional id)
1665 (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1666 (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
1668 (defun org-xhtml-format-headline (title extra-targets tags
1669 &optional snumber level)
1670 (concat
1671 (org-lparse-format 'EXTRA-TARGETS extra-targets)
1672 (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
1673 title
1674 (and tags (concat (org-lparse-format 'SPACES 3)
1675 (org-lparse-format 'ORG-TAGS tags)))))
1677 (defun org-xhtml-format-anchor (text name &optional class)
1678 (let* ((id name)
1679 (extra (concat
1680 (when name (format " name=\"%s\"" name))
1681 (when id (format " id=\"%s\"" id))
1682 (when class (format " class=\"%s\"" class)))))
1683 (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
1685 (defun org-xhtml-format-footnote-reference (n def refcnt)
1686 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1687 (format org-export-xhtml-footnote-format
1688 (format
1689 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1690 n extra n n))))
1692 (defun org-xhtml-format-footnotes-section (section-name definitions)
1693 (if (not definitions) ""
1694 (format org-export-xhtml-footnotes-section section-name definitions)))
1696 (defun org-xhtml-format-org-entity (wd)
1697 (org-entity-get-representation wd 'html))
1699 (defun org-xhtml-format-tags (tag text &rest args)
1700 (let ((prefix (when org-lparse-encode-pending "@"))
1701 (suffix (when org-lparse-encode-pending "@")))
1702 (apply 'org-lparse-format-tags tag text prefix suffix args)))
1704 (defun org-xhtml-get (what &optional opt-plist)
1705 (case what
1706 (BACKEND 'html)
1707 (INIT-METHOD nil)
1708 (SAVE-METHOD nil)
1709 (CLEANUP-METHOD nil)
1710 ;; (OTHER-BACKENDS
1711 ;; ;; There is a provision to register a per-backend converter and
1712 ;; ;; output formats. Refer `org-lparse-get-converter' and
1713 ;; ;; `org-lparse-get-other-backends'.
1715 ;; ;; The default behaviour is to use `org-lparse-convert-process'
1716 ;; ;; and `org-lparse-convert-capabilities'.
1717 ;; )
1718 ;; (CONVERT-METHOD
1719 ;; ;; See note above
1720 ;; )
1721 (EXPORT-DIR (org-export-directory :html opt-plist))
1722 (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
1723 (EXPORT-BUFFER-NAME "*Org HTML Export*")
1724 (ENTITY-CONTROL org-xhtml-entity-control-callbacks-alist)
1725 (ENTITY-FORMAT org-xhtml-entity-format-callbacks-alist)
1726 (TOPLEVEL-HLEVEL org-export-xhtml-toplevel-hlevel)
1727 (SPECIAL-STRING-REGEXPS org-export-xhtml-special-string-regexps)
1728 (CODING-SYSTEM-FOR-WRITE org-export-xhtml-coding-system)
1729 (CODING-SYSTEM-FOR-SAVE org-export-xhtml-coding-system)
1730 (INLINE-IMAGES org-export-xhtml-inline-images)
1731 (INLINE-IMAGE-EXTENSIONS org-export-xhtml-inline-image-extensions)
1732 (PLAIN-TEXT-MAP org-export-xhtml-protect-char-alist)
1733 (TABLE-FIRST-COLUMN-AS-LABELS
1734 org-export-xhtml-table-use-header-tags-for-first-column)
1735 (TODO-KWD-CLASS-PREFIX org-export-xhtml-todo-kwd-class-prefix)
1736 (TAG-CLASS-PREFIX org-export-xhtml-tag-class-prefix)
1737 (FOOTNOTE-SEPARATOR org-export-xhtml-footnote-separator)
1738 (t (error "Unknown property: %s" what))))
1740 (defun org-xhtml-get-coding-system-for-write ()
1741 (or org-export-xhtml-coding-system
1742 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1744 (defun org-xhtml-get-coding-system-for-save ()
1745 (or org-export-xhtml-coding-system
1746 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1748 (defun org-xhtml-insert-toc (toc)
1749 ;; locate where toc needs to be inserted
1750 (goto-char (point-min))
1751 (cond
1752 ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1753 (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t))
1754 (goto-char (match-beginning 0))
1755 (replace-match "")
1756 (insert toc))
1757 (org-lparse-dyn-first-heading-pos
1758 (goto-char org-lparse-dyn-first-heading-pos)
1759 (when (looking-at "\\s-*</p>")
1760 (goto-char (match-end 0))
1761 (insert "\n"))
1762 (insert toc))
1763 (t (ignore))))
1765 (defun org-xhtml-insert-preamble (opt-plist)
1766 (when (plist-get opt-plist :html-preamble)
1767 (let ((html-pre (plist-get opt-plist :html-preamble))
1768 (title (plist-get opt-plist :title))
1769 (date (plist-get opt-plist :effective-date))
1770 (author (plist-get opt-plist :author))
1771 (lang-words (plist-get opt-plist :lang-words))
1772 (email (plist-get opt-plist :email))
1773 html-pre-real-contents)
1774 (cond ((stringp html-pre)
1775 (setq html-pre-real-contents
1776 (format-spec html-pre `((?t . ,title) (?a . ,author)
1777 (?d . ,date) (?e . ,email)))))
1778 ((functionp html-pre)
1779 (insert "<div id=\"" (nth 0 org-export-xhtml-divs) "\">\n")
1780 (funcall html-pre)
1781 (insert "\n</div>\n"))
1783 (setq html-pre-real-contents
1784 (format-spec
1785 (or (cadr (assoc (nth 0 lang-words)
1786 org-export-xhtml-preamble-format))
1787 (cadr (assoc "en" org-export-xhtml-preamble-format)))
1788 `((?t . ,title) (?a . ,author)
1789 (?d . ,date) (?e . ,email))))))
1791 ;; don't output an empty preamble DIV
1792 (unless (and (functionp html-pre)
1793 (equal html-pre-real-contents ""))
1794 (insert "<div id=\"" (nth 0 org-export-xhtml-divs) "\">\n")
1795 (insert html-pre-real-contents)
1796 (insert "\n</div>\n")))))
1798 (defun org-xhtml-insert-postamble (opt-plist)
1799 (when org-lparse-footnote-definitions
1800 (insert
1801 (org-lparse-format
1802 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
1803 (mapconcat (lambda (x) (cdr x))
1804 (nreverse org-lparse-footnote-definitions) "\n"))))
1805 (let ((bib (org-export-xhtml-get-bibliography)))
1806 (when bib
1807 (insert "\n" bib "\n")))
1809 (unless body-only
1810 (org-lparse-insert-tag "</div>"))
1812 ;; export html postamble
1813 (unless body-only
1814 (let* ((html-post (plist-get opt-plist :html-postamble))
1815 (date (plist-get opt-plist :effective-date))
1816 (author (plist-get opt-plist :author))
1817 (email (plist-get opt-plist :email))
1818 (lang-words (plist-get opt-plist :lang-words))
1819 (html-validation-link (or org-export-xhtml-validation-link ""))
1820 (email
1821 (mapconcat (lambda(e)
1822 (format "<a href=\"mailto:%s\">%s</a>" e e))
1823 (split-string email ",+ *")
1824 ", "))
1825 (creator-info
1826 (concat "Org version " org-version " with Emacs version "
1827 (number-to-string emacs-major-version))))
1828 (when (plist-get opt-plist :html-postamble)
1829 (insert "\n<div id=\"" (nth 2 org-export-xhtml-divs) "\">\n")
1830 (cond ((stringp html-post)
1831 (insert (format-spec html-post
1832 `((?a . ,author) (?e . ,email)
1833 (?d . ,date) (?c . ,creator-info)
1834 (?v . ,html-validation-link)))))
1835 ((functionp html-post)
1836 (funcall html-post))
1837 ((eq html-post 'auto)
1838 ;; fall back on default postamble
1839 (when (plist-get opt-plist :time-stamp-file)
1840 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
1841 (when (and (plist-get opt-plist :author-info) author)
1842 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1843 (when (and (plist-get opt-plist :email-info) email)
1844 (insert "<p class=\"email\">" email "</p>\n"))
1845 (when (plist-get opt-plist :creator-info)
1846 (insert "<p class=\"creator\">"
1847 (concat "Org version " org-version " with Emacs version "
1848 (number-to-string emacs-major-version) "</p>\n")))
1849 (insert html-validation-link "\n"))
1851 (insert (format-spec
1852 (or (cadr (assoc (nth 0 lang-words)
1853 org-export-xhtml-postamble-format))
1854 (cadr (assoc "en" org-export-xhtml-postamble-format)))
1855 `((?a . ,author) (?e . ,email)
1856 (?d . ,date) (?c . ,creator-info)
1857 (?v . ,html-validation-link))))))
1858 (insert "</div>"))))
1860 ;; FIXME `org-export-xhtml-with-timestamp' has been declared
1861 ;; obsolete since Org 7.7 -- don't forget to remove this.
1862 (when org-export-xhtml-with-timestamp
1863 (insert org-export-xhtml-html-helper-timestamp)))
1865 ;; There are references to org-html-expand, org-html-protect and
1866 ;; org-html-do-expand outside of org-html.el. For now provide a
1867 ;; migration path. Ultimately these functions have to be removed.
1869 ;; (defun org-html-expand (string)
1870 ;; "A simple wrapper around `org-xml-encode-org-text-skip-links'."
1871 ;; (org-xml-encode-org-text-skip-links string))
1873 ;; (defun org-html-protect (s)
1874 ;; "A simple wrapper around `org-xml-encode-plain-text'."
1875 ;; (org-xml-encode-plain-text s))
1877 ;; (defun org-html-do-expand (s)
1878 ;; "A simple wrapper around `org-xml-encode-org-text'."
1879 ;; (org-xml-encode-org-text s))
1881 ;; (defun org-export-xhtml-format-href (s)
1882 ;; "A simple wrapper around `org-xml-format-href'."
1883 ;; (org-xml-format-href s))
1885 ;; (defun org-export-xhtml-format-desc (s)
1886 ;; "A simple wrapper around `org-xml-format-desc'."
1887 ;; (org-xml-format-desc s))
1889 (provide 'org-xhtml)
1891 ;;; org-xhtml.el ends here