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