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