Release 6.27
[org-mode/org-tableheadings.git] / lisp / org-html.el
blob16cf937146538758d6322662cd7585b20dce95e7
1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
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.27
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)
31 (declare-function org-id-find-id-file "org-id" (id))
32 (declare-function htmlize-region "ext:htmlize" (beg end))
34 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
35 <h2 class=\"footnotes\">%s: </h2>
36 <div id=\"text-footnotes\">
38 </div>
39 </div>"
40 "Format for the footnotes section.
41 Should contain a two instances of %s. The first will be replaced with the
42 language-specific word for \"Footnotes\", the second one will be replaced
43 by the footnotes themselves."
44 :group 'org-export-html
45 :type 'string)
47 (defgroup org-export-html nil
48 "Options specific for HTML export of Org-mode files."
49 :tag "Org Export HTML"
50 :group 'org-export)
52 (defcustom org-export-html-coding-system nil
53 "Coding system for HTML export, defaults to buffer-file-coding-system."
54 :group 'org-export-html
55 :type 'coding-system)
57 (defcustom org-export-html-extension "html"
58 "The extension for exported HTML files."
59 :group 'org-export-html
60 :type 'string)
62 (defcustom org-export-html-xml-declaration
63 "<?xml version=\"1.0\" encoding=\"%s\"?>"
64 "The extension for exported HTML files.
65 %s will be replaced with the charset of the exported file."
66 :group 'org-export-html
67 :type 'string)
69 (defcustom org-export-html-style-include-scripts t
70 "Non-nil means, include the javascript snippets in exported HTML files.
71 The actual script is defined in `org-export-html-scripts' and should
72 not be modified."
73 :group 'org-export-html
74 :type 'boolean)
76 (defconst org-export-html-scripts
77 "<script type=\"text/javascript\">
78 <!--/*--><![CDATA[/*><!--*/
79 function CodeHighlightOn(elem, id)
81 var target = document.getElementById(id);
82 if(null != target) {
83 elem.cacheClassElem = elem.className;
84 elem.cacheClassTarget = target.className;
85 target.className = \"code-highlighted\";
86 elem.className = \"code-highlighted\";
89 function CodeHighlightOff(elem, id)
91 var target = document.getElementById(id);
92 if(elem.cacheClassElem)
93 elem.className = elem.cacheClassElem;
94 if(elem.cacheClassTarget)
95 target.className = elem.cacheClassTarget;
97 /*]]>*///-->
98 </script>"
99 "Basic javascript that is needed by HTML files produced by Org-mode.")
101 (defconst org-export-html-style-default
102 "<style type=\"text/css\">
103 <!--/*--><![CDATA[/*><!--*/
104 html { font-family: Times, serif; font-size: 12pt; }
105 .title { text-align: center; }
106 .todo { color: red; }
107 .done { color: green; }
108 .tag { background-color: #add8e6; font-weight:normal }
109 .target { }
110 .timestamp { color: #bebebe; }
111 .timestamp-kwd { color: #5f9ea0; }
112 p.verse { margin-left: 3% }
113 pre {
114 border: 1pt solid #AEBDCC;
115 background-color: #F3F5F7;
116 padding: 5pt;
117 font-family: courier, monospace;
118 font-size: 90%;
119 overflow:auto;
121 table { border-collapse: collapse; }
122 td, th { vertical-align: top; }
123 dt { font-weight: bold; }
124 div.figure { padding: 0.5em; }
125 div.figure p { text-align: center; }
126 .linenr { font-size:smaller }
127 .code-highlighted {background-color:#ffff00;}
128 .org-info-js_info-navigation { border-style:none; }
129 #org-info-js_console-label { font-size:10px; font-weight:bold;
130 white-space:nowrap; }
131 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
132 font-weight:bold; }
133 /*]]>*/-->
134 </style>"
135 "The default style specification for exported HTML files.
136 Please use the variables `org-export-html-style' and
137 `org-export-html-style-extra' to add to this style. If you wish to not
138 have the default style included, customize the variable
139 `org-export-html-style-include-default'.")
141 (defcustom org-export-html-style-include-default t
142 "Non-nil means, include the default style in exported HTML files.
143 The actual style is defined in `org-export-html-style-default' and should
144 not be modified. Use the variables `org-export-html-style' to add
145 your own style information."
146 :group 'org-export-html
147 :type 'boolean)
148 ;;;###autoload
149 (put 'org-export-html-style 'safe-local-variable 'booleanp)
151 (defcustom org-export-html-style ""
152 "Org-wide style definitions for exported HTML files.
154 This variable needs to contain the full HTML structure to provide a style,
155 including the surrounding HTML tags. If you set the value of this variable,
156 you should consider to include definitions for the following classes:
157 title, todo, done, timestamp, timestamp-kwd, tag, target.
159 For example, a valid value would be:
161 <style type=\"text/css\">
162 <![CDATA[
163 p { font-weight: normal; color: gray; }
164 h1 { color: black; }
165 .title { text-align: center; }
166 .todo, .timestamp-kwd { color: red; }
167 .done { color: green; }
169 </style>
171 If you'd like to refer to en external style file, use something like
173 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
175 As the value of this option simply gets inserted into the HTML <head> header,
176 you can \"misuse\" it to add arbitrary text to the header.
177 See also the variable `org-export-html-style-extra'."
178 :group 'org-export-html
179 :type 'string)
180 ;;;###autoload
181 (put 'org-export-html-style 'safe-local-variable 'stringp)
183 (defcustom org-export-html-style-extra ""
184 "Additional style information for HTML export.
185 The value of this variable is inserted into the HTML buffer right after
186 the value of `org-export-html-style'. Use this variable for per-file
187 settings of style information, and do not forget to surround the style
188 settings with <style>...</style> tags."
189 :group 'org-export-html
190 :type 'string)
191 ;;;###autoload
192 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
194 (defcustom org-export-html-tag-class-prefix ""
195 "Prefix to clas names for TODO keywords.
196 Each tag gets a class given by the tag itself, with this prefix.
197 The default prefix is empty because it is nice to just use the keyword
198 as a class name. But if you get into conflicts with other, existing
199 CSS classes, then this prefic can be very useful."
200 :group 'org-export-html
201 :type 'string)
203 (defcustom org-export-html-todo-kwd-class-prefix ""
204 "Prefix to clas names for TODO keywords.
205 Each TODO keyword gets a class given by the keyword itself, with this prefix.
206 The default prefix is empty because it is nice to just use the keyword
207 as a class name. But if you get into conflicts with other, existing
208 CSS classes, then this prefic can be very useful."
209 :group 'org-export-html
210 :type 'string)
212 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
213 "Format for typesetting the document title in HTML export."
214 :group 'org-export-html
215 :type 'string)
217 (defcustom org-export-html-toplevel-hlevel 2
218 "The <H> level for level 1 headings in HTML export.
219 This is also important for the classes that will be wrapped around headlines
220 and outline structure. If this variable is 1, the top-level headlines will
221 be <h1>, and the corresponding classes will be outline-1, section-number-1,
222 and outline-text-1. If this is 2, all of these will get a 2 instead.
223 The default for this variable is 2, because we use <h1> for formatting the
224 document title."
225 :group 'org-export-html
226 :type 'string)
228 (defcustom org-export-html-link-org-files-as-html t
229 "Non-nil means, make file links to `file.org' point to `file.html'.
230 When org-mode is exporting an org-mode file to HTML, links to
231 non-html files are directly put into a href tag in HTML.
232 However, links to other Org-mode files (recognized by the
233 extension `.org.) should become links to the corresponding html
234 file, assuming that the linked org-mode file will also be
235 converted to HTML.
236 When nil, the links still point to the plain `.org' file."
237 :group 'org-export-html
238 :type 'boolean)
240 (defcustom org-export-html-inline-images 'maybe
241 "Non-nil means, inline images into exported HTML pages.
242 This is done using an <img> tag. When nil, an anchor with href is used to
243 link to the image. If this option is `maybe', then images in links with
244 an empty description will be inlined, while images with a description will
245 be linked only."
246 :group 'org-export-html
247 :type '(choice (const :tag "Never" nil)
248 (const :tag "Always" t)
249 (const :tag "When there is no description" maybe)))
251 (defcustom org-export-html-inline-image-extensions
252 '("png" "jpeg" "jpg" "gif")
253 "Extensions of image files that can be inlined into HTML."
254 :group 'org-export-html
255 :type '(repeat (string :tag "Extension")))
257 (defcustom org-export-html-table-tag
258 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
259 "The HTML tag that is used to start a table.
260 This must be a <table> tag, but you may change the options like
261 borders and spacing."
262 :group 'org-export-html
263 :type 'string)
265 (defcustom org-export-table-header-tags '("<th scope=\"%s\">" . "</th>")
266 "The opening tag for table header fields.
267 This is customizable so that alignment options can be specified.
268 %s will be filled with the scope of the field, either row or col.
269 See also the variable `org-export-html-table-use-header-tags-for-first-column'."
270 :group 'org-export-tables
271 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
273 (defcustom org-export-table-data-tags '("<td>" . "</td>")
274 "The opening tag for table data fields.
275 This is customizable so that alignment options can be specified."
276 :group 'org-export-tables
277 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
279 (defcustom org-export-html-table-use-header-tags-for-first-column nil
280 "Non-nil means, format column one in tables with header tags.
281 When nil, also column one will use data tags."
282 :group 'org-export-tables
283 :type 'boolean)
285 (defcustom org-export-html-validation-link nil
286 "Non-nil means, add validationlink to postamble of HTML exported files."
287 :group 'org-export-html
288 :type '(choice
289 (const :tag "Nothing" nil)
290 (const :tag "XHTML 1.0" "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a></p>")
291 (string :tag "Specify full HTML")))
294 (defcustom org-export-html-with-timestamp nil
295 "If non-nil, write `org-export-html-html-helper-timestamp'
296 into the exported HTML text. Otherwise, the buffer will just be saved
297 to a file."
298 :group 'org-export-html
299 :type 'boolean)
301 (defcustom org-export-html-html-helper-timestamp
302 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
303 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
304 :group 'org-export-html
305 :type 'string)
307 (defgroup org-export-htmlize nil
308 "Options for processing examples with htmlize.el."
309 :tag "Org Export Htmlize"
310 :group 'org-export-html)
312 (defcustom org-export-htmlize-output-type 'inline-css
313 "Output type to be used by htmlize when formatting code snippets.
314 We use as default `inline-css', in order to make the resulting
315 HTML self-containing.
316 However, this will fail when using Emacs in batch mode for export, because
317 then no rich font definitions are in place. It will also not be good if
318 people with different Emacs setup contribute HTML files to a website,
319 because the fonts will represent the individual setups. In these cases,
320 it is much better to let Org/Htmlize assign classes only, and to use
321 a style file to define the look of these classes.
322 To get a start for your css file, start Emacs session nnd make sure that
323 all the faces you are interested in are defined, for example by loading files
324 in all modes you want. Then, use the command
325 \\[org-export-htmlize-generate-css] to extract class definitions."
326 :group 'org-export-htmlize
327 :type '(choice (const css) (const inline-css)))
329 (defcustom org-export-htmlize-css-font-prefix "org-"
330 "The prefix for CSS class names for htmlize font specifications."
331 :group 'org-export-htmlize
332 :type 'string)
334 (defcustom org-export-htmlized-org-css-url nil
335 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
336 Normally when creating an htmlized version of an Org buffer, htmlize will
337 create CSS to define the font colors. However, this does not work when
338 converting in batch mode, and it also can look bad if different people
339 with different fontification setup work on the same website.
340 When this variable is non-nil, creating an htmlized version of an Org buffer
341 using `org-export-as-org' will remove the internal CSS section and replace it
342 with a link to this URL."
343 :group 'org-export-htmlize
344 :type '(choice
345 (const :tag "Keep internal css" nil)
346 (string :tag "URL or local href")))
348 ;;; Variables, constants, and parameter plists
350 (defvar org-export-html-preamble nil
351 "Preamble, to be inserted just before <body>. Set by publishing functions.")
352 (defvar org-export-html-postamble nil
353 "Preamble, to be inserted just after </body>. Set by publishing functions.")
354 (defvar org-export-html-auto-preamble t
355 "Should default preamble be inserted? Set by publishing functions.")
356 (defvar org-export-html-auto-postamble t
357 "Should default postamble be inserted? Set by publishing functions.")
359 ;;; Hooks
361 (defvar org-export-html-after-blockquotes-hook nil
362 "Hook run during HTML export, after blockquote, verse, center are done.")
364 ;;; HTML export
366 (defun org-export-html-preprocess (parameters)
367 ;; Convert LaTeX fragments to images
368 (when (and org-current-export-file
369 (plist-get parameters :LaTeX-fragments))
370 (org-format-latex
371 (concat "ltxpng/" (file-name-sans-extension
372 (file-name-nondirectory
373 org-current-export-file)))
374 org-current-export-dir nil "Creating LaTeX image %s"))
375 (message "Exporting..."))
377 ;;;###autoload
378 (defun org-export-as-html-and-open (arg)
379 "Export the outline as HTML and immediately open it with a browser.
380 If there is an active region, export only the region.
381 The prefix ARG specifies how many levels of the outline should become
382 headlines. The default is 3. Lower levels will become bulleted lists."
383 (interactive "P")
384 (org-export-as-html arg 'hidden)
385 (org-open-file buffer-file-name))
387 ;;;###autoload
388 (defun org-export-as-html-batch ()
389 "Call `org-export-as-html', may be used in batch processing as
390 emacs --batch
391 --load=$HOME/lib/emacs/org.el
392 --eval \"(setq org-export-headline-levels 2)\"
393 --visit=MyFile --funcall org-export-as-html-batch"
394 (org-export-as-html org-export-headline-levels 'hidden))
396 ;;;###autoload
397 (defun org-export-as-html-to-buffer (arg)
398 "Call `org-export-as-html` with output to a temporary buffer.
399 No file is created. The prefix ARG is passed through to `org-export-as-html'."
400 (interactive "P")
401 (org-export-as-html arg nil nil "*Org HTML Export*")
402 (when org-export-show-temporary-export-buffer
403 (switch-to-buffer-other-window "*Org HTML Export*")))
405 ;;;###autoload
406 (defun org-replace-region-by-html (beg end)
407 "Assume the current region has org-mode syntax, and convert it to HTML.
408 This can be used in any buffer. For example, you could write an
409 itemized list in org-mode syntax in an HTML buffer and then use this
410 command to convert it."
411 (interactive "r")
412 (let (reg html buf pop-up-frames)
413 (save-window-excursion
414 (if (org-mode-p)
415 (setq html (org-export-region-as-html
416 beg end t 'string))
417 (setq reg (buffer-substring beg end)
418 buf (get-buffer-create "*Org tmp*"))
419 (with-current-buffer buf
420 (erase-buffer)
421 (insert reg)
422 (org-mode)
423 (setq html (org-export-region-as-html
424 (point-min) (point-max) t 'string)))
425 (kill-buffer buf)))
426 (delete-region beg end)
427 (insert html)))
429 ;;;###autoload
430 (defun org-export-region-as-html (beg end &optional body-only buffer)
431 "Convert region from BEG to END in org-mode buffer to HTML.
432 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
433 contents, and only produce the region of converted text, useful for
434 cut-and-paste operations.
435 If BUFFER is a buffer or a string, use/create that buffer as a target
436 of the converted HTML. If BUFFER is the symbol `string', return the
437 produced HTML as a string and leave not buffer behind. For example,
438 a Lisp program could call this function in the following way:
440 (setq html (org-export-region-as-html beg end t 'string))
442 When called interactively, the output buffer is selected, and shown
443 in a window. A non-interactive call will only return the buffer."
444 (interactive "r\nP")
445 (when (interactive-p)
446 (setq buffer "*Org HTML Export*"))
447 (let ((transient-mark-mode t) (zmacs-regions t)
448 ext-plist rtn)
449 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
450 (goto-char end)
451 (set-mark (point)) ;; to activate the region
452 (goto-char beg)
453 (setq rtn (org-export-as-html
454 nil nil ext-plist
455 buffer body-only))
456 (if (fboundp 'deactivate-mark) (deactivate-mark))
457 (if (and (interactive-p) (bufferp rtn))
458 (switch-to-buffer-other-window rtn)
459 rtn)))
461 (defvar html-table-tag nil) ; dynamically scoped into this.
462 (defvar org-par-open nil)
463 ;;;###autoload
464 (defun org-export-as-html (arg &optional hidden ext-plist
465 to-buffer body-only pub-dir)
466 "Export the outline as a pretty HTML file.
467 If there is an active region, export only the region. The prefix
468 ARG specifies how many levels of the outline should become
469 headlines. The default is 3. Lower levels will become bulleted
470 lists. HIDDEN is obsolete and does nothing.
471 EXT-PLIST is a property list with external parameters overriding
472 org-mode's default settings, but still inferior to file-local
473 settings. When TO-BUFFER is non-nil, create a buffer with that
474 name and export to that buffer. If TO-BUFFER is the symbol
475 `string', don't leave any buffer behind but just return the
476 resulting HTML as a string. When BODY-ONLY is set, don't produce
477 the file header and footer, simply return the content of
478 <body>...</body>, without even the body tags themselves. When
479 PUB-DIR is set, use this as the publishing directory."
480 (interactive "P")
482 ;; Make sure we have a file name when we need it.
483 (when (and (not (or to-buffer body-only))
484 (not buffer-file-name))
485 (if (buffer-base-buffer)
486 (org-set-local 'buffer-file-name
487 (with-current-buffer (buffer-base-buffer)
488 buffer-file-name))
489 (error "Need a file name to be able to export.")))
491 (message "Exporting...")
492 (setq-default org-todo-line-regexp org-todo-line-regexp)
493 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
494 (setq-default org-done-keywords org-done-keywords)
495 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
496 (let* ((opt-plist
497 (org-export-process-option-filters
498 (org-combine-plists (org-default-export-plist)
499 ext-plist
500 (org-infile-export-plist))))
501 (style (concat (if (plist-get opt-plist :style-include-default)
502 org-export-html-style-default)
503 (plist-get opt-plist :style)
504 (plist-get opt-plist :style-extra)
505 "\n"
506 (if (plist-get opt-plist :style-include-scripts)
507 org-export-html-scripts)))
508 (html-extension (plist-get opt-plist :html-extension))
509 (link-validate (plist-get opt-plist :link-validation-function))
510 valid thetoc have-headings first-heading-pos
511 (odd org-odd-levels-only)
512 (region-p (org-region-active-p))
513 (rbeg (and region-p (region-beginning)))
514 (rend (and region-p (region-end)))
515 (subtree-p
516 (if (plist-get opt-plist :ignore-subree-p)
518 (when region-p
519 (save-excursion
520 (goto-char rbeg)
521 (and (org-at-heading-p)
522 (>= (org-end-of-subtree t t) rend))))))
523 (level-offset (if subtree-p
524 (save-excursion
525 (goto-char rbeg)
526 (+ (funcall outline-level)
527 (if org-odd-levels-only 1 0)))
529 (opt-plist (setq org-export-opt-plist
530 (if subtree-p
531 (org-export-add-subtree-options opt-plist rbeg)
532 opt-plist)))
533 ;; The following two are dynamically scoped into other
534 ;; routines below.
535 (org-current-export-dir
536 (or pub-dir (org-export-directory :html opt-plist)))
537 (org-current-export-file buffer-file-name)
538 (level 0) (line "") (origline "") txt todo
539 (umax nil)
540 (umax-toc nil)
541 (filename (if to-buffer nil
542 (expand-file-name
543 (concat
544 (file-name-sans-extension
545 (or (and subtree-p
546 (org-entry-get (region-beginning)
547 "EXPORT_FILE_NAME" t))
548 (file-name-nondirectory buffer-file-name)))
549 "." html-extension)
550 (file-name-as-directory
551 (or pub-dir (org-export-directory :html opt-plist))))))
552 (current-dir (if buffer-file-name
553 (file-name-directory buffer-file-name)
554 default-directory))
555 (buffer (if to-buffer
556 (cond
557 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
558 (t (get-buffer-create to-buffer)))
559 (find-file-noselect filename)))
560 (org-levels-open (make-vector org-level-max nil))
561 (date (plist-get opt-plist :date))
562 (author (plist-get opt-plist :author))
563 (title (or (and subtree-p (org-export-get-title-from-subtree))
564 (plist-get opt-plist :title)
565 (and (not
566 (plist-get opt-plist :skip-before-1st-heading))
567 (org-export-grab-title-from-buffer))
568 (and buffer-file-name
569 (file-name-sans-extension
570 (file-name-nondirectory buffer-file-name)))
571 "UNTITLED"))
572 (html-table-tag (plist-get opt-plist :html-table-tag))
573 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
574 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
575 (inquote nil)
576 (infixed nil)
577 (inverse nil)
578 (in-local-list nil)
579 (local-list-type nil)
580 (local-list-indent nil)
581 (llt org-plain-list-ordered-item-terminator)
582 (email (plist-get opt-plist :email))
583 (language (plist-get opt-plist :language))
584 (keywords (plist-get opt-plist :keywords))
585 (description (plist-get opt-plist :description))
586 (lang-words nil)
587 (head-count 0) cnt
588 (start 0)
589 (coding-system (and (boundp 'buffer-file-coding-system)
590 buffer-file-coding-system))
591 (coding-system-for-write (or org-export-html-coding-system
592 coding-system))
593 (save-buffer-coding-system (or org-export-html-coding-system
594 coding-system))
595 (charset (and coding-system-for-write
596 (fboundp 'coding-system-get)
597 (coding-system-get coding-system-for-write
598 'mime-charset)))
599 (region
600 (buffer-substring
601 (if region-p (region-beginning) (point-min))
602 (if region-p (region-end) (point-max))))
603 (lines
604 (org-split-string
605 (org-export-preprocess-string
606 region
607 :emph-multiline t
608 :for-html t
609 :skip-before-1st-heading
610 (plist-get opt-plist :skip-before-1st-heading)
611 :drawers (plist-get opt-plist :drawers)
612 :todo-keywords (plist-get opt-plist :todo-keywords)
613 :tags (plist-get opt-plist :tags)
614 :priority (plist-get opt-plist :priority)
615 :footnotes (plist-get opt-plist :footnotes)
616 :timestamps (plist-get opt-plist :timestamps)
617 :archived-trees
618 (plist-get opt-plist :archived-trees)
619 :select-tags (plist-get opt-plist :select-tags)
620 :exclude-tags (plist-get opt-plist :exclude-tags)
621 :add-text
622 (plist-get opt-plist :text)
623 :LaTeX-fragments
624 (plist-get opt-plist :LaTeX-fragments))
625 "[\r\n]"))
626 table-open type
627 table-buffer table-orig-buffer
628 ind item-type starter didclose
629 rpl path attr desc descp desc1 desc2 link
630 snumber fnc item-tag
631 footnotes footref-seen
632 id-file href
635 (let ((inhibit-read-only t))
636 (org-unmodified
637 (remove-text-properties (point-min) (point-max)
638 '(:org-license-to-kill t))))
640 (message "Exporting...")
642 (setq org-min-level (org-get-min-level lines level-offset))
643 (setq org-last-level org-min-level)
644 (org-init-section-numbers)
646 (cond
647 ((and date (string-match "%" date))
648 (setq date (format-time-string date)))
649 (date)
650 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
652 ;; Get the language-dependent settings
653 (setq lang-words (or (assoc language org-export-language-setup)
654 (assoc "en" org-export-language-setup)))
656 ;; Switch to the output buffer
657 (set-buffer buffer)
658 (let ((inhibit-read-only t)) (erase-buffer))
659 (fundamental-mode)
661 (and (fboundp 'set-buffer-file-coding-system)
662 (set-buffer-file-coding-system coding-system-for-write))
664 (let ((case-fold-search nil)
665 (org-odd-levels-only odd))
666 ;; create local variables for all options, to make sure all called
667 ;; functions get the correct information
668 (mapc (lambda (x)
669 (set (make-local-variable (nth 2 x))
670 (plist-get opt-plist (car x))))
671 org-export-plist-vars)
672 (setq umax (if arg (prefix-numeric-value arg)
673 org-export-headline-levels))
674 (setq umax-toc (if (integerp org-export-with-toc)
675 (min org-export-with-toc umax)
676 umax))
677 (unless body-only
678 ;; File header
679 (insert (format
681 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
682 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
683 <html xmlns=\"http://www.w3.org/1999/xhtml\"
684 lang=\"%s\" xml:lang=\"%s\">
685 <head>
686 <title>%s</title>
687 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
688 <meta name=\"generator\" content=\"Org-mode\"/>
689 <meta name=\"generated\" content=\"%s\"/>
690 <meta name=\"author\" content=\"%s\"/>
691 <meta name=\"description\" content=\"%s\"/>
692 <meta name=\"keywords\" content=\"%s\"/>
694 </head>
695 <body>
696 <div id=\"content\">
698 (format org-export-html-xml-declaration
699 (or charset "iso-8859-1"))
700 language language (org-html-expand title)
701 (or charset "iso-8859-1")
702 date author description keywords
703 style))
705 (insert (or (plist-get opt-plist :preamble) ""))
707 (when (plist-get opt-plist :auto-preamble)
708 (if title (insert (format org-export-html-title-format
709 (org-html-expand title))))))
711 (if (and org-export-with-toc (not body-only))
712 (progn
713 (push (format "<h%d>%s</h%d>\n"
714 org-export-html-toplevel-hlevel
715 (nth 3 lang-words)
716 org-export-html-toplevel-hlevel)
717 thetoc)
718 (push "<div id=\"text-table-of-contents\">\n" thetoc)
719 (push "<ul>\n<li>" thetoc)
720 (setq lines
721 (mapcar '(lambda (line)
722 (if (string-match org-todo-line-regexp line)
723 ;; This is a headline
724 (progn
725 (setq have-headings t)
726 (setq level (- (match-end 1) (match-beginning 1)
727 level-offset)
728 level (org-tr-level level)
729 txt (save-match-data
730 (org-html-expand
731 (org-export-cleanup-toc-line
732 (match-string 3 line))))
733 todo
734 (or (and org-export-mark-todo-in-toc
735 (match-beginning 2)
736 (not (member (match-string 2 line)
737 org-done-keywords)))
738 ; TODO, not DONE
739 (and org-export-mark-todo-in-toc
740 (= level umax-toc)
741 (org-search-todo-below
742 line lines level))))
743 (if (string-match
744 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
745 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
746 (if (string-match quote-re0 txt)
747 (setq txt (replace-match "" t t txt)))
748 (setq snumber (org-section-number level))
749 (if org-export-with-section-numbers
750 (setq txt (concat snumber " " txt)))
751 (if (<= level (max umax umax-toc))
752 (setq head-count (+ head-count 1)))
753 (if (<= level umax-toc)
754 (progn
755 (if (> level org-last-level)
756 (progn
757 (setq cnt (- level org-last-level))
758 (while (>= (setq cnt (1- cnt)) 0)
759 (push "\n<ul>\n<li>" thetoc))
760 (push "\n" thetoc)))
761 (if (< level org-last-level)
762 (progn
763 (setq cnt (- org-last-level level))
764 (while (>= (setq cnt (1- cnt)) 0)
765 (push "</li>\n</ul>" thetoc))
766 (push "\n" thetoc)))
767 ;; Check for targets
768 (while (string-match org-any-target-regexp line)
769 (setq line (replace-match
770 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
771 t t line)))
772 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
773 (setq txt (replace-match "" t t txt)))
774 (setq href (format "sec-%s" snumber))
775 (setq href (or (cdr (assoc href org-export-preferred-target-alist)) href))
776 (push
777 (format
778 (if todo
779 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
780 "</li>\n<li><a href=\"#%s\">%s</a>")
781 href txt) thetoc)
783 (setq org-last-level level))
785 line)
786 lines))
787 (while (> org-last-level (1- org-min-level))
788 (setq org-last-level (1- org-last-level))
789 (push "</li>\n</ul>\n" thetoc))
790 (push "</div>\n" thetoc)
791 (setq thetoc (if have-headings (nreverse thetoc) nil))))
793 (setq head-count 0)
794 (org-init-section-numbers)
796 (org-open-par)
798 (while (setq line (pop lines) origline line)
799 (catch 'nextline
801 ;; end of quote section?
802 (when (and inquote (string-match "^\\*+ " line))
803 (insert "</pre>\n")
804 (org-open-par)
805 (setq inquote nil))
806 ;; inside a quote section?
807 (when inquote
808 (insert (org-html-protect line) "\n")
809 (throw 'nextline nil))
811 ;; Fixed-width, verbatim lines (examples)
812 (when (and org-export-with-fixed-width
813 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
814 (when (not infixed)
815 (setq infixed t)
816 (org-close-par-maybe)
818 (insert "<pre class=\"example\">\n"))
819 (insert (org-html-protect (match-string 3 line)) "\n")
820 (when (or (not lines)
821 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
822 (car lines))))
823 (setq infixed nil)
824 (insert "</pre>\n")
825 (org-open-par))
826 (throw 'nextline nil))
828 ;; Protected HTML
829 (when (get-text-property 0 'org-protected line)
830 (let (par)
831 (when (re-search-backward
832 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
833 (setq par (match-string 1))
834 (replace-match "\\2\n"))
835 (insert line "\n")
836 (while (and lines
837 (or (= (length (car lines)) 0)
838 (get-text-property 0 'org-protected (car lines))))
839 (insert (pop lines) "\n"))
840 (and par (insert "<p>\n")))
841 (throw 'nextline nil))
843 ;; Horizontal line
844 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
845 (if org-par-open
846 (insert "\n</p>\n<hr/>\n<p>\n")
847 (insert "\n<hr/>\n"))
848 (throw 'nextline nil))
850 ;; Blockquotes, verse, and center
851 (when (equal "ORG-BLOCKQUOTE-START" line)
852 (org-close-par-maybe)
853 (insert "<blockquote>\n")
854 (org-open-par)
855 (throw 'nextline nil))
856 (when (equal "ORG-BLOCKQUOTE-END" line)
857 (org-close-par-maybe)
858 (insert "\n</blockquote>\n")
859 (org-open-par)
860 (throw 'nextline nil))
861 (when (equal "ORG-VERSE-START" line)
862 (org-close-par-maybe)
863 (insert "\n<p class=\"verse\">\n")
864 (setq inverse t)
865 (throw 'nextline nil))
866 (when (equal "ORG-VERSE-END" line)
867 (insert "</p>\n")
868 (org-open-par)
869 (setq inverse nil)
870 (throw 'nextline nil))
871 (when (equal "ORG-CENTER-START" line)
872 (org-close-par-maybe)
873 (insert "\n<div style=\"text-align: center\">")
874 (org-open-par)
875 (throw 'nextline nil))
876 (when (equal "ORG-CENTER-END" line)
877 (org-close-par-maybe)
878 (insert "\n</div>")
879 (org-open-par)
880 (throw 'nextline nil))
881 (run-hooks 'org-export-html-after-blockquotes-hook)
882 (when inverse
883 (let ((i (org-get-string-indentation line)))
884 (if (> i 0)
885 (setq line (concat (mapconcat 'identity
886 (make-list (* 2 i) "\\nbsp") "")
887 " " (org-trim line))))
888 (unless (string-match "\\\\\\\\[ \t]*$" line)
889 (setq line (concat line "\\\\")))))
891 ;; make targets to anchors
892 (while (string-match
893 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
894 (cond
895 ((match-end 2)
896 (setq line (replace-match
897 (format
898 "@<a name=\"%s\" id=\"%s\">@</a>"
899 (org-solidify-link-text (match-string 1 line))
900 (org-solidify-link-text (match-string 1 line)))
901 t t line)))
902 ((and org-export-with-toc (equal (string-to-char line) ?*))
903 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
904 (setq line (replace-match
905 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
906 ; (concat "@<i>" (match-string 1 line) "@</i> ")
907 t t line)))
909 (setq line (replace-match
910 (concat "@<a name=\""
911 (org-solidify-link-text (match-string 1 line))
912 "\" class=\"target\">" (match-string 1 line) "@</a> ")
913 t t line)))))
915 (setq line (org-html-handle-time-stamps line))
917 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
918 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
919 ;; Also handle sub_superscripts and checkboxes
920 (or (string-match org-table-hline-regexp line)
921 (setq line (org-html-expand line)))
923 ;; Format the links
924 (setq start 0)
925 (while (string-match org-bracket-link-analytic-regexp++ line start)
926 (setq start (match-beginning 0))
927 (setq path (save-match-data (org-link-unescape
928 (match-string 3 line))))
929 (setq type (cond
930 ((match-end 2) (match-string 2 line))
931 ((save-match-data
932 (or (file-name-absolute-p path)
933 (string-match "^\\.\\.?/" path)))
934 "file")
935 (t "internal")))
936 (setq path (org-extract-attributes (org-link-unescape path)))
937 (setq attr (get-text-property 0 'org-attributes path))
938 (setq desc1 (if (match-end 5) (match-string 5 line))
939 desc2 (if (match-end 2) (concat type ":" path) path)
940 descp (and desc1 (not (equal desc1 desc2)))
941 desc (or desc1 desc2))
942 ;; Make an image out of the description if that is so wanted
943 (when (and descp (org-file-image-p
944 desc org-export-html-inline-image-extensions))
945 (save-match-data
946 (if (string-match "^file:" desc)
947 (setq desc (substring desc (match-end 0)))))
948 (setq desc (org-add-props
949 (concat "<img src=\"" desc "\"/>")
950 '(org-protected t))))
951 ;; FIXME: do we need to unescape here somewhere?
952 (cond
953 ((equal type "internal")
954 (setq rpl
955 (concat
956 "<a href=\""
957 (if (= (string-to-char path) ?#) "" "#")
958 (org-solidify-link-text
959 (save-match-data (org-link-unescape path)) nil)
960 "\"" attr ">"
961 (org-export-html-format-desc desc)
962 "</a>")))
963 ((and (equal type "id")
964 (setq id-file (org-id-find-id-file path)))
965 ;; This is an id: link to another file (if it was the same file,
966 ;; it would have become an internal link...)
967 (setq id-file (file-relative-name
968 id-file (file-name-directory org-current-export-file)))
969 (setq id-file (concat (file-name-sans-extension id-file)
970 "." html-extension))
971 (setq rpl (concat "<a href=\"" id-file "#"
972 (if (org-uuidgen-p path) "ID-")
973 path "\""
974 attr ">"
975 (org-export-html-format-desc desc)
976 "</a>")))
977 ((member type '("http" "https"))
978 ;; standard URL, just check if we need to inline an image
979 (if (and (or (eq t org-export-html-inline-images)
980 (and org-export-html-inline-images (not descp)))
981 (org-file-image-p
982 path org-export-html-inline-image-extensions))
983 (setq rpl (org-export-html-format-image
984 (concat type ":" path) org-par-open))
985 (setq link (concat type ":" path))
986 (setq rpl (concat "<a href=\""
987 (org-export-html-format-href link)
988 "\"" attr ">"
989 (org-export-html-format-desc desc)
990 "</a>"))))
991 ((member type '("ftp" "mailto" "news"))
992 ;; standard URL
993 (setq link (concat type ":" path))
994 (setq rpl (concat "<a href=\""
995 (org-export-html-format-href link)
996 "\"" attr ">"
997 (org-export-html-format-desc desc)
998 "</a>")))
1000 ((string= type "coderef")
1001 (setq rpl (format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
1002 path path path
1003 (format (org-export-get-coderef-format path (and descp desc))
1004 (cdr (assoc path org-export-code-refs))))))
1006 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
1007 ;; The link protocol has a function for format the link
1008 (setq rpl
1009 (save-match-data
1010 (funcall fnc (org-link-unescape path) desc1 'html))))
1012 ((string= type "file")
1013 ;; FILE link
1014 (let* ((filename path)
1015 (abs-p (file-name-absolute-p filename))
1016 thefile file-is-image-p search)
1017 (save-match-data
1018 (if (string-match "::\\(.*\\)" filename)
1019 (setq search (match-string 1 filename)
1020 filename (replace-match "" t nil filename)))
1021 (setq valid
1022 (if (functionp link-validate)
1023 (funcall link-validate filename current-dir)
1025 (setq file-is-image-p
1026 (org-file-image-p
1027 filename org-export-html-inline-image-extensions))
1028 (setq thefile (if abs-p (expand-file-name filename) filename))
1029 (when (and org-export-html-link-org-files-as-html
1030 (string-match "\\.org$" thefile))
1031 (setq thefile (concat (substring thefile 0
1032 (match-beginning 0))
1033 "." html-extension))
1034 (if (and search
1035 ;; make sure this is can be used as target search
1036 (not (string-match "^[0-9]*$" search))
1037 (not (string-match "^\\*" search))
1038 (not (string-match "^/.*/$" search)))
1039 (setq thefile (concat thefile "#"
1040 (org-solidify-link-text
1041 (org-link-unescape search)))))
1042 (when (string-match "^file:" desc)
1043 (setq desc (replace-match "" t t desc))
1044 (if (string-match "\\.org$" desc)
1045 (setq desc (replace-match "" t t desc))))))
1046 (setq rpl (if (and file-is-image-p
1047 (or (eq t org-export-html-inline-images)
1048 (and org-export-html-inline-images
1049 (not descp))))
1050 (progn
1051 (message "image %s %s" thefile org-par-open)
1052 (org-export-html-format-image thefile org-par-open))
1053 (concat "<a href=\"" thefile "\"" attr ">"
1054 (org-export-html-format-desc desc)
1055 "</a>")))
1056 (if (not valid) (setq rpl desc))))
1059 ;; just publish the path, as default
1060 (setq rpl (concat "<i>&lt;" type ":"
1061 (save-match-data (org-link-unescape path))
1062 "&gt;</i>"))))
1063 (setq line (replace-match rpl t t line)
1064 start (+ start (length rpl))))
1066 ;; TODO items
1067 (if (and (string-match org-todo-line-regexp line)
1068 (match-beginning 2))
1070 (setq line
1071 (concat (substring line 0 (match-beginning 2))
1072 "<span class=\""
1073 (if (member (match-string 2 line)
1074 org-done-keywords)
1075 "done" "todo")
1076 " " (match-string 2 line)
1077 "\"> " (org-export-html-get-todo-kwd-class-name
1078 (match-string 2 line))
1079 "</span>" (substring line (match-end 2)))))
1081 ;; Does this contain a reference to a footnote?
1082 (when org-export-with-footnotes
1083 (setq start 0)
1084 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
1085 (if (get-text-property (match-beginning 2) 'org-protected line)
1086 (setq start (match-end 2))
1087 (let ((n (match-string 2 line)) extra a)
1088 (if (setq a (assoc n footref-seen))
1089 (progn
1090 (setcdr a (1+ (cdr a)))
1091 (setq extra (format ".%d" (cdr a))))
1092 (setq extra "")
1093 (push (cons n 1) footref-seen))
1094 (setq line
1095 (replace-match
1096 (format
1097 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
1098 (match-string 1 line) n extra n n)
1099 t t line))))))
1101 (cond
1102 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1103 ;; This is a headline
1104 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1105 level-offset))
1106 txt (match-string 2 line))
1107 (if (string-match quote-re0 txt)
1108 (setq txt (replace-match "" t t txt)))
1109 (if (<= level (max umax umax-toc))
1110 (setq head-count (+ head-count 1)))
1111 (when in-local-list
1112 ;; Close any local lists before inserting a new header line
1113 (while local-list-type
1114 (org-close-li (car local-list-type))
1115 (insert (format "</%sl>\n" (car local-list-type)))
1116 (pop local-list-type))
1117 (setq local-list-indent nil
1118 in-local-list nil))
1119 (setq first-heading-pos (or first-heading-pos (point)))
1120 (org-html-level-start level txt umax
1121 (and org-export-with-toc (<= level umax))
1122 head-count)
1124 ;; QUOTES
1125 (when (string-match quote-re line)
1126 (org-close-par-maybe)
1127 (insert "<pre>")
1128 (setq inquote t)))
1130 ((string-match "^[ \t]*- __+[ \t]*$" line)
1131 ;; Explicit list closure
1132 (when local-list-type
1133 (let ((ind (org-get-indentation line)))
1134 (while (and local-list-indent
1135 (<= ind (car local-list-indent)))
1136 (org-close-li (car local-list-type))
1137 (insert (format "</%sl>\n" (car local-list-type)))
1138 (pop local-list-type)
1139 (pop local-list-indent))
1140 (or local-list-indent (setq in-local-list nil))))
1141 (throw 'nextline nil))
1143 ((and org-export-with-tables
1144 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1145 (when (not table-open)
1146 ;; New table starts
1147 (setq table-open t table-buffer nil table-orig-buffer nil))
1149 ;; Accumulate lines
1150 (setq table-buffer (cons line table-buffer)
1151 table-orig-buffer (cons origline table-orig-buffer))
1152 (when (or (not lines)
1153 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1154 (car lines))))
1155 (setq table-open nil
1156 table-buffer (nreverse table-buffer)
1157 table-orig-buffer (nreverse table-orig-buffer))
1158 (org-close-par-maybe)
1159 (insert (org-format-table-html table-buffer table-orig-buffer))))
1161 ;; Normal lines
1162 (when (string-match
1163 (cond
1164 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1165 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1166 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1167 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
1168 line)
1169 (setq ind (org-get-string-indentation line)
1170 item-type (if (match-beginning 4) "o" "u")
1171 starter (if (match-beginning 2)
1172 (substring (match-string 2 line) 0 -1))
1173 line (substring line (match-beginning 5))
1174 item-tag nil)
1175 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
1176 (setq item-type "d"
1177 item-tag (match-string 1 line)
1178 line (substring line (match-end 0))))
1179 (when (and (not (equal item-type "d"))
1180 (not (string-match "[^ \t]" line)))
1181 ;; empty line. Pretend indentation is large.
1182 (setq ind (if org-empty-line-terminates-plain-lists
1184 (1+ (or (car local-list-indent) 1)))))
1185 (setq didclose nil)
1186 (while (and in-local-list
1187 (or (and (= ind (car local-list-indent))
1188 (not starter))
1189 (< ind (car local-list-indent))))
1190 (setq didclose t)
1191 (org-close-li (car local-list-type))
1192 (insert (format "</%sl>\n" (car local-list-type)))
1193 (pop local-list-type) (pop local-list-indent)
1194 (setq in-local-list local-list-indent))
1195 (cond
1196 ((and starter
1197 (or (not in-local-list)
1198 (> ind (car local-list-indent))))
1199 ;; Start new (level of) list
1200 (org-close-par-maybe)
1201 (insert (cond
1202 ((equal item-type "u") "<ul>\n<li>\n")
1203 ((equal item-type "o") "<ol>\n<li>\n")
1204 ((equal item-type "d")
1205 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
1206 (push item-type local-list-type)
1207 (push ind local-list-indent)
1208 (setq in-local-list t))
1209 (starter
1210 ;; continue current list
1211 (org-close-li (car local-list-type))
1212 (insert (cond
1213 ((equal (car local-list-type) "d")
1214 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
1215 (t "<li>\n"))))
1216 (didclose
1217 ;; we did close a list, normal text follows: need <p>
1218 (org-open-par)))
1219 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
1220 (setq line
1221 (replace-match
1222 (if (equal (match-string 1 line) "X")
1223 "<b>[X]</b>"
1224 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
1225 t t line))))
1227 ;; Empty lines start a new paragraph. If hand-formatted lists
1228 ;; are not fully interpreted, lines starting with "-", "+", "*"
1229 ;; also start a new paragraph.
1230 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
1232 ;; Is this the start of a footnote?
1233 (when org-export-with-footnotes
1234 (when (and (boundp 'footnote-section-tag-regexp)
1235 (string-match (concat "^" footnote-section-tag-regexp)
1236 line))
1237 ;; ignore this line
1238 (throw 'nextline nil))
1239 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1240 (org-close-par-maybe)
1241 (let ((n (match-string 1 line)))
1242 (setq org-par-open t
1243 line (replace-match
1244 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
1246 ;; Check if the line break needs to be conserved
1247 (cond
1248 ((string-match "\\\\\\\\[ \t]*$" line)
1249 (setq line (replace-match "<br/>" t t line)))
1250 (org-export-preserve-breaks
1251 (setq line (concat line "<br/>"))))
1253 ;; Check if a paragraph should be started
1254 (let ((start 0))
1255 (while (and org-par-open
1256 (string-match "\\\\par\\>" line start))
1257 ;; Leave a space in the </p> so that the footnote matcher
1258 ;; does not see this.
1259 (if (not (get-text-property (match-beginning 0)
1260 'org-protected line))
1261 (setq line (replace-match "</p ><p >" t t line)))
1262 (setq start (match-end 0))))
1264 (insert line "\n")))))
1266 ;; Properly close all local lists and other lists
1267 (when inquote
1268 (insert "</pre>\n")
1269 (org-open-par))
1270 (when in-local-list
1271 ;; Close any local lists before inserting a new header line
1272 (while local-list-type
1273 (org-close-li (car local-list-type))
1274 (insert (format "</%sl>\n" (car local-list-type)))
1275 (pop local-list-type))
1276 (setq local-list-indent nil
1277 in-local-list nil))
1278 (org-html-level-start 1 nil umax
1279 (and org-export-with-toc (<= level umax))
1280 head-count)
1281 ;; the </div> to close the last text-... div.
1282 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
1284 (save-excursion
1285 (goto-char (point-min))
1286 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
1287 (push (match-string 0) footnotes)
1288 (replace-match "" t t)))
1289 (when footnotes
1290 (insert (format org-export-html-footnotes-section
1291 (or (nth 4 lang-words) "Footnotes")
1292 (mapconcat 'identity (nreverse footnotes) "\n"))
1293 "\n"))
1294 (let ((bib (org-export-html-get-bibliography)))
1295 (when bib
1296 (insert "\n" bib "\n")))
1297 (unless body-only
1298 (when (plist-get opt-plist :auto-postamble)
1299 (insert "<div id=\"postamble\">\n")
1300 (when (and org-export-author-info author)
1301 (insert "<p class=\"author\"> "
1302 (nth 1 lang-words) ": " author "\n")
1303 (when email
1304 (if (listp (split-string email ",+ *"))
1305 (mapc (lambda(e)
1306 (insert "<a href=\"mailto:" e "\">&lt;"
1307 e "&gt;</a>\n"))
1308 (split-string email ",+ *"))
1309 (insert "<a href=\"mailto:" email "\">&lt;"
1310 email "&gt;</a>\n")))
1311 (insert "</p>\n"))
1312 (when (and date org-export-time-stamp-file)
1313 (insert "<p class=\"date\"> "
1314 (nth 2 lang-words) ": "
1315 date "</p>\n"))
1316 (when org-export-creator-info
1317 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
1318 org-version emacs-major-version)))
1319 (when org-export-html-validation-link
1320 (insert org-export-html-validation-link "\n"))
1321 (insert "</div>"))
1323 (if org-export-html-with-timestamp
1324 (insert org-export-html-html-helper-timestamp))
1325 (insert (or (plist-get opt-plist :postamble) ""))
1326 (insert "\n</div>\n</body>\n</html>\n"))
1328 (unless (plist-get opt-plist :buffer-will-be-killed)
1329 (normal-mode)
1330 (if (eq major-mode default-major-mode) (html-mode)))
1332 ;; insert the table of contents
1333 (goto-char (point-min))
1334 (when thetoc
1335 (if (or (re-search-forward
1336 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
1337 (re-search-forward
1338 "\\[TABLE-OF-CONTENTS\\]" nil t))
1339 (progn
1340 (goto-char (match-beginning 0))
1341 (replace-match ""))
1342 (goto-char first-heading-pos)
1343 (when (looking-at "\\s-*</p>")
1344 (goto-char (match-end 0))
1345 (insert "\n")))
1346 (insert "<div id=\"table-of-contents\">\n")
1347 (mapc 'insert thetoc)
1348 (insert "</div>\n"))
1349 ;; remove empty paragraphs and lists
1350 (goto-char (point-min))
1351 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
1352 (replace-match ""))
1353 (goto-char (point-min))
1354 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
1355 (replace-match ""))
1356 (goto-char (point-min))
1357 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
1358 (replace-match ""))
1359 ;; Convert whitespace place holders
1360 (goto-char (point-min))
1361 (let (beg end n)
1362 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1363 (setq n (get-text-property beg 'org-whitespace)
1364 end (next-single-property-change beg 'org-whitespace))
1365 (goto-char beg)
1366 (delete-region beg end)
1367 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1368 (make-string n ?x)))))
1369 (or to-buffer (save-buffer))
1370 (goto-char (point-min))
1371 (or (org-export-push-to-kill-ring "HTML")
1372 (message "Exporting... done"))
1373 (if (eq to-buffer 'string)
1374 (prog1 (buffer-substring (point-min) (point-max))
1375 (kill-buffer (current-buffer)))
1376 (current-buffer)))))
1378 (defun org-export-html-format-href (s)
1379 "Make sure the S is valid as a href reference in an XHTML document."
1380 (save-match-data
1381 (let ((start 0))
1382 (while (string-match "&" s start)
1383 (setq start (+ (match-beginning 0) 3)
1384 s (replace-match "&amp;" t t s)))))
1387 (defun org-export-html-format-desc (s)
1388 "Make sure the S is valid as a description in a link."
1389 (if (and s (not (get-text-property 1 'org-protected s)))
1390 (save-match-data
1391 (org-html-do-expand s))
1394 (defun org-export-html-format-image (src par-open)
1395 "Create image tag with source and attributes."
1396 (save-match-data
1397 (if (string-match "^ltxpng/" src)
1398 (format "<img src=\"%s\"/>" src)
1399 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1400 (attr (org-find-text-property-in-string 'org-attributes src))
1401 (label (org-find-text-property-in-string 'org-label src)))
1402 (format "%s<div %sclass=\"figure\">
1403 <p><img src=\"%s\"%s /></p>%s
1404 </div>%s"
1405 (if org-par-open "</p>\n" "")
1406 (if label (format "id=\"%s\" " label) "")
1408 (if (string-match "\\<alt=" (or attr ""))
1409 (concat " " attr )
1410 (concat " " attr " alt=\"" src "\""))
1411 (if caption (concat "\n<p>" caption "</p>") "")
1412 (if org-par-open "\n<p>" ""))))))
1414 (defun org-export-html-get-bibliography ()
1415 "Find bibliography, cut it out and return it."
1416 (catch 'exit
1417 (let (beg end (cnt 1) bib)
1418 (save-excursion
1419 (goto-char (point-min))
1420 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1421 (setq beg (match-beginning 0))
1422 (while (re-search-forward "</?div\\>" nil t)
1423 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1424 (when (= cnt 0)
1425 (and (looking-at ">") (forward-char 1))
1426 (setq bib (buffer-substring beg (point)))
1427 (delete-region beg (point))
1428 (throw 'exit bib))))
1429 nil))))
1431 (defvar org-table-number-regexp) ; defined in org-table.el
1432 (defun org-format-table-html (lines olines)
1433 "Find out which HTML converter to use and return the HTML code."
1434 (if (stringp lines)
1435 (setq lines (org-split-string lines "\n")))
1436 (if (string-match "^[ \t]*|" (car lines))
1437 ;; A normal org table
1438 (org-format-org-table-html lines)
1439 ;; Table made by table.el - test for spanning
1440 (let* ((hlines (delq nil (mapcar
1441 (lambda (x)
1442 (if (string-match "^[ \t]*\\+-" x) x
1443 nil))
1444 lines)))
1445 (first (car hlines))
1446 (ll (and (string-match "\\S-+" first)
1447 (match-string 0 first)))
1448 (re (concat "^[ \t]*" (regexp-quote ll)))
1449 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
1450 hlines))))
1451 (if (and (not spanning)
1452 (not org-export-prefer-native-exporter-for-tables))
1453 ;; We can use my own converter with HTML conversions
1454 (org-format-table-table-html lines)
1455 ;; Need to use the code generator in table.el, with the original text.
1456 (org-format-table-table-html-using-table-generate-source olines)))))
1458 (defvar org-table-number-fraction) ; defined in org-table.el
1459 (defun org-format-org-table-html (lines &optional splice)
1460 "Format a table into HTML."
1461 (require 'org-table)
1462 ;; Get rid of hlines at beginning and end
1463 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1464 (setq lines (nreverse lines))
1465 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1466 (setq lines (nreverse lines))
1467 (when org-export-table-remove-special-lines
1468 ;; Check if the table has a marking column. If yes remove the
1469 ;; column and the special lines
1470 (setq lines (org-table-clean-before-export lines)))
1472 (let* ((caption (or (get-text-property 0 'org-caption (car lines))
1473 (get-text-property (or (next-single-property-change
1474 0 'org-caption (car lines))
1476 'org-caption (car lines))))
1477 (attributes (or (get-text-property 0 'org-attributes (car lines))
1478 (get-text-property (or (next-single-property-change
1479 0 'org-attributes (car lines))
1481 'org-attributes (car lines))))
1482 (html-table-tag (org-export-splice-attributes
1483 html-table-tag attributes))
1484 (head (and org-export-highlight-first-table-line
1485 (delq nil (mapcar
1486 (lambda (x) (string-match "^[ \t]*|-" x))
1487 (cdr lines)))))
1489 (nlines 0) fnum i
1490 tbopen line fields html gr colgropen)
1491 (if splice (setq head nil))
1492 (unless splice (push (if head "<thead>" "<tbody>") html))
1493 (setq tbopen t)
1494 (while (setq line (pop lines))
1495 (catch 'next-line
1496 (if (string-match "^[ \t]*|-" line)
1497 (progn
1498 (unless splice
1499 (push (if head "</thead>" "</tbody>") html)
1500 (if lines (push "<tbody>" html) (setq tbopen nil)))
1501 (setq head nil) ;; head ends here, first time around
1502 ;; ignore this line
1503 (throw 'next-line t)))
1504 ;; Break the line into fields
1505 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1506 (unless fnum (setq fnum (make-vector (length fields) 0)))
1507 (setq nlines (1+ nlines) i -1)
1508 (push (concat "<tr>"
1509 (mapconcat
1510 (lambda (x)
1511 (setq i (1+ i))
1512 (if (and (< i nlines)
1513 (string-match org-table-number-regexp x))
1514 (incf (aref fnum i)))
1515 (cond
1516 (head
1517 (concat
1518 (format (car org-export-table-header-tags) "col")
1520 (cdr org-export-table-header-tags)))
1521 ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
1522 (concat
1523 (format (car org-export-table-header-tags) "row")
1525 (cdr org-export-table-header-tags)))
1527 (concat (car org-export-table-data-tags) x
1528 (cdr org-export-table-data-tags)))))
1529 fields "")
1530 "</tr>")
1531 html)))
1532 (unless splice (if tbopen (push "</tbody>" html)))
1533 (unless splice (push "</table>\n" html))
1534 (setq html (nreverse html))
1535 (unless splice
1536 ;; Put in col tags with the alignment (unfortunately often ignored...)
1537 (push (concat
1538 "<colgroup>"
1539 (mapconcat
1540 (lambda (x)
1541 (setq gr (pop org-table-colgroup-info))
1542 (format "<col align=\"%s\" />"
1543 (if (> (/ (float x) nlines) org-table-number-fraction)
1544 "right" "left")))
1545 fnum "")
1546 "</colgroup>")
1547 html)
1549 ;; Since the output of HTML table formatter can also be used in
1550 ;; DocBook document, we want to always include the caption to make
1551 ;; DocBook XML file valid.
1552 (push (format "<caption>%s</caption>" (or caption "")) html)
1553 (push html-table-tag html))
1554 (concat (mapconcat 'identity html "\n") "\n")))
1556 (defun org-export-splice-attributes (tag attributes)
1557 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1558 (if (not attributes)
1560 (let (oldatt newatt)
1561 (setq oldatt (org-extract-attributes-from-string tag)
1562 tag (pop oldatt)
1563 newatt (cdr (org-extract-attributes-from-string attributes)))
1564 (while newatt
1565 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1566 (if (string-match ">" tag)
1567 (setq tag
1568 (replace-match (concat (org-attributes-to-string oldatt) ">")
1569 t t tag)))
1570 tag)))
1572 (defun org-format-table-table-html (lines)
1573 "Format a table generated by table.el into HTML.
1574 This conversion does *not* use `table-generate-source' from table.el.
1575 This has the advantage that Org-mode's HTML conversions can be used.
1576 But it has the disadvantage, that no cell- or row-spanning is allowed."
1577 (let (line field-buffer
1578 (head org-export-highlight-first-table-line)
1579 fields html empty i)
1580 (setq html (concat html-table-tag "\n"))
1581 (while (setq line (pop lines))
1582 (setq empty "&nbsp;")
1583 (catch 'next-line
1584 (if (string-match "^[ \t]*\\+-" line)
1585 (progn
1586 (if field-buffer
1587 (progn
1588 (setq
1589 html
1590 (concat
1591 html
1592 "<tr>"
1593 (mapconcat
1594 (lambda (x)
1595 (if (equal x "") (setq x empty))
1596 (if head
1597 (concat
1598 (format (car org-export-table-header-tags) "col")
1600 (cdr org-export-table-header-tags))
1601 (concat (car org-export-table-data-tags) x
1602 (cdr org-export-table-data-tags))))
1603 field-buffer "\n")
1604 "</tr>\n"))
1605 (setq head nil)
1606 (setq field-buffer nil)))
1607 ;; Ignore this line
1608 (throw 'next-line t)))
1609 ;; Break the line into fields and store the fields
1610 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1611 (if field-buffer
1612 (setq field-buffer (mapcar
1613 (lambda (x)
1614 (concat x "<br/>" (pop fields)))
1615 field-buffer))
1616 (setq field-buffer fields))))
1617 (setq html (concat html "</table>\n"))
1618 html))
1620 (defun org-format-table-table-html-using-table-generate-source (lines)
1621 "Format a table into html, using `table-generate-source' from table.el.
1622 This has the advantage that cell- or row-spanning is allowed.
1623 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
1624 (require 'table)
1625 (with-current-buffer (get-buffer-create " org-tmp1 ")
1626 (erase-buffer)
1627 (insert (mapconcat 'identity lines "\n"))
1628 (goto-char (point-min))
1629 (if (not (re-search-forward "|[^+]" nil t))
1630 (error "Error processing table"))
1631 (table-recognize-table)
1632 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1633 (table-generate-source 'html " org-tmp2 ")
1634 (set-buffer " org-tmp2 ")
1635 (buffer-substring (point-min) (point-max))))
1637 (defun org-export-splice-style (style extra)
1638 "Splice EXTRA into STYLE, just before \"</style>\"."
1639 (if (and (stringp extra)
1640 (string-match "\\S-" extra)
1641 (string-match "</style>" style))
1642 (concat (substring style 0 (match-beginning 0))
1643 "\n" extra "\n"
1644 (substring style (match-beginning 0)))
1645 style))
1647 (defun org-html-handle-time-stamps (s)
1648 "Format time stamps in string S, or remove them."
1649 (catch 'exit
1650 (let (r b)
1651 (while (string-match org-maybe-keyword-time-regexp s)
1652 (or b (setq b (substring s 0 (match-beginning 0))))
1653 (setq r (concat
1654 r (substring s 0 (match-beginning 0))
1655 " @<span class=\"timestamp-wrapper\">"
1656 (if (match-end 1)
1657 (format "@<span class=\"timestamp-kwd\">%s @</span>"
1658 (match-string 1 s)))
1659 (format " @<span class=\"timestamp\">%s@</span>"
1660 (substring
1661 (org-translate-time (match-string 3 s)) 1 -1))
1662 "@</span>")
1663 s (substring s (match-end 0))))
1664 ;; Line break if line started and ended with time stamp stuff
1665 (if (not r)
1667 (setq r (concat r s))
1668 (unless (string-match "\\S-" (concat b s))
1669 (setq r (concat r "@<br/>")))
1670 r))))
1672 (defvar htmlize-buffer-places) ; from htmlize.el
1673 (defun org-export-htmlize-region-for-paste (beg end)
1674 "Convert the region to HTML, using htmlize.el.
1675 This is much like `htmlize-region-for-paste', only that it uses
1676 the settings define in the org-... variables."
1677 (let* ((htmlize-output-type org-export-htmlize-output-type)
1678 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
1679 (htmlbuf (htmlize-region beg end)))
1680 (unwind-protect
1681 (with-current-buffer htmlbuf
1682 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1683 (plist-get htmlize-buffer-places 'content-end)))
1684 (kill-buffer htmlbuf))))
1686 ;;;###autoload
1687 (defun org-export-htmlize-generate-css ()
1688 "Create the CSS for all font definitions in the current Emacs session.
1689 Use this to create face definitions in your CSS style file that can then
1690 be used by code snippets transformed by htmlize.
1691 This command just produces a buffer that contains class definitions for all
1692 faces used in the current Emacs session. You can copy and paste the ones you
1693 need into your CSS file.
1695 If you then set `org-export-htmlize-output-type' to `css', calls to
1696 the function `org-export-htmlize-region-for-paste' will produce code
1697 that uses these same face definitions."
1698 (interactive)
1699 (require 'htmlize)
1700 (and (get-buffer "*html*") (kill-buffer "*html*"))
1701 (with-temp-buffer
1702 (let ((fl (face-list))
1703 (htmlize-css-name-prefix "org-")
1704 (htmlize-output-type 'css)
1705 f i)
1706 (while (setq f (pop fl)
1707 i (and f (face-attribute f :inherit)))
1708 (when (and (symbolp f) (or (not i) (not (listp i))))
1709 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1710 (htmlize-region (point-min) (point-max))))
1711 (switch-to-buffer "*html*")
1712 (goto-char (point-min))
1713 (if (re-search-forward "<style" nil t)
1714 (delete-region (point-min) (match-beginning 0)))
1715 (if (re-search-forward "</style>" nil t)
1716 (delete-region (1+ (match-end 0)) (point-max)))
1717 (beginning-of-line 1)
1718 (if (looking-at " +") (replace-match ""))
1719 (goto-char (point-min)))
1721 (defun org-html-protect (s)
1722 ;; convert & to &amp;, < to &lt; and > to &gt;
1723 (let ((start 0))
1724 (while (string-match "&" s start)
1725 (setq s (replace-match "&amp;" t t s)
1726 start (1+ (match-beginning 0))))
1727 (while (string-match "<" s)
1728 (setq s (replace-match "&lt;" t t s)))
1729 (while (string-match ">" s)
1730 (setq s (replace-match "&gt;" t t s)))
1731 ; (while (string-match "\"" s)
1732 ; (setq s (replace-match "&quot;" t t s)))
1736 (defun org-html-expand (string)
1737 "Prepare STRING for HTML export. Applies all active conversions.
1738 If there are links in the string, don't modify these."
1739 (let* ((re (concat org-bracket-link-regexp "\\|"
1740 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
1741 m s l res)
1742 (while (setq m (string-match re string))
1743 (setq s (substring string 0 m)
1744 l (match-string 0 string)
1745 string (substring string (match-end 0)))
1746 (push (org-html-do-expand s) res)
1747 (push l res))
1748 (push (org-html-do-expand string) res)
1749 (apply 'concat (nreverse res))))
1751 (defun org-html-do-expand (s)
1752 "Apply all active conversions to translate special ASCII to HTML."
1753 (setq s (org-html-protect s))
1754 (if org-export-html-expand
1755 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
1756 (setq s (replace-match "<\\1>" t nil s))))
1757 (if org-export-with-emphasize
1758 (setq s (org-export-html-convert-emphasize s)))
1759 (if org-export-with-special-strings
1760 (setq s (org-export-html-convert-special-strings s)))
1761 (if org-export-with-sub-superscripts
1762 (setq s (org-export-html-convert-sub-super s)))
1763 (if org-export-with-TeX-macros
1764 (let ((start 0) wd ass)
1765 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
1766 s start))
1767 (if (get-text-property (match-beginning 0) 'org-protected s)
1768 (setq start (match-end 0))
1769 (setq wd (match-string 1 s))
1770 (if (setq ass (assoc wd org-html-entities))
1771 (setq s (replace-match (or (cdr ass)
1772 (concat "&" (car ass) ";"))
1773 t t s))
1774 (setq start (+ start (length wd))))))))
1777 (defconst org-export-html-special-string-regexps
1778 '(("\\\\-" . "&shy;")
1779 ("---\\([^-]\\)" . "&mdash;\\1")
1780 ("--\\([^-]\\)" . "&ndash;\\1")
1781 ("\\.\\.\\." . "&hellip;"))
1782 "Regular expressions for special string conversion.")
1784 (defun org-export-html-convert-special-strings (string)
1785 "Convert special characters in STRING to HTML."
1786 (let ((all org-export-html-special-string-regexps)
1787 e a re rpl start)
1788 (while (setq a (pop all))
1789 (setq re (car a) rpl (cdr a) start 0)
1790 (while (string-match re string start)
1791 (if (get-text-property (match-beginning 0) 'org-protected string)
1792 (setq start (match-end 0))
1793 (setq string (replace-match rpl t nil string)))))
1794 string))
1796 (defun org-export-html-convert-sub-super (string)
1797 "Convert sub- and superscripts in STRING to HTML."
1798 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
1799 (while (string-match org-match-substring-regexp string s)
1800 (cond
1801 ((and requireb (match-end 8)) (setq s (match-end 2)))
1802 ((get-text-property (match-beginning 2) 'org-protected string)
1803 (setq s (match-end 2)))
1805 (setq s (match-end 1)
1806 key (if (string= (match-string 2 string) "_") "sub" "sup")
1807 c (or (match-string 8 string)
1808 (match-string 6 string)
1809 (match-string 5 string))
1810 string (replace-match
1811 (concat (match-string 1 string)
1812 "<" key ">" c "</" key ">")
1813 t t string)))))
1814 (while (string-match "\\\\\\([_^]\\)" string)
1815 (setq string (replace-match (match-string 1 string) t t string)))
1816 string))
1818 (defun org-export-html-convert-emphasize (string)
1819 "Apply emphasis."
1820 (let ((s 0) rpl)
1821 (while (string-match org-emph-re string s)
1822 (if (not (equal
1823 (substring string (match-beginning 3) (1+ (match-beginning 3)))
1824 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
1825 (setq s (match-beginning 0)
1827 (concat
1828 (match-string 1 string)
1829 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
1830 (match-string 4 string)
1831 (nth 3 (assoc (match-string 3 string)
1832 org-emphasis-alist))
1833 (match-string 5 string))
1834 string (replace-match rpl t t string)
1835 s (+ s (- (length rpl) 2)))
1836 (setq s (1+ s))))
1837 string))
1839 (defun org-open-par ()
1840 "Insert <p>, but first close previous paragraph if any."
1841 (org-close-par-maybe)
1842 (insert "\n<p>")
1843 (setq org-par-open t))
1844 (defun org-close-par-maybe ()
1845 "Close paragraph if there is one open."
1846 (when org-par-open
1847 (insert "</p>")
1848 (setq org-par-open nil)))
1849 (defun org-close-li (&optional type)
1850 "Close <li> if necessary."
1851 (org-close-par-maybe)
1852 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
1854 (defvar body-only) ; dynamically scoped into this.
1855 (defun org-html-level-start (level title umax with-toc head-count)
1856 "Insert a new level in HTML export.
1857 When TITLE is nil, just close all open levels."
1858 (org-close-par-maybe)
1859 (let* ((target (and title (org-get-text-property-any 0 'target title)))
1860 (extra-targets (assoc target org-export-target-aliases))
1861 (preferred (cdr (assoc target org-export-preferred-target-alist)))
1862 (remove (or preferred target))
1863 (l org-level-max)
1864 snumber href suffix)
1865 (setq extra-targets (remove remove extra-targets))
1866 (setq extra-targets
1867 (mapconcat (lambda (x)
1868 (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
1869 (format "<a name=\"%s\" id=\"%s\"></a>"
1870 x x))
1871 extra-targets
1872 ""))
1873 (while (>= l level)
1874 (if (aref org-levels-open (1- l))
1875 (progn
1876 (org-html-level-close l umax)
1877 (aset org-levels-open (1- l) nil)))
1878 (setq l (1- l)))
1879 (when title
1880 ;; If title is nil, this means this function is called to close
1881 ;; all levels, so the rest is done only if title is given
1882 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
1883 (setq title (replace-match
1884 (if org-export-with-tags
1885 (save-match-data
1886 (concat
1887 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
1888 (mapconcat
1889 (lambda (x)
1890 (format "<span class=\"%s\">%s</span>"
1891 (org-export-html-get-tag-class-name x)
1893 (org-split-string (match-string 1 title) ":")
1894 "&nbsp;")
1895 "</span>"))
1897 t t title)))
1898 (if (> level umax)
1899 (progn
1900 (if (aref org-levels-open (1- level))
1901 (progn
1902 (org-close-li)
1903 (if target
1904 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
1905 (insert "<li>" title "<br/>\n")))
1906 (aset org-levels-open (1- level) t)
1907 (org-close-par-maybe)
1908 (if target
1909 (insert (format "<ul>\n<li id=\"%s\">" target)
1910 extra-targets title "<br/>\n")
1911 (insert "<ul>\n<li>" title "<br/>\n"))))
1912 (aset org-levels-open (1- level) t)
1913 (setq snumber (org-section-number level))
1914 (setq level (+ level org-export-html-toplevel-hlevel -1))
1915 (if (and org-export-with-section-numbers (not body-only))
1916 (setq title (concat
1917 (format "<span class=\"section-number-%d\">%s</span>"
1918 level snumber)
1919 " " title)))
1920 (unless (= head-count 1) (insert "\n</div>\n"))
1921 (setq href (cdr (assoc (concat "sec-" snumber) org-export-preferred-target-alist)))
1922 (setq suffix (or href snumber))
1923 (setq href (or href (concat "sec-" snumber)))
1924 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
1925 suffix level level href
1926 extra-targets
1927 title level level suffix))
1928 (org-open-par)))))
1930 (defun org-export-html-get-tag-class-name (tag)
1931 "Turn tag into a valid class name.
1932 Replaces invalid characters with \"_\" and then prepends a prefix."
1933 (save-match-data
1934 (while (string-match "[^a-zA-Z0-9_]" tag)
1935 (setq tag (replace-match "_" t t tag))))
1936 (concat org-export-html-tag-class-prefix tag))
1938 (defun org-export-html-get-todo-kwd-class-name (kwd)
1939 "Turn todo keyword into a valid class name.
1940 Replaces invalid characters with \"_\" and then prepends a prefix."
1941 (save-match-data
1942 (while (string-match "[^a-zA-Z0-9_]" kwd)
1943 (setq kwd (replace-match "_" t t kwd))))
1944 (concat org-export-html-todo-kwd-class-prefix kwd))
1946 (defun org-html-level-close (level max-outline-level)
1947 "Terminate one level in HTML export."
1948 (if (<= level max-outline-level)
1949 (insert "</div>\n")
1950 (org-close-li)
1951 (insert "</ul>\n")))
1953 (provide 'org-html)
1955 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
1957 ;;; org-html.el ends here