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