Insert a customizable separator between footnotes
[org-mode/org-jambu.git] / lisp / org-html.el
blob82d21ebdeb31b8c5543b71d645f6f085ad682529
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.5
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 :type '(repeat (cons (string :tag "Character")
569 (string :tag "HTML equivalent"))))
571 (defgroup org-export-htmlize nil
572 "Options for processing examples with htmlize.el."
573 :tag "Org Export Htmlize"
574 :group 'org-export-html)
576 (defcustom org-export-htmlize-output-type 'inline-css
577 "Output type to be used by htmlize when formatting code snippets.
578 Choices are `css', to export the CSS selectors only, or `inline-css', to
579 export the CSS attribute values inline in the HTML. We use as default
580 `inline-css', in order to make the resulting HTML self-containing.
582 However, this will fail when using Emacs in batch mode for export, because
583 then no rich font definitions are in place. It will also not be good if
584 people with different Emacs setup contribute HTML files to a website,
585 because the fonts will represent the individual setups. In these cases,
586 it is much better to let Org/Htmlize assign classes only, and to use
587 a style file to define the look of these classes.
588 To get a start for your css file, start Emacs session and make sure that
589 all the faces you are interested in are defined, for example by loading files
590 in all modes you want. Then, use the command
591 \\[org-export-htmlize-generate-css] to extract class definitions."
592 :group 'org-export-htmlize
593 :type '(choice (const css) (const inline-css)))
595 (defcustom org-export-htmlize-css-font-prefix "org-"
596 "The prefix for CSS class names for htmlize font specifications."
597 :group 'org-export-htmlize
598 :type 'string)
600 (defcustom org-export-htmlized-org-css-url nil
601 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
602 Normally when creating an htmlized version of an Org buffer, htmlize will
603 create CSS to define the font colors. However, this does not work when
604 converting in batch mode, and it also can look bad if different people
605 with different fontification setup work on the same website.
606 When this variable is non-nil, creating an htmlized version of an Org buffer
607 using `org-export-as-org' will remove the internal CSS section and replace it
608 with a link to this URL."
609 :group 'org-export-htmlize
610 :type '(choice
611 (const :tag "Keep internal css" nil)
612 (string :tag "URL or local href")))
614 (defcustom org-export-content-div "content"
615 "The name of the container DIV that holds all the page contents."
616 :group 'org-export-htmlize
617 :type 'string)
619 ;;; Hooks
621 (defvar org-export-html-after-blockquotes-hook nil
622 "Hook run during HTML export, after blockquote, verse, center are done.")
624 (defvar org-export-html-final-hook nil
625 "Hook run at the end of HTML export, in the new buffer.")
627 ;;; HTML export
629 (defun org-export-html-preprocess (parameters)
630 "Convert LaTeX fragments to images."
631 (when (and org-current-export-file
632 (plist-get parameters :LaTeX-fragments))
633 (org-format-latex
634 (concat "ltxpng/" (file-name-sans-extension
635 (file-name-nondirectory
636 org-current-export-file)))
637 org-current-export-dir nil "Creating LaTeX image %s"
638 nil nil
639 (cond
640 ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
641 ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
642 ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
643 ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
644 (t nil))))
645 (goto-char (point-min))
646 (let (label l1)
647 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
648 (org-if-unprotected-at (match-beginning 1)
649 (setq label (match-string 1))
650 (save-match-data
651 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
652 (setq l1 (substring label (match-beginning 1)))
653 (setq l1 label)))
654 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
656 ;;;###autoload
657 (defun org-export-as-html-and-open (arg)
658 "Export the outline as HTML and immediately open it with a browser.
659 If there is an active region, export only the region.
660 The prefix ARG specifies how many levels of the outline should become
661 headlines. The default is 3. Lower levels will become bulleted lists."
662 (interactive "P")
663 (org-export-as-html arg 'hidden)
664 (org-open-file buffer-file-name)
665 (when org-export-kill-product-buffer-when-displayed
666 (kill-buffer (current-buffer))))
668 ;;;###autoload
669 (defun org-export-as-html-batch ()
670 "Call the function `org-export-as-html'.
671 This function can be used in batch processing as:
672 emacs --batch
673 --load=$HOME/lib/emacs/org.el
674 --eval \"(setq org-export-headline-levels 2)\"
675 --visit=MyFile --funcall org-export-as-html-batch"
676 (org-export-as-html org-export-headline-levels 'hidden))
678 ;;;###autoload
679 (defun org-export-as-html-to-buffer (arg)
680 "Call `org-export-as-html` with output to a temporary buffer.
681 No file is created. The prefix ARG is passed through to `org-export-as-html'."
682 (interactive "P")
683 (org-export-as-html arg nil nil "*Org HTML Export*")
684 (when org-export-show-temporary-export-buffer
685 (switch-to-buffer-other-window "*Org HTML Export*")))
687 ;;;###autoload
688 (defun org-replace-region-by-html (beg end)
689 "Assume the current region has org-mode syntax, and convert it to HTML.
690 This can be used in any buffer. For example, you could write an
691 itemized list in org-mode syntax in an HTML buffer and then use this
692 command to convert it."
693 (interactive "r")
694 (let (reg html buf pop-up-frames)
695 (save-window-excursion
696 (if (org-mode-p)
697 (setq html (org-export-region-as-html
698 beg end t 'string))
699 (setq reg (buffer-substring beg end)
700 buf (get-buffer-create "*Org tmp*"))
701 (with-current-buffer buf
702 (erase-buffer)
703 (insert reg)
704 (org-mode)
705 (setq html (org-export-region-as-html
706 (point-min) (point-max) t 'string)))
707 (kill-buffer buf)))
708 (delete-region beg end)
709 (insert html)))
711 ;;;###autoload
712 (defun org-export-region-as-html (beg end &optional body-only buffer)
713 "Convert region from BEG to END in org-mode buffer to HTML.
714 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
715 contents, and only produce the region of converted text, useful for
716 cut-and-paste operations.
717 If BUFFER is a buffer or a string, use/create that buffer as a target
718 of the converted HTML. If BUFFER is the symbol `string', return the
719 produced HTML as a string and leave not buffer behind. For example,
720 a Lisp program could call this function in the following way:
722 (setq html (org-export-region-as-html beg end t 'string))
724 When called interactively, the output buffer is selected, and shown
725 in a window. A non-interactive call will only return the buffer."
726 (interactive "r\nP")
727 (when (interactive-p)
728 (setq buffer "*Org HTML Export*"))
729 (let ((transient-mark-mode t) (zmacs-regions t)
730 ext-plist rtn)
731 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
732 (goto-char end)
733 (set-mark (point)) ;; to activate the region
734 (goto-char beg)
735 (setq rtn (org-export-as-html
736 nil nil ext-plist
737 buffer body-only))
738 (if (fboundp 'deactivate-mark) (deactivate-mark))
739 (if (and (interactive-p) (bufferp rtn))
740 (switch-to-buffer-other-window rtn)
741 rtn)))
743 (defvar html-table-tag nil) ; dynamically scoped into this.
744 (defvar org-par-open nil)
746 ;;; org-html-cvt-link-fn
747 (defconst org-html-cvt-link-fn
749 "Function to convert link URLs to exportable URLs.
750 Takes two arguments, TYPE and PATH.
751 Returns exportable url as (TYPE PATH), or nil to signal that it
752 didn't handle this case.
753 Intended to be locally bound around a call to `org-export-as-html'." )
755 (defun org-html-cvt-org-as-html (opt-plist type path)
756 "Convert an org filename to an equivalent html filename.
757 If TYPE is not file, just return `nil'.
758 See variable `org-export-html-link-org-files-as-html'"
760 (save-match-data
761 (and
762 org-export-html-link-org-files-as-html
763 (string= type "file")
764 (string-match "\\.org$" path)
765 (progn
766 (list
767 "file"
768 (concat
769 (substring path 0 (match-beginning 0))
771 (plist-get opt-plist :html-extension)))))))
774 ;;; org-html-should-inline-p
775 (defun org-html-should-inline-p (filename descp)
776 "Return non-nil if link FILENAME should be inlined.
777 The decision to inline the FILENAME link is based on the current
778 settings. DESCP is the boolean of whether there was a link
779 description. See variables `org-export-html-inline-images' and
780 `org-export-html-inline-image-extensions'."
781 (declare (special
782 org-export-html-inline-images
783 org-export-html-inline-image-extensions))
784 (and (or (eq t org-export-html-inline-images)
785 (and org-export-html-inline-images (not descp)))
786 (org-file-image-p
787 filename org-export-html-inline-image-extensions)))
789 ;;; org-html-make-link
790 (defun org-html-make-link (opt-plist type path fragment desc attr
791 may-inline-p)
792 "Make an HTML link.
793 OPT-PLIST is an options list.
794 TYPE is the device-type of the link (THIS://foo.html)
795 PATH is the path of the link (http://THIS#locationx)
796 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
797 DESC is the link description, if any.
798 ATTR is a string of other attributes of the a element.
799 MAY-INLINE-P allows inlining it as an image."
801 (declare (special org-par-open))
802 (save-match-data
803 (let* ((filename path)
804 ;;First pass. Just sanity stuff.
805 (components-1
806 (cond
807 ((string= type "file")
808 (list
809 type
810 ;;Substitute just if original path was absolute.
811 ;;(Otherwise path must remain relative)
812 (if (file-name-absolute-p path)
813 (concat "file://" (expand-file-name path))
814 path)))
815 ((string= type "")
816 (list nil path))
817 (t (list type path))))
819 ;;Second pass. Components converted so they can refer
820 ;;to a remote site.
821 (components-2
823 (and org-html-cvt-link-fn
824 (apply org-html-cvt-link-fn
825 opt-plist components-1))
826 (apply #'org-html-cvt-org-as-html
827 opt-plist components-1)
828 components-1))
829 (type (first components-2))
830 (thefile (second components-2)))
833 ;;Third pass. Build final link except for leading type
834 ;;spec.
835 (cond
836 ((or
837 (not type)
838 (string= type "http")
839 (string= type "https")
840 (string= type "file")
841 (string= type "coderef"))
842 (if fragment
843 (setq thefile (concat thefile "#" fragment))))
845 (t))
847 ;;Final URL-build, for all types.
848 (setq thefile
849 (let
850 ((str (org-export-html-format-href thefile)))
851 (if (and type (not (or (string= "file" type)
852 (string= "coderef" type))))
853 (concat type ":" str)
854 str)))
856 (if (and
857 may-inline-p
858 ;;Can't inline a URL with a fragment.
859 (not fragment))
860 (progn
861 (message "image %s %s" thefile org-par-open)
862 (org-export-html-format-image thefile org-par-open))
863 (concat
864 "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
865 (org-export-html-format-desc desc)
866 "</a>")))))
868 (defun org-html-handle-links (line opt-plist)
869 "Return LINE with markup of Org mode links.
870 OPT-PLIST is the export options list."
871 (let ((start 0)
872 (current-dir (if buffer-file-name
873 (file-name-directory buffer-file-name)
874 default-directory))
875 (link-validate (plist-get opt-plist :link-validation-function))
876 type id-file fnc
877 rpl path attr desc descp desc1 desc2 link)
878 (while (string-match org-bracket-link-analytic-regexp++ line start)
879 (setq start (match-beginning 0))
880 (setq path (save-match-data (org-link-unescape
881 (match-string 3 line))))
882 (setq type (cond
883 ((match-end 2) (match-string 2 line))
884 ((save-match-data
885 (or (file-name-absolute-p path)
886 (string-match "^\\.\\.?/" path)))
887 "file")
888 (t "internal")))
889 (setq path (org-extract-attributes (org-link-unescape path)))
890 (setq attr (get-text-property 0 'org-attributes path))
891 (setq desc1 (if (match-end 5) (match-string 5 line))
892 desc2 (if (match-end 2) (concat type ":" path) path)
893 descp (and desc1 (not (equal desc1 desc2)))
894 desc (or desc1 desc2))
895 ;; Make an image out of the description if that is so wanted
896 (when (and descp (org-file-image-p
897 desc org-export-html-inline-image-extensions))
898 (save-match-data
899 (if (string-match "^file:" desc)
900 (setq desc (substring desc (match-end 0)))))
901 (setq desc (org-add-props
902 (concat "<img src=\"" desc "\" alt=\""
903 (file-name-nondirectory desc) "\"/>")
904 '(org-protected t))))
905 (cond
906 ((equal type "internal")
907 (let
908 ((frag-0
909 (if (= (string-to-char path) ?#)
910 (substring path 1)
911 path)))
912 (setq rpl
913 (org-html-make-link
914 opt-plist
917 (org-solidify-link-text
918 (save-match-data (org-link-unescape frag-0))
919 nil)
920 desc attr nil))))
921 ((and (equal type "id")
922 (setq id-file (org-id-find-id-file path)))
923 ;; This is an id: link to another file (if it was the same file,
924 ;; it would have become an internal link...)
925 (save-match-data
926 (setq id-file (file-relative-name
927 id-file
928 (file-name-directory org-current-export-file)))
929 (setq rpl
930 (org-html-make-link opt-plist
931 "file" id-file
932 (concat (if (org-uuidgen-p path) "ID-") path)
933 desc
934 attr
935 nil))))
936 ((member type '("http" "https"))
937 ;; standard URL, can inline as image
938 (setq rpl
939 (org-html-make-link opt-plist
940 type path nil
941 desc
942 attr
943 (org-html-should-inline-p path descp))))
944 ((member type '("ftp" "mailto" "news"))
945 ;; standard URL, can't inline as image
946 (setq rpl
947 (org-html-make-link opt-plist
948 type path nil
949 desc
950 attr
951 nil)))
953 ((string= type "coderef")
954 (let*
955 ((coderef-str (format "coderef-%s" path))
956 (attr-1
957 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
958 coderef-str coderef-str)))
959 (setq rpl
960 (org-html-make-link opt-plist
961 type "" coderef-str
962 (format
963 (org-export-get-coderef-format
964 path
965 (and descp desc))
966 (cdr (assoc path org-export-code-refs)))
967 attr-1
968 nil))))
970 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
971 ;; The link protocol has a function for format the link
972 (setq rpl
973 (save-match-data
974 (funcall fnc (org-link-unescape path) desc1 'html))))
976 ((string= type "file")
977 ;; FILE link
978 (save-match-data
979 (let*
980 ((components
982 (string-match "::\\(.*\\)" path)
983 (list
984 (replace-match "" t nil path)
985 (match-string 1 path))
986 (list path nil)))
988 ;;The proper path, without a fragment
989 (path-1
990 (first components))
992 ;;The raw fragment
993 (fragment-0
994 (second components))
996 ;;Check the fragment. If it can't be used as
997 ;;target fragment we'll pass nil instead.
998 (fragment-1
1000 (and fragment-0
1001 (not (string-match "^[0-9]*$" fragment-0))
1002 (not (string-match "^\\*" fragment-0))
1003 (not (string-match "^/.*/$" fragment-0)))
1004 (org-solidify-link-text
1005 (org-link-unescape fragment-0))
1006 nil))
1007 (desc-2
1008 ;;Description minus "file:" and ".org"
1009 (if (string-match "^file:" desc)
1010 (let
1011 ((desc-1 (replace-match "" t t desc)))
1012 (if (string-match "\\.org$" desc-1)
1013 (replace-match "" t t desc-1)
1014 desc-1))
1015 desc)))
1017 (setq rpl
1019 (and
1020 (functionp link-validate)
1021 (not (funcall link-validate path-1 current-dir)))
1022 desc
1023 (org-html-make-link opt-plist
1024 "file" path-1 fragment-1 desc-2 attr
1025 (org-html-should-inline-p path-1 descp)))))))
1028 ;; just publish the path, as default
1029 (setq rpl (concat "@<i>&lt;" type ":"
1030 (save-match-data (org-link-unescape path))
1031 "&gt;@</i>"))))
1032 (setq line (replace-match rpl t t line)
1033 start (+ start (length rpl))))
1034 line))
1036 ;;; org-export-as-html
1037 ;;;###autoload
1038 (defun org-export-as-html (arg &optional hidden ext-plist
1039 to-buffer body-only pub-dir)
1040 "Export the outline as a pretty HTML file.
1041 If there is an active region, export only the region. The prefix
1042 ARG specifies how many levels of the outline should become
1043 headlines. The default is 3. Lower levels will become bulleted
1044 lists. HIDDEN is obsolete and does nothing.
1045 EXT-PLIST is a property list with external parameters overriding
1046 org-mode's default settings, but still inferior to file-local
1047 settings. When TO-BUFFER is non-nil, create a buffer with that
1048 name and export to that buffer. If TO-BUFFER is the symbol
1049 `string', don't leave any buffer behind but just return the
1050 resulting HTML as a string. When BODY-ONLY is set, don't produce
1051 the file header and footer, simply return the content of
1052 <body>...</body>, without even the body tags themselves. When
1053 PUB-DIR is set, use this as the publishing directory."
1054 (interactive "P")
1055 (run-hooks 'org-export-first-hook)
1057 ;; Make sure we have a file name when we need it.
1058 (when (and (not (or to-buffer body-only))
1059 (not buffer-file-name))
1060 (if (buffer-base-buffer)
1061 (org-set-local 'buffer-file-name
1062 (with-current-buffer (buffer-base-buffer)
1063 buffer-file-name))
1064 (error "Need a file name to be able to export")))
1066 (message "Exporting...")
1067 (setq-default org-todo-line-regexp org-todo-line-regexp)
1068 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
1069 (setq-default org-done-keywords org-done-keywords)
1070 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
1071 (let* ((opt-plist
1072 (org-export-process-option-filters
1073 (org-combine-plists (org-default-export-plist)
1074 ext-plist
1075 (org-infile-export-plist))))
1076 (body-only (or body-only (plist-get opt-plist :body-only)))
1077 (style (concat (if (plist-get opt-plist :style-include-default)
1078 org-export-html-style-default)
1079 (plist-get opt-plist :style)
1080 (plist-get opt-plist :style-extra)
1081 "\n"
1082 (if (plist-get opt-plist :style-include-scripts)
1083 org-export-html-scripts)))
1084 (html-extension (plist-get opt-plist :html-extension))
1085 valid thetoc have-headings first-heading-pos
1086 (odd org-odd-levels-only)
1087 (region-p (org-region-active-p))
1088 (rbeg (and region-p (region-beginning)))
1089 (rend (and region-p (region-end)))
1090 (subtree-p
1091 (if (plist-get opt-plist :ignore-subtree-p)
1093 (when region-p
1094 (save-excursion
1095 (goto-char rbeg)
1096 (and (org-at-heading-p)
1097 (>= (org-end-of-subtree t t) rend))))))
1098 (level-offset (if subtree-p
1099 (save-excursion
1100 (goto-char rbeg)
1101 (+ (funcall outline-level)
1102 (if org-odd-levels-only 1 0)))
1104 (opt-plist (setq org-export-opt-plist
1105 (if subtree-p
1106 (org-export-add-subtree-options opt-plist rbeg)
1107 opt-plist)))
1108 ;; The following two are dynamically scoped into other
1109 ;; routines below.
1110 (org-current-export-dir
1111 (or pub-dir (org-export-directory :html opt-plist)))
1112 (org-current-export-file buffer-file-name)
1113 (level 0) (line "") (origline "") txt todo
1114 (umax nil)
1115 (umax-toc nil)
1116 (filename (if to-buffer nil
1117 (expand-file-name
1118 (concat
1119 (file-name-sans-extension
1120 (or (and subtree-p
1121 (org-entry-get (region-beginning)
1122 "EXPORT_FILE_NAME" t))
1123 (file-name-nondirectory buffer-file-name)))
1124 "." html-extension)
1125 (file-name-as-directory
1126 (or pub-dir (org-export-directory :html opt-plist))))))
1127 (current-dir (if buffer-file-name
1128 (file-name-directory buffer-file-name)
1129 default-directory))
1130 (buffer (if to-buffer
1131 (cond
1132 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
1133 (t (get-buffer-create to-buffer)))
1134 (find-file-noselect filename)))
1135 (org-levels-open (make-vector org-level-max nil))
1136 (date (plist-get opt-plist :date))
1137 (author (plist-get opt-plist :author))
1138 (html-validation-link (or org-export-html-validation-link ""))
1139 (title (org-html-expand
1140 (or (and subtree-p (org-export-get-title-from-subtree))
1141 (plist-get opt-plist :title)
1142 (and (not body-only)
1143 (not
1144 (plist-get opt-plist :skip-before-1st-heading))
1145 (org-export-grab-title-from-buffer))
1146 (and buffer-file-name
1147 (file-name-sans-extension
1148 (file-name-nondirectory buffer-file-name)))
1149 "UNTITLED")))
1150 (link-up (and (plist-get opt-plist :link-up)
1151 (string-match "\\S-" (plist-get opt-plist :link-up))
1152 (plist-get opt-plist :link-up)))
1153 (link-home (and (plist-get opt-plist :link-home)
1154 (string-match "\\S-" (plist-get opt-plist :link-home))
1155 (plist-get opt-plist :link-home)))
1156 (dummy (setq opt-plist (plist-put opt-plist :title title)))
1157 (html-table-tag (plist-get opt-plist :html-table-tag))
1158 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1159 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
1160 (inquote nil)
1161 (infixed nil)
1162 (inverse nil)
1163 (email (plist-get opt-plist :email))
1164 (language (plist-get opt-plist :language))
1165 (keywords (plist-get opt-plist :keywords))
1166 (description (plist-get opt-plist :description))
1167 (num (plist-get opt-plist :section-numbers))
1168 (lang-words nil)
1169 (head-count 0) cnt
1170 (start 0)
1171 (coding-system (and (boundp 'buffer-file-coding-system)
1172 buffer-file-coding-system))
1173 (coding-system-for-write (or org-export-html-coding-system
1174 coding-system))
1175 (save-buffer-coding-system (or org-export-html-coding-system
1176 coding-system))
1177 (charset (and coding-system-for-write
1178 (fboundp 'coding-system-get)
1179 (coding-system-get coding-system-for-write
1180 'mime-charset)))
1181 (region
1182 (buffer-substring
1183 (if region-p (region-beginning) (point-min))
1184 (if region-p (region-end) (point-max))))
1185 (org-export-have-math nil)
1186 (org-export-footnotes-markers nil)
1187 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
1188 (lines
1189 (org-split-string
1190 (org-export-preprocess-string
1191 region
1192 :emph-multiline t
1193 :for-backend 'html
1194 :skip-before-1st-heading
1195 (plist-get opt-plist :skip-before-1st-heading)
1196 :drawers (plist-get opt-plist :drawers)
1197 :todo-keywords (plist-get opt-plist :todo-keywords)
1198 :tasks (plist-get opt-plist :tasks)
1199 :tags (plist-get opt-plist :tags)
1200 :priority (plist-get opt-plist :priority)
1201 :footnotes (plist-get opt-plist :footnotes)
1202 :timestamps (plist-get opt-plist :timestamps)
1203 :archived-trees
1204 (plist-get opt-plist :archived-trees)
1205 :select-tags (plist-get opt-plist :select-tags)
1206 :exclude-tags (plist-get opt-plist :exclude-tags)
1207 :add-text
1208 (plist-get opt-plist :text)
1209 :LaTeX-fragments
1210 (plist-get opt-plist :LaTeX-fragments))
1211 "[\r\n]"))
1212 (mathjax
1213 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
1214 (and org-export-have-math
1215 (eq (plist-get opt-plist :LaTeX-fragments) t)))
1217 (org-export-html-mathjax-config
1218 org-export-html-mathjax-template
1219 org-export-html-mathjax-options
1220 (or (plist-get opt-plist :mathjax) ""))
1221 ""))
1222 table-open
1223 table-buffer table-orig-buffer
1225 rpl path attr desc descp desc1 desc2 link
1226 snumber fnc
1227 footnotes footref-seen
1228 href
1231 (let ((inhibit-read-only t))
1232 (org-unmodified
1233 (remove-text-properties (point-min) (point-max)
1234 '(:org-license-to-kill t))))
1236 (message "Exporting...")
1238 (setq org-min-level (org-get-min-level lines level-offset))
1239 (setq org-last-level org-min-level)
1240 (org-init-section-numbers)
1242 (cond
1243 ((and date (string-match "%" date))
1244 (setq date (format-time-string date)))
1245 (date)
1246 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
1248 ;; Get the language-dependent settings
1249 (setq lang-words (or (assoc language org-export-language-setup)
1250 (assoc "en" org-export-language-setup)))
1252 ;; Switch to the output buffer
1253 (set-buffer buffer)
1254 (let ((inhibit-read-only t)) (erase-buffer))
1255 (fundamental-mode)
1256 (org-install-letbind)
1258 (and (fboundp 'set-buffer-file-coding-system)
1259 (set-buffer-file-coding-system coding-system-for-write))
1261 (let ((case-fold-search nil)
1262 (org-odd-levels-only odd))
1263 ;; create local variables for all options, to make sure all called
1264 ;; functions get the correct information
1265 (mapc (lambda (x)
1266 (set (make-local-variable (nth 2 x))
1267 (plist-get opt-plist (car x))))
1268 org-export-plist-vars)
1269 (setq umax (if arg (prefix-numeric-value arg)
1270 org-export-headline-levels))
1271 (setq umax-toc (if (integerp org-export-with-toc)
1272 (min org-export-with-toc umax)
1273 umax))
1274 (unless body-only
1275 ;; File header
1276 (insert (format
1278 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1279 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1280 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1281 lang=\"%s\" xml:lang=\"%s\">
1282 <head>
1283 <title>%s</title>
1284 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1285 <meta name=\"generator\" content=\"Org-mode\"/>
1286 <meta name=\"generated\" content=\"%s\"/>
1287 <meta name=\"author\" content=\"%s\"/>
1288 <meta name=\"description\" content=\"%s\"/>
1289 <meta name=\"keywords\" content=\"%s\"/>
1292 </head>
1293 <body>
1294 <div id=\"%s\">
1297 (format
1298 (or (and (stringp org-export-html-xml-declaration)
1299 org-export-html-xml-declaration)
1300 (cdr (assoc html-extension org-export-html-xml-declaration))
1301 (cdr (assoc "html" org-export-html-xml-declaration))
1304 (or charset "iso-8859-1"))
1305 language language
1306 title
1307 (or charset "iso-8859-1")
1308 date author description keywords
1309 style
1310 mathjax
1311 org-export-content-div
1312 (if (or link-up link-home)
1313 (concat
1314 (format org-export-html-home/up-format
1315 (or link-up link-home)
1316 (or link-home link-up))
1317 "\n")
1318 "")))
1320 ;; insert html preamble
1321 (when (plist-get opt-plist :html-preamble)
1322 (let ((html-pre (plist-get opt-plist :html-preamble)))
1323 (cond ((stringp html-pre)
1324 (insert
1325 (format-spec html-pre `((?t . ,title) (?a . ,author)
1326 (?d . ,date) (?e . ,email)))))
1327 ((functionp html-pre)
1328 (funcall html-pre opt-plist))
1330 (insert
1331 (format-spec
1332 (or (cadr (assoc (nth 0 lang-words)
1333 org-export-html-preamble-format))
1334 (cadr (assoc "en" org-export-html-preamble-format)))
1335 `((?t . ,title) (?a . ,author)
1336 (?d . ,date) (?e . ,email)))))))))
1338 (if (and org-export-with-toc (not body-only))
1339 (progn
1340 (push (format "<h%d>%s</h%d>\n"
1341 org-export-html-toplevel-hlevel
1342 (nth 3 lang-words)
1343 org-export-html-toplevel-hlevel)
1344 thetoc)
1345 (push "<div id=\"text-table-of-contents\">\n" thetoc)
1346 (push "<ul>\n<li>" thetoc)
1347 (setq lines
1348 (mapcar #'(lambda (line)
1349 (if (and (string-match org-todo-line-regexp line)
1350 (not (get-text-property 0 'org-protected line)))
1351 ;; This is a headline
1352 (progn
1353 (setq have-headings t)
1354 (setq level (- (match-end 1) (match-beginning 1)
1355 level-offset)
1356 level (org-tr-level level)
1357 txt (save-match-data
1358 (org-html-expand
1359 (org-export-cleanup-toc-line
1360 (match-string 3 line))))
1361 todo
1362 (or (and org-export-mark-todo-in-toc
1363 (match-beginning 2)
1364 (not (member (match-string 2 line)
1365 org-done-keywords)))
1366 ; TODO, not DONE
1367 (and org-export-mark-todo-in-toc
1368 (= level umax-toc)
1369 (org-search-todo-below
1370 line lines level))))
1371 (if (string-match
1372 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
1373 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
1374 (if (string-match quote-re0 txt)
1375 (setq txt (replace-match "" t t txt)))
1376 (setq snumber (org-section-number level))
1377 (if (and num (if (integerp num)
1378 (>= num level)
1379 num))
1380 (setq txt (concat snumber " " txt)))
1381 (if (<= level (max umax umax-toc))
1382 (setq head-count (+ head-count 1)))
1383 (if (<= level umax-toc)
1384 (progn
1385 (if (> level org-last-level)
1386 (progn
1387 (setq cnt (- level org-last-level))
1388 (while (>= (setq cnt (1- cnt)) 0)
1389 (push "\n<ul>\n<li>" thetoc))
1390 (push "\n" thetoc)))
1391 (if (< level org-last-level)
1392 (progn
1393 (setq cnt (- org-last-level level))
1394 (while (>= (setq cnt (1- cnt)) 0)
1395 (push "</li>\n</ul>" thetoc))
1396 (push "\n" thetoc)))
1397 ;; Check for targets
1398 (while (string-match org-any-target-regexp line)
1399 (setq line (replace-match
1400 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
1401 t t line)))
1402 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
1403 (setq txt (replace-match "" t t txt)))
1404 (setq href
1405 (replace-regexp-in-string
1406 "\\." "-" (format "sec-%s" snumber)))
1407 (setq href (org-solidify-link-text (or (cdr (assoc href org-export-preferred-target-alist)) href)))
1408 (push
1409 (format
1410 (if todo
1411 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1412 "</li>\n<li><a href=\"#%s\">%s</a>")
1413 href txt) thetoc)
1415 (setq org-last-level level))
1417 line)
1418 lines))
1419 (while (> org-last-level (1- org-min-level))
1420 (setq org-last-level (1- org-last-level))
1421 (push "</li>\n</ul>\n" thetoc))
1422 (push "</div>\n" thetoc)
1423 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1425 (setq head-count 0)
1426 (org-init-section-numbers)
1428 (org-open-par)
1430 (while (setq line (pop lines) origline line)
1431 (catch 'nextline
1433 ;; end of quote section?
1434 (when (and inquote (string-match "^\\*+ " line))
1435 (insert "</pre>\n")
1436 (org-open-par)
1437 (setq inquote nil))
1438 ;; inside a quote section?
1439 (when inquote
1440 (insert (org-html-protect line) "\n")
1441 (throw 'nextline nil))
1443 ;; Fixed-width, verbatim lines (examples)
1444 (when (and org-export-with-fixed-width
1445 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
1446 (when (not infixed)
1447 (setq infixed t)
1448 (org-close-par-maybe)
1450 (insert "<pre class=\"example\">\n"))
1451 (insert (org-html-protect (match-string 3 line)) "\n")
1452 (when (or (not lines)
1453 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1454 (car lines))))
1455 (setq infixed nil)
1456 (insert "</pre>\n")
1457 (org-open-par))
1458 (throw 'nextline nil))
1460 ;; Protected HTML
1461 (when (and (get-text-property 0 'org-protected line)
1462 ;; Make sure it is the entire line that is protected
1463 (not (< (or (next-single-property-change
1464 0 'org-protected line) 10000)
1465 (length line))))
1466 (let (par (ind (get-text-property 0 'original-indentation line)))
1467 (when (re-search-backward
1468 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
1469 (setq par (match-string 1))
1470 (replace-match "\\2\n"))
1471 (insert line "\n")
1472 (while (and lines
1473 (or (= (length (car lines)) 0)
1474 (not ind)
1475 (equal ind (get-text-property 0 'original-indentation (car lines))))
1476 (or (= (length (car lines)) 0)
1477 (get-text-property 0 'org-protected (car lines))))
1478 (insert (pop lines) "\n"))
1479 (and par (insert "<p>\n")))
1480 (throw 'nextline nil))
1482 ;; Blockquotes, verse, and center
1483 (when (equal "ORG-BLOCKQUOTE-START" line)
1484 (org-close-par-maybe)
1485 (insert "<blockquote>\n")
1486 (org-open-par)
1487 (throw 'nextline nil))
1488 (when (equal "ORG-BLOCKQUOTE-END" line)
1489 (org-close-par-maybe)
1490 (insert "\n</blockquote>\n")
1491 (org-open-par)
1492 (throw 'nextline nil))
1493 (when (equal "ORG-VERSE-START" line)
1494 (org-close-par-maybe)
1495 (insert "\n<p class=\"verse\">\n")
1496 (setq org-par-open t)
1497 (setq inverse t)
1498 (throw 'nextline nil))
1499 (when (equal "ORG-VERSE-END" line)
1500 (insert "</p>\n")
1501 (setq org-par-open nil)
1502 (org-open-par)
1503 (setq inverse nil)
1504 (throw 'nextline nil))
1505 (when (equal "ORG-CENTER-START" line)
1506 (org-close-par-maybe)
1507 (insert "\n<div style=\"text-align: center\">")
1508 (org-open-par)
1509 (throw 'nextline nil))
1510 (when (equal "ORG-CENTER-END" line)
1511 (org-close-par-maybe)
1512 (insert "\n</div>")
1513 (org-open-par)
1514 (throw 'nextline nil))
1515 (run-hooks 'org-export-html-after-blockquotes-hook)
1516 (when inverse
1517 (let ((i (org-get-string-indentation line)))
1518 (if (> i 0)
1519 (setq line (concat (mapconcat 'identity
1520 (make-list (* 2 i) "\\nbsp") "")
1521 " " (org-trim line))))
1522 (unless (string-match "\\\\\\\\[ \t]*$" line)
1523 (setq line (concat line "\\\\")))))
1525 ;; make targets to anchors
1526 (setq start 0)
1527 (while (string-match
1528 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1529 (cond
1530 ((get-text-property (match-beginning 1) 'org-protected line)
1531 (setq start (match-end 1)))
1532 ((match-end 2)
1533 (setq line (replace-match
1534 (format
1535 "@<a name=\"%s\" id=\"%s\">@</a>"
1536 (org-solidify-link-text (match-string 1 line))
1537 (org-solidify-link-text (match-string 1 line)))
1538 t t line)))
1539 ((and org-export-with-toc (equal (string-to-char line) ?*))
1540 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1541 (setq line (replace-match
1542 (concat "@<span class=\"target\">"
1543 (match-string 1 line) "@</span> ")
1544 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1545 t t line)))
1547 (setq line (replace-match
1548 (concat "@<a name=\""
1549 (org-solidify-link-text (match-string 1 line))
1550 "\" class=\"target\">" (match-string 1 line)
1551 "@</a> ")
1552 t t line)))))
1554 (setq line (org-html-handle-time-stamps line))
1556 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1557 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
1558 ;; Also handle sub_superscripts and checkboxes
1559 (or (string-match org-table-hline-regexp line)
1560 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line)
1561 (setq line (org-html-expand line)))
1563 ;; Format the links
1564 (setq line (org-html-handle-links line opt-plist))
1566 ;; TODO items
1567 (if (and (string-match org-todo-line-regexp line)
1568 (match-beginning 2))
1570 (setq line
1571 (concat (substring line 0 (match-beginning 2))
1572 "<span class=\""
1573 (if (member (match-string 2 line)
1574 org-done-keywords)
1575 "done" "todo")
1576 " " (match-string 2 line)
1577 "\"> " (org-export-html-get-todo-kwd-class-name
1578 (match-string 2 line))
1579 "</span>" (substring line (match-end 2)))))
1581 ;; Does this contain a reference to a footnote?
1582 (when org-export-with-footnotes
1583 (setq start 0)
1584 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
1585 (if (get-text-property (match-beginning 2) 'org-protected line)
1586 (setq start (match-end 2))
1587 (let ((n (match-string 2 line)) extra a)
1588 (if (setq a (assoc n footref-seen))
1589 (progn
1590 (setcdr a (1+ (cdr a)))
1591 (setq extra (format ".%d" (cdr a))))
1592 (setq extra "")
1593 (push (cons n 1) footref-seen))
1594 (setq line
1595 (replace-match
1596 (concat
1597 (format
1598 (concat "%s"
1599 (format org-export-html-footnote-format
1600 (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
1601 (or (match-string 1 line) "") n extra n n)
1602 ;; If another footnote is following the
1603 ;; current one, add a separator.
1604 (if (save-match-data
1605 (string-match "\\`\\[[0-9]+\\]"
1606 (substring line (match-end 0))))
1607 org-export-html-footnote-separator
1608 ""))
1609 t t line))))))
1611 (cond
1612 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1613 ;; This is a headline
1614 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1615 level-offset))
1616 txt (match-string 2 line))
1617 (if (string-match quote-re0 txt)
1618 (setq txt (replace-match "" t t txt)))
1619 (if (<= level (max umax umax-toc))
1620 (setq head-count (+ head-count 1)))
1621 (setq first-heading-pos (or first-heading-pos (point)))
1622 (org-html-level-start level txt umax
1623 (and org-export-with-toc (<= level umax))
1624 head-count opt-plist)
1626 ;; QUOTES
1627 (when (string-match quote-re line)
1628 (org-close-par-maybe)
1629 (insert "<pre>")
1630 (setq inquote t)))
1632 ((and org-export-with-tables
1633 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1634 (when (not table-open)
1635 ;; New table starts
1636 (setq table-open t table-buffer nil table-orig-buffer nil))
1638 ;; Accumulate lines
1639 (setq table-buffer (cons line table-buffer)
1640 table-orig-buffer (cons origline table-orig-buffer))
1641 (when (or (not lines)
1642 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1643 (car lines))))
1644 (setq table-open nil
1645 table-buffer (nreverse table-buffer)
1646 table-orig-buffer (nreverse table-orig-buffer))
1647 (org-close-par-maybe)
1648 (insert (org-format-table-html table-buffer table-orig-buffer))))
1650 ;; Normal lines
1653 ;; This line either is list item or end a list.
1654 (when (get-text-property 0 'list-item line)
1655 (setq line (org-html-export-list-line
1656 line
1657 (get-text-property 0 'list-item line)
1658 (get-text-property 0 'list-struct line)
1659 (get-text-property 0 'list-prevs line))))
1661 ;; Horizontal line
1662 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1663 (if org-par-open
1664 (insert "\n</p>\n<hr/>\n<p>\n")
1665 (insert "\n<hr/>\n"))
1666 (throw 'nextline nil))
1668 ;; Empty lines start a new paragraph. If hand-formatted lists
1669 ;; are not fully interpreted, lines starting with "-", "+", "*"
1670 ;; also start a new paragraph.
1671 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
1673 ;; Is this the start of a footnote?
1674 (when org-export-with-footnotes
1675 (when (and (boundp 'footnote-section-tag-regexp)
1676 (string-match (concat "^" footnote-section-tag-regexp)
1677 line))
1678 ;; ignore this line
1679 (throw 'nextline nil))
1680 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1681 (org-close-par-maybe)
1682 (let ((n (match-string 1 line)))
1683 (setq org-par-open t
1684 line (replace-match
1685 (format
1686 (concat "<p class=\"footnote\">"
1687 (format org-export-html-footnote-format
1688 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1689 n n n) t t line)))))
1690 ;; Check if the line break needs to be conserved
1691 (cond
1692 ((string-match "\\\\\\\\[ \t]*$" line)
1693 (setq line (replace-match "<br/>" t t line)))
1694 (org-export-preserve-breaks
1695 (setq line (concat line "<br/>"))))
1697 ;; Check if a paragraph should be started
1698 (let ((start 0))
1699 (while (and org-par-open
1700 (string-match "\\\\par\\>" line start))
1701 ;; Leave a space in the </p> so that the footnote matcher
1702 ;; does not see this.
1703 (if (not (get-text-property (match-beginning 0)
1704 'org-protected line))
1705 (setq line (replace-match "</p ><p >" t t line)))
1706 (setq start (match-end 0))))
1708 (insert line "\n")))))
1710 ;; Properly close all local lists and other lists
1711 (when inquote
1712 (insert "</pre>\n")
1713 (org-open-par))
1715 (org-html-level-start 1 nil umax
1716 (and org-export-with-toc (<= level umax))
1717 head-count opt-plist)
1718 ;; the </div> to close the last text-... div.
1719 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
1721 (save-excursion
1722 (goto-char (point-min))
1723 (while (re-search-forward
1724 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1725 nil t)
1726 (push (match-string 1) footnotes)
1727 (replace-match "\\4" t nil)
1728 (goto-char (match-beginning 0))))
1729 (when footnotes
1730 (insert (format org-export-html-footnotes-section
1731 (nth 4 lang-words)
1732 (mapconcat 'identity (nreverse footnotes) "\n"))
1733 "\n"))
1734 (let ((bib (org-export-html-get-bibliography)))
1735 (when bib
1736 (insert "\n" bib "\n")))
1738 ;; export html postamble
1739 (unless body-only
1740 (let ((html-post (plist-get opt-plist :html-postamble))
1741 (email
1742 (mapconcat (lambda(e)
1743 (format "<a href=\"mailto:%s\">%s</a>" e e))
1744 (split-string email ",+ *")
1745 ", "))
1746 (creator-info
1747 (concat "Org version " org-version " with Emacs version "
1748 (number-to-string emacs-major-version))))
1749 (when (plist-get opt-plist :html-postamble)
1750 (cond ((stringp html-post)
1751 (insert "<div id=\"postamble\">\n")
1752 (insert (format-spec html-post
1753 `((?a . ,author) (?e . ,email)
1754 (?d . ,date) (?c . ,creator-info)
1755 (?v . ,html-validation-link))))
1756 (insert "</div>"))
1757 ((functionp html-post)
1758 (funcall html-post opt-plist))
1759 ((eq html-post 'auto)
1760 ;; fall back on default postamble
1761 (insert "<div id=\"postamble\">\n")
1762 (when (plist-get opt-plist :time-stamp-file)
1763 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
1764 (when (and (plist-get opt-plist :author-info) author)
1765 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
1766 (when (and (plist-get opt-plist :email-info) email)
1767 (insert "<p class=\"email\">" email "</p>\n"))
1768 (when (plist-get opt-plist :creator-info)
1769 (insert "<p class=\"creator\">"
1770 (concat "Org version " org-version " with Emacs version "
1771 (number-to-string emacs-major-version) "</p>\n")))
1772 (insert html-validation-link "\n</div>"))
1774 (insert "<div id=\"postamble\">\n")
1775 (insert (format-spec
1776 (or (cadr (assoc (nth 0 lang-words)
1777 org-export-html-postamble-format))
1778 (cadr (assoc "en" org-export-html-postamble-format)))
1779 `((?a . ,author) (?e . ,email)
1780 (?d . ,date) (?c . ,creator-info)
1781 (?v . ,html-validation-link))))
1782 (insert "</div>"))))))
1784 (if org-export-html-with-timestamp
1785 (insert org-export-html-html-helper-timestamp))
1787 (unless body-only (insert "\n</div>\n</body>\n</html>\n"))
1789 (unless (plist-get opt-plist :buffer-will-be-killed)
1790 (normal-mode)
1791 (if (eq major-mode (default-value 'major-mode))
1792 (html-mode)))
1794 ;; insert the table of contents
1795 (goto-char (point-min))
1796 (when thetoc
1797 (if (or (re-search-forward
1798 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1799 (re-search-forward
1800 "\\[TABLE-OF-CONTENTS\\]" nil t))
1801 (progn
1802 (goto-char (match-beginning 0))
1803 (replace-match ""))
1804 (goto-char first-heading-pos)
1805 (when (looking-at "\\s-*</p>")
1806 (goto-char (match-end 0))
1807 (insert "\n")))
1808 (insert "<div id=\"table-of-contents\">\n")
1809 (let ((beg (point)))
1810 (mapc 'insert thetoc)
1811 (insert "</div>\n")
1812 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
1813 (replace-match ""))))
1814 ;; remove empty paragraphs
1815 (goto-char (point-min))
1816 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
1817 (replace-match ""))
1818 (goto-char (point-min))
1819 ;; Convert whitespace place holders
1820 (goto-char (point-min))
1821 (let (beg end n)
1822 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1823 (setq n (get-text-property beg 'org-whitespace)
1824 end (next-single-property-change beg 'org-whitespace))
1825 (goto-char beg)
1826 (delete-region beg end)
1827 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1828 (make-string n ?x)))))
1829 ;; Remove empty lines at the beginning of the file.
1830 (goto-char (point-min))
1831 (when (looking-at "\\s-+\n") (replace-match ""))
1832 ;; Remove display properties
1833 (remove-text-properties (point-min) (point-max) '(display t))
1834 ;; Run the hook
1835 (run-hooks 'org-export-html-final-hook)
1836 (or to-buffer (save-buffer))
1837 (goto-char (point-min))
1838 (or (org-export-push-to-kill-ring "HTML")
1839 (message "Exporting... done"))
1840 (if (eq to-buffer 'string)
1841 (prog1 (buffer-substring (point-min) (point-max))
1842 (kill-buffer (current-buffer)))
1843 (current-buffer)))))
1845 (defun org-export-html-format-href (s)
1846 "Make sure the S is valid as a href reference in an XHTML document."
1847 (save-match-data
1848 (let ((start 0))
1849 (while (string-match "&" s start)
1850 (setq start (+ (match-beginning 0) 3)
1851 s (replace-match "&amp;" t t s)))))
1854 (defun org-export-html-format-desc (s)
1855 "Make sure the S is valid as a description in a link."
1856 (if (and s (not (get-text-property 1 'org-protected s)))
1857 (save-match-data
1858 (org-html-do-expand s))
1861 (defun org-export-html-format-image (src par-open)
1862 "Create image tag with source and attributes."
1863 (save-match-data
1864 (if (string-match "^ltxpng/" src)
1865 (format "<img src=\"%s\" alt=\"%s\"/>"
1866 src (org-find-text-property-in-string 'org-latex-src src))
1867 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1868 (attr (org-find-text-property-in-string 'org-attributes src))
1869 (label (org-find-text-property-in-string 'org-label src)))
1870 (setq caption (and caption (org-html-do-expand caption)))
1871 (concat
1872 (if caption
1873 (format "%s<div %sclass=\"figure\">
1874 <p>"
1875 (if org-par-open "</p>\n" "")
1876 (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
1877 (format "<img src=\"%s\"%s />"
1879 (if (string-match "\\<alt=" (or attr ""))
1880 (concat " " attr )
1881 (concat " " attr " alt=\"" src "\"")))
1882 (if caption
1883 (format "</p>%s
1884 </div>%s"
1885 (concat "\n<p>" caption "</p>")
1886 (if org-par-open "\n<p>" ""))))))))
1888 (defun org-export-html-get-bibliography ()
1889 "Find bibliography, cut it out and return it."
1890 (catch 'exit
1891 (let (beg end (cnt 1) bib)
1892 (save-excursion
1893 (goto-char (point-min))
1894 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1895 (setq beg (match-beginning 0))
1896 (while (re-search-forward "</?div\\>" nil t)
1897 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1898 (when (= cnt 0)
1899 (and (looking-at ">") (forward-char 1))
1900 (setq bib (buffer-substring beg (point)))
1901 (delete-region beg (point))
1902 (throw 'exit bib))))
1903 nil))))
1905 (defvar org-table-number-regexp) ; defined in org-table.el
1906 (defun org-format-table-html (lines olines &optional no-css)
1907 "Find out which HTML converter to use and return the HTML code.
1908 NO-CSS is passed to the exporter."
1909 (if (stringp lines)
1910 (setq lines (org-split-string lines "\n")))
1911 (if (string-match "^[ \t]*|" (car lines))
1912 ;; A normal org table
1913 (org-format-org-table-html lines nil no-css)
1914 ;; Table made by table.el
1915 (or (org-format-table-table-html-using-table-generate-source
1916 olines (not org-export-prefer-native-exporter-for-tables))
1917 ;; We are here only when table.el table has NO col or row
1918 ;; spanning and the user prefers using org's own converter for
1919 ;; exporting of such simple table.el tables.
1920 (org-format-table-table-html lines))))
1922 (defvar org-table-number-fraction) ; defined in org-table.el
1923 (defun org-format-org-table-html (lines &optional splice no-css)
1924 "Format a table into HTML.
1925 LINES is a list of lines. Optional argument SPLICE means, do not
1926 insert header and surrounding <table> tags, just format the lines.
1927 Optional argument NO-CSS means use XHTML attributes instead of CSS
1928 for formatting. This is required for the DocBook exporter."
1929 (require 'org-table)
1930 ;; Get rid of hlines at beginning and end
1931 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1932 (setq lines (nreverse lines))
1933 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1934 (setq lines (nreverse lines))
1935 (when org-export-table-remove-special-lines
1936 ;; Check if the table has a marking column. If yes remove the
1937 ;; column and the special lines
1938 (setq lines (org-table-clean-before-export lines)))
1940 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
1941 (label (org-find-text-property-in-string 'org-label (car lines)))
1942 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
1943 (car lines)))
1944 (attributes (org-find-text-property-in-string 'org-attributes
1945 (car lines)))
1946 (html-table-tag (org-export-splice-attributes
1947 html-table-tag attributes))
1948 (head (and org-export-highlight-first-table-line
1949 (delq nil (mapcar
1950 (lambda (x) (string-match "^[ \t]*|-" x))
1951 (cdr lines)))))
1952 (nline 0) fnum nfields i (cnt 0)
1953 tbopen line fields html gr colgropen rowstart rowend
1954 ali align aligns n)
1955 (setq caption (and caption (org-html-do-expand caption)))
1956 (when (and forced-aligns org-table-clean-did-remove-column)
1957 (setq forced-aligns
1958 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
1959 (if splice (setq head nil))
1960 (unless splice (push (if head "<thead>" "<tbody>") html))
1961 (setq tbopen t)
1962 (while (setq line (pop lines))
1963 (catch 'next-line
1964 (if (string-match "^[ \t]*|-" line)
1965 (progn
1966 (unless splice
1967 (push (if head "</thead>" "</tbody>") html)
1968 (if lines (push "<tbody>" html) (setq tbopen nil)))
1969 (setq head nil) ;; head ends here, first time around
1970 ;; ignore this line
1971 (throw 'next-line t)))
1972 ;; Break the line into fields
1973 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1974 (unless fnum (setq fnum (make-vector (length fields) 0)
1975 nfields (length fnum)))
1976 (setq nline (1+ nline) i -1
1977 rowstart (eval (car org-export-table-row-tags))
1978 rowend (eval (cdr org-export-table-row-tags)))
1979 (push (concat rowstart
1980 (mapconcat
1981 (lambda (x)
1982 (setq i (1+ i) ali (format "@@class%03d@@" i))
1983 (if (and (< i nfields) ; make sure no rogue line causes an error here
1984 (string-match org-table-number-regexp x))
1985 (incf (aref fnum i)))
1986 (cond
1987 (head
1988 (concat
1989 (format (car org-export-table-header-tags)
1990 "col" ali)
1992 (cdr org-export-table-header-tags)))
1993 ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
1994 (concat
1995 (format (car org-export-table-header-tags)
1996 "row" ali)
1998 (cdr org-export-table-header-tags)))
2000 (concat (format (car org-export-table-data-tags) ali)
2002 (cdr org-export-table-data-tags)))))
2003 fields "")
2004 rowend)
2005 html)))
2006 (unless splice (if tbopen (push "</tbody>" html)))
2007 (unless splice (push "</table>\n" html))
2008 (setq html (nreverse html))
2009 (unless splice
2010 ;; Put in col tags with the alignment (unfortunately often ignored...)
2011 (unless (car org-table-colgroup-info)
2012 (setq org-table-colgroup-info
2013 (cons :start (cdr org-table-colgroup-info))))
2014 (setq i 0)
2015 (push (mapconcat
2016 (lambda (x)
2017 (setq gr (pop org-table-colgroup-info)
2018 i (1+ i)
2019 align (if (assoc i forced-aligns)
2020 (cdr (assoc (cdr (assoc i forced-aligns))
2021 '(("l" . "left") ("r" . "right")
2022 ("c" . "center"))))
2023 (if (> (/ (float x) nline)
2024 org-table-number-fraction)
2025 "right" "left")))
2026 (push align aligns)
2027 (format (if no-css
2028 "%s<col align=\"%s\" />%s"
2029 "%s<col class=\"%s\" />%s")
2030 (if (memq gr '(:start :startend))
2031 (prog1
2032 (if colgropen
2033 "</colgroup>\n<colgroup>"
2034 "<colgroup>")
2035 (setq colgropen t))
2037 align
2038 (if (memq gr '(:end :startend))
2039 (progn (setq colgropen nil) "</colgroup>")
2040 "")))
2041 fnum "")
2042 html)
2043 (setq aligns (nreverse aligns))
2044 (if colgropen (setq html (cons (car html)
2045 (cons "</colgroup>" (cdr html)))))
2046 ;; Since the output of HTML table formatter can also be used in
2047 ;; DocBook document, we want to always include the caption to make
2048 ;; DocBook XML file valid.
2049 (push (format "<caption>%s</caption>" (or caption "")) html)
2050 (when label
2051 (setq html-table-tag (org-export-splice-attributes html-table-tag (format "id=\"%s\"" (org-solidify-link-text label)))))
2052 (push html-table-tag html))
2053 (setq html (mapcar
2054 (lambda (x)
2055 (replace-regexp-in-string
2056 "@@class\\([0-9]+\\)@@"
2057 (lambda (txt)
2058 (if (not org-export-html-table-align-individual-fields)
2060 (setq n (string-to-number (match-string 1 txt)))
2061 (format (if no-css " align=\"%s\"" " class=\"%s\"")
2062 (or (nth n aligns) "left"))))
2064 html))
2065 (concat (mapconcat 'identity html "\n") "\n")))
2067 (defun org-export-splice-attributes (tag attributes)
2068 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2069 (if (not attributes)
2071 (let (oldatt newatt)
2072 (setq oldatt (org-extract-attributes-from-string tag)
2073 tag (pop oldatt)
2074 newatt (cdr (org-extract-attributes-from-string attributes)))
2075 (while newatt
2076 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
2077 (if (string-match ">" tag)
2078 (setq tag
2079 (replace-match (concat (org-attributes-to-string oldatt) ">")
2080 t t tag)))
2081 tag)))
2083 (defun org-format-table-table-html (lines)
2084 "Format a table generated by table.el into HTML.
2085 This conversion does *not* use `table-generate-source' from table.el.
2086 This has the advantage that Org-mode's HTML conversions can be used.
2087 But it has the disadvantage, that no cell- or row-spanning is allowed."
2088 (let (line field-buffer
2089 (head org-export-highlight-first-table-line)
2090 fields html empty i)
2091 (setq html (concat html-table-tag "\n"))
2092 (while (setq line (pop lines))
2093 (setq empty "&nbsp;")
2094 (catch 'next-line
2095 (if (string-match "^[ \t]*\\+-" line)
2096 (progn
2097 (if field-buffer
2098 (progn
2099 (setq
2100 html
2101 (concat
2102 html
2103 "<tr>"
2104 (mapconcat
2105 (lambda (x)
2106 (if (equal x "") (setq x empty))
2107 (if head
2108 (concat
2109 (format (car org-export-table-header-tags) "col" "")
2111 (cdr org-export-table-header-tags))
2112 (concat (format (car org-export-table-data-tags) "") x
2113 (cdr org-export-table-data-tags))))
2114 field-buffer "\n")
2115 "</tr>\n"))
2116 (setq head nil)
2117 (setq field-buffer nil)))
2118 ;; Ignore this line
2119 (throw 'next-line t)))
2120 ;; Break the line into fields and store the fields
2121 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2122 (if field-buffer
2123 (setq field-buffer (mapcar
2124 (lambda (x)
2125 (concat x "<br/>" (pop fields)))
2126 field-buffer))
2127 (setq field-buffer fields))))
2128 (setq html (concat html "</table>\n"))
2129 html))
2131 (defun org-format-table-table-html-using-table-generate-source (lines
2132 &optional
2133 spanned-only)
2134 "Format a table into html, using `table-generate-source' from table.el.
2135 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
2137 When SPANNED-ONLY is nil, all table.el tables are exported. When
2138 SPANNED-ONLY is non-nil, only tables with either row or column
2139 spans are exported.
2141 This routine returns the generated source or nil as appropriate.
2143 Refer docstring of `org-export-prefer-native-exporter-for-tables'
2144 for further information."
2145 (require 'table)
2146 (with-current-buffer (get-buffer-create " org-tmp1 ")
2147 (erase-buffer)
2148 (insert (mapconcat 'identity lines "\n"))
2149 (goto-char (point-min))
2150 (if (not (re-search-forward "|[^+]" nil t))
2151 (error "Error processing table"))
2152 (table-recognize-table)
2153 (when (or (not spanned-only)
2154 (let* ((dim (table-query-dimension))
2155 (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim)))
2156 (not (= (* c r) cells))))
2157 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2158 (table-generate-source 'html " org-tmp2 ")
2159 (set-buffer " org-tmp2 ")
2160 (buffer-substring (point-min) (point-max)))))
2162 (defun org-export-splice-style (style extra)
2163 "Splice EXTRA into STYLE, just before \"</style>\"."
2164 (if (and (stringp extra)
2165 (string-match "\\S-" extra)
2166 (string-match "</style>" style))
2167 (concat (substring style 0 (match-beginning 0))
2168 "\n" extra "\n"
2169 (substring style (match-beginning 0)))
2170 style))
2172 (defun org-html-handle-time-stamps (s)
2173 "Format time stamps in string S, or remove them."
2174 (catch 'exit
2175 (let (r b)
2176 (while (string-match org-maybe-keyword-time-regexp s)
2177 (or b (setq b (substring s 0 (match-beginning 0))))
2178 (setq r (concat
2179 r (substring s 0 (match-beginning 0))
2180 " @<span class=\"timestamp-wrapper\">"
2181 (if (match-end 1)
2182 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2183 (match-string 1 s)))
2184 (format " @<span class=\"timestamp\">%s@</span>"
2185 (substring
2186 (org-translate-time (match-string 3 s)) 1 -1))
2187 "@</span>")
2188 s (substring s (match-end 0))))
2189 ;; Line break if line started and ended with time stamp stuff
2190 (if (not r)
2192 (setq r (concat r s))
2193 (unless (string-match "\\S-" (concat b s))
2194 (setq r (concat r "@<br/>")))
2195 r))))
2197 (defvar htmlize-buffer-places) ; from htmlize.el
2198 (defun org-export-htmlize-region-for-paste (beg end)
2199 "Convert the region to HTML, using htmlize.el.
2200 This is much like `htmlize-region-for-paste', only that it uses
2201 the settings define in the org-... variables."
2202 (let* ((htmlize-output-type org-export-htmlize-output-type)
2203 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
2204 (htmlbuf (htmlize-region beg end)))
2205 (unwind-protect
2206 (with-current-buffer htmlbuf
2207 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
2208 (plist-get htmlize-buffer-places 'content-end)))
2209 (kill-buffer htmlbuf))))
2211 ;;;###autoload
2212 (defun org-export-htmlize-generate-css ()
2213 "Create the CSS for all font definitions in the current Emacs session.
2214 Use this to create face definitions in your CSS style file that can then
2215 be used by code snippets transformed by htmlize.
2216 This command just produces a buffer that contains class definitions for all
2217 faces used in the current Emacs session. You can copy and paste the ones you
2218 need into your CSS file.
2220 If you then set `org-export-htmlize-output-type' to `css', calls to
2221 the function `org-export-htmlize-region-for-paste' will produce code
2222 that uses these same face definitions."
2223 (interactive)
2224 (require 'htmlize)
2225 (and (get-buffer "*html*") (kill-buffer "*html*"))
2226 (with-temp-buffer
2227 (let ((fl (face-list))
2228 (htmlize-css-name-prefix "org-")
2229 (htmlize-output-type 'css)
2230 f i)
2231 (while (setq f (pop fl)
2232 i (and f (face-attribute f :inherit)))
2233 (when (and (symbolp f) (or (not i) (not (listp i))))
2234 (insert (org-add-props (copy-sequence "1") nil 'face f))))
2235 (htmlize-region (point-min) (point-max))))
2236 (switch-to-buffer "*html*")
2237 (goto-char (point-min))
2238 (if (re-search-forward "<style" nil t)
2239 (delete-region (point-min) (match-beginning 0)))
2240 (if (re-search-forward "</style>" nil t)
2241 (delete-region (1+ (match-end 0)) (point-max)))
2242 (beginning-of-line 1)
2243 (if (looking-at " +") (replace-match ""))
2244 (goto-char (point-min)))
2246 (defun org-html-protect (s)
2247 "Convert characters to HTML equivalent.
2248 Possible conversions are set in `org-export-html-protect-char-alist'."
2249 (let ((cl org-export-html-protect-char-alist) c)
2250 (while (setq c (pop cl))
2251 (let ((start 0))
2252 (while (string-match (car c) s start)
2253 (setq s (replace-match (cdr c) t t s)
2254 start (1+ (match-beginning 0))))))
2257 (defun org-html-expand (string)
2258 "Prepare STRING for HTML export. Apply all active conversions.
2259 If there are links in the string, don't modify these."
2260 (let* ((re (concat org-bracket-link-regexp "\\|"
2261 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2262 m s l res)
2263 (while (setq m (string-match re string))
2264 (setq s (substring string 0 m)
2265 l (match-string 0 string)
2266 string (substring string (match-end 0)))
2267 (push (org-html-do-expand s) res)
2268 (push l res))
2269 (push (org-html-do-expand string) res)
2270 (apply 'concat (nreverse res))))
2272 (defun org-html-do-expand (s)
2273 "Apply all active conversions to translate special ASCII to HTML."
2274 (setq s (org-html-protect s))
2275 (if org-export-html-expand
2276 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
2277 (setq s (replace-match "<\\1>" t nil s))))
2278 (if org-export-with-emphasize
2279 (setq s (org-export-html-convert-emphasize s)))
2280 (if org-export-with-special-strings
2281 (setq s (org-export-html-convert-special-strings s)))
2282 (if org-export-with-sub-superscripts
2283 (setq s (org-export-html-convert-sub-super s)))
2284 (if org-export-with-TeX-macros
2285 (let ((start 0) wd rep)
2286 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2287 s start))
2288 (if (get-text-property (match-beginning 0) 'org-protected s)
2289 (setq start (match-end 0))
2290 (setq wd (match-string 1 s))
2291 (if (setq rep (org-entity-get-representation wd 'html))
2292 (setq s (replace-match rep t t s))
2293 (setq start (+ start (length wd))))))))
2296 (defun org-export-html-convert-special-strings (string)
2297 "Convert special characters in STRING to HTML."
2298 (let ((all org-export-html-special-string-regexps)
2299 e a re rpl start)
2300 (while (setq a (pop all))
2301 (setq re (car a) rpl (cdr a) start 0)
2302 (while (string-match re string start)
2303 (if (get-text-property (match-beginning 0) 'org-protected string)
2304 (setq start (match-end 0))
2305 (setq string (replace-match rpl t nil string)))))
2306 string))
2308 (defun org-export-html-convert-sub-super (string)
2309 "Convert sub- and superscripts in STRING to HTML."
2310 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
2311 (while (string-match org-match-substring-regexp string s)
2312 (cond
2313 ((and requireb (match-end 8)) (setq s (match-end 2)))
2314 ((get-text-property (match-beginning 2) 'org-protected string)
2315 (setq s (match-end 2)))
2317 (setq s (match-end 1)
2318 key (if (string= (match-string 2 string) "_") "sub" "sup")
2319 c (or (match-string 8 string)
2320 (match-string 6 string)
2321 (match-string 5 string))
2322 string (replace-match
2323 (concat (match-string 1 string)
2324 "<" key ">" c "</" key ">")
2325 t t string)))))
2326 (while (string-match "\\\\\\([_^]\\)" string)
2327 (setq string (replace-match (match-string 1 string) t t string)))
2328 string))
2330 (defun org-export-html-convert-emphasize (string)
2331 "Apply emphasis."
2332 (let ((s 0) rpl)
2333 (while (string-match org-emph-re string s)
2334 (if (not (equal
2335 (substring string (match-beginning 3) (1+ (match-beginning 3)))
2336 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
2337 (setq s (match-beginning 0)
2339 (concat
2340 (match-string 1 string)
2341 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
2342 (match-string 4 string)
2343 (nth 3 (assoc (match-string 3 string)
2344 org-emphasis-alist))
2345 (match-string 5 string))
2346 string (replace-match rpl t t string)
2347 s (+ s (- (length rpl) 2)))
2348 (setq s (1+ s))))
2349 string))
2351 (defun org-open-par ()
2352 "Insert <p>, but first close previous paragraph if any."
2353 (org-close-par-maybe)
2354 (insert "\n<p>")
2355 (setq org-par-open t))
2356 (defun org-close-par-maybe ()
2357 "Close paragraph if there is one open."
2358 (when org-par-open
2359 (insert "</p>")
2360 (setq org-par-open nil)))
2361 (defun org-close-li (&optional type)
2362 "Close <li> if necessary."
2363 (org-close-par-maybe)
2364 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
2366 (defvar body-only) ; dynamically scoped into this.
2367 (defun org-html-level-start (level title umax with-toc head-count &optional opt-plist)
2368 "Insert a new level in HTML export.
2369 When TITLE is nil, just close all open levels."
2370 (org-close-par-maybe)
2371 (let* ((target (and title (org-get-text-property-any 0 'target title)))
2372 (extra-targets (and target
2373 (assoc target org-export-target-aliases)))
2374 (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
2375 (preferred (and target
2376 (cdr (assoc target org-export-preferred-target-alist))))
2377 (l org-level-max)
2378 (num (plist-get opt-plist :section-numbers))
2379 snumber snu href suffix)
2380 (setq extra-targets (remove (or preferred target) extra-targets))
2381 (setq extra-targets
2382 (mapconcat (lambda (x)
2383 (setq x (org-solidify-link-text
2384 (if (org-uuidgen-p x) (concat "ID-" x) x)))
2385 (format "<a name=\"%s\" id=\"%s\"></a>"
2386 x x))
2387 extra-targets
2388 ""))
2389 (while (>= l level)
2390 (if (aref org-levels-open (1- l))
2391 (progn
2392 (org-html-level-close l umax)
2393 (aset org-levels-open (1- l) nil)))
2394 (setq l (1- l)))
2395 (when title
2396 ;; If title is nil, this means this function is called to close
2397 ;; all levels, so the rest is done only if title is given
2398 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2399 (setq title (replace-match
2400 (if org-export-with-tags
2401 (save-match-data
2402 (concat
2403 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
2404 (mapconcat
2405 (lambda (x)
2406 (format "<span class=\"%s\">%s</span>"
2407 (org-export-html-get-tag-class-name x)
2409 (org-split-string (match-string 1 title) ":")
2410 "&nbsp;")
2411 "</span>"))
2413 t t title)))
2414 (if (> level umax)
2415 (progn
2416 (if (aref org-levels-open (1- level))
2417 (progn
2418 (org-close-li)
2419 (if target
2420 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2421 extra-targets title "<br/>\n")
2422 (insert "<li>" title "<br/>\n")))
2423 (aset org-levels-open (1- level) t)
2424 (org-close-par-maybe)
2425 (if target
2426 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
2427 extra-targets title "<br/>\n")
2428 (insert "<ul>\n<li>" title "<br/>\n"))))
2429 (aset org-levels-open (1- level) t)
2430 (setq snumber (org-section-number level)
2431 snu (replace-regexp-in-string "\\." "-" snumber))
2432 (setq level (+ level org-export-html-toplevel-hlevel -1))
2433 (if (and num (not body-only))
2434 (setq title (concat
2435 (format "<span class=\"section-number-%d\">%s</span>"
2436 level
2437 (if (and num
2438 (if (integerp num)
2439 ;; fix up num to take into
2440 ;; account the top-level
2441 ;; heading value
2442 (>= (+ num org-export-html-toplevel-hlevel -1)
2443 level)
2444 num))
2445 snumber
2446 ""))
2447 " " title)))
2448 (unless (= head-count 1) (insert "\n</div>\n"))
2449 (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
2450 (setq suffix (org-solidify-link-text (or href snu)))
2451 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2452 (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"
2453 suffix level (if extra-class (concat " " extra-class) "")
2454 level href
2455 extra-targets
2456 title level level suffix))
2457 (org-open-par)))))
2459 (defun org-export-html-get-tag-class-name (tag)
2460 "Turn tag into a valid class name.
2461 Replaces invalid characters with \"_\" and then prepends a prefix."
2462 (save-match-data
2463 (while (string-match "[^a-zA-Z0-9_]" tag)
2464 (setq tag (replace-match "_" t t tag))))
2465 (concat org-export-html-tag-class-prefix tag))
2467 (defun org-export-html-get-todo-kwd-class-name (kwd)
2468 "Turn todo keyword into a valid class name.
2469 Replaces invalid characters with \"_\" and then prepends a prefix."
2470 (save-match-data
2471 (while (string-match "[^a-zA-Z0-9_]" kwd)
2472 (setq kwd (replace-match "_" t t kwd))))
2473 (concat org-export-html-todo-kwd-class-prefix kwd))
2475 (defun org-html-level-close (level max-outline-level)
2476 "Terminate one level in HTML export."
2477 (if (<= level max-outline-level)
2478 (insert "</div>\n")
2479 (org-close-li)
2480 (insert "</ul>\n")))
2482 (defun org-html-export-list-line (line pos struct prevs)
2483 "Insert list syntax in export buffer. Return LINE, maybe modified.
2485 POS is the item position or line position the line had before
2486 modifications to buffer. STRUCT is the list structure. PREVS is
2487 the alist of previous items."
2488 (let* ((get-type
2489 (function
2490 ;; Translate type of list containing POS to "d", "o" or
2491 ;; "u".
2492 (lambda (pos struct prevs)
2493 (let ((type (org-list-get-list-type pos struct prevs)))
2494 (cond
2495 ((eq 'ordered type) "o")
2496 ((eq 'descriptive type) "d")
2497 (t "u"))))))
2498 (get-closings
2499 (function
2500 ;; Return list of all items and sublists ending at POS, in
2501 ;; reverse order.
2502 (lambda (pos)
2503 (let (out)
2504 (catch 'exit
2505 (mapc (lambda (e)
2506 (let ((end (nth 6 e))
2507 (item (car e)))
2508 (cond
2509 ((= end pos) (push item out))
2510 ((>= item pos) (throw 'exit nil)))))
2511 struct))
2512 out)))))
2513 ;; First close any previous item, or list, ending at POS.
2514 (mapc (lambda (e)
2515 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2516 (first-item (org-list-get-list-begin e struct prevs))
2517 (type (funcall get-type first-item struct prevs)))
2518 (org-close-par-maybe)
2519 ;; Ending for every item
2520 (org-close-li type)
2521 ;; We're ending last item of the list: end list.
2522 (when lastp
2523 (insert (format "</%sl>\n" type))
2524 (org-open-par))))
2525 (funcall get-closings pos))
2526 (cond
2527 ;; At an item: insert appropriate tags in export buffer.
2528 ((assq pos struct)
2529 (string-match
2530 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2531 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2532 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2533 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2534 "\\(.*\\)") line)
2535 (let* ((checkbox (match-string 3 line))
2536 (desc-tag (or (match-string 4 line) "???"))
2537 (body (or (match-string 5 line) ""))
2538 (list-beg (org-list-get-list-begin pos struct prevs))
2539 (firstp (= list-beg pos))
2540 ;; Always refer to first item to determine list type, in
2541 ;; case list is ill-formed.
2542 (type (funcall get-type list-beg struct prevs))
2543 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2544 (cond
2545 ((not count-tmp) nil)
2546 ((string-match "[A-Za-z]" count-tmp)
2547 (- (string-to-char (upcase count-tmp)) 64))
2548 ((string-match "[0-9]+" count-tmp)
2549 count-tmp)))))
2550 (when firstp
2551 (org-close-par-maybe)
2552 (insert (format "<%sl>\n" type)))
2553 (insert (cond
2554 ((equal type "d")
2555 (format "<dt>%s</dt><dd>" desc-tag))
2556 ((and (equal type "o") counter)
2557 (format "<li value=\"%s\">" counter))
2558 (t "<li>")))
2559 ;; If line had a checkbox, some additional modification is required.
2560 (when checkbox
2561 (setq body
2562 (concat
2563 (cond
2564 ((string-match "X" checkbox) "<code>[X]</code> ")
2565 ((string-match " " checkbox) "<code>[&nbsp;]</code> ")
2566 (t "<code>[-]</code> "))
2567 body)))
2568 ;; Return modified line
2569 body))
2570 ;; At a list ender: go to next line (side-effects only).
2571 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2572 ;; Not at an item: return line unchanged (side-effects only).
2573 (t line))))
2575 (provide 'org-html)
2577 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
2578 ;;; org-html.el ends here