HTML export: correct a bug in coderef link.
[org-mode.git] / lisp / org-html.el
blob5d53478806cbf6a687fcf8077e7919a692a451bf
1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 ;;; Hooks
610 (defvar org-export-html-after-blockquotes-hook nil
611 "Hook run during HTML export, after blockquote, verse, center are done.")
613 (defvar org-export-html-final-hook nil
614 "Hook run at the end of HTML export, in the new buffer.")
616 ;;; HTML export
618 (defun org-export-html-preprocess (parameters)
619 "Convert LaTeX fragments to images."
620 (when (and org-current-export-file
621 (plist-get parameters :LaTeX-fragments))
622 (org-format-latex
623 (concat "ltxpng/" (file-name-sans-extension
624 (file-name-nondirectory
625 org-current-export-file)))
626 org-current-export-dir nil "Creating LaTeX image %s"
627 nil nil
628 (cond
629 ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
630 ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
631 ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
632 ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
633 (t nil))))
634 (goto-char (point-min))
635 (let (label l1)
636 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
637 (org-if-unprotected-at (match-beginning 1)
638 (setq label (match-string 1))
639 (save-match-data
640 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
641 (setq l1 (substring label (match-beginning 1)))
642 (setq l1 label)))
643 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
645 ;;;###autoload
646 (defun org-export-as-html-and-open (arg)
647 "Export the outline as HTML and immediately open it with a browser.
648 If there is an active region, export only the region.
649 The prefix ARG specifies how many levels of the outline should become
650 headlines. The default is 3. Lower levels will become bulleted lists."
651 (interactive "P")
652 (org-export-as-html arg 'hidden)
653 (org-open-file buffer-file-name)
654 (when org-export-kill-product-buffer-when-displayed
655 (kill-buffer (current-buffer))))
657 ;;;###autoload
658 (defun org-export-as-html-batch ()
659 "Call the function `org-export-as-html'.
660 This function can be used in batch processing as:
661 emacs --batch
662 --load=$HOME/lib/emacs/org.el
663 --eval \"(setq org-export-headline-levels 2)\"
664 --visit=MyFile --funcall org-export-as-html-batch"
665 (org-export-as-html org-export-headline-levels 'hidden))
667 ;;;###autoload
668 (defun org-export-as-html-to-buffer (arg)
669 "Call `org-export-as-html` with output to a temporary buffer.
670 No file is created. The prefix ARG is passed through to `org-export-as-html'."
671 (interactive "P")
672 (org-export-as-html arg nil nil "*Org HTML Export*")
673 (when org-export-show-temporary-export-buffer
674 (switch-to-buffer-other-window "*Org HTML Export*")))
676 ;;;###autoload
677 (defun org-replace-region-by-html (beg end)
678 "Assume the current region has org-mode syntax, and convert it to HTML.
679 This can be used in any buffer. For example, you could write an
680 itemized list in org-mode syntax in an HTML buffer and then use this
681 command to convert it."
682 (interactive "r")
683 (let (reg html buf pop-up-frames)
684 (save-window-excursion
685 (if (org-mode-p)
686 (setq html (org-export-region-as-html
687 beg end t 'string))
688 (setq reg (buffer-substring beg end)
689 buf (get-buffer-create "*Org tmp*"))
690 (with-current-buffer buf
691 (erase-buffer)
692 (insert reg)
693 (org-mode)
694 (setq html (org-export-region-as-html
695 (point-min) (point-max) t 'string)))
696 (kill-buffer buf)))
697 (delete-region beg end)
698 (insert html)))
700 ;;;###autoload
701 (defun org-export-region-as-html (beg end &optional body-only buffer)
702 "Convert region from BEG to END in org-mode buffer to HTML.
703 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
704 contents, and only produce the region of converted text, useful for
705 cut-and-paste operations.
706 If BUFFER is a buffer or a string, use/create that buffer as a target
707 of the converted HTML. If BUFFER is the symbol `string', return the
708 produced HTML as a string and leave not buffer behind. For example,
709 a Lisp program could call this function in the following way:
711 (setq html (org-export-region-as-html beg end t 'string))
713 When called interactively, the output buffer is selected, and shown
714 in a window. A non-interactive call will only return the buffer."
715 (interactive "r\nP")
716 (when (interactive-p)
717 (setq buffer "*Org HTML Export*"))
718 (let ((transient-mark-mode t) (zmacs-regions t)
719 ext-plist rtn)
720 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
721 (goto-char end)
722 (set-mark (point)) ;; to activate the region
723 (goto-char beg)
724 (setq rtn (org-export-as-html
725 nil nil ext-plist
726 buffer body-only))
727 (if (fboundp 'deactivate-mark) (deactivate-mark))
728 (if (and (interactive-p) (bufferp rtn))
729 (switch-to-buffer-other-window rtn)
730 rtn)))
732 (defvar html-table-tag nil) ; dynamically scoped into this.
733 (defvar org-par-open nil)
735 ;;; org-html-cvt-link-fn
736 (defconst org-html-cvt-link-fn
738 "Function to convert link URLs to exportable URLs.
739 Takes two arguments, TYPE and PATH.
740 Returns exportable url as (TYPE PATH), or nil to signal that it
741 didn't handle this case.
742 Intended to be locally bound around a call to `org-export-as-html'." )
744 (defun org-html-cvt-org-as-html (opt-plist type path)
745 "Convert an org filename to an equivalent html filename.
746 If TYPE is not file, just return `nil'.
747 See variable `org-export-html-link-org-files-as-html'"
749 (save-match-data
750 (and
751 org-export-html-link-org-files-as-html
752 (string= type "file")
753 (string-match "\\.org$" path)
754 (progn
755 (list
756 "file"
757 (concat
758 (substring path 0 (match-beginning 0))
760 (plist-get opt-plist :html-extension)))))))
763 ;;; org-html-should-inline-p
764 (defun org-html-should-inline-p (filename descp)
765 "Return non-nil if link FILENAME should be inlined.
766 The decision to inline the FILENAME link is based on the current
767 settings. DESCP is the boolean of whether there was a link
768 description. See variables `org-export-html-inline-images' and
769 `org-export-html-inline-image-extensions'."
770 (declare (special
771 org-export-html-inline-images
772 org-export-html-inline-image-extensions))
773 (and (or (eq t org-export-html-inline-images)
774 (and org-export-html-inline-images (not descp)))
775 (org-file-image-p
776 filename org-export-html-inline-image-extensions)))
778 ;;; org-html-make-link
779 (defun org-html-make-link (opt-plist type path fragment desc attr
780 may-inline-p)
781 "Make an HTML link.
782 OPT-PLIST is an options list.
783 TYPE is the device-type of the link (THIS://foo.html)
784 PATH is the path of the link (http://THIS#locationx)
785 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
786 DESC is the link description, if any.
787 ATTR is a string of other attributes of the a element.
788 MAY-INLINE-P allows inlining it as an image."
790 (declare (special org-par-open))
791 (save-match-data
792 (let* ((filename path)
793 ;;First pass. Just sanity stuff.
794 (components-1
795 (cond
796 ((string= type "file")
797 (list
798 type
799 ;;Substitute just if original path was absolute.
800 ;;(Otherwise path must remain relative)
801 (if (file-name-absolute-p path)
802 (concat "file://" (expand-file-name path))
803 path)))
804 ((string= type "")
805 (list nil path))
806 (t (list type path))))
808 ;;Second pass. Components converted so they can refer
809 ;;to a remote site.
810 (components-2
812 (and org-html-cvt-link-fn
813 (apply org-html-cvt-link-fn
814 opt-plist components-1))
815 (apply #'org-html-cvt-org-as-html
816 opt-plist components-1)
817 components-1))
818 (type (first components-2))
819 (thefile (second components-2)))
822 ;;Third pass. Build final link except for leading type
823 ;;spec.
824 (cond
825 ((or
826 (not type)
827 (string= type "http")
828 (string= type "https")
829 (string= type "file")
830 (string= type "coderef"))
831 (if fragment
832 (setq thefile (concat thefile "#" fragment))))
834 (t))
836 ;;Final URL-build, for all types.
837 (setq thefile
838 (let
839 ((str (org-export-html-format-href thefile)))
840 (if (and type (not (or (string= "file" type)
841 (string= "coderef" type))))
842 (concat type ":" str)
843 str)))
845 (if (and
846 may-inline-p
847 ;;Can't inline a URL with a fragment.
848 (not fragment))
849 (progn
850 (message "image %s %s" thefile org-par-open)
851 (org-export-html-format-image thefile org-par-open))
852 (concat
853 "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
854 (org-export-html-format-desc desc)
855 "</a>")))))
857 (defun org-html-handle-links (line opt-plist)
858 "Return LINE with markup of Org mode links.
859 OPT-PLIST is the export options list."
860 (let ((start 0)
861 (current-dir (if buffer-file-name
862 (file-name-directory buffer-file-name)
863 default-directory))
864 (link-validate (plist-get opt-plist :link-validation-function))
865 type id-file fnc
866 rpl path attr desc descp desc1 desc2 link)
867 (while (string-match org-bracket-link-analytic-regexp++ line start)
868 (setq start (match-beginning 0))
869 (setq path (save-match-data (org-link-unescape
870 (match-string 3 line))))
871 (setq type (cond
872 ((match-end 2) (match-string 2 line))
873 ((save-match-data
874 (or (file-name-absolute-p path)
875 (string-match "^\\.\\.?/" path)))
876 "file")
877 (t "internal")))
878 (setq path (org-extract-attributes (org-link-unescape path)))
879 (setq attr (get-text-property 0 'org-attributes path))
880 (setq desc1 (if (match-end 5) (match-string 5 line))
881 desc2 (if (match-end 2) (concat type ":" path) path)
882 descp (and desc1 (not (equal desc1 desc2)))
883 desc (or desc1 desc2))
884 ;; Make an image out of the description if that is so wanted
885 (when (and descp (org-file-image-p
886 desc org-export-html-inline-image-extensions))
887 (save-match-data
888 (if (string-match "^file:" desc)
889 (setq desc (substring desc (match-end 0)))))
890 (setq desc (org-add-props
891 (concat "<img src=\"" desc "\"/>")
892 '(org-protected t))))
893 (cond
894 ((equal type "internal")
895 (let
896 ((frag-0
897 (if (= (string-to-char path) ?#)
898 (substring path 1)
899 path)))
900 (setq rpl
901 (org-html-make-link
902 opt-plist
905 (org-solidify-link-text
906 (save-match-data (org-link-unescape frag-0))
907 nil)
908 desc attr nil))))
909 ((and (equal type "id")
910 (setq id-file (org-id-find-id-file path)))
911 ;; This is an id: link to another file (if it was the same file,
912 ;; it would have become an internal link...)
913 (save-match-data
914 (setq id-file (file-relative-name
915 id-file
916 (file-name-directory org-current-export-file)))
917 (setq rpl
918 (org-html-make-link opt-plist
919 "file" id-file
920 (concat (if (org-uuidgen-p path) "ID-") path)
921 desc
922 attr
923 nil))))
924 ((member type '("http" "https"))
925 ;; standard URL, can inline as image
926 (setq rpl
927 (org-html-make-link opt-plist
928 type path nil
929 desc
930 attr
931 (org-html-should-inline-p path descp))))
932 ((member type '("ftp" "mailto" "news"))
933 ;; standard URL, can't inline as image
934 (setq rpl
935 (org-html-make-link opt-plist
936 type path nil
937 desc
938 attr
939 nil)))
941 ((string= type "coderef")
942 (let*
943 ((coderef-str (format "coderef-%s" path))
944 (attr-1
945 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
946 coderef-str coderef-str)))
947 (setq rpl
948 (org-html-make-link opt-plist
949 type "" coderef-str
950 (format
951 (org-export-get-coderef-format
952 path
953 (and descp desc))
954 (cdr (assoc path org-export-code-refs)))
955 attr-1
956 nil))))
958 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
959 ;; The link protocol has a function for format the link
960 (setq rpl
961 (save-match-data
962 (funcall fnc (org-link-unescape path) desc1 'html))))
964 ((string= type "file")
965 ;; FILE link
966 (save-match-data
967 (let*
968 ((components
970 (string-match "::\\(.*\\)" path)
971 (list
972 (replace-match "" t nil path)
973 (match-string 1 path))
974 (list path nil)))
976 ;;The proper path, without a fragment
977 (path-1
978 (first components))
980 ;;The raw fragment
981 (fragment-0
982 (second components))
984 ;;Check the fragment. If it can't be used as
985 ;;target fragment we'll pass nil instead.
986 (fragment-1
988 (and fragment-0
989 (not (string-match "^[0-9]*$" fragment-0))
990 (not (string-match "^\\*" fragment-0))
991 (not (string-match "^/.*/$" fragment-0)))
992 (org-solidify-link-text
993 (org-link-unescape fragment-0))
994 nil))
995 (desc-2
996 ;;Description minus "file:" and ".org"
997 (if (string-match "^file:" desc)
998 (let
999 ((desc-1 (replace-match "" t t desc)))
1000 (if (string-match "\\.org$" desc-1)
1001 (replace-match "" t t desc-1)
1002 desc-1))
1003 desc)))
1005 (setq rpl
1007 (and
1008 (functionp link-validate)
1009 (not (funcall link-validate path-1 current-dir)))
1010 desc
1011 (org-html-make-link opt-plist
1012 "file" path-1 fragment-1 desc-2 attr
1013 (org-html-should-inline-p path-1 descp)))))))
1016 ;; just publish the path, as default
1017 (setq rpl (concat "@<i>&lt;" type ":"
1018 (save-match-data (org-link-unescape path))
1019 "&gt;@</i>"))))
1020 (setq line (replace-match rpl t t line)
1021 start (+ start (length rpl))))
1022 line))
1024 ;;; org-export-as-html
1025 ;;;###autoload
1026 (defun org-export-as-html (arg &optional hidden ext-plist
1027 to-buffer body-only pub-dir)
1028 "Export the outline as a pretty HTML file.
1029 If there is an active region, export only the region. The prefix
1030 ARG specifies how many levels of the outline should become
1031 headlines. The default is 3. Lower levels will become bulleted
1032 lists. HIDDEN is obsolete and does nothing.
1033 EXT-PLIST is a property list with external parameters overriding
1034 org-mode's default settings, but still inferior to file-local
1035 settings. When TO-BUFFER is non-nil, create a buffer with that
1036 name and export to that buffer. If TO-BUFFER is the symbol
1037 `string', don't leave any buffer behind but just return the
1038 resulting HTML as a string. When BODY-ONLY is set, don't produce
1039 the file header and footer, simply return the content of
1040 <body>...</body>, without even the body tags themselves. When
1041 PUB-DIR is set, use this as the publishing directory."
1042 (interactive "P")
1043 (run-hooks 'org-export-first-hook)
1045 ;; Make sure we have a file name when we need it.
1046 (when (and (not (or to-buffer body-only))
1047 (not buffer-file-name))
1048 (if (buffer-base-buffer)
1049 (org-set-local 'buffer-file-name
1050 (with-current-buffer (buffer-base-buffer)
1051 buffer-file-name))
1052 (error "Need a file name to be able to export")))
1054 (message "Exporting...")
1055 (setq-default org-todo-line-regexp org-todo-line-regexp)
1056 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
1057 (setq-default org-done-keywords org-done-keywords)
1058 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
1059 (let* ((opt-plist
1060 (org-export-process-option-filters
1061 (org-combine-plists (org-default-export-plist)
1062 ext-plist
1063 (org-infile-export-plist))))
1064 (body-only (or body-only (plist-get opt-plist :body-only)))
1065 (style (concat (if (plist-get opt-plist :style-include-default)
1066 org-export-html-style-default)
1067 (plist-get opt-plist :style)
1068 (plist-get opt-plist :style-extra)
1069 "\n"
1070 (if (plist-get opt-plist :style-include-scripts)
1071 org-export-html-scripts)))
1072 (html-extension (plist-get opt-plist :html-extension))
1073 valid thetoc have-headings first-heading-pos
1074 (odd org-odd-levels-only)
1075 (region-p (org-region-active-p))
1076 (rbeg (and region-p (region-beginning)))
1077 (rend (and region-p (region-end)))
1078 (subtree-p
1079 (if (plist-get opt-plist :ignore-subtree-p)
1081 (when region-p
1082 (save-excursion
1083 (goto-char rbeg)
1084 (and (org-at-heading-p)
1085 (>= (org-end-of-subtree t t) rend))))))
1086 (level-offset (if subtree-p
1087 (save-excursion
1088 (goto-char rbeg)
1089 (+ (funcall outline-level)
1090 (if org-odd-levels-only 1 0)))
1092 (opt-plist (setq org-export-opt-plist
1093 (if subtree-p
1094 (org-export-add-subtree-options opt-plist rbeg)
1095 opt-plist)))
1096 ;; The following two are dynamically scoped into other
1097 ;; routines below.
1098 (org-current-export-dir
1099 (or pub-dir (org-export-directory :html opt-plist)))
1100 (org-current-export-file buffer-file-name)
1101 (level 0) (line "") (origline "") txt todo
1102 (umax nil)
1103 (umax-toc nil)
1104 (filename (if to-buffer nil
1105 (expand-file-name
1106 (concat
1107 (file-name-sans-extension
1108 (or (and subtree-p
1109 (org-entry-get (region-beginning)
1110 "EXPORT_FILE_NAME" t))
1111 (file-name-nondirectory buffer-file-name)))
1112 "." html-extension)
1113 (file-name-as-directory
1114 (or pub-dir (org-export-directory :html opt-plist))))))
1115 (current-dir (if buffer-file-name
1116 (file-name-directory buffer-file-name)
1117 default-directory))
1118 (buffer (if to-buffer
1119 (cond
1120 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
1121 (t (get-buffer-create to-buffer)))
1122 (find-file-noselect filename)))
1123 (org-levels-open (make-vector org-level-max nil))
1124 (date (plist-get opt-plist :date))
1125 (author (plist-get opt-plist :author))
1126 (html-validation-link (or org-export-html-validation-link ""))
1127 (title (org-html-expand
1128 (or (and subtree-p (org-export-get-title-from-subtree))
1129 (plist-get opt-plist :title)
1130 (and (not body-only)
1131 (not
1132 (plist-get opt-plist :skip-before-1st-heading))
1133 (org-export-grab-title-from-buffer))
1134 (and buffer-file-name
1135 (file-name-sans-extension
1136 (file-name-nondirectory buffer-file-name)))
1137 "UNTITLED")))
1138 (link-up (and (plist-get opt-plist :link-up)
1139 (string-match "\\S-" (plist-get opt-plist :link-up))
1140 (plist-get opt-plist :link-up)))
1141 (link-home (and (plist-get opt-plist :link-home)
1142 (string-match "\\S-" (plist-get opt-plist :link-home))
1143 (plist-get opt-plist :link-home)))
1144 (dummy (setq opt-plist (plist-put opt-plist :title title)))
1145 (html-table-tag (plist-get opt-plist :html-table-tag))
1146 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1147 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
1148 (inquote nil)
1149 (infixed nil)
1150 (inverse nil)
1151 (email (plist-get opt-plist :email))
1152 (language (plist-get opt-plist :language))
1153 (keywords (plist-get opt-plist :keywords))
1154 (description (plist-get opt-plist :description))
1155 (num (plist-get opt-plist :section-numbers))
1156 (lang-words nil)
1157 (head-count 0) cnt
1158 (start 0)
1159 (coding-system (and (boundp 'buffer-file-coding-system)
1160 buffer-file-coding-system))
1161 (coding-system-for-write (or org-export-html-coding-system
1162 coding-system))
1163 (save-buffer-coding-system (or org-export-html-coding-system
1164 coding-system))
1165 (charset (and coding-system-for-write
1166 (fboundp 'coding-system-get)
1167 (coding-system-get coding-system-for-write
1168 'mime-charset)))
1169 (region
1170 (buffer-substring
1171 (if region-p (region-beginning) (point-min))
1172 (if region-p (region-end) (point-max))))
1173 (org-export-have-math nil)
1174 (lines
1175 (org-split-string
1176 (org-export-preprocess-string
1177 region
1178 :emph-multiline t
1179 :for-backend 'html
1180 :skip-before-1st-heading
1181 (plist-get opt-plist :skip-before-1st-heading)
1182 :drawers (plist-get opt-plist :drawers)
1183 :todo-keywords (plist-get opt-plist :todo-keywords)
1184 :tasks (plist-get opt-plist :tasks)
1185 :tags (plist-get opt-plist :tags)
1186 :priority (plist-get opt-plist :priority)
1187 :footnotes (plist-get opt-plist :footnotes)
1188 :timestamps (plist-get opt-plist :timestamps)
1189 :archived-trees
1190 (plist-get opt-plist :archived-trees)
1191 :select-tags (plist-get opt-plist :select-tags)
1192 :exclude-tags (plist-get opt-plist :exclude-tags)
1193 :add-text
1194 (plist-get opt-plist :text)
1195 :LaTeX-fragments
1196 (plist-get opt-plist :LaTeX-fragments))
1197 "[\r\n]"))
1198 (mathjax
1199 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
1200 (and org-export-have-math
1201 (eq (plist-get opt-plist :LaTeX-fragments) t)))
1203 (org-export-html-mathjax-config
1204 org-export-html-mathjax-template
1205 org-export-html-mathjax-options
1206 (or (plist-get opt-plist :mathjax) ""))
1207 ""))
1208 table-open
1209 table-buffer table-orig-buffer
1211 rpl path attr desc descp desc1 desc2 link
1212 snumber fnc
1213 footnotes footref-seen
1214 href
1217 (let ((inhibit-read-only t))
1218 (org-unmodified
1219 (remove-text-properties (point-min) (point-max)
1220 '(:org-license-to-kill t))))
1222 (message "Exporting...")
1224 (setq org-min-level (org-get-min-level lines level-offset))
1225 (setq org-last-level org-min-level)
1226 (org-init-section-numbers)
1228 (cond
1229 ((and date (string-match "%" date))
1230 (setq date (format-time-string date)))
1231 (date)
1232 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
1234 ;; Get the language-dependent settings
1235 (setq lang-words (or (assoc language org-export-language-setup)
1236 (assoc "en" org-export-language-setup)))
1238 ;; Switch to the output buffer
1239 (set-buffer buffer)
1240 (let ((inhibit-read-only t)) (erase-buffer))
1241 (fundamental-mode)
1242 (org-install-letbind)
1244 (and (fboundp 'set-buffer-file-coding-system)
1245 (set-buffer-file-coding-system coding-system-for-write))
1247 (let ((case-fold-search nil)
1248 (org-odd-levels-only odd))
1249 ;; create local variables for all options, to make sure all called
1250 ;; functions get the correct information
1251 (mapc (lambda (x)
1252 (set (make-local-variable (nth 2 x))
1253 (plist-get opt-plist (car x))))
1254 org-export-plist-vars)
1255 (setq umax (if arg (prefix-numeric-value arg)
1256 org-export-headline-levels))
1257 (setq umax-toc (if (integerp org-export-with-toc)
1258 (min org-export-with-toc umax)
1259 umax))
1260 (unless body-only
1261 ;; File header
1262 (insert (format
1264 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1265 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1266 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1267 lang=\"%s\" xml:lang=\"%s\">
1268 <head>
1269 <title>%s</title>
1270 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1271 <meta name=\"generator\" content=\"Org-mode\"/>
1272 <meta name=\"generated\" content=\"%s\"/>
1273 <meta name=\"author\" content=\"%s\"/>
1274 <meta name=\"description\" content=\"%s\"/>
1275 <meta name=\"keywords\" content=\"%s\"/>
1278 </head>
1279 <body>
1280 <div id=\"content\">
1283 (format
1284 (or (and (stringp org-export-html-xml-declaration)
1285 org-export-html-xml-declaration)
1286 (cdr (assoc html-extension org-export-html-xml-declaration))
1287 (cdr (assoc "html" org-export-html-xml-declaration))
1290 (or charset "iso-8859-1"))
1291 language language
1292 title
1293 (or charset "iso-8859-1")
1294 date author description keywords
1295 style
1296 mathjax
1297 (if (or link-up link-home)
1298 (concat
1299 (format org-export-html-home/up-format
1300 (or link-up link-home)
1301 (or link-home link-up))
1302 "\n")
1303 "")))
1305 ;; insert html preamble
1306 (when (plist-get opt-plist :html-preamble)
1307 (let ((html-pre (plist-get opt-plist :html-preamble)))
1308 (cond ((stringp html-pre)
1309 (insert
1310 (format-spec html-pre `((?t . ,title) (?a . ,author)
1311 (?d . ,date) (?e . ,email)))))
1312 ((functionp html-pre)
1313 (funcall html-pre opt-plist))
1315 (insert
1316 (format-spec
1317 (or (cadr (assoc (nth 0 lang-words)
1318 org-export-html-preamble-format))
1319 (cadr (assoc "en" org-export-html-preamble-format)))
1320 `((?t . ,title) (?a . ,author)
1321 (?d . ,date) (?e . ,email)))))))))
1323 (if (and org-export-with-toc (not body-only))
1324 (progn
1325 (push (format "<h%d>%s</h%d>\n"
1326 org-export-html-toplevel-hlevel
1327 (nth 3 lang-words)
1328 org-export-html-toplevel-hlevel)
1329 thetoc)
1330 (push "<div id=\"text-table-of-contents\">\n" thetoc)
1331 (push "<ul>\n<li>" thetoc)
1332 (setq lines
1333 (mapcar '(lambda (line)
1334 (if (and (string-match org-todo-line-regexp line)
1335 (not (get-text-property 0 'org-protected line)))
1336 ;; This is a headline
1337 (progn
1338 (setq have-headings t)
1339 (setq level (- (match-end 1) (match-beginning 1)
1340 level-offset)
1341 level (org-tr-level level)
1342 txt (save-match-data
1343 (org-html-expand
1344 (org-export-cleanup-toc-line
1345 (match-string 3 line))))
1346 todo
1347 (or (and org-export-mark-todo-in-toc
1348 (match-beginning 2)
1349 (not (member (match-string 2 line)
1350 org-done-keywords)))
1351 ; TODO, not DONE
1352 (and org-export-mark-todo-in-toc
1353 (= level umax-toc)
1354 (org-search-todo-below
1355 line lines level))))
1356 (if (string-match
1357 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
1358 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
1359 (if (string-match quote-re0 txt)
1360 (setq txt (replace-match "" t t txt)))
1361 (setq snumber (org-section-number level))
1362 (if (and num (if (integerp num)
1363 (>= num level)
1364 num))
1365 (setq txt (concat snumber " " txt)))
1366 (if (<= level (max umax umax-toc))
1367 (setq head-count (+ head-count 1)))
1368 (if (<= level umax-toc)
1369 (progn
1370 (if (> level org-last-level)
1371 (progn
1372 (setq cnt (- level org-last-level))
1373 (while (>= (setq cnt (1- cnt)) 0)
1374 (push "\n<ul>\n<li>" thetoc))
1375 (push "\n" thetoc)))
1376 (if (< level org-last-level)
1377 (progn
1378 (setq cnt (- org-last-level level))
1379 (while (>= (setq cnt (1- cnt)) 0)
1380 (push "</li>\n</ul>" thetoc))
1381 (push "\n" thetoc)))
1382 ;; Check for targets
1383 (while (string-match org-any-target-regexp line)
1384 (setq line (replace-match
1385 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
1386 t t line)))
1387 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
1388 (setq txt (replace-match "" t t txt)))
1389 (setq href
1390 (replace-regexp-in-string
1391 "\\." "_" (format "sec-%s" snumber)))
1392 (setq href (org-solidify-link-text (or (cdr (assoc href org-export-preferred-target-alist)) href)))
1393 (push
1394 (format
1395 (if todo
1396 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1397 "</li>\n<li><a href=\"#%s\">%s</a>")
1398 href txt) thetoc)
1400 (setq org-last-level level))
1402 line)
1403 lines))
1404 (while (> org-last-level (1- org-min-level))
1405 (setq org-last-level (1- org-last-level))
1406 (push "</li>\n</ul>\n" thetoc))
1407 (push "</div>\n" thetoc)
1408 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1410 (setq head-count 0)
1411 (org-init-section-numbers)
1413 (org-open-par)
1415 (while (setq line (pop lines) origline line)
1416 (catch 'nextline
1418 ;; end of quote section?
1419 (when (and inquote (string-match "^\\*+ " line))
1420 (insert "</pre>\n")
1421 (org-open-par)
1422 (setq inquote nil))
1423 ;; inside a quote section?
1424 (when inquote
1425 (insert (org-html-protect line) "\n")
1426 (throw 'nextline nil))
1428 ;; Fixed-width, verbatim lines (examples)
1429 (when (and org-export-with-fixed-width
1430 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
1431 (when (not infixed)
1432 (setq infixed t)
1433 (org-close-par-maybe)
1435 (insert "<pre class=\"example\">\n"))
1436 (insert (org-html-protect (match-string 3 line)) "\n")
1437 (when (or (not lines)
1438 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1439 (car lines))))
1440 (setq infixed nil)
1441 (insert "</pre>\n")
1442 (org-open-par))
1443 (throw 'nextline nil))
1445 ;; Protected HTML
1446 (when (and (get-text-property 0 'org-protected line)
1447 ;; Make sure it is the entire line that is protected
1448 (not (< (or (next-single-property-change
1449 0 'org-protected line) 10000)
1450 (length line))))
1451 (let (par (ind (get-text-property 0 'original-indentation line)))
1452 (when (re-search-backward
1453 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
1454 (setq par (match-string 1))
1455 (replace-match "\\2\n"))
1456 (insert line "\n")
1457 (while (and lines
1458 (or (= (length (car lines)) 0)
1459 (not ind)
1460 (equal ind (get-text-property 0 'original-indentation (car lines))))
1461 (or (= (length (car lines)) 0)
1462 (get-text-property 0 'org-protected (car lines))))
1463 (insert (pop lines) "\n"))
1464 (and par (insert "<p>\n")))
1465 (throw 'nextline nil))
1467 ;; Blockquotes, verse, and center
1468 (when (equal "ORG-BLOCKQUOTE-START" line)
1469 (org-close-par-maybe)
1470 (insert "<blockquote>\n")
1471 (org-open-par)
1472 (throw 'nextline nil))
1473 (when (equal "ORG-BLOCKQUOTE-END" line)
1474 (org-close-par-maybe)
1475 (insert "\n</blockquote>\n")
1476 (org-open-par)
1477 (throw 'nextline nil))
1478 (when (equal "ORG-VERSE-START" line)
1479 (org-close-par-maybe)
1480 (insert "\n<p class=\"verse\">\n")
1481 (setq org-par-open t)
1482 (setq inverse t)
1483 (throw 'nextline nil))
1484 (when (equal "ORG-VERSE-END" line)
1485 (insert "</p>\n")
1486 (setq org-par-open nil)
1487 (org-open-par)
1488 (setq inverse nil)
1489 (throw 'nextline nil))
1490 (when (equal "ORG-CENTER-START" line)
1491 (org-close-par-maybe)
1492 (insert "\n<div style=\"text-align: center\">")
1493 (org-open-par)
1494 (throw 'nextline nil))
1495 (when (equal "ORG-CENTER-END" line)
1496 (org-close-par-maybe)
1497 (insert "\n</div>")
1498 (org-open-par)
1499 (throw 'nextline nil))
1500 (run-hooks 'org-export-html-after-blockquotes-hook)
1501 (when inverse
1502 (let ((i (org-get-string-indentation line)))
1503 (if (> i 0)
1504 (setq line (concat (mapconcat 'identity
1505 (make-list (* 2 i) "\\nbsp") "")
1506 " " (org-trim line))))
1507 (unless (string-match "\\\\\\\\[ \t]*$" line)
1508 (setq line (concat line "\\\\")))))
1510 ;; make targets to anchors
1511 (setq start 0)
1512 (while (string-match
1513 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1514 (cond
1515 ((get-text-property (match-beginning 1) 'org-protected line)
1516 (setq start (match-end 1)))
1517 ((match-end 2)
1518 (setq line (replace-match
1519 (format
1520 "@<a name=\"%s\" id=\"%s\">@</a>"
1521 (org-solidify-link-text (match-string 1 line))
1522 (org-solidify-link-text (match-string 1 line)))
1523 t t line)))
1524 ((and org-export-with-toc (equal (string-to-char line) ?*))
1525 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1526 (setq line (replace-match
1527 (concat "@<span class=\"target\">"
1528 (match-string 1 line) "@</span> ")
1529 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1530 t t line)))
1532 (setq line (replace-match
1533 (concat "@<a name=\""
1534 (org-solidify-link-text (match-string 1 line))
1535 "\" class=\"target\">" (match-string 1 line)
1536 "@</a> ")
1537 t t line)))))
1539 (setq line (org-html-handle-time-stamps line))
1541 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1542 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
1543 ;; Also handle sub_superscripts and checkboxes
1544 (or (string-match org-table-hline-regexp line)
1545 (setq line (org-html-expand line)))
1547 ;; Format the links
1548 (setq line (org-html-handle-links line opt-plist))
1550 ;; TODO items
1551 (if (and (string-match org-todo-line-regexp line)
1552 (match-beginning 2))
1554 (setq line
1555 (concat (substring line 0 (match-beginning 2))
1556 "<span class=\""
1557 (if (member (match-string 2 line)
1558 org-done-keywords)
1559 "done" "todo")
1560 " " (match-string 2 line)
1561 "\"> " (org-export-html-get-todo-kwd-class-name
1562 (match-string 2 line))
1563 "</span>" (substring line (match-end 2)))))
1565 ;; Does this contain a reference to a footnote?
1566 (when org-export-with-footnotes
1567 (setq start 0)
1568 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
1569 (if (get-text-property (match-beginning 2) 'org-protected line)
1570 (setq start (match-end 2))
1571 (let ((n (match-string 2 line)) extra a)
1572 (if (setq a (assoc n footref-seen))
1573 (progn
1574 (setcdr a (1+ (cdr a)))
1575 (setq extra (format ".%d" (cdr a))))
1576 (setq extra "")
1577 (push (cons n 1) footref-seen))
1578 (setq line
1579 (replace-match
1580 (format
1581 (concat "%s"
1582 (format org-export-html-footnote-format
1583 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
1584 (or (match-string 1 line) "") n extra n n)
1585 t t line))))))
1587 (cond
1588 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1589 ;; This is a headline
1590 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1591 level-offset))
1592 txt (match-string 2 line))
1593 (if (string-match quote-re0 txt)
1594 (setq txt (replace-match "" t t txt)))
1595 (if (<= level (max umax umax-toc))
1596 (setq head-count (+ head-count 1)))
1597 (setq first-heading-pos (or first-heading-pos (point)))
1598 (org-html-level-start level txt umax
1599 (and org-export-with-toc (<= level umax))
1600 head-count opt-plist)
1602 ;; QUOTES
1603 (when (string-match quote-re line)
1604 (org-close-par-maybe)
1605 (insert "<pre>")
1606 (setq inquote t)))
1608 ((and org-export-with-tables
1609 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1610 (when (not table-open)
1611 ;; New table starts
1612 (setq table-open t table-buffer nil table-orig-buffer nil))
1614 ;; Accumulate lines
1615 (setq table-buffer (cons line table-buffer)
1616 table-orig-buffer (cons origline table-orig-buffer))
1617 (when (or (not lines)
1618 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1619 (car lines))))
1620 (setq table-open nil
1621 table-buffer (nreverse table-buffer)
1622 table-orig-buffer (nreverse table-orig-buffer))
1623 (org-close-par-maybe)
1624 (insert (org-format-table-html table-buffer table-orig-buffer))))
1626 ;; Normal lines
1629 ;; This line either is list item or end a list.
1630 (when (get-text-property 0 'list-item line)
1631 (setq line (org-html-export-list-line
1632 line
1633 (get-text-property 0 'list-item line)
1634 (get-text-property 0 'list-struct line)
1635 (get-text-property 0 'list-prevs line))))
1637 ;; Horizontal line
1638 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1639 (if org-par-open
1640 (insert "\n</p>\n<hr/>\n<p>\n")
1641 (insert "\n<hr/>\n"))
1642 (throw 'nextline nil))
1644 ;; Empty lines start a new paragraph. If hand-formatted lists
1645 ;; are not fully interpreted, lines starting with "-", "+", "*"
1646 ;; also start a new paragraph.
1647 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
1649 ;; Is this the start of a footnote?
1650 (when org-export-with-footnotes
1651 (when (and (boundp 'footnote-section-tag-regexp)
1652 (string-match (concat "^" footnote-section-tag-regexp)
1653 line))
1654 ;; ignore this line
1655 (throw 'nextline nil))
1656 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1657 (org-close-par-maybe)
1658 (let ((n (match-string 1 line)))
1659 (setq org-par-open t
1660 line (replace-match
1661 (format
1662 (concat "<p class=\"footnote\">"
1663 (format org-export-html-footnote-format
1664 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1665 n n n) t t line)))))
1666 ;; Check if the line break needs to be conserved
1667 (cond
1668 ((string-match "\\\\\\\\[ \t]*$" line)
1669 (setq line (replace-match "<br/>" t t line)))
1670 (org-export-preserve-breaks
1671 (setq line (concat line "<br/>"))))
1673 ;; Check if a paragraph should be started
1674 (let ((start 0))
1675 (while (and org-par-open
1676 (string-match "\\\\par\\>" line start))
1677 ;; Leave a space in the </p> so that the footnote matcher
1678 ;; does not see this.
1679 (if (not (get-text-property (match-beginning 0)
1680 'org-protected line))
1681 (setq line (replace-match "</p ><p >" t t line)))
1682 (setq start (match-end 0))))
1684 (insert line "\n")))))
1686 ;; Properly close all local lists and other lists
1687 (when inquote
1688 (insert "</pre>\n")
1689 (org-open-par))
1691 (org-html-level-start 1 nil umax
1692 (and org-export-with-toc (<= level umax))
1693 head-count opt-plist)
1694 ;; the </div> to close the last text-... div.
1695 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
1697 (save-excursion
1698 (goto-char (point-min))
1699 (while (re-search-forward
1700 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1701 nil t)
1702 (push (match-string 1) footnotes)
1703 (replace-match "\\4" t nil)
1704 (goto-char (match-beginning 0))))
1705 (when footnotes
1706 (insert (format org-export-html-footnotes-section
1707 (nth 4 lang-words)
1708 (mapconcat 'identity (nreverse footnotes) "\n"))
1709 "\n"))
1710 (let ((bib (org-export-html-get-bibliography)))
1711 (when bib
1712 (insert "\n" bib "\n")))
1714 ;; export html postamble
1715 (unless body-only
1716 (let ((html-post (plist-get opt-plist :html-postamble))
1717 (email
1718 (mapconcat (lambda(e)
1719 (format "<a href=\"mailto:%s\">%s</a>" e e))
1720 (split-string email ",+ *")
1721 ", "))
1722 (creator-info
1723 (concat "Org version " org-version " with Emacs version "
1724 (number-to-string emacs-major-version))))
1725 (when (plist-get opt-plist :html-postamble)
1726 (cond ((stringp html-post)
1727 (insert "<div id=\"postamble\">\n")
1728 (insert (format-spec html-post
1729 `((?a . ,author) (?e . ,email)
1730 (?d . ,date) (?c . ,creator-info)
1731 (?v . ,html-validation-link))))
1732 (insert "</div>"))
1733 ((functionp html-post)
1734 (funcall html-post opt-plist))
1735 ((eq html-post 'auto)
1736 ;; fall back on default postamble
1737 (insert "<div id=\"postamble\">\n")
1738 (when (plist-get opt-plist :time-stamp-file)
1739 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
1740 (when (and (plist-get opt-plist :author-info) author)
1741 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1742 (when (and (plist-get opt-plist :email-info) email)
1743 (insert "<p class=\"email\">" email "</p>\n"))
1744 (when (plist-get opt-plist :creator-info)
1745 (insert "<p class=\"creator\">"
1746 (concat "Org version " org-version " with Emacs version "
1747 (number-to-string emacs-major-version) "</p>\n")))
1748 (insert html-validation-link "\n</div>"))
1750 (insert "<div id=\"postamble\">\n")
1751 (insert (format-spec
1752 (or (cadr (assoc (nth 0 lang-words)
1753 org-export-html-postamble-format))
1754 (cadr (assoc "en" org-export-html-postamble-format)))
1755 `((?a . ,author) (?e . ,email)
1756 (?d . ,date) (?c . ,creator-info)
1757 (?v . ,html-validation-link))))
1758 (insert "</div>"))))))
1760 (if org-export-html-with-timestamp
1761 (insert org-export-html-html-helper-timestamp))
1763 (unless body-only (insert "\n</div>\n</body>\n</html>\n"))
1765 (unless (plist-get opt-plist :buffer-will-be-killed)
1766 (normal-mode)
1767 (if (eq major-mode (default-value 'major-mode))
1768 (html-mode)))
1770 ;; insert the table of contents
1771 (goto-char (point-min))
1772 (when thetoc
1773 (if (or (re-search-forward
1774 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1775 (re-search-forward
1776 "\\[TABLE-OF-CONTENTS\\]" nil t))
1777 (progn
1778 (goto-char (match-beginning 0))
1779 (replace-match ""))
1780 (goto-char first-heading-pos)
1781 (when (looking-at "\\s-*</p>")
1782 (goto-char (match-end 0))
1783 (insert "\n")))
1784 (insert "<div id=\"table-of-contents\">\n")
1785 (let ((beg (point)))
1786 (mapc 'insert thetoc)
1787 (insert "</div>\n")
1788 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
1789 (replace-match ""))))
1790 ;; remove empty paragraphs
1791 (goto-char (point-min))
1792 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
1793 (replace-match ""))
1794 (goto-char (point-min))
1795 ;; Convert whitespace place holders
1796 (goto-char (point-min))
1797 (let (beg end n)
1798 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1799 (setq n (get-text-property beg 'org-whitespace)
1800 end (next-single-property-change beg 'org-whitespace))
1801 (goto-char beg)
1802 (delete-region beg end)
1803 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1804 (make-string n ?x)))))
1805 ;; Remove empty lines at the beginning of the file.
1806 (goto-char (point-min))
1807 (when (looking-at "\\s-+\n") (replace-match ""))
1808 ;; Remove display properties
1809 (remove-text-properties (point-min) (point-max) '(display t))
1810 ;; Run the hook
1811 (run-hooks 'org-export-html-final-hook)
1812 (or to-buffer (save-buffer))
1813 (goto-char (point-min))
1814 (or (org-export-push-to-kill-ring "HTML")
1815 (message "Exporting... done"))
1816 (if (eq to-buffer 'string)
1817 (prog1 (buffer-substring (point-min) (point-max))
1818 (kill-buffer (current-buffer)))
1819 (current-buffer)))))
1821 (defun org-export-html-format-href (s)
1822 "Make sure the S is valid as a href reference in an XHTML document."
1823 (save-match-data
1824 (let ((start 0))
1825 (while (string-match "&" s start)
1826 (setq start (+ (match-beginning 0) 3)
1827 s (replace-match "&amp;" t t s)))))
1830 (defun org-export-html-format-desc (s)
1831 "Make sure the S is valid as a description in a link."
1832 (if (and s (not (get-text-property 1 'org-protected s)))
1833 (save-match-data
1834 (org-html-do-expand s))
1837 (defun org-export-html-format-image (src par-open)
1838 "Create image tag with source and attributes."
1839 (save-match-data
1840 (if (string-match "^ltxpng/" src)
1841 (format "<img src=\"%s\" alt=\"%s\"/>"
1842 src (org-find-text-property-in-string 'org-latex-src src))
1843 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1844 (attr (org-find-text-property-in-string 'org-attributes src))
1845 (label (org-find-text-property-in-string 'org-label src)))
1846 (setq caption (and caption (org-html-do-expand caption)))
1847 (concat
1848 (if caption
1849 (format "%s<div %sclass=\"figure\">
1850 <p>"
1851 (if org-par-open "</p>\n" "")
1852 (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
1853 (format "<img src=\"%s\"%s />"
1855 (if (string-match "\\<alt=" (or attr ""))
1856 (concat " " attr )
1857 (concat " " attr " alt=\"" src "\"")))
1858 (if caption
1859 (format "</p>%s
1860 </div>%s"
1861 (concat "\n<p>" caption "</p>")
1862 (if org-par-open "\n<p>" ""))))))))
1864 (defun org-export-html-get-bibliography ()
1865 "Find bibliography, cut it out and return it."
1866 (catch 'exit
1867 (let (beg end (cnt 1) bib)
1868 (save-excursion
1869 (goto-char (point-min))
1870 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1871 (setq beg (match-beginning 0))
1872 (while (re-search-forward "</?div\\>" nil t)
1873 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1874 (when (= cnt 0)
1875 (and (looking-at ">") (forward-char 1))
1876 (setq bib (buffer-substring beg (point)))
1877 (delete-region beg (point))
1878 (throw 'exit bib))))
1879 nil))))
1881 (defvar org-table-number-regexp) ; defined in org-table.el
1882 (defun org-format-table-html (lines olines &optional no-css)
1883 "Find out which HTML converter to use and return the HTML code.
1884 NO-CSS is passed to the exporter."
1885 (if (stringp lines)
1886 (setq lines (org-split-string lines "\n")))
1887 (if (string-match "^[ \t]*|" (car lines))
1888 ;; A normal org table
1889 (org-format-org-table-html lines nil no-css)
1890 ;; Table made by table.el - test for spanning
1891 (let* ((hlines (delq nil (mapcar
1892 (lambda (x)
1893 (if (string-match "^[ \t]*\\+-" x) x
1894 nil))
1895 lines)))
1896 (first (car hlines))
1897 (ll (and (string-match "\\S-+" first)
1898 (match-string 0 first)))
1899 (re (concat "^[ \t]*" (regexp-quote ll)))
1900 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
1901 hlines))))
1902 (if (and (not spanning)
1903 (not org-export-prefer-native-exporter-for-tables))
1904 ;; We can use my own converter with HTML conversions
1905 (org-format-table-table-html lines)
1906 ;; Need to use the code generator in table.el, with the original text.
1907 (org-format-table-table-html-using-table-generate-source olines)))))
1909 (defvar org-table-number-fraction) ; defined in org-table.el
1910 (defun org-format-org-table-html (lines &optional splice no-css)
1911 "Format a table into HTML.
1912 LINES is a list of lines. Optional argument SPLICE means, do not
1913 insert header and surrounding <table> tags, just format the lines.
1914 Optional argument NO-CSS means use XHTML attributes instead of CSS
1915 for formatting. This is required for the DocBook exporter."
1916 (require 'org-table)
1917 ;; Get rid of hlines at beginning and end
1918 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1919 (setq lines (nreverse lines))
1920 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1921 (setq lines (nreverse lines))
1922 (when org-export-table-remove-special-lines
1923 ;; Check if the table has a marking column. If yes remove the
1924 ;; column and the special lines
1925 (setq lines (org-table-clean-before-export lines)))
1927 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
1928 (label (org-find-text-property-in-string 'org-label (car lines)))
1929 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
1930 (car lines)))
1931 (attributes (org-find-text-property-in-string 'org-attributes
1932 (car lines)))
1933 (html-table-tag (org-export-splice-attributes
1934 html-table-tag attributes))
1935 (head (and org-export-highlight-first-table-line
1936 (delq nil (mapcar
1937 (lambda (x) (string-match "^[ \t]*|-" x))
1938 (cdr lines)))))
1939 (nline 0) fnum nfields i (cnt 0)
1940 tbopen line fields html gr colgropen rowstart rowend
1941 ali align aligns n)
1942 (setq caption (and caption (org-html-do-expand caption)))
1943 (when (and forced-aligns org-table-clean-did-remove-column)
1944 (setq forced-aligns
1945 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
1946 (if splice (setq head nil))
1947 (unless splice (push (if head "<thead>" "<tbody>") html))
1948 (setq tbopen t)
1949 (while (setq line (pop lines))
1950 (catch 'next-line
1951 (if (string-match "^[ \t]*|-" line)
1952 (progn
1953 (unless splice
1954 (push (if head "</thead>" "</tbody>") html)
1955 (if lines (push "<tbody>" html) (setq tbopen nil)))
1956 (setq head nil) ;; head ends here, first time around
1957 ;; ignore this line
1958 (throw 'next-line t)))
1959 ;; Break the line into fields
1960 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1961 (unless fnum (setq fnum (make-vector (length fields) 0)
1962 nfields (length fnum)))
1963 (setq nline (1+ nline) i -1
1964 rowstart (eval (car org-export-table-row-tags))
1965 rowend (eval (cdr org-export-table-row-tags)))
1966 (push (concat rowstart
1967 (mapconcat
1968 (lambda (x)
1969 (setq i (1+ i) ali (format "@@class%03d@@" i))
1970 (if (and (< i nfields) ; make sure no rogue line causes an error here
1971 (string-match org-table-number-regexp x))
1972 (incf (aref fnum i)))
1973 (cond
1974 (head
1975 (concat
1976 (format (car org-export-table-header-tags)
1977 "col" ali)
1979 (cdr org-export-table-header-tags)))
1980 ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
1981 (concat
1982 (format (car org-export-table-header-tags)
1983 "row" ali)
1985 (cdr org-export-table-header-tags)))
1987 (concat (format (car org-export-table-data-tags) ali)
1989 (cdr org-export-table-data-tags)))))
1990 fields "")
1991 rowend)
1992 html)))
1993 (unless splice (if tbopen (push "</tbody>" html)))
1994 (unless splice (push "</table>\n" html))
1995 (setq html (nreverse html))
1996 (unless splice
1997 ;; Put in col tags with the alignment (unfortunately often ignored...)
1998 (unless (car org-table-colgroup-info)
1999 (setq org-table-colgroup-info
2000 (cons :start (cdr org-table-colgroup-info))))
2001 (setq i 0)
2002 (push (mapconcat
2003 (lambda (x)
2004 (setq gr (pop org-table-colgroup-info)
2005 i (1+ i)
2006 align (if (assoc i forced-aligns)
2007 (cdr (assoc (cdr (assoc i forced-aligns))
2008 '(("l" . "left") ("r" . "right")
2009 ("c" . "center"))))
2010 (if (> (/ (float x) nline)
2011 org-table-number-fraction)
2012 "right" "left")))
2013 (push align aligns)
2014 (format (if no-css
2015 "%s<col align=\"%s\" />%s"
2016 "%s<col class=\"%s\" />%s")
2017 (if (memq gr '(:start :startend))
2018 (prog1
2019 (if colgropen
2020 "</colgroup>\n<colgroup>"
2021 "<colgroup>")
2022 (setq colgropen t))
2024 align
2025 (if (memq gr '(:end :startend))
2026 (progn (setq colgropen nil) "</colgroup>")
2027 "")))
2028 fnum "")
2029 html)
2030 (setq aligns (nreverse aligns))
2031 (if colgropen (setq html (cons (car html)
2032 (cons "</colgroup>" (cdr html)))))
2033 ;; Since the output of HTML table formatter can also be used in
2034 ;; DocBook document, we want to always include the caption to make
2035 ;; DocBook XML file valid.
2036 (push (format "<caption>%s</caption>" (or caption "")) html)
2037 (when label
2038 (setq html-table-tag (org-export-splice-attributes html-table-tag (format "id=\"%s\"" (org-solidify-link-text label)))))
2039 (push html-table-tag html))
2040 (setq html (mapcar
2041 (lambda (x)
2042 (replace-regexp-in-string
2043 "@@class\\([0-9]+\\)@@"
2044 (lambda (txt)
2045 (if (not org-export-html-table-align-individual-fields)
2047 (setq n (string-to-number (match-string 1 txt)))
2048 (format (if no-css " align=\"%s\"" " class=\"%s\"")
2049 (or (nth n aligns) "left"))))
2051 html))
2052 (concat (mapconcat 'identity html "\n") "\n")))
2054 (defun org-export-splice-attributes (tag attributes)
2055 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2056 (if (not attributes)
2058 (let (oldatt newatt)
2059 (setq oldatt (org-extract-attributes-from-string tag)
2060 tag (pop oldatt)
2061 newatt (cdr (org-extract-attributes-from-string attributes)))
2062 (while newatt
2063 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
2064 (if (string-match ">" tag)
2065 (setq tag
2066 (replace-match (concat (org-attributes-to-string oldatt) ">")
2067 t t tag)))
2068 tag)))
2070 (defun org-format-table-table-html (lines)
2071 "Format a table generated by table.el into HTML.
2072 This conversion does *not* use `table-generate-source' from table.el.
2073 This has the advantage that Org-mode's HTML conversions can be used.
2074 But it has the disadvantage, that no cell- or row-spanning is allowed."
2075 (let (line field-buffer
2076 (head org-export-highlight-first-table-line)
2077 fields html empty i)
2078 (setq html (concat html-table-tag "\n"))
2079 (while (setq line (pop lines))
2080 (setq empty "&nbsp;")
2081 (catch 'next-line
2082 (if (string-match "^[ \t]*\\+-" line)
2083 (progn
2084 (if field-buffer
2085 (progn
2086 (setq
2087 html
2088 (concat
2089 html
2090 "<tr>"
2091 (mapconcat
2092 (lambda (x)
2093 (if (equal x "") (setq x empty))
2094 (if head
2095 (concat
2096 (format (car org-export-table-header-tags) "col" "")
2098 (cdr org-export-table-header-tags))
2099 (concat (format (car org-export-table-data-tags) "") x
2100 (cdr org-export-table-data-tags))))
2101 field-buffer "\n")
2102 "</tr>\n"))
2103 (setq head nil)
2104 (setq field-buffer nil)))
2105 ;; Ignore this line
2106 (throw 'next-line t)))
2107 ;; Break the line into fields and store the fields
2108 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2109 (if field-buffer
2110 (setq field-buffer (mapcar
2111 (lambda (x)
2112 (concat x "<br/>" (pop fields)))
2113 field-buffer))
2114 (setq field-buffer fields))))
2115 (setq html (concat html "</table>\n"))
2116 html))
2118 (defun org-format-table-table-html-using-table-generate-source (lines)
2119 "Format a table into html, using `table-generate-source' from table.el.
2120 This has the advantage that cell- or row-spanning is allowed.
2121 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
2122 (require 'table)
2123 (with-current-buffer (get-buffer-create " org-tmp1 ")
2124 (erase-buffer)
2125 (insert (mapconcat 'identity lines "\n"))
2126 (goto-char (point-min))
2127 (if (not (re-search-forward "|[^+]" nil t))
2128 (error "Error processing table"))
2129 (table-recognize-table)
2130 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2131 (table-generate-source 'html " org-tmp2 ")
2132 (set-buffer " org-tmp2 ")
2133 (buffer-substring (point-min) (point-max))))
2135 (defun org-export-splice-style (style extra)
2136 "Splice EXTRA into STYLE, just before \"</style>\"."
2137 (if (and (stringp extra)
2138 (string-match "\\S-" extra)
2139 (string-match "</style>" style))
2140 (concat (substring style 0 (match-beginning 0))
2141 "\n" extra "\n"
2142 (substring style (match-beginning 0)))
2143 style))
2145 (defun org-html-handle-time-stamps (s)
2146 "Format time stamps in string S, or remove them."
2147 (catch 'exit
2148 (let (r b)
2149 (while (string-match org-maybe-keyword-time-regexp s)
2150 (or b (setq b (substring s 0 (match-beginning 0))))
2151 (setq r (concat
2152 r (substring s 0 (match-beginning 0))
2153 " @<span class=\"timestamp-wrapper\">"
2154 (if (match-end 1)
2155 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2156 (match-string 1 s)))
2157 (format " @<span class=\"timestamp\">%s@</span>"
2158 (substring
2159 (org-translate-time (match-string 3 s)) 1 -1))
2160 "@</span>")
2161 s (substring s (match-end 0))))
2162 ;; Line break if line started and ended with time stamp stuff
2163 (if (not r)
2165 (setq r (concat r s))
2166 (unless (string-match "\\S-" (concat b s))
2167 (setq r (concat r "@<br/>")))
2168 r))))
2170 (defvar htmlize-buffer-places) ; from htmlize.el
2171 (defun org-export-htmlize-region-for-paste (beg end)
2172 "Convert the region to HTML, using htmlize.el.
2173 This is much like `htmlize-region-for-paste', only that it uses
2174 the settings define in the org-... variables."
2175 (let* ((htmlize-output-type org-export-htmlize-output-type)
2176 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
2177 (htmlbuf (htmlize-region beg end)))
2178 (unwind-protect
2179 (with-current-buffer htmlbuf
2180 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
2181 (plist-get htmlize-buffer-places 'content-end)))
2182 (kill-buffer htmlbuf))))
2184 ;;;###autoload
2185 (defun org-export-htmlize-generate-css ()
2186 "Create the CSS for all font definitions in the current Emacs session.
2187 Use this to create face definitions in your CSS style file that can then
2188 be used by code snippets transformed by htmlize.
2189 This command just produces a buffer that contains class definitions for all
2190 faces used in the current Emacs session. You can copy and paste the ones you
2191 need into your CSS file.
2193 If you then set `org-export-htmlize-output-type' to `css', calls to
2194 the function `org-export-htmlize-region-for-paste' will produce code
2195 that uses these same face definitions."
2196 (interactive)
2197 (require 'htmlize)
2198 (and (get-buffer "*html*") (kill-buffer "*html*"))
2199 (with-temp-buffer
2200 (let ((fl (face-list))
2201 (htmlize-css-name-prefix "org-")
2202 (htmlize-output-type 'css)
2203 f i)
2204 (while (setq f (pop fl)
2205 i (and f (face-attribute f :inherit)))
2206 (when (and (symbolp f) (or (not i) (not (listp i))))
2207 (insert (org-add-props (copy-sequence "1") nil 'face f))))
2208 (htmlize-region (point-min) (point-max))))
2209 (switch-to-buffer "*html*")
2210 (goto-char (point-min))
2211 (if (re-search-forward "<style" nil t)
2212 (delete-region (point-min) (match-beginning 0)))
2213 (if (re-search-forward "</style>" nil t)
2214 (delete-region (1+ (match-end 0)) (point-max)))
2215 (beginning-of-line 1)
2216 (if (looking-at " +") (replace-match ""))
2217 (goto-char (point-min)))
2219 (defun org-html-protect (s)
2220 "Convert characters to HTML equivalent.
2221 Possible conversions are set in `org-export-html-protect-char-alist'."
2222 (let ((cl org-export-html-protect-char-alist) c)
2223 (while (setq c (pop cl))
2224 (let ((start 0))
2225 (while (string-match (car c) s start)
2226 (setq s (replace-match (cdr c) t t s)
2227 start (1+ (match-beginning 0))))))
2230 (defun org-html-expand (string)
2231 "Prepare STRING for HTML export. Apply all active conversions.
2232 If there are links in the string, don't modify these."
2233 (let* ((re (concat org-bracket-link-regexp "\\|"
2234 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2235 m s l res)
2236 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
2237 string
2238 (while (setq m (string-match re string))
2239 (setq s (substring string 0 m)
2240 l (match-string 0 string)
2241 string (substring string (match-end 0)))
2242 (push (org-html-do-expand s) res)
2243 (push l res))
2244 (push (org-html-do-expand string) res)
2245 (apply 'concat (nreverse res)))))
2247 (defun org-html-do-expand (s)
2248 "Apply all active conversions to translate special ASCII to HTML."
2249 (setq s (org-html-protect s))
2250 (if org-export-html-expand
2251 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
2252 (setq s (replace-match "<\\1>" t nil s))))
2253 (if org-export-with-emphasize
2254 (setq s (org-export-html-convert-emphasize s)))
2255 (if org-export-with-special-strings
2256 (setq s (org-export-html-convert-special-strings s)))
2257 (if org-export-with-sub-superscripts
2258 (setq s (org-export-html-convert-sub-super s)))
2259 (if org-export-with-TeX-macros
2260 (let ((start 0) wd rep)
2261 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2262 s start))
2263 (if (get-text-property (match-beginning 0) 'org-protected s)
2264 (setq start (match-end 0))
2265 (setq wd (match-string 1 s))
2266 (if (setq rep (org-entity-get-representation wd 'html))
2267 (setq s (replace-match rep t t s))
2268 (setq start (+ start (length wd))))))))
2271 (defun org-export-html-convert-special-strings (string)
2272 "Convert special characters in STRING to HTML."
2273 (let ((all org-export-html-special-string-regexps)
2274 e a re rpl start)
2275 (while (setq a (pop all))
2276 (setq re (car a) rpl (cdr a) start 0)
2277 (while (string-match re string start)
2278 (if (get-text-property (match-beginning 0) 'org-protected string)
2279 (setq start (match-end 0))
2280 (setq string (replace-match rpl t nil string)))))
2281 string))
2283 (defun org-export-html-convert-sub-super (string)
2284 "Convert sub- and superscripts in STRING to HTML."
2285 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
2286 (while (string-match org-match-substring-regexp string s)
2287 (cond
2288 ((and requireb (match-end 8)) (setq s (match-end 2)))
2289 ((get-text-property (match-beginning 2) 'org-protected string)
2290 (setq s (match-end 2)))
2292 (setq s (match-end 1)
2293 key (if (string= (match-string 2 string) "_") "sub" "sup")
2294 c (or (match-string 8 string)
2295 (match-string 6 string)
2296 (match-string 5 string))
2297 string (replace-match
2298 (concat (match-string 1 string)
2299 "<" key ">" c "</" key ">")
2300 t t string)))))
2301 (while (string-match "\\\\\\([_^]\\)" string)
2302 (setq string (replace-match (match-string 1 string) t t string)))
2303 string))
2305 (defun org-export-html-convert-emphasize (string)
2306 "Apply emphasis."
2307 (let ((s 0) rpl)
2308 (while (string-match org-emph-re string s)
2309 (if (not (equal
2310 (substring string (match-beginning 3) (1+ (match-beginning 3)))
2311 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
2312 (setq s (match-beginning 0)
2314 (concat
2315 (match-string 1 string)
2316 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
2317 (match-string 4 string)
2318 (nth 3 (assoc (match-string 3 string)
2319 org-emphasis-alist))
2320 (match-string 5 string))
2321 string (replace-match rpl t t string)
2322 s (+ s (- (length rpl) 2)))
2323 (setq s (1+ s))))
2324 string))
2326 (defun org-open-par ()
2327 "Insert <p>, but first close previous paragraph if any."
2328 (org-close-par-maybe)
2329 (insert "\n<p>")
2330 (setq org-par-open t))
2331 (defun org-close-par-maybe ()
2332 "Close paragraph if there is one open."
2333 (when org-par-open
2334 (insert "</p>")
2335 (setq org-par-open nil)))
2336 (defun org-close-li (&optional type)
2337 "Close <li> if necessary."
2338 (org-close-par-maybe)
2339 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
2341 (defvar body-only) ; dynamically scoped into this.
2342 (defun org-html-level-start (level title umax with-toc head-count &optional opt-plist)
2343 "Insert a new level in HTML export.
2344 When TITLE is nil, just close all open levels."
2345 (org-close-par-maybe)
2346 (let* ((target (and title (org-get-text-property-any 0 'target title)))
2347 (extra-targets (and target
2348 (assoc target org-export-target-aliases)))
2349 (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
2350 (preferred (and target
2351 (cdr (assoc target org-export-preferred-target-alist))))
2352 (l org-level-max)
2353 (num (plist-get opt-plist :section-numbers))
2354 snumber snu href suffix)
2355 (setq extra-targets (remove (or preferred target) extra-targets))
2356 (setq extra-targets
2357 (mapconcat (lambda (x)
2358 (setq x (org-solidify-link-text
2359 (if (org-uuidgen-p x) (concat "ID-" x) x)))
2360 (format "<a name=\"%s\" id=\"%s\"></a>"
2361 x x))
2362 extra-targets
2363 ""))
2364 (while (>= l level)
2365 (if (aref org-levels-open (1- l))
2366 (progn
2367 (org-html-level-close l umax)
2368 (aset org-levels-open (1- l) nil)))
2369 (setq l (1- l)))
2370 (when title
2371 ;; If title is nil, this means this function is called to close
2372 ;; all levels, so the rest is done only if title is given
2373 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2374 (setq title (replace-match
2375 (if org-export-with-tags
2376 (save-match-data
2377 (concat
2378 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
2379 (mapconcat
2380 (lambda (x)
2381 (format "<span class=\"%s\">%s</span>"
2382 (org-export-html-get-tag-class-name x)
2384 (org-split-string (match-string 1 title) ":")
2385 "&nbsp;")
2386 "</span>"))
2388 t t title)))
2389 (if (> level umax)
2390 (progn
2391 (if (aref org-levels-open (1- level))
2392 (progn
2393 (org-close-li)
2394 (if target
2395 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2396 extra-targets title "<br/>\n")
2397 (insert "<li>" title "<br/>\n")))
2398 (aset org-levels-open (1- level) t)
2399 (org-close-par-maybe)
2400 (if target
2401 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2402 extra-targets title "<br/>\n")
2403 (insert "<ul>\n<li>" title "<br/>\n"))))
2404 (aset org-levels-open (1- level) t)
2405 (setq snumber (org-section-number level)
2406 snu (replace-regexp-in-string "\\." "_" snumber))
2407 (setq level (+ level org-export-html-toplevel-hlevel -1))
2408 (if (and num (not body-only))
2409 (setq title (concat
2410 (format "<span class=\"section-number-%d\">%s</span>"
2411 level
2412 (if (and num
2413 (if (integerp num)
2414 ;; fix up num to take into
2415 ;; account the top-level
2416 ;; heading value
2417 (>= (+ num org-export-html-toplevel-hlevel -1)
2418 level)
2419 num))
2420 snumber
2421 ""))
2422 " " title)))
2423 (unless (= head-count 1) (insert "\n</div>\n"))
2424 (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
2425 (setq suffix (org-solidify-link-text (or href snu)))
2426 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2427 (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"
2428 suffix level (if extra-class (concat " " extra-class) "")
2429 level href
2430 extra-targets
2431 title level level suffix))
2432 (org-open-par)))))
2434 (defun org-export-html-get-tag-class-name (tag)
2435 "Turn tag into a valid class name.
2436 Replaces invalid characters with \"_\" and then prepends a prefix."
2437 (save-match-data
2438 (while (string-match "[^a-zA-Z0-9_]" tag)
2439 (setq tag (replace-match "_" t t tag))))
2440 (concat org-export-html-tag-class-prefix tag))
2442 (defun org-export-html-get-todo-kwd-class-name (kwd)
2443 "Turn todo keyword into a valid class name.
2444 Replaces invalid characters with \"_\" and then prepends a prefix."
2445 (save-match-data
2446 (while (string-match "[^a-zA-Z0-9_]" kwd)
2447 (setq kwd (replace-match "_" t t kwd))))
2448 (concat org-export-html-todo-kwd-class-prefix kwd))
2450 (defun org-html-level-close (level max-outline-level)
2451 "Terminate one level in HTML export."
2452 (if (<= level max-outline-level)
2453 (insert "</div>\n")
2454 (org-close-li)
2455 (insert "</ul>\n")))
2457 (defun org-html-export-list-line (line pos struct prevs)
2458 "Insert list syntax in export buffer. Return LINE, maybe modified.
2460 POS is the item position or line position the line had before
2461 modifications to buffer. STRUCT is the list structure. PREVS is
2462 the alist of previous items."
2463 (let* ((get-type
2464 (function
2465 ;; Translate type of list containing POS to "d", "o" or
2466 ;; "u".
2467 (lambda (pos struct prevs)
2468 (let ((type (org-list-get-list-type pos struct prevs)))
2469 (cond
2470 ((eq 'ordered type) "o")
2471 ((eq 'descriptive type) "d")
2472 (t "u"))))))
2473 (get-closings
2474 (function
2475 ;; Return list of all items and sublists ending at POS, in
2476 ;; reverse order.
2477 (lambda (pos)
2478 (let (out)
2479 (catch 'exit
2480 (mapc (lambda (e)
2481 (let ((end (nth 6 e))
2482 (item (car e)))
2483 (cond
2484 ((= end pos) (push item out))
2485 ((>= item pos) (throw 'exit nil)))))
2486 struct))
2487 out)))))
2488 ;; First close any previous item, or list, ending at POS.
2489 (mapc (lambda (e)
2490 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2491 (first-item (org-list-get-list-begin e struct prevs))
2492 (type (funcall get-type first-item struct prevs)))
2493 (org-close-par-maybe)
2494 ;; Ending for every item
2495 (org-close-li type)
2496 ;; We're ending last item of the list: end list.
2497 (when lastp
2498 (insert (format "</%sl>\n" type))
2499 (org-open-par))))
2500 (funcall get-closings pos))
2501 (cond
2502 ;; At an item: insert appropriate tags in export buffer.
2503 ((assq pos struct)
2504 (string-match
2505 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2506 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2507 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2508 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2509 "\\(.*\\)") line)
2510 (let* ((checkbox (match-string 3 line))
2511 (desc-tag (or (match-string 4 line) "???"))
2512 (body (or (match-string 5 line) ""))
2513 (list-beg (org-list-get-list-begin pos struct prevs))
2514 (firstp (= list-beg pos))
2515 ;; Always refer to first item to determine list type, in
2516 ;; case list is ill-formed.
2517 (type (funcall get-type list-beg struct prevs))
2518 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2519 (cond
2520 ((not count-tmp) nil)
2521 ((string-match "[A-Za-z]" count-tmp)
2522 (- (string-to-char (upcase count-tmp)) 64))
2523 ((string-match "[0-9]+" count-tmp)
2524 count-tmp)))))
2525 (when firstp
2526 (org-close-par-maybe)
2527 (insert (format "<%sl>\n" type)))
2528 (insert (cond
2529 ((equal type "d")
2530 (format "<dt>%s</dt><dd>" desc-tag))
2531 ((and (equal type "o") counter)
2532 (format "<li value=\"%s\">" counter))
2533 (t "<li>")))
2534 ;; If line had a checkbox, some additional modification is required.
2535 (when checkbox
2536 (setq body
2537 (concat
2538 (cond
2539 ((string-match "X" checkbox) "<code>[X]</code> ")
2540 ((string-match " " checkbox) "<code>[&nbsp;]</code> ")
2541 (t "<code>[-]</code> "))
2542 body)))
2543 ;; Return modified line
2544 body))
2545 ;; At a list ender: go to next line (side-effects only).
2546 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2547 ;; Not at an item: return line unchanged (side-effects only).
2548 (t line))))
2550 (provide 'org-html)
2552 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
2553 ;;; org-html.el ends here