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