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