initialize Babel languages and provide possibility to load extra packages for testing
[org-mode.git] / lisp / org-html.el
blob385d8ec0e3215857718e14a1ecd163de0cf36831
1 ;;; org-html.el --- HTML export for Org-mode
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 part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;;; Code:
29 (require 'org-exp)
30 (require 'format-spec)
32 (eval-when-compile (require 'cl))
34 (declare-function org-id-find-id-file "org-id" (id))
35 (declare-function htmlize-region "ext:htmlize" (beg end))
36 (declare-function org-pop-to-buffer-same-window
37 "org-compat" (&optional buffer-or-name norecord label))
39 (defgroup org-export-html nil
40 "Options specific for HTML export of Org-mode files."
41 :tag "Org Export HTML"
42 :group 'org-export)
44 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
45 <h2 class=\"footnotes\">%s: </h2>
46 <div id=\"text-footnotes\">
48 </div>
49 </div>"
50 "Format for the footnotes section.
51 Should contain a two instances of %s. The first will be replaced with the
52 language-specific word for \"Footnotes\", the second one will be replaced
53 by the footnotes themselves."
54 :group 'org-export-html
55 :type 'string)
57 (defcustom org-export-html-footnote-format "<sup>%s</sup>"
58 "The format for the footnote reference.
59 %s will be replaced by the footnote reference itself."
60 :group 'org-export-html
61 :type 'string)
64 (defcustom org-export-html-footnote-separator "<sup>, </sup>"
65 "Text used to separate footnotes."
66 :group 'org-export-html
67 :version "24.1"
68 :type 'string)
70 (defcustom org-export-html-coding-system nil
71 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
72 :group 'org-export-html
73 :type 'coding-system)
75 (defcustom org-export-html-extension "html"
76 "The extension for exported HTML files."
77 :group 'org-export-html
78 :type 'string)
80 (defcustom org-export-html-xml-declaration
81 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
82 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
83 "The extension for exported HTML files.
84 %s will be replaced with the charset of the exported file.
85 This may be a string, or an alist with export extensions
86 and corresponding declarations."
87 :group 'org-export-html
88 :type '(choice
89 (string :tag "Single declaration")
90 (repeat :tag "Dependent on extension"
91 (cons (string :tag "Extension")
92 (string :tag "Declaration")))))
94 (defcustom org-export-html-style-include-scripts t
95 "Non-nil means include the JavaScript snippets in exported HTML files.
96 The actual script is defined in `org-export-html-scripts' and should
97 not be modified."
98 :group 'org-export-html
99 :type 'boolean)
101 (defconst org-export-html-scripts
102 "<script type=\"text/javascript\">
103 <!--/*--><![CDATA[/*><!--*/
104 function CodeHighlightOn(elem, id)
106 var target = document.getElementById(id);
107 if(null != target) {
108 elem.cacheClassElem = elem.className;
109 elem.cacheClassTarget = target.className;
110 target.className = \"code-highlighted\";
111 elem.className = \"code-highlighted\";
114 function CodeHighlightOff(elem, id)
116 var target = document.getElementById(id);
117 if(elem.cacheClassElem)
118 elem.className = elem.cacheClassElem;
119 if(elem.cacheClassTarget)
120 target.className = elem.cacheClassTarget;
122 /*]]>*///-->
123 </script>"
124 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
126 (defconst org-export-html-style-default
127 "<style type=\"text/css\">
128 <!--/*--><![CDATA[/*><!--*/
129 html { font-family: Times, serif; font-size: 12pt; }
130 .title { text-align: center; }
131 .todo { color: red; }
132 .done { color: green; }
133 .tag { background-color: #add8e6; font-weight:normal }
134 .target { }
135 .timestamp { color: #bebebe; }
136 .timestamp-kwd { color: #5f9ea0; }
137 .right {margin-left:auto; margin-right:0px; text-align:right;}
138 .left {margin-left:0px; margin-right:auto; text-align:left;}
139 .center {margin-left:auto; margin-right:auto; text-align:center;}
140 p.verse { margin-left: 3% }
141 pre {
142 border: 1pt solid #AEBDCC;
143 background-color: #F3F5F7;
144 padding: 5pt;
145 font-family: courier, monospace;
146 font-size: 90%;
147 overflow:auto;
149 table { border-collapse: collapse; }
150 td, th { vertical-align: top; }
151 th.right { text-align:center; }
152 th.left { text-align:center; }
153 th.center { text-align:center; }
154 td.right { text-align:right; }
155 td.left { text-align:left; }
156 td.center { text-align:center; }
157 dt { font-weight: bold; }
158 div.figure { padding: 0.5em; }
159 div.figure p { text-align: center; }
160 div.inlinetask {
161 padding:10px;
162 border:2px solid gray;
163 margin:10px;
164 background: #ffffcc;
166 textarea { overflow-x: auto; }
167 .linenr { font-size:smaller }
168 .code-highlighted {background-color:#ffff00;}
169 .org-info-js_info-navigation { border-style:none; }
170 #org-info-js_console-label { font-size:10px; font-weight:bold;
171 white-space:nowrap; }
172 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
173 font-weight:bold; }
174 /*]]>*/-->
175 </style>"
176 "The default style specification for exported HTML files.
177 Please use the variables `org-export-html-style' and
178 `org-export-html-style-extra' to add to this style. If you wish to not
179 have the default style included, customize the variable
180 `org-export-html-style-include-default'.")
182 (defcustom org-export-html-style-include-default t
183 "Non-nil means include the default style in exported HTML files.
184 The actual style is defined in `org-export-html-style-default' and should
185 not be modified. Use the variables `org-export-html-style' to add
186 your own style information."
187 :group 'org-export-html
188 :type 'boolean)
189 ;;;###autoload
190 (put 'org-export-html-style-include-default 'safe-local-variable 'booleanp)
192 (defcustom org-export-html-style ""
193 "Org-wide style definitions for exported HTML files.
195 This variable needs to contain the full HTML structure to provide a style,
196 including the surrounding HTML tags. If you set the value of this variable,
197 you should consider to include definitions for the following classes:
198 title, todo, done, timestamp, timestamp-kwd, tag, target.
200 For example, a valid value would be:
202 <style type=\"text/css\">
203 <![CDATA[
204 p { font-weight: normal; color: gray; }
205 h1 { color: black; }
206 .title { text-align: center; }
207 .todo, .timestamp-kwd { color: red; }
208 .done { color: green; }
210 </style>
212 If you'd like to refer to an external style file, use something like
214 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
216 As the value of this option simply gets inserted into the HTML <head> header,
217 you can \"misuse\" it to add arbitrary text to the header.
218 See also the variable `org-export-html-style-extra'."
219 :group 'org-export-html
220 :type 'string)
221 ;;;###autoload
222 (put 'org-export-html-style 'safe-local-variable 'stringp)
224 (defcustom org-export-html-style-extra ""
225 "Additional style information for HTML export.
226 The value of this variable is inserted into the HTML buffer right after
227 the value of `org-export-html-style'. Use this variable for per-file
228 settings of style information, and do not forget to surround the style
229 settings with <style>...</style> tags."
230 :group 'org-export-html
231 :type 'string)
232 ;;;###autoload
233 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
235 (defcustom org-export-html-mathjax-options
236 '((path "http://orgmode.org/mathjax/MathJax.js")
237 (scale "100")
238 (align "center")
239 (indent "2em")
240 (mathml nil))
241 "Options for MathJax setup.
243 path The path where to find MathJax
244 scale Scaling for the HTML-CSS backend, usually between 100 and 133
245 align How to align display math: left, center, or right
246 indent If align is not center, how far from the left/right side?
247 mathml Should a MathML player be used if available?
248 This is faster and reduces bandwidth use, but currently
249 sometimes has lower spacing quality. Therefore, the default is
250 nil. When browsers get better, this switch can be flipped.
252 You can also customize this for each buffer, using something like
254 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
255 :group 'org-export-html
256 :version "24.1"
257 :type '(list :greedy t
258 (list :tag "path (the path from where to load MathJax.js)"
259 (const :format " " path) (string))
260 (list :tag "scale (scaling for the displayed math)"
261 (const :format " " scale) (string))
262 (list :tag "align (alignment of displayed equations)"
263 (const :format " " align) (string))
264 (list :tag "indent (indentation with left or right alignment)"
265 (const :format " " indent) (string))
266 (list :tag "mathml (should MathML display be used is possible)"
267 (const :format " " mathml) (boolean))))
269 (defun org-export-html-mathjax-config (template options in-buffer)
270 "Insert the user setup into the matchjax template."
271 (let (name val (yes " ") (no "// ") x)
272 (mapc
273 (lambda (e)
274 (setq name (car e) val (nth 1 e))
275 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
276 (setq val (car (read-from-string
277 (substring in-buffer (match-end 0))))))
278 (if (not (stringp val)) (setq val (format "%s" val)))
279 (if (string-match (concat "%" (upcase (symbol-name name))) template)
280 (setq template (replace-match val t t template))))
281 options)
282 (setq val (nth 1 (assq 'mathml options)))
283 (if (string-match (concat "\\<mathml:") in-buffer)
284 (setq val (car (read-from-string
285 (substring in-buffer (match-end 0))))))
286 ;; Exchange prefixes depending on mathml setting
287 (if (not val) (setq x yes yes no no x))
288 ;; Replace cookies to turn on or off the config/jax lines
289 (if (string-match ":MMLYES:" template)
290 (setq template (replace-match yes t t template)))
291 (if (string-match ":MMLNO:" template)
292 (setq template (replace-match no t t template)))
293 ;; Return the modified template
294 template))
296 (defcustom org-export-html-mathjax-template
297 "<script type=\"text/javascript\" src=\"%PATH\">
298 <!--/*--><![CDATA[/*><!--*/
299 MathJax.Hub.Config({
300 // Only one of the two following lines, depending on user settings
301 // First allows browser-native MathML display, second forces HTML/CSS
302 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
303 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
304 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
305 \"TeX/noUndefined.js\"],
306 tex2jax: {
307 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
308 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
309 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
310 ignoreClass: \"tex2jax_ignore\",
311 processEscapes: false,
312 processEnvironments: true,
313 preview: \"TeX\"
315 showProcessingMessages: true,
316 displayAlign: \"%ALIGN\",
317 displayIndent: \"%INDENT\",
319 \"HTML-CSS\": {
320 scale: %SCALE,
321 availableFonts: [\"STIX\",\"TeX\"],
322 preferredFont: \"TeX\",
323 webFont: \"TeX\",
324 imageFont: \"TeX\",
325 showMathMenu: true,
327 MMLorHTML: {
328 prefer: {
329 MSIE: \"MML\",
330 Firefox: \"MML\",
331 Opera: \"HTML\",
332 other: \"HTML\"
336 /*]]>*///-->
337 </script>"
338 "The MathJax setup for XHTML files."
339 :group 'org-export-html
340 :version "24.1"
341 :type 'string)
343 (defcustom org-export-html-tag-class-prefix ""
344 "Prefix to class names for TODO keywords.
345 Each tag gets a class given by the tag itself, with this prefix.
346 The default prefix is empty because it is nice to just use the keyword
347 as a class name. But if you get into conflicts with other, existing
348 CSS classes, then this prefix can be very useful."
349 :group 'org-export-html
350 :type 'string)
352 (defcustom org-export-html-todo-kwd-class-prefix ""
353 "Prefix to class names for TODO keywords.
354 Each TODO keyword gets a class given by the keyword itself, with this prefix.
355 The default prefix is empty because it is nice to just use the keyword
356 as a class name. But if you get into conflicts with other, existing
357 CSS classes, then this prefix can be very useful."
358 :group 'org-export-html
359 :type 'string)
361 (defcustom org-export-html-headline-anchor-format "<a name=\"%s\" id=\"%s\"></a>"
362 "Format for anchors in HTML headlines.
363 It requires to %s: both will be replaced by the anchor referring
364 to the headline (e.g. \"sec-2\"). When set to `nil', don't insert
365 HTML anchors in headlines."
366 :group 'org-export-html
367 :version "24.1"
368 :type 'string)
370 (defcustom org-export-html-preamble t
371 "Non-nil means insert a preamble in HTML export.
373 When `t', insert a string as defined by one of the formatting
374 strings in `org-export-html-preamble-format'. When set to a
375 string, this string overrides `org-export-html-preamble-format'.
376 When set to a function, apply this function and insert the
377 returned string. The function takes no argument, but you can
378 use `opt-plist' to access the current export options.
380 Setting :html-preamble in publishing projects will take
381 precedence over this variable."
382 :group 'org-export-html
383 :type '(choice (const :tag "No preamble" nil)
384 (const :tag "Default preamble" t)
385 (string :tag "Custom format string")
386 (function :tag "Function (must return a string)")))
388 (defcustom org-export-html-preamble-format '(("en" ""))
389 "Alist of languages and format strings for the HTML preamble.
391 The first element of each list is the language code, as used for
392 the #+LANGUAGE keyword.
394 The second element of each list is a format string to format the
395 preamble itself. This format string can contain these elements:
397 %t stands for the title.
398 %a stands for the author's name.
399 %e stands for the author's email.
400 %d stands for the date.
402 If you need to use a \"%\" character, you need to escape it
403 like that: \"%%\"."
404 :group 'org-export-html
405 :version "24.1"
406 :type 'string)
408 (defcustom org-export-html-postamble 'auto
409 "Non-nil means insert a postamble in HTML export.
411 When `t', insert a string as defined by the formatting string in
412 `org-export-html-postamble-format'. When set to a string, this
413 string overrides `org-export-html-postamble-format'. When set to
414 'auto, discard `org-export-html-postamble-format' and honor
415 `org-export-author/email/creator-info' variables. When set to a
416 function, apply this function and insert the returned string.
417 The function takes no argument, but you can use `opt-plist' to
418 access the current export options.
420 Setting :html-postamble in publishing projects will take
421 precedence over this variable."
422 :group 'org-export-html
423 :type '(choice (const :tag "No postamble" nil)
424 (const :tag "Auto preamble" 'auto)
425 (const :tag "Default format string" t)
426 (string :tag "Custom format string")
427 (function :tag "Function (must return a string)")))
429 (defcustom org-export-html-postamble-format
430 '(("en" "<p class=\"author\">Author: %a (%e)</p>
431 <p class=\"date\">Date: %d</p>
432 <p class=\"creator\">Generated by %c</p>
433 <p class=\"xhtml-validation\">%v</p>
435 "Alist of languages and format strings for the HTML postamble.
437 The first element of each list is the language code, as used for
438 the #+LANGUAGE keyword.
440 The second element of each list is a format string to format the
441 postamble itself. This format string can contain these elements:
443 %a stands for the author's name.
444 %e stands for the author's email.
445 %d stands for the date.
446 %c will be replaced by information about Org/Emacs versions.
447 %v will be replaced by `org-export-html-validation-link'.
449 If you need to use a \"%\" character, you need to escape it
450 like that: \"%%\"."
451 :group 'org-export-html
452 :version "24.1"
453 :type 'string)
455 (defcustom org-export-html-home/up-format
456 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
457 <a accesskey=\"h\" href=\"%s\"> UP </a>
459 <a accesskey=\"H\" href=\"%s\"> HOME </a>
460 </div>"
461 "Snippet used to insert the HOME and UP links.
462 This is a format string, the first %s will receive the UP link,
463 the second the HOME link. If both `org-export-html-link-up' and
464 `org-export-html-link-home' are empty, the entire snippet will be
465 ignored."
466 :group 'org-export-html
467 :type 'string)
469 (defcustom org-export-html-toplevel-hlevel 2
470 "The <H> level for level 1 headings in HTML export.
471 This is also important for the classes that will be wrapped around headlines
472 and outline structure. If this variable is 1, the top-level headlines will
473 be <h1>, and the corresponding classes will be outline-1, section-number-1,
474 and outline-text-1. If this is 2, all of these will get a 2 instead.
475 The default for this variable is 2, because we use <h1> for formatting the
476 document title."
477 :group 'org-export-html
478 :type 'string)
480 (defcustom org-export-html-link-org-files-as-html t
481 "Non-nil means make file links to `file.org' point to `file.html'.
482 When org-mode is exporting an org-mode file to HTML, links to
483 non-html files are directly put into a href tag in HTML.
484 However, links to other Org-mode files (recognized by the
485 extension `.org.) should become links to the corresponding html
486 file, assuming that the linked org-mode file will also be
487 converted to HTML.
488 When nil, the links still point to the plain `.org' file."
489 :group 'org-export-html
490 :type 'boolean)
492 (defcustom org-export-html-inline-images 'maybe
493 "Non-nil means inline images into exported HTML pages.
494 This is done using an <img> tag. When nil, an anchor with href is used to
495 link to the image. If this option is `maybe', then images in links with
496 an empty description will be inlined, while images with a description will
497 be linked only."
498 :group 'org-export-html
499 :type '(choice (const :tag "Never" nil)
500 (const :tag "Always" t)
501 (const :tag "When there is no description" maybe)))
503 (defcustom org-export-html-inline-image-extensions
504 '("png" "jpeg" "jpg" "gif" "svg")
505 "Extensions of image files that can be inlined into HTML."
506 :group 'org-export-html
507 :type '(repeat (string :tag "Extension")))
509 (defcustom org-export-html-table-tag
510 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
511 "The HTML tag that is used to start a table.
512 This must be a <table> tag, but you may change the options like
513 borders and spacing."
514 :group 'org-export-html
515 :type 'string)
517 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
518 "The opening tag for table header fields.
519 This is customizable so that alignment options can be specified.
520 The first %s will be filled with the scope of the field, either row or col.
521 The second %s will be replaced by a style entry to align the field.
522 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
523 See also the variable `org-export-html-table-align-individual-fields'."
524 :group 'org-export-tables
525 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
527 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
528 "The opening tag for table data fields.
529 This is customizable so that alignment options can be specified.
530 The first %s will be filled with the scope of the field, either row or col.
531 The second %s will be replaced by a style entry to align the field.
532 See also the variable `org-export-html-table-align-individual-fields'."
533 :group 'org-export-tables
534 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
536 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
537 "The opening tag for table data fields.
538 This is customizable so that alignment options can be specified.
539 Instead of strings, these can be Lisp forms that will be evaluated
540 for each row in order to construct the table row tags. During evaluation,
541 the variable `head' will be true when this is a header line, nil when this
542 is a body line. And the variable `nline' will contain the line number,
543 starting from 1 in the first header line. For example
545 (setq org-export-table-row-tags
546 (cons '(if head
547 \"<tr>\"
548 (if (= (mod nline 2) 1)
549 \"<tr class=\\\"tr-odd\\\">\"
550 \"<tr class=\\\"tr-even\\\">\"))
551 \"</tr>\"))
553 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
554 :group 'org-export-tables
555 :type '(cons
556 (choice :tag "Opening tag"
557 (string :tag "Specify")
558 (sexp))
559 (choice :tag "Closing tag"
560 (string :tag "Specify")
561 (sexp))))
563 (defcustom org-export-html-table-align-individual-fields t
564 "Non-nil means attach style attributes for alignment to each table field.
565 When nil, alignment will only be specified in the column tags, but this
566 is ignored by some browsers (like Firefox, Safari). Opera does it right
567 though."
568 :group 'org-export-tables
569 :version "24.1"
570 :type 'boolean)
572 (defcustom org-export-html-table-use-header-tags-for-first-column nil
573 "Non-nil means format column one in tables with header tags.
574 When nil, also column one will use data tags."
575 :group 'org-export-tables
576 :type 'boolean)
578 (defcustom org-export-html-validation-link
579 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
580 "Link to HTML validation service."
581 :group 'org-export-html
582 :type 'string)
584 ;; FIXME Obsolete since Org 7.7
585 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
586 (defvar org-export-html-with-timestamp nil
587 "If non-nil, write container for HTML-helper-mode timestamp.")
589 ;; FIXME Obsolete since Org 7.7
590 (defvar org-export-html-html-helper-timestamp
591 "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
592 "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
594 (defcustom org-export-html-protect-char-alist
595 '(("&" . "&amp;")
596 ("<" . "&lt;")
597 (">" . "&gt;"))
598 "Alist of characters to be converted by `org-html-protect'."
599 :group 'org-export-html
600 :version "24.1"
601 :type '(repeat (cons (string :tag "Character")
602 (string :tag "HTML equivalent"))))
604 (defgroup org-export-htmlize nil
605 "Options for processing examples with htmlize.el."
606 :tag "Org Export Htmlize"
607 :group 'org-export-html)
609 (defcustom org-export-htmlize-output-type 'inline-css
610 "Output type to be used by htmlize when formatting code snippets.
611 Choices are `css', to export the CSS selectors only, or `inline-css', to
612 export the CSS attribute values inline in the HTML. We use as default
613 `inline-css', in order to make the resulting HTML self-containing.
615 However, this will fail when using Emacs in batch mode for export, because
616 then no rich font definitions are in place. It will also not be good if
617 people with different Emacs setup contribute HTML files to a website,
618 because the fonts will represent the individual setups. In these cases,
619 it is much better to let Org/Htmlize assign classes only, and to use
620 a style file to define the look of these classes.
621 To get a start for your css file, start Emacs session and make sure that
622 all the faces you are interested in are defined, for example by loading files
623 in all modes you want. Then, use the command
624 \\[org-export-htmlize-generate-css] to extract class definitions."
625 :group 'org-export-htmlize
626 :type '(choice (const css) (const inline-css)))
628 (defcustom org-export-htmlize-css-font-prefix "org-"
629 "The prefix for CSS class names for htmlize font specifications."
630 :group 'org-export-htmlize
631 :type 'string)
633 (defcustom org-export-htmlized-org-css-url nil
634 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
635 Normally when creating an htmlized version of an Org buffer, htmlize will
636 create CSS to define the font colors. However, this does not work when
637 converting in batch mode, and it also can look bad if different people
638 with different fontification setup work on the same website.
639 When this variable is non-nil, creating an htmlized version of an Org buffer
640 using `org-export-as-org' will remove the internal CSS section and replace it
641 with a link to this URL."
642 :group 'org-export-htmlize
643 :type '(choice
644 (const :tag "Keep internal css" nil)
645 (string :tag "URL or local href")))
647 ;; FIXME: The following variable is obsolete since Org 7.7 but is
648 ;; still declared and checked within code for compatibility reasons.
649 ;; Use the custom variables `org-export-html-divs' instead.
650 (defvar org-export-html-content-div "content"
651 "The name of the container DIV that holds all the page contents.
653 This variable is obsolete since Org version 7.7.
654 Please set `org-export-html-divs' instead.")
656 (defcustom org-export-html-divs '("preamble" "content" "postamble")
657 "The name of the main divs for HTML export.
658 This is a list of three strings, the first one for the preamble
659 DIV, the second one for the content DIV and the third one for the
660 postamble DIV."
661 :group 'org-export-html
662 :version "24.1"
663 :type '(list
664 (string :tag " Div for the preamble:")
665 (string :tag " Div for the content:")
666 (string :tag "Div for the postamble:")))
668 (defcustom org-export-html-date-format-string "%Y-%m-%dT%R%z"
669 "Format string to format the date and time.
671 The default is an extended format of the ISO 8601 specification."
672 :group 'org-export-html
673 :version "24.1"
674 :type 'string)
676 ;;; Hooks
678 (defvar org-export-html-after-blockquotes-hook nil
679 "Hook run during HTML export, after blockquote, verse, center are done.")
681 (defvar org-export-html-final-hook nil
682 "Hook run at the end of HTML export, in the new buffer.")
684 ;;; HTML export
686 (defun org-export-html-preprocess (parameters)
687 "Convert LaTeX fragments to images."
688 (when (and org-current-export-file
689 (plist-get parameters :LaTeX-fragments))
690 (org-format-latex
691 (concat "ltxpng/" (file-name-sans-extension
692 (file-name-nondirectory
693 org-current-export-file)))
694 org-current-export-dir nil "Creating LaTeX image %s"
695 nil nil
696 (cond
697 ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
698 ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
699 ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
700 ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
701 (t nil))))
702 (goto-char (point-min))
703 (let (label l1)
704 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
705 (org-if-unprotected-at (match-beginning 1)
706 (setq label (match-string 1))
707 (save-match-data
708 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
709 (setq l1 (substring label (match-beginning 1)))
710 (setq l1 label)))
711 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
713 ;;;###autoload
714 (defun org-export-as-html-and-open (arg)
715 "Export the outline as HTML and immediately open it with a browser.
716 If there is an active region, export only the region.
717 The prefix ARG specifies how many levels of the outline should become
718 headlines. The default is 3. Lower levels will become bulleted lists."
719 (interactive "P")
720 (org-export-as-html arg 'hidden)
721 (org-open-file buffer-file-name)
722 (when org-export-kill-product-buffer-when-displayed
723 (kill-buffer (current-buffer))))
725 ;;;###autoload
726 (defun org-export-as-html-batch ()
727 "Call the function `org-export-as-html'.
728 This function can be used in batch processing as:
729 emacs --batch
730 --load=$HOME/lib/emacs/org.el
731 --eval \"(setq org-export-headline-levels 2)\"
732 --visit=MyFile --funcall org-export-as-html-batch"
733 (org-export-as-html org-export-headline-levels 'hidden))
735 ;;;###autoload
736 (defun org-export-as-html-to-buffer (arg)
737 "Call `org-export-as-html` with output to a temporary buffer.
738 No file is created. The prefix ARG is passed through to `org-export-as-html'."
739 (interactive "P")
740 (org-export-as-html arg nil nil "*Org HTML Export*")
741 (when org-export-show-temporary-export-buffer
742 (switch-to-buffer-other-window "*Org HTML Export*")))
744 ;;;###autoload
745 (defun org-replace-region-by-html (beg end)
746 "Assume the current region has org-mode syntax, and convert it to HTML.
747 This can be used in any buffer. For example, you could write an
748 itemized list in org-mode syntax in an HTML buffer and then use this
749 command to convert it."
750 (interactive "r")
751 (let (reg html buf pop-up-frames)
752 (save-window-excursion
753 (if (eq major-mode 'org-mode)
754 (setq html (org-export-region-as-html
755 beg end t 'string))
756 (setq reg (buffer-substring beg end)
757 buf (get-buffer-create "*Org tmp*"))
758 (with-current-buffer buf
759 (erase-buffer)
760 (insert reg)
761 (org-mode)
762 (setq html (org-export-region-as-html
763 (point-min) (point-max) t 'string)))
764 (kill-buffer buf)))
765 (delete-region beg end)
766 (insert html)))
768 ;;;###autoload
769 (defun org-export-region-as-html (beg end &optional body-only buffer)
770 "Convert region from BEG to END in org-mode buffer to HTML.
771 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
772 contents, and only produce the region of converted text, useful for
773 cut-and-paste operations.
774 If BUFFER is a buffer or a string, use/create that buffer as a target
775 of the converted HTML. If BUFFER is the symbol `string', return the
776 produced HTML as a string and leave not buffer behind. For example,
777 a Lisp program could call this function in the following way:
779 (setq html (org-export-region-as-html beg end t 'string))
781 When called interactively, the output buffer is selected, and shown
782 in a window. A non-interactive call will only return the buffer."
783 (interactive "r\nP")
784 (when (org-called-interactively-p 'any)
785 (setq buffer "*Org HTML Export*"))
786 (let ((transient-mark-mode t) (zmacs-regions t)
787 ext-plist rtn)
788 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
789 (goto-char end)
790 (set-mark (point)) ;; to activate the region
791 (goto-char beg)
792 (setq rtn (org-export-as-html
793 nil nil ext-plist
794 buffer body-only))
795 (if (fboundp 'deactivate-mark) (deactivate-mark))
796 (if (and (org-called-interactively-p 'any) (bufferp rtn))
797 (switch-to-buffer-other-window rtn)
798 rtn)))
800 (defvar html-table-tag nil) ; dynamically scoped into this.
801 (defvar org-par-open nil)
803 ;;; org-html-cvt-link-fn
804 (defconst org-html-cvt-link-fn
806 "Function to convert link URLs to exportable URLs.
807 Takes two arguments, TYPE and PATH.
808 Returns exportable url as (TYPE PATH), or nil to signal that it
809 didn't handle this case.
810 Intended to be locally bound around a call to `org-export-as-html'." )
812 (defun org-html-cvt-org-as-html (opt-plist type path)
813 "Convert an org filename to an equivalent html filename.
814 If TYPE is not file, just return `nil'.
815 See variable `org-export-html-link-org-files-as-html'"
817 (save-match-data
818 (and
819 org-export-html-link-org-files-as-html
820 (string= type "file")
821 (string-match "\\.org$" path)
822 (progn
823 (list
824 "file"
825 (concat
826 (substring path 0 (match-beginning 0))
828 (plist-get opt-plist :html-extension)))))))
831 ;;; org-html-should-inline-p
832 (defun org-html-should-inline-p (filename descp)
833 "Return non-nil if link FILENAME should be inlined.
834 The decision to inline the FILENAME link is based on the current
835 settings. DESCP is the boolean of whether there was a link
836 description. See variables `org-export-html-inline-images' and
837 `org-export-html-inline-image-extensions'."
838 (declare (special
839 org-export-html-inline-images
840 org-export-html-inline-image-extensions))
841 (and (or (eq t org-export-html-inline-images)
842 (and org-export-html-inline-images (not descp)))
843 (org-file-image-p
844 filename org-export-html-inline-image-extensions)))
846 ;;; org-html-make-link
847 (defun org-html-make-link (opt-plist type path fragment desc attr
848 may-inline-p)
849 "Make an HTML link.
850 OPT-PLIST is an options list.
851 TYPE is the device-type of the link (THIS://foo.html).
852 PATH is the path of the link (http://THIS#location).
853 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
854 DESC is the link description, if any.
855 ATTR is a string of other attributes of the \"a\" element.
856 MAY-INLINE-P allows inlining it as an image."
858 (declare (special org-par-open))
859 (save-match-data
860 (let* ((filename path)
861 ;;First pass. Just sanity stuff.
862 (components-1
863 (cond
864 ((string= type "file")
865 (list
866 type
867 ;;Substitute just if original path was absolute.
868 ;;(Otherwise path must remain relative)
869 (if (file-name-absolute-p path)
870 (concat "file://" (expand-file-name path))
871 path)))
872 ((string= type "")
873 (list nil path))
874 (t (list type path))))
876 ;;Second pass. Components converted so they can refer
877 ;;to a remote site.
878 (components-2
880 (and org-html-cvt-link-fn
881 (apply org-html-cvt-link-fn
882 opt-plist components-1))
883 (apply #'org-html-cvt-org-as-html
884 opt-plist components-1)
885 components-1))
886 (type (first components-2))
887 (thefile (second components-2)))
890 ;;Third pass. Build final link except for leading type
891 ;;spec.
892 (cond
893 ((or
894 (not type)
895 (string= type "http")
896 (string= type "https")
897 (string= type "file")
898 (string= type "coderef"))
899 (if fragment
900 (setq thefile (concat thefile "#" fragment))))
902 (t))
904 ;;Final URL-build, for all types.
905 (setq thefile
906 (let
907 ((str (org-export-html-format-href thefile)))
908 (if (and type (not (or (string= "file" type)
909 (string= "coderef" type))))
910 (concat type ":" str)
911 str)))
913 (if (and
914 may-inline-p
915 ;;Can't inline a URL with a fragment.
916 (not fragment))
917 (progn
918 (message "image %s %s" thefile org-par-open)
919 (org-export-html-format-image thefile org-par-open))
920 (concat
921 "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
922 (org-export-html-format-desc desc)
923 "</a>")))))
925 (defun org-html-handle-links (line opt-plist)
926 "Return LINE with markup of Org mode links.
927 OPT-PLIST is the export options list."
928 (let ((start 0)
929 (current-dir (if buffer-file-name
930 (file-name-directory buffer-file-name)
931 default-directory))
932 (link-validate (plist-get opt-plist :link-validation-function))
933 type id-file fnc
934 rpl path attr desc descp desc1 desc2 link)
935 (while (string-match org-bracket-link-analytic-regexp++ line start)
936 (setq start (match-beginning 0))
937 (setq path (save-match-data (org-link-unescape
938 (match-string 3 line))))
939 (setq type (cond
940 ((match-end 2) (match-string 2 line))
941 ((save-match-data
942 (or (file-name-absolute-p path)
943 (string-match "^\\.\\.?/" path)))
944 "file")
945 (t "internal")))
946 (setq path (org-extract-attributes path))
947 (setq attr (get-text-property 0 'org-attributes path))
948 (setq desc1 (if (match-end 5) (match-string 5 line))
949 desc2 (if (match-end 2) (concat type ":" path) path)
950 descp (and desc1 (not (equal desc1 desc2)))
951 desc (or desc1 desc2))
952 ;; Make an image out of the description if that is so wanted
953 (when (and descp (org-file-image-p
954 desc org-export-html-inline-image-extensions))
955 (save-match-data
956 (if (string-match "^file:" desc)
957 (setq desc (substring desc (match-end 0)))))
958 (setq desc (org-add-props
959 (concat "<img src=\"" desc "\" alt=\""
960 (file-name-nondirectory desc) "\"/>")
961 '(org-protected t))))
962 (cond
963 ((equal type "internal")
964 (let
965 ((frag-0
966 (if (= (string-to-char path) ?#)
967 (substring path 1)
968 path)))
969 (setq rpl
970 (org-html-make-link
971 opt-plist
974 (org-solidify-link-text
975 (save-match-data (org-link-unescape frag-0))
976 nil)
977 desc attr nil))))
978 ((and (equal type "id")
979 (setq id-file (org-id-find-id-file path)))
980 ;; This is an id: link to another file (if it was the same file,
981 ;; it would have become an internal link...)
982 (save-match-data
983 (setq id-file (file-relative-name
984 id-file
985 (file-name-directory org-current-export-file)))
986 (setq rpl
987 (org-html-make-link opt-plist
988 "file" id-file
989 (concat (if (org-uuidgen-p path) "ID-") path)
990 desc
991 attr
992 nil))))
993 ((member type '("http" "https"))
994 ;; standard URL, can inline as image
995 (setq rpl
996 (org-html-make-link opt-plist
997 type path nil
998 desc
999 attr
1000 (org-html-should-inline-p path descp))))
1001 ((member type '("ftp" "mailto" "news"))
1002 ;; standard URL, can't inline as image
1003 (setq rpl
1004 (org-html-make-link opt-plist
1005 type path nil
1006 desc
1007 attr
1008 nil)))
1010 ((string= type "coderef")
1011 (let*
1012 ((coderef-str (format "coderef-%s" path))
1013 (attr-1
1014 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1015 coderef-str coderef-str)))
1016 (setq rpl
1017 (org-html-make-link opt-plist
1018 type "" coderef-str
1019 (format
1020 (org-export-get-coderef-format
1021 path
1022 (and descp desc))
1023 (cdr (assoc path org-export-code-refs)))
1024 attr-1
1025 nil))))
1027 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
1028 ;; The link protocol has a function for format the link
1029 (setq rpl
1030 (save-match-data
1031 (funcall fnc (org-link-unescape path) desc1 'html))))
1033 ((string= type "file")
1034 ;; FILE link
1035 (save-match-data
1036 (let*
1037 ((components
1039 (string-match "::\\(.*\\)" path)
1040 (list
1041 (replace-match "" t nil path)
1042 (match-string 1 path))
1043 (list path nil)))
1045 ;;The proper path, without a fragment
1046 (path-1
1047 (first components))
1049 ;;The raw fragment
1050 (fragment-0
1051 (second components))
1053 ;;Check the fragment. If it can't be used as
1054 ;;target fragment we'll pass nil instead.
1055 (fragment-1
1057 (and fragment-0
1058 (not (string-match "^[0-9]*$" fragment-0))
1059 (not (string-match "^\\*" fragment-0))
1060 (not (string-match "^/.*/$" fragment-0)))
1061 (org-solidify-link-text
1062 (org-link-unescape fragment-0))
1063 nil))
1064 (desc-2
1065 ;;Description minus "file:" and ".org"
1066 (if (string-match "^file:" desc)
1067 (let
1068 ((desc-1 (replace-match "" t t desc)))
1069 (if (string-match "\\.org$" desc-1)
1070 (replace-match "" t t desc-1)
1071 desc-1))
1072 desc)))
1074 (setq rpl
1076 (and
1077 (functionp link-validate)
1078 (not (funcall link-validate path-1 current-dir)))
1079 desc
1080 (org-html-make-link opt-plist
1081 "file" path-1 fragment-1 desc-2 attr
1082 (org-html-should-inline-p path-1 descp)))))))
1085 ;; just publish the path, as default
1086 (setq rpl (concat "<i>&lt;" type ":"
1087 (save-match-data (org-link-unescape path))
1088 "&gt;</i>"))))
1089 (setq line (replace-match rpl t t line)
1090 start (+ start (length rpl))))
1091 line))
1093 ;;; org-export-as-html
1095 (defvar org-heading-keyword-regexp-format) ; defined in org.el
1097 ;;;###autoload
1098 (defun org-export-as-html (arg &optional hidden ext-plist
1099 to-buffer body-only pub-dir)
1100 "Export the outline as a pretty HTML file.
1101 If there is an active region, export only the region. The prefix
1102 ARG specifies how many levels of the outline should become
1103 headlines. The default is 3. Lower levels will become bulleted
1104 lists. HIDDEN is obsolete and does nothing.
1105 EXT-PLIST is a property list with external parameters overriding
1106 org-mode's default settings, but still inferior to file-local
1107 settings. When TO-BUFFER is non-nil, create a buffer with that
1108 name and export to that buffer. If TO-BUFFER is the symbol
1109 `string', don't leave any buffer behind but just return the
1110 resulting HTML as a string. When BODY-ONLY is set, don't produce
1111 the file header and footer, simply return the content of
1112 <body>...</body>, without even the body tags themselves. When
1113 PUB-DIR is set, use this as the publishing directory."
1114 (interactive "P")
1115 (run-hooks 'org-export-first-hook)
1117 ;; Make sure we have a file name when we need it.
1118 (when (and (not (or to-buffer body-only))
1119 (not buffer-file-name))
1120 (if (buffer-base-buffer)
1121 (org-set-local 'buffer-file-name
1122 (with-current-buffer (buffer-base-buffer)
1123 buffer-file-name))
1124 (error "Need a file name to be able to export")))
1126 (message "Exporting...")
1127 (setq-default org-todo-line-regexp org-todo-line-regexp)
1128 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
1129 (setq-default org-done-keywords org-done-keywords)
1130 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
1131 (let* ((opt-plist
1132 (org-export-process-option-filters
1133 (org-combine-plists (org-default-export-plist)
1134 ext-plist
1135 (org-infile-export-plist))))
1136 (body-only (or body-only (plist-get opt-plist :body-only)))
1137 (style (concat (if (plist-get opt-plist :style-include-default)
1138 org-export-html-style-default)
1139 (plist-get opt-plist :style)
1140 (plist-get opt-plist :style-extra)
1141 "\n"
1142 (if (plist-get opt-plist :style-include-scripts)
1143 org-export-html-scripts)))
1144 (html-extension (plist-get opt-plist :html-extension))
1145 valid thetoc have-headings first-heading-pos
1146 (odd org-odd-levels-only)
1147 (region-p (org-region-active-p))
1148 (rbeg (and region-p (region-beginning)))
1149 (rend (and region-p (region-end)))
1150 (subtree-p
1151 (if (plist-get opt-plist :ignore-subtree-p)
1153 (when region-p
1154 (save-excursion
1155 (goto-char rbeg)
1156 (and (org-at-heading-p)
1157 (>= (org-end-of-subtree t t) rend))))))
1158 (level-offset (if subtree-p
1159 (save-excursion
1160 (goto-char rbeg)
1161 (+ (funcall outline-level)
1162 (if org-odd-levels-only 1 0)))
1164 (opt-plist (setq org-export-opt-plist
1165 (if subtree-p
1166 (org-export-add-subtree-options opt-plist rbeg)
1167 opt-plist)))
1168 ;; The following two are dynamically scoped into other
1169 ;; routines below.
1170 (org-current-export-dir
1171 (or pub-dir (org-export-directory :html opt-plist)))
1172 (org-current-export-file buffer-file-name)
1173 (level 0) (line "") (origline "") txt todo
1174 (umax nil)
1175 (umax-toc nil)
1176 (filename (if to-buffer nil
1177 (expand-file-name
1178 (concat
1179 (file-name-sans-extension
1180 (or (and subtree-p
1181 (org-entry-get (region-beginning)
1182 "EXPORT_FILE_NAME" t))
1183 (file-name-nondirectory buffer-file-name)))
1184 "." html-extension)
1185 (file-name-as-directory
1186 (or pub-dir (org-export-directory :html opt-plist))))))
1187 (current-dir (if buffer-file-name
1188 (file-name-directory buffer-file-name)
1189 default-directory))
1190 (auto-insert nil); Avoid any auto-insert stuff for the new file
1191 (buffer (if to-buffer
1192 (cond
1193 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
1194 (t (get-buffer-create to-buffer)))
1195 (find-file-noselect filename)))
1196 (org-levels-open (make-vector org-level-max nil))
1197 (date (org-html-expand (plist-get opt-plist :date)))
1198 (author (org-html-expand (plist-get opt-plist :author)))
1199 (html-validation-link (or org-export-html-validation-link ""))
1200 (title (org-html-expand
1201 (or (and subtree-p (org-export-get-title-from-subtree))
1202 (plist-get opt-plist :title)
1203 (and (not body-only)
1204 (not
1205 (plist-get opt-plist :skip-before-1st-heading))
1206 (org-export-grab-title-from-buffer))
1207 (and buffer-file-name
1208 (file-name-sans-extension
1209 (file-name-nondirectory buffer-file-name)))
1210 "UNTITLED")))
1211 (link-up (and (plist-get opt-plist :link-up)
1212 (string-match "\\S-" (plist-get opt-plist :link-up))
1213 (plist-get opt-plist :link-up)))
1214 (link-home (and (plist-get opt-plist :link-home)
1215 (string-match "\\S-" (plist-get opt-plist :link-home))
1216 (plist-get opt-plist :link-home)))
1217 (dummy (setq opt-plist (plist-put opt-plist :title title)))
1218 (html-table-tag (plist-get opt-plist :html-table-tag))
1219 (quote-re0 (concat "^ *" org-quote-string "\\( +\\|[ \t]*$\\)"))
1220 (quote-re (format org-heading-keyword-regexp-format
1221 org-quote-string))
1222 (inquote nil)
1223 (infixed nil)
1224 (inverse nil)
1225 (email (plist-get opt-plist :email))
1226 (language (plist-get opt-plist :language))
1227 (keywords (org-html-expand (plist-get opt-plist :keywords)))
1228 (description (org-html-expand (plist-get opt-plist :description)))
1229 (num (plist-get opt-plist :section-numbers))
1230 (lang-words nil)
1231 (head-count 0) cnt
1232 (start 0)
1233 (coding-system (and (boundp 'buffer-file-coding-system)
1234 buffer-file-coding-system))
1235 (coding-system-for-write (or org-export-html-coding-system
1236 coding-system))
1237 (save-buffer-coding-system (or org-export-html-coding-system
1238 coding-system))
1239 (charset (and coding-system-for-write
1240 (fboundp 'coding-system-get)
1241 (coding-system-get coding-system-for-write
1242 'mime-charset)))
1243 (region
1244 (buffer-substring
1245 (if region-p (region-beginning) (point-min))
1246 (if region-p (region-end) (point-max))))
1247 (org-export-have-math nil)
1248 (org-export-footnotes-seen nil)
1249 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
1250 (lines
1251 (org-split-string
1252 (org-export-preprocess-string
1253 region
1254 :emph-multiline t
1255 :for-backend 'html
1256 :skip-before-1st-heading
1257 (plist-get opt-plist :skip-before-1st-heading)
1258 :drawers (plist-get opt-plist :drawers)
1259 :todo-keywords (plist-get opt-plist :todo-keywords)
1260 :tasks (plist-get opt-plist :tasks)
1261 :tags (plist-get opt-plist :tags)
1262 :priority (plist-get opt-plist :priority)
1263 :footnotes (plist-get opt-plist :footnotes)
1264 :timestamps (plist-get opt-plist :timestamps)
1265 :archived-trees
1266 (plist-get opt-plist :archived-trees)
1267 :select-tags (plist-get opt-plist :select-tags)
1268 :exclude-tags (plist-get opt-plist :exclude-tags)
1269 :add-text
1270 (plist-get opt-plist :text)
1271 :LaTeX-fragments
1272 (plist-get opt-plist :LaTeX-fragments))
1273 "[\r\n]"))
1274 (mathjax
1275 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
1276 (and org-export-have-math
1277 (eq (plist-get opt-plist :LaTeX-fragments) t)))
1279 (org-export-html-mathjax-config
1280 org-export-html-mathjax-template
1281 org-export-html-mathjax-options
1282 (or (plist-get opt-plist :mathjax) ""))
1283 ""))
1284 table-open
1285 table-buffer table-orig-buffer
1287 rpl path attr desc descp desc1 desc2 link
1288 snumber fnc
1289 footnotes footref-seen
1290 href
1293 (let ((inhibit-read-only t))
1294 (org-unmodified
1295 (remove-text-properties (point-min) (point-max)
1296 '(:org-license-to-kill t))))
1298 (message "Exporting...")
1300 (setq org-min-level (org-get-min-level lines level-offset))
1301 (setq org-last-level org-min-level)
1302 (org-init-section-numbers)
1304 (cond
1305 ((and date (string-match "%" date))
1306 (setq date (format-time-string date)))
1307 (date)
1308 (t (setq date (format-time-string org-export-html-date-format-string))))
1310 ;; Get the language-dependent settings
1311 (setq lang-words (or (assoc language org-export-language-setup)
1312 (assoc "en" org-export-language-setup)))
1314 ;; Switch to the output buffer
1315 (set-buffer buffer)
1316 (let ((inhibit-read-only t)) (erase-buffer))
1317 (fundamental-mode)
1318 (org-install-letbind)
1320 (and (fboundp 'set-buffer-file-coding-system)
1321 (set-buffer-file-coding-system coding-system-for-write))
1323 (let ((case-fold-search nil)
1324 (org-odd-levels-only odd))
1325 ;; create local variables for all options, to make sure all called
1326 ;; functions get the correct information
1327 (mapc (lambda (x)
1328 (set (make-local-variable (nth 2 x))
1329 (plist-get opt-plist (car x))))
1330 org-export-plist-vars)
1331 (setq umax (if arg (prefix-numeric-value arg)
1332 org-export-headline-levels))
1333 (setq umax-toc (if (integerp org-export-with-toc)
1334 (min org-export-with-toc umax)
1335 umax))
1336 (unless body-only
1337 ;; File header
1338 (insert (format
1340 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1341 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1342 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
1343 <head>
1344 <title>%s</title>
1345 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1346 <meta name=\"title\" content=\"%s\"/>
1347 <meta name=\"generator\" content=\"Org-mode\"/>
1348 <meta name=\"generated\" content=\"%s\"/>
1349 <meta name=\"author\" content=\"%s\"/>
1350 <meta name=\"description\" content=\"%s\"/>
1351 <meta name=\"keywords\" content=\"%s\"/>
1354 </head>
1355 <body>
1358 (format
1359 (or (and (stringp org-export-html-xml-declaration)
1360 org-export-html-xml-declaration)
1361 (cdr (assoc html-extension org-export-html-xml-declaration))
1362 (cdr (assoc "html" org-export-html-xml-declaration))
1365 (or charset "iso-8859-1"))
1366 language language
1367 title
1368 (or charset "iso-8859-1")
1369 title date author description keywords
1370 style
1371 mathjax
1372 (if (or link-up link-home)
1373 (concat
1374 (format org-export-html-home/up-format
1375 (or link-up link-home)
1376 (or link-home link-up))
1377 "\n")
1378 "")))
1380 ;; insert html preamble
1381 (when (plist-get opt-plist :html-preamble)
1382 (let ((html-pre (plist-get opt-plist :html-preamble))
1383 (html-pre-real-contents ""))
1384 (cond ((stringp html-pre)
1385 (setq html-pre-real-contents
1386 (format-spec html-pre `((?t . ,title) (?a . ,author)
1387 (?d . ,date) (?e . ,email)))))
1388 ((functionp html-pre)
1389 (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
1390 (if (stringp (funcall html-pre)) (insert (funcall html-pre)))
1391 (insert "\n</div>\n"))
1393 (setq html-pre-real-contents
1394 (format-spec
1395 (or (cadr (assoc (nth 0 lang-words)
1396 org-export-html-preamble-format))
1397 (cadr (assoc "en" org-export-html-preamble-format)))
1398 `((?t . ,title) (?a . ,author)
1399 (?d . ,date) (?e . ,email))))))
1400 ;; don't output an empty preamble DIV
1401 (unless (and (functionp html-pre)
1402 (equal html-pre-real-contents ""))
1403 (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
1404 (insert html-pre-real-contents)
1405 (insert "\n</div>\n"))))
1407 ;; begin wrap around body
1408 (insert (format "\n<div id=\"%s\">"
1409 ;; FIXME org-export-html-content-div is obsolete since 7.7
1410 (or org-export-html-content-div
1411 (nth 1 org-export-html-divs)))
1412 ;; FIXME this should go in the preamble but is here so
1413 ;; that org-infojs can still find it
1414 "\n<h1 class=\"title\">" title "</h1>\n"))
1416 ;; insert body
1417 (if org-export-with-toc
1418 (progn
1419 (push (format "<h%d>%s</h%d>\n"
1420 org-export-html-toplevel-hlevel
1421 (nth 3 lang-words)
1422 org-export-html-toplevel-hlevel)
1423 thetoc)
1424 (push "<div id=\"text-table-of-contents\">\n" thetoc)
1425 (push "<ul>\n<li>" thetoc)
1426 (setq lines
1427 (mapcar
1428 #'(lambda (line)
1429 (if (and (string-match org-todo-line-regexp line)
1430 (not (get-text-property 0 'org-protected line)))
1431 ;; This is a headline
1432 (progn
1433 (setq have-headings t)
1434 (setq level (- (match-end 1) (match-beginning 1)
1435 level-offset)
1436 level (org-tr-level level)
1437 txt (save-match-data
1438 (org-html-expand
1439 (org-export-cleanup-toc-line
1440 (match-string 3 line))))
1441 todo
1442 (or (and org-export-mark-todo-in-toc
1443 (match-beginning 2)
1444 (not (member (match-string 2 line)
1445 org-done-keywords)))
1446 ; TODO, not DONE
1447 (and org-export-mark-todo-in-toc
1448 (= level umax-toc)
1449 (org-search-todo-below
1450 line lines level))))
1451 (if (string-match
1452 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
1453 (setq txt (replace-match
1454 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">\\1</span>" t nil txt)))
1455 (if (string-match quote-re0 txt)
1456 (setq txt (replace-match "" t t txt)))
1457 (setq snumber (org-section-number level))
1458 (if (and num (if (integerp num)
1459 (>= num level)
1460 num))
1461 (setq txt (concat snumber " " txt)))
1462 (if (<= level (max umax umax-toc))
1463 (setq head-count (+ head-count 1)))
1464 (if (<= level umax-toc)
1465 (progn
1466 (if (> level org-last-level)
1467 (progn
1468 (setq cnt (- level org-last-level))
1469 (while (>= (setq cnt (1- cnt)) 0)
1470 (push "\n<ul>\n<li>" thetoc))
1471 (push "\n" thetoc)))
1472 (if (< level org-last-level)
1473 (progn
1474 (setq cnt (- org-last-level level))
1475 (while (>= (setq cnt (1- cnt)) 0)
1476 (push "</li>\n</ul>" thetoc))
1477 (push "\n" thetoc)))
1478 ;; Check for targets
1479 (while (string-match org-any-target-regexp line)
1480 (setq line (replace-match
1481 (concat "@<span class=\"target\">"
1482 (match-string 1 line) "@</span> ")
1483 t t line)))
1484 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
1485 (setq txt (replace-match "" t t txt)))
1486 (setq href
1487 (replace-regexp-in-string
1488 "\\." "-" (format "sec-%s" snumber)))
1489 (setq href (org-solidify-link-text
1490 (or (cdr (assoc href
1491 org-export-preferred-target-alist)) href)))
1492 (push
1493 (format
1494 (if todo
1495 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1496 "</li>\n<li><a href=\"#%s\">%s</a>")
1497 href txt) thetoc)
1499 (setq org-last-level level)))))
1500 line)
1501 lines))
1502 (while (> org-last-level (1- org-min-level))
1503 (setq org-last-level (1- org-last-level))
1504 (push "</li>\n</ul>\n" thetoc))
1505 (push "</div>\n" thetoc)
1506 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1508 (setq head-count 0)
1509 (org-init-section-numbers)
1511 (org-open-par)
1513 (while (setq line (pop lines) origline line)
1514 (catch 'nextline
1516 ;; end of quote section?
1517 (when (and inquote (string-match org-outline-regexp-bol line))
1518 (insert "</pre>\n")
1519 (org-open-par)
1520 (setq inquote nil))
1521 ;; inside a quote section?
1522 (when inquote
1523 (insert (org-html-protect line) "\n")
1524 (throw 'nextline nil))
1526 ;; Fixed-width, verbatim lines (examples)
1527 (when (and org-export-with-fixed-width
1528 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
1529 (when (not infixed)
1530 (setq infixed t)
1531 (org-close-par-maybe)
1533 (insert "<pre class=\"example\">\n"))
1534 (insert (org-html-protect (match-string 3 line)) "\n")
1535 (when (or (not lines)
1536 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1537 (car lines))))
1538 (setq infixed nil)
1539 (insert "</pre>\n")
1540 (org-open-par))
1541 (throw 'nextline nil))
1543 ;; Protected HTML
1544 (when (and (get-text-property 0 'org-protected line)
1545 ;; Make sure it is the entire line that is protected
1546 (not (< (or (next-single-property-change
1547 0 'org-protected line) 10000)
1548 (length line))))
1549 (let (par (ind (get-text-property 0 'original-indentation line)))
1550 (when (re-search-backward
1551 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
1552 (setq par (match-string 1))
1553 (replace-match "\\2\n"))
1554 (insert line "\n")
1555 (while (and lines
1556 (or (= (length (car lines)) 0)
1557 (not ind)
1558 (equal ind (get-text-property 0 'original-indentation (car lines))))
1559 (or (= (length (car lines)) 0)
1560 (get-text-property 0 'org-protected (car lines))))
1561 (insert (pop lines) "\n"))
1562 (and par (insert "<p>\n")))
1563 (throw 'nextline nil))
1565 ;; Blockquotes, verse, and center
1566 (when (equal "ORG-BLOCKQUOTE-START" line)
1567 (org-close-par-maybe)
1568 (insert "<blockquote>\n")
1569 (org-open-par)
1570 (throw 'nextline nil))
1571 (when (equal "ORG-BLOCKQUOTE-END" line)
1572 (org-close-par-maybe)
1573 (insert "\n</blockquote>\n")
1574 (org-open-par)
1575 (throw 'nextline nil))
1576 (when (equal "ORG-VERSE-START" line)
1577 (org-close-par-maybe)
1578 (insert "\n<p class=\"verse\">\n")
1579 (setq org-par-open t)
1580 (setq inverse t)
1581 (throw 'nextline nil))
1582 (when (equal "ORG-VERSE-END" line)
1583 (insert "</p>\n")
1584 (setq org-par-open nil)
1585 (org-open-par)
1586 (setq inverse nil)
1587 (throw 'nextline nil))
1588 (when (equal "ORG-CENTER-START" line)
1589 (org-close-par-maybe)
1590 (insert "\n<div style=\"text-align: center\">")
1591 (org-open-par)
1592 (throw 'nextline nil))
1593 (when (equal "ORG-CENTER-END" line)
1594 (org-close-par-maybe)
1595 (insert "\n</div>")
1596 (org-open-par)
1597 (throw 'nextline nil))
1598 (run-hooks 'org-export-html-after-blockquotes-hook)
1599 (when inverse
1600 (let ((i (org-get-string-indentation line)))
1601 (if (> i 0)
1602 (setq line (concat (mapconcat 'identity
1603 (make-list (* 2 i) "\\nbsp") "")
1604 " " (org-trim line))))
1605 (unless (string-match "\\\\\\\\[ \t]*$" line)
1606 (setq line (concat line "\\\\")))))
1608 ;; make targets to anchors
1609 (setq start 0)
1610 (while (string-match
1611 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1612 (cond
1613 ((get-text-property (match-beginning 1) 'org-protected line)
1614 (setq start (match-end 1)))
1615 ((match-end 2)
1616 (setq line (replace-match
1617 (format
1618 "@<a name=\"%s\" id=\"%s\">@</a>"
1619 (org-solidify-link-text (match-string 1 line))
1620 (org-solidify-link-text (match-string 1 line)))
1621 t t line)))
1622 ((and org-export-with-toc (equal (string-to-char line) ?*))
1623 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1624 (setq line (replace-match
1625 (concat "@<span class=\"target\">"
1626 (match-string 1 line) "@</span> ")
1627 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1628 t t line)))
1630 (setq line (replace-match
1631 (concat "@<a name=\""
1632 (org-solidify-link-text (match-string 1 line))
1633 "\" class=\"target\">" (match-string 1 line)
1634 "@</a> ")
1635 t t line)))))
1637 (setq line (org-html-handle-time-stamps line))
1639 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1640 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
1641 ;; Also handle sub_superscripts and checkboxes
1642 (or (string-match org-table-hline-regexp line)
1643 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line)
1644 (setq line (org-html-expand line)))
1646 ;; Format the links
1647 (setq line (org-html-handle-links line opt-plist))
1649 ;; TODO items
1650 (if (and org-todo-line-regexp
1651 (string-match org-todo-line-regexp line)
1652 (match-beginning 2))
1654 (setq line
1655 (concat (substring line 0 (match-beginning 2))
1656 "<span class=\""
1657 (if (member (match-string 2 line)
1658 org-done-keywords)
1659 "done" "todo")
1660 " " (org-export-html-get-todo-kwd-class-name
1661 (match-string 2 line))
1662 "\">" (match-string 2 line)
1663 "</span>" (substring line (match-end 2)))))
1665 ;; Does this contain a reference to a footnote?
1666 (when org-export-with-footnotes
1667 (setq start 0)
1668 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
1669 ;; Discard protected matches not clearly identified as
1670 ;; footnote markers.
1671 (if (or (get-text-property (match-beginning 2) 'org-protected line)
1672 (not (get-text-property (match-beginning 2) 'org-footnote line)))
1673 (setq start (match-end 2))
1674 (let ((n (match-string 2 line)) extra a)
1675 (if (setq a (assoc n footref-seen))
1676 (progn
1677 (setcdr a (1+ (cdr a)))
1678 (setq extra (format ".%d" (cdr a))))
1679 (setq extra "")
1680 (push (cons n 1) footref-seen))
1681 (setq line
1682 (replace-match
1683 (concat
1684 (format
1685 (concat "%s"
1686 (format org-export-html-footnote-format
1687 (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
1688 (or (match-string 1 line) "") n extra n n)
1689 ;; If another footnote is following the
1690 ;; current one, add a separator.
1691 (if (save-match-data
1692 (string-match "\\`\\[[0-9]+\\]"
1693 (substring line (match-end 0))))
1694 org-export-html-footnote-separator
1695 ""))
1696 t t line))))))
1698 (cond
1699 ((string-match "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" line)
1700 ;; This is a headline
1701 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1702 level-offset))
1703 txt (match-string 2 line))
1704 (if (string-match quote-re0 txt)
1705 (setq txt (replace-match "" t t txt)))
1706 (if (<= level (max umax umax-toc))
1707 (setq head-count (+ head-count 1)))
1708 (setq first-heading-pos (or first-heading-pos (point)))
1709 (org-html-level-start level txt umax
1710 (and org-export-with-toc (<= level umax))
1711 head-count opt-plist)
1713 ;; QUOTES
1714 (when (string-match quote-re line)
1715 (org-close-par-maybe)
1716 (insert "<pre>")
1717 (setq inquote t)))
1719 ((and org-export-with-tables
1720 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1721 (when (not table-open)
1722 ;; New table starts
1723 (setq table-open t table-buffer nil table-orig-buffer nil))
1725 ;; Accumulate lines
1726 (setq table-buffer (cons line table-buffer)
1727 table-orig-buffer (cons origline table-orig-buffer))
1728 (when (or (not lines)
1729 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1730 (car lines))))
1731 (setq table-open nil
1732 table-buffer (nreverse table-buffer)
1733 table-orig-buffer (nreverse table-orig-buffer))
1734 (org-close-par-maybe)
1735 (insert (org-format-table-html table-buffer table-orig-buffer))))
1737 ;; Normal lines
1740 ;; This line either is list item or end a list.
1741 (when (get-text-property 0 'list-item line)
1742 (setq line (org-html-export-list-line
1743 line
1744 (get-text-property 0 'list-item line)
1745 (get-text-property 0 'list-struct line)
1746 (get-text-property 0 'list-prevs line))))
1748 ;; Horizontal line
1749 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1750 (if org-par-open
1751 (insert "\n</p>\n<hr/>\n<p>\n")
1752 (insert "\n<hr/>\n"))
1753 (throw 'nextline nil))
1755 ;; Empty lines start a new paragraph. If hand-formatted lists
1756 ;; are not fully interpreted, lines starting with "-", "+", "*"
1757 ;; also start a new paragraph.
1758 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
1760 ;; Is this the start of a footnote?
1761 (when org-export-with-footnotes
1762 (when (and (boundp 'footnote-section-tag-regexp)
1763 (string-match (concat "^" footnote-section-tag-regexp)
1764 line))
1765 ;; ignore this line
1766 (throw 'nextline nil))
1767 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1768 (org-close-par-maybe)
1769 (let ((n (match-string 1 line)))
1770 (setq org-par-open t
1771 line (replace-match
1772 (format
1773 (concat "<p class=\"footnote\">"
1774 (format org-export-html-footnote-format
1775 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1776 n n n) t t line)))))
1777 ;; Check if the line break needs to be conserved
1778 (cond
1779 ((string-match "\\\\\\\\[ \t]*$" line)
1780 (setq line (replace-match "<br/>" t t line)))
1781 (org-export-preserve-breaks
1782 (setq line (concat line "<br/>"))))
1784 ;; Check if a paragraph should be started
1785 (let ((start 0))
1786 (while (and org-par-open
1787 (string-match "\\\\par\\>" line start))
1788 ;; Leave a space in the </p> so that the footnote matcher
1789 ;; does not see this.
1790 (if (not (get-text-property (match-beginning 0)
1791 'org-protected line))
1792 (setq line (replace-match "</p ><p >" t t line)))
1793 (setq start (match-end 0))))
1795 (insert line "\n")))))
1797 ;; Properly close all local lists and other lists
1798 (when inquote
1799 (insert "</pre>\n")
1800 (org-open-par))
1802 (org-html-level-start 1 nil umax
1803 (and org-export-with-toc (<= level umax))
1804 head-count opt-plist)
1805 ;; the </div> to close the last text-... div.
1806 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
1808 (save-excursion
1809 (goto-char (point-min))
1810 (while (re-search-forward
1811 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1812 nil t)
1813 (push (match-string 1) footnotes)
1814 (replace-match "\\4" t nil)
1815 (goto-char (match-beginning 0))))
1816 (when footnotes
1817 (insert (format org-export-html-footnotes-section
1818 (nth 4 lang-words)
1819 (mapconcat 'identity (nreverse footnotes) "\n"))
1820 "\n"))
1821 (let ((bib (org-export-html-get-bibliography)))
1822 (when bib
1823 (insert "\n" bib "\n")))
1825 (unless body-only
1826 ;; end wrap around body
1827 (insert "</div>\n")
1829 ;; export html postamble
1830 (let ((html-post (plist-get opt-plist :html-postamble))
1831 (email
1832 (mapconcat (lambda(e)
1833 (format "<a href=\"mailto:%s\">%s</a>" e e))
1834 (split-string email ",+ *")
1835 ", "))
1836 (creator-info
1837 (concat "Org version " org-version " with Emacs version "
1838 (number-to-string emacs-major-version))))
1840 (when (plist-get opt-plist :html-postamble)
1841 (insert "\n<div id=\"" (nth 2 org-export-html-divs) "\">\n")
1842 (cond ((stringp html-post)
1843 (insert (format-spec html-post
1844 `((?a . ,author) (?e . ,email)
1845 (?d . ,date) (?c . ,creator-info)
1846 (?v . ,html-validation-link)))))
1847 ((functionp html-post)
1848 (if (stringp (funcall html-post)) (insert (funcall html-post))))
1849 ((eq html-post 'auto)
1850 ;; fall back on default postamble
1851 (when (plist-get opt-plist :time-stamp-file)
1852 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
1853 (when (and (plist-get opt-plist :author-info) author)
1854 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1855 (when (and (plist-get opt-plist :email-info) email)
1856 (insert "<p class=\"email\">" email "</p>\n"))
1857 (when (plist-get opt-plist :creator-info)
1858 (insert "<p class=\"creator\">"
1859 (concat "Org version " org-version " with Emacs version "
1860 (number-to-string emacs-major-version) "</p>\n")))
1861 (insert html-validation-link "\n"))
1863 (insert (format-spec
1864 (or (cadr (assoc (nth 0 lang-words)
1865 org-export-html-postamble-format))
1866 (cadr (assoc "en" org-export-html-postamble-format)))
1867 `((?a . ,author) (?e . ,email)
1868 (?d . ,date) (?c . ,creator-info)
1869 (?v . ,html-validation-link))))))
1870 (insert "\n</div>"))))
1872 ;; FIXME `org-export-html-with-timestamp' has been declared
1873 ;; obsolete since Org 7.7 -- don't forget to remove this.
1874 (if org-export-html-with-timestamp
1875 (insert org-export-html-html-helper-timestamp))
1877 (unless body-only (insert "\n</body>\n</html>\n"))
1879 (unless (plist-get opt-plist :buffer-will-be-killed)
1880 (normal-mode)
1881 (if (eq major-mode (default-value 'major-mode))
1882 (html-mode)))
1884 ;; insert the table of contents
1885 (goto-char (point-min))
1886 (when thetoc
1887 (if (or (re-search-forward
1888 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1889 (re-search-forward
1890 "\\[TABLE-OF-CONTENTS\\]" nil t))
1891 (progn
1892 (goto-char (match-beginning 0))
1893 (replace-match ""))
1894 (goto-char first-heading-pos)
1895 (when (looking-at "\\s-*</p>")
1896 (goto-char (match-end 0))
1897 (insert "\n")))
1898 (insert "<div id=\"table-of-contents\">\n")
1899 (let ((beg (point)))
1900 (mapc 'insert thetoc)
1901 (insert "</div>\n")
1902 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
1903 (replace-match ""))))
1904 ;; remove empty paragraphs
1905 (goto-char (point-min))
1906 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
1907 (replace-match ""))
1908 (goto-char (point-min))
1909 ;; Convert whitespace place holders
1910 (goto-char (point-min))
1911 (let (beg end n)
1912 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1913 (setq n (get-text-property beg 'org-whitespace)
1914 end (next-single-property-change beg 'org-whitespace))
1915 (goto-char beg)
1916 (delete-region beg end)
1917 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1918 (make-string n ?x)))))
1919 ;; Remove empty lines at the beginning of the file.
1920 (goto-char (point-min))
1921 (when (looking-at "\\s-+\n") (replace-match ""))
1922 ;; Remove display properties
1923 (remove-text-properties (point-min) (point-max) '(display t))
1924 ;; Run the hook
1925 (run-hooks 'org-export-html-final-hook)
1926 (or to-buffer (save-buffer))
1927 (goto-char (point-min))
1928 (or (org-export-push-to-kill-ring "HTML")
1929 (message "Exporting... done"))
1930 (if (eq to-buffer 'string)
1931 (prog1 (buffer-substring (point-min) (point-max))
1932 (kill-buffer (current-buffer)))
1933 (current-buffer)))))
1935 (defun org-export-html-format-href (s)
1936 "Make sure the S is valid as a href reference in an XHTML document."
1937 (save-match-data
1938 (let ((start 0))
1939 (while (string-match "&" s start)
1940 (setq start (+ (match-beginning 0) 3)
1941 s (replace-match "&amp;" t t s)))))
1944 (defun org-export-html-format-desc (s)
1945 "Make sure the S is valid as a description in a link."
1946 (if (and s (not (get-text-property 1 'org-protected s)))
1947 (save-match-data
1948 (org-html-do-expand s))
1951 (defun org-export-html-format-image (src par-open)
1952 "Create image tag with source and attributes."
1953 (save-match-data
1954 (if (string-match "^ltxpng/" src)
1955 (format "<img src=\"%s\" alt=\"%s\"/>"
1956 src (org-find-text-property-in-string 'org-latex-src src))
1957 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1958 (attr (org-find-text-property-in-string 'org-attributes src))
1959 (label (org-find-text-property-in-string 'org-label src)))
1960 (setq caption (and caption (org-html-do-expand caption)))
1961 (concat
1962 (if caption
1963 (format "%s<div %sclass=\"figure\">
1964 <p>"
1965 (if org-par-open "</p>\n" "")
1966 (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
1967 (format "<img src=\"%s\"%s />"
1969 (if (string-match "\\<alt=" (or attr ""))
1970 (concat " " attr )
1971 (concat " " attr " alt=\"" src "\"")))
1972 (if caption
1973 (format "</p>%s
1974 </div>%s"
1975 (concat "\n<p>" caption "</p>")
1976 (if org-par-open "\n<p>" ""))))))))
1978 (defun org-export-html-get-bibliography ()
1979 "Find bibliography, cut it out and return it."
1980 (catch 'exit
1981 (let (beg end (cnt 1) bib)
1982 (save-excursion
1983 (goto-char (point-min))
1984 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1985 (setq beg (match-beginning 0))
1986 (while (re-search-forward "</?div\\>" nil t)
1987 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1988 (when (= cnt 0)
1989 (and (looking-at ">") (forward-char 1))
1990 (setq bib (buffer-substring beg (point)))
1991 (delete-region beg (point))
1992 (throw 'exit bib))))
1993 nil))))
1995 (defvar org-table-number-regexp) ; defined in org-table.el
1996 (defun org-format-table-html (lines olines &optional no-css)
1997 "Find out which HTML converter to use and return the HTML code.
1998 NO-CSS is passed to the exporter."
1999 (if (stringp lines)
2000 (setq lines (org-split-string lines "\n")))
2001 (if (string-match "^[ \t]*|" (car lines))
2002 ;; A normal org table
2003 (org-format-org-table-html lines nil no-css)
2004 ;; Table made by table.el
2005 (or (org-format-table-table-html-using-table-generate-source
2006 olines (not org-export-prefer-native-exporter-for-tables))
2007 ;; We are here only when table.el table has NO col or row
2008 ;; spanning and the user prefers using org's own converter for
2009 ;; exporting of such simple table.el tables.
2010 (org-format-table-table-html lines))))
2012 (defvar org-table-number-fraction) ; defined in org-table.el
2013 (defun org-format-org-table-html (lines &optional splice no-css)
2014 "Format a table into HTML.
2015 LINES is a list of lines. Optional argument SPLICE means, do not
2016 insert header and surrounding <table> tags, just format the lines.
2017 Optional argument NO-CSS means use XHTML attributes instead of CSS
2018 for formatting. This is required for the DocBook exporter."
2019 (require 'org-table)
2020 ;; Get rid of hlines at beginning and end
2021 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2022 (setq lines (nreverse lines))
2023 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2024 (setq lines (nreverse lines))
2025 (when org-export-table-remove-special-lines
2026 ;; Check if the table has a marking column. If yes remove the
2027 ;; column and the special lines
2028 (setq lines (org-table-clean-before-export lines)))
2030 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
2031 (label (org-find-text-property-in-string 'org-label (car lines)))
2032 (col-cookies (org-find-text-property-in-string 'org-col-cookies
2033 (car lines)))
2034 (attributes (org-find-text-property-in-string 'org-attributes
2035 (car lines)))
2036 (html-table-tag (org-export-splice-attributes
2037 html-table-tag attributes))
2038 (head (and org-export-highlight-first-table-line
2039 (delq nil (mapcar
2040 (lambda (x) (string-match "^[ \t]*|-" x))
2041 (cdr lines)))))
2042 (nline 0) fnum nfields i (cnt 0)
2043 tbopen line fields html gr colgropen rowstart rowend
2044 ali align aligns n)
2045 (setq caption (and caption (org-html-do-expand caption)))
2046 (when (and col-cookies org-table-clean-did-remove-column)
2047 (setq col-cookies
2048 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
2049 (if splice (setq head nil))
2050 (unless splice (push (if head "<thead>" "<tbody>") html))
2051 (setq tbopen t)
2052 (while (setq line (pop lines))
2053 (catch 'next-line
2054 (if (string-match "^[ \t]*|-" line)
2055 (progn
2056 (unless splice
2057 (push (if head "</thead>" "</tbody>") html)
2058 (if lines (push "<tbody>" html) (setq tbopen nil)))
2059 (setq head nil) ;; head ends here, first time around
2060 ;; ignore this line
2061 (throw 'next-line t)))
2062 ;; Break the line into fields
2063 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2064 (unless fnum (setq fnum (make-vector (length fields) 0)
2065 nfields (length fnum)))
2066 (setq nline (1+ nline) i -1
2067 rowstart (eval (car org-export-table-row-tags))
2068 rowend (eval (cdr org-export-table-row-tags)))
2069 (push (concat rowstart
2070 (mapconcat
2071 (lambda (x)
2072 (setq i (1+ i) ali (format "@@class%03d@@" i))
2073 (if (and (< i nfields) ; make sure no rogue line causes an error here
2074 (string-match org-table-number-regexp x))
2075 (incf (aref fnum i)))
2076 (cond
2077 (head
2078 (concat
2079 (format (car org-export-table-header-tags)
2080 "col" ali)
2082 (cdr org-export-table-header-tags)))
2083 ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
2084 (concat
2085 (format (car org-export-table-header-tags)
2086 "row" ali)
2088 (cdr org-export-table-header-tags)))
2090 (concat (format (car org-export-table-data-tags) ali)
2092 (cdr org-export-table-data-tags)))))
2093 fields "")
2094 rowend)
2095 html)))
2096 (unless splice (if tbopen (push "</tbody>" html)))
2097 (unless splice (push "</table>\n" html))
2098 (setq html (nreverse html))
2099 (unless splice
2100 ;; Put in col tags with the alignment (unfortunately often ignored...)
2101 (unless (car org-table-colgroup-info)
2102 (setq org-table-colgroup-info
2103 (cons :start (cdr org-table-colgroup-info))))
2104 (setq i 0)
2105 (push (mapconcat
2106 (lambda (x)
2107 (setq gr (pop org-table-colgroup-info)
2108 i (1+ i)
2109 align (if (nth 1 (assoc i col-cookies))
2110 (cdr (assoc (nth 1 (assoc i col-cookies))
2111 '(("l" . "left") ("r" . "right")
2112 ("c" . "center"))))
2113 (if (> (/ (float x) nline)
2114 org-table-number-fraction)
2115 "right" "left")))
2116 (push align aligns)
2117 (format (if no-css
2118 "%s<col align=\"%s\" />%s"
2119 "%s<col class=\"%s\" />%s")
2120 (if (memq gr '(:start :startend))
2121 (prog1
2122 (if colgropen
2123 "</colgroup>\n<colgroup>"
2124 "<colgroup>")
2125 (setq colgropen t))
2127 align
2128 (if (memq gr '(:end :startend))
2129 (progn (setq colgropen nil) "</colgroup>")
2130 "")))
2131 fnum "")
2132 html)
2133 (setq aligns (nreverse aligns))
2134 (if colgropen (setq html (cons (car html)
2135 (cons "</colgroup>" (cdr html)))))
2136 ;; Since the output of HTML table formatter can also be used in
2137 ;; DocBook document, we want to always include the caption to make
2138 ;; DocBook XML file valid.
2139 (push (format "<caption>%s</caption>" (or caption "")) html)
2140 (when label
2141 (setq html-table-tag (org-export-splice-attributes html-table-tag (format "id=\"%s\"" (org-solidify-link-text label)))))
2142 (push html-table-tag html))
2143 (setq html (mapcar
2144 (lambda (x)
2145 (replace-regexp-in-string
2146 "@@class\\([0-9]+\\)@@"
2147 (lambda (txt)
2148 (if (not org-export-html-table-align-individual-fields)
2150 (setq n (string-to-number (match-string 1 txt)))
2151 (format (if no-css " align=\"%s\"" " class=\"%s\"")
2152 (or (nth n aligns) "left"))))
2154 html))
2155 (concat (mapconcat 'identity html "\n") "\n")))
2157 (defun org-export-splice-attributes (tag attributes)
2158 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2159 (if (not attributes)
2161 (let (oldatt newatt)
2162 (setq oldatt (org-extract-attributes-from-string tag)
2163 tag (pop oldatt)
2164 newatt (cdr (org-extract-attributes-from-string attributes)))
2165 (while newatt
2166 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
2167 (if (string-match ">" tag)
2168 (setq tag
2169 (replace-match (concat (org-attributes-to-string oldatt) ">")
2170 t t tag)))
2171 tag)))
2173 (defun org-format-table-table-html (lines)
2174 "Format a table generated by table.el into HTML.
2175 This conversion does *not* use `table-generate-source' from table.el.
2176 This has the advantage that Org-mode's HTML conversions can be used.
2177 But it has the disadvantage, that no cell- or row-spanning is allowed."
2178 (let (line field-buffer
2179 (head org-export-highlight-first-table-line)
2180 fields html empty i)
2181 (setq html (concat html-table-tag "\n"))
2182 (while (setq line (pop lines))
2183 (setq empty "&nbsp;")
2184 (catch 'next-line
2185 (if (string-match "^[ \t]*\\+-" line)
2186 (progn
2187 (if field-buffer
2188 (progn
2189 (setq
2190 html
2191 (concat
2192 html
2193 "<tr>"
2194 (mapconcat
2195 (lambda (x)
2196 (if (equal x "") (setq x empty))
2197 (if head
2198 (concat
2199 (format (car org-export-table-header-tags) "col" "")
2201 (cdr org-export-table-header-tags))
2202 (concat (format (car org-export-table-data-tags) "") x
2203 (cdr org-export-table-data-tags))))
2204 field-buffer "\n")
2205 "</tr>\n"))
2206 (setq head nil)
2207 (setq field-buffer nil)))
2208 ;; Ignore this line
2209 (throw 'next-line t)))
2210 ;; Break the line into fields and store the fields
2211 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2212 (if field-buffer
2213 (setq field-buffer (mapcar
2214 (lambda (x)
2215 (concat x "<br/>" (pop fields)))
2216 field-buffer))
2217 (setq field-buffer fields))))
2218 (setq html (concat html "</table>\n"))
2219 html))
2221 (defun org-format-table-table-html-using-table-generate-source (lines
2222 &optional
2223 spanned-only)
2224 "Format a table into html, using `table-generate-source' from table.el.
2225 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
2227 When SPANNED-ONLY is nil, all table.el tables are exported. When
2228 SPANNED-ONLY is non-nil, only tables with either row or column
2229 spans are exported.
2231 This routine returns the generated source or nil as appropriate.
2233 Refer docstring of `org-export-prefer-native-exporter-for-tables'
2234 for further information."
2235 (require 'table)
2236 (with-current-buffer (get-buffer-create " org-tmp1 ")
2237 (erase-buffer)
2238 (insert (mapconcat 'identity lines "\n"))
2239 (goto-char (point-min))
2240 (if (not (re-search-forward "|[^+]" nil t))
2241 (error "Error processing table"))
2242 (table-recognize-table)
2243 (when (or (not spanned-only)
2244 (let* ((dim (table-query-dimension))
2245 (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim)))
2246 (not (= (* c r) cells))))
2247 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2248 (table-generate-source 'html " org-tmp2 ")
2249 (set-buffer " org-tmp2 ")
2250 (buffer-substring (point-min) (point-max)))))
2252 (defun org-export-splice-style (style extra)
2253 "Splice EXTRA into STYLE, just before \"</style>\"."
2254 (if (and (stringp extra)
2255 (string-match "\\S-" extra)
2256 (string-match "</style>" style))
2257 (concat (substring style 0 (match-beginning 0))
2258 "\n" extra "\n"
2259 (substring style (match-beginning 0)))
2260 style))
2262 (defun org-html-handle-time-stamps (s)
2263 "Format time stamps in string S, or remove them."
2264 (catch 'exit
2265 (let (r b)
2266 (when org-maybe-keyword-time-regexp
2267 (while (string-match org-maybe-keyword-time-regexp s)
2268 (or b (setq b (substring s 0 (match-beginning 0))))
2269 (setq r (concat
2270 r (substring s 0 (match-beginning 0))
2271 " @<span class=\"timestamp-wrapper\">"
2272 (if (match-end 1)
2273 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2274 (match-string 1 s)))
2275 (format " @<span class=\"timestamp\">%s@</span>"
2276 (substring
2277 (org-translate-time (match-string 3 s)) 1 -1))
2278 "@</span>")
2279 s (substring s (match-end 0)))))
2280 ;; Line break if line started and ended with time stamp stuff
2281 (if (not r)
2283 (setq r (concat r s))
2284 (unless (string-match "\\S-" (concat b s))
2285 (setq r (concat r "@<br/>")))
2286 r))))
2288 (defvar htmlize-buffer-places) ; from htmlize.el
2289 (defun org-export-htmlize-region-for-paste (beg end)
2290 "Convert the region to HTML, using htmlize.el.
2291 This is much like `htmlize-region-for-paste', only that it uses
2292 the settings define in the org-... variables."
2293 (let* ((htmlize-output-type org-export-htmlize-output-type)
2294 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
2295 (htmlbuf (htmlize-region beg end)))
2296 (unwind-protect
2297 (with-current-buffer htmlbuf
2298 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
2299 (plist-get htmlize-buffer-places 'content-end)))
2300 (kill-buffer htmlbuf))))
2302 ;;;###autoload
2303 (defun org-export-htmlize-generate-css ()
2304 "Create the CSS for all font definitions in the current Emacs session.
2305 Use this to create face definitions in your CSS style file that can then
2306 be used by code snippets transformed by htmlize.
2307 This command just produces a buffer that contains class definitions for all
2308 faces used in the current Emacs session. You can copy and paste the ones you
2309 need into your CSS file.
2311 If you then set `org-export-htmlize-output-type' to `css', calls to
2312 the function `org-export-htmlize-region-for-paste' will produce code
2313 that uses these same face definitions."
2314 (interactive)
2315 (require 'htmlize)
2316 (and (get-buffer "*html*") (kill-buffer "*html*"))
2317 (with-temp-buffer
2318 (let ((fl (face-list))
2319 (htmlize-css-name-prefix "org-")
2320 (htmlize-output-type 'css)
2321 f i)
2322 (while (setq f (pop fl)
2323 i (and f (face-attribute f :inherit)))
2324 (when (and (symbolp f) (or (not i) (not (listp i))))
2325 (insert (org-add-props (copy-sequence "1") nil 'face f))))
2326 (htmlize-region (point-min) (point-max))))
2327 (org-pop-to-buffer-same-window "*html*")
2328 (goto-char (point-min))
2329 (if (re-search-forward "<style" nil t)
2330 (delete-region (point-min) (match-beginning 0)))
2331 (if (re-search-forward "</style>" nil t)
2332 (delete-region (1+ (match-end 0)) (point-max)))
2333 (beginning-of-line 1)
2334 (if (looking-at " +") (replace-match ""))
2335 (goto-char (point-min)))
2337 (defun org-html-protect (s)
2338 "Convert characters to HTML equivalent.
2339 Possible conversions are set in `org-export-html-protect-char-alist'."
2340 (let ((cl org-export-html-protect-char-alist) c)
2341 (while (setq c (pop cl))
2342 (let ((start 0))
2343 (while (string-match (car c) s start)
2344 (setq s (replace-match (cdr c) t t s)
2345 start (1+ (match-beginning 0))))))
2348 (defun org-html-expand (string)
2349 "Prepare STRING for HTML export. Apply all active conversions.
2350 If there are links in the string, don't modify these. If STRING
2351 is nil, return nil."
2352 (when string
2353 (let* ((re (concat org-bracket-link-regexp "\\|"
2354 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2355 m s l res)
2356 (while (setq m (string-match re string))
2357 (setq s (substring string 0 m)
2358 l (match-string 0 string)
2359 string (substring string (match-end 0)))
2360 (push (org-html-do-expand s) res)
2361 (push l res))
2362 (push (org-html-do-expand string) res)
2363 (apply 'concat (nreverse res)))))
2365 (defun org-html-do-expand (s)
2366 "Apply all active conversions to translate special ASCII to HTML."
2367 (setq s (org-html-protect s))
2368 (if org-export-html-expand
2369 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
2370 (setq s (replace-match "<\\1>" t nil s))))
2371 (if org-export-with-emphasize
2372 (setq s (org-export-html-convert-emphasize s)))
2373 (if org-export-with-special-strings
2374 (setq s (org-export-html-convert-special-strings s)))
2375 (if org-export-with-sub-superscripts
2376 (setq s (org-export-html-convert-sub-super s)))
2377 (if org-export-with-TeX-macros
2378 (let ((start 0) wd rep)
2379 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2380 s start))
2381 (if (get-text-property (match-beginning 0) 'org-protected s)
2382 (setq start (match-end 0))
2383 (setq wd (match-string 1 s))
2384 (if (setq rep (org-entity-get-representation wd 'html))
2385 (setq s (replace-match rep t t s))
2386 (setq start (+ start (length wd))))))))
2389 (defun org-export-html-convert-special-strings (string)
2390 "Convert special characters in STRING to HTML."
2391 (let ((all org-export-html-special-string-regexps)
2392 e a re rpl start)
2393 (while (setq a (pop all))
2394 (setq re (car a) rpl (cdr a) start 0)
2395 (while (string-match re string start)
2396 (if (get-text-property (match-beginning 0) 'org-protected string)
2397 (setq start (match-end 0))
2398 (setq string (replace-match rpl t nil string)))))
2399 string))
2401 (defun org-export-html-convert-sub-super (string)
2402 "Convert sub- and superscripts in STRING to HTML."
2403 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
2404 (while (string-match org-match-substring-regexp string s)
2405 (cond
2406 ((and requireb (match-end 8)) (setq s (match-end 2)))
2407 ((get-text-property (match-beginning 2) 'org-protected string)
2408 (setq s (match-end 2)))
2410 (setq s (match-end 1)
2411 key (if (string= (match-string 2 string) "_") "sub" "sup")
2412 c (or (match-string 8 string)
2413 (match-string 6 string)
2414 (match-string 5 string))
2415 string (replace-match
2416 (concat (match-string 1 string)
2417 "<" key ">" c "</" key ">")
2418 t t string)))))
2419 (while (string-match "\\\\\\([_^]\\)" string)
2420 (setq string (replace-match (match-string 1 string) t t string)))
2421 string))
2423 (defun org-export-html-convert-emphasize (string)
2424 "Apply emphasis."
2425 (let ((s 0) rpl)
2426 (while (string-match org-emph-re string s)
2427 (if (not (equal
2428 (substring string (match-beginning 3) (1+ (match-beginning 3)))
2429 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
2430 (setq s (match-beginning 0)
2432 (concat
2433 (match-string 1 string)
2434 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
2435 (match-string 4 string)
2436 (nth 3 (assoc (match-string 3 string)
2437 org-emphasis-alist))
2438 (match-string 5 string))
2439 string (replace-match rpl t t string)
2440 s (+ s (- (length rpl) 2)))
2441 (setq s (1+ s))))
2442 string))
2444 (defun org-open-par ()
2445 "Insert <p>, but first close previous paragraph if any."
2446 (org-close-par-maybe)
2447 (insert "\n<p>")
2448 (setq org-par-open t))
2449 (defun org-close-par-maybe ()
2450 "Close paragraph if there is one open."
2451 (when org-par-open
2452 (insert "</p>")
2453 (setq org-par-open nil)))
2454 (defun org-close-li (&optional type)
2455 "Close <li> if necessary."
2456 (org-close-par-maybe)
2457 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
2459 (defvar body-only) ; dynamically scoped into this.
2460 (defun org-html-level-start (level title umax with-toc head-count &optional opt-plist)
2461 "Insert a new level in HTML export.
2462 When TITLE is nil, just close all open levels."
2463 (org-close-par-maybe)
2464 (let* ((target (and title (org-get-text-property-any 0 'target title)))
2465 (extra-targets (and target
2466 (assoc target org-export-target-aliases)))
2467 (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
2468 (preferred (and target
2469 (cdr (assoc target org-export-preferred-target-alist))))
2470 (l org-level-max)
2471 (num (plist-get opt-plist :section-numbers))
2472 snumber snu href suffix)
2473 (setq extra-targets (remove (or preferred target) extra-targets))
2474 (setq extra-targets
2475 (mapconcat (lambda (x)
2476 (setq x (org-solidify-link-text
2477 (if (org-uuidgen-p x) (concat "ID-" x) x)))
2478 (if (stringp org-export-html-headline-anchor-format)
2479 (format org-export-html-headline-anchor-format x x)
2480 ""))
2481 extra-targets
2482 ""))
2483 (while (>= l level)
2484 (if (aref org-levels-open (1- l))
2485 (progn
2486 (org-html-level-close l umax)
2487 (aset org-levels-open (1- l) nil)))
2488 (setq l (1- l)))
2489 (when title
2490 ;; If title is nil, this means this function is called to close
2491 ;; all levels, so the rest is done only if title is given
2492 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2493 (setq title (replace-match
2494 (if org-export-with-tags
2495 (save-match-data
2496 (concat
2497 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
2498 (mapconcat
2499 (lambda (x)
2500 (format "<span class=\"%s\">%s</span>"
2501 (org-export-html-get-tag-class-name x)
2503 (org-split-string (match-string 1 title) ":")
2504 "&nbsp;")
2505 "</span>"))
2507 t t title)))
2508 (if (> level umax)
2509 (progn
2510 (if (aref org-levels-open (1- level))
2511 (progn
2512 (org-close-li)
2513 (if target
2514 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2515 extra-targets title "<br/>\n")
2516 (insert "<li>" title "<br/>\n")))
2517 (aset org-levels-open (1- level) t)
2518 (org-close-par-maybe)
2519 (if target
2520 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2521 extra-targets title "<br/>\n")
2522 (insert "<ul>\n<li>" title "<br/>\n"))))
2523 (aset org-levels-open (1- level) t)
2524 (setq snumber (org-section-number level)
2525 snu (replace-regexp-in-string "\\." "-" snumber))
2526 (setq level (+ level org-export-html-toplevel-hlevel -1))
2527 (if (and num (not body-only))
2528 (setq title (concat
2529 (format "<span class=\"section-number-%d\">%s</span>"
2530 level
2531 (if (and num
2532 (if (integerp num)
2533 ;; fix up num to take into
2534 ;; account the top-level
2535 ;; heading value
2536 (>= (+ num org-export-html-toplevel-hlevel -1)
2537 level)
2538 num))
2539 snumber
2540 ""))
2541 " " title)))
2542 (unless (= head-count 1) (insert "\n</div>\n"))
2543 (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
2544 (setq suffix (org-solidify-link-text (or href snu)))
2545 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2546 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d%s\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
2547 suffix level (if extra-class (concat " " extra-class) "")
2548 level href
2549 extra-targets
2550 title level level suffix))
2551 (org-open-par)))))
2553 (defun org-export-html-get-tag-class-name (tag)
2554 "Turn tag into a valid class name.
2555 Replaces invalid characters with \"_\" and then prepends a prefix."
2556 (save-match-data
2557 (while (string-match "[^a-zA-Z0-9_]" tag)
2558 (setq tag (replace-match "_" t t tag))))
2559 (concat org-export-html-tag-class-prefix tag))
2561 (defun org-export-html-get-todo-kwd-class-name (kwd)
2562 "Turn todo keyword into a valid class name.
2563 Replaces invalid characters with \"_\" and then prepends a prefix."
2564 (save-match-data
2565 (while (string-match "[^a-zA-Z0-9_]" kwd)
2566 (setq kwd (replace-match "_" t t kwd))))
2567 (concat org-export-html-todo-kwd-class-prefix kwd))
2569 (defun org-html-level-close (level max-outline-level)
2570 "Terminate one level in HTML export."
2571 (if (<= level max-outline-level)
2572 (insert "</div>\n")
2573 (org-close-li)
2574 (insert "</ul>\n")))
2576 (defun org-html-export-list-line (line pos struct prevs)
2577 "Insert list syntax in export buffer. Return LINE, maybe modified.
2579 POS is the item position or line position the line had before
2580 modifications to buffer. STRUCT is the list structure. PREVS is
2581 the alist of previous items."
2582 (let* ((get-type
2583 (function
2584 ;; Translate type of list containing POS to "d", "o" or
2585 ;; "u".
2586 (lambda (pos struct prevs)
2587 (let ((type (org-list-get-list-type pos struct prevs)))
2588 (cond
2589 ((eq 'ordered type) "o")
2590 ((eq 'descriptive type) "d")
2591 (t "u"))))))
2592 (get-closings
2593 (function
2594 ;; Return list of all items and sublists ending at POS, in
2595 ;; reverse order.
2596 (lambda (pos)
2597 (let (out)
2598 (catch 'exit
2599 (mapc (lambda (e)
2600 (let ((end (nth 6 e))
2601 (item (car e)))
2602 (cond
2603 ((= end pos) (push item out))
2604 ((>= item pos) (throw 'exit nil)))))
2605 struct))
2606 out)))))
2607 ;; First close any previous item, or list, ending at POS.
2608 (mapc (lambda (e)
2609 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2610 (first-item (org-list-get-list-begin e struct prevs))
2611 (type (funcall get-type first-item struct prevs)))
2612 (org-close-par-maybe)
2613 ;; Ending for every item
2614 (org-close-li type)
2615 ;; We're ending last item of the list: end list.
2616 (when lastp
2617 (insert (format "</%sl>\n" type))
2618 (org-open-par))))
2619 (funcall get-closings pos))
2620 (cond
2621 ;; At an item: insert appropriate tags in export buffer.
2622 ((assq pos struct)
2623 (string-match
2624 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2625 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
2626 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2627 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2628 "\\(.*\\)") line)
2629 (let* ((checkbox (match-string 3 line))
2630 (desc-tag (or (match-string 4 line) "???"))
2631 (body (or (match-string 5 line) ""))
2632 (list-beg (org-list-get-list-begin pos struct prevs))
2633 (firstp (= list-beg pos))
2634 ;; Always refer to first item to determine list type, in
2635 ;; case list is ill-formed.
2636 (type (funcall get-type list-beg struct prevs))
2637 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2638 (cond
2639 ((not count-tmp) nil)
2640 ((string-match "[A-Za-z]" count-tmp)
2641 (- (string-to-char (upcase count-tmp)) 64))
2642 ((string-match "[0-9]+" count-tmp)
2643 count-tmp)))))
2644 (when firstp
2645 (org-close-par-maybe)
2646 (insert (format "<%sl>\n" type)))
2647 (insert (cond
2648 ((equal type "d")
2649 (format "<dt>%s</dt><dd>" desc-tag))
2650 ((and (equal type "o") counter)
2651 (format "<li value=\"%s\">" counter))
2652 (t "<li>")))
2653 ;; If line had a checkbox, some additional modification is required.
2654 (when checkbox
2655 (setq body
2656 (concat
2657 (cond
2658 ((string-match "X" checkbox) "<code>[X]</code> ")
2659 ((string-match " " checkbox) "<code>[&nbsp;]</code> ")
2660 (t "<code>[-]</code> "))
2661 body)))
2662 ;; Return modified line
2663 body))
2664 ;; At a list ender: go to next line (side-effects only).
2665 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2666 ;; Not at an item: return line unchanged (side-effects only).
2667 (t line))))
2669 (provide 'org-html)
2671 ;;; org-html.el ends here