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