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