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