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