Remove the website update from the release code.
[org-mode.git] / lisp / org-exp.el
blobc7c988cc5030652920636ec4868ad8196c79d5c9
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.00pre-2
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 (require 'org)
31 (require 'org-agenda)
32 (eval-and-compile
33 (require 'cl))
35 (declare-function org-export-latex-cleaned-string "org-export-latex" ())
36 (declare-function org-agenda-skip "org-agenda" ())
38 (defgroup org-export nil
39 "Options for exporting org-listings."
40 :tag "Org Export"
41 :group 'org)
43 (defgroup org-export-general nil
44 "General options for exporting Org-mode files."
45 :tag "Org Export General"
46 :group 'org-export)
48 ;; FIXME
49 (defvar org-export-publishing-directory nil)
51 (defcustom org-export-with-special-strings t
52 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
53 When this option is turned on, these strings will be exported as:
55 Org HTML LaTeX
56 -----+----------+--------
57 \\- &shy; \\-
58 -- &ndash; --
59 --- &mdash; ---
60 ... &hellip; \ldots
62 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
63 :group 'org-export-translation
64 :type 'boolean)
66 (defcustom org-export-language-setup
67 '(("en" "Author" "Date" "Table of Contents")
68 ("cs" "Autor" "Datum" "Obsah")
69 ("da" "Ophavsmand" "Dato" "Indhold")
70 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
71 ("es" "Autor" "Fecha" "\xcdndice")
72 ("fr" "Auteur" "Date" "Table des mati\xe8res")
73 ("it" "Autore" "Data" "Indice")
74 ("nl" "Auteur" "Datum" "Inhoudsopgave")
75 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
76 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
77 "Terms used in export text, translated to different languages.
78 Use the variable `org-export-default-language' to set the language,
79 or use the +OPTION lines for a per-file setting."
80 :group 'org-export-general
81 :type '(repeat
82 (list
83 (string :tag "HTML language tag")
84 (string :tag "Author")
85 (string :tag "Date")
86 (string :tag "Table of Contents"))))
88 (defcustom org-export-default-language "en"
89 "The default language of HTML export, as a string.
90 This should have an association in `org-export-language-setup'."
91 :group 'org-export-general
92 :type 'string)
94 (defcustom org-export-skip-text-before-1st-heading t
95 "Non-nil means, skip all text before the first headline when exporting.
96 When nil, that text is exported as well."
97 :group 'org-export-general
98 :type 'boolean)
100 (defcustom org-export-headline-levels 3
101 "The last level which is still exported as a headline.
102 Inferior levels will produce itemize lists when exported.
103 Note that a numeric prefix argument to an exporter function overrides
104 this setting.
106 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
107 :group 'org-export-general
108 :type 'number)
110 (defcustom org-export-with-section-numbers t
111 "Non-nil means, add section numbers to headlines when exporting.
113 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
114 :group 'org-export-general
115 :type 'boolean)
117 (defcustom org-export-with-toc t
118 "Non-nil means, create a table of contents in exported files.
119 The TOC contains headlines with levels up to`org-export-headline-levels'.
120 When an integer, include levels up to N in the toc, this may then be
121 different from `org-export-headline-levels', but it will not be allowed
122 to be larger than the number of headline levels.
123 When nil, no table of contents is made.
125 Headlines which contain any TODO items will be marked with \"(*)\" in
126 ASCII export, and with red color in HTML output, if the option
127 `org-export-mark-todo-in-toc' is set.
129 In HTML output, the TOC will be clickable.
131 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
132 or \"toc:3\"."
133 :group 'org-export-general
134 :type '(choice
135 (const :tag "No Table of Contents" nil)
136 (const :tag "Full Table of Contents" t)
137 (integer :tag "TOC to level")))
139 (defcustom org-export-mark-todo-in-toc nil
140 "Non-nil means, mark TOC lines that contain any open TODO items."
141 :group 'org-export-general
142 :type 'boolean)
144 (defcustom org-export-preserve-breaks nil
145 "Non-nil means, preserve all line breaks when exporting.
146 Normally, in HTML output paragraphs will be reformatted. In ASCII
147 export, line breaks will always be preserved, regardless of this variable.
149 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
150 :group 'org-export-general
151 :type 'boolean)
153 (defcustom org-export-with-archived-trees 'headline
154 "Whether subtrees with the ARCHIVE tag should be exported.
155 This can have three different values
156 nil Do not export, pretend this tree is not present
157 t Do export the entire tree
158 headline Only export the headline, but skip the tree below it."
159 :group 'org-export-general
160 :group 'org-archive
161 :type '(choice
162 (const :tag "not at all" nil)
163 (const :tag "headline only" 'headline)
164 (const :tag "entirely" t)))
166 (defcustom org-export-author-info t
167 "Non-nil means, insert author name and email into the exported file.
169 This option can also be set with the +OPTIONS line,
170 e.g. \"author-info:nil\"."
171 :group 'org-export-general
172 :type 'boolean)
174 (defcustom org-export-time-stamp-file t
175 "Non-nil means, insert a time stamp into the exported file.
176 The time stamp shows when the file was created.
178 This option can also be set with the +OPTIONS line,
179 e.g. \"timestamp:nil\"."
180 :group 'org-export-general
181 :type 'boolean)
183 (defcustom org-export-with-timestamps t
184 "If nil, do not export time stamps and associated keywords."
185 :group 'org-export-general
186 :type 'boolean)
188 (defcustom org-export-remove-timestamps-from-toc t
189 "If nil, remove timestamps from the table of contents entries."
190 :group 'org-export-general
191 :type 'boolean)
193 (defcustom org-export-with-tags 'not-in-toc
194 "If nil, do not export tags, just remove them from headlines.
195 If this is the symbol `not-in-toc', tags will be removed from table of
196 contents entries, but still be shown in the headlines of the document.
198 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
199 :group 'org-export-general
200 :type '(choice
201 (const :tag "Off" nil)
202 (const :tag "Not in TOC" not-in-toc)
203 (const :tag "On" t)))
205 (defcustom org-export-with-drawers nil
206 "Non-nil means, export with drawers like the property drawer.
207 When t, all drawers are exported. This may also be a list of
208 drawer names to export."
209 :group 'org-export-general
210 :type '(choice
211 (const :tag "All drawers" t)
212 (const :tag "None" nil)
213 (repeat :tag "Selected drawers"
214 (string :tag "Drawer name"))))
216 (defgroup org-export-translation nil
217 "Options for translating special ascii sequences for the export backends."
218 :tag "Org Export Translation"
219 :group 'org-export)
221 (defcustom org-export-with-emphasize t
222 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
223 If the export target supports emphasizing text, the word will be
224 typeset in bold, italic, or underlined, respectively. Works only for
225 single words, but you can say: I *really* *mean* *this*.
226 Not all export backends support this.
228 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
229 :group 'org-export-translation
230 :type 'boolean)
232 (defcustom org-export-with-footnotes t
233 "If nil, export [1] as a footnote marker.
234 Lines starting with [1] will be formatted as footnotes.
236 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
237 :group 'org-export-translation
238 :type 'boolean)
240 (defcustom org-export-with-sub-superscripts t
241 "Non-nil means, interpret \"_\" and \"^\" for export.
242 When this option is turned on, you can use TeX-like syntax for sub- and
243 superscripts. Several characters after \"_\" or \"^\" will be
244 considered as a single item - so grouping with {} is normally not
245 needed. For example, the following things will be parsed as single
246 sub- or superscripts.
248 10^24 or 10^tau several digits will be considered 1 item.
249 10^-12 or 10^-tau a leading sign with digits or a word
250 x^2-y^3 will be read as x^2 - y^3, because items are
251 terminated by almost any nonword/nondigit char.
252 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
254 Still, ambiguity is possible - so when in doubt use {} to enclose the
255 sub/superscript. If you set this variable to the symbol `{}',
256 the braces are *required* in order to trigger interpretations as
257 sub/superscript. This can be helpful in documents that need \"_\"
258 frequently in plain text.
260 Not all export backends support this, but HTML does.
262 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
263 :group 'org-export-translation
264 :type '(choice
265 (const :tag "Always interpret" t)
266 (const :tag "Only with braces" {})
267 (const :tag "Never interpret" nil)))
269 (defcustom org-export-with-special-strings t
270 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
271 When this option is turned on, these strings will be exported as:
273 \\- : &shy;
274 -- : &ndash;
275 --- : &mdash;
277 Not all export backends support this, but HTML does.
279 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
280 :group 'org-export-translation
281 :type 'boolean)
283 (defcustom org-export-with-TeX-macros t
284 "Non-nil means, interpret simple TeX-like macros when exporting.
285 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
286 No only real TeX macros will work here, but the standard HTML entities
287 for math can be used as macro names as well. For a list of supported
288 names in HTML export, see the constant `org-html-entities'.
289 Not all export backends support this.
291 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
292 :group 'org-export-translation
293 :group 'org-export-latex
294 :type 'boolean)
296 (defcustom org-export-with-LaTeX-fragments nil
297 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
298 When set, the exporter will find LaTeX environments if the \\begin line is
299 the first non-white thing on a line. It will also find the math delimiters
300 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
301 display math.
303 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
304 :group 'org-export-translation
305 :group 'org-export-latex
306 :type 'boolean)
308 (defcustom org-export-with-fixed-width t
309 "Non-nil means, lines starting with \":\" will be in fixed width font.
310 This can be used to have pre-formatted text, fragments of code etc. For
311 example:
312 : ;; Some Lisp examples
313 : (while (defc cnt)
314 : (ding))
315 will be looking just like this in also HTML. See also the QUOTE keyword.
316 Not all export backends support this.
318 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
319 :group 'org-export-translation
320 :type 'boolean)
322 (defcustom org-match-sexp-depth 3
323 "Number of stacked braces for sub/superscript matching.
324 This has to be set before loading org.el to be effective."
325 :group 'org-export-translation
326 :type 'integer)
328 (defgroup org-export-tables nil
329 "Options for exporting tables in Org-mode."
330 :tag "Org Export Tables"
331 :group 'org-export)
333 (defcustom org-export-with-tables t
334 "If non-nil, lines starting with \"|\" define a table.
335 For example:
337 | Name | Address | Birthday |
338 |-------------+----------+-----------|
339 | Arthur Dent | England | 29.2.2100 |
341 Not all export backends support this.
343 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
344 :group 'org-export-tables
345 :type 'boolean)
347 (defcustom org-export-highlight-first-table-line t
348 "Non-nil means, highlight the first table line.
349 In HTML export, this means use <th> instead of <td>.
350 In tables created with table.el, this applies to the first table line.
351 In Org-mode tables, all lines before the first horizontal separator
352 line will be formatted with <th> tags."
353 :group 'org-export-tables
354 :type 'boolean)
356 (defcustom org-export-table-remove-special-lines t
357 "Remove special lines and marking characters in calculating tables.
358 This removes the special marking character column from tables that are set
359 up for spreadsheet calculations. It also removes the entire lines
360 marked with `!', `_', or `^'. The lines with `$' are kept, because
361 the values of constants may be useful to have."
362 :group 'org-export-tables
363 :type 'boolean)
365 (defcustom org-export-prefer-native-exporter-for-tables nil
366 "Non-nil means, always export tables created with table.el natively.
367 Natively means, use the HTML code generator in table.el.
368 When nil, Org-mode's own HTML generator is used when possible (i.e. if
369 the table does not use row- or column-spanning). This has the
370 advantage, that the automatic HTML conversions for math symbols and
371 sub/superscripts can be applied. Org-mode's HTML generator is also
372 much faster."
373 :group 'org-export-tables
374 :type 'boolean)
376 (defgroup org-export-ascii nil
377 "Options specific for ASCII export of Org-mode files."
378 :tag "Org Export ASCII"
379 :group 'org-export)
381 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
382 "Characters for underlining headings in ASCII export.
383 In the given sequence, these characters will be used for level 1, 2, ..."
384 :group 'org-export-ascii
385 :type '(repeat character))
387 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
388 "Bullet characters for headlines converted to lists in ASCII export.
389 The first character is used for the first lest level generated in this
390 way, and so on. If there are more levels than characters given here,
391 the list will be repeated.
392 Note that plain lists will keep the same bullets as the have in the
393 Org-mode file."
394 :group 'org-export-ascii
395 :type '(repeat character))
397 (defgroup org-export-xml nil
398 "Options specific for XML export of Org-mode files."
399 :tag "Org Export XML"
400 :group 'org-export)
402 (defgroup org-export-html nil
403 "Options specific for HTML export of Org-mode files."
404 :tag "Org Export HTML"
405 :group 'org-export)
407 (defcustom org-export-html-coding-system nil
409 :group 'org-export-html
410 :type 'coding-system)
412 (defcustom org-export-html-extension "html"
413 "The extension for exported HTML files."
414 :group 'org-export-html
415 :type 'string)
417 (defcustom org-export-html-style
418 "<style type=\"text/css\">
419 html {
420 font-family: Times, serif;
421 font-size: 12pt;
423 .title { text-align: center; }
424 .todo { color: red; }
425 .done { color: green; }
426 .timestamp { color: grey }
427 .timestamp-kwd { color: CadetBlue }
428 .tag { background-color:lightblue; font-weight:normal }
429 .target { background-color: lavender; }
430 pre {
431 border: 1pt solid #AEBDCC;
432 background-color: #F3F5F7;
433 padding: 5pt;
434 font-family: courier, monospace;
436 table { border-collapse: collapse; }
437 td, th {
438 vertical-align: top;
439 <!--border: 1pt solid #ADB9CC;-->
441 </style>"
442 "The default style specification for exported HTML files.
443 Since there are different ways of setting style information, this variable
444 needs to contain the full HTML structure to provide a style, including the
445 surrounding HTML tags. The style specifications should include definitions
446 for new classes todo, done, title, and deadline. For example, valid values
447 would be:
449 <style type=\"text/css\">
450 p { font-weight: normal; color: gray; }
451 h1 { color: black; }
452 .title { text-align: center; }
453 .todo, .deadline { color: red; }
454 .done { color: green; }
455 </style>
457 or, if you want to keep the style in a file,
459 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
461 As the value of this option simply gets inserted into the HTML <head> header,
462 you can \"misuse\" it to add arbitrary text to the header."
463 :group 'org-export-html
464 :type 'string)
467 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
468 "Format for typesetting the document title in HTML export."
469 :group 'org-export-html
470 :type 'string)
472 (defcustom org-export-html-toplevel-hlevel 2
473 "The <H> level for level 1 headings in HTML export."
474 :group 'org-export-html
475 :type 'string)
477 (defcustom org-export-html-link-org-files-as-html t
478 "Non-nil means, make file links to `file.org' point to `file.html'.
479 When org-mode is exporting an org-mode file to HTML, links to
480 non-html files are directly put into a href tag in HTML.
481 However, links to other Org-mode files (recognized by the
482 extension `.org.) should become links to the corresponding html
483 file, assuming that the linked org-mode file will also be
484 converted to HTML.
485 When nil, the links still point to the plain `.org' file."
486 :group 'org-export-html
487 :type 'boolean)
489 (defcustom org-export-html-inline-images 'maybe
490 "Non-nil means, inline images into exported HTML pages.
491 This is done using an <img> tag. When nil, an anchor with href is used to
492 link to the image. If this option is `maybe', then images in links with
493 an empty description will be inlined, while images with a description will
494 be linked only."
495 :group 'org-export-html
496 :type '(choice (const :tag "Never" nil)
497 (const :tag "Always" t)
498 (const :tag "When there is no description" maybe)))
500 ;; FIXME: rename
501 (defcustom org-export-html-expand t
502 "Non-nil means, for HTML export, treat @<...> as HTML tag.
503 When nil, these tags will be exported as plain text and therefore
504 not be interpreted by a browser.
506 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
507 :group 'org-export-html
508 :type 'boolean)
510 (defcustom org-export-html-table-tag
511 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
512 "The HTML tag that is used to start a table.
513 This must be a <table> tag, but you may change the options like
514 borders and spacing."
515 :group 'org-export-html
516 :type 'string)
518 (defcustom org-export-table-header-tags '("<th>" . "</th>")
519 "The opening tag for table header fields.
520 This is customizable so that alignment options can be specified."
521 :group 'org-export-tables
522 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
524 (defcustom org-export-table-data-tags '("<td>" . "</td>")
525 "The opening tag for table data fields.
526 This is customizable so that alignment options can be specified."
527 :group 'org-export-tables
528 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
530 (defcustom org-export-html-with-timestamp nil
531 "If non-nil, write `org-export-html-html-helper-timestamp'
532 into the exported HTML text. Otherwise, the buffer will just be saved
533 to a file."
534 :group 'org-export-html
535 :type 'boolean)
537 (defcustom org-export-html-html-helper-timestamp
538 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
539 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
540 :group 'org-export-html
541 :type 'string)
543 (defgroup org-export-icalendar nil
544 "Options specific for iCalendar export of Org-mode files."
545 :tag "Org Export iCalendar"
546 :group 'org-export)
548 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
549 "The file name for the iCalendar file covering all agenda files.
550 This file is created with the command \\[org-export-icalendar-all-agenda-files].
551 The file name should be absolute, the file will be overwritten without warning."
552 :group 'org-export-icalendar
553 :type 'file)
555 (defcustom org-icalendar-include-todo nil
556 "Non-nil means, export to iCalendar files should also cover TODO items."
557 :group 'org-export-icalendar
558 :type '(choice
559 (const :tag "None" nil)
560 (const :tag "Unfinished" t)
561 (const :tag "All" all)))
563 (defcustom org-icalendar-include-sexps t
564 "Non-nil means, export to iCalendar files should also cover sexp entries.
565 These are entries like in the diary, but directly in an Org-mode file."
566 :group 'org-export-icalendar
567 :type 'boolean)
569 (defcustom org-icalendar-include-body 100
570 "Amount of text below headline to be included in iCalendar export.
571 This is a number of characters that should maximally be included.
572 Properties, scheduling and clocking lines will always be removed.
573 The text will be inserted into the DESCRIPTION field."
574 :group 'org-export-icalendar
575 :type '(choice
576 (const :tag "Nothing" nil)
577 (const :tag "Everything" t)
578 (integer :tag "Max characters")))
580 (defcustom org-icalendar-combined-name "OrgMode"
581 "Calendar name for the combined iCalendar representing all agenda files."
582 :group 'org-export-icalendar
583 :type 'string)
585 ;;;; Exporting
587 ;;; Variables, constants, and parameter plists
589 (defconst org-level-max 20)
591 (defvar org-export-html-preamble nil
592 "Preamble, to be inserted just after <body>. Set by publishing functions.")
593 (defvar org-export-html-postamble nil
594 "Preamble, to be inserted just before </body>. Set by publishing functions.")
595 (defvar org-export-html-auto-preamble t
596 "Should default preamble be inserted? Set by publishing functions.")
597 (defvar org-export-html-auto-postamble t
598 "Should default postamble be inserted? Set by publishing functions.")
599 (defvar org-current-export-file nil) ; dynamically scoped parameter
600 (defvar org-current-export-dir nil) ; dynamically scoped parameter
602 (defconst org-export-plist-vars
603 '((:language . org-export-default-language)
604 (:customtime . org-display-custom-times)
605 (:headline-levels . org-export-headline-levels)
606 (:section-numbers . org-export-with-section-numbers)
607 (:table-of-contents . org-export-with-toc)
608 (:preserve-breaks . org-export-preserve-breaks)
609 (:archived-trees . org-export-with-archived-trees)
610 (:emphasize . org-export-with-emphasize)
611 (:sub-superscript . org-export-with-sub-superscripts)
612 (:special-strings . org-export-with-special-strings)
613 (:footnotes . org-export-with-footnotes)
614 (:drawers . org-export-with-drawers)
615 (:tags . org-export-with-tags)
616 (:TeX-macros . org-export-with-TeX-macros)
617 (:LaTeX-fragments . org-export-with-LaTeX-fragments)
618 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
619 (:fixed-width . org-export-with-fixed-width)
620 (:timestamps . org-export-with-timestamps)
621 (:author-info . org-export-author-info)
622 (:time-stamp-file . org-export-time-stamp-file)
623 (:tables . org-export-with-tables)
624 (:table-auto-headline . org-export-highlight-first-table-line)
625 (:style . org-export-html-style)
626 (:agenda-style . org-agenda-export-html-style)
627 (:convert-org-links . org-export-html-link-org-files-as-html)
628 (:inline-images . org-export-html-inline-images)
629 (:html-extension . org-export-html-extension)
630 (:html-table-tag . org-export-html-table-tag)
631 (:expand-quoted-html . org-export-html-expand)
632 (:timestamp . org-export-html-with-timestamp)
633 (:publishing-directory . org-export-publishing-directory)
634 (:preamble . org-export-html-preamble)
635 (:postamble . org-export-html-postamble)
636 (:auto-preamble . org-export-html-auto-preamble)
637 (:auto-postamble . org-export-html-auto-postamble)
638 (:author . user-full-name)
639 (:email . user-mail-address)))
641 (defun org-default-export-plist ()
642 "Return the property list with default settings for the export variables."
643 (let ((l org-export-plist-vars) rtn e)
644 (while (setq e (pop l))
645 (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
646 rtn))
648 (defun org-infile-export-plist ()
649 "Return the property list with file-local settings for export."
650 (save-excursion
651 (save-restriction
652 (widen)
653 (goto-char 0)
654 (let ((re (org-make-options-regexp
655 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE")))
656 p key val text options)
657 (while (re-search-forward re nil t)
658 (setq key (org-match-string-no-properties 1)
659 val (org-match-string-no-properties 2))
660 (cond
661 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
662 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
663 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
664 ((string-equal key "DATE") (setq p (plist-put p :date val)))
665 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
666 ((string-equal key "TEXT")
667 (setq text (if text (concat text "\n" val) val)))
668 ((string-equal key "OPTIONS") (setq options val))))
669 (setq p (plist-put p :text text))
670 (when options
671 (let ((op '(("H" . :headline-levels)
672 ("num" . :section-numbers)
673 ("toc" . :table-of-contents)
674 ("\\n" . :preserve-breaks)
675 ("@" . :expand-quoted-html)
676 (":" . :fixed-width)
677 ("|" . :tables)
678 ("^" . :sub-superscript)
679 ("-" . :special-strings)
680 ("f" . :footnotes)
681 ("d" . :drawers)
682 ("tags" . :tags)
683 ("*" . :emphasize)
684 ("TeX" . :TeX-macros)
685 ("LaTeX" . :LaTeX-fragments)
686 ("skip" . :skip-before-1st-heading)
687 ("author" . :author-info)
688 ("timestamp" . :time-stamp-file)))
690 (while (setq o (pop op))
691 (if (string-match (concat (regexp-quote (car o))
692 ":\\([^ \t\n\r;,.]*\\)")
693 options)
694 (setq p (plist-put p (cdr o)
695 (car (read-from-string
696 (match-string 1 options)))))))))
697 p))))
699 (defun org-export-directory (type plist)
700 (let* ((val (plist-get plist :publishing-directory))
701 (dir (if (listp val)
702 (or (cdr (assoc type val)) ".")
703 val)))
704 dir))
706 ;;;###autoload
707 (defun org-export (&optional arg)
708 "Export dispatcher for Org-mode."
709 (interactive)
710 (let ((help "[t] insert the export option template
711 \[v] limit export to visible part of outline tree
713 \[a] export as ASCII
715 \[h] export as HTML
716 \[H] export as HTML to temporary buffer
717 \[R] export region as HTML
718 \[b] export as HTML and browse immediately
719 \[x] export as XOXO
721 \[l] export as LaTeX
722 \[L] export as LaTeX to temporary buffer
724 \[i] export current file as iCalendar file
725 \[I] export all agenda files as iCalendar files
726 \[c] export agenda files into combined iCalendar file
728 \[F] publish current file
729 \[P] publish current project
730 \[X] publish... (project will be prompted for)
731 \[A] publish all projects")
732 (cmds
733 '((?t . org-insert-export-options-template)
734 (?v . org-export-visible)
735 (?a . org-export-as-ascii)
736 (?h . org-export-as-html)
737 (?b . org-export-as-html-and-open)
738 (?H . org-export-as-html-to-buffer)
739 (?R . org-export-region-as-html)
740 (?x . org-export-as-xoxo)
741 (?l . org-export-as-latex)
742 (?L . org-export-as-latex-to-buffer)
743 (?i . org-export-icalendar-this-file)
744 (?I . org-export-icalendar-all-agenda-files)
745 (?c . org-export-icalendar-combine-agenda-files)
746 (?F . org-publish-current-file)
747 (?P . org-publish-current-project)
748 (?X . org-publish)
749 (?A . org-publish-all)))
750 r1 r2 ass)
751 (save-window-excursion
752 (delete-other-windows)
753 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
754 (princ help))
755 (message "Select command: ")
756 (setq r1 (read-char-exclusive)))
757 (setq r2 (if (< r1 27) (+ r1 96) r1))
758 (if (setq ass (assq r2 cmds))
759 (call-interactively (cdr ass))
760 (error "No command associated with key %c" r1))))
762 (defconst org-html-entities
763 '(("nbsp")
764 ("iexcl")
765 ("cent")
766 ("pound")
767 ("curren")
768 ("yen")
769 ("brvbar")
770 ("vert" . "&#124;")
771 ("sect")
772 ("uml")
773 ("copy")
774 ("ordf")
775 ("laquo")
776 ("not")
777 ("shy")
778 ("reg")
779 ("macr")
780 ("deg")
781 ("plusmn")
782 ("sup2")
783 ("sup3")
784 ("acute")
785 ("micro")
786 ("para")
787 ("middot")
788 ("odot"."o")
789 ("star"."*")
790 ("cedil")
791 ("sup1")
792 ("ordm")
793 ("raquo")
794 ("frac14")
795 ("frac12")
796 ("frac34")
797 ("iquest")
798 ("Agrave")
799 ("Aacute")
800 ("Acirc")
801 ("Atilde")
802 ("Auml")
803 ("Aring") ("AA"."&Aring;")
804 ("AElig")
805 ("Ccedil")
806 ("Egrave")
807 ("Eacute")
808 ("Ecirc")
809 ("Euml")
810 ("Igrave")
811 ("Iacute")
812 ("Icirc")
813 ("Iuml")
814 ("ETH")
815 ("Ntilde")
816 ("Ograve")
817 ("Oacute")
818 ("Ocirc")
819 ("Otilde")
820 ("Ouml")
821 ("times")
822 ("Oslash")
823 ("Ugrave")
824 ("Uacute")
825 ("Ucirc")
826 ("Uuml")
827 ("Yacute")
828 ("THORN")
829 ("szlig")
830 ("agrave")
831 ("aacute")
832 ("acirc")
833 ("atilde")
834 ("auml")
835 ("aring")
836 ("aelig")
837 ("ccedil")
838 ("egrave")
839 ("eacute")
840 ("ecirc")
841 ("euml")
842 ("igrave")
843 ("iacute")
844 ("icirc")
845 ("iuml")
846 ("eth")
847 ("ntilde")
848 ("ograve")
849 ("oacute")
850 ("ocirc")
851 ("otilde")
852 ("ouml")
853 ("divide")
854 ("oslash")
855 ("ugrave")
856 ("uacute")
857 ("ucirc")
858 ("uuml")
859 ("yacute")
860 ("thorn")
861 ("yuml")
862 ("fnof")
863 ("Alpha")
864 ("Beta")
865 ("Gamma")
866 ("Delta")
867 ("Epsilon")
868 ("Zeta")
869 ("Eta")
870 ("Theta")
871 ("Iota")
872 ("Kappa")
873 ("Lambda")
874 ("Mu")
875 ("Nu")
876 ("Xi")
877 ("Omicron")
878 ("Pi")
879 ("Rho")
880 ("Sigma")
881 ("Tau")
882 ("Upsilon")
883 ("Phi")
884 ("Chi")
885 ("Psi")
886 ("Omega")
887 ("alpha")
888 ("beta")
889 ("gamma")
890 ("delta")
891 ("epsilon")
892 ("varepsilon"."&epsilon;")
893 ("zeta")
894 ("eta")
895 ("theta")
896 ("iota")
897 ("kappa")
898 ("lambda")
899 ("mu")
900 ("nu")
901 ("xi")
902 ("omicron")
903 ("pi")
904 ("rho")
905 ("sigmaf") ("varsigma"."&sigmaf;")
906 ("sigma")
907 ("tau")
908 ("upsilon")
909 ("phi")
910 ("chi")
911 ("psi")
912 ("omega")
913 ("thetasym") ("vartheta"."&thetasym;")
914 ("upsih")
915 ("piv")
916 ("bull") ("bullet"."&bull;")
917 ("hellip") ("dots"."&hellip;")
918 ("prime")
919 ("Prime")
920 ("oline")
921 ("frasl")
922 ("weierp")
923 ("image")
924 ("real")
925 ("trade")
926 ("alefsym")
927 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
928 ("uarr") ("uparrow"."&uarr;")
929 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
930 ("darr")("downarrow"."&darr;")
931 ("harr") ("leftrightarrow"."&harr;")
932 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
933 ("lArr") ("Leftarrow"."&lArr;")
934 ("uArr") ("Uparrow"."&uArr;")
935 ("rArr") ("Rightarrow"."&rArr;")
936 ("dArr") ("Downarrow"."&dArr;")
937 ("hArr") ("Leftrightarrow"."&hArr;")
938 ("forall")
939 ("part") ("partial"."&part;")
940 ("exist") ("exists"."&exist;")
941 ("empty") ("emptyset"."&empty;")
942 ("nabla")
943 ("isin") ("in"."&isin;")
944 ("notin")
945 ("ni")
946 ("prod")
947 ("sum")
948 ("minus")
949 ("lowast") ("ast"."&lowast;")
950 ("radic")
951 ("prop") ("proptp"."&prop;")
952 ("infin") ("infty"."&infin;")
953 ("ang") ("angle"."&ang;")
954 ("and") ("wedge"."&and;")
955 ("or") ("vee"."&or;")
956 ("cap")
957 ("cup")
958 ("int")
959 ("there4")
960 ("sim")
961 ("cong") ("simeq"."&cong;")
962 ("asymp")("approx"."&asymp;")
963 ("ne") ("neq"."&ne;")
964 ("equiv")
965 ("le")
966 ("ge")
967 ("sub") ("subset"."&sub;")
968 ("sup") ("supset"."&sup;")
969 ("nsub")
970 ("sube")
971 ("supe")
972 ("oplus")
973 ("otimes")
974 ("perp")
975 ("sdot") ("cdot"."&sdot;")
976 ("lceil")
977 ("rceil")
978 ("lfloor")
979 ("rfloor")
980 ("lang")
981 ("rang")
982 ("loz") ("Diamond"."&loz;")
983 ("spades") ("spadesuit"."&spades;")
984 ("clubs") ("clubsuit"."&clubs;")
985 ("hearts") ("diamondsuit"."&hearts;")
986 ("diams") ("diamondsuit"."&diams;")
987 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
988 ("quot")
989 ("amp")
990 ("lt")
991 ("gt")
992 ("OElig")
993 ("oelig")
994 ("Scaron")
995 ("scaron")
996 ("Yuml")
997 ("circ")
998 ("tilde")
999 ("ensp")
1000 ("emsp")
1001 ("thinsp")
1002 ("zwnj")
1003 ("zwj")
1004 ("lrm")
1005 ("rlm")
1006 ("ndash")
1007 ("mdash")
1008 ("lsquo")
1009 ("rsquo")
1010 ("sbquo")
1011 ("ldquo")
1012 ("rdquo")
1013 ("bdquo")
1014 ("dagger")
1015 ("Dagger")
1016 ("permil")
1017 ("lsaquo")
1018 ("rsaquo")
1019 ("euro")
1021 ("arccos"."arccos")
1022 ("arcsin"."arcsin")
1023 ("arctan"."arctan")
1024 ("arg"."arg")
1025 ("cos"."cos")
1026 ("cosh"."cosh")
1027 ("cot"."cot")
1028 ("coth"."coth")
1029 ("csc"."csc")
1030 ("deg"."deg")
1031 ("det"."det")
1032 ("dim"."dim")
1033 ("exp"."exp")
1034 ("gcd"."gcd")
1035 ("hom"."hom")
1036 ("inf"."inf")
1037 ("ker"."ker")
1038 ("lg"."lg")
1039 ("lim"."lim")
1040 ("liminf"."liminf")
1041 ("limsup"."limsup")
1042 ("ln"."ln")
1043 ("log"."log")
1044 ("max"."max")
1045 ("min"."min")
1046 ("Pr"."Pr")
1047 ("sec"."sec")
1048 ("sin"."sin")
1049 ("sinh"."sinh")
1050 ("sup"."sup")
1051 ("tan"."tan")
1052 ("tanh"."tanh")
1054 "Entities for TeX->HTML translation.
1055 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1056 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1057 In that case, \"\\ent\" will be translated to \"&other;\".
1058 The list contains HTML entities for Latin-1, Greek and other symbols.
1059 It is supplemented by a number of commonly used TeX macros with appropriate
1060 translations. There is currently no way for users to extend this.")
1062 ;;; General functions for all backends
1064 (defun org-cleaned-string-for-export (string &rest parameters)
1065 "Cleanup a buffer STRING so that links can be created safely."
1066 (interactive)
1067 (let* ((re-radio (and org-target-link-regexp
1068 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
1069 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1070 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1071 (re-archive (concat ":" org-archive-tag ":"))
1072 (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
1073 (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1074 (htmlp (plist-get parameters :for-html))
1075 (asciip (plist-get parameters :for-ascii))
1076 (latexp (plist-get parameters :for-LaTeX))
1077 (commentsp (plist-get parameters :comments))
1078 (archived-trees (plist-get parameters :archived-trees))
1079 (inhibit-read-only t)
1080 (drawers org-drawers)
1081 (exp-drawers (plist-get parameters :drawers))
1082 (outline-regexp "\\*+ ")
1083 a b xx
1084 rtn p)
1085 (with-current-buffer (get-buffer-create " org-mode-tmp")
1086 (erase-buffer)
1087 (insert string)
1088 ;; Remove license-to-kill stuff
1089 (while (setq p (text-property-any (point-min) (point-max)
1090 :org-license-to-kill t))
1091 (delete-region p (next-single-property-change p :org-license-to-kill)))
1093 (let ((org-inhibit-startup t)) (org-mode))
1094 (untabify (point-min) (point-max))
1096 ;; Get rid of drawers
1097 (unless (eq t exp-drawers)
1098 (goto-char (point-min))
1099 (let ((re (concat "^[ \t]*:\\("
1100 (mapconcat
1101 'identity
1102 (org-delete-all exp-drawers
1103 (copy-sequence drawers))
1104 "\\|")
1105 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1106 (while (re-search-forward re nil t)
1107 (replace-match ""))))
1109 ;; Get the correct stuff before the first headline
1110 (when (plist-get parameters :skip-before-1st-heading)
1111 (goto-char (point-min))
1112 (when (re-search-forward "^\\*+[ \t]" nil t)
1113 (delete-region (point-min) (match-beginning 0))
1114 (goto-char (point-min))
1115 (insert "\n")))
1116 (when (plist-get parameters :add-text)
1117 (goto-char (point-min))
1118 (insert (plist-get parameters :add-text) "\n"))
1120 ;; Get rid of archived trees
1121 (when (not (eq archived-trees t))
1122 (goto-char (point-min))
1123 (while (re-search-forward re-archive nil t)
1124 (if (not (org-on-heading-p t))
1125 (org-end-of-subtree t)
1126 (beginning-of-line 1)
1127 (setq a (if archived-trees
1128 (1+ (point-at-eol)) (point))
1129 b (org-end-of-subtree t))
1130 (if (> b a) (delete-region a b)))))
1132 ;; Find targets in comments and move them out of comments,
1133 ;; but mark them as targets that should be invisible
1134 (goto-char (point-min))
1135 (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t)
1136 (replace-match "\\1(INVISIBLE)"))
1138 ;; Protect backend specific stuff, throw away the others.
1139 (let ((formatters
1140 `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
1141 (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
1142 (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1143 fmt)
1144 (goto-char (point-min))
1145 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1146 (goto-char (match-end 0))
1147 (while (not (looking-at "#\\+END_EXAMPLE"))
1148 (insert ": ")
1149 (beginning-of-line 2)))
1150 (goto-char (point-min))
1151 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1152 (add-text-properties (match-beginning 0) (match-end 0)
1153 '(org-protected t)))
1154 (while formatters
1155 (setq fmt (pop formatters))
1156 (when (car fmt)
1157 (goto-char (point-min))
1158 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1159 ":[ \t]*\\(.*\\)") nil t)
1160 (replace-match "\\1" t)
1161 (add-text-properties
1162 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1163 '(org-protected t))))
1164 (goto-char (point-min))
1165 (while (re-search-forward
1166 (concat "^#\\+"
1167 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1168 (cadddr fmt) "\\>.*\n?") nil t)
1169 (if (car fmt)
1170 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1171 '(org-protected t))
1172 (delete-region (match-beginning 0) (match-end 0))))))
1174 ;; Protect quoted subtrees
1175 (goto-char (point-min))
1176 (while (re-search-forward re-quote nil t)
1177 (goto-char (match-beginning 0))
1178 (end-of-line 1)
1179 (add-text-properties (point) (org-end-of-subtree t)
1180 '(org-protected t)))
1182 ;; Protect verbatim elements
1183 (goto-char (point-min))
1184 (while (re-search-forward org-verbatim-re nil t)
1185 (add-text-properties (match-beginning 4) (match-end 4)
1186 '(org-protected t))
1187 (goto-char (1+ (match-end 4))))
1189 ;; Remove subtrees that are commented
1190 (goto-char (point-min))
1191 (while (re-search-forward re-commented nil t)
1192 (goto-char (match-beginning 0))
1193 (delete-region (point) (org-end-of-subtree t)))
1195 ;; Remove special table lines
1196 (when org-export-table-remove-special-lines
1197 (goto-char (point-min))
1198 (while (re-search-forward "^[ \t]*|" nil t)
1199 (beginning-of-line 1)
1200 (if (or (looking-at "[ \t]*| *[!_^] *|")
1201 (and (looking-at ".*?| *<[0-9]+> *|")
1202 (not (looking-at ".*?| *[^ <|]"))))
1203 (delete-region (max (point-min) (1- (point-at-bol)))
1204 (point-at-eol))
1205 (end-of-line 1))))
1207 ;; Specific LaTeX stuff
1208 (when latexp
1209 (require 'org-export-latex nil)
1210 (org-export-latex-cleaned-string))
1212 (when asciip
1213 (org-export-ascii-clean-string))
1215 ;; Specific HTML stuff
1216 (when htmlp
1217 ;; Convert LaTeX fragments to images
1218 (when (plist-get parameters :LaTeX-fragments)
1219 (org-format-latex
1220 (concat "ltxpng/" (file-name-sans-extension
1221 (file-name-nondirectory
1222 org-current-export-file)))
1223 org-current-export-dir nil "Creating LaTeX image %s"))
1224 (message "Exporting..."))
1226 ;; Remove or replace comments
1227 (goto-char (point-min))
1228 (while (re-search-forward "^#\\(.*\n?\\)" nil t)
1229 (if commentsp
1230 (progn (add-text-properties
1231 (match-beginning 0) (match-end 0) '(org-protected t))
1232 (replace-match (format commentsp (match-string 1)) t t))
1233 (replace-match "")))
1235 ;; Find matches for radio targets and turn them into internal links
1236 (goto-char (point-min))
1237 (when re-radio
1238 (while (re-search-forward re-radio nil t)
1239 (org-if-unprotected
1240 (replace-match "\\1[[\\2]]"))))
1242 ;; Find all links that contain a newline and put them into a single line
1243 (goto-char (point-min))
1244 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1245 (org-if-unprotected
1246 (replace-match "\\1 \\3")
1247 (goto-char (match-beginning 0))))
1250 ;; Normalize links: Convert angle and plain links into bracket links
1251 ;; Expand link abbreviations
1252 (goto-char (point-min))
1253 (while (re-search-forward re-plain-link nil t)
1254 (goto-char (1- (match-end 0)))
1255 (org-if-unprotected
1256 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1257 ":" (match-string 3) "]]")))
1258 ;; added 'org-link face to links
1259 (put-text-property 0 (length s) 'face 'org-link s)
1260 (replace-match s t t))))
1261 (goto-char (point-min))
1262 (while (re-search-forward re-angle-link nil t)
1263 (goto-char (1- (match-end 0)))
1264 (org-if-unprotected
1265 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1266 ":" (match-string 3) "]]")))
1267 (put-text-property 0 (length s) 'face 'org-link s)
1268 (replace-match s t t))))
1269 (goto-char (point-min))
1270 (while (re-search-forward org-bracket-link-regexp nil t)
1271 (org-if-unprotected
1272 (let* ((s (concat "[[" (setq xx (save-match-data
1273 (org-link-expand-abbrev (match-string 1))))
1275 (if (match-end 3)
1276 (match-string 2)
1277 (concat "[" xx "]"))
1278 "]")))
1279 (put-text-property 0 (length s) 'face 'org-link s)
1280 (replace-match s t t))))
1282 ;; Find multiline emphasis and put them into single line
1283 (when (plist-get parameters :emph-multiline)
1284 (goto-char (point-min))
1285 (while (re-search-forward org-emph-re nil t)
1286 (if (not (= (char-after (match-beginning 3))
1287 (char-after (match-beginning 4))))
1288 (org-if-unprotected
1289 (subst-char-in-region (match-beginning 0) (match-end 0)
1290 ?\n ?\ t)
1291 (goto-char (1- (match-end 0))))
1292 (goto-char (1+ (match-beginning 0))))))
1294 (setq rtn (buffer-string)))
1295 (kill-buffer " org-mode-tmp")
1296 rtn))
1298 (defun org-export-grab-title-from-buffer ()
1299 "Get a title for the current document, from looking at the buffer."
1300 (let ((inhibit-read-only t))
1301 (save-excursion
1302 (goto-char (point-min))
1303 (let ((end (save-excursion (outline-next-heading) (point))))
1304 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1305 ;; Mark the line so that it will not be exported as normal text.
1306 (org-unmodified
1307 (add-text-properties (match-beginning 0) (match-end 0)
1308 (list :org-license-to-kill t)))
1309 ;; Return the title string
1310 (org-trim (match-string 0)))))))
1312 (defun org-export-get-title-from-subtree ()
1313 "Return subtree title and exclude it from export."
1314 (let (title (m (mark)))
1315 (save-excursion
1316 (goto-char (region-beginning))
1317 (when (and (org-at-heading-p)
1318 (>= (org-end-of-subtree t t) (region-end)))
1319 ;; This is a subtree, we take the title from the first heading
1320 (goto-char (region-beginning))
1321 (looking-at org-todo-line-regexp)
1322 (setq title (match-string 3))
1323 (org-unmodified
1324 (add-text-properties (point) (1+ (point-at-eol))
1325 (list :org-license-to-kill t)))))
1326 title))
1328 (defun org-solidify-link-text (s &optional alist)
1329 "Take link text and make a safe target out of it."
1330 (save-match-data
1331 (let* ((rtn
1332 (mapconcat
1333 'identity
1334 (org-split-string s "[ \t\r\n]+") "--"))
1335 (a (assoc rtn alist)))
1336 (or (cdr a) rtn))))
1338 (defun org-get-min-level (lines)
1339 "Get the minimum level in LINES."
1340 (let ((re "^\\(\\*+\\) ") l min)
1341 (catch 'exit
1342 (while (setq l (pop lines))
1343 (if (string-match re l)
1344 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1345 1)))
1347 ;; Variable holding the vector with section numbers
1348 (defvar org-section-numbers (make-vector org-level-max 0))
1350 (defun org-init-section-numbers ()
1351 "Initialize the vector for the section numbers."
1352 (let* ((level -1)
1353 (numbers (nreverse (org-split-string "" "\\.")))
1354 (depth (1- (length org-section-numbers)))
1355 (i depth) number-string)
1356 (while (>= i 0)
1357 (if (> i level)
1358 (aset org-section-numbers i 0)
1359 (setq number-string (or (car numbers) "0"))
1360 (if (string-match "\\`[A-Z]\\'" number-string)
1361 (aset org-section-numbers i
1362 (- (string-to-char number-string) ?A -1))
1363 (aset org-section-numbers i (string-to-number number-string)))
1364 (pop numbers))
1365 (setq i (1- i)))))
1367 (defun org-section-number (&optional level)
1368 "Return a string with the current section number.
1369 When LEVEL is non-nil, increase section numbers on that level."
1370 (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
1371 (when level
1372 (when (> level -1)
1373 (aset org-section-numbers
1374 level (1+ (aref org-section-numbers level))))
1375 (setq idx (1+ level))
1376 (while (<= idx depth)
1377 (if (not (= idx 1))
1378 (aset org-section-numbers idx 0))
1379 (setq idx (1+ idx))))
1380 (setq idx 0)
1381 (while (<= idx depth)
1382 (setq n (aref org-section-numbers idx))
1383 (setq string (concat string (if (not (string= string "")) "." "")
1384 (int-to-string n)))
1385 (setq idx (1+ idx)))
1386 (save-match-data
1387 (if (string-match "\\`\\([@0]\\.\\)+" string)
1388 (setq string (replace-match "" t nil string)))
1389 (if (string-match "\\(\\.0\\)+\\'" string)
1390 (setq string (replace-match "" t nil string))))
1391 string))
1393 ;;; ASCII export
1395 (defvar org-last-level nil) ; dynamically scoped variable
1396 (defvar org-min-level nil) ; dynamically scoped variable
1397 (defvar org-levels-open nil) ; dynamically scoped parameter
1398 (defvar org-ascii-current-indentation nil) ; For communication
1400 ;;;###autoload
1401 (defun org-export-as-ascii (arg)
1402 "Export the outline as a pretty ASCII file.
1403 If there is an active region, export only the region.
1404 The prefix ARG specifies how many levels of the outline should become
1405 underlined headlines. The default is 3."
1406 (interactive "P")
1407 (setq-default org-todo-line-regexp org-todo-line-regexp)
1408 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1409 (org-infile-export-plist)))
1410 (region-p (org-region-active-p))
1411 (subtree-p
1412 (when region-p
1413 (save-excursion
1414 (goto-char (region-beginning))
1415 (and (org-at-heading-p)
1416 (>= (org-end-of-subtree t t) (region-end))))))
1417 (custom-times org-display-custom-times)
1418 (org-ascii-current-indentation '(0 . 0))
1419 (level 0) line txt
1420 (umax nil)
1421 (umax-toc nil)
1422 (case-fold-search nil)
1423 (filename (concat (file-name-as-directory
1424 (org-export-directory :ascii opt-plist))
1425 (file-name-sans-extension
1426 (or (and subtree-p
1427 (org-entry-get (region-beginning)
1428 "EXPORT_FILE_NAME" t))
1429 (file-name-nondirectory buffer-file-name)))
1430 ".txt"))
1431 (filename (if (equal (file-truename filename)
1432 (file-truename buffer-file-name))
1433 (concat filename ".txt")
1434 filename))
1435 (buffer (find-file-noselect filename))
1436 (org-levels-open (make-vector org-level-max nil))
1437 (odd org-odd-levels-only)
1438 (date (plist-get opt-plist :date))
1439 (author (plist-get opt-plist :author))
1440 (title (or (and subtree-p (org-export-get-title-from-subtree))
1441 (plist-get opt-plist :title)
1442 (and (not
1443 (plist-get opt-plist :skip-before-1st-heading))
1444 (org-export-grab-title-from-buffer))
1445 (file-name-sans-extension
1446 (file-name-nondirectory buffer-file-name))))
1447 (email (plist-get opt-plist :email))
1448 (language (plist-get opt-plist :language))
1449 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1450 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1451 (todo nil)
1452 (lang-words nil)
1453 (region
1454 (buffer-substring
1455 (if (org-region-active-p) (region-beginning) (point-min))
1456 (if (org-region-active-p) (region-end) (point-max))))
1457 (lines (org-split-string
1458 (org-cleaned-string-for-export
1459 region
1460 :for-ascii t
1461 :skip-before-1st-heading
1462 (plist-get opt-plist :skip-before-1st-heading)
1463 :drawers (plist-get opt-plist :drawers)
1464 :verbatim-multiline t
1465 :archived-trees
1466 (plist-get opt-plist :archived-trees)
1467 :add-text (plist-get opt-plist :text))
1468 "\n"))
1469 thetoc have-headings first-heading-pos
1470 table-open table-buffer)
1472 (let ((inhibit-read-only t))
1473 (org-unmodified
1474 (remove-text-properties (point-min) (point-max)
1475 '(:org-license-to-kill t))))
1477 (setq org-min-level (org-get-min-level lines))
1478 (setq org-last-level org-min-level)
1479 (org-init-section-numbers)
1481 (find-file-noselect filename)
1483 (setq lang-words (or (assoc language org-export-language-setup)
1484 (assoc "en" org-export-language-setup)))
1485 (switch-to-buffer-other-window buffer)
1486 (erase-buffer)
1487 (fundamental-mode)
1488 ;; create local variables for all options, to make sure all called
1489 ;; functions get the correct information
1490 (mapc (lambda (x)
1491 (set (make-local-variable (cdr x))
1492 (plist-get opt-plist (car x))))
1493 org-export-plist-vars)
1494 (org-set-local 'org-odd-levels-only odd)
1495 (setq umax (if arg (prefix-numeric-value arg)
1496 org-export-headline-levels))
1497 (setq umax-toc (if (integerp org-export-with-toc)
1498 (min org-export-with-toc umax)
1499 umax))
1501 ;; File header
1502 (if title (org-insert-centered title ?=))
1503 (insert "\n")
1504 (if (and (or author email)
1505 org-export-author-info)
1506 (insert (concat (nth 1 lang-words) ": " (or author "")
1507 (if email (concat " <" email ">") "")
1508 "\n")))
1510 (cond
1511 ((and date (string-match "%" date))
1512 (setq date (format-time-string date)))
1513 (date)
1514 (t (setq date (format-time-string "%Y/%m/%d %X"))))
1516 (if (and date org-export-time-stamp-file)
1517 (insert (concat (nth 2 lang-words) ": " date"\n")))
1519 (insert "\n\n")
1521 (if org-export-with-toc
1522 (progn
1523 (push (concat (nth 3 lang-words) "\n") thetoc)
1524 (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
1525 (mapc '(lambda (line)
1526 (if (string-match org-todo-line-regexp
1527 line)
1528 ;; This is a headline
1529 (progn
1530 (setq have-headings t)
1531 (setq level (- (match-end 1) (match-beginning 1))
1532 level (org-tr-level level)
1533 txt (match-string 3 line)
1534 todo
1535 (or (and org-export-mark-todo-in-toc
1536 (match-beginning 2)
1537 (not (member (match-string 2 line)
1538 org-done-keywords)))
1539 ; TODO, not DONE
1540 (and org-export-mark-todo-in-toc
1541 (= level umax-toc)
1542 (org-search-todo-below
1543 line lines level))))
1544 (setq txt (org-html-expand-for-ascii txt))
1546 (while (string-match org-bracket-link-regexp txt)
1547 (setq txt
1548 (replace-match
1549 (match-string (if (match-end 2) 3 1) txt)
1550 t t txt)))
1552 (if (and (memq org-export-with-tags '(not-in-toc nil))
1553 (string-match
1554 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1555 txt))
1556 (setq txt (replace-match "" t t txt)))
1557 (if (string-match quote-re0 txt)
1558 (setq txt (replace-match "" t t txt)))
1560 (if org-export-with-section-numbers
1561 (setq txt (concat (org-section-number level)
1562 " " txt)))
1563 (if (<= level umax-toc)
1564 (progn
1565 (push
1566 (concat
1567 (make-string
1568 (* (max 0 (- level org-min-level)) 4) ?\ )
1569 (format (if todo "%s (*)\n" "%s\n") txt))
1570 thetoc)
1571 (setq org-last-level level))
1572 ))))
1573 lines)
1574 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1576 (org-init-section-numbers)
1577 (while (setq line (pop lines))
1578 ;; Remove the quoted HTML tags.
1579 (setq line (org-html-expand-for-ascii line))
1580 ;; Remove targets
1581 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
1582 (setq line (replace-match "" t t line)))
1583 ;; Replace internal links
1584 (while (string-match org-bracket-link-regexp line)
1585 (setq line (replace-match
1586 (if (match-end 3) "[\\3]" "[\\1]")
1587 t nil line)))
1588 (when custom-times
1589 (setq line (org-translate-time line)))
1590 (cond
1591 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1592 ;; a Headline
1593 (setq first-heading-pos (or first-heading-pos (point)))
1594 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
1595 txt (match-string 2 line))
1596 (org-ascii-level-start level txt umax lines))
1598 ((and org-export-with-tables
1599 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1600 (if (not table-open)
1601 ;; New table starts
1602 (setq table-open t table-buffer nil))
1603 ;; Accumulate lines
1604 (setq table-buffer (cons line table-buffer))
1605 (when (or (not lines)
1606 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1607 (car lines))))
1608 (setq table-open nil
1609 table-buffer (nreverse table-buffer))
1610 (insert (mapconcat
1611 (lambda (x)
1612 (org-fix-indentation x org-ascii-current-indentation))
1613 (org-format-table-ascii table-buffer)
1614 "\n") "\n")))
1616 (setq line (org-fix-indentation line org-ascii-current-indentation))
1617 (if (and org-export-with-fixed-width
1618 (string-match "^\\([ \t]*\\)\\(:\\)" line))
1619 (setq line (replace-match "\\1" nil nil line)))
1620 (insert line "\n"))))
1622 (normal-mode)
1624 ;; insert the table of contents
1625 (when thetoc
1626 (goto-char (point-min))
1627 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
1628 (progn
1629 (goto-char (match-beginning 0))
1630 (replace-match ""))
1631 (goto-char first-heading-pos))
1632 (mapc 'insert thetoc)
1633 (or (looking-at "[ \t]*\n[ \t]*\n")
1634 (insert "\n\n")))
1636 ;; Convert whitespace place holders
1637 (goto-char (point-min))
1638 (let (beg end)
1639 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1640 (setq end (next-single-property-change beg 'org-whitespace))
1641 (goto-char beg)
1642 (delete-region beg end)
1643 (insert (make-string (- end beg) ?\ ))))
1645 (save-buffer)
1646 ;; remove display and invisible chars
1647 (let (beg end)
1648 (goto-char (point-min))
1649 (while (setq beg (next-single-property-change (point) 'display))
1650 (setq end (next-single-property-change beg 'display))
1651 (delete-region beg end)
1652 (goto-char beg)
1653 (insert "=>"))
1654 (goto-char (point-min))
1655 (while (setq beg (next-single-property-change (point) 'org-cwidth))
1656 (setq end (next-single-property-change beg 'org-cwidth))
1657 (delete-region beg end)
1658 (goto-char beg)))
1659 (goto-char (point-min))))
1661 (defun org-export-ascii-clean-string ()
1662 "Do extra work for ASCII export"
1663 (goto-char (point-min))
1664 (while (re-search-forward org-verbatim-re nil t)
1665 (goto-char (match-end 2))
1666 (backward-delete-char 1) (insert "'")
1667 (goto-char (match-beginning 2))
1668 (delete-char 1) (insert "`")
1669 (goto-char (match-end 2))))
1671 (defun org-search-todo-below (line lines level)
1672 "Search the subtree below LINE for any TODO entries."
1673 (let ((rest (cdr (memq line lines)))
1674 (re org-todo-line-regexp)
1675 line lv todo)
1676 (catch 'exit
1677 (while (setq line (pop rest))
1678 (if (string-match re line)
1679 (progn
1680 (setq lv (- (match-end 1) (match-beginning 1))
1681 todo (and (match-beginning 2)
1682 (not (member (match-string 2 line)
1683 org-done-keywords))))
1684 ; TODO, not DONE
1685 (if (<= lv level) (throw 'exit nil))
1686 (if todo (throw 'exit t))))))))
1688 (defun org-html-expand-for-ascii (line)
1689 "Handle quoted HTML for ASCII export."
1690 (if org-export-html-expand
1691 (while (string-match "@<[^<>\n]*>" line)
1692 ;; We just remove the tags for now.
1693 (setq line (replace-match "" nil nil line))))
1694 line)
1696 (defun org-insert-centered (s &optional underline)
1697 "Insert the string S centered and underline it with character UNDERLINE."
1698 (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
1699 (insert (make-string ind ?\ ) s "\n")
1700 (if underline
1701 (insert (make-string ind ?\ )
1702 (make-string (string-width s) underline)
1703 "\n"))))
1705 (defun org-ascii-level-start (level title umax &optional lines)
1706 "Insert a new level in ASCII export."
1707 (let (char (n (- level umax 1)) (ind 0))
1708 (if (> level umax)
1709 (progn
1710 (insert (make-string (* 2 n) ?\ )
1711 (char-to-string (nth (% n (length org-export-ascii-bullets))
1712 org-export-ascii-bullets))
1713 " " title "\n")
1714 ;; find the indentation of the next non-empty line
1715 (catch 'stop
1716 (while lines
1717 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
1718 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
1719 (throw 'stop (setq ind (org-get-indentation (car lines)))))
1720 (pop lines)))
1721 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
1722 (if (or (not (equal (char-before) ?\n))
1723 (not (equal (char-before (1- (point))) ?\n)))
1724 (insert "\n"))
1725 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
1726 (unless org-export-with-tags
1727 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
1728 (setq title (replace-match "" t t title))))
1729 (if org-export-with-section-numbers
1730 (setq title (concat (org-section-number level) " " title)))
1731 (insert title "\n" (make-string (string-width title) char) "\n")
1732 (setq org-ascii-current-indentation '(0 . 0)))))
1734 ;;;###autoload
1735 (defun org-export-visible (type arg)
1736 "Create a copy of the visible part of the current buffer, and export it.
1737 The copy is created in a temporary buffer and removed after use.
1738 TYPE is the final key (as a string) that also select the export command in
1739 the `C-c C-e' export dispatcher.
1740 As a special case, if the you type SPC at the prompt, the temporary
1741 org-mode file will not be removed but presented to you so that you can
1742 continue to use it. The prefix arg ARG is passed through to the exporting
1743 command."
1744 (interactive
1745 (list (progn
1746 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
1747 (read-char-exclusive))
1748 current-prefix-arg))
1749 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
1750 (error "Invalid export key"))
1751 (let* ((binding (cdr (assoc type
1752 '((?a . org-export-as-ascii)
1753 (?\C-a . org-export-as-ascii)
1754 (?b . org-export-as-html-and-open)
1755 (?\C-b . org-export-as-html-and-open)
1756 (?h . org-export-as-html)
1757 (?H . org-export-as-html-to-buffer)
1758 (?R . org-export-region-as-html)
1759 (?x . org-export-as-xoxo)))))
1760 (keepp (equal type ?\ ))
1761 (file buffer-file-name)
1762 (buffer (get-buffer-create "*Org Export Visible*"))
1763 s e)
1764 ;; Need to hack the drawers here.
1765 (save-excursion
1766 (goto-char (point-min))
1767 (while (re-search-forward org-drawer-regexp nil t)
1768 (goto-char (match-beginning 1))
1769 (or (org-invisible-p) (org-flag-drawer nil))))
1770 (with-current-buffer buffer (erase-buffer))
1771 (save-excursion
1772 (setq s (goto-char (point-min)))
1773 (while (not (= (point) (point-max)))
1774 (goto-char (org-find-invisible))
1775 (append-to-buffer buffer s (point))
1776 (setq s (goto-char (org-find-visible))))
1777 (org-cycle-hide-drawers 'all)
1778 (goto-char (point-min))
1779 (unless keepp
1780 ;; Copy all comment lines to the end, to make sure #+ settings are
1781 ;; still available for the second export step. Kind of a hack, but
1782 ;; does do the trick.
1783 (if (looking-at "#[^\r\n]*")
1784 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
1785 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
1786 (append-to-buffer buffer (1+ (match-beginning 0))
1787 (min (point-max) (1+ (match-end 0))))))
1788 (set-buffer buffer)
1789 (let ((buffer-file-name file)
1790 (org-inhibit-startup t))
1791 (org-mode)
1792 (show-all)
1793 (unless keepp (funcall binding arg))))
1794 (if (not keepp)
1795 (kill-buffer buffer)
1796 (switch-to-buffer-other-window buffer)
1797 (goto-char (point-min)))))
1799 (defun org-find-visible ()
1800 (let ((s (point)))
1801 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
1802 (get-char-property s 'invisible)))
1804 (defun org-find-invisible ()
1805 (let ((s (point)))
1806 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
1807 (not (get-char-property s 'invisible))))
1810 ;;; HTML export
1812 (defun org-get-current-options ()
1813 "Return a string with current options as keyword options.
1814 Does include HTML export options as well as TODO and CATEGORY stuff."
1815 (format
1816 "#+TITLE: %s
1817 #+AUTHOR: %s
1818 #+EMAIL: %s
1819 #+DATE: %s
1820 #+LANGUAGE: %s
1821 #+TEXT: Some descriptive text to be emitted. Several lines OK.
1822 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s tags:%s
1823 #+CATEGORY: %s
1824 #+SEQ_TODO: %s
1825 #+TYP_TODO: %s
1826 #+PRIORITIES: %c %c %c
1827 #+DRAWERS: %s
1828 #+STARTUP: %s %s %s %s %s
1829 #+TAGS: %s
1830 #+ARCHIVE: %s
1831 #+LINK: %s
1833 (buffer-name) (user-full-name) user-mail-address
1834 (format-time-string (car org-time-stamp-formats))
1835 org-export-default-language
1836 org-export-headline-levels
1837 org-export-with-section-numbers
1838 org-export-with-toc
1839 org-export-preserve-breaks
1840 org-export-html-expand
1841 org-export-with-fixed-width
1842 org-export-with-tables
1843 org-export-with-sub-superscripts
1844 org-export-with-special-strings
1845 org-export-with-footnotes
1846 org-export-with-emphasize
1847 org-export-with-TeX-macros
1848 org-export-with-LaTeX-fragments
1849 org-export-skip-text-before-1st-heading
1850 org-export-with-drawers
1851 org-export-with-tags
1852 (file-name-nondirectory buffer-file-name)
1853 "TODO FEEDBACK VERIFY DONE"
1854 "Me Jason Marie DONE"
1855 org-highest-priority org-lowest-priority org-default-priority
1856 (mapconcat 'identity org-drawers " ")
1857 (cdr (assoc org-startup-folded
1858 '((nil . "showall") (t . "overview") (content . "content"))))
1859 (if org-odd-levels-only "odd" "oddeven")
1860 (if org-hide-leading-stars "hidestars" "showstars")
1861 (if org-startup-align-all-tables "align" "noalign")
1862 (cond ((eq org-log-done t) "logdone")
1863 ((equal org-log-done 'note) "lognotedone")
1864 ((not org-log-done) "nologdone"))
1865 (or (mapconcat (lambda (x)
1866 (cond
1867 ((equal '(:startgroup) x) "{")
1868 ((equal '(:endgroup) x) "}")
1869 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
1870 (t (car x))))
1871 (or org-tag-alist (org-get-buffer-tags)) " ") "")
1872 org-archive-location
1873 "org file:~/org/%s.org"
1876 ;;;###autoload
1877 (defun org-insert-export-options-template ()
1878 "Insert into the buffer a template with information for exporting."
1879 (interactive)
1880 (if (not (bolp)) (newline))
1881 (let ((s (org-get-current-options)))
1882 (and (string-match "#\\+CATEGORY" s)
1883 (setq s (substring s 0 (match-beginning 0))))
1884 (insert s)))
1886 ;;;###autoload
1887 (defun org-export-as-html-and-open (arg)
1888 "Export the outline as HTML and immediately open it with a browser.
1889 If there is an active region, export only the region.
1890 The prefix ARG specifies how many levels of the outline should become
1891 headlines. The default is 3. Lower levels will become bulleted lists."
1892 (interactive "P")
1893 (org-export-as-html arg 'hidden)
1894 (org-open-file buffer-file-name))
1896 ;;;###autoload
1897 (defun org-export-as-html-batch ()
1898 "Call `org-export-as-html', may be used in batch processing as
1899 emacs --batch
1900 --load=$HOME/lib/emacs/org.el
1901 --eval \"(setq org-export-headline-levels 2)\"
1902 --visit=MyFile --funcall org-export-as-html-batch"
1903 (org-export-as-html org-export-headline-levels 'hidden))
1905 ;;;###autoload
1906 (defun org-export-as-html-to-buffer (arg)
1907 "Call `org-exort-as-html` with output to a temporary buffer.
1908 No file is created. The prefix ARG is passed through to `org-export-as-html'."
1909 (interactive "P")
1910 (org-export-as-html arg nil nil "*Org HTML Export*")
1911 (switch-to-buffer-other-window "*Org HTML Export*"))
1913 ;;;###autoload
1914 (defun org-replace-region-by-html (beg end)
1915 "Assume the current region has org-mode syntax, and convert it to HTML.
1916 This can be used in any buffer. For example, you could write an
1917 itemized list in org-mode syntax in an HTML buffer and then use this
1918 command to convert it."
1919 (interactive "r")
1920 (let (reg html buf pop-up-frames)
1921 (save-window-excursion
1922 (if (org-mode-p)
1923 (setq html (org-export-region-as-html
1924 beg end t 'string))
1925 (setq reg (buffer-substring beg end)
1926 buf (get-buffer-create "*Org tmp*"))
1927 (with-current-buffer buf
1928 (erase-buffer)
1929 (insert reg)
1930 (org-mode)
1931 (setq html (org-export-region-as-html
1932 (point-min) (point-max) t 'string)))
1933 (kill-buffer buf)))
1934 (delete-region beg end)
1935 (insert html)))
1937 ;;;###autoload
1938 (defun org-export-region-as-html (beg end &optional body-only buffer)
1939 "Convert region from BEG to END in org-mode buffer to HTML.
1940 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
1941 contents, and only produce the region of converted text, useful for
1942 cut-and-paste operations.
1943 If BUFFER is a buffer or a string, use/create that buffer as a target
1944 of the converted HTML. If BUFFER is the symbol `string', return the
1945 produced HTML as a string and leave not buffer behind. For example,
1946 a Lisp program could call this function in the following way:
1948 (setq html (org-export-region-as-html beg end t 'string))
1950 When called interactively, the output buffer is selected, and shown
1951 in a window. A non-interactive call will only retunr the buffer."
1952 (interactive "r\nP")
1953 (when (interactive-p)
1954 (setq buffer "*Org HTML Export*"))
1955 (let ((transient-mark-mode t) (zmacs-regions t)
1956 rtn)
1957 (goto-char end)
1958 (set-mark (point)) ;; to activate the region
1959 (goto-char beg)
1960 (setq rtn (org-export-as-html
1961 nil nil nil
1962 buffer body-only))
1963 (if (fboundp 'deactivate-mark) (deactivate-mark))
1964 (if (and (interactive-p) (bufferp rtn))
1965 (switch-to-buffer-other-window rtn)
1966 rtn)))
1968 (defvar html-table-tag nil) ; dynamically scoped into this.
1969 ;;;###autoload
1970 (defun org-export-as-html (arg &optional hidden ext-plist
1971 to-buffer body-only pub-dir)
1972 "Export the outline as a pretty HTML file.
1973 If there is an active region, export only the region. The prefix
1974 ARG specifies how many levels of the outline should become
1975 headlines. The default is 3. Lower levels will become bulleted
1976 lists. When HIDDEN is non-nil, don't display the HTML buffer.
1977 EXT-PLIST is a property list with external parameters overriding
1978 org-mode's default settings, but still inferior to file-local
1979 settings. When TO-BUFFER is non-nil, create a buffer with that
1980 name and export to that buffer. If TO-BUFFER is the symbol
1981 `string', don't leave any buffer behind but just return the
1982 resulting HTML as a string. When BODY-ONLY is set, don't produce
1983 the file header and footer, simply return the content of
1984 <body>...</body>, without even the body tags themselves. When
1985 PUB-DIR is set, use this as the publishing directory."
1986 (interactive "P")
1988 ;; Make sure we have a file name when we need it.
1989 (when (and (not (or to-buffer body-only))
1990 (not buffer-file-name))
1991 (if (buffer-base-buffer)
1992 (org-set-local 'buffer-file-name
1993 (with-current-buffer (buffer-base-buffer)
1994 buffer-file-name))
1995 (error "Need a file name to be able to export.")))
1997 (message "Exporting...")
1998 (setq-default org-todo-line-regexp org-todo-line-regexp)
1999 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2000 (setq-default org-done-keywords org-done-keywords)
2001 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2002 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2003 ext-plist
2004 (org-infile-export-plist)))
2006 (style (plist-get opt-plist :style))
2007 (html-extension (plist-get opt-plist :html-extension))
2008 (link-validate (plist-get opt-plist :link-validation-function))
2009 valid thetoc have-headings first-heading-pos
2010 (odd org-odd-levels-only)
2011 (region-p (org-region-active-p))
2012 (subtree-p
2013 (when region-p
2014 (save-excursion
2015 (goto-char (region-beginning))
2016 (and (org-at-heading-p)
2017 (>= (org-end-of-subtree t t) (region-end))))))
2018 ;; The following two are dynamically scoped into other
2019 ;; routines below.
2020 (org-current-export-dir
2021 (or pub-dir (org-export-directory :html opt-plist)))
2022 (org-current-export-file buffer-file-name)
2023 (level 0) (line "") (origline "") txt todo
2024 (umax nil)
2025 (umax-toc nil)
2026 (filename (if to-buffer nil
2027 (expand-file-name
2028 (concat
2029 (file-name-sans-extension
2030 (or (and subtree-p
2031 (org-entry-get (region-beginning)
2032 "EXPORT_FILE_NAME" t))
2033 (file-name-nondirectory buffer-file-name)))
2034 "." html-extension)
2035 (file-name-as-directory
2036 (or pub-dir (org-export-directory :html opt-plist))))))
2037 (current-dir (if buffer-file-name
2038 (file-name-directory buffer-file-name)
2039 default-directory))
2040 (buffer (if to-buffer
2041 (cond
2042 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2043 (t (get-buffer-create to-buffer)))
2044 (find-file-noselect filename)))
2045 (org-levels-open (make-vector org-level-max nil))
2046 (date (plist-get opt-plist :date))
2047 (author (plist-get opt-plist :author))
2048 (title (or (and subtree-p (org-export-get-title-from-subtree))
2049 (plist-get opt-plist :title)
2050 (and (not
2051 (plist-get opt-plist :skip-before-1st-heading))
2052 (org-export-grab-title-from-buffer))
2053 (and buffer-file-name
2054 (file-name-sans-extension
2055 (file-name-nondirectory buffer-file-name)))
2056 "UNTITLED"))
2057 (html-table-tag (plist-get opt-plist :html-table-tag))
2058 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2059 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2060 (inquote nil)
2061 (infixed nil)
2062 (in-local-list nil)
2063 (local-list-num nil)
2064 (local-list-indent nil)
2065 (llt org-plain-list-ordered-item-terminator)
2066 (email (plist-get opt-plist :email))
2067 (language (plist-get opt-plist :language))
2068 (lang-words nil)
2069 (target-alist nil) tg
2070 (head-count 0) cnt
2071 (start 0)
2072 (coding-system (and (boundp 'buffer-file-coding-system)
2073 buffer-file-coding-system))
2074 (coding-system-for-write (or org-export-html-coding-system
2075 coding-system))
2076 (save-buffer-coding-system (or org-export-html-coding-system
2077 coding-system))
2078 (charset (and coding-system-for-write
2079 (fboundp 'coding-system-get)
2080 (coding-system-get coding-system-for-write
2081 'mime-charset)))
2082 (region
2083 (buffer-substring
2084 (if region-p (region-beginning) (point-min))
2085 (if region-p (region-end) (point-max))))
2086 (lines
2087 (org-split-string
2088 (org-cleaned-string-for-export
2089 region
2090 :emph-multiline t
2091 :for-html t
2092 :skip-before-1st-heading
2093 (plist-get opt-plist :skip-before-1st-heading)
2094 :drawers (plist-get opt-plist :drawers)
2095 :archived-trees
2096 (plist-get opt-plist :archived-trees)
2097 :add-text
2098 (plist-get opt-plist :text)
2099 :LaTeX-fragments
2100 (plist-get opt-plist :LaTeX-fragments))
2101 "[\r\n]"))
2102 table-open type
2103 table-buffer table-orig-buffer
2104 ind start-is-num starter didclose
2105 rpl path desc descp desc1 desc2 link
2106 snumber fnc
2109 (let ((inhibit-read-only t))
2110 (org-unmodified
2111 (remove-text-properties (point-min) (point-max)
2112 '(:org-license-to-kill t))))
2114 (message "Exporting...")
2116 (setq org-min-level (org-get-min-level lines))
2117 (setq org-last-level org-min-level)
2118 (org-init-section-numbers)
2120 (cond
2121 ((and date (string-match "%" date))
2122 (setq date (format-time-string date)))
2123 (date)
2124 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2126 ;; Get the language-dependent settings
2127 (setq lang-words (or (assoc language org-export-language-setup)
2128 (assoc "en" org-export-language-setup)))
2130 ;; Switch to the output buffer
2131 (set-buffer buffer)
2132 (let ((inhibit-read-only t)) (erase-buffer))
2133 (fundamental-mode)
2135 (and (fboundp 'set-buffer-file-coding-system)
2136 (set-buffer-file-coding-system coding-system-for-write))
2138 (let ((case-fold-search nil)
2139 (org-odd-levels-only odd))
2140 ;; create local variables for all options, to make sure all called
2141 ;; functions get the correct information
2142 (mapc (lambda (x)
2143 (set (make-local-variable (cdr x))
2144 (plist-get opt-plist (car x))))
2145 org-export-plist-vars)
2146 (setq umax (if arg (prefix-numeric-value arg)
2147 org-export-headline-levels))
2148 (setq umax-toc (if (integerp org-export-with-toc)
2149 (min org-export-with-toc umax)
2150 umax))
2151 (unless body-only
2152 ;; File header
2153 (insert (format
2154 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2155 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2156 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2157 lang=\"%s\" xml:lang=\"%s\">
2158 <head>
2159 <title>%s</title>
2160 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2161 <meta name=\"generator\" content=\"Org-mode\"/>
2162 <meta name=\"generated\" content=\"%s\"/>
2163 <meta name=\"author\" content=\"%s\"/>
2165 </head><body>
2167 language language (org-html-expand title)
2168 (or charset "iso-8859-1") date author style))
2170 (insert (or (plist-get opt-plist :preamble) ""))
2172 (when (plist-get opt-plist :auto-preamble)
2173 (if title (insert (format org-export-html-title-format
2174 (org-html-expand title))))))
2176 (if (and org-export-with-toc (not body-only))
2177 (progn
2178 (push (format "<h%d>%s</h%d>\n"
2179 org-export-html-toplevel-hlevel
2180 (nth 3 lang-words)
2181 org-export-html-toplevel-hlevel)
2182 thetoc)
2183 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2184 (push "<ul>\n<li>" thetoc)
2185 (setq lines
2186 (mapcar '(lambda (line)
2187 (if (string-match org-todo-line-regexp line)
2188 ;; This is a headline
2189 (progn
2190 (setq have-headings t)
2191 (setq level (- (match-end 1) (match-beginning 1))
2192 level (org-tr-level level)
2193 txt (save-match-data
2194 (org-html-expand
2195 (org-export-cleanup-toc-line
2196 (match-string 3 line))))
2197 todo
2198 (or (and org-export-mark-todo-in-toc
2199 (match-beginning 2)
2200 (not (member (match-string 2 line)
2201 org-done-keywords)))
2202 ; TODO, not DONE
2203 (and org-export-mark-todo-in-toc
2204 (= level umax-toc)
2205 (org-search-todo-below
2206 line lines level))))
2207 (if (string-match
2208 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2209 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2210 (if (string-match quote-re0 txt)
2211 (setq txt (replace-match "" t t txt)))
2212 (setq snumber (org-section-number level))
2213 (if org-export-with-section-numbers
2214 (setq txt (concat snumber " " txt)))
2215 (if (<= level (max umax umax-toc))
2216 (setq head-count (+ head-count 1)))
2217 (if (<= level umax-toc)
2218 (progn
2219 (if (> level org-last-level)
2220 (progn
2221 (setq cnt (- level org-last-level))
2222 (while (>= (setq cnt (1- cnt)) 0)
2223 (push "\n<ul>\n<li>" thetoc))
2224 (push "\n" thetoc)))
2225 (if (< level org-last-level)
2226 (progn
2227 (setq cnt (- org-last-level level))
2228 (while (>= (setq cnt (1- cnt)) 0)
2229 (push "</li>\n</ul>" thetoc))
2230 (push "\n" thetoc)))
2231 ;; Check for targets
2232 (while (string-match org-target-regexp line)
2233 (setq tg (match-string 1 line)
2234 line (replace-match
2235 (concat "@<span class=\"target\">" tg "@</span> ")
2236 t t line))
2237 (push (cons (org-solidify-link-text tg)
2238 (format "sec-%s" snumber))
2239 target-alist))
2240 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2241 (setq txt (replace-match "" t t txt)))
2242 (push
2243 (format
2244 (if todo
2245 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2246 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2247 snumber txt) thetoc)
2249 (setq org-last-level level))
2251 line)
2252 lines))
2253 (while (> org-last-level (1- org-min-level))
2254 (setq org-last-level (1- org-last-level))
2255 (push "</li>\n</ul>\n" thetoc))
2256 (push "</div>\n" thetoc)
2257 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2259 (setq head-count 0)
2260 (org-init-section-numbers)
2262 (while (setq line (pop lines) origline line)
2263 (catch 'nextline
2265 ;; end of quote section?
2266 (when (and inquote (string-match "^\\*+ " line))
2267 (insert "</pre>\n")
2268 (setq inquote nil))
2269 ;; inside a quote section?
2270 (when inquote
2271 (insert (org-html-protect line) "\n")
2272 (throw 'nextline nil))
2274 ;; verbatim lines
2275 (when (and org-export-with-fixed-width
2276 (string-match "^[ \t]*:\\(.*\\)" line))
2277 (when (not infixed)
2278 (setq infixed t)
2279 (insert "<pre>\n"))
2280 (insert (org-html-protect (match-string 1 line)) "\n")
2281 (when (and lines
2282 (not (string-match "^[ \t]*\\(:.*\\)"
2283 (car lines))))
2284 (setq infixed nil)
2285 (insert "</pre>\n"))
2286 (throw 'nextline nil))
2288 ;; Protected HTML
2289 (when (get-text-property 0 'org-protected line)
2290 (let (par)
2291 (when (re-search-backward
2292 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2293 (setq par (match-string 1))
2294 (replace-match "\\2\n"))
2295 (insert line "\n")
2296 (while (and lines
2297 (or (= (length (car lines)) 0)
2298 (get-text-property 0 'org-protected (car lines))))
2299 (insert (pop lines) "\n"))
2300 (and par (insert "<p>\n")))
2301 (throw 'nextline nil))
2303 ;; Horizontal line
2304 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2305 (insert "\n<hr/>\n")
2306 (throw 'nextline nil))
2308 ;; make targets to anchors
2309 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2310 (cond
2311 ((match-end 2)
2312 (setq line (replace-match
2313 (concat "@<a name=\""
2314 (org-solidify-link-text (match-string 1 line))
2315 "\">\\nbsp@</a>")
2316 t t line)))
2317 ((and org-export-with-toc (equal (string-to-char line) ?*))
2318 (setq line (replace-match
2319 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2320 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2321 t t line)))
2323 (setq line (replace-match
2324 (concat "@<a name=\""
2325 (org-solidify-link-text (match-string 1 line))
2326 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2327 t t line)))))
2329 (setq line (org-html-handle-time-stamps line))
2331 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2332 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2333 ;; Also handle sub_superscripts and checkboxes
2334 (or (string-match org-table-hline-regexp line)
2335 (setq line (org-html-expand line)))
2337 ;; Format the links
2338 (setq start 0)
2339 (while (string-match org-bracket-link-analytic-regexp line start)
2340 (setq start (match-beginning 0))
2341 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2342 (setq path (match-string 3 line))
2343 (setq desc1 (if (match-end 5) (match-string 5 line))
2344 desc2 (if (match-end 2) (concat type ":" path) path)
2345 descp (and desc1 (not (equal desc1 desc2)))
2346 desc (or desc1 desc2))
2347 ;; Make an image out of the description if that is so wanted
2348 (when (and descp (org-file-image-p desc))
2349 (save-match-data
2350 (if (string-match "^file:" desc)
2351 (setq desc (substring desc (match-end 0)))))
2352 (setq desc (concat "<img src=\"" desc "\"/>")))
2353 ;; FIXME: do we need to unescape here somewhere?
2354 (cond
2355 ((equal type "internal")
2356 (setq rpl
2357 (concat
2358 "<a href=\"#"
2359 (org-solidify-link-text
2360 (save-match-data (org-link-unescape path)) target-alist)
2361 "\">" desc "</a>")))
2362 ((member type '("http" "https"))
2363 ;; standard URL, just check if we need to inline an image
2364 (if (and (or (eq t org-export-html-inline-images)
2365 (and org-export-html-inline-images (not descp)))
2366 (org-file-image-p path))
2367 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2368 (setq link (concat type ":" path))
2369 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2370 ((member type '("ftp" "mailto" "news"))
2371 ;; standard URL
2372 (setq link (concat type ":" path))
2373 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2374 ((string= type "file")
2375 ;; FILE link
2376 (let* ((filename path)
2377 (abs-p (file-name-absolute-p filename))
2378 thefile file-is-image-p search)
2379 (save-match-data
2380 (if (string-match "::\\(.*\\)" filename)
2381 (setq search (match-string 1 filename)
2382 filename (replace-match "" t nil filename)))
2383 (setq valid
2384 (if (functionp link-validate)
2385 (funcall link-validate filename current-dir)
2387 (setq file-is-image-p (org-file-image-p filename))
2388 (setq thefile (if abs-p (expand-file-name filename) filename))
2389 (when (and org-export-html-link-org-files-as-html
2390 (string-match "\\.org$" thefile))
2391 (setq thefile (concat (substring thefile 0
2392 (match-beginning 0))
2393 "." html-extension))
2394 (if (and search
2395 ;; make sure this is can be used as target search
2396 (not (string-match "^[0-9]*$" search))
2397 (not (string-match "^\\*" search))
2398 (not (string-match "^/.*/$" search)))
2399 (setq thefile (concat thefile "#"
2400 (org-solidify-link-text
2401 (org-link-unescape search)))))
2402 (when (string-match "^file:" desc)
2403 (setq desc (replace-match "" t t desc))
2404 (if (string-match "\\.org$" desc)
2405 (setq desc (replace-match "" t t desc))))))
2406 (setq rpl (if (and file-is-image-p
2407 (or (eq t org-export-html-inline-images)
2408 (and org-export-html-inline-images
2409 (not descp))))
2410 (concat "<img src=\"" thefile "\"/>")
2411 (concat "<a href=\"" thefile "\">" desc "</a>")))
2412 (if (not valid) (setq rpl desc))))
2414 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2415 (setq rpl
2416 (save-match-data
2417 (funcall fnc (org-link-unescape path) desc1 'html))))
2420 ;; just publish the path, as default
2421 (setq rpl (concat "<i>&lt;" type ":"
2422 (save-match-data (org-link-unescape path))
2423 "&gt;</i>"))))
2424 (setq line (replace-match rpl t t line)
2425 start (+ start (length rpl))))
2427 ;; TODO items
2428 (if (and (string-match org-todo-line-regexp line)
2429 (match-beginning 2))
2431 (setq line
2432 (concat (substring line 0 (match-beginning 2))
2433 "<span class=\""
2434 (if (member (match-string 2 line)
2435 org-done-keywords)
2436 "done" "todo")
2437 "\">" (match-string 2 line)
2438 "</span>" (substring line (match-end 2)))))
2440 ;; Does this contain a reference to a footnote?
2441 (when org-export-with-footnotes
2442 (setq start 0)
2443 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
2444 (if (get-text-property (match-beginning 2) 'org-protected line)
2445 (setq start (match-end 2))
2446 (let ((n (match-string 2 line)))
2447 (setq line
2448 (replace-match
2449 (format
2450 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2451 (match-string 1 line) n n n)
2452 t t line))))))
2454 (cond
2455 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2456 ;; This is a headline
2457 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2458 txt (match-string 2 line))
2459 (if (string-match quote-re0 txt)
2460 (setq txt (replace-match "" t t txt)))
2461 (if (<= level (max umax umax-toc))
2462 (setq head-count (+ head-count 1)))
2463 (when in-local-list
2464 ;; Close any local lists before inserting a new header line
2465 (while local-list-num
2466 (org-close-li)
2467 (insert (if (car local-list-num) "</ol>\n" "</ul>"))
2468 (pop local-list-num))
2469 (setq local-list-indent nil
2470 in-local-list nil))
2471 (setq first-heading-pos (or first-heading-pos (point)))
2472 (org-html-level-start level txt umax
2473 (and org-export-with-toc (<= level umax))
2474 head-count)
2475 ;; QUOTES
2476 (when (string-match quote-re line)
2477 (insert "<pre>")
2478 (setq inquote t)))
2480 ((and org-export-with-tables
2481 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2482 (if (not table-open)
2483 ;; New table starts
2484 (setq table-open t table-buffer nil table-orig-buffer nil))
2485 ;; Accumulate lines
2486 (setq table-buffer (cons line table-buffer)
2487 table-orig-buffer (cons origline table-orig-buffer))
2488 (when (or (not lines)
2489 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2490 (car lines))))
2491 (setq table-open nil
2492 table-buffer (nreverse table-buffer)
2493 table-orig-buffer (nreverse table-orig-buffer))
2494 (org-close-par-maybe)
2495 (insert (org-format-table-html table-buffer table-orig-buffer))))
2497 ;; Normal lines
2498 (when (string-match
2499 (cond
2500 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2501 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2502 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2503 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2504 line)
2505 (setq ind (org-get-string-indentation line)
2506 start-is-num (match-beginning 4)
2507 starter (if (match-beginning 2)
2508 (substring (match-string 2 line) 0 -1))
2509 line (substring line (match-beginning 5)))
2510 (unless (string-match "[^ \t]" line)
2511 ;; empty line. Pretend indentation is large.
2512 (setq ind (if org-empty-line-terminates-plain-lists
2514 (1+ (or (car local-list-indent) 1)))))
2515 (setq didclose nil)
2516 (while (and in-local-list
2517 (or (and (= ind (car local-list-indent))
2518 (not starter))
2519 (< ind (car local-list-indent))))
2520 (setq didclose t)
2521 (org-close-li)
2522 (insert (if (car local-list-num) "</ol>\n" "</ul>"))
2523 (pop local-list-num) (pop local-list-indent)
2524 (setq in-local-list local-list-indent))
2525 (cond
2526 ((and starter
2527 (or (not in-local-list)
2528 (> ind (car local-list-indent))))
2529 ;; Start new (level of) list
2530 (org-close-par-maybe)
2531 (insert (if start-is-num "<ol>\n<li>\n" "<ul>\n<li>\n"))
2532 (push start-is-num local-list-num)
2533 (push ind local-list-indent)
2534 (setq in-local-list t))
2535 (starter
2536 ;; continue current list
2537 (org-close-li)
2538 (insert "<li>\n"))
2539 (didclose
2540 ;; we did close a list, normal text follows: need <p>
2541 (org-open-par)))
2542 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
2543 (setq line
2544 (replace-match
2545 (if (equal (match-string 1 line) "X")
2546 "<b>[X]</b>"
2547 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2548 t t line))))
2550 ;; Empty lines start a new paragraph. If hand-formatted lists
2551 ;; are not fully interpreted, lines starting with "-", "+", "*"
2552 ;; also start a new paragraph.
2553 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
2555 ;; Is this the start of a footnote?
2556 (when org-export-with-footnotes
2557 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
2558 (org-close-par-maybe)
2559 (let ((n (match-string 1 line)))
2560 (setq line (replace-match
2561 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
2563 ;; Check if the line break needs to be conserved
2564 (cond
2565 ((string-match "\\\\\\\\[ \t]*$" line)
2566 (setq line (replace-match "<br/>" t t line)))
2567 (org-export-preserve-breaks
2568 (setq line (concat line "<br/>"))))
2570 (insert line "\n")))))
2572 ;; Properly close all local lists and other lists
2573 (when inquote (insert "</pre>\n"))
2574 (when in-local-list
2575 ;; Close any local lists before inserting a new header line
2576 (while local-list-num
2577 (org-close-li)
2578 (insert (if (car local-list-num) "</ol>\n" "</ul>\n"))
2579 (pop local-list-num))
2580 (setq local-list-indent nil
2581 in-local-list nil))
2582 (org-html-level-start 1 nil umax
2583 (and org-export-with-toc (<= level umax))
2584 head-count)
2585 ;; the </div> to lose the last text-... div.
2586 (insert "</div>\n")
2588 (unless body-only
2589 (when (plist-get opt-plist :auto-postamble)
2590 (insert "<div id=\"postamble\">")
2591 (when (and org-export-author-info author)
2592 (insert "<p class=\"author\"> "
2593 (nth 1 lang-words) ": " author "\n")
2594 (when email
2595 (if (listp (split-string email ",+ *"))
2596 (mapc (lambda(e)
2597 (insert "<a href=\"mailto:" e "\">&lt;"
2598 e "&gt;</a>\n"))
2599 (split-string email ",+ *"))
2600 (insert "<a href=\"mailto:" email "\">&lt;"
2601 email "&gt;</a>\n")))
2602 (insert "</p>\n"))
2603 (when (and date org-export-time-stamp-file)
2604 (insert "<p class=\"date\"> "
2605 (nth 2 lang-words) ": "
2606 date "</p>\n"))
2607 (insert "</div>"))
2609 (if org-export-html-with-timestamp
2610 (insert org-export-html-html-helper-timestamp))
2611 (insert (or (plist-get opt-plist :postamble) ""))
2612 (insert "</body>\n</html>\n"))
2614 (normal-mode)
2615 (if (eq major-mode default-major-mode) (html-mode))
2617 ;; insert the table of contents
2618 (goto-char (point-min))
2619 (when thetoc
2620 (if (or (re-search-forward
2621 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
2622 (re-search-forward
2623 "\\[TABLE-OF-CONTENTS\\]" nil t))
2624 (progn
2625 (goto-char (match-beginning 0))
2626 (replace-match ""))
2627 (goto-char first-heading-pos)
2628 (when (looking-at "\\s-*</p>")
2629 (goto-char (match-end 0))
2630 (insert "\n")))
2631 (insert "<div id=\"table-of-contents\">\n")
2632 (mapc 'insert thetoc)
2633 (insert "</div>\n"))
2634 ;; remove empty paragraphs and lists
2635 (goto-char (point-min))
2636 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2637 (replace-match ""))
2638 (goto-char (point-min))
2639 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
2640 (replace-match ""))
2641 (goto-char (point-min))
2642 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
2643 (replace-match ""))
2644 ;; Convert whitespace place holders
2645 (goto-char (point-min))
2646 (let (beg end n)
2647 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2648 (setq n (get-text-property beg 'org-whitespace)
2649 end (next-single-property-change beg 'org-whitespace))
2650 (goto-char beg)
2651 (delete-region beg end)
2652 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2653 (make-string n ?x)))))
2654 (or to-buffer (save-buffer))
2655 (goto-char (point-min))
2656 (message "Exporting... done")
2657 (if (eq to-buffer 'string)
2658 (prog1 (buffer-substring (point-min) (point-max))
2659 (kill-buffer (current-buffer)))
2660 (current-buffer)))))
2662 (defvar org-table-colgroup-info nil)
2663 (defun org-format-table-ascii (lines)
2664 "Format a table for ascii export."
2665 (if (stringp lines)
2666 (setq lines (org-split-string lines "\n")))
2667 (if (not (string-match "^[ \t]*|" (car lines)))
2668 ;; Table made by table.el - test for spanning
2669 lines
2671 ;; A normal org table
2672 ;; Get rid of hlines at beginning and end
2673 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2674 (setq lines (nreverse lines))
2675 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2676 (setq lines (nreverse lines))
2677 (when org-export-table-remove-special-lines
2678 ;; Check if the table has a marking column. If yes remove the
2679 ;; column and the special lines
2680 (setq lines (org-table-clean-before-export lines)))
2681 ;; Get rid of the vertical lines except for grouping
2682 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
2683 rtn line vl1 start)
2684 (while (setq line (pop lines))
2685 (if (string-match org-table-hline-regexp line)
2686 (and (string-match "|\\(.*\\)|" line)
2687 (setq line (replace-match " \\1" t nil line)))
2688 (setq start 0 vl1 vl)
2689 (while (string-match "|" line start)
2690 (setq start (match-end 0))
2691 (or (pop vl1) (setq line (replace-match " " t t line)))))
2692 (push line rtn))
2693 (nreverse rtn))))
2695 (defun org-colgroup-info-to-vline-list (info)
2696 (let (vl new last)
2697 (while info
2698 (setq last new new (pop info))
2699 (if (or (memq last '(:end :startend))
2700 (memq new '(:start :startend)))
2701 (push t vl)
2702 (push nil vl)))
2703 (setq vl (nreverse vl))
2704 (and vl (setcar vl nil))
2705 vl))
2707 (defvar org-table-number-regexp) ; defined in org-table.el
2708 (defun org-format-table-html (lines olines)
2709 "Find out which HTML converter to use and return the HTML code."
2710 (if (stringp lines)
2711 (setq lines (org-split-string lines "\n")))
2712 (if (string-match "^[ \t]*|" (car lines))
2713 ;; A normal org table
2714 (org-format-org-table-html lines)
2715 ;; Table made by table.el - test for spanning
2716 (let* ((hlines (delq nil (mapcar
2717 (lambda (x)
2718 (if (string-match "^[ \t]*\\+-" x) x
2719 nil))
2720 lines)))
2721 (first (car hlines))
2722 (ll (and (string-match "\\S-+" first)
2723 (match-string 0 first)))
2724 (re (concat "^[ \t]*" (regexp-quote ll)))
2725 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
2726 hlines))))
2727 (if (and (not spanning)
2728 (not org-export-prefer-native-exporter-for-tables))
2729 ;; We can use my own converter with HTML conversions
2730 (org-format-table-table-html lines)
2731 ;; Need to use the code generator in table.el, with the original text.
2732 (org-format-table-table-html-using-table-generate-source olines)))))
2734 (defvar org-table-number-fraction) ; defined in org-table.el
2735 (defun org-format-org-table-html (lines &optional splice)
2736 "Format a table into HTML."
2737 (require 'org-table)
2738 ;; Get rid of hlines at beginning and end
2739 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2740 (setq lines (nreverse lines))
2741 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2742 (setq lines (nreverse lines))
2743 (when org-export-table-remove-special-lines
2744 ;; Check if the table has a marking column. If yes remove the
2745 ;; column and the special lines
2746 (setq lines (org-table-clean-before-export lines)))
2748 (let ((head (and org-export-highlight-first-table-line
2749 (delq nil (mapcar
2750 (lambda (x) (string-match "^[ \t]*|-" x))
2751 (cdr lines)))))
2752 (nlines 0) fnum i
2753 tbopen line fields html gr colgropen)
2754 (if splice (setq head nil))
2755 (unless splice (push (if head "<thead>" "<tbody>") html))
2756 (setq tbopen t)
2757 (while (setq line (pop lines))
2758 (catch 'next-line
2759 (if (string-match "^[ \t]*|-" line)
2760 (progn
2761 (unless splice
2762 (push (if head "</thead>" "</tbody>") html)
2763 (if lines (push "<tbody>" html) (setq tbopen nil)))
2764 (setq head nil) ;; head ends here, first time around
2765 ;; ignore this line
2766 (throw 'next-line t)))
2767 ;; Break the line into fields
2768 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2769 (unless fnum (setq fnum (make-vector (length fields) 0)))
2770 (setq nlines (1+ nlines) i -1)
2771 (push (concat "<tr>"
2772 (mapconcat
2773 (lambda (x)
2774 (setq i (1+ i))
2775 (if (and (< i nlines)
2776 (string-match org-table-number-regexp x))
2777 (incf (aref fnum i)))
2778 (if head
2779 (concat (car org-export-table-header-tags) x
2780 (cdr org-export-table-header-tags))
2781 (concat (car org-export-table-data-tags) x
2782 (cdr org-export-table-data-tags))))
2783 fields "")
2784 "</tr>")
2785 html)))
2786 (unless splice (if tbopen (push "</tbody>" html)))
2787 (unless splice (push "</table>\n" html))
2788 (setq html (nreverse html))
2789 (unless splice
2790 ;; Put in col tags with the alignment (unfortuntely often ignored...)
2791 (push (mapconcat
2792 (lambda (x)
2793 (setq gr (pop org-table-colgroup-info))
2794 (format "%s<col align=\"%s\"></col>%s"
2795 (if (memq gr '(:start :startend))
2796 (prog1
2797 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
2798 (setq colgropen t))
2800 (if (> (/ (float x) nlines) org-table-number-fraction)
2801 "right" "left")
2802 (if (memq gr '(:end :startend))
2803 (progn (setq colgropen nil) "</colgroup>")
2804 "")))
2805 fnum "")
2806 html)
2807 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
2808 (push html-table-tag html))
2809 (concat (mapconcat 'identity html "\n") "\n")))
2811 (defun org-table-clean-before-export (lines)
2812 "Check if the table has a marking column.
2813 If yes remove the column and the special lines."
2814 (setq org-table-colgroup-info nil)
2815 (if (memq nil
2816 (mapcar
2817 (lambda (x) (or (string-match "^[ \t]*|-" x)
2818 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
2819 lines))
2820 (progn
2821 (setq org-table-clean-did-remove-column nil)
2822 (delq nil
2823 (mapcar
2824 (lambda (x)
2825 (cond
2826 ((string-match "^[ \t]*| */ *|" x)
2827 (setq org-table-colgroup-info
2828 (mapcar (lambda (x)
2829 (cond ((member x '("<" "&lt;")) :start)
2830 ((member x '(">" "&gt;")) :end)
2831 ((member x '("<>" "&lt;&gt;")) :startend)
2832 (t nil)))
2833 (org-split-string x "[ \t]*|[ \t]*")))
2834 nil)
2835 (t x)))
2836 lines)))
2837 (setq org-table-clean-did-remove-column t)
2838 (delq nil
2839 (mapcar
2840 (lambda (x)
2841 (cond
2842 ((string-match "^[ \t]*| */ *|" x)
2843 (setq org-table-colgroup-info
2844 (mapcar (lambda (x)
2845 (cond ((member x '("<" "&lt;")) :start)
2846 ((member x '(">" "&gt;")) :end)
2847 ((member x '("<>" "&lt;&gt;")) :startend)
2848 (t nil)))
2849 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2850 nil)
2851 ((string-match "^[ \t]*| *[!_^/] *|" x)
2852 nil) ; ignore this line
2853 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2854 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2855 ;; remove the first column
2856 (replace-match "\\1|" t nil x))))
2857 lines))))
2859 (defun org-format-table-table-html (lines)
2860 "Format a table generated by table.el into HTML.
2861 This conversion does *not* use `table-generate-source' from table.el.
2862 This has the advantage that Org-mode's HTML conversions can be used.
2863 But it has the disadvantage, that no cell- or row-spanning is allowed."
2864 (let (line field-buffer
2865 (head org-export-highlight-first-table-line)
2866 fields html empty)
2867 (setq html (concat html-table-tag "\n"))
2868 (while (setq line (pop lines))
2869 (setq empty "&nbsp;")
2870 (catch 'next-line
2871 (if (string-match "^[ \t]*\\+-" line)
2872 (progn
2873 (if field-buffer
2874 (progn
2875 (setq
2876 html
2877 (concat
2878 html
2879 "<tr>"
2880 (mapconcat
2881 (lambda (x)
2882 (if (equal x "") (setq x empty))
2883 (if head
2884 (concat (car org-export-table-header-tags) x
2885 (cdr org-export-table-header-tags))
2886 (concat (car org-export-table-data-tags) x
2887 (cdr org-export-table-data-tags))))
2888 field-buffer "\n")
2889 "</tr>\n"))
2890 (setq head nil)
2891 (setq field-buffer nil)))
2892 ;; Ignore this line
2893 (throw 'next-line t)))
2894 ;; Break the line into fields and store the fields
2895 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2896 (if field-buffer
2897 (setq field-buffer (mapcar
2898 (lambda (x)
2899 (concat x "<br/>" (pop fields)))
2900 field-buffer))
2901 (setq field-buffer fields))))
2902 (setq html (concat html "</table>\n"))
2903 html))
2905 (defun org-format-table-table-html-using-table-generate-source (lines)
2906 "Format a table into html, using `table-generate-source' from table.el.
2907 This has the advantage that cell- or row-spanning is allowed.
2908 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
2909 (require 'table)
2910 (with-current-buffer (get-buffer-create " org-tmp1 ")
2911 (erase-buffer)
2912 (insert (mapconcat 'identity lines "\n"))
2913 (goto-char (point-min))
2914 (if (not (re-search-forward "|[^+]" nil t))
2915 (error "Error processing table"))
2916 (table-recognize-table)
2917 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2918 (table-generate-source 'html " org-tmp2 ")
2919 (set-buffer " org-tmp2 ")
2920 (buffer-substring (point-min) (point-max))))
2922 (defun org-html-handle-time-stamps (s)
2923 "Format time stamps in string S, or remove them."
2924 (catch 'exit
2925 (let (r b)
2926 (while (string-match org-maybe-keyword-time-regexp s)
2927 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
2928 ;; never export CLOCK
2929 (throw 'exit ""))
2930 (or b (setq b (substring s 0 (match-beginning 0))))
2931 (if (not org-export-with-timestamps)
2932 (setq r (concat r (substring s 0 (match-beginning 0)))
2933 s (substring s (match-end 0)))
2934 (setq r (concat
2935 r (substring s 0 (match-beginning 0))
2936 (if (match-end 1)
2937 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2938 (match-string 1 s)))
2939 (format " @<span class=\"timestamp\">%s@</span>"
2940 (substring
2941 (org-translate-time (match-string 3 s)) 1 -1)))
2942 s (substring s (match-end 0)))))
2943 ;; Line break if line started and ended with time stamp stuff
2944 (if (not r)
2946 (setq r (concat r s))
2947 (unless (string-match "\\S-" (concat b s))
2948 (setq r (concat r "@<br/>")))
2949 r))))
2951 (defun org-html-protect (s)
2952 ;; convert & to &amp;, < to &lt; and > to &gt;
2953 (let ((start 0))
2954 (while (string-match "&" s start)
2955 (setq s (replace-match "&amp;" t t s)
2956 start (1+ (match-beginning 0))))
2957 (while (string-match "<" s)
2958 (setq s (replace-match "&lt;" t t s)))
2959 (while (string-match ">" s)
2960 (setq s (replace-match "&gt;" t t s))))
2963 (defun org-export-cleanup-toc-line (s)
2964 "Remove tags and time staps from lines going into the toc."
2965 (when (memq org-export-with-tags '(not-in-toc nil))
2966 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2967 (setq s (replace-match "" t t s))))
2968 (when org-export-remove-timestamps-from-toc
2969 (while (string-match org-maybe-keyword-time-regexp s)
2970 (setq s (replace-match "" t t s))))
2971 (while (string-match org-bracket-link-regexp s)
2972 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2973 t t s)))
2976 (defun org-html-expand (string)
2977 "Prepare STRING for HTML export. Applies all active conversions.
2978 If there are links in the string, don't modify these."
2979 (let* ((re (concat org-bracket-link-regexp "\\|"
2980 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
2981 m s l res)
2982 (while (setq m (string-match re string))
2983 (setq s (substring string 0 m)
2984 l (match-string 0 string)
2985 string (substring string (match-end 0)))
2986 (push (org-html-do-expand s) res)
2987 (push l res))
2988 (push (org-html-do-expand string) res)
2989 (apply 'concat (nreverse res))))
2991 (defun org-html-do-expand (s)
2992 "Apply all active conversions to translate special ASCII to HTML."
2993 (setq s (org-html-protect s))
2994 (if org-export-html-expand
2995 (let ((start 0))
2996 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
2997 (setq s (replace-match "<\\1>" t nil s)))))
2998 (if org-export-with-emphasize
2999 (setq s (org-export-html-convert-emphasize s)))
3000 (if org-export-with-special-strings
3001 (setq s (org-export-html-convert-special-strings s)))
3002 (if org-export-with-sub-superscripts
3003 (setq s (org-export-html-convert-sub-super s)))
3004 (if org-export-with-TeX-macros
3005 (let ((start 0) wd ass)
3006 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3007 (if (get-text-property (match-beginning 0) 'org-protected s)
3008 (setq start (match-end 0))
3009 (setq wd (match-string 1 s))
3010 (if (setq ass (assoc wd org-html-entities))
3011 (setq s (replace-match (or (cdr ass)
3012 (concat "&" (car ass) ";"))
3013 t t s))
3014 (setq start (+ start (length wd))))))))
3017 (defun org-create-multibrace-regexp (left right n)
3018 "Create a regular expression which will match a balanced sexp.
3019 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3020 as single character strings.
3021 The regexp returned will match the entire expression including the
3022 delimiters. It will also define a single group which contains the
3023 match except for the outermost delimiters. The maximum depth of
3024 stacked delimiters is N. Escaping delimiters is not possible."
3025 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3026 (or "\\|")
3027 (re nothing)
3028 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3029 (while (> n 1)
3030 (setq n (1- n)
3031 re (concat re or next)
3032 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3033 (concat left "\\(" re "\\)" right)))
3035 (defvar org-match-substring-regexp
3036 (concat
3037 "\\([^\\]\\)\\([_^]\\)\\("
3038 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3039 "\\|"
3040 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3041 "\\|"
3042 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3043 "The regular expression matching a sub- or superscript.")
3045 (defvar org-match-substring-with-braces-regexp
3046 (concat
3047 "\\([^\\]\\)\\([_^]\\)\\("
3048 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3049 "\\)")
3050 "The regular expression matching a sub- or superscript, forcing braces.")
3052 (defconst org-export-html-special-string-regexps
3053 '(("\\\\-" . "&shy;")
3054 ("---\\([^-]\\)" . "&mdash;\\1")
3055 ("--\\([^-]\\)" . "&ndash;\\1")
3056 ("\\.\\.\\." . "&hellip;"))
3057 "Regular expressions for special string conversion.")
3059 (defun org-export-html-convert-special-strings (string)
3060 "Convert special characters in STRING to HTML."
3061 (let ((all org-export-html-special-string-regexps)
3062 e a re rpl start)
3063 (while (setq a (pop all))
3064 (setq re (car a) rpl (cdr a) start 0)
3065 (while (string-match re string start)
3066 (if (get-text-property (match-beginning 0) 'org-protected string)
3067 (setq start (match-end 0))
3068 (setq string (replace-match rpl t nil string)))))
3069 string))
3071 (defun org-export-html-convert-sub-super (string)
3072 "Convert sub- and superscripts in STRING to HTML."
3073 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3074 (while (string-match org-match-substring-regexp string s)
3075 (cond
3076 ((and requireb (match-end 8)) (setq s (match-end 2)))
3077 ((get-text-property (match-beginning 2) 'org-protected string)
3078 (setq s (match-end 2)))
3080 (setq s (match-end 1)
3081 key (if (string= (match-string 2 string) "_") "sub" "sup")
3082 c (or (match-string 8 string)
3083 (match-string 6 string)
3084 (match-string 5 string))
3085 string (replace-match
3086 (concat (match-string 1 string)
3087 "<" key ">" c "</" key ">")
3088 t t string)))))
3089 (while (string-match "\\\\\\([_^]\\)" string)
3090 (setq string (replace-match (match-string 1 string) t t string)))
3091 string))
3093 (defun org-export-html-convert-emphasize (string)
3094 "Apply emphasis."
3095 (let ((s 0) rpl)
3096 (while (string-match org-emph-re string s)
3097 (if (not (equal
3098 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3099 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3100 (setq s (match-beginning 0)
3102 (concat
3103 (match-string 1 string)
3104 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3105 (match-string 4 string)
3106 (nth 3 (assoc (match-string 3 string)
3107 org-emphasis-alist))
3108 (match-string 5 string))
3109 string (replace-match rpl t t string)
3110 s (+ s (- (length rpl) 2)))
3111 (setq s (1+ s))))
3112 string))
3114 (defvar org-par-open nil)
3115 (defun org-open-par ()
3116 "Insert <p>, but first close previous paragraph if any."
3117 (org-close-par-maybe)
3118 (insert "\n<p>")
3119 (setq org-par-open t))
3120 (defun org-close-par-maybe ()
3121 "Close paragraph if there is one open."
3122 (when org-par-open
3123 (insert "</p>")
3124 (setq org-par-open nil)))
3125 (defun org-close-li ()
3126 "Close <li> if necessary."
3127 (org-close-par-maybe)
3128 (insert "</li>\n"))
3130 (defvar body-only) ; dynamically scoped into this.
3131 (defun org-html-level-start (level title umax with-toc head-count)
3132 "Insert a new level in HTML export.
3133 When TITLE is nil, just close all open levels."
3134 (org-close-par-maybe)
3135 (let ((l org-level-max) snumber)
3136 (while (>= l level)
3137 (if (aref org-levels-open (1- l))
3138 (progn
3139 (org-html-level-close l umax)
3140 (aset org-levels-open (1- l) nil)))
3141 (setq l (1- l)))
3142 (when title
3143 ;; If title is nil, this means this function is called to close
3144 ;; all levels, so the rest is done only if title is given
3145 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3146 (setq title (replace-match
3147 (if org-export-with-tags
3148 (save-match-data
3149 (concat
3150 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3151 (mapconcat 'identity (org-split-string
3152 (match-string 1 title) ":")
3153 "&nbsp;")
3154 "</span>"))
3156 t t title)))
3157 (if (> level umax)
3158 (progn
3159 (if (aref org-levels-open (1- level))
3160 (progn
3161 (org-close-li)
3162 (insert "<li>" title "<br/>\n"))
3163 (aset org-levels-open (1- level) t)
3164 (org-close-par-maybe)
3165 (insert "<ul>\n<li>" title "<br/>\n")))
3166 (aset org-levels-open (1- level) t)
3167 (setq snumber (org-section-number level))
3168 (if (and org-export-with-section-numbers (not body-only))
3169 (setq title (concat snumber " " title)))
3170 (setq level (+ level org-export-html-toplevel-hlevel -1))
3171 (unless (= head-count 1) (insert "\n</div>\n"))
3172 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s</h%d>\n<div id=\"text-%s\">\n"
3173 snumber level level snumber title level snumber))
3174 (org-open-par)))))
3176 (defun org-html-level-close (level max-outline-level)
3177 "Terminate one level in HTML export."
3178 (if (<= level max-outline-level)
3179 (insert "</div>\n")
3180 (org-close-li)
3181 (insert "</ul>\n")))
3183 ;;; iCalendar export
3185 ;;;###autoload
3186 (defun org-export-icalendar-this-file ()
3187 "Export current file as an iCalendar file.
3188 The iCalendar file will be located in the same directory as the Org-mode
3189 file, but with extension `.ics'."
3190 (interactive)
3191 (org-export-icalendar nil buffer-file-name))
3193 ;;;###autoload
3194 (defun org-export-icalendar-all-agenda-files ()
3195 "Export all files in `org-agenda-files' to iCalendar .ics files.
3196 Each iCalendar file will be located in the same directory as the Org-mode
3197 file, but with extension `.ics'."
3198 (interactive)
3199 (apply 'org-export-icalendar nil (org-agenda-files t)))
3201 ;;;###autoload
3202 (defun org-export-icalendar-combine-agenda-files ()
3203 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3204 The file is stored under the name `org-combined-agenda-icalendar-file'."
3205 (interactive)
3206 (apply 'org-export-icalendar t (org-agenda-files t)))
3208 (defun org-export-icalendar (combine &rest files)
3209 "Create iCalendar files for all elements of FILES.
3210 If COMBINE is non-nil, combine all calendar entries into a single large
3211 file and store it under the name `org-combined-agenda-icalendar-file'."
3212 (save-excursion
3213 (org-prepare-agenda-buffers files)
3214 (let* ((dir (org-export-directory
3215 :ical (list :publishing-directory
3216 org-export-publishing-directory)))
3217 file ical-file ical-buffer category started org-agenda-new-buffers)
3218 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3219 (when combine
3220 (setq ical-file
3221 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3222 org-combined-agenda-icalendar-file
3223 (expand-file-name org-combined-agenda-icalendar-file dir))
3224 ical-buffer (org-get-agenda-file-buffer ical-file))
3225 (set-buffer ical-buffer) (erase-buffer))
3226 (while (setq file (pop files))
3227 (catch 'nextfile
3228 (org-check-agenda-file file)
3229 (set-buffer (org-get-agenda-file-buffer file))
3230 (unless combine
3231 (setq ical-file (concat (file-name-as-directory dir)
3232 (file-name-sans-extension
3233 (file-name-nondirectory buffer-file-name))
3234 ".ics"))
3235 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3236 (with-current-buffer ical-buffer (erase-buffer)))
3237 (setq category (or org-category
3238 (file-name-sans-extension
3239 (file-name-nondirectory buffer-file-name))))
3240 (if (symbolp category) (setq category (symbol-name category)))
3241 (let ((standard-output ical-buffer))
3242 (if combine
3243 (and (not started) (setq started t)
3244 (org-start-icalendar-file org-icalendar-combined-name))
3245 (org-start-icalendar-file category))
3246 (org-print-icalendar-entries combine)
3247 (when (or (and combine (not files)) (not combine))
3248 (org-finish-icalendar-file)
3249 (set-buffer ical-buffer)
3250 (save-buffer)
3251 (run-hooks 'org-after-save-iCalendar-file-hook)))))
3252 (org-release-buffers org-agenda-new-buffers))))
3254 (defvar org-after-save-iCalendar-file-hook nil
3255 "Hook run after an iCalendar file has been saved.
3256 The iCalendar buffer is still current when this hook is run.
3257 A good way to use this is to tell a desktop calenndar application to re-read
3258 the iCalendar file.")
3260 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3261 (defun org-print-icalendar-entries (&optional combine)
3262 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3263 When COMBINE is non nil, add the category to each line."
3264 (require 'org-agenda)
3265 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3266 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3267 (dts (org-ical-ts-to-string
3268 (format-time-string (cdr org-time-stamp-formats) (current-time))
3269 "DTSTART"))
3270 hd ts ts2 state status (inc t) pos b sexp rrule
3271 scheduledp deadlinep tmp pri category entry location summary desc
3272 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3273 (org-refresh-category-properties)
3274 (save-excursion
3275 (goto-char (point-min))
3276 (while (re-search-forward re1 nil t)
3277 (catch :skip
3278 (org-agenda-skip)
3279 (when (boundp 'org-icalendar-verify-function)
3280 (unless (funcall org-icalendar-verify-function)
3281 (outline-next-heading)
3282 (backward-char 1)
3283 (throw :skip nil)))
3284 (setq pos (match-beginning 0)
3285 ts (match-string 0)
3286 inc t
3287 hd (condition-case nil (org-get-heading)
3288 (error (throw :skip nil)))
3289 summary (org-icalendar-cleanup-string
3290 (org-entry-get nil "SUMMARY"))
3291 desc (org-icalendar-cleanup-string
3292 (or (org-entry-get nil "DESCRIPTION")
3293 (and org-icalendar-include-body (org-get-entry)))
3294 t org-icalendar-include-body)
3295 location (org-icalendar-cleanup-string
3296 (org-entry-get nil "LOCATION"))
3297 category (org-get-category))
3298 (if (looking-at re2)
3299 (progn
3300 (goto-char (match-end 0))
3301 (setq ts2 (match-string 1) inc nil))
3302 (setq tmp (buffer-substring (max (point-min)
3303 (- pos org-ds-keyword-length))
3304 pos)
3305 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3306 (progn
3307 (setq inc nil)
3308 (replace-match "\\1" t nil ts))
3310 deadlinep (string-match org-deadline-regexp tmp)
3311 scheduledp (string-match org-scheduled-regexp tmp)
3312 ;; donep (org-entry-is-done-p)
3314 (if (or (string-match org-tr-regexp hd)
3315 (string-match org-ts-regexp hd))
3316 (setq hd (replace-match "" t t hd)))
3317 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3318 (setq rrule
3319 (concat "\nRRULE:FREQ="
3320 (cdr (assoc
3321 (match-string 2 ts)
3322 '(("d" . "DAILY")("w" . "WEEKLY")
3323 ("m" . "MONTHLY")("y" . "YEARLY"))))
3324 ";INTERVAL=" (match-string 1 ts)))
3325 (setq rrule ""))
3326 (setq summary (or summary hd))
3327 (if (string-match org-bracket-link-regexp summary)
3328 (setq summary
3329 (replace-match (if (match-end 3)
3330 (match-string 3 summary)
3331 (match-string 1 summary))
3332 t t summary)))
3333 (if deadlinep (setq summary (concat "DL: " summary)))
3334 (if scheduledp (setq summary (concat "S: " summary)))
3335 (if (string-match "\\`<%%" ts)
3336 (with-current-buffer sexp-buffer
3337 (insert (substring ts 1 -1) " " summary "\n"))
3338 (princ (format "BEGIN:VEVENT
3340 %s%s
3341 SUMMARY:%s%s%s
3342 CATEGORIES:%s
3343 END:VEVENT\n"
3344 (org-ical-ts-to-string ts "DTSTART")
3345 (org-ical-ts-to-string ts2 "DTEND" inc)
3346 rrule summary
3347 (if (and desc (string-match "\\S-" desc))
3348 (concat "\nDESCRIPTION: " desc) "")
3349 (if (and location (string-match "\\S-" location))
3350 (concat "\nLOCATION: " location) "")
3351 category)))))
3353 (when (and org-icalendar-include-sexps
3354 (condition-case nil (require 'icalendar) (error nil))
3355 (fboundp 'icalendar-export-region))
3356 ;; Get all the literal sexps
3357 (goto-char (point-min))
3358 (while (re-search-forward "^&?%%(" nil t)
3359 (catch :skip
3360 (org-agenda-skip)
3361 (setq b (match-beginning 0))
3362 (goto-char (1- (match-end 0)))
3363 (forward-sexp 1)
3364 (end-of-line 1)
3365 (setq sexp (buffer-substring b (point)))
3366 (with-current-buffer sexp-buffer
3367 (insert sexp "\n"))
3368 (princ (org-diary-to-ical-string sexp-buffer)))))
3370 (when org-icalendar-include-todo
3371 (goto-char (point-min))
3372 (while (re-search-forward org-todo-line-regexp nil t)
3373 (catch :skip
3374 (org-agenda-skip)
3375 (when (boundp 'org-icalendar-verify-function)
3376 (unless (funcall org-icalendar-verify-function)
3377 (outline-next-heading)
3378 (backward-char 1)
3379 (throw :skip nil)))
3380 (setq state (match-string 2))
3381 (setq status (if (member state org-done-keywords)
3382 "COMPLETED" "NEEDS-ACTION"))
3383 (when (and state
3384 (or (not (member state org-done-keywords))
3385 (eq org-icalendar-include-todo 'all))
3386 (not (member org-archive-tag (org-get-tags-at)))
3388 (setq hd (match-string 3)
3389 summary (org-icalendar-cleanup-string
3390 (org-entry-get nil "SUMMARY"))
3391 desc (org-icalendar-cleanup-string
3392 (or (org-entry-get nil "DESCRIPTION")
3393 (and org-icalendar-include-body (org-get-entry)))
3394 t org-icalendar-include-body)
3395 location (org-icalendar-cleanup-string
3396 (org-entry-get nil "LOCATION")))
3397 (if (string-match org-bracket-link-regexp hd)
3398 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
3399 (match-string 1 hd))
3400 t t hd)))
3401 (if (string-match org-priority-regexp hd)
3402 (setq pri (string-to-char (match-string 2 hd))
3403 hd (concat (substring hd 0 (match-beginning 1))
3404 (substring hd (match-end 1))))
3405 (setq pri org-default-priority))
3406 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
3407 (- org-lowest-priority org-highest-priority))))))
3409 (princ (format "BEGIN:VTODO
3411 SUMMARY:%s%s%s
3412 CATEGORIES:%s
3413 SEQUENCE:1
3414 PRIORITY:%d
3415 STATUS:%s
3416 END:VTODO\n"
3418 (or summary hd)
3419 (if (and location (string-match "\\S-" location))
3420 (concat "\nLOCATION: " location) "")
3421 (if (and desc (string-match "\\S-" desc))
3422 (concat "\nDESCRIPTION: " desc) "")
3423 category pri status)))))))))
3425 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
3426 "Take out stuff and quote what needs to be quoted.
3427 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3428 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3429 characters."
3430 (if (not s)
3432 (when is-body
3433 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
3434 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
3435 (while (string-match re s) (setq s (replace-match "" t t s)))
3436 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
3437 (let ((start 0))
3438 (while (string-match "\\([,;\\]\\)" s start)
3439 (setq start (+ (match-beginning 0) 2)
3440 s (replace-match "\\\\\\1" nil nil s))))
3441 (when is-body
3442 (while (string-match "[ \t]*\n[ \t]*" s)
3443 (setq s (replace-match "\\n" t t s))))
3444 (setq s (org-trim s))
3445 (if is-body
3446 (if maxlength
3447 (if (and (numberp maxlength)
3448 (> (length s) maxlength))
3449 (setq s (substring s 0 maxlength)))))
3452 (defun org-get-entry ()
3453 "Clean-up description string."
3454 (save-excursion
3455 (org-back-to-heading t)
3456 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
3458 (defun org-start-icalendar-file (name)
3459 "Start an iCalendar file by inserting the header."
3460 (let ((user user-full-name)
3461 (name (or name "unknown"))
3462 (timezone (cadr (current-time-zone))))
3463 (princ
3464 (format "BEGIN:VCALENDAR
3465 VERSION:2.0
3466 X-WR-CALNAME:%s
3467 PRODID:-//%s//Emacs with Org-mode//EN
3468 X-WR-TIMEZONE:%s
3469 CALSCALE:GREGORIAN\n" name user timezone))))
3471 (defun org-finish-icalendar-file ()
3472 "Finish an iCalendar file by inserting the END statement."
3473 (princ "END:VCALENDAR\n"))
3475 (defun org-ical-ts-to-string (s keyword &optional inc)
3476 "Take a time string S and convert it to iCalendar format.
3477 KEYWORD is added in front, to make a complete line like DTSTART....
3478 When INC is non-nil, increase the hour by two (if time string contains
3479 a time), or the day by one (if it does not contain a time)."
3480 (let ((t1 (org-parse-time-string s 'nodefault))
3481 t2 fmt have-time time)
3482 (if (and (car t1) (nth 1 t1) (nth 2 t1))
3483 (setq t2 t1 have-time t)
3484 (setq t2 (org-parse-time-string s)))
3485 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
3486 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
3487 (when inc
3488 (if have-time
3489 (if org-agenda-default-appointment-duration
3490 (setq mi (+ org-agenda-default-appointment-duration mi))
3491 (setq h (+ 2 h)))
3492 (setq d (1+ d))))
3493 (setq time (encode-time s mi h d m y)))
3494 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3495 (concat keyword (format-time-string fmt time))))
3497 ;;; XOXO export
3499 (defun org-export-as-xoxo-insert-into (buffer &rest output)
3500 (with-current-buffer buffer
3501 (apply 'insert output)))
3502 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
3504 ;;;###autoload
3505 (defun org-export-as-xoxo (&optional buffer)
3506 "Export the org buffer as XOXO.
3507 The XOXO buffer is named *xoxo-<source buffer name>*"
3508 (interactive (list (current-buffer)))
3509 ;; A quickie abstraction
3511 ;; Output everything as XOXO
3512 (with-current-buffer (get-buffer buffer)
3513 (let* ((pos (point))
3514 (opt-plist (org-combine-plists (org-default-export-plist)
3515 (org-infile-export-plist)))
3516 (filename (concat (file-name-as-directory
3517 (org-export-directory :xoxo opt-plist))
3518 (file-name-sans-extension
3519 (file-name-nondirectory buffer-file-name))
3520 ".html"))
3521 (out (find-file-noselect filename))
3522 (last-level 1)
3523 (hanging-li nil))
3524 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3525 ;; Check the output buffer is empty.
3526 (with-current-buffer out (erase-buffer))
3527 ;; Kick off the output
3528 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
3529 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
3530 (let* ((hd (match-string-no-properties 1))
3531 (level (length hd))
3532 (text (concat
3533 (match-string-no-properties 2)
3534 (save-excursion
3535 (goto-char (match-end 0))
3536 (let ((str ""))
3537 (catch 'loop
3538 (while 't
3539 (forward-line)
3540 (if (looking-at "^[ \t]\\(.*\\)")
3541 (setq str (concat str (match-string-no-properties 1)))
3542 (throw 'loop str)))))))))
3544 ;; Handle level rendering
3545 (cond
3546 ((> level last-level)
3547 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
3549 ((< level last-level)
3550 (dotimes (- (- last-level level) 1)
3551 (if hanging-li
3552 (org-export-as-xoxo-insert-into out "</li>\n"))
3553 (org-export-as-xoxo-insert-into out "</ol>\n"))
3554 (when hanging-li
3555 (org-export-as-xoxo-insert-into out "</li>\n")
3556 (setq hanging-li nil)))
3558 ((equal level last-level)
3559 (if hanging-li
3560 (org-export-as-xoxo-insert-into out "</li>\n")))
3563 (setq last-level level)
3565 ;; And output the new li
3566 (setq hanging-li 't)
3567 (if (equal ?+ (elt text 0))
3568 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
3569 (org-export-as-xoxo-insert-into out "<li>" text))))
3571 ;; Finally finish off the ol
3572 (dotimes (- last-level 1)
3573 (if hanging-li
3574 (org-export-as-xoxo-insert-into out "</li>\n"))
3575 (org-export-as-xoxo-insert-into out "</ol>\n"))
3577 (goto-char pos)
3578 ;; Finish the buffer off and clean it up.
3579 (switch-to-buffer-other-window out)
3580 (indent-region (point-min) (point-max) nil)
3581 (save-buffer)
3582 (goto-char (point-min))
3585 (provide 'org-exp)
3587 ;;; org-exp.el ends here