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