org-html.el: Take care of byte-compiler warnings.
[org-mode/org-jambu.git] / lisp / org-html.el
blobbd5374154c2bd7b34087b4a4181ee0866f6e4a2e
1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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)
63 (defcustom org-export-html-coding-system nil
64 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
65 :group 'org-export-html
66 :type 'coding-system)
68 (defcustom org-export-html-extension "html"
69 "The extension for exported HTML files."
70 :group 'org-export-html
71 :type 'string)
73 (defcustom org-export-html-xml-declaration
74 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
75 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
76 "The extension for exported HTML files.
77 %s will be replaced with the charset of the exported file.
78 This may be a string, or an alist with export extensions
79 and corresponding declarations."
80 :group 'org-export-html
81 :type '(choice
82 (string :tag "Single declaration")
83 (repeat :tag "Dependent on extension"
84 (cons (string :tag "Extension")
85 (string :tag "Declaration")))))
87 (defcustom org-export-html-style-include-scripts t
88 "Non-nil means include the JavaScript snippets in exported HTML files.
89 The actual script is defined in `org-export-html-scripts' and should
90 not be modified."
91 :group 'org-export-html
92 :type 'boolean)
94 (defconst org-export-html-scripts
95 "<script type=\"text/javascript\">
96 <!--/*--><![CDATA[/*><!--*/
97 function CodeHighlightOn(elem, id)
99 var target = document.getElementById(id);
100 if(null != target) {
101 elem.cacheClassElem = elem.className;
102 elem.cacheClassTarget = target.className;
103 target.className = \"code-highlighted\";
104 elem.className = \"code-highlighted\";
107 function CodeHighlightOff(elem, id)
109 var target = document.getElementById(id);
110 if(elem.cacheClassElem)
111 elem.className = elem.cacheClassElem;
112 if(elem.cacheClassTarget)
113 target.className = elem.cacheClassTarget;
115 /*]]>*///-->
116 </script>"
117 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
119 (defconst org-export-html-style-default
120 "<style type=\"text/css\">
121 <!--/*--><![CDATA[/*><!--*/
122 html { font-family: Times, serif; font-size: 12pt; }
123 .title { text-align: center; }
124 .todo { color: red; }
125 .done { color: green; }
126 .tag { background-color: #add8e6; font-weight:normal }
127 .target { }
128 .timestamp { color: #bebebe; }
129 .timestamp-kwd { color: #5f9ea0; }
130 .right {margin-left:auto; margin-right:0px; text-align:right;}
131 .left {margin-left:0px; margin-right:auto; text-align:left;}
132 .center {margin-left:auto; margin-right:auto; text-align:center;}
133 p.verse { margin-left: 3% }
134 pre {
135 border: 1pt solid #AEBDCC;
136 background-color: #F3F5F7;
137 padding: 5pt;
138 font-family: courier, monospace;
139 font-size: 90%;
140 overflow:auto;
142 table { border-collapse: collapse; }
143 td, th { vertical-align: top; }
144 th.right { text-align:center; }
145 th.left { text-align:center; }
146 th.center { text-align:center; }
147 td.right { text-align:right; }
148 td.left { text-align:left; }
149 td.center { text-align:center; }
150 dt { font-weight: bold; }
151 div.figure { padding: 0.5em; }
152 div.figure p { text-align: center; }
153 textarea { overflow-x: auto; }
154 .linenr { font-size:smaller }
155 .code-highlighted {background-color:#ffff00;}
156 .org-info-js_info-navigation { border-style:none; }
157 #org-info-js_console-label { font-size:10px; font-weight:bold;
158 white-space:nowrap; }
159 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
160 font-weight:bold; }
161 /*]]>*/-->
162 </style>"
163 "The default style specification for exported HTML files.
164 Please use the variables `org-export-html-style' and
165 `org-export-html-style-extra' to add to this style. If you wish to not
166 have the default style included, customize the variable
167 `org-export-html-style-include-default'.")
169 (defcustom org-export-html-style-include-default t
170 "Non-nil means include the default style in exported HTML files.
171 The actual style is defined in `org-export-html-style-default' and should
172 not be modified. Use the variables `org-export-html-style' to add
173 your own style information."
174 :group 'org-export-html
175 :type 'boolean)
176 ;;;###autoload
177 (put 'org-export-html-style-include-default 'safe-local-variable 'booleanp)
179 (defcustom org-export-html-style ""
180 "Org-wide style definitions for exported HTML files.
182 This variable needs to contain the full HTML structure to provide a style,
183 including the surrounding HTML tags. If you set the value of this variable,
184 you should consider to include definitions for the following classes:
185 title, todo, done, timestamp, timestamp-kwd, tag, target.
187 For example, a valid value would be:
189 <style type=\"text/css\">
190 <![CDATA[
191 p { font-weight: normal; color: gray; }
192 h1 { color: black; }
193 .title { text-align: center; }
194 .todo, .timestamp-kwd { color: red; }
195 .done { color: green; }
197 </style>
199 If you'd like to refer to en external style file, use something like
201 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
203 As the value of this option simply gets inserted into the HTML <head> header,
204 you can \"misuse\" it to add arbitrary text to the header.
205 See also the variable `org-export-html-style-extra'."
206 :group 'org-export-html
207 :type 'string)
208 ;;;###autoload
209 (put 'org-export-html-style 'safe-local-variable 'stringp)
211 (defcustom org-export-html-style-extra ""
212 "Additional style information for HTML export.
213 The value of this variable is inserted into the HTML buffer right after
214 the value of `org-export-html-style'. Use this variable for per-file
215 settings of style information, and do not forget to surround the style
216 settings with <style>...</style> tags."
217 :group 'org-export-html
218 :type 'string)
219 ;;;###autoload
220 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
222 (defcustom org-export-html-mathjax-options
223 '((path "http://orgmode.org/mathjax/MathJax.js")
224 (scale "100")
225 (align "center")
226 (indent "2em")
227 (mathml nil))
228 "Options for MathJax setup.
230 path The path where to find MathJax
231 scale Scaling for the HTML-CSS backend, usually between 100 and 133
232 align How to align display math: left, center, or right
233 indent If align is not center, how far from the left/right side?
234 mathml Should a MathML player be used if available?
235 This is faster and reduces bandwidth use, but currently
236 sometimes has lower spacing quality. Therefore, the default is
237 nil. When browsers get better, this switch can be flipped.
239 You can also customize this for each buffer, using something like
241 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
242 :group 'org-export-html
243 :type '(list :greedy t
244 (list :tag "path (the path from where to load MathJax.js)"
245 (const :format " " path) (string))
246 (list :tag "scale (scaling for the displayed math)"
247 (const :format " " scale) (string))
248 (list :tag "align (alignment of displayed equations)"
249 (const :format " " align) (string))
250 (list :tag "indent (indentation with left or right alignment)"
251 (const :format " " indent) (string))
252 (list :tag "mathml (should MathML display be used is possible)"
253 (const :format " " mathml) (boolean))))
255 (defun org-export-html-mathjax-config (template options in-buffer)
256 "Insert the user setup into the matchjax template."
257 (let (name val (yes " ") (no "// ") x)
258 (mapc
259 (lambda (e)
260 (setq name (car e) val (nth 1 e))
261 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
262 (setq val (car (read-from-string
263 (substring in-buffer (match-end 0))))))
264 (if (not (stringp val)) (setq val (format "%s" val)))
265 (if (string-match (concat "%" (upcase (symbol-name name))) template)
266 (setq template (replace-match val t t template))))
267 options)
268 (setq val (nth 1 (assq 'mathml options)))
269 (if (string-match (concat "\\<mathml:") in-buffer)
270 (setq val (car (read-from-string
271 (substring in-buffer (match-end 0))))))
272 ;; Exchange prefixes depending on mathml setting
273 (if (not val) (setq x yes yes no no x))
274 ;; Replace cookies to turn on or off the config/jax lines
275 (if (string-match ":MMLYES:" template)
276 (setq template (replace-match yes t t template)))
277 (if (string-match ":MMLNO:" template)
278 (setq template (replace-match no t t template)))
279 ;; Return the modified template
280 template))
282 (defcustom org-export-html-mathjax-template
283 "<script type=\"text/javascript\" src=\"%PATH\">
284 <!--/*--><![CDATA[/*><!--*/
285 MathJax.Hub.Config({
286 // Only one of the two following lines, depending on user settings
287 // First allows browser-native MathML display, second forces HTML/CSS
288 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
289 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
290 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
291 \"TeX/noUndefined.js\"],
292 tex2jax: {
293 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
294 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
295 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
296 ignoreClass: \"tex2jax_ignore\",
297 processEscapes: false,
298 processEnvironments: true,
299 preview: \"TeX\"
301 showProcessingMessages: true,
302 displayAlign: \"%ALIGN\",
303 displayIndent: \"%INDENT\",
305 \"HTML-CSS\": {
306 scale: %SCALE,
307 availableFonts: [\"STIX\",\"TeX\"],
308 preferredFont: \"TeX\",
309 webFont: \"TeX\",
310 imageFont: \"TeX\",
311 showMathMenu: true,
313 MMLorHTML: {
314 prefer: {
315 MSIE: \"MML\",
316 Firefox: \"MML\",
317 Opera: \"HTML\",
318 other: \"HTML\"
322 /*]]>*///-->
323 </script>"
324 "The MathJax setup for XHTML files."
325 :group 'org-export-html
326 :type 'string)
328 (defcustom org-export-html-tag-class-prefix ""
329 "Prefix to class names for TODO keywords.
330 Each tag gets a class given by the tag itself, with this prefix.
331 The default prefix is empty because it is nice to just use the keyword
332 as a class name. But if you get into conflicts with other, existing
333 CSS classes, then this prefix can be very useful."
334 :group 'org-export-html
335 :type 'string)
337 (defcustom org-export-html-todo-kwd-class-prefix ""
338 "Prefix to class names for TODO keywords.
339 Each TODO keyword gets a class given by the keyword itself, with this prefix.
340 The default prefix is empty because it is nice to just use the keyword
341 as a class name. But if you get into conflicts with other, existing
342 CSS classes, then this prefix can be very useful."
343 :group 'org-export-html
344 :type 'string)
346 (defcustom org-export-html-preamble t
347 "Non-nil means insert a preamble in HTML export.
349 When `t', insert a string as defined by one of the formatting
350 strings in `org-export-html-preamble-format'. When set to a
351 string, this string overrides `org-export-html-preamble-format'.
352 When set to a function, apply this function and insert the
353 returned string. The function takes the property list of export
354 options as its only argument.
356 Setting :html-preamble in publishing projects will take
357 precedence over this variable."
358 :group 'org-export-html
359 :type '(choice (const :tag "No preamble" nil)
360 (const :tag "Default preamble" t)
361 (string :tag "Custom formatting string")
362 (function :tag "Function (must return a string)")))
364 (defcustom org-export-html-preamble-format
365 '(("en" "<h1 class=\"title\">%t</h1>"))
366 "The format for the HTML preamble.
368 %t stands for the title.
370 If you need to use a \"%\" character, you need to escape it
371 like that: \"%%\"."
372 :group 'org-export-html
373 :type 'string)
375 (defcustom org-export-html-postamble 'auto
376 "Non-nil means insert a postamble in HTML export.
378 When `t', insert a string as defined by the formatting string in
379 `org-export-html-postamble-format'. When set to a string, this
380 string overrides `org-export-html-postamble-format'. When set to
381 'auto, discard `org-export-html-postamble-format' and honor
382 `org-export-author/email/creator-info' variables. When set to a
383 function, apply this function and insert the returned string.
384 The function takes the property list of export options as its
385 only argument.
387 Setting :html-postamble in publishing projects will take
388 precedence over this variable."
389 :group 'org-export-html
390 :type '(choice (const :tag "No postamble" nil)
391 (const :tag "Auto preamble" 'auto)
392 (const :tag "Default formatting string" t)
393 (string :tag "Custom formatting string")
394 (function :tag "Function (must return a string)")))
396 (defcustom org-export-html-postamble-format
397 '(("en" "<p class=\"author\">Author: %a (%e)</p>
398 <p class=\"date\">Date: %d</p>
399 <p class=\"creator\">Generated by %c</p>
400 <p class=\"xhtml-validation\">%v</p>
402 "The format for the HTML postamble.
404 %a stands for the author.
405 %e stands for the email(s).
406 %d stands for the date.
407 %c will be replaced by information about Org/Emacs.
408 %v will be replaced by `org-export-html-validation-link'.
410 If you need to use a \"%\" character, you need to escape it
411 like that: \"%%\"."
412 :group 'org-export-html
413 :type 'string)
415 (defcustom org-export-html-home/up-format
416 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
417 <a accesskey=\"h\" href=\"%s\"> UP </a>
419 <a accesskey=\"H\" href=\"%s\"> HOME </a>
420 </div>"
421 "Snippet used to insert the HOME and UP links.
422 This is a format string, the first %s will receive the UP link,
423 the second the HOME link. If both `org-export-html-link-up' and
424 `org-export-html-link-home' are empty, the entire snippet will be
425 ignored."
426 :group 'org-export-html
427 :type 'string)
429 (defcustom org-export-html-toplevel-hlevel 2
430 "The <H> level for level 1 headings in HTML export.
431 This is also important for the classes that will be wrapped around headlines
432 and outline structure. If this variable is 1, the top-level headlines will
433 be <h1>, and the corresponding classes will be outline-1, section-number-1,
434 and outline-text-1. If this is 2, all of these will get a 2 instead.
435 The default for this variable is 2, because we use <h1> for formatting the
436 document title."
437 :group 'org-export-html
438 :type 'string)
440 (defcustom org-export-html-link-org-files-as-html t
441 "Non-nil means make file links to `file.org' point to `file.html'.
442 When org-mode is exporting an org-mode file to HTML, links to
443 non-html files are directly put into a href tag in HTML.
444 However, links to other Org-mode files (recognized by the
445 extension `.org.) should become links to the corresponding html
446 file, assuming that the linked org-mode file will also be
447 converted to HTML.
448 When nil, the links still point to the plain `.org' file."
449 :group 'org-export-html
450 :type 'boolean)
452 (defcustom org-export-html-inline-images 'maybe
453 "Non-nil means inline images into exported HTML pages.
454 This is done using an <img> tag. When nil, an anchor with href is used to
455 link to the image. If this option is `maybe', then images in links with
456 an empty description will be inlined, while images with a description will
457 be linked only."
458 :group 'org-export-html
459 :type '(choice (const :tag "Never" nil)
460 (const :tag "Always" t)
461 (const :tag "When there is no description" maybe)))
463 (defcustom org-export-html-inline-image-extensions
464 '("png" "jpeg" "jpg" "gif" "svg")
465 "Extensions of image files that can be inlined into HTML."
466 :group 'org-export-html
467 :type '(repeat (string :tag "Extension")))
469 (defcustom org-export-html-table-tag
470 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
471 "The HTML tag that is used to start a table.
472 This must be a <table> tag, but you may change the options like
473 borders and spacing."
474 :group 'org-export-html
475 :type 'string)
477 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
478 "The opening tag for table header fields.
479 This is customizable so that alignment options can be specified.
480 The first %s will be filled with the scope of the field, either row or col.
481 The second %s will be replaced by a style entry to align the field.
482 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
483 See also the variable `org-export-html-table-align-individual-fields'."
484 :group 'org-export-tables
485 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
487 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
488 "The opening tag for table data fields.
489 This is customizable so that alignment options can be specified.
490 The first %s will be filled with the scope of the field, either row or col.
491 The second %s will be replaced by a style entry to align the field.
492 See also the variable `org-export-html-table-align-individual-fields'."
493 :group 'org-export-tables
494 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
496 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
497 "The opening tag for table data fields.
498 This is customizable so that alignment options can be specified.
499 Instead of strings, these can be Lisp forms that will be evaluated
500 for each row in order to construct the table row tags. During evaluation,
501 the variable `head' will be true when this is a header line, nil when this
502 is a body line. And the variable `nline' will contain the line number,
503 starting from 1 in the first header line. For example
505 (setq org-export-table-row-tags
506 (cons '(if head
507 \"<tr>\"
508 (if (= (mod nline 2) 1)
509 \"<tr class=\\\"tr-odd\\\">\"
510 \"<tr class=\\\"tr-even\\\">\"))
511 \"</tr>\"))
513 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
514 :group 'org-export-tables
515 :type '(cons
516 (choice :tag "Opening tag"
517 (string :tag "Specify")
518 (sexp))
519 (choice :tag "Closing tag"
520 (string :tag "Specify")
521 (sexp))))
523 (defcustom org-export-html-table-align-individual-fields t
524 "Non-nil means attach style attributes for alignment to each table field.
525 When nil, alignment will only be specified in the column tags, but this
526 is ignored by some browsers (like Firefox, Safari). Opera does it right
527 though."
528 :group 'org-export-tables
529 :type 'boolean)
531 (defcustom org-export-html-table-use-header-tags-for-first-column nil
532 "Non-nil means format column one in tables with header tags.
533 When nil, also column one will use data tags."
534 :group 'org-export-tables
535 :type 'boolean)
537 (defcustom org-export-html-validation-link
538 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
539 "Link to HTML validation service."
540 :group 'org-export-html
541 :type 'string)
543 (defcustom org-export-html-with-timestamp nil
544 "If non-nil, write timestamp into the exported HTML text.
545 If non-nil, write `org-export-html-html-helper-timestamp' into the
546 exported HTML text. Otherwise, the buffer will just be saved to
547 a file."
548 :group 'org-export-html
549 :type 'boolean)
551 (defcustom org-export-html-html-helper-timestamp
552 "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
553 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
554 :group 'org-export-html
555 :type 'string)
557 (defcustom org-export-html-protect-char-alist
558 '(("&" . "&amp;")
559 ("<" . "&lt;")
560 (">" . "&gt;"))
561 "Alist of characters to be converted by `org-html-protect'."
562 :type '(repeat (cons (string :tag "Character")
563 (string :tag "HTML equivalent"))))
565 (defgroup org-export-htmlize nil
566 "Options for processing examples with htmlize.el."
567 :tag "Org Export Htmlize"
568 :group 'org-export-html)
570 (defcustom org-export-htmlize-output-type 'inline-css
571 "Output type to be used by htmlize when formatting code snippets.
572 Choices are `css', to export the CSS selectors only, or `inline-css', to
573 export the CSS attribute values inline in the HTML. We use as default
574 `inline-css', in order to make the resulting HTML self-containing.
576 However, this will fail when using Emacs in batch mode for export, because
577 then no rich font definitions are in place. It will also not be good if
578 people with different Emacs setup contribute HTML files to a website,
579 because the fonts will represent the individual setups. In these cases,
580 it is much better to let Org/Htmlize assign classes only, and to use
581 a style file to define the look of these classes.
582 To get a start for your css file, start Emacs session and make sure that
583 all the faces you are interested in are defined, for example by loading files
584 in all modes you want. Then, use the command
585 \\[org-export-htmlize-generate-css] to extract class definitions."
586 :group 'org-export-htmlize
587 :type '(choice (const css) (const inline-css)))
589 (defcustom org-export-htmlize-css-font-prefix "org-"
590 "The prefix for CSS class names for htmlize font specifications."
591 :group 'org-export-htmlize
592 :type 'string)
594 (defcustom org-export-htmlized-org-css-url nil
595 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
596 Normally when creating an htmlized version of an Org buffer, htmlize will
597 create CSS to define the font colors. However, this does not work when
598 converting in batch mode, and it also can look bad if different people
599 with different fontification setup work on the same website.
600 When this variable is non-nil, creating an htmlized version of an Org buffer
601 using `org-export-as-org' will remove the internal CSS section and replace it
602 with a link to this URL."
603 :group 'org-export-htmlize
604 :type '(choice
605 (const :tag "Keep internal css" nil)
606 (string :tag "URL or local href")))
608 ;;; Hooks
610 (defvar org-export-html-after-blockquotes-hook nil
611 "Hook run during HTML export, after blockquote, verse, center are done.")
613 (defvar org-export-html-final-hook nil
614 "Hook run at the end of HTML export, in the new buffer.")
616 ;;; HTML export
618 (defun org-export-html-preprocess (parameters)
619 "Convert LaTeX fragments to images."
620 (when (and org-current-export-file
621 (plist-get parameters :LaTeX-fragments))
622 (org-format-latex
623 (concat "ltxpng/" (file-name-sans-extension
624 (file-name-nondirectory
625 org-current-export-file)))
626 org-current-export-dir nil "Creating LaTeX image %s"
627 nil nil
628 (cond
629 ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
630 ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
631 ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
632 ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
633 (t nil))))
634 (goto-char (point-min))
635 (let (label l1)
636 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
637 (org-if-unprotected-at (match-beginning 1)
638 (setq label (match-string 1))
639 (save-match-data
640 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
641 (setq l1 (substring label (match-beginning 1)))
642 (setq l1 label)))
643 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
645 ;;;###autoload
646 (defun org-export-as-html-and-open (arg)
647 "Export the outline as HTML and immediately open it with a browser.
648 If there is an active region, export only the region.
649 The prefix ARG specifies how many levels of the outline should become
650 headlines. The default is 3. Lower levels will become bulleted lists."
651 (interactive "P")
652 (org-export-as-html arg 'hidden)
653 (org-open-file buffer-file-name)
654 (when org-export-kill-product-buffer-when-displayed
655 (kill-buffer (current-buffer))))
657 ;;;###autoload
658 (defun org-export-as-html-batch ()
659 "Call the function `org-export-as-html'.
660 This function can be used in batch processing as:
661 emacs --batch
662 --load=$HOME/lib/emacs/org.el
663 --eval \"(setq org-export-headline-levels 2)\"
664 --visit=MyFile --funcall org-export-as-html-batch"
665 (org-export-as-html org-export-headline-levels 'hidden))
667 ;;;###autoload
668 (defun org-export-as-html-to-buffer (arg)
669 "Call `org-export-as-html` with output to a temporary buffer.
670 No file is created. The prefix ARG is passed through to `org-export-as-html'."
671 (interactive "P")
672 (org-export-as-html arg nil nil "*Org HTML Export*")
673 (when org-export-show-temporary-export-buffer
674 (switch-to-buffer-other-window "*Org HTML Export*")))
676 ;;;###autoload
677 (defun org-replace-region-by-html (beg end)
678 "Assume the current region has org-mode syntax, and convert it to HTML.
679 This can be used in any buffer. For example, you could write an
680 itemized list in org-mode syntax in an HTML buffer and then use this
681 command to convert it."
682 (interactive "r")
683 (let (reg html buf pop-up-frames)
684 (save-window-excursion
685 (if (org-mode-p)
686 (setq html (org-export-region-as-html
687 beg end t 'string))
688 (setq reg (buffer-substring beg end)
689 buf (get-buffer-create "*Org tmp*"))
690 (with-current-buffer buf
691 (erase-buffer)
692 (insert reg)
693 (org-mode)
694 (setq html (org-export-region-as-html
695 (point-min) (point-max) t 'string)))
696 (kill-buffer buf)))
697 (delete-region beg end)
698 (insert html)))
700 ;;;###autoload
701 (defun org-export-region-as-html (beg end &optional body-only buffer)
702 "Convert region from BEG to END in org-mode buffer to HTML.
703 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
704 contents, and only produce the region of converted text, useful for
705 cut-and-paste operations.
706 If BUFFER is a buffer or a string, use/create that buffer as a target
707 of the converted HTML. If BUFFER is the symbol `string', return the
708 produced HTML as a string and leave not buffer behind. For example,
709 a Lisp program could call this function in the following way:
711 (setq html (org-export-region-as-html beg end t 'string))
713 When called interactively, the output buffer is selected, and shown
714 in a window. A non-interactive call will only return the buffer."
715 (interactive "r\nP")
716 (when (interactive-p)
717 (setq buffer "*Org HTML Export*"))
718 (let ((transient-mark-mode t) (zmacs-regions t)
719 ext-plist rtn)
720 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
721 (goto-char end)
722 (set-mark (point)) ;; to activate the region
723 (goto-char beg)
724 (setq rtn (org-export-as-html
725 nil nil ext-plist
726 buffer body-only))
727 (if (fboundp 'deactivate-mark) (deactivate-mark))
728 (if (and (interactive-p) (bufferp rtn))
729 (switch-to-buffer-other-window rtn)
730 rtn)))
732 (defvar html-table-tag nil) ; dynamically scoped into this.
733 (defvar org-par-open nil)
735 ;;; org-html-cvt-link-fn
736 (defconst org-html-cvt-link-fn
738 "Function to convert link URLs to exportable URLs.
739 Takes two arguments, TYPE and PATH.
740 Returns exportable url as (TYPE PATH), or nil to signal that it
741 didn't handle this case.
742 Intended to be locally bound around a call to `org-export-as-html'." )
744 (defun org-html-cvt-org-as-html (opt-plist type path)
745 "Convert an org filename to an equivalent html filename.
746 If TYPE is not file, just return `nil'.
747 See variable `org-export-html-link-org-files-as-html'"
749 (save-match-data
750 (and
751 org-export-html-link-org-files-as-html
752 (string= type "file")
753 (string-match "\\.org$" path)
754 (progn
755 (list
756 "file"
757 (concat
758 (substring path 0 (match-beginning 0))
760 (plist-get opt-plist :html-extension)))))))
763 ;;; org-html-should-inline-p
764 (defun org-html-should-inline-p (filename descp)
765 "Return non-nil if link FILENAME should be inlined.
766 The decision to inline the FILENAME link is based on the current
767 settings. DESCP is the boolean of whether there was a link
768 description. See variables `org-export-html-inline-images' and
769 `org-export-html-inline-image-extensions'."
770 (declare (special
771 org-export-html-inline-images
772 org-export-html-inline-image-extensions))
773 (and (or (eq t org-export-html-inline-images)
774 (and org-export-html-inline-images (not descp)))
775 (org-file-image-p
776 filename org-export-html-inline-image-extensions)))
778 ;;; org-html-format-org-link
779 (defun org-html-format-org-link (opt-plist type-1 path fragment desc attr
780 descp)
781 "Make an HTML link.
782 OPT-PLIST is an options list.
783 TYPE is the device-type of the link (THIS://foo.html)
784 PATH is the path of the link (http://THIS#locationx)
785 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
786 DESC is the link description, if any.
787 ATTR is a string of other attributes of the a element.
788 MAY-INLINE-P allows inlining it as an image."
790 (declare (special org-par-open))
791 (save-match-data
792 (let* ((may-inline-p
793 (and (member type-1 '("http" "https" "file"))
794 (org-html-should-inline-p path descp)
795 (not fragment)))
796 (type (if (equal type-1 "id") "file" type-1))
797 (filename path)
798 ;;First pass. Just sanity stuff.
799 (components-1
800 (cond
801 ((string= type "file")
802 (list
803 type
804 ;;Substitute just if original path was absolute.
805 ;;(Otherwise path must remain relative)
806 (if (file-name-absolute-p path)
807 (concat "file://" (expand-file-name path))
808 path)))
809 ((string= type "")
810 (list nil path))
811 (t (list type path))))
813 ;;Second pass. Components converted so they can refer
814 ;;to a remote site.
815 (components-2
817 (and org-html-cvt-link-fn
818 (apply org-html-cvt-link-fn
819 opt-plist components-1))
820 (apply #'org-html-cvt-org-as-html
821 opt-plist components-1)
822 components-1))
823 (type (first components-2))
824 (thefile (second components-2)))
827 ;;Third pass. Build final link except for leading type
828 ;;spec.
829 (cond
830 ((or
831 (not type)
832 (string= type "http")
833 (string= type "https")
834 (string= type "file"))
835 (if fragment
836 (setq thefile (concat thefile "#" fragment))))
838 (t))
840 ;;Final URL-build, for all types.
841 (setq thefile
842 (let
843 ((str (org-export-html-format-href thefile)))
844 (if (and type (not (string= "file" type)))
845 (concat type ":" str)
846 str)))
848 (if may-inline-p
849 (org-export-html-format-image thefile)
850 (org-parse-format
851 'LINK (org-export-html-format-desc desc) thefile attr)))))
853 (defun org-html-format-inline-image (desc)
854 ;; FIXME: alt text missing here?
855 (org-html-format-tags '("<img src=\"%s\" alt=\"\">" . "</img>") "" desc))
857 (defvar org-parse-link-description-is-image)
858 (defun org-parse-format-org-link (line opt-plist)
859 "Return LINE with markup of Org mode links.
860 OPT-PLIST is the export options list."
861 (let ((start 0)
862 (current-dir (if buffer-file-name
863 (file-name-directory buffer-file-name)
864 default-directory))
865 (link-validate (plist-get opt-plist :link-validation-function))
866 type id-file fnc
867 rpl path attr desc descp desc1 desc2 link
868 org-parse-link-description-is-image)
869 (while (string-match org-bracket-link-analytic-regexp++ line start)
870 (setq org-parse-link-description-is-image nil)
871 (setq start (match-beginning 0))
872 (setq path (save-match-data (org-link-unescape
873 (match-string 3 line))))
874 (setq type (cond
875 ((match-end 2) (match-string 2 line))
876 ((save-match-data
877 (or (file-name-absolute-p path)
878 (string-match "^\\.\\.?/" path)))
879 "file")
880 (t "internal")))
881 (setq path (org-extract-attributes (org-link-unescape path)))
882 (setq attr (get-text-property 0 'org-attributes path))
883 (setq desc1 (if (match-end 5) (match-string 5 line))
884 desc2 (if (match-end 2) (concat type ":" path) path)
885 descp (and desc1 (not (equal desc1 desc2)))
886 desc (or desc1 desc2))
887 ;; Make an image out of the description if that is so wanted
888 (when (and descp (org-file-image-p
889 desc org-export-html-inline-image-extensions))
890 (setq org-parse-link-description-is-image t)
891 (save-match-data
892 (if (string-match "^file:" desc)
893 (setq desc (substring desc (match-end 0)))))
894 (save-match-data
895 (setq desc (org-add-props
896 (org-parse-format 'INLINE-IMAGE desc)
897 '(org-protected t)))))
898 (cond
899 ((equal type "internal")
900 (let
901 ((frag-0
902 (if (= (string-to-char path) ?#)
903 (substring path 1)
904 path)))
905 (setq rpl
906 (org-parse-format
907 'ORG-LINK opt-plist "" "" (org-solidify-link-text
908 (save-match-data
909 (org-link-unescape frag-0))
910 nil) desc attr descp))))
911 ((and (equal type "id")
912 (setq id-file (org-id-find-id-file path)))
913 ;; This is an id: link to another file (if it was the same file,
914 ;; it would have become an internal link...)
915 (save-match-data
916 (setq id-file (file-relative-name
917 id-file
918 (file-name-directory org-current-export-file)))
919 (setq rpl
920 (org-parse-format
921 'ORG-LINK opt-plist type id-file
922 (concat (if (org-uuidgen-p path) "ID-") path)
923 desc attr descp))))
924 ((member type '("http" "https"))
925 ;; standard URL, can inline as image
926 (setq rpl
927 (org-parse-format
928 'ORG-LINK opt-plist type path nil desc attr descp)))
929 ((member type '("ftp" "mailto" "news"))
930 ;; standard URL, can't inline as image
931 (setq rpl
932 (org-parse-format
933 'ORG-LINK opt-plist type path nil desc attr descp)))
935 ((string= type "coderef")
936 (let*
937 ((coderef-str (format "coderef-%s" path))
938 (attr-1
939 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
940 coderef-str coderef-str)))
941 (setq rpl
942 (org-parse-format
943 'ORG-LINK opt-plist type "" coderef-str
944 (format
945 (org-export-get-coderef-format
946 path
947 (and descp desc))
948 (cdr (assoc path org-export-code-refs))) attr-1 descp))))
950 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
951 ;; The link protocol has a function for format the link
952 (setq rpl
953 (save-match-data
954 (funcall fnc (org-link-unescape path) desc1 'html))))
956 ((string= type "file")
957 ;; FILE link
958 (save-match-data
959 (let*
960 ((components
962 (string-match "::\\(.*\\)" path)
963 (list
964 (replace-match "" t nil path)
965 (match-string 1 path))
966 (list path nil)))
968 ;;The proper path, without a fragment
969 (path-1
970 (first components))
972 ;;The raw fragment
973 (fragment-0
974 (second components))
976 ;;Check the fragment. If it can't be used as
977 ;;target fragment we'll pass nil instead.
978 (fragment-1
980 (and fragment-0
981 (not (string-match "^[0-9]*$" fragment-0))
982 (not (string-match "^\\*" fragment-0))
983 (not (string-match "^/.*/$" fragment-0)))
984 (org-solidify-link-text
985 (org-link-unescape fragment-0))
986 nil))
987 (desc-2
988 ;;Description minus "file:" and ".org"
989 (if (string-match "^file:" desc)
990 (let
991 ((desc-1 (replace-match "" t t desc)))
992 (if (string-match "\\.org$" desc-1)
993 (replace-match "" t t desc-1)
994 desc-1))
995 desc)))
997 (setq rpl
999 (and
1000 (functionp link-validate)
1001 (not (funcall link-validate path-1 current-dir)))
1002 desc
1003 (org-parse-format
1004 'ORG-LINK opt-plist "file" path-1 fragment-1
1005 desc-2 attr descp))))))
1008 ;; just publish the path, as default
1009 (setq rpl (concat "<i>&lt;" type ":"
1010 (save-match-data (org-link-unescape path))
1011 "&gt;</i>"))))
1012 (setq line (replace-match rpl t t line)
1013 start (+ start (length rpl))))
1014 line))
1016 (defmacro with-org-parse-preserve-paragraph-state (&rest body)
1017 `(let ((org-do-open-par org-par-open))
1018 (org-parse-end-paragraph)
1019 ,@body
1020 (when org-do-open-par
1021 (org-parse-begin-paragraph))))
1023 ;;; org-export-as-html
1024 ;;;###autoload
1025 (defun org-export-as-html (arg &optional hidden ext-plist
1026 to-buffer body-only pub-dir)
1027 "Export the outline as a pretty HTML file.
1028 If there is an active region, export only the region. The prefix
1029 ARG specifies how many levels of the outline should become
1030 headlines. The default is 3. Lower levels will become bulleted
1031 lists. HIDDEN is obsolete and does nothing.
1032 EXT-PLIST is a property list with external parameters overriding
1033 org-mode's default settings, but still inferior to file-local
1034 settings. When TO-BUFFER is non-nil, create a buffer with that
1035 name and export to that buffer. If TO-BUFFER is the symbol
1036 `string', don't leave any buffer behind but just return the
1037 resulting HTML as a string. When BODY-ONLY is set, don't produce
1038 the file header and footer, simply return the content of
1039 <body>...</body>, without even the body tags themselves. When
1040 PUB-DIR is set, use this as the publishing directory."
1041 (interactive "P")
1042 (run-hooks 'org-export-first-hook)
1044 (let* ((org-parse-get-callback 'org-html-get))
1045 (org-do-export arg hidden ext-plist to-buffer body-only pub-dir)))
1047 ;; Following variables are let-bound while `org-do-export' is in
1048 ;; progress
1049 (defvar org-html-dyn-first-heading-pos)
1050 (defvar org-parse-table-of-contents)
1051 (defvar org-parse-entity-control-callbacks-alist)
1052 (defvar org-parse-entity-format-callbacks-alist)
1053 (defvar org-parse-get-callback)
1055 (defun org-do-export (arg &optional hidden ext-plist
1056 to-buffer body-only pub-dir)
1057 "Export the outline as a pretty HTML file."
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* (org-html-protect org-par-open
1073 (org-parse-entity-control-callbacks-alist
1074 (org-parse-get 'ENTITY-CONTROL))
1075 (org-parse-entity-format-callbacks-alist
1076 (org-parse-get 'ENTITY-FORMAT))
1077 (opt-plist
1078 (org-export-process-option-filters
1079 (org-combine-plists (org-default-export-plist)
1080 ext-plist
1081 (org-infile-export-plist))))
1082 (body-only (or body-only (plist-get opt-plist :body-only)))
1083 valid org-html-dyn-first-heading-pos
1084 (odd org-odd-levels-only)
1085 (region-p (org-region-active-p))
1086 (rbeg (and region-p (region-beginning)))
1087 (rend (and region-p (region-end)))
1088 (subtree-p
1089 (if (plist-get opt-plist :ignore-subtree-p)
1091 (when region-p
1092 (save-excursion
1093 (goto-char rbeg)
1094 (and (org-at-heading-p)
1095 (>= (org-end-of-subtree t t) rend))))))
1096 (level-offset (if subtree-p
1097 (save-excursion
1098 (goto-char rbeg)
1099 (+ (funcall outline-level)
1100 (if org-odd-levels-only 1 0)))
1102 (opt-plist (setq org-export-opt-plist
1103 (if subtree-p
1104 (org-export-add-subtree-options opt-plist rbeg)
1105 opt-plist)))
1106 ;; The following two are dynamically scoped into other
1107 ;; routines below.
1108 (org-current-export-dir
1109 (or pub-dir (org-parse-get 'EXPORT-DIR opt-plist)))
1110 (org-current-export-file buffer-file-name)
1111 (level 0) (line "") (origline "") txt todo
1112 (umax nil)
1113 (umax-toc nil)
1114 (filename (if to-buffer nil
1115 (expand-file-name
1116 (concat
1117 (file-name-sans-extension
1118 (or (and subtree-p
1119 (org-entry-get (region-beginning)
1120 "EXPORT_FILE_NAME" t))
1121 (file-name-nondirectory buffer-file-name)))
1122 "." (org-parse-get 'FILE-NAME-EXTENSION opt-plist))
1123 (file-name-as-directory
1124 (or pub-dir (org-parse-get 'EXPORT-DIR opt-plist))))))
1125 (current-dir (if buffer-file-name
1126 (file-name-directory buffer-file-name)
1127 default-directory))
1128 (buffer (if to-buffer
1129 (cond
1130 ((eq to-buffer 'string)
1131 (get-buffer-create (org-parse-get 'EXPORT-BUFFER-NAME)))
1132 (t (get-buffer-create to-buffer)))
1133 (find-file-noselect
1134 (or (let ((f (org-parse-get 'INIT-METHOD)))
1135 (and f (functionp f) (funcall f filename)))
1136 filename))))
1137 (org-levels-open (make-vector org-level-max nil))
1138 (date (plist-get opt-plist :date))
1139 (date (cond
1140 ((and date (string-match "%" date))
1141 (format-time-string date))
1142 (date date)
1143 (t (format-time-string "%Y-%m-%d %T %Z"))))
1144 (dummy (setq opt-plist (plist-put opt-plist :effective-date date)))
1145 (title (org-html-expand
1146 (or (and subtree-p (org-export-get-title-from-subtree))
1147 (plist-get opt-plist :title)
1148 (and (not body-only)
1149 (not
1150 (plist-get opt-plist :skip-before-1st-heading))
1151 (org-export-grab-title-from-buffer))
1152 (and buffer-file-name
1153 (file-name-sans-extension
1154 (file-name-nondirectory buffer-file-name)))
1155 "UNTITLED")))
1156 (dummy (setq opt-plist (plist-put opt-plist :title title)))
1157 (html-table-tag (plist-get opt-plist :html-table-tag))
1158 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1159 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
1160 (org-parse-dyn-current-environment nil)
1161 ;; Get the language-dependent settings
1162 (lang-words (or (assoc (plist-get opt-plist :language)
1163 org-export-language-setup)
1164 (assoc "en" org-export-language-setup)))
1165 (dummy (setq opt-plist (plist-put opt-plist :lang-words lang-words)))
1166 (head-count 0) cnt
1167 (start 0)
1168 (coding-system-for-write (org-html-get-coding-system-for-write))
1169 (save-buffer-coding-system (org-html-get-coding-system-for-save))
1170 (region
1171 (buffer-substring
1172 (if region-p (region-beginning) (point-min))
1173 (if region-p (region-end) (point-max))))
1174 (org-export-have-math nil)
1175 (insertion-point-for-normalized-footnotes 'point-min)
1176 (org-parse-backend (org-parse-get 'BACKEND))
1177 (lines
1178 (org-split-string
1179 (org-export-preprocess-string
1180 region
1181 :emph-multiline t
1182 :for-backend org-parse-backend
1183 :skip-before-1st-heading
1184 (plist-get opt-plist :skip-before-1st-heading)
1185 :drawers (plist-get opt-plist :drawers)
1186 :todo-keywords (plist-get opt-plist :todo-keywords)
1187 :tags (plist-get opt-plist :tags)
1188 :priority (plist-get opt-plist :priority)
1189 :footnotes (plist-get opt-plist :footnotes)
1190 :timestamps (plist-get opt-plist :timestamps)
1191 :archived-trees
1192 (plist-get opt-plist :archived-trees)
1193 :select-tags (plist-get opt-plist :select-tags)
1194 :exclude-tags (plist-get opt-plist :exclude-tags)
1195 :add-text
1196 (plist-get opt-plist :text)
1197 :LaTeX-fragments
1198 (plist-get opt-plist :LaTeX-fragments))
1199 "[\r\n]"))
1200 table-open
1201 table-buffer table-orig-buffer
1203 rpl path attr desc descp desc1 desc2 link
1204 snumber fnc
1205 footnotes footref-seen
1206 org-html-output-buffer
1207 org-html-footnote-definitions
1208 org-html-footnote-number
1209 org-html-footnote-buffer
1210 org-parse-table-of-contents
1211 href
1214 (let ((inhibit-read-only t))
1215 (org-unmodified
1216 (remove-text-properties (point-min) (point-max)
1217 '(:org-license-to-kill t))))
1219 (message "Exporting...")
1220 (org-init-section-numbers)
1222 ;; Switch to the output buffer
1223 (setq org-html-output-buffer buffer)
1224 (set-buffer org-html-output-buffer)
1225 (let ((inhibit-read-only t)) (erase-buffer))
1226 (fundamental-mode)
1227 (org-install-letbind)
1229 (and (fboundp 'set-buffer-file-coding-system)
1230 (set-buffer-file-coding-system coding-system-for-write))
1232 (let ((case-fold-search nil)
1233 (org-odd-levels-only odd))
1234 ;; create local variables for all options, to make sure all called
1235 ;; functions get the correct information
1236 (mapc (lambda (x)
1237 (set (make-local-variable (nth 2 x))
1238 (plist-get opt-plist (car x))))
1239 org-export-plist-vars)
1240 (setq umax (if arg (prefix-numeric-value arg)
1241 org-export-headline-levels))
1242 (setq umax-toc (if (integerp org-export-with-toc)
1243 (min org-export-with-toc umax)
1244 umax))
1246 (when (and org-export-with-toc (not body-only))
1247 (setq lines (org-html-prepare-toc
1248 lines level-offset opt-plist umax-toc)))
1250 (unless body-only
1251 (org-parse-begin 'DOCUMENT-CONTENT opt-plist)
1252 (org-parse-begin 'DOCUMENT-BODY opt-plist))
1254 (setq head-count 0)
1255 (org-init-section-numbers)
1257 (org-parse-begin-paragraph)
1259 (while (setq line (pop lines) origline line)
1260 (catch 'nextline
1261 (when (and (org-parse-current-environment-p 'quote)
1262 (string-match "^\\*+ " line))
1263 (org-parse-end-environment 'quote))
1265 (when (org-parse-current-environment-p 'quote)
1266 (insert (org-parse-format 'PLAIN line))
1267 (throw 'nextline nil))
1269 ;; Fixed-width, verbatim lines (examples)
1270 (when (and org-export-with-fixed-width
1271 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
1272 (when (not (org-parse-current-environment-p 'fixedwidth))
1273 (org-parse-begin-environment 'fixedwidth))
1274 (insert (org-parse-format 'PLAIN (match-string 3 line)))
1275 (when (or (not lines)
1276 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1277 (car lines))))
1278 (org-parse-end-environment 'fixedwidth))
1279 (throw 'nextline nil))
1281 ;; Protected HTML
1282 (when (and (get-text-property 0 'org-protected line)
1283 ;; Make sure it is the entire line that is protected
1284 (not (< (or (next-single-property-change
1285 0 'org-protected line) 10000)
1286 (length line))))
1287 (let ((ind (get-text-property 0 'original-indentation line)))
1288 (with-org-parse-preserve-paragraph-state
1289 (insert (org-parse-format 'PLAIN line))
1290 (while (and lines
1291 (or (= (length (car lines)) 0)
1292 (not ind)
1293 (equal ind (get-text-property
1294 0 'original-indentation (car lines))))
1295 (or (= (length (car lines)) 0)
1296 (get-text-property 0 'org-protected (car lines))))
1297 (insert (org-parse-format 'PLAIN (pop lines))))))
1298 (throw 'nextline nil))
1300 ;; Blockquotes, verse, and center
1301 (when (string-match "^ORG-\\(.+\\)-\\(START\\|END\\)$" line)
1302 (let* ((style (intern (downcase (match-string 1 line))))
1303 (f (cdr (assoc (match-string 2 line)
1304 '(("START" . org-parse-begin-environment)
1305 ("END" . org-parse-end-environment))))))
1306 (when (memq style '(blockquote verse center))
1307 (funcall f style)
1308 (throw 'nextline nil))))
1310 (run-hooks 'org-export-html-after-blockquotes-hook)
1311 (when (org-parse-current-environment-p 'verse)
1312 (let ((i (org-get-string-indentation line)))
1313 (if (> i 0)
1314 (setq line (concat
1315 (let ((org-html-protect t))
1316 (org-parse-format 'SPACES (* 2 i)))
1317 " " (org-trim line))))
1318 (unless (string-match "\\\\\\\\[ \t]*$" line)
1319 (setq line (concat line "\\\\")))))
1321 ;; make targets to anchors
1322 (setq start 0)
1323 (while (string-match
1324 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1325 (cond
1326 ((get-text-property (match-beginning 1) 'org-protected line)
1327 (setq start (match-end 1)))
1328 ((match-end 2)
1329 (setq line (replace-match
1330 (let ((org-html-protect t))
1331 (org-parse-format
1332 'ANCHOR "" (org-solidify-link-text
1333 (match-string 1 line))))
1334 t t line)))
1335 ((and org-export-with-toc (equal (string-to-char line) ?*))
1336 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1337 (setq line (replace-match
1338 (let ((org-html-protect t))
1339 (org-parse-format
1340 'FONTIFY (match-string 1 line) "target"))
1341 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1342 t t line)))
1344 (setq line (replace-match
1345 (concat
1346 (let ((org-html-protect t))
1347 (org-parse-format
1348 'ANCHOR (match-string 1 line)
1349 (org-solidify-link-text (match-string 1 line))
1350 "target")) " ")
1351 t t line)))))
1353 (let ((org-html-protect t))
1354 (setq line (org-html-handle-time-stamps line)))
1356 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1357 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
1358 ;; Also handle sub_superscripts and checkboxes
1359 (or (string-match org-table-hline-regexp line)
1360 (setq line (org-html-expand line)))
1362 (setq line (org-parse-format-org-link line opt-plist))
1364 ;; TODO items
1365 (if (and (string-match org-todo-line-regexp line)
1366 (match-beginning 2))
1367 (setq line (concat
1368 (substring line 0 (match-beginning 2))
1369 (org-parse-format 'TODO (match-string 2 line))
1370 (substring line (match-end 2)))))
1372 ;; Does this contain a reference to a footnote?
1373 (when org-export-with-footnotes
1374 (setq start 0)
1375 (while (string-match "\\([^* \t].*?\\)[ \t]*\\[\\([0-9]+\\)\\]" line start)
1376 (if (get-text-property (match-beginning 2) 'org-protected line)
1377 (setq start (match-end 2))
1378 (let ((n (match-string 2 line)) refcnt a)
1379 (if (setq a (assoc n footref-seen))
1380 (progn
1381 (setcdr a (1+ (cdr a)))
1382 (setq refcnt (cdr a)))
1383 (setq refcnt 1)
1384 (push (cons n 1) footref-seen))
1385 (setq line
1386 (replace-match
1387 (concat
1388 (or (match-string 1 line) "")
1389 (org-parse-format
1390 'FOOTNOTE-REFERENCE
1391 n (cdr (assoc n org-html-footnote-definitions))
1392 refcnt))
1393 t t line))))))
1395 (cond
1396 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1397 ;; This is a headline
1398 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1399 level-offset))
1400 txt (match-string 2 line))
1401 (if (string-match quote-re0 txt)
1402 (setq txt (replace-match "" t t txt)))
1403 (if (<= level (max umax umax-toc))
1404 (setq head-count (+ head-count 1)))
1405 (unless org-html-dyn-first-heading-pos
1406 (setq org-html-dyn-first-heading-pos (point)))
1407 (org-parse-begin 'LEVEL level txt umax
1408 (and org-export-with-toc (<= level umax))
1409 head-count)
1411 ;; QUOTES
1412 (when (string-match quote-re line)
1413 (org-parse-begin-environment 'quote)))
1415 ((and org-export-with-tables
1416 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1417 (when (not table-open)
1418 ;; New table starts
1419 (setq table-open t table-buffer nil table-orig-buffer nil))
1421 ;; Accumulate lines
1422 (setq table-buffer (cons line table-buffer)
1423 table-orig-buffer (cons origline table-orig-buffer))
1424 (when (or (not lines)
1425 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1426 (car lines))))
1427 (setq table-open nil
1428 table-buffer (nreverse table-buffer)
1429 table-orig-buffer (nreverse table-orig-buffer))
1430 (org-parse-end-paragraph)
1431 (insert (org-format-table-html table-buffer table-orig-buffer))))
1433 ;; Normal lines
1436 ;; This line either is list item or end a list.
1437 (when (get-text-property 0 'list-item line)
1438 (setq line (org-html-export-list-line
1439 line
1440 (get-text-property 0 'list-item line)
1441 (get-text-property 0 'list-struct line)
1442 (get-text-property 0 'list-prevs line))))
1444 ;; Horizontal line
1445 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1446 (with-org-parse-preserve-paragraph-state
1447 (insert (org-parse-format 'HORIZONTAL-LINE)))
1448 (throw 'nextline nil))
1450 ;; Empty lines start a new paragraph. If hand-formatted lists
1451 ;; are not fully interpreted, lines starting with "-", "+", "*"
1452 ;; also start a new paragraph.
1453 (when (string-match "^ [-+*]-\\|^[ \t]*$" line)
1454 (when org-html-footnote-number
1455 (org-parse-end-footnote-definition org-html-footnote-number)
1456 (setq org-html-footnote-number nil))
1457 (org-parse-begin-paragraph))
1459 ;; Is this the start of a footnote?
1460 (when org-export-with-footnotes
1461 (when (and (boundp 'footnote-section-tag-regexp)
1462 (string-match (concat "^" footnote-section-tag-regexp)
1463 line))
1464 ;; ignore this line
1465 (throw 'nextline nil))
1466 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1467 (org-parse-end-paragraph)
1468 (setq org-html-footnote-number (match-string 1 line))
1469 (setq line (replace-match "" t t line))
1470 (org-parse-begin-footnote-definition org-html-footnote-number)))
1471 ;; Check if the line break needs to be conserved
1472 (cond
1473 ((string-match "\\\\\\\\[ \t]*$" line)
1474 (setq line (replace-match
1475 (org-parse-format 'LINE-BREAK)
1476 t t line)))
1477 (org-export-preserve-breaks
1478 (setq line (concat line (org-parse-format 'LINE-BREAK)))))
1480 ;; Check if a paragraph should be started
1481 (let ((start 0))
1482 (while (and org-par-open
1483 (string-match "\\\\par\\>" line start))
1484 (error "FIXME")
1485 ;; Leave a space in the </p> so that the footnote matcher
1486 ;; does not see this.
1487 (if (not (get-text-property (match-beginning 0)
1488 'org-protected line))
1489 (setq line (replace-match "</p ><p >" t t line)))
1490 (setq start (match-end 0))))
1492 (insert (org-parse-format 'PLAIN line))))))
1494 ;; Properly close all local lists and other lists
1495 (when (org-parse-current-environment-p 'quote)
1496 (org-parse-end-environment 'quote))
1498 (org-parse-end 'LEVEL 1 umax)
1500 ;; the </div> to close the last text-... div.
1501 (when (and (> umax 0) org-html-dyn-first-heading-pos)
1502 (org-parse-end 'SECTION))
1504 (org-parse-end 'DOCUMENT-BODY opt-plist)
1505 (unless body-only
1506 (org-parse-end 'DOCUMENT-CONTENT))
1508 (unless (plist-get opt-plist :buffer-will-be-killed)
1509 (set-auto-mode t))
1511 (org-parse-end 'EXPORT)
1513 (goto-char (point-min))
1514 (or (org-export-push-to-kill-ring
1515 (upcase (symbol-name org-parse-backend)))
1516 (message "Exporting... done"))
1518 (cond
1519 ((not to-buffer)
1520 (let ((f (org-parse-get 'SAVE-METHOD)))
1521 (or (and f (functionp f) (funcall f filename))
1522 (save-buffer)))
1523 (current-buffer))
1524 ((eq to-buffer 'string)
1525 (prog1 (buffer-substring (point-min) (point-max))
1526 (kill-buffer (current-buffer))))
1527 (t (current-buffer))))))
1529 (defun org-export-html-format-href (s)
1530 "Make sure the S is valid as a href reference in an XHTML document."
1531 (save-match-data
1532 (let ((start 0))
1533 (while (string-match "&" s start)
1534 (setq start (+ (match-beginning 0) 3)
1535 s (replace-match "&amp;" t t s)))))
1538 (defun org-export-html-format-desc (s)
1539 "Make sure the S is valid as a description in a link."
1540 (if (and s (not (get-text-property 1 'org-protected s)))
1541 (save-match-data
1542 (org-html-do-expand s))
1545 (defun org-export-html-format-image (src)
1546 "Create image tag with source and attributes."
1547 (save-match-data
1548 (if (string-match "^ltxpng/" src)
1549 (format "<img src=\"%s\" alt=\"%s\"/>"
1550 src (org-find-text-property-in-string 'org-latex-src src))
1551 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1552 (attr (org-find-text-property-in-string 'org-attributes src))
1553 (label (org-find-text-property-in-string 'org-label src))
1554 (caption (and caption (org-html-do-expand caption)))
1555 (img (format "<img src=\"%s\"%s />"
1557 (if (string-match "\\<alt=" (or attr ""))
1558 (concat " " attr )
1559 (concat " " attr " alt=\"" src "\""))))
1560 (extra (concat
1561 (and label
1562 (format "id=\"%s\" " (org-solidify-link-text label)))
1563 "class=\"figure\"")))
1564 (if caption
1565 (with-temp-buffer
1566 (with-org-parse-preserve-paragraph-state
1567 (insert
1568 (org-parse-format
1569 '("<div %s>" . "\n</div>")
1570 (concat
1571 (org-parse-format '("\n<p>" . "</p>") img)
1572 (org-parse-format '("\n<p>" . "</p>") caption))
1573 extra)))
1574 (buffer-string))
1575 img)))))
1577 (defun org-export-html-get-bibliography ()
1578 "Find bibliography, cut it out and return it."
1579 (catch 'exit
1580 (let (beg end (cnt 1) bib)
1581 (save-excursion
1582 (goto-char (point-min))
1583 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1584 (setq beg (match-beginning 0))
1585 (while (re-search-forward "</?div\\>" nil t)
1586 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1587 (when (= cnt 0)
1588 (and (looking-at ">") (forward-char 1))
1589 (setq bib (buffer-substring beg (point)))
1590 (delete-region beg (point))
1591 (throw 'exit bib))))
1592 nil))))
1594 ;; Following variable is defined for native tables i.e., when
1595 ;; `org-table-is-styled' evals to t.
1596 (defvar no-css)
1597 (defvar org-table-number-regexp) ; defined in org-table.el
1598 (defun org-format-table-html (lines olines &optional no-css)
1599 "Find out which HTML converter to use and return the HTML code.
1600 NO-CSS is passed to the exporter."
1601 (if (stringp lines)
1602 (setq lines (org-split-string lines "\n")))
1603 (if (string-match "^[ \t]*|" (car lines))
1604 ;; A normal org table
1605 (org-format-org-table-html lines nil no-css)
1606 ;; Table made by table.el - test for spanning
1607 (let* ((hlines (delq nil (mapcar
1608 (lambda (x)
1609 (if (string-match "^[ \t]*\\+-" x) x
1610 nil))
1611 lines)))
1612 (first (car hlines))
1613 (ll (and (string-match "\\S-+" first)
1614 (match-string 0 first)))
1615 (re (concat "^[ \t]*" (regexp-quote ll)))
1616 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
1617 hlines))))
1618 (if (and (not spanning)
1619 (not org-export-prefer-native-exporter-for-tables))
1620 ;; We can use my own converter with HTML conversions
1621 (org-format-table-table-html lines)
1622 ;; Need to use the code generator in table.el, with the original text.
1623 (org-format-table-table-html-using-table-generate-source olines)))))
1625 (defun org-table-get-colalign-info (lines)
1626 (let ((forced-aligns (org-find-text-property-in-string
1627 'org-forced-aligns (car lines))))
1628 (when (and forced-aligns org-table-clean-did-remove-column)
1629 (setq forced-aligns
1630 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
1632 forced-aligns))
1634 (defvar org-table-style)
1635 (defvar org-table-ncols)
1636 (defvar org-table-rownum)
1638 (defvar org-table-is-styled)
1639 (defvar org-table-begin-marker)
1640 (defvar org-table-num-numeric-items-per-column)
1641 (defvar org-table-colalign-info)
1642 (defvar org-table-colalign-vector)
1643 (defvar org-table-number-fraction) ; defined in org-table.el
1644 (defun org-do-format-org-table-html (lines &optional splice no-css)
1645 "Format a table into HTML.
1646 LINES is a list of lines. Optional argument SPLICE means, do not
1647 insert header and surrounding <table> tags, just format the lines.
1648 Optional argument NO-CSS means use XHTML attributes instead of CSS
1649 for formatting. This is required for the DocBook exporter."
1650 (require 'org-table)
1651 ;; Get rid of hlines at beginning and end
1652 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1653 (setq lines (nreverse lines))
1654 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1655 (setq lines (nreverse lines))
1656 (when org-export-table-remove-special-lines
1657 ;; Check if the table has a marking column. If yes remove the
1658 ;; column and the special lines
1659 (setq lines (org-table-clean-before-export lines)))
1661 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
1662 (caption (and caption (org-html-do-expand caption)))
1663 (label (org-find-text-property-in-string 'org-label (car lines)))
1664 (org-table-colalign-info (org-table-get-colalign-info lines))
1665 (attributes (org-find-text-property-in-string 'org-attributes
1666 (car lines)))
1667 (head (and org-export-highlight-first-table-line
1668 (delq nil (mapcar
1669 (lambda (x) (string-match "^[ \t]*|-" x))
1670 (cdr lines)))))
1671 (org-table-rownum -1) org-table-ncols i (cnt 0)
1672 tbopen line fields
1673 org-table-current-rowgroup-is-header
1674 org-table-rowgroup-open
1675 org-table-num-numeric-items-per-column
1676 org-table-colalign-vector n
1677 org-table-rowgroup-info
1678 org-table-begin-marker
1679 (org-table-style 'org-table)
1680 org-table-is-styled)
1681 (cond
1682 (splice
1683 (setq org-table-is-styled nil)
1684 (while (setq line (pop lines))
1685 (unless (string-match "^[ \t]*|-" line)
1686 (insert
1687 (org-parse-format-table-row
1688 (org-split-string line "[ \t]*|[ \t]*")) "\n"))))
1690 (setq org-table-is-styled t)
1691 (org-parse-begin 'TABLE caption label attributes)
1692 (setq org-table-begin-marker (point))
1693 (org-parse-begin-table-rowgroup head)
1694 (while (setq line (pop lines))
1695 (cond
1696 ((string-match "^[ \t]*|-" line)
1697 (when lines (org-parse-begin-table-rowgroup)))
1699 (insert
1700 (org-parse-format-table-row
1701 (org-split-string line "[ \t]*|[ \t]*")) "\n"))))
1702 (org-parse-end 'TABLE-ROWGROUP)
1703 (org-parse-end-table)))))
1705 (defun org-format-org-table-html (lines &optional splice no-css)
1706 (with-temp-buffer
1707 (org-do-format-org-table-html lines splice no-css)
1708 (buffer-substring-no-properties (point-min) (point-max))))
1710 (defun org-export-splice-attributes (tag attributes)
1711 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1712 (if (not attributes)
1714 (let (oldatt newatt)
1715 (setq oldatt (org-extract-attributes-from-string tag)
1716 tag (pop oldatt)
1717 newatt (cdr (org-extract-attributes-from-string attributes)))
1718 (while newatt
1719 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1720 (if (string-match ">" tag)
1721 (setq tag
1722 (replace-match (concat (org-attributes-to-string oldatt) ">")
1723 t t tag)))
1724 tag)))
1726 (defun org-do-format-table-table-html (lines)
1727 "Format a table generated by table.el into HTML.
1728 This conversion does *not* use `table-generate-source' from table.el.
1729 This has the advantage that Org-mode's HTML conversions can be used.
1730 But it has the disadvantage, that no cell- or row-spanning is allowed."
1731 (let (line field-buffer
1732 (org-table-current-rowgroup-is-header
1733 org-export-highlight-first-table-line)
1734 (caption nil)
1735 (attributes nil)
1736 (label nil)
1737 (org-table-style 'table-table)
1738 (org-table-is-styled nil)
1739 fields org-table-ncols i (org-table-rownum -1)
1740 (empty (org-parse-format 'SPACES 1)))
1741 (org-parse-begin 'TABLE caption label attributes)
1742 (while (setq line (pop lines))
1743 (cond
1744 ((string-match "^[ \t]*\\+-" line)
1745 (when field-buffer
1746 (let ((org-export-table-row-tags '("<tr>" . "</tr>"))
1747 (org-export-html-table-use-header-tags-for-first-column nil))
1748 (insert (org-parse-format-table-row field-buffer empty)))
1749 (setq org-table-current-rowgroup-is-header nil)
1750 (setq field-buffer nil)))
1752 ;; Break the line into fields and store the fields
1753 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1754 (if field-buffer
1755 (setq field-buffer (mapcar
1756 (lambda (x)
1757 (concat x (org-parse-format 'LINE-BREAK)
1758 (pop fields)))
1759 field-buffer))
1760 (setq field-buffer fields)))))
1761 (org-parse-end-table)))
1763 (defun org-format-table-table-html (lines)
1764 (with-temp-buffer
1765 (org-do-format-table-table-html lines)
1766 (buffer-substring-no-properties (point-min) (point-max))))
1768 (defun org-format-table-table-html-using-table-generate-source (lines)
1769 "Format a table into html, using `table-generate-source' from table.el.
1770 This has the advantage that cell- or row-spanning is allowed.
1771 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
1772 (require 'table)
1773 (with-current-buffer (get-buffer-create " org-tmp1 ")
1774 (erase-buffer)
1775 (insert (mapconcat 'identity lines "\n"))
1776 (goto-char (point-min))
1777 (if (not (re-search-forward "|[^+]" nil t))
1778 (error "Error processing table"))
1779 (table-recognize-table)
1780 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1781 (table-generate-source 'html " org-tmp2 ")
1782 (set-buffer " org-tmp2 ")
1783 (buffer-substring (point-min) (point-max))))
1785 (defun org-export-splice-style (style extra)
1786 "Splice EXTRA into STYLE, just before \"</style>\"."
1787 (if (and (stringp extra)
1788 (string-match "\\S-" extra)
1789 (string-match "</style>" style))
1790 (concat (substring style 0 (match-beginning 0))
1791 "\n" extra "\n"
1792 (substring style (match-beginning 0)))
1793 style))
1795 (defun org-html-handle-time-stamps (s)
1796 "Format time stamps in string S, or remove them."
1797 (catch 'exit
1798 (let (r b)
1799 (while (string-match org-maybe-keyword-time-regexp s)
1800 (or b (setq b (substring s 0 (match-beginning 0))))
1801 (setq r (concat
1802 r (substring s 0 (match-beginning 0))
1803 (org-parse-format
1804 'FONTIFY
1805 (concat
1806 (if (match-end 1)
1807 (org-parse-format
1808 'FONTIFY
1809 (match-string 1 s) "timestamp-kwd"))
1810 (org-parse-format
1811 'FONTIFY
1812 (substring (org-translate-time (match-string 3 s)) 1 -1)
1813 "timestamp"))
1814 "timestamp-wrapper"))
1815 s (substring s (match-end 0))))
1816 ;; Line break if line started and ended with time stamp stuff
1817 (if (not r)
1819 (setq r (concat r s))
1820 (unless (string-match "\\S-" (concat b s))
1821 (setq r (concat r (org-parse-format 'LINE-BREAK))))
1822 r))))
1824 (defvar htmlize-buffer-places) ; from htmlize.el
1825 (defun org-export-htmlize-region-for-paste (beg end)
1826 "Convert the region to HTML, using htmlize.el.
1827 This is much like `htmlize-region-for-paste', only that it uses
1828 the settings define in the org-... variables."
1829 (let* ((htmlize-output-type org-export-htmlize-output-type)
1830 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
1831 (htmlbuf (htmlize-region beg end)))
1832 (unwind-protect
1833 (with-current-buffer htmlbuf
1834 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1835 (plist-get htmlize-buffer-places 'content-end)))
1836 (kill-buffer htmlbuf))))
1838 ;;;###autoload
1839 (defun org-export-htmlize-generate-css ()
1840 "Create the CSS for all font definitions in the current Emacs session.
1841 Use this to create face definitions in your CSS style file that can then
1842 be used by code snippets transformed by htmlize.
1843 This command just produces a buffer that contains class definitions for all
1844 faces used in the current Emacs session. You can copy and paste the ones you
1845 need into your CSS file.
1847 If you then set `org-export-htmlize-output-type' to `css', calls to
1848 the function `org-export-htmlize-region-for-paste' will produce code
1849 that uses these same face definitions."
1850 (interactive)
1851 (require 'htmlize)
1852 (and (get-buffer "*html*") (kill-buffer "*html*"))
1853 (with-temp-buffer
1854 (let ((fl (face-list))
1855 (htmlize-css-name-prefix "org-")
1856 (htmlize-output-type 'css)
1857 f i)
1858 (while (setq f (pop fl)
1859 i (and f (face-attribute f :inherit)))
1860 (when (and (symbolp f) (or (not i) (not (listp i))))
1861 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1862 (htmlize-region (point-min) (point-max))))
1863 (switch-to-buffer "*html*")
1864 (goto-char (point-min))
1865 (if (re-search-forward "<style" nil t)
1866 (delete-region (point-min) (match-beginning 0)))
1867 (if (re-search-forward "</style>" nil t)
1868 (delete-region (1+ (match-end 0)) (point-max)))
1869 (beginning-of-line 1)
1870 (if (looking-at " +") (replace-match ""))
1871 (goto-char (point-min)))
1873 (defun org-html-protect (s)
1874 "Convert characters to HTML equivalent.
1875 Possible conversions are set in `org-export-html-protect-char-alist'."
1876 (let ((cl org-export-html-protect-char-alist) c)
1877 (while (setq c (pop cl))
1878 (let ((start 0))
1879 (while (string-match (car c) s start)
1880 (setq s (replace-match (cdr c) t t s)
1881 start (1+ (match-beginning 0))))))
1884 (defun org-html-expand (string)
1885 "Prepare STRING for HTML export. Apply all active conversions.
1886 If there are links in the string, don't modify these."
1887 (let* ((re (concat org-bracket-link-regexp "\\|"
1888 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1889 m s l res)
1890 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
1891 string
1892 (while (setq m (string-match re string))
1893 (setq s (substring string 0 m)
1894 l (match-string 0 string)
1895 string (substring string (match-end 0)))
1896 (push (org-html-do-expand s) res)
1897 (push l res))
1898 (push (org-html-do-expand string) res)
1899 (apply 'concat (nreverse res)))))
1901 (defun org-html-do-expand (s)
1902 "Apply all active conversions to translate special ASCII to HTML."
1903 (setq s (org-html-protect s))
1904 (if org-export-html-expand
1905 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
1906 (setq s (replace-match "<\\1>" t nil s))))
1907 (if org-export-with-emphasize
1908 (setq s (org-export-html-convert-emphasize s)))
1909 (if org-export-with-special-strings
1910 (setq s (org-export-html-convert-special-strings s)))
1911 (if org-export-with-sub-superscripts
1912 (setq s (org-export-html-convert-sub-super s)))
1913 (if org-export-with-TeX-macros
1914 (let ((start 0) wd rep)
1915 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
1916 s start))
1917 (if (get-text-property (match-beginning 0) 'org-protected s)
1918 (setq start (match-end 0))
1919 (setq wd (match-string 1 s))
1920 (if (setq rep (org-entity-get-representation wd 'html))
1921 (setq s (replace-match rep t t s))
1922 (setq start (+ start (length wd))))))))
1925 (defun org-export-html-convert-special-strings (string)
1926 "Convert special characters in STRING to HTML."
1927 (let ((all org-export-html-special-string-regexps)
1928 e a re rpl start)
1929 (while (setq a (pop all))
1930 (setq re (car a) rpl (cdr a) start 0)
1931 (while (string-match re string start)
1932 (if (get-text-property (match-beginning 0) 'org-protected string)
1933 (setq start (match-end 0))
1934 (setq string (replace-match rpl t nil string)))))
1935 string))
1937 (defun org-export-html-convert-sub-super (string)
1938 "Convert sub- and superscripts in STRING to HTML."
1939 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
1940 (while (string-match org-match-substring-regexp string s)
1941 (cond
1942 ((and requireb (match-end 8)) (setq s (match-end 2)))
1943 ((get-text-property (match-beginning 2) 'org-protected string)
1944 (setq s (match-end 2)))
1946 (setq s (match-end 1)
1947 key (if (string= (match-string 2 string) "_")
1948 'subscript 'superscript)
1949 c (or (match-string 8 string)
1950 (match-string 6 string)
1951 (match-string 5 string))
1952 string (replace-match
1953 (concat (match-string 1 string)
1954 (org-parse-format 'FONTIFY c key))
1955 t t string)))))
1956 (while (string-match "\\\\\\([_^]\\)" string)
1957 (setq string (replace-match (match-string 1 string) t t string)))
1958 string))
1960 (defun org-export-html-convert-emphasize (string)
1961 "Apply emphasis."
1962 (let ((s 0) rpl)
1963 (while (string-match org-emph-re string s)
1964 (if (not (equal
1965 (substring string (match-beginning 3) (1+ (match-beginning 3)))
1966 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
1967 (setq s (match-beginning 0)
1969 (concat
1970 (match-string 1 string)
1971 (org-parse-format
1972 'FONTIFY (match-string 4 string)
1973 (nth 1 (assoc (match-string 3 string)
1974 org-html-emphasis-alist)))
1975 (match-string 5 string))
1976 string (replace-match rpl t t string)
1977 s (+ s (- (length rpl) 2)))
1978 (setq s (1+ s))))
1979 string))
1981 (defvar body-only) ; dynamically scoped into this.
1982 (defun org-export-html-get-tag-class-name (tag)
1983 "Turn tag into a valid class name.
1984 Replaces invalid characters with \"_\" and then prepends a prefix."
1985 (save-match-data
1986 (while (string-match "[^a-zA-Z0-9_]" tag)
1987 (setq tag (replace-match "_" t t tag))))
1988 (concat org-export-html-tag-class-prefix tag))
1990 (defun org-export-html-get-todo-kwd-class-name (kwd)
1991 "Turn todo keyword into a valid class name.
1992 Replaces invalid characters with \"_\" and then prepends a prefix."
1993 (save-match-data
1994 (while (string-match "[^a-zA-Z0-9_]" kwd)
1995 (setq kwd (replace-match "_" t t kwd))))
1996 (concat org-export-html-todo-kwd-class-prefix kwd))
1998 (defun org-html-export-list-line (line pos struct prevs)
1999 "Insert list syntax in export buffer. Return LINE, maybe modified.
2001 POS is the item position or line position the line had before
2002 modifications to buffer. STRUCT is the list structure. PREVS is
2003 the alist of previous items."
2004 (let* ((get-type
2005 (function
2006 ;; Translate type of list containing POS to "d", "o" or
2007 ;; "u".
2008 (lambda (pos struct prevs)
2009 (let ((type (org-list-get-list-type pos struct prevs)))
2010 (cond
2011 ((eq 'ordered type) "o")
2012 ((eq 'descriptive type) "d")
2013 (t "u"))))))
2014 (get-closings
2015 (function
2016 ;; Return list of all items and sublists ending at POS, in
2017 ;; reverse order.
2018 (lambda (pos)
2019 (let (out)
2020 (catch 'exit
2021 (mapc (lambda (e)
2022 (let ((end (nth 6 e))
2023 (item (car e)))
2024 (cond
2025 ((= end pos) (push item out))
2026 ((>= item pos) (throw 'exit nil)))))
2027 struct))
2028 out)))))
2029 ;; First close any previous item, or list, ending at POS.
2030 (mapc (lambda (e)
2031 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2032 (first-item (org-list-get-list-begin e struct prevs))
2033 (type (funcall get-type first-item struct prevs)))
2034 (org-parse-end-paragraph)
2035 ;; Ending for every item
2036 (org-close-li type)
2037 ;; We're ending last item of the list: end list.
2038 (when lastp
2039 (org-parse-end 'LIST type)
2040 (org-parse-begin-paragraph))))
2041 (funcall get-closings pos))
2042 (cond
2043 ;; At an item: insert appropriate tags in export buffer.
2044 ((assq pos struct)
2045 (string-match
2046 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2047 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2048 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2049 "\\(?:\\(.*\\)[ \t]+::[ \t]+\\)?"
2050 "\\(.*\\)") line)
2051 (let* ((checkbox (match-string 3 line))
2052 (desc-tag (or (match-string 4 line) "???"))
2053 (body (or (match-string 5 line) ""))
2054 (list-beg (org-list-get-list-begin pos struct prevs))
2055 (firstp (= list-beg pos))
2056 ;; Always refer to first item to determine list type, in
2057 ;; case list is ill-formed.
2058 (type (funcall get-type list-beg struct prevs))
2059 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2060 (cond
2061 ((not count-tmp) nil)
2062 ((string-match "[A-Za-z]" count-tmp)
2063 (- (string-to-char (upcase count-tmp)) 64))
2064 ((string-match "[0-9]+" count-tmp)
2065 count-tmp)))))
2066 (when firstp
2067 (org-parse-end-paragraph)
2068 (org-parse-begin 'LIST type))
2070 (let ((arg (cond ((equal type "d") desc-tag)
2071 ((equal type "o") counter))))
2072 (org-parse-begin 'LIST-ITEM type arg))
2074 ;; If line had a checkbox, some additional modification is required.
2075 (when checkbox
2076 (setq body
2077 (concat
2078 (org-parse-format
2079 'FONTIFY (concat
2081 (cond
2082 ((string-match "X" checkbox) "X")
2083 ((string-match " " checkbox)
2084 (org-parse-format 'SPACES 1))
2085 (t "-"))
2086 "]")
2087 'code)
2089 body)))
2090 ;; Return modified line
2091 body))
2092 ;; At a list ender: go to next line (side-effects only).
2093 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2094 ;; Not at an item: return line unchanged (side-effects only).
2095 (t line))))
2097 ;; miscellaneous
2099 (defun org-html-bind-local-variables (opt-plist)
2100 (mapc (lambda (x)
2101 (set (make-local-variable (nth 2 x))
2102 (plist-get opt-plist (car x))))
2103 org-export-plist-vars))
2106 ;; This replaces org-emphasis-alist
2107 (defvar org-table-rowgroup-open)
2108 (defvar org-table-current-rowgroup-is-header)
2109 (defvar org-html-footnote-number)
2110 (defvar org-html-footnote-definitions)
2111 (defvar org-html-footnote-buffer)
2112 (defvar org-html-output-buffer)
2114 (defun org-html-end-export ()
2115 ;; insert the table of contents
2116 (when (and org-export-with-toc (not body-only))
2117 (org-html-insert-toc org-parse-table-of-contents))
2119 ;; remove empty paragraphs
2120 (goto-char (point-min))
2121 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2122 (replace-match ""))
2124 ;; Convert whitespace place holders
2125 (goto-char (point-min))
2126 (let (beg end n)
2127 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2128 (setq n (get-text-property beg 'org-whitespace)
2129 end (next-single-property-change beg 'org-whitespace))
2130 (goto-char beg)
2131 (delete-region beg end)
2132 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2133 (make-string n ?x)))))
2135 ;; Remove empty lines at the beginning of the file.
2136 (goto-char (point-min))
2137 (when (looking-at "\\s-+\n") (replace-match ""))
2139 ;; Remove display properties
2140 (remove-text-properties (point-min) (point-max) '(display t))
2142 ;; kill temporary buffers
2143 (when org-html-footnote-buffer
2144 (kill-buffer org-html-footnote-buffer))
2146 ;; Run the hook
2147 (run-hooks 'org-export-html-final-hook))
2150 ;;;_ org-parse.el
2151 ;;;_. preamble
2152 ;;;_ , user-specific
2153 ;;;_ . custom-settings
2154 (defcustom org-parse-debug nil
2156 :group 'org-parse
2157 :type 'boolean)
2162 ;;;_ , callbacks
2163 ;;;_ . control callbacks
2164 ;;;_ , generic
2165 (defun org-parse-begin (entity &rest args)
2166 (when (and (member org-parse-debug '(t control))
2167 (not (eq entity 'DOCUMENT-CONTENT)))
2168 (insert (org-parse-format 'COMMENT "%s BEGIN %S" entity args)))
2170 (let ((f (cadr (assoc entity org-parse-entity-control-callbacks-alist))))
2171 (unless f (error "Unknown entity: %s" entity))
2172 (apply f args)))
2174 (defun org-parse-end (entity &rest args)
2175 (when (and (member org-parse-debug '(t control))
2176 (not (eq entity 'DOCUMENT-CONTENT)))
2177 (insert (org-parse-format 'COMMENT "%s END %S" entity args)))
2179 (let ((f (caddr (assoc entity org-parse-entity-control-callbacks-alist))))
2180 (unless f (error "Unknown entity: %s" entity))
2181 (apply f args)))
2184 ;;;_ , paragraph
2185 (defun org-parse-begin-paragraph (&optional style)
2186 "Insert <p>, but first close previous paragraph if any."
2187 (org-parse-end-paragraph)
2188 (org-parse-begin 'PARAGRAPH style)
2189 (setq org-par-open t))
2191 (defun org-parse-end-paragraph ()
2192 "Close paragraph if there is one open."
2193 (when org-par-open
2194 (org-parse-end 'PARAGRAPH)
2195 (setq org-par-open nil)))
2197 ;;;_ , list
2198 (defun org-close-li (&optional type)
2199 "Close <li> if necessary."
2200 (org-parse-end-paragraph)
2201 (org-parse-end 'LIST-ITEM (or type "u")))
2204 ;;;_ , environment
2205 (defvar org-parse-dyn-current-environment nil)
2206 (defun org-parse-begin-environment (style)
2207 (assert (not org-parse-dyn-current-environment) t)
2208 (setq org-parse-dyn-current-environment style)
2209 (org-parse-begin 'ENVIRONMENT style))
2211 (defun org-parse-end-environment (style)
2212 (org-parse-end 'ENVIRONMENT style)
2214 (assert (eq org-parse-dyn-current-environment style) t)
2215 (setq org-parse-dyn-current-environment nil))
2217 (defun org-parse-current-environment-p (style)
2218 (eq org-parse-dyn-current-environment style))
2221 ;;;_ , footnote definition
2222 (defun org-parse-begin-footnote-definition (n)
2223 (unless org-html-footnote-buffer
2224 (setq org-html-footnote-buffer
2225 (get-buffer-create "*Org HTML Export Footnotes*")))
2226 (set-buffer org-html-footnote-buffer)
2227 (erase-buffer)
2228 (org-parse-begin 'FOOTNOTE-DEFINITION n))
2230 (defun org-parse-end-footnote-definition (n)
2231 (org-parse-end 'FOOTNOTE-DEFINITION n)
2232 (push (cons n (buffer-string)) org-html-footnote-definitions)
2233 (set-buffer org-html-output-buffer))
2238 ;;;_ . format callbacks
2239 ;;;_ , generic
2240 (defun org-parse-format (entity &rest args)
2241 (when (and (member org-parse-debug '(t format))
2242 (not (equal entity 'COMMENT)))
2243 (insert (org-parse-format 'COMMENT "%s: %S" entity args)))
2244 (cond
2245 ((consp entity)
2246 (let ((text (pop args)))
2247 (apply 'org-parse-format 'TAGS entity text args)))
2249 (let ((f (cdr (assoc entity org-parse-entity-format-callbacks-alist))))
2250 (unless f (error "Unknown entity: %s" entity))
2251 (apply f args)))))
2254 ;;;_ , toc (rename these routines)
2255 (defun org-html-format-toc-entry (snumber todo headline tags href)
2256 (setq headline (concat
2257 (and org-export-with-section-numbers
2258 (concat snumber " "))
2259 headline
2260 (and tags
2261 (concat
2262 (org-parse-format 'SPACES 3)
2263 (org-parse-format 'FONTIFY tags "tag")))))
2264 (when todo
2265 (setq headline (org-parse-format 'FONTIFY headline "todo")))
2266 (org-parse-format 'LINK headline (concat "#" href)))
2268 (defun org-html-format-toc-item (toc-entry level org-last-level)
2269 (when (> level org-last-level)
2270 (let ((cnt (- level org-last-level)))
2271 (while (>= (setq cnt (1- cnt)) 0)
2272 (org-parse-begin 'LIST 'unordered)
2273 (org-parse-begin 'LIST-ITEM 'unordered))))
2274 (when (< level org-last-level)
2275 (let ((cnt (- org-last-level level)))
2276 (while (>= (setq cnt (1- cnt)) 0)
2277 (org-close-li)
2278 (org-parse-end 'LIST 'unordered))))
2280 (org-close-li)
2281 (org-parse-begin 'LIST-ITEM 'unordered)
2282 (insert toc-entry))
2284 (defun org-html-prepare-toc (lines level-offset opt-plist umax-toc)
2285 (let* ((quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2286 (org-min-level (org-get-min-level lines level-offset))
2287 (org-last-level org-min-level)
2288 level)
2289 (with-temp-buffer
2290 (org-html-bind-local-variables opt-plist)
2291 (erase-buffer)
2292 (org-parse-begin 'SECTION "table-of-contents")
2293 (insert
2294 (org-parse-format 'HEADING
2295 (nth 3 (plist-get opt-plist :lang-words))
2296 org-export-html-toplevel-hlevel))
2297 (org-parse-begin 'SECTION "text-table-of-contents")
2298 (org-parse-begin 'LIST 'unordered)
2299 (org-parse-begin 'LIST-ITEM 'unordered)
2300 (setq
2301 lines
2302 (mapcar
2303 '(lambda (line)
2304 (when (and (string-match org-todo-line-regexp line)
2305 (not (get-text-property 0 'org-protected line))
2306 (<= (setq level (org-tr-level
2307 (- (match-end 1) (match-beginning 1)
2308 level-offset)))
2309 umax-toc))
2310 (let ((txt (save-match-data
2311 (org-html-expand
2312 (org-export-cleanup-toc-line
2313 (match-string 3 line)))))
2314 (todo (and
2315 org-export-mark-todo-in-toc
2316 (or (and (match-beginning 2)
2317 (not (member (match-string 2 line)
2318 org-done-keywords)))
2319 (and (= level umax-toc)
2320 (org-search-todo-below
2321 line lines level)))))
2322 tags)
2323 ;; Check for targets
2324 (while (string-match org-any-target-regexp line)
2325 (setq line
2326 (replace-match
2327 (let ((org-html-protect t))
2328 (org-parse-format 'FONTIFY
2329 (match-string 1 line) "target"))
2330 t t line)))
2331 (when (string-match
2332 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2333 (setq txt (replace-match "" t nil txt)
2334 tags (match-string 1 txt)))
2335 (when (string-match quote-re0 txt)
2336 (setq txt (replace-match "" t t txt)))
2337 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2338 (setq txt (replace-match "" t t txt)))
2339 (org-parse-format
2340 'TOC-ITEM
2341 (let* ((snumber (org-section-number level))
2342 (href (replace-regexp-in-string
2343 "\\." "_" (format "sec-%s" snumber)))
2344 (href
2346 (cdr (assoc
2347 href org-export-preferred-target-alist))
2348 href))
2349 (href (org-solidify-link-text href)))
2350 (org-parse-format 'TOC-ENTRY snumber todo txt tags href))
2351 level org-last-level)
2352 (setq org-last-level level)))
2353 line)
2354 lines))
2355 (while (> org-last-level (1- org-min-level))
2356 (setq org-last-level (1- org-last-level))
2357 (org-close-li)
2358 (org-parse-end 'LIST 'unordered))
2359 (org-parse-end 'SECTION)
2360 (org-parse-end 'SECTION)
2361 ;; cleanup empty list items in toc
2362 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
2363 (replace-match ""))
2364 (setq org-parse-table-of-contents (buffer-string))))
2365 lines)
2368 ;;;_ , table row
2369 (defun org-parse-format-table-row (fields &optional text-for-empty-fields)
2370 (unless org-table-ncols
2371 ;; first row of the table
2372 (setq org-table-ncols (length fields))
2373 (when org-table-is-styled
2374 (setq org-table-num-numeric-items-per-column (make-vector org-table-ncols 0))
2375 (setq org-table-colalign-vector (make-vector org-table-ncols nil))
2376 (let ((c -1))
2377 (while (< (incf c) org-table-ncols)
2378 (let ((cookie (cdr (assoc (1+ c) org-table-colalign-info))))
2379 (setf (aref org-table-colalign-vector c)
2380 (cond
2381 ((string= cookie "l") "left")
2382 ((string= cookie "r") "right")
2383 ((string= cookie "c") "center")
2384 (t nil))))))))
2385 (incf org-table-rownum)
2387 (let ((i -1))
2388 (org-parse-format
2389 'TABLE-ROW
2390 (mapconcat
2391 (lambda (x)
2392 (when (string= x "")
2393 (setq x text-for-empty-fields))
2394 (incf i)
2395 (and org-table-is-styled
2396 (< i org-table-ncols)
2397 (string-match org-table-number-regexp x)
2398 (incf (aref org-table-num-numeric-items-per-column i)))
2399 (org-parse-format 'TABLE-CELL x org-table-rownum i))
2400 fields "\n"))))
2402 ;;;_ . get callback
2403 (defun org-parse-get (what &optional opt-plist)
2404 (funcall org-parse-get-callback what opt-plist))
2406 ;;;_. postamble
2409 ;;;_ org-newhtml.el
2410 ;;;_. preamble
2411 ;;;_. obsolete
2412 ;;;_. maybe
2413 ;;;_. hacks (to be documented)
2414 (defconst org-html-emphasis-alist
2415 `(("*" bold)
2416 ("/" emphasis)
2417 ("_" underline)
2418 ("=" code)
2419 ("~" verbatim)
2420 ("+" strike)))
2423 ;;;_. user-specific
2424 ;;;_ , custom settings
2425 ;;;_ . potential custom settings
2426 ;;;_ , interactive commands
2427 ;;;_. parser
2428 ;;;_ , initialization
2429 (defvar org-html-entity-control-callbacks-alist
2430 `((EXPORT
2431 . (org-html-begin-export org-html-end-export))
2432 (DOCUMENT-CONTENT
2433 . (org-html-begin-document-content org-html-end-document-content))
2434 (DOCUMENT-BODY
2435 . (org-html-begin-document-body org-html-end-document-body))
2436 (ENVIRONMENT
2437 . (org-html-begin-environment org-html-end-environment))
2438 (LEVEL
2439 . (org-html-begin-level org-html-end-level))
2440 (FOOTNOTE-DEFINITION
2441 . (org-html-begin-footnote-definition org-html-end-footnote-definition))
2442 (TABLE
2443 . (org-html-begin-table org-html-end-table))
2444 (TABLE-ROWGROUP
2445 . (org-html-begin-table-rowgroup org-html-end-table-rowgroup))
2446 (LIST
2447 . (org-html-begin-list org-html-end-list))
2448 (LIST-ITEM
2449 . (org-html-begin-list-item org-html-end-list-item))
2450 (SECTION
2451 . (org-html-begin-section org-html-end-section))
2452 (PARAGRAPH
2453 . (org-html-begin-paragraph org-html-end-paragraph)))
2456 (defvar org-html-entity-format-callbacks-alist
2457 `((EXTRA-TARGETS . org-html-format-extra-targets)
2458 (ORG-TAGS . org-html-format-org-tags)
2459 (SECTION-NUMBER . org-html-format-section-number)
2460 (HEADLINE . org-html-format-headline)
2461 (TOC-ENTRY . org-html-format-toc-entry)
2462 (TOC-ITEM . org-html-format-toc-item)
2463 (TAGS . org-html-format-tags)
2464 (SPACES . org-html-format-spaces)
2465 (TABS . org-html-format-tabs)
2466 (LINE-BREAK . org-html-format-line-break)
2467 (FONTIFY . org-html-format-fontify)
2468 (TODO . org-html-format-todo)
2469 (ORG-LINK . org-html-format-org-link)
2470 (LINK . org-html-format-link)
2471 (INLINE-IMAGE . org-html-format-inline-image)
2472 (HEADING . org-html-format-heading)
2473 (ANCHOR . org-html-format-anchor)
2474 (TABLE-ROW . org-html-format-table-row)
2475 (TABLE-CELL . org-html-format-table-cell)
2476 (FOOTNOTES-SECTION . org-html-format-footnotes-section)
2477 (FOOTNOTE-REFERENCE . org-html-format-footnote-reference)
2478 (HORIZONTAL-LINE . org-html-format-horizontal-line)
2479 (PLAIN . org-html-format-plain)
2480 (COMMENT . org-html-format-comment))
2485 ;;;_ , callbacks
2486 ;;;_ . control callbacks
2487 ;;;_ , generic
2488 (defvar org-html-insert-tag-with-newlines 'both)
2490 (defun org-html-insert-tag (tag &rest args)
2491 (when (member org-html-insert-tag-with-newlines '(lead both))
2492 (insert "\n"))
2493 (insert (apply 'format tag args))
2494 (when (member org-html-insert-tag-with-newlines '(trail both))
2495 (insert "\n")))
2497 ;;;_ , document body
2498 (defun org-html-begin-document-body (opt-plist)
2499 (let ((link-up (and (plist-get opt-plist :link-up)
2500 (string-match "\\S-" (plist-get opt-plist :link-up))
2501 (plist-get opt-plist :link-up)))
2502 (link-home (and (plist-get opt-plist :link-home)
2503 (string-match "\\S-" (plist-get opt-plist :link-home))
2504 (plist-get opt-plist :link-home))))
2505 (insert "\n<body>")
2506 (org-parse-begin 'SECTION "content")
2507 (insert "\n"
2508 (or (and (or link-up link-home)
2509 (format org-export-html-home/up-format
2510 (or link-up link-home)
2511 (or link-home link-up))) "")
2512 "\n"))
2513 (org-html-insert-preamble opt-plist))
2515 (defun org-html-end-document-body (opt-plist)
2516 (org-html-insert-postamble opt-plist)
2517 (unless body-only
2518 (org-parse-end 'SECTION)
2519 (insert "\n</body>")))
2522 ;;;_ , document content
2523 (defun org-html-begin-document-content (opt-plist)
2524 (let* ((language (plist-get opt-plist :language))
2525 (charset (or (and coding-system-for-write
2526 (fboundp 'coding-system-get)
2527 (coding-system-get coding-system-for-write
2528 'mime-charset))
2529 "iso-8859-1"))
2530 (style (concat (if (plist-get opt-plist :style-include-default)
2531 org-export-html-style-default)
2532 (plist-get opt-plist :style)
2533 (plist-get opt-plist :style-extra)
2534 "\n"
2535 (if (plist-get opt-plist :style-include-scripts)
2536 org-export-html-scripts)))
2537 (mathjax
2538 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
2539 (and org-export-have-math
2540 (eq (plist-get opt-plist :LaTeX-fragments) t)))
2542 (org-export-html-mathjax-config
2543 org-export-html-mathjax-template
2544 org-export-html-mathjax-options
2545 (or (plist-get opt-plist :mathjax) "")) "")))
2546 (insert (format
2548 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2549 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2550 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2551 lang=\"%s\" xml:lang=\"%s\">
2552 <head>
2553 <title>%s</title>
2554 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2555 <meta name=\"generator\" content=\"Org-mode\"/>
2556 <meta name=\"generated\" content=\"%s\"/>
2557 <meta name=\"author\" content=\"%s\"/>
2558 <meta name=\"description\" content=\"%s\"/>
2559 <meta name=\"keywords\" content=\"%s\"/>
2562 </head>
2564 (format
2565 (or (and (stringp org-export-html-xml-declaration)
2566 org-export-html-xml-declaration)
2567 (cdr (assoc (plist-get opt-plist :html-extension)
2568 org-export-html-xml-declaration))
2569 (cdr (assoc "html" org-export-html-xml-declaration))
2572 charset)
2573 language language
2574 (plist-get opt-plist :title)
2575 charset
2576 (plist-get opt-plist :effective-date)
2577 (plist-get opt-plist :author)
2578 (plist-get opt-plist :description)
2579 (plist-get opt-plist :keywords)
2580 style
2581 mathjax))))
2583 (defun org-html-end-document-content ()
2584 (insert "\n</html>\n"))
2587 ;;;_ , level
2588 (defun org-html-begin-level (level title umax with-toc head-count)
2589 "Insert a new level in HTML export.
2590 When TITLE is nil, just close all open levels."
2591 (org-parse-end 'LEVEL level umax)
2592 (unless title (error "Why is heading nil"))
2593 (let* ((target (org-get-text-property-any 0 'target title))
2594 (extra-targets (and target
2595 (assoc target org-export-target-aliases)))
2596 (extra-class (org-get-text-property-any 0 'html-container-class title))
2597 (preferred (and target
2598 (cdr (assoc target org-export-preferred-target-alist))))
2599 snumber snu href suffix tags level1)
2600 (setq extra-targets (remove (or preferred target) extra-targets))
2601 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2602 (setq tags (and org-export-with-tags (match-string 1 title)))
2603 (setq title (replace-match "" t t title)))
2604 (if (> level umax)
2605 (progn
2606 (if (aref org-levels-open (1- level))
2607 (org-close-li)
2608 (aset org-levels-open (1- level) t)
2609 (org-parse-end-paragraph)
2610 (org-parse-begin 'LIST 'unordered))
2611 (org-parse-begin
2612 'LIST-ITEM 'unordered (and target (org-solidify-link-text
2613 (or preferred target))))
2615 (insert
2616 (org-parse-format 'HEADLINE title extra-targets tags))
2617 (insert "<br/>\n"))
2618 (aset org-levels-open (1- level) t)
2619 (setq snumber (org-section-number level)
2620 snu (replace-regexp-in-string "\\." "_" snumber))
2621 (setq level1 (+ level org-export-html-toplevel-hlevel -1))
2622 (unless (= head-count 1)
2623 (org-parse-end 'SECTION))
2624 (setq href (cdr (assoc (concat "sec-" snu)
2625 org-export-preferred-target-alist)))
2626 (setq suffix (org-solidify-link-text (or href snu)))
2627 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2628 (let ((id (format "outline-container-%s" suffix))
2629 (class (format "outline-%d%s" level1
2630 (if extra-class (concat " " extra-class) ""))))
2631 (org-parse-begin 'SECTION id class))
2632 (insert
2633 (org-parse-format 'HEADING
2634 (org-parse-format
2635 'HEADLINE title extra-targets tags snumber level1)
2636 level1 href))
2637 (let ((id (format "text-%s" suffix))
2638 (class (format "outline-text-%d" level1)))
2639 (org-parse-begin 'SECTION id class))
2641 (org-parse-begin-paragraph))))
2643 (defun org-html-end-level (level umax)
2644 (org-parse-end-paragraph)
2645 (let* ((l org-level-max))
2646 (while (>= l level)
2647 (if (aref org-levels-open (1- l))
2648 (progn
2649 ;; Terminate one level in HTML export
2650 (if (<= l umax)
2651 (org-parse-end 'SECTION)
2652 (org-close-li)
2653 (org-parse-end 'LIST 'unordered))
2654 (aset org-levels-open (1- l) nil)))
2655 (setq l (1- l)))))
2658 ;;;_ , section
2659 (defun org-html-begin-section (&optional id class)
2660 (let ((extra (concat (when id (format " id=\"%s\"" id))
2661 (when class (format " class=\"%s\"" class)))))
2662 (org-html-insert-tag "<div%s>" extra)))
2664 (defun org-html-end-section ()
2665 (org-html-insert-tag "</div>"))
2669 ;;;_ , paragraph
2670 (defun org-html-begin-paragraph (&optional style)
2671 (let* ((class (cdr (assoc style '((footnote . "footnote")
2672 (verse . nil)))))
2673 (extra (if class (format " class=\"%s\"" class) "")))
2674 (org-html-insert-tag "<p%s>" extra)))
2676 (defun org-html-end-paragraph ()
2677 (insert "</p>"))
2680 ;;;_ , environment
2681 (defun org-html-format-environment (style beg-end)
2682 (assert (memq style '(blockquote center verse fixedwidth quote)) t)
2683 (case style
2684 (blockquote
2685 (case beg-end
2686 (BEGIN
2687 (org-parse-end-paragraph)
2688 (insert "<blockquote>\n")
2689 (org-parse-begin-paragraph))
2690 (END
2691 (org-parse-end-paragraph)
2692 (insert "\n</blockquote>\n")
2693 (org-parse-begin-paragraph))))
2694 (verse
2695 (case beg-end
2696 (BEGIN
2697 (org-parse-end-paragraph)
2698 (insert "\n<p class=\"verse\">\n")
2699 (setq org-par-open t))
2700 (END
2701 (insert "</p>\n")
2702 (setq org-par-open nil)
2703 (org-parse-begin-paragraph))))
2704 (center
2705 (case beg-end
2706 (BEGIN
2707 (org-parse-end-paragraph)
2708 (insert "\n<div style=\"text-align: center\">")
2709 (org-parse-begin-paragraph))
2710 (END
2711 (org-parse-end-paragraph)
2712 (insert "\n</div>")
2713 (org-parse-begin-paragraph))))
2714 (fixedwidth
2715 (case beg-end
2716 (BEGIN
2717 (org-parse-end-paragraph)
2718 (insert "<pre class=\"example\">\n"))
2719 (END
2720 (insert "</pre>\n")
2721 (org-parse-begin-paragraph))))
2722 (quote
2723 (case beg-end
2724 (BEGIN
2725 (org-parse-end-paragraph)
2726 (insert "<pre>"))
2727 (END
2728 (insert "</pre>\n")
2729 (org-parse-begin-paragraph))))
2730 (t (error "Unknown environment %s" style))))
2733 (defun org-html-begin-environment (style)
2734 (org-html-format-environment style 'BEGIN))
2736 (defun org-html-end-environment (style)
2737 (org-html-format-environment style 'END))
2740 ;;;_ , list
2741 (defun org-html-html-list-type-to-canonical-list-type (ltype)
2742 (cdr (assoc ltype '(("o" . ordered)
2743 ("u" . unordered)
2744 ("d" . description)))))
2746 (defun org-html-begin-list (ltype &optional arg1)
2747 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2748 ltype))
2750 (case ltype
2751 (ordered (let ((extra (if arg1 (format " start=\"%d\"" arg1) "")))
2752 (org-html-insert-tag "<ol%s>" extra)))
2753 (unordered (org-html-insert-tag "<ul>"))
2754 (description (org-html-insert-tag "<dl>"))
2755 (t (error "Unknown list type: %s" ltype))))
2757 (defun org-html-end-list (ltype)
2758 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2759 ltype))
2761 (org-html-insert-tag
2762 (case ltype
2763 (ordered "</ol>")
2764 (unordered "</ul>")
2765 (description "</dl>")
2766 (t (error "Unknown list type: %s" ltype)))))
2768 (defun org-html-begin-list-item (ltype &optional arg)
2769 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2770 ltype))
2771 (case ltype
2772 (ordered
2773 (let* ((counter arg)
2774 (extra (if counter (format " value=\"%s\"" counter) "")))
2775 (org-html-insert-tag "<li%s>" extra)))
2776 (unordered
2777 (let* ((id arg)
2778 (extra (if id (format " id=\"%s\"" id) "")))
2779 (org-html-insert-tag "<li%s>" extra)))
2780 (description
2781 (let* ((desc-tag (or arg "(no term)")))
2782 (insert
2783 (org-html-format-tags '("<dt>" . "</dt>") desc-tag))
2784 (org-html-insert-tag "<dd>")))
2785 (t (error "Unknown list type"))))
2787 (defun org-html-end-list-item (ltype)
2788 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2789 ltype))
2790 (case ltype
2791 (ordered (org-html-insert-tag "</li>"))
2792 (unordered (org-html-insert-tag "</li>"))
2793 (description (org-html-insert-tag "</dd>"))
2794 (t (error "Unknown list type"))))
2797 ;;;_ , table
2799 (defvar org-table-rowgroup-info)
2800 (defun org-parse-begin-table-rowgroup (&optional is-header-row)
2801 (push (cons (1+ org-table-rownum) :start) org-table-rowgroup-info)
2802 (org-parse-begin 'TABLE-ROWGROUP is-header-row))
2804 (defun org-html-begin-table-rowgroup (&optional is-header-row)
2805 (when org-table-rowgroup-open
2806 (org-parse-end 'TABLE-ROWGROUP))
2807 (org-html-insert-tag (if is-header-row "<thead>" "<tbody>"))
2808 (setq org-table-rowgroup-open t)
2809 (setq org-table-current-rowgroup-is-header is-header-row))
2811 (defun org-html-end-table-rowgroup ()
2812 (when org-table-rowgroup-open
2813 (setq org-table-rowgroup-open nil)
2814 (org-html-insert-tag
2815 (if org-table-current-rowgroup-is-header "</thead>" "</tbody>"))))
2817 (defun org-html-begin-table (caption label attributes)
2818 (let ((html-table-tag
2819 (org-export-splice-attributes html-table-tag attributes)))
2820 (when label
2821 (setq html-table-tag
2822 (org-export-splice-attributes
2823 html-table-tag
2824 (format "id=\"%s\"" (org-solidify-link-text label)))))
2825 (org-html-insert-tag html-table-tag))
2827 ;; Since the output of HTML table formatter can also be used in
2828 ;; DocBook document, we want to always include the caption to make
2829 ;; DocBook XML file valid.
2830 (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
2832 (defun org-parse-end-table ()
2833 (when org-table-is-styled
2834 ;; column groups
2835 (unless (car org-table-colgroup-info)
2836 (setq org-table-colgroup-info
2837 (cons :start (cdr org-table-colgroup-info))))
2839 ;; column alignment
2840 (let ((c -1))
2841 (mapc
2842 (lambda (x)
2843 (incf c)
2844 (setf (aref org-table-colalign-vector c)
2845 (or (aref org-table-colalign-vector c)
2846 (if (> (/ (float x) (1+ org-table-rownum))
2847 org-table-number-fraction)
2848 "right" "left"))))
2849 org-table-num-numeric-items-per-column)))
2850 (org-parse-end 'TABLE))
2852 (defun org-html-end-table ()
2853 (when org-table-is-styled
2854 (goto-char org-table-begin-marker)
2855 (setq org-table-begin-marker nil)
2857 (let ((c -1) gr colgropen)
2858 (insert
2859 (mapconcat
2860 (lambda (x)
2861 (incf c)
2862 (setq gr (pop org-table-colgroup-info))
2864 (concat
2865 (if (memq gr '(:start :startend))
2866 (prog1
2867 (if colgropen
2868 "</colgroup>\n<colgroup>"
2869 "<colgroup>")
2870 (setq colgropen t))
2873 (let* ((align (aref org-table-colalign-vector c))
2874 (alignspec (if no-css " align=\"%s\"" " class=\"%s\""))
2875 (extra (format alignspec align)))
2876 (format "<col%s />" extra))
2878 (if (memq gr '(:end :startend))
2879 (progn (setq colgropen nil) "</colgroup>")
2880 "")))
2881 org-table-num-numeric-items-per-column ""))
2883 (if colgropen (insert "</colgroup>")))
2885 ;; fill style attributes for table cells
2886 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
2887 (let ((c (string-to-number (match-string 1))))
2888 (replace-match
2889 (if org-export-html-table-align-individual-fields
2890 (format (if no-css " align=\"%s\"" " class=\"%s\"")
2891 (or (aref org-table-colalign-vector c) "left")) "")
2892 t t)))
2893 (goto-char (point-max)))
2894 (org-html-insert-tag "</table>\n"))
2896 (defun org-html-format-table-row (row)
2897 (org-html-format-tags
2898 (cons (eval (car org-export-table-row-tags))
2899 (eval (cdr org-export-table-row-tags))) row))
2901 (defun org-html-format-table-cell (text r c)
2902 (let ((cell-style-cookie (or (and org-table-is-styled
2903 (format "@@class%03d@@" c)) "")))
2904 (cond
2905 (org-table-current-rowgroup-is-header
2906 (org-html-format-tags
2907 org-export-table-header-tags text "col" cell-style-cookie))
2908 ((and (= c 0) org-export-html-table-use-header-tags-for-first-column)
2909 (org-html-format-tags
2910 org-export-table-header-tags text "row" cell-style-cookie))
2912 (org-html-format-tags
2913 org-export-table-data-tags text cell-style-cookie)))))
2916 ;;;_ , footnote definition
2917 (defun org-html-begin-footnote-definition (n)
2918 (org-parse-begin-paragraph 'footnote)
2919 (insert
2920 (format
2921 (format org-export-html-footnote-format
2922 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
2923 n n n)))
2925 (defun org-html-end-footnote-definition (n)
2926 (org-parse-end-paragraph))
2930 ;;;_ . format callbacks
2932 (defvar org-html-protect nil)
2933 ;;;_ , spaces
2934 (defun org-html-format-spaces (n)
2935 (let ((space (or (and org-html-protect "\\nbsp") "&nbsp;")) out)
2936 (while (> n 0)
2937 (setq out (concat out space))
2938 (setq n (1- n))) out))
2940 ;;;_ , tabs
2941 (defun org-html-format-tabs (&optional n)
2942 (ignore))
2944 ;;;_ , line break
2945 (defun org-html-format-line-break ()
2946 (org-html-format-tags '("<br>" . "</br>") ""))
2948 ;;;_ , horizontal line
2949 (defun org-html-format-horizontal-line ()
2950 (concat "\n" "<hr/>" "\n"))
2952 ;;;_ , line
2954 (defun org-html-format-plain (line)
2955 (case org-parse-dyn-current-environment
2956 ((quote fixedwidth) (concat (org-html-protect line) "\n"))
2957 (t (concat line "\n"))))
2959 (defun org-html-format-comment (fmt &rest args)
2960 (let ((comment (apply 'format fmt args)))
2961 (format "\n<!-- %s -->\n" comment)))
2964 ;;;_ , character styles
2965 (defun org-html-format-fontify (text style &optional id)
2966 (let (class extra how)
2967 (cond
2968 ((eq style 'underline)
2969 (setq extra " style=\"text-decoration:underline;\"" ))
2970 ((setq how (cdr (assoc style
2971 '((bold . ("<b>" . "</b>"))
2972 (emphasis . ("<i>" . "</i>"))
2973 (code . ("<code>" . "</code>"))
2974 (verbatim . ("<code>" . "</code>"))
2975 (strike . ("<del>" . "</del>"))
2976 (subscript . ("<sub>" . "</sub>"))
2977 (superscript . ("<sup>" . "</sup>")))))))
2978 ((listp style)
2979 (setq class (mapconcat 'identity style " ")))
2980 ((stringp style)
2981 (setq class style))
2982 (t (error "Unknown style %S" style)))
2984 (setq extra (concat (when class (format " class=\"%s\"" class))
2985 (when id (format " id=\"%s\"" id))
2986 extra))
2987 (org-html-format-tags
2988 (or how '("<span%s>" . "</span>")) text extra)))
2990 ;;;_ , link
2991 (defun org-html-format-link (text href &optional extra)
2992 (let* ((extra (concat (format " href=\"%s\"" href) extra)))
2993 (org-html-format-tags '("<a%s>" . "</a>") text extra)))
2995 ;;;_ , heading
2996 (defun org-html-format-heading (text level &optional id class)
2997 (let* ((extra (concat
2998 (when id (format " id=\"%s\"" id))
2999 (when class (format " class=\"%s\"" class)))))
3000 ;; (org-html-format-tags
3001 ;; text '("<h%d%s>" . "</h%d>") level extra)
3003 ;; Also look at org-export-html-preamble-format
3004 (concat
3005 (format "<h%d%s>" level extra) text (format "</h%d>" level))))
3007 ;;;_ , headline
3008 (defun org-html-format-headline (title extra-targets tags
3009 &optional snumber level)
3010 (concat
3011 (org-parse-format 'EXTRA-TARGETS extra-targets)
3012 (concat (org-parse-format 'SECTION-NUMBER snumber level) " ")
3013 title
3014 (and tags (concat (org-parse-format 'SPACES 3)
3015 (org-parse-format 'ORG-TAGS tags)))))
3017 ;;;_ , anchor
3018 (defun org-html-format-anchor (text name &optional class)
3019 (let* ((id name)
3020 (extra (concat
3021 (when name (format " name=\"%s\"" name))
3022 (when id (format " id=\"%s\"" id))
3023 (when class (format " class=\"%s\"" class)))))
3024 (org-html-format-tags '("<a%s>" . "</a>") text extra)))
3028 ;;;_ , target
3029 ;;;_ , footnote reference
3030 (defun org-html-format-footnote-reference (n def refcnt)
3031 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
3032 (format org-export-html-footnote-format
3033 (format
3034 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
3035 n extra n n))))
3039 ;;;_ , footnotes section
3040 (defun org-html-format-footnotes-section (section-name definitions)
3041 (if (not definitions) ""
3042 (format org-export-html-footnotes-section section-name definitions)))
3045 ;;;_ , image
3046 ;;;_ , generic
3047 (defun org-html-format-tags (tag text &rest args)
3048 (let ((prefix (when org-html-protect "@"))
3049 (suffix (when org-html-protect "@")))
3050 (concat prefix (apply 'format (car tag) args)
3051 text
3052 suffix (format (cdr tag)))))
3055 ;;;_ . maintenance callbacks
3056 ;;;_ , init method
3057 ;;;_ , save method
3058 ;;;_ , cleanup method
3059 ;;;_ . get callback
3060 (defun org-html-get (what &optional opt-plist)
3061 (case what
3062 (BACKEND 'html)
3063 (INIT-METHOD nil)
3064 (SAVE-METHOD nil)
3065 (CLEANUP-METHOD nil)
3066 (EXPORT-DIR (org-export-directory :html opt-plist))
3067 (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
3068 (EXPORT-BUFFER-NAME "*Org HTML Export*")
3069 (ENTITY-CONTROL org-html-entity-control-callbacks-alist)
3070 (ENTITY-FORMAT org-html-entity-format-callbacks-alist)
3071 (t (error "Unknown property: %s" what))))
3074 ;;;_ , coding system
3075 (defun org-html-get-coding-system-for-write ()
3076 (or org-export-html-coding-system
3077 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
3079 (defun org-html-get-coding-system-for-save ()
3080 (or org-export-html-coding-system
3081 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
3084 ;;;_. newhtml (non-parser & misc)
3085 (defun org-html-insert-toc (toc)
3086 ;; locate where toc needs to be inserted
3087 (goto-char (point-min))
3088 (if (or (re-search-forward
3089 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3090 (re-search-forward
3091 "\\[TABLE-OF-CONTENTS\\]" nil t))
3092 (progn
3093 (goto-char (match-beginning 0))
3094 (replace-match ""))
3095 (goto-char org-html-dyn-first-heading-pos)
3096 (when (looking-at "\\s-*</p>")
3097 (goto-char (match-end 0))
3098 (insert "\n")))
3099 (insert toc))
3101 (defun org-html-insert-preamble (opt-plist)
3102 (when (plist-get opt-plist :html-preamble)
3103 (let ((html-pre (plist-get opt-plist :html-preamble))
3104 (title (plist-get opt-plist :title))
3105 (date (plist-get opt-plist :effective-date))
3106 (author (plist-get opt-plist :author))
3107 (lang-words (plist-get opt-plist :lang-words))
3108 (email (plist-get opt-plist :email)))
3109 (cond ((stringp html-pre)
3110 (insert
3111 (format-spec html-pre `((?t . ,title) (?a . ,author)
3112 (?d . ,date) (?e . ,email)))))
3113 ((functionp html-pre)
3114 (funcall html-pre opt-plist))
3116 (insert
3117 (format-spec
3118 (or (cadr (assoc (nth 0 lang-words)
3119 org-export-html-preamble-format))
3120 (cadr (assoc "en" org-export-html-preamble-format)))
3121 `((?t . ,title) (?a . ,author)
3122 (?d . ,date) (?e . ,email)))))))))
3124 (defun org-html-insert-postamble (opt-plist)
3125 (when org-html-footnote-definitions
3126 (insert
3127 (org-parse-format
3128 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
3129 (mapconcat (lambda (x) (cdr x))
3130 (nreverse org-html-footnote-definitions) "\n"))))
3131 (let ((bib (org-export-html-get-bibliography)))
3132 (when bib
3133 (insert "\n" bib "\n")))
3135 ;; export html postamble
3136 (unless body-only
3137 (let* ((html-post (plist-get opt-plist :html-postamble))
3138 (date (plist-get opt-plist :effective-date))
3139 (author (plist-get opt-plist :author))
3140 (email (plist-get opt-plist :email))
3141 (lang-words (plist-get opt-plist :lang-words))
3142 (html-validation-link (or org-export-html-validation-link ""))
3143 (email
3144 (mapconcat (lambda(e)
3145 (format "<a href=\"mailto:%s\">%s</a>" e e))
3146 (split-string email ",+ *")
3147 ", "))
3148 (creator-info
3149 (concat "Org version " org-version " with Emacs version "
3150 (number-to-string emacs-major-version))))
3151 (when (plist-get opt-plist :html-postamble)
3152 (cond ((stringp html-post)
3153 (insert "<div id=\"postamble\">\n")
3154 (insert (format-spec html-post
3155 `((?a . ,author) (?e . ,email)
3156 (?d . ,date) (?c . ,creator-info)
3157 (?v . ,html-validation-link))))
3158 (insert "</div>"))
3159 ((functionp html-post)
3160 (funcall html-post opt-plist))
3161 ((eq html-post 'auto)
3162 ;; fall back on default postamble
3163 (insert "<div id=\"postamble\">\n")
3164 (when (plist-get opt-plist :time-stamp-file)
3165 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
3166 (when (and (plist-get opt-plist :author-info) author)
3167 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
3168 (when (and (plist-get opt-plist :email-info) email)
3169 (insert "<p class=\"email\">" email "</p>\n"))
3170 (when (plist-get opt-plist :creator-info)
3171 (insert "<p class=\"creator\">"
3172 (concat "Org version " org-version " with Emacs version "
3173 (number-to-string emacs-major-version) "</p>\n")))
3174 (insert html-validation-link "\n</div>"))
3176 (insert "<div id=\"postamble\">\n")
3177 (insert (format-spec
3178 (or (cadr (assoc (nth 0 lang-words)
3179 org-export-html-postamble-format))
3180 (cadr (assoc "en" org-export-html-postamble-format)))
3181 `((?a . ,author) (?e . ,email)
3182 (?d . ,date) (?c . ,creator-info)
3183 (?v . ,html-validation-link))))
3184 (insert "</div>"))))))
3186 (if org-export-html-with-timestamp
3187 (insert org-export-html-html-helper-timestamp)))
3190 (defun org-html-format-todo (todo)
3191 (org-parse-format 'FONTIFY
3192 (org-export-html-get-todo-kwd-class-name todo)
3193 (list (if (member todo org-done-keywords) "done" "todo")
3194 todo)))
3198 (defun org-html-format-extra-targets (extra-targets)
3199 (if (not extra-targets) ""
3200 (mapconcat (lambda (x)
3201 (setq x (org-solidify-link-text
3202 (if (org-uuidgen-p x) (concat "ID-" x) x)))
3203 (org-parse-format 'ANCHOR "" x))
3204 extra-targets "")))
3206 (defun org-html-format-org-tags (tags)
3207 (if (not tags) ""
3208 (org-parse-format
3209 'FONTIFY (mapconcat
3210 (lambda (x)
3211 (org-parse-format
3212 'FONTIFY x (org-export-html-get-tag-class-name x)))
3213 (org-split-string tags ":")
3214 (org-parse-format 'SPACES 1)) "tag")))
3216 (defun org-html-format-section-number (&optional snumber level)
3217 (and org-export-with-section-numbers
3218 (not body-only) snumber level
3219 (org-parse-format 'FONTIFY snumber (format "section-number-%d" level))))
3221 ;;;_. preprocessor
3222 ;;;_. postamble
3224 (provide 'org-html)
3226 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
3227 ;;; org-html.el ends here