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