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