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