org-lparse.el & co: Bring over few commits (contd.)
[org-mode.git] / contrib / lisp / org-xhtml.el
blob84f94b71ae0e461001f5ca1ec965a58bf0132000
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 ;;
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
386 '(("en" "<h1 class=\"title\">%t</h1>"))
387 "The format for the HTML preamble.
389 %t stands for the title.
391 If you need to use a \"%\" character, you need to escape it
392 like that: \"%%\"."
393 :group 'org-export-xhtml
394 :type 'string)
396 (defcustom org-export-xhtml-postamble 'auto
397 "Non-nil means insert a postamble in HTML export.
399 When `t', insert a string as defined by the formatting string in
400 `org-export-xhtml-postamble-format'. When set to a string, this
401 string overrides `org-export-xhtml-postamble-format'. When set to
402 'auto, discard `org-export-xhtml-postamble-format' and honor
403 `org-export-author/email/creator-info' variables. When set to a
404 function, apply this function and insert the returned string.
405 The function takes the property list of export options as its
406 only argument.
408 Setting :html-postamble in publishing projects will take
409 precedence over this variable."
410 :group 'org-export-xhtml
411 :type '(choice (const :tag "No postamble" nil)
412 (const :tag "Auto preamble" 'auto)
413 (const :tag "Default formatting string" t)
414 (string :tag "Custom formatting string")
415 (function :tag "Function (must return a string)")))
417 (defcustom org-export-xhtml-postamble-format
418 '(("en" "<p class=\"author\">Author: %a (%e)</p>
419 <p class=\"date\">Date: %d</p>
420 <p class=\"creator\">Generated by %c</p>
421 <p class=\"xhtml-validation\">%v</p>
423 "The format for the HTML postamble.
425 %a stands for the author.
426 %e stands for the email(s).
427 %d stands for the date.
428 %c will be replaced by information about Org/Emacs.
429 %v will be replaced by `org-export-xhtml-validation-link'.
431 If you need to use a \"%\" character, you need to escape it
432 like that: \"%%\"."
433 :group 'org-export-xhtml
434 :type 'string)
436 (defcustom org-export-xhtml-home/up-format
437 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
438 <a accesskey=\"h\" href=\"%s\"> UP </a>
440 <a accesskey=\"H\" href=\"%s\"> HOME </a>
441 </div>"
442 "Snippet used to insert the HOME and UP links.
443 This is a format string, the first %s will receive the UP link,
444 the second the HOME link. If both `org-export-xhtml-link-up' and
445 `org-export-xhtml-link-home' are empty, the entire snippet will be
446 ignored."
447 :group 'org-export-xhtml
448 :type 'string)
450 (defcustom org-export-xhtml-toplevel-hlevel 2
451 "The <H> level for level 1 headings in HTML export.
452 This is also important for the classes that will be wrapped around headlines
453 and outline structure. If this variable is 1, the top-level headlines will
454 be <h1>, and the corresponding classes will be outline-1, section-number-1,
455 and outline-text-1. If this is 2, all of these will get a 2 instead.
456 The default for this variable is 2, because we use <h1> for formatting the
457 document title."
458 :group 'org-export-xhtml
459 :type 'string)
461 (defcustom org-export-xhtml-link-org-files-as-html t
462 "Non-nil means make file links to `file.org' point to `file.html'.
463 When org-mode is exporting an org-mode file to HTML, links to
464 non-html files are directly put into a href tag in HTML.
465 However, links to other Org-mode files (recognized by the
466 extension `.org.) should become links to the corresponding html
467 file, assuming that the linked org-mode file will also be
468 converted to HTML.
469 When nil, the links still point to the plain `.org' file."
470 :group 'org-export-xhtml
471 :type 'boolean)
473 (defcustom org-export-xhtml-inline-images 'maybe
474 "Non-nil means inline images into exported HTML pages.
475 This is done using an <img> tag. When nil, an anchor with href is used to
476 link to the image. If this option is `maybe', then images in links with
477 an empty description will be inlined, while images with a description will
478 be linked only."
479 :group 'org-export-xhtml
480 :type '(choice (const :tag "Never" nil)
481 (const :tag "Always" t)
482 (const :tag "When there is no description" maybe)))
484 (defcustom org-export-xhtml-inline-image-extensions
485 '("png" "jpeg" "jpg" "gif" "svg")
486 "Extensions of image files that can be inlined into HTML."
487 :group 'org-export-xhtml
488 :type '(repeat (string :tag "Extension")))
490 (defcustom org-export-xhtml-table-tag
491 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
492 "The HTML tag that is used to start a table.
493 This must be a <table> tag, but you may change the options like
494 borders and spacing."
495 :group 'org-export-xhtml
496 :type 'string)
498 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
499 "The opening tag for table header fields.
500 This is customizable so that alignment options can be specified.
501 The first %s will be filled with the scope of the field, either row or col.
502 The second %s will be replaced by a style entry to align the field.
503 See also the variable `org-export-xhtml-table-use-header-tags-for-first-column'.
504 See also the variable `org-export-xhtml-table-align-individual-fields'."
505 :group 'org-export-tables
506 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
508 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
509 "The opening tag for table data fields.
510 This is customizable so that alignment options can be specified.
511 The first %s will be filled with the scope of the field, either row or col.
512 The second %s will be replaced by a style entry to align the field.
513 See also the variable `org-export-xhtml-table-align-individual-fields'."
514 :group 'org-export-tables
515 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
517 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
518 "The opening tag for table data fields.
519 This is customizable so that alignment options can be specified.
520 Instead of strings, these can be Lisp forms that will be evaluated
521 for each row in order to construct the table row tags. During evaluation,
522 the variable `head' will be true when this is a header line, nil when this
523 is a body line. And the variable `nline' will contain the line number,
524 starting from 1 in the first header line. For example
526 (setq org-export-table-row-tags
527 (cons '(if head
528 \"<tr>\"
529 (if (= (mod nline 2) 1)
530 \"<tr class=\\\"tr-odd\\\">\"
531 \"<tr class=\\\"tr-even\\\">\"))
532 \"</tr>\"))
534 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
535 :group 'org-export-tables
536 :type '(cons
537 (choice :tag "Opening tag"
538 (string :tag "Specify")
539 (sexp))
540 (choice :tag "Closing tag"
541 (string :tag "Specify")
542 (sexp))))
544 (defcustom org-export-xhtml-table-align-individual-fields t
545 "Non-nil means attach style attributes for alignment to each table field.
546 When nil, alignment will only be specified in the column tags, but this
547 is ignored by some browsers (like Firefox, Safari). Opera does it right
548 though."
549 :group 'org-export-tables
550 :type 'boolean)
552 (defcustom org-export-xhtml-table-use-header-tags-for-first-column nil
553 "Non-nil means format column one in tables with header tags.
554 When nil, also column one will use data tags."
555 :group 'org-export-tables
556 :type 'boolean)
558 (defcustom org-export-xhtml-validation-link
559 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
560 "Link to HTML validation service."
561 :group 'org-export-xhtml
562 :type 'string)
564 (defcustom org-export-xhtml-with-timestamp nil
565 "If non-nil, write timestamp into the exported HTML text.
566 If non-nil, write `org-export-xhtml-html-helper-timestamp' into the
567 exported HTML text. Otherwise, the buffer will just be saved to
568 a file."
569 :group 'org-export-xhtml
570 :type 'boolean)
572 (defcustom org-export-xhtml-html-helper-timestamp
573 "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
574 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
575 :group 'org-export-xhtml
576 :type 'string)
578 (defcustom org-export-xhtml-protect-char-alist
579 '(("&" . "&amp;")
580 ("<" . "&lt;")
581 (">" . "&gt;"))
582 "Alist of characters to be converted by `org-html-protect'."
583 :group 'org-export-xhtml
584 :type '(repeat (cons (string :tag "Character")
585 (string :tag "HTML equivalent"))))
587 (defgroup org-export-xhtmlize nil
588 "Options for processing examples with htmlize.el."
589 :tag "Org Export Htmlize"
590 :group 'org-export-xhtml)
592 (defcustom org-export-xhtmlize-output-type 'inline-css
593 "Output type to be used by htmlize when formatting code snippets.
594 Choices are `css', to export the CSS selectors only, or `inline-css', to
595 export the CSS attribute values inline in the HTML. We use as default
596 `inline-css', in order to make the resulting HTML self-containing.
598 However, this will fail when using Emacs in batch mode for export, because
599 then no rich font definitions are in place. It will also not be good if
600 people with different Emacs setup contribute HTML files to a website,
601 because the fonts will represent the individual setups. In these cases,
602 it is much better to let Org/Htmlize assign classes only, and to use
603 a style file to define the look of these classes.
604 To get a start for your css file, start Emacs session and make sure that
605 all the faces you are interested in are defined, for example by loading files
606 in all modes you want. Then, use the command
607 \\[org-export-xhtmlize-generate-css] to extract class definitions."
608 :group 'org-export-xhtmlize
609 :type '(choice (const css) (const inline-css)))
611 (defcustom org-export-xhtmlize-css-font-prefix "org-"
612 "The prefix for CSS class names for htmlize font specifications."
613 :group 'org-export-xhtmlize
614 :type 'string)
616 (defcustom org-export-xhtmlized-org-css-url nil
617 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
618 Normally when creating an htmlized version of an Org buffer, htmlize will
619 create CSS to define the font colors. However, this does not work when
620 converting in batch mode, and it also can look bad if different people
621 with different fontification setup work on the same website.
622 When this variable is non-nil, creating an htmlized version of an Org buffer
623 using `org-export-as-org' will remove the internal CSS section and replace it
624 with a link to this URL."
625 :group 'org-export-xhtmlize
626 :type '(choice
627 (const :tag "Keep internal css" nil)
628 (string :tag "URL or local href")))
630 ;;; Hooks
632 (defvar org-export-xhtml-after-blockquotes-hook nil
633 "Hook run during HTML export, after blockquote, verse, center are done.")
635 (defvar org-export-xhtml-final-hook nil
636 "Hook run at the end of HTML export, in the new buffer.")
638 (defun org-export-xhtml-preprocess-latex-fragments ()
639 (when (equal org-lparse-backend 'xhtml)
640 (org-export-xhtml-do-preprocess-latex-fragments)))
642 (defvar org-lparse-opt-plist) ; bound during org-do-lparse
643 (defun org-export-xhtml-do-preprocess-latex-fragments ()
644 "Convert LaTeX fragments to images."
645 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist :LaTeX-fragments))
646 (latex-frag-opt-1 ; massage the options
647 (cond
648 ((eq latex-frag-opt 'verbatim) 'verbatim)
649 ((eq latex-frag-opt 'mathjax ) 'mathjax)
650 ((eq latex-frag-opt t ) 'mathjax)
651 ((eq latex-frag-opt 'dvipng ) 'dvipng)
652 (t nil))))
653 (when (and org-current-export-file latex-frag-opt)
654 (org-format-latex
655 (concat "ltxpng/" (file-name-sans-extension
656 (file-name-nondirectory
657 org-current-export-file)))
658 org-current-export-dir nil "Creating LaTeX image %s"
659 nil nil latex-frag-opt-1))))
661 (defun org-export-xhtml-preprocess-label-references ()
662 (goto-char (point-min))
663 (let (label l1)
664 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
665 (org-if-unprotected-at (match-beginning 1)
666 (setq label (match-string 1))
667 (save-match-data
668 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
669 (setq l1 (substring label (match-beginning 1)))
670 (setq l1 label)))
671 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
673 (defun org-export-xhtml-preprocess (parameters)
674 (org-export-xhtml-preprocess-label-references))
676 ;; Process latex fragments as part of
677 ;; `org-export-preprocess-after-blockquote-hook'. Note that this hook
678 ;; is the one that is closest and well before the call to
679 ;; `org-export-attach-captions-and-attributes' in
680 ;; `org-export-preprocess-stirng'. The above arrangement permits
681 ;; captions, labels and attributes to be attached to png images
682 ;; generated out of latex equations.
683 (add-hook 'org-export-preprocess-after-blockquote-hook
684 'org-export-xhtml-preprocess-latex-fragments)
686 (defvar html-table-tag nil) ; dynamically scoped into this.
689 ;; FIXME: it already exists in org-html.el
690 (defconst org-html-cvt-link-fn
692 "Function to convert link URLs to exportable URLs.
693 Takes two arguments, TYPE and PATH.
694 Returns exportable url as (TYPE PATH), or nil to signal that it
695 didn't handle this case.
696 Intended to be locally bound around a call to `org-export-as-html'." )
699 ;; FIXME: it already exists in org-html.el
700 (defun org-html-cvt-org-as-html (opt-plist type path)
701 "Convert an org filename to an equivalent html filename.
702 If TYPE is not file, just return `nil'.
703 See variable `org-export-xhtml-link-org-files-as-html'"
705 (save-match-data
706 (and
707 org-export-xhtml-link-org-files-as-html
708 (string= type "file")
709 (string-match "\\.org$" path)
710 (progn
711 (list
712 "file"
713 (concat
714 (substring path 0 (match-beginning 0))
716 (plist-get opt-plist :html-extension)))))))
718 (defun org-xhtml-format-org-link (opt-plist type-1 path fragment desc attr
719 descp)
720 "Make an HTML link.
721 OPT-PLIST is an options list.
722 TYPE is the device-type of the link (THIS://foo.html).
723 PATH is the path of the link (http://THIS#location).
724 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
725 DESC is the link description, if any.
726 ATTR is a string of other attributes of the \"a\" element."
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\" lang=\"%s\" xml:lang=\"%s\">
1278 <head>
1279 <title>%s</title>
1280 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1281 <meta name=\"title\" content=\"%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 :title)
1304 (plist-get opt-plist :effective-date)
1305 (plist-get opt-plist :author)
1306 (plist-get opt-plist :description)
1307 (plist-get opt-plist :keywords)
1308 style
1309 mathjax))))
1311 (defun org-xhtml-end-document-content ()
1312 (insert "\n</html>\n"))
1314 (defun org-xhtml-begin-outline (level1 snumber title tags
1315 target extra-targets extra-class)
1316 (let* ((class (format "outline-%d" level1))
1317 (class (if extra-class (concat class " " extra-class) class))
1318 (id (format "outline-container-%s"
1319 (org-lparse-suffix-from-snumber snumber)))
1320 (extra (concat (when id (format " id=\"%s\"" id))
1321 (when class (format " class=\"%s\"" class)))))
1322 (org-lparse-insert-tag "<div%s>" extra)
1323 (insert
1324 (org-lparse-format 'HEADING
1325 (org-lparse-format
1326 'HEADLINE title extra-targets tags snumber level1)
1327 level1 target))))
1329 (defun org-xhtml-end-outline ()
1330 (org-lparse-insert-tag "</div>"))
1332 (defun org-xhtml-begin-outline-text (level1 snumber extra-class)
1333 (let* ((class (format "outline-text-%d" level1))
1334 (class (if extra-class (concat class " " extra-class) class))
1335 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
1336 (extra (concat (when id (format " id=\"%s\"" id))
1337 (when class (format " class=\"%s\"" class)))))
1338 (org-lparse-insert-tag "<div%s>" extra)))
1340 (defun org-xhtml-end-outline-text ()
1341 (org-lparse-insert-tag "</div>"))
1343 (defun org-xhtml-begin-paragraph (&optional style)
1344 (let* ((class (cdr (assoc style '((footnote . "footnote")
1345 (verse . nil)))))
1346 (extra (if class (format " class=\"%s\"" class) "")))
1347 (org-lparse-insert-tag "<p%s>" extra)))
1349 (defun org-xhtml-end-paragraph ()
1350 (insert "</p>"))
1352 (defun org-xhtml-format-environment (style beg-end)
1353 (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
1354 (case style
1355 (blockquote
1356 (case beg-end
1357 (BEGIN
1358 (org-lparse-end-paragraph)
1359 (insert "<blockquote>\n")
1360 (org-lparse-begin-paragraph))
1361 (END
1362 (org-lparse-end-paragraph)
1363 (insert "\n</blockquote>\n")
1364 (org-lparse-begin-paragraph))))
1365 (verse
1366 (case beg-end
1367 (BEGIN
1368 (org-lparse-end-paragraph)
1369 (insert "\n<p class=\"verse\">\n")
1370 (setq org-lparse-par-open t))
1371 (END
1372 (insert "</p>\n")
1373 (setq org-lparse-par-open nil)
1374 (org-lparse-begin-paragraph))))
1375 (center
1376 (case beg-end
1377 (BEGIN
1378 (org-lparse-end-paragraph)
1379 (insert "\n<div style=\"text-align: center\">")
1380 (org-lparse-begin-paragraph))
1381 (END
1382 (org-lparse-end-paragraph)
1383 (insert "\n</div>")
1384 (org-lparse-begin-paragraph))))
1385 (fixedwidth
1386 (case beg-end
1387 (BEGIN
1388 (org-lparse-end-paragraph)
1389 (insert "<pre class=\"example\">\n"))
1390 (END
1391 (insert "</pre>\n")
1392 (org-lparse-begin-paragraph))))
1393 (quote
1394 (case beg-end
1395 (BEGIN
1396 (org-lparse-end-paragraph)
1397 (insert "<pre>"))
1398 (END
1399 (insert "</pre>\n")
1400 (org-lparse-begin-paragraph))))
1401 (native
1402 (case beg-end
1403 (BEGIN (org-lparse-end-paragraph))
1404 (END (org-lparse-begin-paragraph))))
1405 (t (error "Unknown environment %s" style))))
1407 (defun org-xhtml-begin-environment (style env-options-plist)
1408 (org-xhtml-format-environment style 'BEGIN))
1410 (defun org-xhtml-end-environment (style env-options-plist)
1411 (org-xhtml-format-environment style 'END))
1413 (defun org-xhtml-begin-list (ltype)
1414 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1415 ltype))
1416 (case ltype
1417 (ordered (let* ((arg1 nil)
1418 (extra (if arg1 (format " start=\"%d\"" arg1) "")))
1419 (org-lparse-insert-tag "<ol%s>" extra)))
1420 (unordered (org-lparse-insert-tag "<ul>"))
1421 (description (org-lparse-insert-tag "<dl>"))
1422 (t (error "Unknown list type: %s" ltype))))
1424 (defun org-xhtml-end-list (ltype)
1425 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1426 ltype))
1428 (org-lparse-insert-tag
1429 (case ltype
1430 (ordered "</ol>")
1431 (unordered "</ul>")
1432 (description "</dl>")
1433 (t (error "Unknown list type: %s" ltype)))))
1435 (defun org-xhtml-begin-list-item (ltype &optional arg headline)
1436 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1437 ltype))
1438 (case ltype
1439 (ordered
1440 (assert (not headline) t)
1441 (let* ((counter arg)
1442 (extra (if counter (format " value=\"%s\"" counter) "")))
1443 (org-lparse-insert-tag "<li%s>" extra)))
1444 (unordered
1445 (let* ((id arg)
1446 (extra (if id (format " id=\"%s\"" id) "")))
1447 (org-lparse-insert-tag "<li%s>" extra)
1448 (when headline
1449 (insert headline (org-lparse-format 'LINE-BREAK) "\n"))))
1450 (description
1451 (assert (not headline) t)
1452 (let* ((desc-tag (or arg "(no term)")))
1453 (insert
1454 (org-xhtml-format-tags '("<dt>" . "</dt>") desc-tag))
1455 (org-lparse-insert-tag "<dd>")))
1456 (t (error "Unknown list type"))))
1458 (defun org-xhtml-end-list-item (ltype)
1459 (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
1460 ltype))
1461 (case ltype
1462 (ordered (org-lparse-insert-tag "</li>"))
1463 (unordered (org-lparse-insert-tag "</li>"))
1464 (description (org-lparse-insert-tag "</dd>"))
1465 (t (error "Unknown list type"))))
1467 ;; Following variables are let bound when table emission is in
1468 ;; progress. See org-lparse.el.
1470 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1471 (defvar org-lparse-table-begin-marker)
1472 (defvar org-lparse-table-ncols)
1473 (defvar org-lparse-table-rowgrp-open)
1474 (defvar org-lparse-table-rownum)
1475 (defvar org-lparse-table-cur-rowgrp-is-hdr)
1476 (defvar org-lparse-table-is-styled)
1477 (defvar org-lparse-table-rowgrp-info)
1478 (defvar org-lparse-table-colalign-vector)
1479 (defvar org-lparse-table-num-numeric-items-per-column)
1481 (defun org-xhtml-begin-table-rowgroup (&optional is-header-row)
1482 (when org-lparse-table-rowgrp-open
1483 (org-lparse-end 'TABLE-ROWGROUP))
1484 (org-lparse-insert-tag (if is-header-row "<thead>" "<tbody>"))
1485 (setq org-lparse-table-rowgrp-open t)
1486 (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row))
1488 (defun org-xhtml-end-table-rowgroup ()
1489 (when org-lparse-table-rowgrp-open
1490 (setq org-lparse-table-rowgrp-open nil)
1491 (org-lparse-insert-tag
1492 (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>"))))
1494 (defun org-xhtml-begin-table (caption label attributes)
1495 (let ((html-table-tag
1496 (org-export-splice-attributes html-table-tag attributes)))
1497 (when label
1498 (setq html-table-tag
1499 (org-export-splice-attributes
1500 html-table-tag
1501 (format "id=\"%s\"" (org-solidify-link-text label)))))
1502 (org-lparse-insert-tag html-table-tag))
1504 ;; Since the output of HTML table formatter can also be used in
1505 ;; DocBook document, we want to always include the caption to make
1506 ;; DocBook XML file valid.
1507 (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
1509 (defun org-xhtml-end-table ()
1510 (when org-lparse-table-is-styled
1511 (goto-char org-lparse-table-begin-marker)
1512 (setq org-lparse-table-begin-marker nil)
1514 (let ((c -1) gr colgropen)
1515 (insert
1516 (mapconcat
1517 (lambda (x)
1518 (incf c)
1519 (setq gr (pop org-table-colgroup-info))
1521 (concat
1522 (if (memq gr '(:start :startend))
1523 (prog1
1524 (if colgropen
1525 "</colgroup>\n<colgroup>"
1526 "<colgroup>")
1527 (setq colgropen t))
1530 (let* ((align (aref org-lparse-table-colalign-vector c))
1531 (alignspec (if (and (boundp 'org-xhtml-format-table-no-css)
1532 org-xhtml-format-table-no-css)
1533 " align=\"%s\"" " class=\"%s\""))
1534 (extra (format alignspec align)))
1535 (format "<col%s />" extra))
1537 (if (memq gr '(:end :startend))
1538 (progn (setq colgropen nil) "</colgroup>")
1539 "")))
1540 org-lparse-table-num-numeric-items-per-column ""))
1542 (if colgropen (insert "</colgroup>")))
1544 ;; fill style attributes for table cells
1545 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
1546 (let ((c (string-to-number (match-string 1))))
1547 (replace-match
1548 (if org-export-xhtml-table-align-individual-fields
1549 (format (if (and (boundp 'org-xhtml-format-table-no-css)
1550 org-xhtml-format-table-no-css)
1551 " align=\"%s\"" " class=\"%s\"")
1552 (or (aref org-lparse-table-colalign-vector c) "left")) "")
1553 t t)))
1554 (goto-char (point-max)))
1555 (org-lparse-insert-tag "</table>\n"))
1557 (defun org-xhtml-format-table-row (row)
1558 (org-xhtml-format-tags
1559 (cons (eval (car org-export-table-row-tags))
1560 (eval (cdr org-export-table-row-tags))) row))
1562 (defun org-xhtml-format-table-cell (text r c horiz-span)
1563 (let ((cell-style-cookie (or (and org-lparse-table-is-styled
1564 (format "@@class%03d@@" c)) "")))
1565 (cond
1566 (org-lparse-table-cur-rowgrp-is-hdr
1567 (org-xhtml-format-tags
1568 org-export-table-header-tags text "col" cell-style-cookie))
1569 ((and (= c 0) org-export-xhtml-table-use-header-tags-for-first-column)
1570 (org-xhtml-format-tags
1571 org-export-table-header-tags text "row" cell-style-cookie))
1573 (org-xhtml-format-tags
1574 org-export-table-data-tags text cell-style-cookie)))))
1576 (defun org-xhtml-begin-footnote-definition (n)
1577 (org-lparse-begin-paragraph 'footnote)
1578 (insert
1579 (format
1580 (format org-export-xhtml-footnote-format
1581 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1582 n n n)))
1584 (defun org-xhtml-end-footnote-definition (n)
1585 (org-lparse-end-paragraph))
1587 (defun org-xhtml-format-spaces (n)
1588 (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
1589 (while (> n 0)
1590 (setq out (concat out space))
1591 (setq n (1- n))) out))
1593 (defun org-xhtml-format-tabs (&optional n)
1594 (ignore))
1596 (defun org-xhtml-format-line-break ()
1597 (org-xhtml-format-tags "<br/>" ""))
1599 (defun org-xhtml-format-horizontal-line ()
1600 (concat "\n" "<hr/>" "\n"))
1602 (defun org-xhtml-format-line (line)
1603 (case org-lparse-dyn-current-environment
1604 ((quote fixedwidth) (concat (org-xml-encode-plain-text line) "\n"))
1605 (t (concat line "\n"))))
1607 (defun org-xhtml-format-comment (fmt &rest args)
1608 (let ((comment (apply 'format fmt args)))
1609 (format "\n<!-- %s -->\n" comment)))
1611 (defun org-xhtml-format-fontify (text style &optional id)
1612 (let (class extra how)
1613 (cond
1614 ((eq style 'underline)
1615 (setq extra " style=\"text-decoration:underline;\"" ))
1616 ((setq how (cdr (assoc style
1617 '((bold . ("<b>" . "</b>"))
1618 (emphasis . ("<i>" . "</i>"))
1619 (code . ("<code>" . "</code>"))
1620 (verbatim . ("<code>" . "</code>"))
1621 (strike . ("<del>" . "</del>"))
1622 (subscript . ("<sub>" . "</sub>"))
1623 (superscript . ("<sup>" . "</sup>")))))))
1624 ((listp style)
1625 (setq class (mapconcat 'identity style " ")))
1626 ((stringp style)
1627 (setq class style))
1628 (t (error "Unknown style %S" style)))
1630 (setq extra (concat (when class (format " class=\"%s\"" class))
1631 (when id (format " id=\"%s\"" id))
1632 extra))
1633 (org-xhtml-format-tags
1634 (or how '("<span%s>" . "</span>")) text extra)))
1636 (defun org-xhtml-format-link (text href &optional extra)
1637 (let ((extra (concat (format " href=\"%s\"" href)
1638 (and extra (concat " " extra)))))
1639 (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
1641 (defun org-xhtml-format-heading (text level &optional id)
1642 (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1643 (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
1645 (defun org-xhtml-format-headline (title extra-targets tags
1646 &optional snumber level)
1647 (concat
1648 (org-lparse-format 'EXTRA-TARGETS extra-targets)
1649 (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
1650 title
1651 (and tags (concat (org-lparse-format 'SPACES 3)
1652 (org-lparse-format 'ORG-TAGS tags)))))
1654 (defun org-xhtml-format-anchor (text name &optional class)
1655 (let* ((id name)
1656 (extra (concat
1657 (when name (format " name=\"%s\"" name))
1658 (when id (format " id=\"%s\"" id))
1659 (when class (format " class=\"%s\"" class)))))
1660 (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
1662 (defun org-xhtml-format-footnote-reference (n def refcnt)
1663 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1664 (format org-export-xhtml-footnote-format
1665 (format
1666 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1667 n extra n n))))
1669 (defun org-xhtml-format-footnotes-section (section-name definitions)
1670 (if (not definitions) ""
1671 (format org-export-xhtml-footnotes-section section-name definitions)))
1673 (defun org-xhtml-format-org-entity (wd)
1674 (org-entity-get-representation wd 'html))
1676 (defun org-xhtml-format-tags (tag text &rest args)
1677 (let ((prefix (when org-lparse-encode-pending "@"))
1678 (suffix (when org-lparse-encode-pending "@")))
1679 (apply 'org-lparse-format-tags tag text prefix suffix args)))
1681 (defun org-xhtml-get (what &optional opt-plist)
1682 (case what
1683 (BACKEND 'html)
1684 (INIT-METHOD nil)
1685 (SAVE-METHOD nil)
1686 (CLEANUP-METHOD nil)
1687 ;; (OTHER-BACKENDS
1688 ;; ;; There is a provision to register a per-backend converter and
1689 ;; ;; output formats. Refer `org-lparse-get-converter' and
1690 ;; ;; `org-lparse-get-other-backends'.
1692 ;; ;; The default behaviour is to use `org-lparse-convert-process'
1693 ;; ;; and `org-lparse-convert-capabilities'.
1694 ;; )
1695 ;; (CONVERT-METHOD
1696 ;; ;; See note above
1697 ;; )
1698 (EXPORT-DIR (org-export-directory :html opt-plist))
1699 (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
1700 (EXPORT-BUFFER-NAME "*Org HTML Export*")
1701 (ENTITY-CONTROL org-xhtml-entity-control-callbacks-alist)
1702 (ENTITY-FORMAT org-xhtml-entity-format-callbacks-alist)
1703 (TOPLEVEL-HLEVEL org-export-xhtml-toplevel-hlevel)
1704 (SPECIAL-STRING-REGEXPS org-export-xhtml-special-string-regexps)
1705 (CODING-SYSTEM-FOR-WRITE org-export-xhtml-coding-system)
1706 (CODING-SYSTEM-FOR-SAVE org-export-xhtml-coding-system)
1707 (INLINE-IMAGES org-export-xhtml-inline-images)
1708 (INLINE-IMAGE-EXTENSIONS org-export-xhtml-inline-image-extensions)
1709 (PLAIN-TEXT-MAP org-export-xhtml-protect-char-alist)
1710 (TABLE-FIRST-COLUMN-AS-LABELS
1711 org-export-xhtml-table-use-header-tags-for-first-column)
1712 (TODO-KWD-CLASS-PREFIX org-export-xhtml-todo-kwd-class-prefix)
1713 (TAG-CLASS-PREFIX org-export-xhtml-tag-class-prefix)
1714 (FOOTNOTE-SEPARATOR org-export-xhtml-footnote-separator)
1715 (t (error "Unknown property: %s" what))))
1717 (defun org-xhtml-get-coding-system-for-write ()
1718 (or org-export-xhtml-coding-system
1719 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1721 (defun org-xhtml-get-coding-system-for-save ()
1722 (or org-export-xhtml-coding-system
1723 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1725 (defun org-xhtml-insert-toc (toc)
1726 ;; locate where toc needs to be inserted
1727 (goto-char (point-min))
1728 (cond
1729 ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1730 (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t))
1731 (goto-char (match-beginning 0))
1732 (replace-match "")
1733 (insert toc))
1734 (org-lparse-dyn-first-heading-pos
1735 (goto-char org-lparse-dyn-first-heading-pos)
1736 (when (looking-at "\\s-*</p>")
1737 (goto-char (match-end 0))
1738 (insert "\n"))
1739 (insert toc))
1740 (t (ignore))))
1742 (defun org-xhtml-insert-preamble (opt-plist)
1743 (when (plist-get opt-plist :html-preamble)
1744 (let ((html-pre (plist-get opt-plist :html-preamble))
1745 (title (plist-get opt-plist :title))
1746 (date (plist-get opt-plist :effective-date))
1747 (author (plist-get opt-plist :author))
1748 (lang-words (plist-get opt-plist :lang-words))
1749 (email (plist-get opt-plist :email)))
1750 (cond ((stringp html-pre)
1751 (insert
1752 (format-spec html-pre `((?t . ,title) (?a . ,author)
1753 (?d . ,date) (?e . ,email)))))
1754 ((functionp html-pre)
1755 (funcall html-pre))
1757 (insert
1758 (format-spec
1759 (or (cadr (assoc (nth 0 lang-words)
1760 org-export-xhtml-preamble-format))
1761 (cadr (assoc "en" org-export-xhtml-preamble-format)))
1762 `((?t . ,title) (?a . ,author)
1763 (?d . ,date) (?e . ,email)))))))))
1765 (defun org-xhtml-insert-postamble (opt-plist)
1766 (when org-lparse-footnote-definitions
1767 (insert
1768 (org-lparse-format
1769 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
1770 (mapconcat (lambda (x) (cdr x))
1771 (nreverse org-lparse-footnote-definitions) "\n"))))
1772 (let ((bib (org-export-xhtml-get-bibliography)))
1773 (when bib
1774 (insert "\n" bib "\n")))
1776 ;; export html postamble
1777 (unless body-only
1778 (let* ((html-post (plist-get opt-plist :html-postamble))
1779 (date (plist-get opt-plist :effective-date))
1780 (author (plist-get opt-plist :author))
1781 (email (plist-get opt-plist :email))
1782 (lang-words (plist-get opt-plist :lang-words))
1783 (html-validation-link (or org-export-xhtml-validation-link ""))
1784 (email
1785 (mapconcat (lambda(e)
1786 (format "<a href=\"mailto:%s\">%s</a>" e e))
1787 (split-string email ",+ *")
1788 ", "))
1789 (creator-info
1790 (concat "Org version " org-version " with Emacs version "
1791 (number-to-string emacs-major-version))))
1792 (when (plist-get opt-plist :html-postamble)
1793 (cond ((stringp html-post)
1794 (insert "<div id=\"postamble\">\n")
1795 (insert (format-spec html-post
1796 `((?a . ,author) (?e . ,email)
1797 (?d . ,date) (?c . ,creator-info)
1798 (?v . ,html-validation-link))))
1799 (insert "</div>"))
1800 ((functionp html-post)
1801 (funcall html-post))
1802 ((eq html-post 'auto)
1803 ;; fall back on default postamble
1804 (insert "<div id=\"postamble\">\n")
1805 (when (plist-get opt-plist :time-stamp-file)
1806 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
1807 (when (and (plist-get opt-plist :author-info) author)
1808 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1809 (when (and (plist-get opt-plist :email-info) email)
1810 (insert "<p class=\"email\">" email "</p>\n"))
1811 (when (plist-get opt-plist :creator-info)
1812 (insert "<p class=\"creator\">"
1813 (concat "Org version " org-version " with Emacs version "
1814 (number-to-string emacs-major-version) "</p>\n")))
1815 (insert html-validation-link "\n</div>"))
1817 (insert "<div id=\"postamble\">\n")
1818 (insert (format-spec
1819 (or (cadr (assoc (nth 0 lang-words)
1820 org-export-xhtml-postamble-format))
1821 (cadr (assoc "en" org-export-xhtml-postamble-format)))
1822 `((?a . ,author) (?e . ,email)
1823 (?d . ,date) (?c . ,creator-info)
1824 (?v . ,html-validation-link))))
1825 (insert "</div>"))))))
1827 (if org-export-xhtml-with-timestamp
1828 (insert org-export-xhtml-html-helper-timestamp)))
1830 ;; There are references to org-html-expand, org-html-protect and
1831 ;; org-html-do-expand outside of org-html.el. For now provide a
1832 ;; migration path. Ultimately these functions have to be removed.
1834 ;; (defun org-html-expand (string)
1835 ;; "A simple wrapper around `org-xml-encode-org-text-skip-links'."
1836 ;; (org-xml-encode-org-text-skip-links string))
1838 ;; (defun org-html-protect (s)
1839 ;; "A simple wrapper around `org-xml-encode-plain-text'."
1840 ;; (org-xml-encode-plain-text s))
1842 ;; (defun org-html-do-expand (s)
1843 ;; "A simple wrapper around `org-xml-encode-org-text'."
1844 ;; (org-xml-encode-org-text s))
1846 ;; (defun org-export-xhtml-format-href (s)
1847 ;; "A simple wrapper around `org-xml-format-href'."
1848 ;; (org-xml-format-href s))
1850 ;; (defun org-export-xhtml-format-desc (s)
1851 ;; "A simple wrapper around `org-xml-format-desc'."
1852 ;; (org-xml-format-desc s))
1854 (provide 'org-xhtml)
1856 ;;; org-xhtml.el ends here