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