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