Release 7.5
[org-mode/org-tableheadings.git] / lisp / org-html.el
blob333cf4df66cd1c81ffb248669ce9be3cbfc56d24
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 nil
347 "Non-nil means insert a preamble in HTML export.
348 If this is a string, use it as a formatting string it instead of
349 `org-export-html-preamble-format'. Setting :html-preamble in
350 publishing projects will override this."
351 :group 'org-export-html
352 :type 'boolean)
354 (defcustom org-export-html-preamble-format
355 '(("en" "<h1 class=\"title\">%t</h1>"))
356 "The format for the HTML preamble.
358 %t stands for the title.
360 If you need to use a \"%\" character, you need to escape it
361 like that: \"%%\"."
362 :group 'org-export-html
363 :type 'string)
365 (defcustom org-export-html-postamble nil
366 "Non-nil means insert a postamble in HTML export.
367 If this is a string, use it as a formatting string it instead of
368 `org-export-html-postamble-format'. Setting :html-postamble in
369 publishing projects will override this."
370 :group 'org-export-html
371 :type 'boolean)
373 (defcustom org-export-html-postamble-format
374 '(("en" "<p class=\"author\">Author: %a (%e)</p>
375 <p class=\"date\">Date: %d</p>
376 <p class=\"creator\">Generated by %c</p>
377 <p class=\"xhtml-validation\">%v</p>
379 "The format for the HTML postamble.
381 %a stands for the author.
382 %e stands for the email(s).
383 %d stands for the date.
384 %c will be replaced by information about Org/Emacs.
385 %v will be replaced by `org-export-html-validation-link'.
387 If you need to use a \"%\" character, you need to escape it
388 like that: \"%%\"."
389 :group 'org-export-html
390 :type 'string)
392 (defcustom org-export-html-home/up-format
393 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
394 <a accesskey=\"h\" href=\"%s\"> UP </a>
396 <a accesskey=\"H\" href=\"%s\"> HOME </a>
397 </div>"
398 "Snippet used to insert the HOME and UP links.
399 This is a format string, the first %s will receive the UP link,
400 the second the HOME link. If both `org-export-html-link-up' and
401 `org-export-html-link-home' are empty, the entire snippet will be
402 ignored."
403 :group 'org-export-html
404 :type 'string)
406 (defcustom org-export-html-toplevel-hlevel 2
407 "The <H> level for level 1 headings in HTML export.
408 This is also important for the classes that will be wrapped around headlines
409 and outline structure. If this variable is 1, the top-level headlines will
410 be <h1>, and the corresponding classes will be outline-1, section-number-1,
411 and outline-text-1. If this is 2, all of these will get a 2 instead.
412 The default for this variable is 2, because we use <h1> for formatting the
413 document title."
414 :group 'org-export-html
415 :type 'string)
417 (defcustom org-export-html-link-org-files-as-html t
418 "Non-nil means make file links to `file.org' point to `file.html'.
419 When org-mode is exporting an org-mode file to HTML, links to
420 non-html files are directly put into a href tag in HTML.
421 However, links to other Org-mode files (recognized by the
422 extension `.org.) should become links to the corresponding html
423 file, assuming that the linked org-mode file will also be
424 converted to HTML.
425 When nil, the links still point to the plain `.org' file."
426 :group 'org-export-html
427 :type 'boolean)
429 (defcustom org-export-html-inline-images 'maybe
430 "Non-nil means inline images into exported HTML pages.
431 This is done using an <img> tag. When nil, an anchor with href is used to
432 link to the image. If this option is `maybe', then images in links with
433 an empty description will be inlined, while images with a description will
434 be linked only."
435 :group 'org-export-html
436 :type '(choice (const :tag "Never" nil)
437 (const :tag "Always" t)
438 (const :tag "When there is no description" maybe)))
440 (defcustom org-export-html-inline-image-extensions
441 '("png" "jpeg" "jpg" "gif" "svg")
442 "Extensions of image files that can be inlined into HTML."
443 :group 'org-export-html
444 :type '(repeat (string :tag "Extension")))
446 (defcustom org-export-html-table-tag
447 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
448 "The HTML tag that is used to start a table.
449 This must be a <table> tag, but you may change the options like
450 borders and spacing."
451 :group 'org-export-html
452 :type 'string)
454 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
455 "The opening tag for table header fields.
456 This is customizable so that alignment options can be specified.
457 The first %s will be filled with the scope of the field, either row or col.
458 The second %s will be replaced by a style entry to align the field.
459 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
460 See also the variable `org-export-html-table-align-individual-fields'."
461 :group 'org-export-tables
462 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
464 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
465 "The opening tag for table data fields.
466 This is customizable so that alignment options can be specified.
467 The first %s will be filled with the scope of the field, either row or col.
468 The second %s will be replaced by a style entry to align the field.
469 See also the variable `org-export-html-table-align-individual-fields'."
470 :group 'org-export-tables
471 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
473 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
474 "The opening tag for table data fields.
475 This is customizable so that alignment options can be specified.
476 Instead of strings, these can be Lisp forms that will be evaluated
477 for each row in order to construct the table row tags. During evaluation,
478 the variable `head' will be true when this is a header line, nil when this
479 is a body line. And the variable `nline' will contain the line number,
480 starting from 1 in the first header line. For example
482 (setq org-export-table-row-tags
483 (cons '(if head
484 \"<tr>\"
485 (if (= (mod nline 2) 1)
486 \"<tr class=\\\"tr-odd\\\">\"
487 \"<tr class=\\\"tr-even\\\">\"))
488 \"</tr>\"))
490 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
491 :group 'org-export-tables
492 :type '(cons
493 (choice :tag "Opening tag"
494 (string :tag "Specify")
495 (sexp))
496 (choice :tag "Closing tag"
497 (string :tag "Specify")
498 (sexp))))
500 (defcustom org-export-html-table-align-individual-fields t
501 "Non-nil means attach style attributes for alignment to each table field.
502 When nil, alignment will only be specified in the column tags, but this
503 is ignored by some browsers (like Firefox, Safari). Opera does it right
504 though."
505 :group 'org-export-tables
506 :type 'boolean)
508 (defcustom org-export-html-table-use-header-tags-for-first-column nil
509 "Non-nil means format column one in tables with header tags.
510 When nil, also column one will use data tags."
511 :group 'org-export-tables
512 :type 'boolean)
514 (defcustom org-export-html-validation-link
515 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
516 "Link to HTML validation service."
517 :group 'org-export-html
518 :type 'string)
520 (defcustom org-export-html-with-timestamp nil
521 "If non-nil, write timestamp into the exported HTML text.
522 If non-nil Write `org-export-html-html-helper-timestamp' into the
523 exported HTML text. Otherwise, the buffer will just be saved to
524 a file."
525 :group 'org-export-html
526 :type 'boolean)
528 (defcustom org-export-html-html-helper-timestamp
529 "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
530 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
531 :group 'org-export-html
532 :type 'string)
535 (defcustom org-export-html-protect-char-alist
536 '(("&" . "&amp;")
537 ("<" . "&lt;")
538 (">" . "&gt;"))
539 "Alist of characters to be converted by `org-html-protect'."
540 :type '((repeat (cons (string :tag "Character")
541 (string :tag "HTML equivalent")))))
543 (defgroup org-export-htmlize nil
544 "Options for processing examples with htmlize.el."
545 :tag "Org Export Htmlize"
546 :group 'org-export-html)
548 (defcustom org-export-htmlize-output-type 'inline-css
549 "Output type to be used by htmlize when formatting code snippets.
550 Choices are `css', to export the CSS selectors only, or `inline-css', to
551 export the CSS attribute values inline in the HTML. We use as default
552 `inline-css', in order to make the resulting HTML self-containing.
554 However, this will fail when using Emacs in batch mode for export, because
555 then no rich font definitions are in place. It will also not be good if
556 people with different Emacs setup contribute HTML files to a website,
557 because the fonts will represent the individual setups. In these cases,
558 it is much better to let Org/Htmlize assign classes only, and to use
559 a style file to define the look of these classes.
560 To get a start for your css file, start Emacs session and make sure that
561 all the faces you are interested in are defined, for example by loading files
562 in all modes you want. Then, use the command
563 \\[org-export-htmlize-generate-css] to extract class definitions."
564 :group 'org-export-htmlize
565 :type '(choice (const css) (const inline-css)))
567 (defcustom org-export-htmlize-css-font-prefix "org-"
568 "The prefix for CSS class names for htmlize font specifications."
569 :group 'org-export-htmlize
570 :type 'string)
572 (defcustom org-export-htmlized-org-css-url nil
573 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
574 Normally when creating an htmlized version of an Org buffer, htmlize will
575 create CSS to define the font colors. However, this does not work when
576 converting in batch mode, and it also can look bad if different people
577 with different fontification setup work on the same website.
578 When this variable is non-nil, creating an htmlized version of an Org buffer
579 using `org-export-as-org' will remove the internal CSS section and replace it
580 with a link to this URL."
581 :group 'org-export-htmlize
582 :type '(choice
583 (const :tag "Keep internal css" nil)
584 (string :tag "URL or local href")))
586 ;;; Hooks
588 (defvar org-export-html-after-blockquotes-hook nil
589 "Hook run during HTML export, after blockquote, verse, center are done.")
591 (defvar org-export-html-final-hook nil
592 "Hook run at the end of HTML export, in the new buffer.")
594 ;;; HTML export
596 (defun org-export-html-preprocess (parameters)
597 "Convert LaTeX fragments to images."
598 (when (and org-current-export-file
599 (plist-get parameters :LaTeX-fragments))
600 (org-format-latex
601 (concat "ltxpng/" (file-name-sans-extension
602 (file-name-nondirectory
603 org-current-export-file)))
604 org-current-export-dir nil "Creating LaTeX image %s"
605 nil nil
606 (cond
607 ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
608 ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
609 ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
610 ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
611 (t nil))))
612 (goto-char (point-min))
613 (let (label l1)
614 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
615 (org-if-unprotected-at (match-beginning 1)
616 (setq label (match-string 1))
617 (save-match-data
618 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
619 (setq l1 (substring label (match-beginning 1)))
620 (setq l1 label)))
621 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
623 ;;;###autoload
624 (defun org-export-as-html-and-open (arg)
625 "Export the outline as HTML and immediately open it with a browser.
626 If there is an active region, export only the region.
627 The prefix ARG specifies how many levels of the outline should become
628 headlines. The default is 3. Lower levels will become bulleted lists."
629 (interactive "P")
630 (org-export-as-html arg 'hidden)
631 (org-open-file buffer-file-name)
632 (when org-export-kill-product-buffer-when-displayed
633 (kill-buffer (current-buffer))))
635 ;;;###autoload
636 (defun org-export-as-html-batch ()
637 "Call the function `org-export-as-html'.
638 This function can be used in batch processing as:
639 emacs --batch
640 --load=$HOME/lib/emacs/org.el
641 --eval \"(setq org-export-headline-levels 2)\"
642 --visit=MyFile --funcall org-export-as-html-batch"
643 (org-export-as-html org-export-headline-levels 'hidden))
645 ;;;###autoload
646 (defun org-export-as-html-to-buffer (arg)
647 "Call `org-export-as-html` with output to a temporary buffer.
648 No file is created. The prefix ARG is passed through to `org-export-as-html'."
649 (interactive "P")
650 (org-export-as-html arg nil nil "*Org HTML Export*")
651 (when org-export-show-temporary-export-buffer
652 (switch-to-buffer-other-window "*Org HTML Export*")))
654 ;;;###autoload
655 (defun org-replace-region-by-html (beg end)
656 "Assume the current region has org-mode syntax, and convert it to HTML.
657 This can be used in any buffer. For example, you could write an
658 itemized list in org-mode syntax in an HTML buffer and then use this
659 command to convert it."
660 (interactive "r")
661 (let (reg html buf pop-up-frames)
662 (save-window-excursion
663 (if (org-mode-p)
664 (setq html (org-export-region-as-html
665 beg end t 'string))
666 (setq reg (buffer-substring beg end)
667 buf (get-buffer-create "*Org tmp*"))
668 (with-current-buffer buf
669 (erase-buffer)
670 (insert reg)
671 (org-mode)
672 (setq html (org-export-region-as-html
673 (point-min) (point-max) t 'string)))
674 (kill-buffer buf)))
675 (delete-region beg end)
676 (insert html)))
678 ;;;###autoload
679 (defun org-export-region-as-html (beg end &optional body-only buffer)
680 "Convert region from BEG to END in org-mode buffer to HTML.
681 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
682 contents, and only produce the region of converted text, useful for
683 cut-and-paste operations.
684 If BUFFER is a buffer or a string, use/create that buffer as a target
685 of the converted HTML. If BUFFER is the symbol `string', return the
686 produced HTML as a string and leave not buffer behind. For example,
687 a Lisp program could call this function in the following way:
689 (setq html (org-export-region-as-html beg end t 'string))
691 When called interactively, the output buffer is selected, and shown
692 in a window. A non-interactive call will only return the buffer."
693 (interactive "r\nP")
694 (when (interactive-p)
695 (setq buffer "*Org HTML Export*"))
696 (let ((transient-mark-mode t) (zmacs-regions t)
697 ext-plist rtn)
698 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
699 (goto-char end)
700 (set-mark (point)) ;; to activate the region
701 (goto-char beg)
702 (setq rtn (org-export-as-html
703 nil nil ext-plist
704 buffer body-only))
705 (if (fboundp 'deactivate-mark) (deactivate-mark))
706 (if (and (interactive-p) (bufferp rtn))
707 (switch-to-buffer-other-window rtn)
708 rtn)))
710 (defvar html-table-tag nil) ; dynamically scoped into this.
711 (defvar org-par-open nil)
713 ;;; org-html-cvt-link-fn
714 (defconst org-html-cvt-link-fn
716 "Function to convert link URLs to exportable URLs.
717 Takes two arguments, TYPE and PATH.
718 Returns exportable url as (TYPE PATH), or nil to signal that it
719 didn't handle this case.
720 Intended to be locally bound around a call to `org-export-as-html'." )
722 (defun org-html-cvt-org-as-html (opt-plist type path)
723 "Convert an org filename to an equivalent html filename.
724 If TYPE is not file, just return `nil'.
725 See variable `org-export-html-link-org-files-as-html'"
727 (save-match-data
728 (and
729 org-export-html-link-org-files-as-html
730 (string= type "file")
731 (string-match "\\.org$" path)
732 (progn
733 (list
734 "file"
735 (concat
736 (substring path 0 (match-beginning 0))
738 (plist-get opt-plist :html-extension)))))))
741 ;;; org-html-should-inline-p
742 (defun org-html-should-inline-p (filename descp)
743 "Return non-nil if link FILENAME should be inlined.
744 The decision to inline the FILENAME link is based on the current
745 settings. DESCP is the boolean of whether there was a link
746 description. See variables `org-export-html-inline-images' and
747 `org-export-html-inline-image-extensions'."
748 (declare (special
749 org-export-html-inline-images
750 org-export-html-inline-image-extensions))
751 (and (or (eq t org-export-html-inline-images)
752 (and org-export-html-inline-images (not descp)))
753 (org-file-image-p
754 filename org-export-html-inline-image-extensions)))
756 ;;; org-html-make-link
757 (defun org-html-make-link (opt-plist type path fragment desc attr
758 may-inline-p)
759 "Make an HTML link.
760 OPT-PLIST is an options list.
761 TYPE is the device-type of the link (THIS://foo.html)
762 PATH is the path of the link (http://THIS#locationx)
763 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
764 DESC is the link description, if any.
765 ATTR is a string of other attributes of the a element.
766 MAY-INLINE-P allows inlining it as an image."
768 (declare (special org-par-open))
769 (save-match-data
770 (let* ((filename path)
771 ;;First pass. Just sanity stuff.
772 (components-1
773 (cond
774 ((string= type "file")
775 (list
776 type
777 ;;Substitute just if original path was absolute.
778 ;;(Otherwise path must remain relative)
779 (if (file-name-absolute-p path)
780 (concat "file://" (expand-file-name path))
781 path)))
782 ((string= type "")
783 (list nil path))
784 (t (list type path))))
786 ;;Second pass. Components converted so they can refer
787 ;;to a remote site.
788 (components-2
790 (and org-html-cvt-link-fn
791 (apply org-html-cvt-link-fn
792 opt-plist components-1))
793 (apply #'org-html-cvt-org-as-html
794 opt-plist components-1)
795 components-1))
796 (type (first components-2))
797 (thefile (second components-2)))
800 ;;Third pass. Build final link except for leading type
801 ;;spec.
802 (cond
803 ((or
804 (not type)
805 (string= type "http")
806 (string= type "https")
807 (string= type "file"))
808 (if fragment
809 (setq thefile (concat thefile "#" fragment))))
811 (t))
813 ;;Final URL-build, for all types.
814 (setq thefile
815 (let
816 ((str (org-export-html-format-href thefile)))
817 (if (and type (not (string= "file" type)))
818 (concat type ":" str)
819 str)))
821 (if (and
822 may-inline-p
823 ;;Can't inline a URL with a fragment.
824 (not fragment))
825 (progn
826 (message "image %s %s" thefile org-par-open)
827 (org-export-html-format-image thefile org-par-open))
828 (concat
829 "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
830 (org-export-html-format-desc desc)
831 "</a>")))))
833 (defun org-html-handle-links (line opt-plist)
834 "Return LINE with markup of Org mode links.
835 OPT-PLIST is the export options list."
836 (let ((start 0)
837 (current-dir (if buffer-file-name
838 (file-name-directory buffer-file-name)
839 default-directory))
840 (link-validate (plist-get opt-plist :link-validation-function))
841 type id-file fnc
842 rpl path attr desc descp desc1 desc2 link)
843 (while (string-match org-bracket-link-analytic-regexp++ line start)
844 (setq start (match-beginning 0))
845 (setq path (save-match-data (org-link-unescape
846 (match-string 3 line))))
847 (setq type (cond
848 ((match-end 2) (match-string 2 line))
849 ((save-match-data
850 (or (file-name-absolute-p path)
851 (string-match "^\\.\\.?/" path)))
852 "file")
853 (t "internal")))
854 (setq path (org-extract-attributes (org-link-unescape path)))
855 (setq attr (get-text-property 0 'org-attributes path))
856 (setq desc1 (if (match-end 5) (match-string 5 line))
857 desc2 (if (match-end 2) (concat type ":" path) path)
858 descp (and desc1 (not (equal desc1 desc2)))
859 desc (or desc1 desc2))
860 ;; Make an image out of the description if that is so wanted
861 (when (and descp (org-file-image-p
862 desc org-export-html-inline-image-extensions))
863 (save-match-data
864 (if (string-match "^file:" desc)
865 (setq desc (substring desc (match-end 0)))))
866 (setq desc (org-add-props
867 (concat "<img src=\"" desc "\"/>")
868 '(org-protected t))))
869 (cond
870 ((equal type "internal")
871 (let
872 ((frag-0
873 (if (= (string-to-char path) ?#)
874 (substring path 1)
875 path)))
876 (setq rpl
877 (org-html-make-link
878 opt-plist
881 (org-solidify-link-text
882 (save-match-data (org-link-unescape frag-0))
883 nil)
884 desc attr nil))))
885 ((and (equal type "id")
886 (setq id-file (org-id-find-id-file path)))
887 ;; This is an id: link to another file (if it was the same file,
888 ;; it would have become an internal link...)
889 (save-match-data
890 (setq id-file (file-relative-name
891 id-file
892 (file-name-directory org-current-export-file)))
893 (setq rpl
894 (org-html-make-link opt-plist
895 "file" id-file
896 (concat (if (org-uuidgen-p path) "ID-") path)
897 desc
898 attr
899 nil))))
900 ((member type '("http" "https"))
901 ;; standard URL, can inline as image
902 (setq rpl
903 (org-html-make-link opt-plist
904 type path nil
905 desc
906 attr
907 (org-html-should-inline-p path descp))))
908 ((member type '("ftp" "mailto" "news"))
909 ;; standard URL, can't inline as image
910 (setq rpl
911 (org-html-make-link opt-plist
912 type path nil
913 desc
914 attr
915 nil)))
917 ((string= type "coderef")
918 (let*
919 ((coderef-str (format "coderef-%s" path))
920 (attr-1
921 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
922 coderef-str coderef-str)))
923 (setq rpl
924 (org-html-make-link opt-plist
925 type "" coderef-str
926 (format
927 (org-export-get-coderef-format
928 path
929 (and descp desc))
930 (cdr (assoc path org-export-code-refs)))
931 attr-1
932 nil))))
934 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
935 ;; The link protocol has a function for format the link
936 (setq rpl
937 (save-match-data
938 (funcall fnc (org-link-unescape path) desc1 'html))))
940 ((string= type "file")
941 ;; FILE link
942 (save-match-data
943 (let*
944 ((components
946 (string-match "::\\(.*\\)" path)
947 (list
948 (replace-match "" t nil path)
949 (match-string 1 path))
950 (list path nil)))
952 ;;The proper path, without a fragment
953 (path-1
954 (first components))
956 ;;The raw fragment
957 (fragment-0
958 (second components))
960 ;;Check the fragment. If it can't be used as
961 ;;target fragment we'll pass nil instead.
962 (fragment-1
964 (and fragment-0
965 (not (string-match "^[0-9]*$" fragment-0))
966 (not (string-match "^\\*" fragment-0))
967 (not (string-match "^/.*/$" fragment-0)))
968 (org-solidify-link-text
969 (org-link-unescape fragment-0))
970 nil))
971 (desc-2
972 ;;Description minus "file:" and ".org"
973 (if (string-match "^file:" desc)
974 (let
975 ((desc-1 (replace-match "" t t desc)))
976 (if (string-match "\\.org$" desc-1)
977 (replace-match "" t t desc-1)
978 desc-1))
979 desc)))
981 (setq rpl
983 (and
984 (functionp link-validate)
985 (not (funcall link-validate path-1 current-dir)))
986 desc
987 (org-html-make-link opt-plist
988 "file" path-1 fragment-1 desc-2 attr
989 (org-html-should-inline-p path-1 descp)))))))
992 ;; just publish the path, as default
993 (setq rpl (concat "<i>&lt;" type ":"
994 (save-match-data (org-link-unescape path))
995 "&gt;</i>"))))
996 (setq line (replace-match rpl t t line)
997 start (+ start (length rpl))))
998 line))
1000 ;;; org-export-as-html
1001 ;;;###autoload
1002 (defun org-export-as-html (arg &optional hidden ext-plist
1003 to-buffer body-only pub-dir)
1004 "Export the outline as a pretty HTML file.
1005 If there is an active region, export only the region. The prefix
1006 ARG specifies how many levels of the outline should become
1007 headlines. The default is 3. Lower levels will become bulleted
1008 lists. HIDDEN is obsolete and does nothing.
1009 EXT-PLIST is a property list with external parameters overriding
1010 org-mode's default settings, but still inferior to file-local
1011 settings. When TO-BUFFER is non-nil, create a buffer with that
1012 name and export to that buffer. If TO-BUFFER is the symbol
1013 `string', don't leave any buffer behind but just return the
1014 resulting HTML as a string. When BODY-ONLY is set, don't produce
1015 the file header and footer, simply return the content of
1016 <body>...</body>, without even the body tags themselves. When
1017 PUB-DIR is set, use this as the publishing directory."
1018 (interactive "P")
1019 (run-hooks 'org-export-first-hook)
1021 ;; Make sure we have a file name when we need it.
1022 (when (and (not (or to-buffer body-only))
1023 (not buffer-file-name))
1024 (if (buffer-base-buffer)
1025 (org-set-local 'buffer-file-name
1026 (with-current-buffer (buffer-base-buffer)
1027 buffer-file-name))
1028 (error "Need a file name to be able to export")))
1030 (message "Exporting...")
1031 (setq-default org-todo-line-regexp org-todo-line-regexp)
1032 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
1033 (setq-default org-done-keywords org-done-keywords)
1034 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
1035 (let* ((opt-plist
1036 (org-export-process-option-filters
1037 (org-combine-plists (org-default-export-plist)
1038 ext-plist
1039 (org-infile-export-plist))))
1040 (body-only (or body-only (plist-get opt-plist :body-only)))
1041 (style (concat (if (plist-get opt-plist :style-include-default)
1042 org-export-html-style-default)
1043 (plist-get opt-plist :style)
1044 (plist-get opt-plist :style-extra)
1045 "\n"
1046 (if (plist-get opt-plist :style-include-scripts)
1047 org-export-html-scripts)))
1048 (html-extension (plist-get opt-plist :html-extension))
1049 valid thetoc have-headings first-heading-pos
1050 (odd org-odd-levels-only)
1051 (region-p (org-region-active-p))
1052 (rbeg (and region-p (region-beginning)))
1053 (rend (and region-p (region-end)))
1054 (subtree-p
1055 (if (plist-get opt-plist :ignore-subtree-p)
1057 (when region-p
1058 (save-excursion
1059 (goto-char rbeg)
1060 (and (org-at-heading-p)
1061 (>= (org-end-of-subtree t t) rend))))))
1062 (level-offset (if subtree-p
1063 (save-excursion
1064 (goto-char rbeg)
1065 (+ (funcall outline-level)
1066 (if org-odd-levels-only 1 0)))
1068 (opt-plist (setq org-export-opt-plist
1069 (if subtree-p
1070 (org-export-add-subtree-options opt-plist rbeg)
1071 opt-plist)))
1072 ;; The following two are dynamically scoped into other
1073 ;; routines below.
1074 (org-current-export-dir
1075 (or pub-dir (org-export-directory :html opt-plist)))
1076 (org-current-export-file buffer-file-name)
1077 (level 0) (line "") (origline "") txt todo
1078 (umax nil)
1079 (umax-toc nil)
1080 (filename (if to-buffer nil
1081 (expand-file-name
1082 (concat
1083 (file-name-sans-extension
1084 (or (and subtree-p
1085 (org-entry-get (region-beginning)
1086 "EXPORT_FILE_NAME" t))
1087 (file-name-nondirectory buffer-file-name)))
1088 "." html-extension)
1089 (file-name-as-directory
1090 (or pub-dir (org-export-directory :html opt-plist))))))
1091 (current-dir (if buffer-file-name
1092 (file-name-directory buffer-file-name)
1093 default-directory))
1094 (buffer (if to-buffer
1095 (cond
1096 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
1097 (t (get-buffer-create to-buffer)))
1098 (find-file-noselect filename)))
1099 (org-levels-open (make-vector org-level-max nil))
1100 (date (plist-get opt-plist :date))
1101 (author (plist-get opt-plist :author))
1102 (html-validation-link (or org-export-html-validation-link ""))
1103 (title (org-html-expand
1104 (or (and subtree-p (org-export-get-title-from-subtree))
1105 (plist-get opt-plist :title)
1106 (and (not body-only)
1107 (not
1108 (plist-get opt-plist :skip-before-1st-heading))
1109 (org-export-grab-title-from-buffer))
1110 (and buffer-file-name
1111 (file-name-sans-extension
1112 (file-name-nondirectory buffer-file-name)))
1113 "UNTITLED")))
1114 (link-up (and (plist-get opt-plist :link-up)
1115 (string-match "\\S-" (plist-get opt-plist :link-up))
1116 (plist-get opt-plist :link-up)))
1117 (link-home (and (plist-get opt-plist :link-home)
1118 (string-match "\\S-" (plist-get opt-plist :link-home))
1119 (plist-get opt-plist :link-home)))
1120 (dummy (setq opt-plist (plist-put opt-plist :title title)))
1121 (html-table-tag (plist-get opt-plist :html-table-tag))
1122 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1123 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
1124 (inquote nil)
1125 (infixed nil)
1126 (inverse nil)
1127 (email (plist-get opt-plist :email))
1128 (language (plist-get opt-plist :language))
1129 (keywords (plist-get opt-plist :keywords))
1130 (description (plist-get opt-plist :description))
1131 (lang-words nil)
1132 (head-count 0) cnt
1133 (start 0)
1134 (coding-system (and (boundp 'buffer-file-coding-system)
1135 buffer-file-coding-system))
1136 (coding-system-for-write (or org-export-html-coding-system
1137 coding-system))
1138 (save-buffer-coding-system (or org-export-html-coding-system
1139 coding-system))
1140 (charset (and coding-system-for-write
1141 (fboundp 'coding-system-get)
1142 (coding-system-get coding-system-for-write
1143 'mime-charset)))
1144 (region
1145 (buffer-substring
1146 (if region-p (region-beginning) (point-min))
1147 (if region-p (region-end) (point-max))))
1148 (org-export-have-math nil)
1149 (lines
1150 (org-split-string
1151 (org-export-preprocess-string
1152 region
1153 :emph-multiline t
1154 :for-backend 'html
1155 :skip-before-1st-heading
1156 (plist-get opt-plist :skip-before-1st-heading)
1157 :drawers (plist-get opt-plist :drawers)
1158 :todo-keywords (plist-get opt-plist :todo-keywords)
1159 :tags (plist-get opt-plist :tags)
1160 :priority (plist-get opt-plist :priority)
1161 :footnotes (plist-get opt-plist :footnotes)
1162 :timestamps (plist-get opt-plist :timestamps)
1163 :archived-trees
1164 (plist-get opt-plist :archived-trees)
1165 :select-tags (plist-get opt-plist :select-tags)
1166 :exclude-tags (plist-get opt-plist :exclude-tags)
1167 :add-text
1168 (plist-get opt-plist :text)
1169 :LaTeX-fragments
1170 (plist-get opt-plist :LaTeX-fragments))
1171 "[\r\n]"))
1172 (mathjax
1173 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
1174 (and org-export-have-math
1175 (eq (plist-get opt-plist :LaTeX-fragments) t)))
1177 (org-export-html-mathjax-config
1178 org-export-html-mathjax-template
1179 org-export-html-mathjax-options
1180 (or (plist-get opt-plist :mathjax) ""))
1181 ""))
1182 table-open
1183 table-buffer table-orig-buffer
1185 rpl path attr desc descp desc1 desc2 link
1186 snumber fnc
1187 footnotes footref-seen
1188 href
1191 (let ((inhibit-read-only t))
1192 (org-unmodified
1193 (remove-text-properties (point-min) (point-max)
1194 '(:org-license-to-kill t))))
1196 (message "Exporting...")
1198 (setq org-min-level (org-get-min-level lines level-offset))
1199 (setq org-last-level org-min-level)
1200 (org-init-section-numbers)
1202 (cond
1203 ((and date (string-match "%" date))
1204 (setq date (format-time-string date)))
1205 (date)
1206 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
1208 ;; Get the language-dependent settings
1209 (setq lang-words (or (assoc language org-export-language-setup)
1210 (assoc "en" org-export-language-setup)))
1212 ;; Switch to the output buffer
1213 (set-buffer buffer)
1214 (let ((inhibit-read-only t)) (erase-buffer))
1215 (fundamental-mode)
1216 (org-install-letbind)
1218 (and (fboundp 'set-buffer-file-coding-system)
1219 (set-buffer-file-coding-system coding-system-for-write))
1221 (let ((case-fold-search nil)
1222 (org-odd-levels-only odd))
1223 ;; create local variables for all options, to make sure all called
1224 ;; functions get the correct information
1225 (mapc (lambda (x)
1226 (set (make-local-variable (nth 2 x))
1227 (plist-get opt-plist (car x))))
1228 org-export-plist-vars)
1229 (setq umax (if arg (prefix-numeric-value arg)
1230 org-export-headline-levels))
1231 (setq umax-toc (if (integerp org-export-with-toc)
1232 (min org-export-with-toc umax)
1233 umax))
1234 (unless body-only
1235 ;; File header
1236 (insert (format
1238 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1239 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1240 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1241 lang=\"%s\" xml:lang=\"%s\">
1242 <head>
1243 <title>%s</title>
1244 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1245 <meta name=\"generator\" content=\"Org-mode\"/>
1246 <meta name=\"generated\" content=\"%s\"/>
1247 <meta name=\"author\" content=\"%s\"/>
1248 <meta name=\"description\" content=\"%s\"/>
1249 <meta name=\"keywords\" content=\"%s\"/>
1252 </head>
1253 <body>
1254 <div id=\"content\">
1257 (format
1258 (or (and (stringp org-export-html-xml-declaration)
1259 org-export-html-xml-declaration)
1260 (cdr (assoc html-extension org-export-html-xml-declaration))
1261 (cdr (assoc "html" org-export-html-xml-declaration))
1264 (or charset "iso-8859-1"))
1265 language language
1266 title
1267 (or charset "iso-8859-1")
1268 date author description keywords
1269 style
1270 mathjax
1271 (if (or link-up link-home)
1272 (concat
1273 (format org-export-html-home/up-format
1274 (or link-up link-home)
1275 (or link-home link-up))
1276 "\n")
1277 "")))
1279 ;; insert html preamble
1280 (if (plist-get opt-plist :html-preamble)
1281 (let* ((html-preamble (plist-get opt-plist :html-preamble))
1282 (html-preamble-format
1283 (if (stringp html-preamble)
1284 html-preamble
1285 (cadr (or (assoc (nth 0 lang-words)
1286 org-export-html-preamble-format)
1287 (assoc "en" org-export-html-preamble-format))))))
1288 (insert (format-spec html-preamble-format
1289 `((?t . ,title)
1290 (?a . ,author) (?d . ,date) (?e . ,email)))))
1291 (insert "<h1 class=\"title\">" title "</h1>")))
1293 (if (and org-export-with-toc (not body-only))
1294 (progn
1295 (push (format "<h%d>%s</h%d>\n"
1296 org-export-html-toplevel-hlevel
1297 (nth 3 lang-words)
1298 org-export-html-toplevel-hlevel)
1299 thetoc)
1300 (push "<div id=\"text-table-of-contents\">\n" thetoc)
1301 (push "<ul>\n<li>" thetoc)
1302 (setq lines
1303 (mapcar '(lambda (line)
1304 (if (and (string-match org-todo-line-regexp line)
1305 (not (get-text-property 0 'org-protected line)))
1306 ;; This is a headline
1307 (progn
1308 (setq have-headings t)
1309 (setq level (- (match-end 1) (match-beginning 1)
1310 level-offset)
1311 level (org-tr-level level)
1312 txt (save-match-data
1313 (org-html-expand
1314 (org-export-cleanup-toc-line
1315 (match-string 3 line))))
1316 todo
1317 (or (and org-export-mark-todo-in-toc
1318 (match-beginning 2)
1319 (not (member (match-string 2 line)
1320 org-done-keywords)))
1321 ; TODO, not DONE
1322 (and org-export-mark-todo-in-toc
1323 (= level umax-toc)
1324 (org-search-todo-below
1325 line lines level))))
1326 (if (string-match
1327 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
1328 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
1329 (if (string-match quote-re0 txt)
1330 (setq txt (replace-match "" t t txt)))
1331 (setq snumber (org-section-number level))
1332 (if org-export-with-section-numbers
1333 (setq txt (concat snumber " " txt)))
1334 (if (<= level (max umax umax-toc))
1335 (setq head-count (+ head-count 1)))
1336 (if (<= level umax-toc)
1337 (progn
1338 (if (> level org-last-level)
1339 (progn
1340 (setq cnt (- level org-last-level))
1341 (while (>= (setq cnt (1- cnt)) 0)
1342 (push "\n<ul>\n<li>" thetoc))
1343 (push "\n" thetoc)))
1344 (if (< level org-last-level)
1345 (progn
1346 (setq cnt (- org-last-level level))
1347 (while (>= (setq cnt (1- cnt)) 0)
1348 (push "</li>\n</ul>" thetoc))
1349 (push "\n" thetoc)))
1350 ;; Check for targets
1351 (while (string-match org-any-target-regexp line)
1352 (setq line (replace-match
1353 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
1354 t t line)))
1355 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
1356 (setq txt (replace-match "" t t txt)))
1357 (setq href
1358 (replace-regexp-in-string
1359 "\\." "_" (format "sec-%s" snumber)))
1360 (setq href (org-solidify-link-text (or (cdr (assoc href org-export-preferred-target-alist)) href)))
1361 (push
1362 (format
1363 (if todo
1364 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1365 "</li>\n<li><a href=\"#%s\">%s</a>")
1366 href txt) thetoc)
1368 (setq org-last-level level))
1370 line)
1371 lines))
1372 (while (> org-last-level (1- org-min-level))
1373 (setq org-last-level (1- org-last-level))
1374 (push "</li>\n</ul>\n" thetoc))
1375 (push "</div>\n" thetoc)
1376 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1378 (setq head-count 0)
1379 (org-init-section-numbers)
1381 (org-open-par)
1383 (while (setq line (pop lines) origline line)
1384 (catch 'nextline
1386 ;; end of quote section?
1387 (when (and inquote (string-match "^\\*+ " line))
1388 (insert "</pre>\n")
1389 (org-open-par)
1390 (setq inquote nil))
1391 ;; inside a quote section?
1392 (when inquote
1393 (insert (org-html-protect line) "\n")
1394 (throw 'nextline nil))
1396 ;; Fixed-width, verbatim lines (examples)
1397 (when (and org-export-with-fixed-width
1398 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
1399 (when (not infixed)
1400 (setq infixed t)
1401 (org-close-par-maybe)
1403 (insert "<pre class=\"example\">\n"))
1404 (insert (org-html-protect (match-string 3 line)) "\n")
1405 (when (or (not lines)
1406 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1407 (car lines))))
1408 (setq infixed nil)
1409 (insert "</pre>\n")
1410 (org-open-par))
1411 (throw 'nextline nil))
1413 ;; Protected HTML
1414 (when (and (get-text-property 0 'org-protected line)
1415 ;; Make sure it is the entire line that is protected
1416 (not (< (or (next-single-property-change
1417 0 'org-protected line) 10000)
1418 (length line))))
1419 (let (par (ind (get-text-property 0 'original-indentation line)))
1420 (when (re-search-backward
1421 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
1422 (setq par (match-string 1))
1423 (replace-match "\\2\n"))
1424 (insert line "\n")
1425 (while (and lines
1426 (or (= (length (car lines)) 0)
1427 (not ind)
1428 (equal ind (get-text-property 0 'original-indentation (car lines))))
1429 (or (= (length (car lines)) 0)
1430 (get-text-property 0 'org-protected (car lines))))
1431 (insert (pop lines) "\n"))
1432 (and par (insert "<p>\n")))
1433 (throw 'nextline nil))
1435 ;; Blockquotes, verse, and center
1436 (when (equal "ORG-BLOCKQUOTE-START" line)
1437 (org-close-par-maybe)
1438 (insert "<blockquote>\n")
1439 (org-open-par)
1440 (throw 'nextline nil))
1441 (when (equal "ORG-BLOCKQUOTE-END" line)
1442 (org-close-par-maybe)
1443 (insert "\n</blockquote>\n")
1444 (org-open-par)
1445 (throw 'nextline nil))
1446 (when (equal "ORG-VERSE-START" line)
1447 (org-close-par-maybe)
1448 (insert "\n<p class=\"verse\">\n")
1449 (setq org-par-open t)
1450 (setq inverse t)
1451 (throw 'nextline nil))
1452 (when (equal "ORG-VERSE-END" line)
1453 (insert "</p>\n")
1454 (setq org-par-open nil)
1455 (org-open-par)
1456 (setq inverse nil)
1457 (throw 'nextline nil))
1458 (when (equal "ORG-CENTER-START" line)
1459 (org-close-par-maybe)
1460 (insert "\n<div style=\"text-align: center\">")
1461 (org-open-par)
1462 (throw 'nextline nil))
1463 (when (equal "ORG-CENTER-END" line)
1464 (org-close-par-maybe)
1465 (insert "\n</div>")
1466 (org-open-par)
1467 (throw 'nextline nil))
1468 (run-hooks 'org-export-html-after-blockquotes-hook)
1469 (when inverse
1470 (let ((i (org-get-string-indentation line)))
1471 (if (> i 0)
1472 (setq line (concat (mapconcat 'identity
1473 (make-list (* 2 i) "\\nbsp") "")
1474 " " (org-trim line))))
1475 (unless (string-match "\\\\\\\\[ \t]*$" line)
1476 (setq line (concat line "\\\\")))))
1478 ;; make targets to anchors
1479 (setq start 0)
1480 (while (string-match
1481 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1482 (cond
1483 ((get-text-property (match-beginning 1) 'org-protected line)
1484 (setq start (match-end 1)))
1485 ((match-end 2)
1486 (setq line (replace-match
1487 (format
1488 "@<a name=\"%s\" id=\"%s\">@</a>"
1489 (org-solidify-link-text (match-string 1 line))
1490 (org-solidify-link-text (match-string 1 line)))
1491 t t line)))
1492 ((and org-export-with-toc (equal (string-to-char line) ?*))
1493 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1494 (setq line (replace-match
1495 (concat "@<span class=\"target\">"
1496 (match-string 1 line) "@</span> ")
1497 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1498 t t line)))
1500 (setq line (replace-match
1501 (concat "@<a name=\""
1502 (org-solidify-link-text (match-string 1 line))
1503 "\" class=\"target\">" (match-string 1 line)
1504 "@</a> ")
1505 t t line)))))
1507 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1508 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
1509 ;; Also handle sub_superscripts and checkboxes
1510 (or (string-match org-table-hline-regexp line)
1511 (setq line (org-html-expand line)))
1513 ;; Format the links
1514 (setq line (org-html-handle-links line opt-plist))
1516 (setq line (org-html-handle-time-stamps line))
1518 ;; TODO items
1519 (if (and (string-match org-todo-line-regexp line)
1520 (match-beginning 2))
1522 (setq line
1523 (concat (substring line 0 (match-beginning 2))
1524 "<span class=\""
1525 (if (member (match-string 2 line)
1526 org-done-keywords)
1527 "done" "todo")
1528 " " (match-string 2 line)
1529 "\"> " (org-export-html-get-todo-kwd-class-name
1530 (match-string 2 line))
1531 "</span>" (substring line (match-end 2)))))
1533 ;; Does this contain a reference to a footnote?
1534 (when org-export-with-footnotes
1535 (setq start 0)
1536 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
1537 (if (get-text-property (match-beginning 2) 'org-protected line)
1538 (setq start (match-end 2))
1539 (let ((n (match-string 2 line)) extra a)
1540 (if (setq a (assoc n footref-seen))
1541 (progn
1542 (setcdr a (1+ (cdr a)))
1543 (setq extra (format ".%d" (cdr a))))
1544 (setq extra "")
1545 (push (cons n 1) footref-seen))
1546 (setq line
1547 (replace-match
1548 (format
1549 (concat "%s"
1550 (format org-export-html-footnote-format
1551 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
1552 (or (match-string 1 line) "") n extra n n)
1553 t t line))))))
1555 (cond
1556 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1557 ;; This is a headline
1558 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1559 level-offset))
1560 txt (match-string 2 line))
1561 (if (string-match quote-re0 txt)
1562 (setq txt (replace-match "" t t txt)))
1563 (if (<= level (max umax umax-toc))
1564 (setq head-count (+ head-count 1)))
1565 (setq first-heading-pos (or first-heading-pos (point)))
1566 (org-html-level-start level txt umax
1567 (and org-export-with-toc (<= level umax))
1568 head-count)
1570 ;; QUOTES
1571 (when (string-match quote-re line)
1572 (org-close-par-maybe)
1573 (insert "<pre>")
1574 (setq inquote t)))
1576 ((and org-export-with-tables
1577 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1578 (when (not table-open)
1579 ;; New table starts
1580 (setq table-open t table-buffer nil table-orig-buffer nil))
1582 ;; Accumulate lines
1583 (setq table-buffer (cons line table-buffer)
1584 table-orig-buffer (cons origline table-orig-buffer))
1585 (when (or (not lines)
1586 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1587 (car lines))))
1588 (setq table-open nil
1589 table-buffer (nreverse table-buffer)
1590 table-orig-buffer (nreverse table-orig-buffer))
1591 (org-close-par-maybe)
1592 (insert (org-format-table-html table-buffer table-orig-buffer))))
1594 ;; Normal lines
1597 ;; This line either is list item or end a list.
1598 (when (get-text-property 0 'list-item line)
1599 (setq line (org-html-export-list-line
1600 line
1601 (get-text-property 0 'list-item line)
1602 (get-text-property 0 'list-struct line)
1603 (get-text-property 0 'list-prevs line))))
1605 ;; Horizontal line
1606 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1607 (if org-par-open
1608 (insert "\n</p>\n<hr/>\n<p>\n")
1609 (insert "\n<hr/>\n"))
1610 (throw 'nextline nil))
1612 ;; Empty lines start a new paragraph. If hand-formatted lists
1613 ;; are not fully interpreted, lines starting with "-", "+", "*"
1614 ;; also start a new paragraph.
1615 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
1617 ;; Is this the start of a footnote?
1618 (when org-export-with-footnotes
1619 (when (and (boundp 'footnote-section-tag-regexp)
1620 (string-match (concat "^" footnote-section-tag-regexp)
1621 line))
1622 ;; ignore this line
1623 (throw 'nextline nil))
1624 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1625 (org-close-par-maybe)
1626 (let ((n (match-string 1 line)))
1627 (setq org-par-open t
1628 line (replace-match
1629 (format
1630 (concat "<p class=\"footnote\">"
1631 (format org-export-html-footnote-format
1632 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1633 n n n) t t line)))))
1634 ;; Check if the line break needs to be conserved
1635 (cond
1636 ((string-match "\\\\\\\\[ \t]*$" line)
1637 (setq line (replace-match "<br/>" t t line)))
1638 (org-export-preserve-breaks
1639 (setq line (concat line "<br/>"))))
1641 ;; Check if a paragraph should be started
1642 (let ((start 0))
1643 (while (and org-par-open
1644 (string-match "\\\\par\\>" line start))
1645 ;; Leave a space in the </p> so that the footnote matcher
1646 ;; does not see this.
1647 (if (not (get-text-property (match-beginning 0)
1648 'org-protected line))
1649 (setq line (replace-match "</p ><p >" t t line)))
1650 (setq start (match-end 0))))
1652 (insert line "\n")))))
1654 ;; Properly close all local lists and other lists
1655 (when inquote
1656 (insert "</pre>\n")
1657 (org-open-par))
1659 (org-html-level-start 1 nil umax
1660 (and org-export-with-toc (<= level umax))
1661 head-count)
1662 ;; the </div> to close the last text-... div.
1663 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
1665 (save-excursion
1666 (goto-char (point-min))
1667 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
1668 (push (match-string 0) footnotes)
1669 (replace-match "" t t)))
1670 (when footnotes
1671 (insert (format org-export-html-footnotes-section
1672 (nth 4 lang-words)
1673 (mapconcat 'identity (nreverse footnotes) "\n"))
1674 "\n"))
1675 (let ((bib (org-export-html-get-bibliography)))
1676 (when bib
1677 (insert "\n" bib "\n")))
1679 ;; export html postamble
1680 (unless body-only
1681 (if (plist-get opt-plist :html-postamble)
1682 (let* ((html-postamble (plist-get opt-plist :html-postamble))
1683 (html-postamble-format
1684 (if (stringp html-postamble)
1685 html-postamble
1686 (or (cadr (assoc (nth 0 lang-words)
1687 org-export-html-postamble-format))
1688 (cadr (assoc "en" org-export-html-postamble-format)))))
1689 (email
1690 (mapconcat (lambda(e)
1691 (format "<a href=\"mailto:%s\">%s</a>" e e))
1692 (split-string email ",+ *")
1693 ", "))
1694 (creator-info
1695 (concat "Org version " org-version " with Emacs version "
1696 (number-to-string emacs-major-version))))
1697 (insert "<div id=\"postamble\">\n")
1698 (insert (format-spec html-postamble-format
1699 `((?a . ,author) (?e . ,email)
1700 (?d . ,date) (?c . ,creator-info)
1701 (?v . ,html-validation-link))))
1702 (insert "</div>"))
1703 ;; fall back on default postamble
1704 (insert "<div id=\"postamble\">\n")
1705 (when (and (plist-get opt-plist :author-info) author)
1706 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1707 (when (and (plist-get opt-plist :email-info) email)
1708 (insert "<p class=\"mailto:" email "\">&lt;" email "&gt;</p>\n"))
1709 (when (plist-get opt-plist :creator-info)
1710 (insert "<p class=\"creator\">"
1711 (concat "Org version " org-version " with Emacs version "
1712 (number-to-string emacs-major-version) "</p>\n")))
1713 (insert html-validation-link "\n</div>")))
1715 (if org-export-html-with-timestamp
1716 (insert org-export-html-html-helper-timestamp))
1718 (insert "\n</div>\n</body>\n</html>\n")
1720 (unless (plist-get opt-plist :buffer-will-be-killed)
1721 (normal-mode)
1722 (if (eq major-mode (default-value 'major-mode))
1723 (html-mode)))
1725 ;; insert the table of contents
1726 (goto-char (point-min))
1727 (when thetoc
1728 (if (or (re-search-forward
1729 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1730 (re-search-forward
1731 "\\[TABLE-OF-CONTENTS\\]" nil t))
1732 (progn
1733 (goto-char (match-beginning 0))
1734 (replace-match ""))
1735 (goto-char first-heading-pos)
1736 (when (looking-at "\\s-*</p>")
1737 (goto-char (match-end 0))
1738 (insert "\n")))
1739 (insert "<div id=\"table-of-contents\">\n")
1740 (let ((beg (point)))
1741 (mapc 'insert thetoc)
1742 (insert "</div>\n")
1743 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
1744 (replace-match ""))))
1745 ;; remove empty paragraphs
1746 (goto-char (point-min))
1747 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
1748 (replace-match ""))
1749 (goto-char (point-min))
1750 ;; Convert whitespace place holders
1751 (goto-char (point-min))
1752 (let (beg end n)
1753 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1754 (setq n (get-text-property beg 'org-whitespace)
1755 end (next-single-property-change beg 'org-whitespace))
1756 (goto-char beg)
1757 (delete-region beg end)
1758 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1759 (make-string n ?x)))))
1760 ;; Remove empty lines at the beginning of the file.
1761 (goto-char (point-min))
1762 (when (looking-at "\\s-+\n") (replace-match ""))
1763 ;; Remove display properties
1764 (remove-text-properties (point-min) (point-max) '(display t))
1765 ;; Run the hook
1766 (run-hooks 'org-export-html-final-hook)
1767 (or to-buffer (save-buffer))
1768 (goto-char (point-min))
1769 (or (org-export-push-to-kill-ring "HTML")
1770 (message "Exporting... done"))
1771 (if (eq to-buffer 'string)
1772 (prog1 (buffer-substring (point-min) (point-max))
1773 (kill-buffer (current-buffer)))
1774 (current-buffer)))))
1776 (defun org-export-html-insert-plist-item (plist key &rest args)
1777 (let ((item (plist-get plist key)))
1778 (cond ((functionp item)
1779 (apply item args))
1780 (item
1781 (insert item)))))
1783 (defun org-export-html-format-href (s)
1784 "Make sure the S is valid as a href reference in an XHTML document."
1785 (save-match-data
1786 (let ((start 0))
1787 (while (string-match "&" s start)
1788 (setq start (+ (match-beginning 0) 3)
1789 s (replace-match "&amp;" t t s)))))
1792 (defun org-export-html-format-desc (s)
1793 "Make sure the S is valid as a description in a link."
1794 (if (and s (not (get-text-property 1 'org-protected s)))
1795 (save-match-data
1796 (org-html-do-expand s))
1799 (defun org-export-html-format-image (src par-open)
1800 "Create image tag with source and attributes."
1801 (save-match-data
1802 (if (string-match "^ltxpng/" src)
1803 (format "<img src=\"%s\" alt=\"%s\"/>"
1804 src (org-find-text-property-in-string 'org-latex-src src))
1805 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1806 (attr (org-find-text-property-in-string 'org-attributes src))
1807 (label (org-find-text-property-in-string 'org-label src)))
1808 (setq caption (and caption (org-html-do-expand caption)))
1809 (concat
1810 (if caption
1811 (format "%s<div %sclass=\"figure\">
1812 <p>"
1813 (if org-par-open "</p>\n" "")
1814 (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
1815 (format "<img src=\"%s\"%s />"
1817 (if (string-match "\\<alt=" (or attr ""))
1818 (concat " " attr )
1819 (concat " " attr " alt=\"" src "\"")))
1820 (if caption
1821 (format "</p>%s
1822 </div>%s"
1823 (concat "\n<p>" caption "</p>")
1824 (if org-par-open "\n<p>" ""))))))))
1826 (defun org-export-html-get-bibliography ()
1827 "Find bibliography, cut it out and return it."
1828 (catch 'exit
1829 (let (beg end (cnt 1) bib)
1830 (save-excursion
1831 (goto-char (point-min))
1832 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1833 (setq beg (match-beginning 0))
1834 (while (re-search-forward "</?div\\>" nil t)
1835 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1836 (when (= cnt 0)
1837 (and (looking-at ">") (forward-char 1))
1838 (setq bib (buffer-substring beg (point)))
1839 (delete-region beg (point))
1840 (throw 'exit bib))))
1841 nil))))
1843 (defvar org-table-number-regexp) ; defined in org-table.el
1844 (defun org-format-table-html (lines olines &optional no-css)
1845 "Find out which HTML converter to use and return the HTML code.
1846 NO-CSS is passed to the exporter."
1847 (if (stringp lines)
1848 (setq lines (org-split-string lines "\n")))
1849 (if (string-match "^[ \t]*|" (car lines))
1850 ;; A normal org table
1851 (org-format-org-table-html lines nil no-css)
1852 ;; Table made by table.el - test for spanning
1853 (let* ((hlines (delq nil (mapcar
1854 (lambda (x)
1855 (if (string-match "^[ \t]*\\+-" x) x
1856 nil))
1857 lines)))
1858 (first (car hlines))
1859 (ll (and (string-match "\\S-+" first)
1860 (match-string 0 first)))
1861 (re (concat "^[ \t]*" (regexp-quote ll)))
1862 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
1863 hlines))))
1864 (if (and (not spanning)
1865 (not org-export-prefer-native-exporter-for-tables))
1866 ;; We can use my own converter with HTML conversions
1867 (org-format-table-table-html lines)
1868 ;; Need to use the code generator in table.el, with the original text.
1869 (org-format-table-table-html-using-table-generate-source olines)))))
1871 (defvar org-table-number-fraction) ; defined in org-table.el
1872 (defun org-format-org-table-html (lines &optional splice no-css)
1873 "Format a table into HTML.
1874 LINES is a list of lines. Optional argument SPLICE means, do not
1875 insert header and surrounding <table> tags, just format the lines.
1876 Optional argument NO-CSS means use XHTML attributes instead of CSS
1877 for formatting. This is required for the DocBook exporter."
1878 (require 'org-table)
1879 ;; Get rid of hlines at beginning and end
1880 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1881 (setq lines (nreverse lines))
1882 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1883 (setq lines (nreverse lines))
1884 (when org-export-table-remove-special-lines
1885 ;; Check if the table has a marking column. If yes remove the
1886 ;; column and the special lines
1887 (setq lines (org-table-clean-before-export lines)))
1889 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
1890 (label (org-find-text-property-in-string 'org-label (car lines)))
1891 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
1892 (car lines)))
1893 (attributes (org-find-text-property-in-string 'org-attributes
1894 (car lines)))
1895 (html-table-tag (org-export-splice-attributes
1896 html-table-tag attributes))
1897 (head (and org-export-highlight-first-table-line
1898 (delq nil (mapcar
1899 (lambda (x) (string-match "^[ \t]*|-" x))
1900 (cdr lines)))))
1901 (nline 0) fnum nfields i (cnt 0)
1902 tbopen line fields html gr colgropen rowstart rowend
1903 ali align aligns n)
1904 (setq caption (and caption (org-html-do-expand caption)))
1905 (when (and forced-aligns org-table-clean-did-remove-column)
1906 (setq forced-aligns
1907 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
1908 (if splice (setq head nil))
1909 (unless splice (push (if head "<thead>" "<tbody>") html))
1910 (setq tbopen t)
1911 (while (setq line (pop lines))
1912 (catch 'next-line
1913 (if (string-match "^[ \t]*|-" line)
1914 (progn
1915 (unless splice
1916 (push (if head "</thead>" "</tbody>") html)
1917 (if lines (push "<tbody>" html) (setq tbopen nil)))
1918 (setq head nil) ;; head ends here, first time around
1919 ;; ignore this line
1920 (throw 'next-line t)))
1921 ;; Break the line into fields
1922 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1923 (unless fnum (setq fnum (make-vector (length fields) 0)
1924 nfields (length fnum)))
1925 (setq nline (1+ nline) i -1
1926 rowstart (eval (car org-export-table-row-tags))
1927 rowend (eval (cdr org-export-table-row-tags)))
1928 (push (concat rowstart
1929 (mapconcat
1930 (lambda (x)
1931 (setq i (1+ i) ali (format "@@class%03d@@" i))
1932 (if (and (< i nfields) ; make sure no rogue line causes an error here
1933 (string-match org-table-number-regexp x))
1934 (incf (aref fnum i)))
1935 (cond
1936 (head
1937 (concat
1938 (format (car org-export-table-header-tags)
1939 "col" ali)
1941 (cdr org-export-table-header-tags)))
1942 ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
1943 (concat
1944 (format (car org-export-table-header-tags)
1945 "row" ali)
1947 (cdr org-export-table-header-tags)))
1949 (concat (format (car org-export-table-data-tags) ali)
1951 (cdr org-export-table-data-tags)))))
1952 fields "")
1953 rowend)
1954 html)))
1955 (unless splice (if tbopen (push "</tbody>" html)))
1956 (unless splice (push "</table>\n" html))
1957 (setq html (nreverse html))
1958 (unless splice
1959 ;; Put in col tags with the alignment (unfortunately often ignored...)
1960 (unless (car org-table-colgroup-info)
1961 (setq org-table-colgroup-info
1962 (cons :start (cdr org-table-colgroup-info))))
1963 (setq i 0)
1964 (push (mapconcat
1965 (lambda (x)
1966 (setq gr (pop org-table-colgroup-info)
1967 i (1+ i)
1968 align (if (assoc i forced-aligns)
1969 (cdr (assoc (cdr (assoc i forced-aligns))
1970 '(("l" . "left") ("r" . "right")
1971 ("c" . "center"))))
1972 (if (> (/ (float x) nline)
1973 org-table-number-fraction)
1974 "right" "left")))
1975 (push align aligns)
1976 (format (if no-css
1977 "%s<col align=\"%s\" />%s"
1978 "%s<col class=\"%s\" />%s")
1979 (if (memq gr '(:start :startend))
1980 (prog1
1981 (if colgropen
1982 "</colgroup>\n<colgroup>"
1983 "<colgroup>")
1984 (setq colgropen t))
1986 align
1987 (if (memq gr '(:end :startend))
1988 (progn (setq colgropen nil) "</colgroup>")
1989 "")))
1990 fnum "")
1991 html)
1992 (setq aligns (nreverse aligns))
1993 (if colgropen (setq html (cons (car html)
1994 (cons "</colgroup>" (cdr html)))))
1995 ;; Since the output of HTML table formatter can also be used in
1996 ;; DocBook document, we want to always include the caption to make
1997 ;; DocBook XML file valid.
1998 (push (format "<caption>%s</caption>" (or caption "")) html)
1999 (when label (push (format "<a name=\"%s\" id=\"%s\"></a>" (org-solidify-link-text label) (org-solidify-link-text label))
2000 html))
2001 (push html-table-tag html))
2002 (setq html (mapcar
2003 (lambda (x)
2004 (replace-regexp-in-string
2005 "@@class\\([0-9]+\\)@@"
2006 (lambda (txt)
2007 (if (not org-export-html-table-align-individual-fields)
2009 (setq n (string-to-number (match-string 1 txt)))
2010 (format (if no-css " align=\"%s\"" " class=\"%s\"")
2011 (or (nth n aligns) "left"))))
2013 html))
2014 (concat (mapconcat 'identity html "\n") "\n")))
2016 (defun org-export-splice-attributes (tag attributes)
2017 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2018 (if (not attributes)
2020 (let (oldatt newatt)
2021 (setq oldatt (org-extract-attributes-from-string tag)
2022 tag (pop oldatt)
2023 newatt (cdr (org-extract-attributes-from-string attributes)))
2024 (while newatt
2025 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
2026 (if (string-match ">" tag)
2027 (setq tag
2028 (replace-match (concat (org-attributes-to-string oldatt) ">")
2029 t t tag)))
2030 tag)))
2032 (defun org-format-table-table-html (lines)
2033 "Format a table generated by table.el into HTML.
2034 This conversion does *not* use `table-generate-source' from table.el.
2035 This has the advantage that Org-mode's HTML conversions can be used.
2036 But it has the disadvantage, that no cell- or row-spanning is allowed."
2037 (let (line field-buffer
2038 (head org-export-highlight-first-table-line)
2039 fields html empty i)
2040 (setq html (concat html-table-tag "\n"))
2041 (while (setq line (pop lines))
2042 (setq empty "&nbsp;")
2043 (catch 'next-line
2044 (if (string-match "^[ \t]*\\+-" line)
2045 (progn
2046 (if field-buffer
2047 (progn
2048 (setq
2049 html
2050 (concat
2051 html
2052 "<tr>"
2053 (mapconcat
2054 (lambda (x)
2055 (if (equal x "") (setq x empty))
2056 (if head
2057 (concat
2058 (format (car org-export-table-header-tags) "col" "")
2060 (cdr org-export-table-header-tags))
2061 (concat (format (car org-export-table-data-tags) "") x
2062 (cdr org-export-table-data-tags))))
2063 field-buffer "\n")
2064 "</tr>\n"))
2065 (setq head nil)
2066 (setq field-buffer nil)))
2067 ;; Ignore this line
2068 (throw 'next-line t)))
2069 ;; Break the line into fields and store the fields
2070 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2071 (if field-buffer
2072 (setq field-buffer (mapcar
2073 (lambda (x)
2074 (concat x "<br/>" (pop fields)))
2075 field-buffer))
2076 (setq field-buffer fields))))
2077 (setq html (concat html "</table>\n"))
2078 html))
2080 (defun org-format-table-table-html-using-table-generate-source (lines)
2081 "Format a table into html, using `table-generate-source' from table.el.
2082 This has the advantage that cell- or row-spanning is allowed.
2083 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
2084 (require 'table)
2085 (with-current-buffer (get-buffer-create " org-tmp1 ")
2086 (erase-buffer)
2087 (insert (mapconcat 'identity lines "\n"))
2088 (goto-char (point-min))
2089 (if (not (re-search-forward "|[^+]" nil t))
2090 (error "Error processing table"))
2091 (table-recognize-table)
2092 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2093 (table-generate-source 'html " org-tmp2 ")
2094 (set-buffer " org-tmp2 ")
2095 (buffer-substring (point-min) (point-max))))
2097 (defun org-export-splice-style (style extra)
2098 "Splice EXTRA into STYLE, just before \"</style>\"."
2099 (if (and (stringp extra)
2100 (string-match "\\S-" extra)
2101 (string-match "</style>" style))
2102 (concat (substring style 0 (match-beginning 0))
2103 "\n" extra "\n"
2104 (substring style (match-beginning 0)))
2105 style))
2107 (defun org-html-handle-time-stamps (s)
2108 "Format time stamps in string S, or remove them."
2109 (catch 'exit
2110 (let (r b)
2111 (while (string-match org-maybe-keyword-time-regexp s)
2112 (or b (setq b (substring s 0 (match-beginning 0))))
2113 (setq r (concat
2114 r (substring s 0 (match-beginning 0))
2115 " <span class=\"timestamp-wrapper\">"
2116 (if (match-end 1)
2117 (format "<span class=\"timestamp-kwd\">%s </span>"
2118 (match-string 1 s)))
2119 (format " <span class=\"timestamp\">%s</span>"
2120 (substring
2121 (org-translate-time (match-string 3 s)) 1 -1))
2122 "</span>")
2123 s (substring s (match-end 0))))
2124 ;; Line break if line started and ended with time stamp stuff
2125 (if (not r)
2127 (setq r (concat r s))
2128 (unless (string-match "\\S-" (concat b s))
2129 (setq r (concat r "<br/>")))
2130 r))))
2132 (defvar htmlize-buffer-places) ; from htmlize.el
2133 (defun org-export-htmlize-region-for-paste (beg end)
2134 "Convert the region to HTML, using htmlize.el.
2135 This is much like `htmlize-region-for-paste', only that it uses
2136 the settings define in the org-... variables."
2137 (let* ((htmlize-output-type org-export-htmlize-output-type)
2138 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
2139 (htmlbuf (htmlize-region beg end)))
2140 (unwind-protect
2141 (with-current-buffer htmlbuf
2142 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
2143 (plist-get htmlize-buffer-places 'content-end)))
2144 (kill-buffer htmlbuf))))
2146 ;;;###autoload
2147 (defun org-export-htmlize-generate-css ()
2148 "Create the CSS for all font definitions in the current Emacs session.
2149 Use this to create face definitions in your CSS style file that can then
2150 be used by code snippets transformed by htmlize.
2151 This command just produces a buffer that contains class definitions for all
2152 faces used in the current Emacs session. You can copy and paste the ones you
2153 need into your CSS file.
2155 If you then set `org-export-htmlize-output-type' to `css', calls to
2156 the function `org-export-htmlize-region-for-paste' will produce code
2157 that uses these same face definitions."
2158 (interactive)
2159 (require 'htmlize)
2160 (and (get-buffer "*html*") (kill-buffer "*html*"))
2161 (with-temp-buffer
2162 (let ((fl (face-list))
2163 (htmlize-css-name-prefix "org-")
2164 (htmlize-output-type 'css)
2165 f i)
2166 (while (setq f (pop fl)
2167 i (and f (face-attribute f :inherit)))
2168 (when (and (symbolp f) (or (not i) (not (listp i))))
2169 (insert (org-add-props (copy-sequence "1") nil 'face f))))
2170 (htmlize-region (point-min) (point-max))))
2171 (switch-to-buffer "*html*")
2172 (goto-char (point-min))
2173 (if (re-search-forward "<style" nil t)
2174 (delete-region (point-min) (match-beginning 0)))
2175 (if (re-search-forward "</style>" nil t)
2176 (delete-region (1+ (match-end 0)) (point-max)))
2177 (beginning-of-line 1)
2178 (if (looking-at " +") (replace-match ""))
2179 (goto-char (point-min)))
2181 (defun org-html-protect (s)
2182 "Convert characters to HTML equivalent.
2183 Possible conversions are set in `org-export-html-protect-char-alist'."
2184 (let ((start 0)
2185 (cl org-export-html-protect-char-alist) c)
2186 (while (setq c (pop cl))
2187 (while (string-match (car c) s start)
2188 (setq s (replace-match (cdr c) t t s)
2189 start (1+ (match-beginning 0)))))
2192 (defun org-html-expand (string)
2193 "Prepare STRING for HTML export. Apply all active conversions.
2194 If there are links in the string, don't modify these."
2195 (let* ((re (concat org-bracket-link-regexp "\\|"
2196 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2197 m s l res)
2198 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
2199 string
2200 (while (setq m (string-match re string))
2201 (setq s (substring string 0 m)
2202 l (match-string 0 string)
2203 string (substring string (match-end 0)))
2204 (push (org-html-do-expand s) res)
2205 (push l res))
2206 (push (org-html-do-expand string) res)
2207 (apply 'concat (nreverse res)))))
2209 (defun org-html-do-expand (s)
2210 "Apply all active conversions to translate special ASCII to HTML."
2211 (setq s (org-html-protect s))
2212 (if org-export-html-expand
2213 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
2214 (setq s (replace-match "<\\1>" t nil s))))
2215 (if org-export-with-emphasize
2216 (setq s (org-export-html-convert-emphasize s)))
2217 (if org-export-with-special-strings
2218 (setq s (org-export-html-convert-special-strings s)))
2219 (if org-export-with-sub-superscripts
2220 (setq s (org-export-html-convert-sub-super s)))
2221 (if org-export-with-TeX-macros
2222 (let ((start 0) wd rep)
2223 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2224 s start))
2225 (if (get-text-property (match-beginning 0) 'org-protected s)
2226 (setq start (match-end 0))
2227 (setq wd (match-string 1 s))
2228 (if (setq rep (org-entity-get-representation wd 'html))
2229 (setq s (replace-match rep t t s))
2230 (setq start (+ start (length wd))))))))
2233 (defun org-export-html-convert-special-strings (string)
2234 "Convert special characters in STRING to HTML."
2235 (let ((all org-export-html-special-string-regexps)
2236 e a re rpl start)
2237 (while (setq a (pop all))
2238 (setq re (car a) rpl (cdr a) start 0)
2239 (while (string-match re string start)
2240 (if (get-text-property (match-beginning 0) 'org-protected string)
2241 (setq start (match-end 0))
2242 (setq string (replace-match rpl t nil string)))))
2243 string))
2245 (defun org-export-html-convert-sub-super (string)
2246 "Convert sub- and superscripts in STRING to HTML."
2247 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
2248 (while (string-match org-match-substring-regexp string s)
2249 (cond
2250 ((and requireb (match-end 8)) (setq s (match-end 2)))
2251 ((get-text-property (match-beginning 2) 'org-protected string)
2252 (setq s (match-end 2)))
2254 (setq s (match-end 1)
2255 key (if (string= (match-string 2 string) "_") "sub" "sup")
2256 c (or (match-string 8 string)
2257 (match-string 6 string)
2258 (match-string 5 string))
2259 string (replace-match
2260 (concat (match-string 1 string)
2261 "<" key ">" c "</" key ">")
2262 t t string)))))
2263 (while (string-match "\\\\\\([_^]\\)" string)
2264 (setq string (replace-match (match-string 1 string) t t string)))
2265 string))
2267 (defun org-export-html-convert-emphasize (string)
2268 "Apply emphasis."
2269 (let ((s 0) rpl)
2270 (while (string-match org-emph-re string s)
2271 (if (not (equal
2272 (substring string (match-beginning 3) (1+ (match-beginning 3)))
2273 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
2274 (setq s (match-beginning 0)
2276 (concat
2277 (match-string 1 string)
2278 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
2279 (match-string 4 string)
2280 (nth 3 (assoc (match-string 3 string)
2281 org-emphasis-alist))
2282 (match-string 5 string))
2283 string (replace-match rpl t t string)
2284 s (+ s (- (length rpl) 2)))
2285 (setq s (1+ s))))
2286 string))
2288 (defun org-open-par ()
2289 "Insert <p>, but first close previous paragraph if any."
2290 (org-close-par-maybe)
2291 (insert "\n<p>")
2292 (setq org-par-open t))
2293 (defun org-close-par-maybe ()
2294 "Close paragraph if there is one open."
2295 (when org-par-open
2296 (insert "</p>")
2297 (setq org-par-open nil)))
2298 (defun org-close-li (&optional type)
2299 "Close <li> if necessary."
2300 (org-close-par-maybe)
2301 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
2303 (defvar body-only) ; dynamically scoped into this.
2304 (defun org-html-level-start (level title umax with-toc head-count)
2305 "Insert a new level in HTML export.
2306 When TITLE is nil, just close all open levels."
2307 (org-close-par-maybe)
2308 (let* ((target (and title (org-get-text-property-any 0 'target title)))
2309 (extra-targets (and target
2310 (assoc target org-export-target-aliases)))
2311 (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
2312 (preferred (and target
2313 (cdr (assoc target org-export-preferred-target-alist))))
2314 (l org-level-max)
2315 snumber snu href suffix)
2316 (setq extra-targets (remove (or preferred target) extra-targets))
2317 (setq extra-targets
2318 (mapconcat (lambda (x)
2319 (setq x (org-solidify-link-text
2320 (if (org-uuidgen-p x) (concat "ID-" x) x)))
2321 (format "<a name=\"%s\" id=\"%s\"></a>"
2322 x x))
2323 extra-targets
2324 ""))
2325 (while (>= l level)
2326 (if (aref org-levels-open (1- l))
2327 (progn
2328 (org-html-level-close l umax)
2329 (aset org-levels-open (1- l) nil)))
2330 (setq l (1- l)))
2331 (when title
2332 ;; If title is nil, this means this function is called to close
2333 ;; all levels, so the rest is done only if title is given
2334 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2335 (setq title (replace-match
2336 (if org-export-with-tags
2337 (save-match-data
2338 (concat
2339 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
2340 (mapconcat
2341 (lambda (x)
2342 (format "<span class=\"%s\">%s</span>"
2343 (org-export-html-get-tag-class-name x)
2345 (org-split-string (match-string 1 title) ":")
2346 "&nbsp;")
2347 "</span>"))
2349 t t title)))
2350 (if (> level umax)
2351 (progn
2352 (if (aref org-levels-open (1- level))
2353 (progn
2354 (org-close-li)
2355 (if target
2356 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2357 extra-targets title "<br/>\n")
2358 (insert "<li>" title "<br/>\n")))
2359 (aset org-levels-open (1- level) t)
2360 (org-close-par-maybe)
2361 (if target
2362 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2363 extra-targets title "<br/>\n")
2364 (insert "<ul>\n<li>" title "<br/>\n"))))
2365 (aset org-levels-open (1- level) t)
2366 (setq snumber (org-section-number level)
2367 snu (replace-regexp-in-string "\\." "_" snumber))
2368 (setq level (+ level org-export-html-toplevel-hlevel -1))
2369 (if (and org-export-with-section-numbers (not body-only))
2370 (setq title (concat
2371 (format "<span class=\"section-number-%d\">%s</span>"
2372 level snumber)
2373 " " title)))
2374 (unless (= head-count 1) (insert "\n</div>\n"))
2375 (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
2376 (setq suffix (org-solidify-link-text (or href snu)))
2377 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2378 (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"
2379 suffix level (if extra-class (concat " " extra-class) "")
2380 level href
2381 extra-targets
2382 title level level suffix))
2383 (org-open-par)))))
2385 (defun org-export-html-get-tag-class-name (tag)
2386 "Turn tag into a valid class name.
2387 Replaces invalid characters with \"_\" and then prepends a prefix."
2388 (save-match-data
2389 (while (string-match "[^a-zA-Z0-9_]" tag)
2390 (setq tag (replace-match "_" t t tag))))
2391 (concat org-export-html-tag-class-prefix tag))
2393 (defun org-export-html-get-todo-kwd-class-name (kwd)
2394 "Turn todo keyword into a valid class name.
2395 Replaces invalid characters with \"_\" and then prepends a prefix."
2396 (save-match-data
2397 (while (string-match "[^a-zA-Z0-9_]" kwd)
2398 (setq kwd (replace-match "_" t t kwd))))
2399 (concat org-export-html-todo-kwd-class-prefix kwd))
2401 (defun org-html-level-close (level max-outline-level)
2402 "Terminate one level in HTML export."
2403 (if (<= level max-outline-level)
2404 (insert "</div>\n")
2405 (org-close-li)
2406 (insert "</ul>\n")))
2408 (defun org-html-export-list-line (line pos struct prevs)
2409 "Insert list syntax in export buffer. Return LINE, maybe modified.
2411 POS is the item position or line position the line had before
2412 modifications to buffer. STRUCT is the list structure. PREVS is
2413 the alist of previous items."
2414 (let* ((get-type
2415 (function
2416 ;; Translate type of list containing POS to "d", "o" or
2417 ;; "u".
2418 (lambda (pos struct prevs)
2419 (let ((type (org-list-get-list-type pos struct prevs)))
2420 (cond
2421 ((eq 'ordered type) "o")
2422 ((eq 'descriptive type) "d")
2423 (t "u"))))))
2424 (get-closings
2425 (function
2426 ;; Return list of all items and sublists ending at POS, in
2427 ;; reverse order.
2428 (lambda (pos)
2429 (let (out)
2430 (catch 'exit
2431 (mapc (lambda (e)
2432 (let ((end (nth 6 e))
2433 (item (car e)))
2434 (cond
2435 ((= end pos) (push item out))
2436 ((>= item pos) (throw 'exit nil)))))
2437 struct))
2438 out)))))
2439 ;; First close any previous item, or list, ending at POS.
2440 (mapc (lambda (e)
2441 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2442 (first-item (org-list-get-list-begin e struct prevs))
2443 (type (funcall get-type first-item struct prevs)))
2444 (org-close-par-maybe)
2445 ;; Ending for every item
2446 (org-close-li type)
2447 ;; We're ending last item of the list: end list.
2448 (when lastp (insert (format "</%sl>\n" type)))))
2449 (funcall get-closings pos))
2450 (cond
2451 ;; At an item: insert appropriate tags in export buffer.
2452 ((assq pos struct)
2453 (string-match
2454 (concat "[ \t]*\\(\\S-+[ \t]+\\)"
2455 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2456 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2457 "\\(?:\\(.*\\)[ \t]+::[ \t]+\\)?"
2458 "\\(.*\\)") line)
2459 (let* ((checkbox (match-string 3 line))
2460 (desc-tag (or (match-string 4 line) "???"))
2461 (body (or (match-string 5 line) ""))
2462 (list-beg (org-list-get-list-begin pos struct prevs))
2463 (firstp (= list-beg pos))
2464 ;; Always refer to first item to determine list type, in
2465 ;; case list is ill-formed.
2466 (type (funcall get-type list-beg struct prevs))
2467 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2468 (cond
2469 ((not count-tmp) nil)
2470 ((string-match "[A-Za-z]" count-tmp)
2471 (- (string-to-char (upcase count-tmp)) 64))
2472 ((string-match "[0-9]+" count-tmp)
2473 count-tmp)))))
2474 (when firstp
2475 (org-close-par-maybe)
2476 (insert (format "<%sl>\n" type)))
2477 (insert (cond
2478 ((equal type "d")
2479 (format "<dt>%s</dt><dd>" desc-tag))
2480 ((and (equal type "o") counter)
2481 (format "<li value=\"%s\">" counter))
2482 (t "<li>")))
2483 ;; If line had a checkbox, some additional modification is required.
2484 (when checkbox
2485 (setq body
2486 (concat
2487 (cond
2488 ((string-match "X" checkbox) "<code>[X]</code> ")
2489 ((string-match " " checkbox) "<code>[&nbsp;]</code> ")
2490 (t "<code>[-]</code> "))
2491 body)))
2492 ;; Return modified line
2493 body))
2494 ;; At a list ender: go to next line (side-effects only).
2495 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2496 ;; Not at an item: return line unchanged (side-effects only).
2497 (t line))))
2499 (provide 'org-html)
2501 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
2502 ;;; org-html.el ends here