Release 6.06.
[org-mode.git] / lisp / org-exp.el
blobd80d5524934637fa035ba75270dce19ec3329ac6
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.06
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 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
29 (require 'org-agenda)
30 (eval-and-compile
31 (require 'cl))
33 (declare-function org-export-latex-preprocess "org-export-latex" ())
34 (declare-function org-agenda-skip "org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
36 (declare-function htmlize-region "ext:htmlize" (beg end))
37 (defvar htmlize-buffer-places) ; from htmlize.el
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 ("no" "Forfatter" "Dato" "Innhold")
92 ("nb" "Forfatter" "Dato" "Innhold") ;; nb = Norsk (bokm.l)
93 ("nn" "Forfattar" "Dato" "Innhald") ;; nn = Norsk (nynorsk)
94 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
95 "Terms used in export text, translated to different languages.
96 Use the variable `org-export-default-language' to set the language,
97 or use the +OPTION lines for a per-file setting."
98 :group 'org-export-general
99 :type '(repeat
100 (list
101 (string :tag "HTML language tag")
102 (string :tag "Author")
103 (string :tag "Date")
104 (string :tag "Table of Contents"))))
106 (defcustom org-export-default-language "en"
107 "The default language of HTML export, as a string.
108 This should have an association in `org-export-language-setup'."
109 :group 'org-export-general
110 :type 'string)
112 (defcustom org-export-skip-text-before-1st-heading nil
113 "Non-nil means, skip all text before the first headline when exporting.
114 When nil, that text is exported as well."
115 :group 'org-export-general
116 :type 'boolean)
118 (defcustom org-export-headline-levels 3
119 "The last level which is still exported as a headline.
120 Inferior levels will produce itemize lists when exported.
121 Note that a numeric prefix argument to an exporter function overrides
122 this setting.
124 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
125 :group 'org-export-general
126 :type 'number)
128 (defcustom org-export-with-section-numbers t
129 "Non-nil means, add section numbers to headlines when exporting.
131 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
132 :group 'org-export-general
133 :type 'boolean)
135 (defcustom org-export-section-number-format '((("1" ".")) . "")
136 "Format of section numbers for export.
137 The variable has two components.
138 1. A list of lists, each indicating a counter type and a separator.
139 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
140 It causes causes numeric, alphabetic, or roman counters, respectively.
141 The separator is only used if another counter for a subsection is being
142 added.
143 If there are more numbered section levels than entries in this lists,
144 then the last entry will be reused.
145 2. A terminator string that will be added after the entire
146 section number."
147 :group 'org-export-general
148 :type '(cons
149 (repeat
150 (list
151 (string :tag "Counter Type")
152 (string :tag "Separator ")))
153 (string :tag "Terminator")))
155 (defcustom org-export-with-toc t
156 "Non-nil means, create a table of contents in exported files.
157 The TOC contains headlines with levels up to`org-export-headline-levels'.
158 When an integer, include levels up to N in the toc, this may then be
159 different from `org-export-headline-levels', but it will not be allowed
160 to be larger than the number of headline levels.
161 When nil, no table of contents is made.
163 Headlines which contain any TODO items will be marked with \"(*)\" in
164 ASCII export, and with red color in HTML output, if the option
165 `org-export-mark-todo-in-toc' is set.
167 In HTML output, the TOC will be clickable.
169 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
170 or \"toc:3\"."
171 :group 'org-export-general
172 :type '(choice
173 (const :tag "No Table of Contents" nil)
174 (const :tag "Full Table of Contents" t)
175 (integer :tag "TOC to level")))
177 (defcustom org-export-mark-todo-in-toc nil
178 "Non-nil means, mark TOC lines that contain any open TODO items."
179 :group 'org-export-general
180 :type 'boolean)
182 (defcustom org-export-preserve-breaks nil
183 "Non-nil means, preserve all line breaks when exporting.
184 Normally, in HTML output paragraphs will be reformatted. In ASCII
185 export, line breaks will always be preserved, regardless of this variable.
187 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
188 :group 'org-export-general
189 :type 'boolean)
191 (defcustom org-export-with-archived-trees 'headline
192 "Whether subtrees with the ARCHIVE tag should be exported.
193 This can have three different values
194 nil Do not export, pretend this tree is not present
195 t Do export the entire tree
196 headline Only export the headline, but skip the tree below it."
197 :group 'org-export-general
198 :group 'org-archive
199 :type '(choice
200 (const :tag "not at all" nil)
201 (const :tag "headline only" 'headline)
202 (const :tag "entirely" t)))
204 (defcustom org-export-author-info t
205 "Non-nil means, insert author name and email into the exported file.
207 This option can also be set with the +OPTIONS line,
208 e.g. \"author-info:nil\"."
209 :group 'org-export-general
210 :type 'boolean)
212 (defcustom org-export-creator-info t
213 "Non-nil means, the postamle should contain a creator sentence.
214 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
215 :group 'org-export-general
216 :type 'boolean)
218 (defcustom org-export-time-stamp-file t
219 "Non-nil means, insert a time stamp into the exported file.
220 The time stamp shows when the file was created.
222 This option can also be set with the +OPTIONS line,
223 e.g. \"timestamp:nil\"."
224 :group 'org-export-general
225 :type 'boolean)
227 (defcustom org-export-with-timestamps t
228 "If nil, do not export time stamps and associated keywords."
229 :group 'org-export-general
230 :type 'boolean)
232 (defcustom org-export-remove-timestamps-from-toc t
233 "If nil, remove timestamps from the table of contents entries."
234 :group 'org-export-general
235 :type 'boolean)
237 (defcustom org-export-with-tags 'not-in-toc
238 "If nil, do not export tags, just remove them from headlines.
239 If this is the symbol `not-in-toc', tags will be removed from table of
240 contents entries, but still be shown in the headlines of the document.
242 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
243 :group 'org-export-general
244 :type '(choice
245 (const :tag "Off" nil)
246 (const :tag "Not in TOC" not-in-toc)
247 (const :tag "On" t)))
249 (defcustom org-export-with-drawers nil
250 "Non-nil means, export with drawers like the property drawer.
251 When t, all drawers are exported. This may also be a list of
252 drawer names to export."
253 :group 'org-export-general
254 :type '(choice
255 (const :tag "All drawers" t)
256 (const :tag "None" nil)
257 (repeat :tag "Selected drawers"
258 (string :tag "Drawer name"))))
260 (defvar org-export-preprocess-hook nil
261 "Hook for preprocessing an export buffer.
262 Pretty much the first thing when exporting is running this hook.")
264 (defgroup org-export-translation nil
265 "Options for translating special ascii sequences for the export backends."
266 :tag "Org Export Translation"
267 :group 'org-export)
269 (defcustom org-export-with-emphasize t
270 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
271 If the export target supports emphasizing text, the word will be
272 typeset in bold, italic, or underlined, respectively. Works only for
273 single words, but you can say: I *really* *mean* *this*.
274 Not all export backends support this.
276 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
277 :group 'org-export-translation
278 :type 'boolean)
280 (defcustom org-export-with-footnotes t
281 "If nil, export [1] as a footnote marker.
282 Lines starting with [1] will be formatted as footnotes.
284 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
285 :group 'org-export-translation
286 :type 'boolean)
288 (defcustom org-export-with-sub-superscripts t
289 "Non-nil means, interpret \"_\" and \"^\" for export.
290 When this option is turned on, you can use TeX-like syntax for sub- and
291 superscripts. Several characters after \"_\" or \"^\" will be
292 considered as a single item - so grouping with {} is normally not
293 needed. For example, the following things will be parsed as single
294 sub- or superscripts.
296 10^24 or 10^tau several digits will be considered 1 item.
297 10^-12 or 10^-tau a leading sign with digits or a word
298 x^2-y^3 will be read as x^2 - y^3, because items are
299 terminated by almost any nonword/nondigit char.
300 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
302 Still, ambiguity is possible - so when in doubt use {} to enclose the
303 sub/superscript. If you set this variable to the symbol `{}',
304 the braces are *required* in order to trigger interpretations as
305 sub/superscript. This can be helpful in documents that need \"_\"
306 frequently in plain text.
308 Not all export backends support this, but HTML does.
310 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
311 :group 'org-export-translation
312 :type '(choice
313 (const :tag "Always interpret" t)
314 (const :tag "Only with braces" {})
315 (const :tag "Never interpret" nil)))
317 (defcustom org-export-with-special-strings t
318 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
319 When this option is turned on, these strings will be exported as:
321 \\- : &shy;
322 -- : &ndash;
323 --- : &mdash;
325 Not all export backends support this, but HTML does.
327 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
328 :group 'org-export-translation
329 :type 'boolean)
331 (defcustom org-export-with-TeX-macros t
332 "Non-nil means, interpret simple TeX-like macros when exporting.
333 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
334 No only real TeX macros will work here, but the standard HTML entities
335 for math can be used as macro names as well. For a list of supported
336 names in HTML export, see the constant `org-html-entities'.
337 Not all export backends support this.
339 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
340 :group 'org-export-translation
341 :group 'org-export-latex
342 :type 'boolean)
344 (defcustom org-export-with-LaTeX-fragments nil
345 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
346 When set, the exporter will find LaTeX environments if the \\begin line is
347 the first non-white thing on a line. It will also find the math delimiters
348 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
349 display math.
351 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
352 :group 'org-export-translation
353 :group 'org-export-latex
354 :type 'boolean)
356 (defcustom org-export-with-fixed-width t
357 "Non-nil means, lines starting with \":\" will be in fixed width font.
358 This can be used to have pre-formatted text, fragments of code etc. For
359 example:
360 : ;; Some Lisp examples
361 : (while (defc cnt)
362 : (ding))
363 will be looking just like this in also HTML. See also the QUOTE keyword.
364 Not all export backends support this.
366 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
367 :group 'org-export-translation
368 :type 'boolean)
370 (defcustom org-match-sexp-depth 3
371 "Number of stacked braces for sub/superscript matching.
372 This has to be set before loading org.el to be effective."
373 :group 'org-export-translation
374 :type 'integer)
376 (defgroup org-export-tables nil
377 "Options for exporting tables in Org-mode."
378 :tag "Org Export Tables"
379 :group 'org-export)
381 (defcustom org-export-with-tables t
382 "If non-nil, lines starting with \"|\" define a table.
383 For example:
385 | Name | Address | Birthday |
386 |-------------+----------+-----------|
387 | Arthur Dent | England | 29.2.2100 |
389 Not all export backends support this.
391 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
392 :group 'org-export-tables
393 :type 'boolean)
395 (defcustom org-export-highlight-first-table-line t
396 "Non-nil means, highlight the first table line.
397 In HTML export, this means use <th> instead of <td>.
398 In tables created with table.el, this applies to the first table line.
399 In Org-mode tables, all lines before the first horizontal separator
400 line will be formatted with <th> tags."
401 :group 'org-export-tables
402 :type 'boolean)
404 (defcustom org-export-table-remove-special-lines t
405 "Remove special lines and marking characters in calculating tables.
406 This removes the special marking character column from tables that are set
407 up for spreadsheet calculations. It also removes the entire lines
408 marked with `!', `_', or `^'. The lines with `$' are kept, because
409 the values of constants may be useful to have."
410 :group 'org-export-tables
411 :type 'boolean)
413 (defcustom org-export-prefer-native-exporter-for-tables nil
414 "Non-nil means, always export tables created with table.el natively.
415 Natively means, use the HTML code generator in table.el.
416 When nil, Org-mode's own HTML generator is used when possible (i.e. if
417 the table does not use row- or column-spanning). This has the
418 advantage, that the automatic HTML conversions for math symbols and
419 sub/superscripts can be applied. Org-mode's HTML generator is also
420 much faster."
421 :group 'org-export-tables
422 :type 'boolean)
424 (defgroup org-export-ascii nil
425 "Options specific for ASCII export of Org-mode files."
426 :tag "Org Export ASCII"
427 :group 'org-export)
429 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
430 "Characters for underlining headings in ASCII export.
431 In the given sequence, these characters will be used for level 1, 2, ..."
432 :group 'org-export-ascii
433 :type '(repeat character))
435 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
436 "Bullet characters for headlines converted to lists in ASCII export.
437 The first character is used for the first lest level generated in this
438 way, and so on. If there are more levels than characters given here,
439 the list will be repeated.
440 Note that plain lists will keep the same bullets as the have in the
441 Org-mode file."
442 :group 'org-export-ascii
443 :type '(repeat character))
445 (defgroup org-export-xml nil
446 "Options specific for XML export of Org-mode files."
447 :tag "Org Export XML"
448 :group 'org-export)
450 (defgroup org-export-html nil
451 "Options specific for HTML export of Org-mode files."
452 :tag "Org Export HTML"
453 :group 'org-export)
455 (defcustom org-export-html-coding-system nil
456 "Coding system for HTML export, defaults to buffer-file-coding-system."
457 :group 'org-export-html
458 :type 'coding-system)
460 (defcustom org-export-html-extension "html"
461 "The extension for exported HTML files."
462 :group 'org-export-html
463 :type 'string)
465 (defcustom org-export-html-link-up ""
466 "Where should the \"UP\" link of exported HTML pages lead?"
467 :group 'org-export-html
468 :type '(string :tag "File or URL"))
470 (defcustom org-export-html-link-home ""
471 "Where should the \"HOME\" link of exported HTML pages lead?"
472 :group 'org-export-html
473 :type '(string :tag "File or URL"))
475 (defconst org-export-html-style-default
476 "<style type=\"text/css\">
477 html { font-family: Times, serif; font-size: 12pt; }
478 .title { text-align: center; }
479 .todo { color: red; }
480 .done { color: green; }
481 .tag { background-color:lightblue; font-weight:normal }
482 .target { }
483 .timestamp { color: grey }
484 .timestamp-kwd { color: CadetBlue }
485 p.verse { margin-left: 3% }
486 pre {
487 border: 1pt solid #AEBDCC;
488 background-color: #F3F5F7;
489 padding: 5pt;
490 font-family: courier, monospace;
491 font-size: 90%;
492 overflow:auto;
494 table { border-collapse: collapse; }
495 td, th { vertical-align: top; }
496 dt { font-weight: bold; }
497 </style>"
498 "The default style specification for exported HTML files.
499 Please use the variables `org-export-html-style' and
500 `org-export-html-style-extra' to add to this style.")
502 (defcustom org-export-html-style ""
503 "Org-wide style definitions for exported HTML files.
505 This variable needs to contain the full HTML structure to provide a style,
506 including the surrounding HTML tags. If you set the value of this variable,
507 you should consider to include definitions for the following classes:
508 title, todo, done, timestamp, timestamp-kwd, tag, target.
510 For example, a valid value would be:
512 <style type=\"text/css\">
513 p { font-weight: normal; color: gray; }
514 h1 { color: black; }
515 .title { text-align: center; }
516 .todo, .timestamp-kwd { color: red; }
517 .done { color: green; }
518 </style>
520 If you'd like to refer to en external style file, use something like
522 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
524 As the value of this option simply gets inserted into the HTML <head> header,
525 you can \"misuse\" it to add arbitrary text to the header.
526 See also the variable `org-export-html-style-extra'."
527 :group 'org-export-html
528 :type 'string)
530 (defcustom org-export-html-style-extra ""
531 "Additional style information for HTML export.
532 The value of this variable is inserted into the HTML buffer right after
533 the value of `org-export-html-style'. Use this variable for per-file
534 settings of style information, and do not forget to surround the style
535 settings with <style>...</style> tags."
536 :group 'org-export-html
537 :type 'string)
539 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
540 "Format for typesetting the document title in HTML export."
541 :group 'org-export-html
542 :type 'string)
544 (defcustom org-export-html-toplevel-hlevel 2
545 "The <H> level for level 1 headings in HTML export."
546 :group 'org-export-html
547 :type 'string)
549 (defcustom org-export-html-link-org-files-as-html t
550 "Non-nil means, make file links to `file.org' point to `file.html'.
551 When org-mode is exporting an org-mode file to HTML, links to
552 non-html files are directly put into a href tag in HTML.
553 However, links to other Org-mode files (recognized by the
554 extension `.org.) should become links to the corresponding html
555 file, assuming that the linked org-mode file will also be
556 converted to HTML.
557 When nil, the links still point to the plain `.org' file."
558 :group 'org-export-html
559 :type 'boolean)
561 (defcustom org-export-html-inline-images 'maybe
562 "Non-nil means, inline images into exported HTML pages.
563 This is done using an <img> tag. When nil, an anchor with href is used to
564 link to the image. If this option is `maybe', then images in links with
565 an empty description will be inlined, while images with a description will
566 be linked only."
567 :group 'org-export-html
568 :type '(choice (const :tag "Never" nil)
569 (const :tag "Always" t)
570 (const :tag "When there is no description" maybe)))
572 ;; FIXME: rename
573 (defcustom org-export-html-expand t
574 "Non-nil means, for HTML export, treat @<...> as HTML tag.
575 When nil, these tags will be exported as plain text and therefore
576 not be interpreted by a browser.
578 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
579 :group 'org-export-html
580 :type 'boolean)
582 (defcustom org-export-html-table-tag
583 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
584 "The HTML tag that is used to start a table.
585 This must be a <table> tag, but you may change the options like
586 borders and spacing."
587 :group 'org-export-html
588 :type 'string)
590 (defcustom org-export-table-header-tags '("<th>" . "</th>")
591 "The opening tag for table header fields.
592 This is customizable so that alignment options can be specified."
593 :group 'org-export-tables
594 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
596 (defcustom org-export-table-data-tags '("<td>" . "</td>")
597 "The opening tag for table data fields.
598 This is customizable so that alignment options can be specified."
599 :group 'org-export-tables
600 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
602 (defcustom org-export-html-with-timestamp nil
603 "If non-nil, write `org-export-html-html-helper-timestamp'
604 into the exported HTML text. Otherwise, the buffer will just be saved
605 to a file."
606 :group 'org-export-html
607 :type 'boolean)
609 (defcustom org-export-html-html-helper-timestamp
610 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
611 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
612 :group 'org-export-html
613 :type 'string)
615 (defgroup org-export-htmlize nil
616 "Options for processing examples with htmlize.el."
617 :tag "Org Export Htmlize"
618 :group 'org-export-html)
620 (defcustom org-export-htmlize-output-type 'inline-css
621 "Output type to be used by htmlize when formatting code snippets.
622 Normally this is `inline-css', but if you have defined to appropriate
623 classes in your css style file, setting this to `css' means that the
624 fontification will use the class names.
625 See also the function `org-export-htmlize-generate-css'."
626 :group 'org-export-htmlize
627 :type '(choice (const css) (const inline-css)))
629 (defcustom org-export-htmlize-css-font-prefix "org-"
630 "The prefix for CSS class names for htmlize font specifications."
631 :group 'org-export-htmlize
632 :type 'string)
634 (defgroup org-export-icalendar nil
635 "Options specific for iCalendar export of Org-mode files."
636 :tag "Org Export iCalendar"
637 :group 'org-export)
639 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
640 "The file name for the iCalendar file covering all agenda files.
641 This file is created with the command \\[org-export-icalendar-all-agenda-files].
642 The file name should be absolute, the file will be overwritten without warning."
643 :group 'org-export-icalendar
644 :type 'file)
646 (defcustom org-icalendar-combined-name "OrgMode"
647 "Calendar name for the combined iCalendar representing all agenda files."
648 :group 'org-export-icalendar
649 :type 'string)
651 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
652 "Contexts where iCalendar export should use a deadline time stamp.
653 This is a list with several symbols in it. Valid symbol are:
655 event-if-todo Deadlines in TODO entries become calendar events.
656 event-if-not-todo Deadlines in non-TODO entries become calendar events.
657 todo-due Use deadlines in TODO entries as due-dates"
658 :group 'org-export-icalendar
659 :type '(set :greedy t
660 (const :tag "Deadlines in non-TODO entries become events"
661 event-if-not-todo)
662 (const :tag "Deadline in TODO entries become events"
663 event-if-todo)
664 (const :tag "Deadlines in TODO entries become due-dates"
665 todo-due)))
667 (defcustom org-icalendar-use-scheduled '(todo-start)
668 "Contexts where iCalendar export should use a scheduling time stamp.
669 This is a list with several symbols in it. Valid symbol are:
671 event-if-todo Scheduling time stamps in TODO entries become an event.
672 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
673 todo-start Scheduling time stamps in TODO entries become start date.
674 Some calendar applications show TODO entries only after
675 that date."
676 :group 'org-export-icalendar
677 :type '(set :greedy t
678 (const :tag
679 "SCHEDULED timestamps in non-TODO entries become events"
680 event-if-not-todo)
681 (const :tag "SCHEDULED timestamps in TODO entries become events"
682 event-if-todo)
683 (const :tag "SCHEDULED in TODO entries become start date"
684 todo-start)))
686 (defcustom org-icalendar-include-todo nil
687 "Non-nil means, export to iCalendar files should also cover TODO items."
688 :group 'org-export-icalendar
689 :type '(choice
690 (const :tag "None" nil)
691 (const :tag "Unfinished" t)
692 (const :tag "All" all)))
694 (defcustom org-icalendar-include-sexps t
695 "Non-nil means, export to iCalendar files should also cover sexp entries.
696 These are entries like in the diary, but directly in an Org-mode file."
697 :group 'org-export-icalendar
698 :type 'boolean)
700 (defcustom org-icalendar-include-body 100
701 "Amount of text below headline to be included in iCalendar export.
702 This is a number of characters that should maximally be included.
703 Properties, scheduling and clocking lines will always be removed.
704 The text will be inserted into the DESCRIPTION field."
705 :group 'org-export-icalendar
706 :type '(choice
707 (const :tag "Nothing" nil)
708 (const :tag "Everything" t)
709 (integer :tag "Max characters")))
711 (defcustom org-icalendar-store-UID nil
712 "Non-nil means, store any created UIDs in properties.
713 The iCalendar standard requires that all entries have a unique identifyer.
714 Org will create these identifiers as needed. When this variable is non-nil,
715 the created UIDs will be stored in the ID property of the entry. Then the
716 next time this entry is exported, it will be exported with the same UID,
717 superceeding the previous form of it. This is essential for
718 synchronization services.
719 This variable is not turned on by default because we want to avoid creating
720 a property drawer in every entry if people are only playing with this feature,
721 or if they are only using it locally."
722 :group 'org-export-icalendar
723 :type 'boolean)
725 ;;;; Exporting
727 ;;; Variables, constants, and parameter plists
729 (defconst org-level-max 20)
731 (defvar org-export-html-preamble nil
732 "Preamble, to be inserted just after <body>. Set by publishing functions.")
733 (defvar org-export-html-postamble nil
734 "Preamble, to be inserted just before </body>. Set by publishing functions.")
735 (defvar org-export-html-auto-preamble t
736 "Should default preamble be inserted? Set by publishing functions.")
737 (defvar org-export-html-auto-postamble t
738 "Should default postamble be inserted? Set by publishing functions.")
739 (defvar org-current-export-file nil) ; dynamically scoped parameter
740 (defvar org-current-export-dir nil) ; dynamically scoped parameter
742 (defconst org-export-plist-vars
743 '((:link-up . org-export-html-link-up)
744 (:link-home . org-export-html-link-home)
745 (:language . org-export-default-language)
746 (:customtime . org-display-custom-times)
747 (:headline-levels . org-export-headline-levels)
748 (:section-numbers . org-export-with-section-numbers)
749 (:section-number-format . org-export-section-number-format)
750 (:table-of-contents . org-export-with-toc)
751 (:preserve-breaks . org-export-preserve-breaks)
752 (:archived-trees . org-export-with-archived-trees)
753 (:emphasize . org-export-with-emphasize)
754 (:sub-superscript . org-export-with-sub-superscripts)
755 (:special-strings . org-export-with-special-strings)
756 (:footnotes . org-export-with-footnotes)
757 (:drawers . org-export-with-drawers)
758 (:tags . org-export-with-tags)
759 (:TeX-macros . org-export-with-TeX-macros)
760 (:LaTeX-fragments . org-export-with-LaTeX-fragments)
761 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
762 (:fixed-width . org-export-with-fixed-width)
763 (:timestamps . org-export-with-timestamps)
764 (:author-info . org-export-author-info)
765 (:creator-info . org-export-creator-info)
766 (:time-stamp-file . org-export-time-stamp-file)
767 (:tables . org-export-with-tables)
768 (:table-auto-headline . org-export-highlight-first-table-line)
769 (:style . org-export-html-style)
770 (:style-extra . org-export-html-style-extra)
771 (:agenda-style . org-agenda-export-html-style)
772 (:convert-org-links . org-export-html-link-org-files-as-html)
773 (:inline-images . org-export-html-inline-images)
774 (:html-extension . org-export-html-extension)
775 (:html-table-tag . org-export-html-table-tag)
776 (:expand-quoted-html . org-export-html-expand)
777 (:timestamp . org-export-html-with-timestamp)
778 (:publishing-directory . org-export-publishing-directory)
779 (:preamble . org-export-html-preamble)
780 (:postamble . org-export-html-postamble)
781 (:auto-preamble . org-export-html-auto-preamble)
782 (:auto-postamble . org-export-html-auto-postamble)
783 (:author . user-full-name)
784 (:email . user-mail-address)))
786 (defun org-default-export-plist ()
787 "Return the property list with default settings for the export variables."
788 (let ((l org-export-plist-vars) rtn e)
789 (while (setq e (pop l))
790 (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
791 rtn))
793 (defvar org-export-inbuffer-options-extra nil
794 "List of additional in-buffer options that should be detected.
795 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
796 etc. Extensions can add to this list to get their options detected, and they
797 can then add a function to `org-export-options-filters' to process these
798 options.
799 Each element in this list must be a list, with the in-buffer keyword as car,
800 and a property (a symbol) as the next element. All occurences of the
801 keyword will be found, the values concatenated with a space character
802 in between, and the result stored in the export options property list.")
804 (defvar org-export-options-filters nil
805 "Functions to be called to finalize the export/publishing options.
806 All these options are stored in a property list, and each of the functions
807 in this hook gets a chance to modify this property list. Each function
808 must accept the property list as an argument, and must return the (possibly
809 modified) list.")
811 (defun org-infile-export-plist ()
812 "Return the property list with file-local settings for export."
813 (save-excursion
814 (save-restriction
815 (widen)
816 (goto-char (point-min))
817 (let ((re (org-make-options-regexp
818 (append
819 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
820 "LINK_UP" "LINK_HOME" "SETUPFILE")
821 (mapcar 'car org-export-inbuffer-options-extra))))
822 p key val text options js-up js-main js-css js-opt a pr
823 ext-setup-or-nil setup-contents (start 0))
824 (while (or (and ext-setup-or-nil
825 (string-match re ext-setup-or-nil start)
826 (setq start (match-end 0)))
827 (and (setq ext-setup-or-nil nil start 0)
828 (re-search-forward re nil t)))
829 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
830 val (org-match-string-no-properties 2 ext-setup-or-nil))
831 (cond
832 ((setq a (assoc key org-export-inbuffer-options-extra))
833 (setq pr (nth 1 a))
834 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
835 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
836 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
837 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
838 ((string-equal key "DATE") (setq p (plist-put p :date val)))
839 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
840 ((string-equal key "TEXT")
841 (setq text (if text (concat text "\n" val) val)))
842 ((string-equal key "OPTIONS")
843 (setq options (concat val " " options)))
844 ((string-equal key "LINK_UP")
845 (setq p (plist-put p :link-up val)))
846 ((string-equal key "LINK_HOME")
847 (setq p (plist-put p :link-home val)))
848 ((equal key "SETUPFILE")
849 (setq setup-contents (org-file-contents
850 (expand-file-name
851 (org-remove-double-quotes
852 (org-trim val)))
853 'noerror))
854 (if (not ext-setup-or-nil)
855 (setq ext-setup-or-nil setup-contents start 0)
856 (setq ext-setup-or-nil
857 (concat (substring ext-setup-or-nil 0 start)
858 "\n" setup-contents "\n"
859 (substring ext-setup-or-nil start)))))))
860 (setq p (plist-put p :text text))
861 (when options
862 (setq p (org-export-add-options-to-plist p options)))
863 p))))
865 (defun org-export-add-options-to-plist (p options)
866 "Parse an OPTONS line and set values in the property list P."
867 (let (o)
868 (when options
869 (let ((op '(("H" . :headline-levels)
870 ("num" . :section-numbers)
871 ("toc" . :table-of-contents)
872 ("\\n" . :preserve-breaks)
873 ("@" . :expand-quoted-html)
874 (":" . :fixed-width)
875 ("|" . :tables)
876 ("^" . :sub-superscript)
877 ("-" . :special-strings)
878 ("f" . :footnotes)
879 ("d" . :drawers)
880 ("tags" . :tags)
881 ("*" . :emphasize)
882 ("TeX" . :TeX-macros)
883 ("LaTeX" . :LaTeX-fragments)
884 ("skip" . :skip-before-1st-heading)
885 ("author" . :author-info)
886 ("timestamp" . :time-stamp-file)))
888 (while (setq o (pop op))
889 (if (string-match (concat (regexp-quote (car o))
890 ":\\([^ \t\n\r;,.]*\\)")
891 options)
892 (setq p (plist-put p (cdr o)
893 (car (read-from-string
894 (match-string 1 options))))))))))
897 (defun org-export-add-subtree-options (p pos)
898 "Add options in subtree at position POS to property list P."
899 (save-excursion
900 (goto-char pos)
901 (when (org-at-heading-p)
902 (let (a)
903 ;; This is actually read in `org-export-get-title-from-subtree'
904 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
905 ;; (setq p (plist-put p :title a)))
906 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
907 (setq p (plist-put p :text a)))
908 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
909 (setq p (org-export-add-options-to-plist p a)))))
912 (defun org-export-directory (type plist)
913 (let* ((val (plist-get plist :publishing-directory))
914 (dir (if (listp val)
915 (or (cdr (assoc type val)) ".")
916 val)))
917 dir))
919 (defun org-export-process-option-filters (plist)
920 (let ((functions org-export-options-filters) f)
921 (while (setq f (pop functions))
922 (setq plist (funcall f plist))))
923 plist)
925 ;;;###autoload
926 (defun org-export (&optional arg)
927 "Export dispatcher for Org-mode.
928 When `org-export-run-in-background' is non-nil, try to run the command
929 in the background. This will be done only for commands that write
930 to a file. For details see the docstring of `org-export-run-in-background'.
932 The prefix argument ARG will be passed to the exporter. However, if
933 ARG is a double universal prefix `C-u C-u', that means to inverse the
934 value of `org-export-run-in-background'."
935 (interactive "P")
936 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
937 (help "[t] insert the export option template
938 \[v] limit export to visible part of outline tree
940 \[a] export as ASCII
942 \[h] export as HTML
943 \[H] export as HTML to temporary buffer
944 \[R] export region as HTML
945 \[b] export as HTML and browse immediately
946 \[x] export as XOXO
948 \[l] export as LaTeX
949 \[L] export as LaTeX to temporary buffer
951 \[i] export current file as iCalendar file
952 \[I] export all agenda files as iCalendar files
953 \[c] export agenda files into combined iCalendar file
955 \[F] publish current file
956 \[P] publish current project
957 \[X] publish... (project will be prompted for)
958 \[A] publish all projects")
959 (cmds
960 '((?t org-insert-export-options-template nil)
961 (?v org-export-visible nil)
962 (?a org-export-as-ascii t)
963 (?h org-export-as-html t)
964 (?b org-export-as-html-and-open t)
965 (?H org-export-as-html-to-buffer nil)
966 (?R org-export-region-as-html nil)
967 (?x org-export-as-xoxo t)
968 (?l org-export-as-latex t)
969 (?L org-export-as-latex-to-buffer nil)
970 (?i org-export-icalendar-this-file t)
971 (?I org-export-icalendar-all-agenda-files t)
972 (?c org-export-icalendar-combine-agenda-files t)
973 (?F org-publish-current-file t)
974 (?P org-publish-current-project t)
975 (?X org-publish t)
976 (?A org-publish-all t)))
977 r1 r2 ass)
978 (save-window-excursion
979 (delete-other-windows)
980 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
981 (princ help))
982 (message "Select command: ")
983 (setq r1 (read-char-exclusive)))
984 (setq r2 (if (< r1 27) (+ r1 96) r1))
985 (unless (setq ass (assq r2 cmds))
986 (error "No command associated with key %c" r1))
987 (if (and bg (nth 2 ass))
988 ;; execute in background
989 (let ((p (start-process
990 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
991 "*Org Processes*"
992 (expand-file-name invocation-name invocation-directory)
993 "-batch"
994 "-l" user-init-file
995 "--eval" "(require 'org-exp)"
996 "--eval" "(setq org-wait .2)"
997 (buffer-file-name)
998 "-f" (symbol-name (nth 1 ass)))))
999 (set-process-sentinel p 'org-export-process-sentinel)
1000 (message "Background process \"%s\": started" p))
1001 ;; background processing not requested, or not possible
1002 (call-interactively (nth 1 ass)))))
1004 (defun org-export-process-sentinel (process status)
1005 (if (string-match "\n+\\'" status)
1006 (setq status (substring status 0 -1)))
1007 (message "Background process \"%s\": %s" process status))
1009 (defconst org-html-entities
1010 '(("nbsp")
1011 ("iexcl")
1012 ("cent")
1013 ("pound")
1014 ("curren")
1015 ("yen")
1016 ("brvbar")
1017 ("vert" . "&#124;")
1018 ("sect")
1019 ("uml")
1020 ("copy")
1021 ("ordf")
1022 ("laquo")
1023 ("not")
1024 ("shy")
1025 ("reg")
1026 ("macr")
1027 ("deg")
1028 ("plusmn")
1029 ("sup2")
1030 ("sup3")
1031 ("acute")
1032 ("micro")
1033 ("para")
1034 ("middot")
1035 ("odot"."o")
1036 ("star"."*")
1037 ("cedil")
1038 ("sup1")
1039 ("ordm")
1040 ("raquo")
1041 ("frac14")
1042 ("frac12")
1043 ("frac34")
1044 ("iquest")
1045 ("Agrave")
1046 ("Aacute")
1047 ("Acirc")
1048 ("Atilde")
1049 ("Auml")
1050 ("Aring") ("AA"."&Aring;")
1051 ("AElig")
1052 ("Ccedil")
1053 ("Egrave")
1054 ("Eacute")
1055 ("Ecirc")
1056 ("Euml")
1057 ("Igrave")
1058 ("Iacute")
1059 ("Icirc")
1060 ("Iuml")
1061 ("ETH")
1062 ("Ntilde")
1063 ("Ograve")
1064 ("Oacute")
1065 ("Ocirc")
1066 ("Otilde")
1067 ("Ouml")
1068 ("times")
1069 ("Oslash")
1070 ("Ugrave")
1071 ("Uacute")
1072 ("Ucirc")
1073 ("Uuml")
1074 ("Yacute")
1075 ("THORN")
1076 ("szlig")
1077 ("agrave")
1078 ("aacute")
1079 ("acirc")
1080 ("atilde")
1081 ("auml")
1082 ("aring")
1083 ("aelig")
1084 ("ccedil")
1085 ("egrave")
1086 ("eacute")
1087 ("ecirc")
1088 ("euml")
1089 ("igrave")
1090 ("iacute")
1091 ("icirc")
1092 ("iuml")
1093 ("eth")
1094 ("ntilde")
1095 ("ograve")
1096 ("oacute")
1097 ("ocirc")
1098 ("otilde")
1099 ("ouml")
1100 ("divide")
1101 ("oslash")
1102 ("ugrave")
1103 ("uacute")
1104 ("ucirc")
1105 ("uuml")
1106 ("yacute")
1107 ("thorn")
1108 ("yuml")
1109 ("fnof")
1110 ("Alpha")
1111 ("Beta")
1112 ("Gamma")
1113 ("Delta")
1114 ("Epsilon")
1115 ("Zeta")
1116 ("Eta")
1117 ("Theta")
1118 ("Iota")
1119 ("Kappa")
1120 ("Lambda")
1121 ("Mu")
1122 ("Nu")
1123 ("Xi")
1124 ("Omicron")
1125 ("Pi")
1126 ("Rho")
1127 ("Sigma")
1128 ("Tau")
1129 ("Upsilon")
1130 ("Phi")
1131 ("Chi")
1132 ("Psi")
1133 ("Omega")
1134 ("alpha")
1135 ("beta")
1136 ("gamma")
1137 ("delta")
1138 ("epsilon")
1139 ("varepsilon"."&epsilon;")
1140 ("zeta")
1141 ("eta")
1142 ("theta")
1143 ("iota")
1144 ("kappa")
1145 ("lambda")
1146 ("mu")
1147 ("nu")
1148 ("xi")
1149 ("omicron")
1150 ("pi")
1151 ("rho")
1152 ("sigmaf") ("varsigma"."&sigmaf;")
1153 ("sigma")
1154 ("tau")
1155 ("upsilon")
1156 ("phi")
1157 ("chi")
1158 ("psi")
1159 ("omega")
1160 ("thetasym") ("vartheta"."&thetasym;")
1161 ("upsih")
1162 ("piv")
1163 ("bull") ("bullet"."&bull;")
1164 ("hellip") ("dots"."&hellip;")
1165 ("prime")
1166 ("Prime")
1167 ("oline")
1168 ("frasl")
1169 ("weierp")
1170 ("image")
1171 ("real")
1172 ("trade")
1173 ("alefsym")
1174 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1175 ("uarr") ("uparrow"."&uarr;")
1176 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1177 ("darr")("downarrow"."&darr;")
1178 ("harr") ("leftrightarrow"."&harr;")
1179 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1180 ("lArr") ("Leftarrow"."&lArr;")
1181 ("uArr") ("Uparrow"."&uArr;")
1182 ("rArr") ("Rightarrow"."&rArr;")
1183 ("dArr") ("Downarrow"."&dArr;")
1184 ("hArr") ("Leftrightarrow"."&hArr;")
1185 ("forall")
1186 ("part") ("partial"."&part;")
1187 ("exist") ("exists"."&exist;")
1188 ("empty") ("emptyset"."&empty;")
1189 ("nabla")
1190 ("isin") ("in"."&isin;")
1191 ("notin")
1192 ("ni")
1193 ("prod")
1194 ("sum")
1195 ("minus")
1196 ("lowast") ("ast"."&lowast;")
1197 ("radic")
1198 ("prop") ("proptp"."&prop;")
1199 ("infin") ("infty"."&infin;")
1200 ("ang") ("angle"."&ang;")
1201 ("and") ("wedge"."&and;")
1202 ("or") ("vee"."&or;")
1203 ("cap")
1204 ("cup")
1205 ("int")
1206 ("there4")
1207 ("sim")
1208 ("cong") ("simeq"."&cong;")
1209 ("asymp")("approx"."&asymp;")
1210 ("ne") ("neq"."&ne;")
1211 ("equiv")
1212 ("le")
1213 ("ge")
1214 ("sub") ("subset"."&sub;")
1215 ("sup") ("supset"."&sup;")
1216 ("nsub")
1217 ("sube")
1218 ("supe")
1219 ("oplus")
1220 ("otimes")
1221 ("perp")
1222 ("sdot") ("cdot"."&sdot;")
1223 ("lceil")
1224 ("rceil")
1225 ("lfloor")
1226 ("rfloor")
1227 ("lang")
1228 ("rang")
1229 ("loz") ("Diamond"."&loz;")
1230 ("spades") ("spadesuit"."&spades;")
1231 ("clubs") ("clubsuit"."&clubs;")
1232 ("hearts") ("diamondsuit"."&hearts;")
1233 ("diams") ("diamondsuit"."&diams;")
1234 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1235 ("quot")
1236 ("amp")
1237 ("lt")
1238 ("gt")
1239 ("OElig")
1240 ("oelig")
1241 ("Scaron")
1242 ("scaron")
1243 ("Yuml")
1244 ("circ")
1245 ("tilde")
1246 ("ensp")
1247 ("emsp")
1248 ("thinsp")
1249 ("zwnj")
1250 ("zwj")
1251 ("lrm")
1252 ("rlm")
1253 ("ndash")
1254 ("mdash")
1255 ("lsquo")
1256 ("rsquo")
1257 ("sbquo")
1258 ("ldquo")
1259 ("rdquo")
1260 ("bdquo")
1261 ("dagger")
1262 ("Dagger")
1263 ("permil")
1264 ("lsaquo")
1265 ("rsaquo")
1266 ("euro")
1268 ("arccos"."arccos")
1269 ("arcsin"."arcsin")
1270 ("arctan"."arctan")
1271 ("arg"."arg")
1272 ("cos"."cos")
1273 ("cosh"."cosh")
1274 ("cot"."cot")
1275 ("coth"."coth")
1276 ("csc"."csc")
1277 ("deg"."deg")
1278 ("det"."det")
1279 ("dim"."dim")
1280 ("exp"."exp")
1281 ("gcd"."gcd")
1282 ("hom"."hom")
1283 ("inf"."inf")
1284 ("ker"."ker")
1285 ("lg"."lg")
1286 ("lim"."lim")
1287 ("liminf"."liminf")
1288 ("limsup"."limsup")
1289 ("ln"."ln")
1290 ("log"."log")
1291 ("max"."max")
1292 ("min"."min")
1293 ("Pr"."Pr")
1294 ("sec"."sec")
1295 ("sin"."sin")
1296 ("sinh"."sinh")
1297 ("sup"."sup")
1298 ("tan"."tan")
1299 ("tanh"."tanh")
1301 "Entities for TeX->HTML translation.
1302 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1303 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1304 In that case, \"\\ent\" will be translated to \"&other;\".
1305 The list contains HTML entities for Latin-1, Greek and other symbols.
1306 It is supplemented by a number of commonly used TeX macros with appropriate
1307 translations. There is currently no way for users to extend this.")
1309 ;;; General functions for all backends
1311 (defun org-export-preprocess-string (string &rest parameters)
1312 "Cleanup STRING so that that the true exported has a more consistent source.
1313 This function takes STRING, which should be a buffer-string of an org-file
1314 to export. It then creates a temporary buffer where it does its job.
1315 The result is then again returned as a string, and the exporter works
1316 on this string to produce the exported version."
1317 (interactive)
1318 (let* ((htmlp (plist-get parameters :for-html))
1319 (asciip (plist-get parameters :for-ascii))
1320 (latexp (plist-get parameters :for-LaTeX))
1321 (archived-trees (plist-get parameters :archived-trees))
1322 (inhibit-read-only t)
1323 (drawers org-drawers)
1324 (outline-regexp "\\*+ ")
1325 target-alist rtn)
1327 (with-current-buffer (get-buffer-create " org-mode-tmp")
1328 (erase-buffer)
1329 (insert string)
1330 (setq case-fold-search t)
1331 ;; Call the hook
1332 (run-hooks 'org-export-preprocess-hook)
1334 ;; Remove license-to-kill stuff
1335 ;; The caller markes some stuff fo killing, stuff that has been
1336 ;; used to create the page title, for example.
1337 (org-export-kill-licensed-text)
1339 (let ((org-inhibit-startup t)) (org-mode))
1340 (setq case-fold-search t)
1341 (untabify (point-min) (point-max))
1343 ;; Handle incude files
1344 (org-export-handle-include-files)
1346 ;; Handle source code snippets
1347 (org-export-replace-src-segments)
1349 ;; Get rid of drawers
1350 (org-export-remove-or-extract-drawers drawers
1351 (plist-get parameters :drawers))
1353 ;; Get the correct stuff before the first headline
1354 (when (plist-get parameters :skip-before-1st-heading)
1355 (goto-char (point-min))
1356 (when (re-search-forward "^\\*+[ \t]" nil t)
1357 (delete-region (point-min) (match-beginning 0))
1358 (goto-char (point-min))
1359 (insert "\n")))
1360 (when (plist-get parameters :add-text)
1361 (goto-char (point-min))
1362 (insert (plist-get parameters :add-text) "\n"))
1364 ;; Get rid of archived trees
1365 (org-export-remove-archived-trees archived-trees)
1367 ;; Find all headings and compute the targets for them
1368 (setq target-alist (org-export-define-heading-targets target-alist))
1370 ;; Find targets in comments and move them out of comments,
1371 ;; but mark them as targets that should be invisible
1372 (setq target-alist (org-export-handle-invisible-targets target-alist))
1374 ;; Protect examples
1375 (org-export-protect-examples)
1377 ;; Protect backend specific stuff, throw away the others.
1378 (org-export-select-backend-specific-text
1379 (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1381 ;; Protect quoted subtrees
1382 (org-export-protect-quoted-subtrees)
1384 ;; Protect verbatim elements
1385 (org-export-protect-verbatim)
1387 ;; Blockquotes and verse
1388 (org-export-mark-blockquote-and-verse)
1390 ;; Remove comment environment and comment subtrees
1391 (org-export-remove-comment-blocks-and-subtrees)
1393 ;; Remove special table lines
1394 (when org-export-table-remove-special-lines
1395 (org-export-remove-special-table-lines))
1397 ;; Specific LaTeX stuff
1398 (when latexp
1399 (require 'org-export-latex nil)
1400 (org-export-latex-preprocess))
1402 ;; Specific ASCII stuff
1403 (when asciip
1404 (org-export-ascii-preprocess))
1406 ;; Specific HTML stuff
1407 (when htmlp
1408 (org-export-html-preprocess parameters))
1410 ;; Remove or replace comments
1411 (org-export-handle-comments (plist-get parameters :comments))
1413 ;; Find matches for radio targets and turn them into internal links
1414 (org-export-mark-radio-links)
1416 ;; Find all links that contain a newline and put them into a single line
1417 (org-export-concatenate-multiline-links)
1419 ;; Normalize links: Convert angle and plain links into bracket links
1420 ;; and expand link abbreviations
1421 (org-export-normalize-links)
1423 ;; Find all internal links. If they have a fuzzy match (i.e. not
1424 ;; a *dedicated* target match, let the link point to the
1425 ;; corresponding section.
1426 (org-export-target-internal-links target-alist)
1428 ;; Find multiline emphasis and put them into single line
1429 (when (plist-get parameters :emph-multiline)
1430 (org-export-concatenate-multiline-emphasis))
1432 (setq rtn (buffer-string)))
1433 (kill-buffer " org-mode-tmp")
1434 rtn))
1436 (defun org-export-kill-licensed-text ()
1437 "Remove all text that is marked with a :org-license-to-kill property."
1438 (let (p q)
1439 (while (setq p (text-property-any (point-min) (point-max)
1440 :org-license-to-kill t))
1441 (delete-region
1442 p (or (next-single-property-change p :org-license-to-kill)
1443 (point-max))))))
1445 (defun org-export-define-heading-targets (target-alist)
1446 "Find all headings and define the targets for them.
1447 The new targets are added to TARGET-ALIST, which is also returned."
1448 (goto-char (point-min))
1449 (org-init-section-numbers)
1450 (let ((re (concat "^" org-outline-regexp))
1451 level target)
1452 (while (re-search-forward re nil t)
1453 (setq level (org-reduced-level
1454 (save-excursion (goto-char (point-at-bol))
1455 (org-outline-level))))
1456 (setq target (org-solidify-link-text
1457 (format "sec-%s" (org-section-number level))))
1458 (push (cons target target) target-alist)
1459 (add-text-properties
1460 (point-at-bol) (point-at-eol)
1461 (list 'target target))))
1462 target-alist)
1464 (defun org-export-handle-invisible-targets (target-alist)
1465 "Find targets in comments and move them out of comments.
1466 Mark them as invisible targets."
1467 (let (target tmp)
1468 (goto-char (point-min))
1469 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1470 ;; Check if the line before or after is a headline with a target
1471 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1472 (get-text-property (point-at-bol 2) 'target)))
1473 (progn
1474 ;; use the existing target in a neighboring line
1475 (setq tmp (match-string 2))
1476 (replace-match "")
1477 (and (looking-at "\n") (delete-char 1))
1478 (push (cons (org-solidify-link-text tmp) target)
1479 target-alist))
1480 ;; Make an invisible target
1481 (replace-match "\\1(INVISIBLE)"))))
1482 target-alist)
1484 (defun org-export-target-internal-links (target-alist)
1485 "Find all internal links and assign target to them.
1486 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1487 let the link point to the corresponding section."
1488 (goto-char (point-min))
1489 (while (re-search-forward org-bracket-link-regexp nil t)
1490 (org-if-unprotected
1491 (let* ((md (match-data))
1492 (desc (match-end 2))
1493 (link (org-link-unescape (match-string 1)))
1494 (slink (org-solidify-link-text link))
1495 found props pos
1496 (target
1497 (cond
1498 ((cdr (assoc slink target-alist)))
1499 ((string-match org-link-types-re link) nil)
1500 ((or (file-name-absolute-p link)
1501 (string-match "^\\." link))
1502 nil)
1504 (save-excursion
1505 (setq found (condition-case nil (org-link-search link)
1506 (error nil)))
1507 (when (and found
1508 (or (org-on-heading-p)
1509 (not (eq found 'dedicated))))
1510 (or (get-text-property (point) 'target)
1511 (get-text-property
1512 (max (point-min)
1513 (1- (previous-single-property-change
1514 (point) 'target)))
1515 'target))))))))
1516 (when target
1517 (set-match-data md)
1518 (goto-char (match-beginning 1))
1519 (setq props (text-properties-at (point)))
1520 (delete-region (match-beginning 1) (match-end 1))
1521 (setq pos (point))
1522 (insert target)
1523 (unless desc (insert "][" link))
1524 (add-text-properties pos (point) props))))))
1526 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1527 "Remove drawers, or extract the content.
1528 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1529 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1530 whose content to keep."
1531 (unless (eq t exp-drawers)
1532 (goto-char (point-min))
1533 (let ((re (concat "^[ \t]*:\\("
1534 (mapconcat
1535 'identity
1536 (org-delete-all exp-drawers
1537 (copy-sequence all-drawers))
1538 "\\|")
1539 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1540 (while (re-search-forward re nil t)
1541 (replace-match "")))))
1543 (defun org-export-remove-archived-trees (export-archived-trees)
1544 "Remove archived trees.
1545 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1546 When it is t, the entire archived tree will be exported.
1547 When it is nil the entire tree including the headline will be removed
1548 from the buffer."
1549 (let ((re-archive (concat ":" org-archive-tag ":"))
1550 a b)
1551 (when (not (eq export-archived-trees t))
1552 (goto-char (point-min))
1553 (while (re-search-forward re-archive nil t)
1554 (if (not (org-on-heading-p t))
1555 (org-end-of-subtree t)
1556 (beginning-of-line 1)
1557 (setq a (if export-archived-trees
1558 (1+ (point-at-eol)) (point))
1559 b (org-end-of-subtree t))
1560 (if (> b a) (delete-region a b)))))))
1562 (defun org-export-protect-quoted-subtrees ()
1563 "Mark quoted subtrees with the protection property."
1564 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1565 (goto-char (point-min))
1566 (while (re-search-forward re-quote nil t)
1567 (goto-char (match-beginning 0))
1568 (end-of-line 1)
1569 (add-text-properties (point) (org-end-of-subtree t)
1570 '(org-protected t)))))
1572 (defun org-export-protect-verbatim ()
1573 "Mark verbatim snippets with the protection property."
1574 (goto-char (point-min))
1575 (while (re-search-forward org-verbatim-re nil t)
1576 (add-text-properties (match-beginning 4) (match-end 4)
1577 '(org-protected t))
1578 (goto-char (1+ (match-end 4)))))
1580 (defun org-export-protect-examples ()
1581 "Protect code that should be exported as monospaced examples."
1582 (goto-char (point-min))
1583 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1584 (goto-char (match-end 0))
1585 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1586 (insert ": ")
1587 (beginning-of-line 2)))
1588 (goto-char (point-min))
1589 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1590 (add-text-properties (match-beginning 0) (match-end 0)
1591 '(org-protected t))))
1593 (defun org-export-select-backend-specific-text (backend)
1594 (let ((formatters
1595 '((html "HTML" "BEGIN_HTML" "END_HTML")
1596 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1597 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1598 fmt)
1600 (while formatters
1601 (setq fmt (pop formatters))
1602 (when (eq (car fmt) backend)
1603 ;; This is selected code, put it into the file for real
1604 (goto-char (point-min))
1605 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1606 ":[ \t]*\\(.*\\)") nil t)
1607 (replace-match "\\1" t)
1608 (add-text-properties
1609 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1610 '(org-protected t))))
1611 (goto-char (point-min))
1612 (while (re-search-forward
1613 (concat "^#\\+"
1614 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1615 (cadddr fmt) "\\>.*\n?") nil t)
1616 (if (eq (car fmt) backend)
1617 ;; yes, keep this
1618 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1619 '(org-protected t))
1620 ;; No, this is for a different backend, kill it
1621 (delete-region (match-beginning 0) (match-end 0)))))))
1623 (defun org-export-mark-blockquote-and-verse ()
1624 "Mark block quote and verse environments with special cookies.
1625 These special cookies will later be interpreted by the backend."
1626 ;; Blockquotes
1627 (goto-char (point-min))
1628 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1629 nil t)
1630 (replace-match (if (equal (downcase (match-string 1)) "end")
1631 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1632 t t))
1633 ;; Verse
1634 (goto-char (point-min))
1635 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1636 (replace-match (if (equal (downcase (match-string 1)) "end")
1637 "ORG-VERSE-END" "ORG-VERSE-START")
1638 t t)))
1640 (defun org-export-remove-comment-blocks-and-subtrees ()
1641 "Remove the comment environment, and also commented subtrees."
1642 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1643 (case-fold-search nil))
1644 ;; Remove comment environment
1645 (goto-char (point-min))
1646 (while (re-search-forward
1647 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1648 (replace-match "" t t))
1649 ;; Remove subtrees that are commented
1650 (goto-char (point-min))
1651 (while (re-search-forward re-commented nil t)
1652 (goto-char (match-beginning 0))
1653 (delete-region (point) (org-end-of-subtree t)))))
1655 (defun org-export-handle-comments (commentsp)
1656 "Remove comments, or convert to backend-specific format.
1657 COMMENTSP can be a format string for publishing comments.
1658 When it is nil, all comments will be removed."
1659 (let ((re "^#\\(.*\n?\\)")
1660 pos)
1661 (goto-char (point-min))
1662 (while (or (looking-at re)
1663 (re-search-forward re nil t))
1664 (setq pos (match-beginning 0))
1665 (if commentsp
1666 (progn (add-text-properties
1667 (match-beginning 0) (match-end 0) '(org-protected t))
1668 (replace-match (format commentsp (match-string 1)) t t))
1669 (goto-char (1+ pos))
1670 (org-if-unprotected
1671 (replace-match "")
1672 (goto-char (max (point-min) (1- pos))))))))
1674 (defun org-export-mark-radio-links ()
1675 "Find all matches for radio targets and turn them into internal links."
1676 (let ((re-radio (and org-target-link-regexp
1677 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1678 (goto-char (point-min))
1679 (when re-radio
1680 (while (re-search-forward re-radio nil t)
1681 (org-if-unprotected
1682 (replace-match "\\1[[\\2]]"))))))
1684 (defun org-export-remove-special-table-lines ()
1685 "Remove tables lines that are used for internal purposes."
1686 (goto-char (point-min))
1687 (while (re-search-forward "^[ \t]*|" nil t)
1688 (beginning-of-line 1)
1689 (if (or (looking-at "[ \t]*| *[!_^] *|")
1690 (and (looking-at ".*?| *<[0-9]+> *|")
1691 (not (looking-at ".*?| *[^ <|]"))))
1692 (delete-region (max (point-min) (1- (point-at-bol)))
1693 (point-at-eol))
1694 (end-of-line 1))))
1696 (defun org-export-normalize-links ()
1697 "Convert all links to bracket links, and expand link abbreviations."
1698 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1699 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1700 (goto-char (point-min))
1701 (while (re-search-forward re-plain-link nil t)
1702 (goto-char (1- (match-end 0)))
1703 (org-if-unprotected
1704 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1705 ":" (match-string 3) "]]")))
1706 ;; added 'org-link face to links
1707 (put-text-property 0 (length s) 'face 'org-link s)
1708 (replace-match s t t))))
1709 (goto-char (point-min))
1710 (while (re-search-forward re-angle-link nil t)
1711 (goto-char (1- (match-end 0)))
1712 (org-if-unprotected
1713 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1714 ":" (match-string 3) "]]")))
1715 (put-text-property 0 (length s) 'face 'org-link s)
1716 (replace-match s t t))))
1717 (goto-char (point-min))
1718 (while (re-search-forward org-bracket-link-regexp nil t)
1719 (goto-char (1- (match-end 0)))
1720 (org-if-unprotected
1721 (let* ((xx (save-match-data
1722 (org-link-expand-abbrev (match-string 1))))
1723 (s (concat
1724 "[[" xx "]"
1725 (if (match-end 3)
1726 (match-string 2)
1727 (concat "[" xx "]"))
1728 "]")))
1729 (put-text-property 0 (length s) 'face 'org-link s)
1730 (replace-match s t t))))))
1732 (defun org-export-concatenate-multiline-links ()
1733 "Find multi-line links and put it all into a single line.
1734 This is to make sure that the line-processing export backends
1735 can work correctly."
1736 (goto-char (point-min))
1737 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1738 (org-if-unprotected
1739 (replace-match "\\1 \\3")
1740 (goto-char (match-beginning 0)))))
1742 (defun org-export-concatenate-multiline-emphasis ()
1743 "Find multi-line emphasis and put it all into a single line.
1744 This is to make sure that the line-processing export backends
1745 can work correctly."
1746 (goto-char (point-min))
1747 (while (re-search-forward org-emph-re nil t)
1748 (if (not (= (char-after (match-beginning 3))
1749 (char-after (match-beginning 4))))
1750 (org-if-unprotected
1751 (subst-char-in-region (match-beginning 0) (match-end 0)
1752 ?\n ?\ t)
1753 (goto-char (1- (match-end 0))))
1754 (goto-char (1+ (match-beginning 0))))))
1756 (defun org-export-grab-title-from-buffer ()
1757 "Get a title for the current document, from looking at the buffer."
1758 (let ((inhibit-read-only t))
1759 (save-excursion
1760 (goto-char (point-min))
1761 (let ((end (save-excursion (outline-next-heading) (point))))
1762 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1763 ;; Mark the line so that it will not be exported as normal text.
1764 (org-unmodified
1765 (add-text-properties (match-beginning 0) (match-end 0)
1766 (list :org-license-to-kill t)))
1767 ;; Return the title string
1768 (org-trim (match-string 0)))))))
1770 (defun org-export-get-title-from-subtree ()
1771 "Return subtree title and exclude it from export."
1772 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1773 (save-excursion
1774 (goto-char rbeg)
1775 (when (and (org-at-heading-p)
1776 (>= (org-end-of-subtree t t) rend))
1777 ;; This is a subtree, we take the title from the first heading
1778 (goto-char rbeg)
1779 (looking-at org-todo-line-regexp)
1780 (setq title (match-string 3))
1781 (org-unmodified
1782 (add-text-properties (point) (1+ (point-at-eol))
1783 (list :org-license-to-kill t)))
1784 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1785 title))
1787 (defun org-solidify-link-text (s &optional alist)
1788 "Take link text and make a safe target out of it."
1789 (save-match-data
1790 (let* ((rtn
1791 (mapconcat
1792 'identity
1793 (org-split-string s "[ \t\r\n]+") "=="))
1794 (a (assoc rtn alist)))
1795 (or (cdr a) rtn))))
1797 (defun org-get-min-level (lines)
1798 "Get the minimum level in LINES."
1799 (let ((re "^\\(\\*+\\) ") l min)
1800 (catch 'exit
1801 (while (setq l (pop lines))
1802 (if (string-match re l)
1803 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1804 1)))
1806 ;; Variable holding the vector with section numbers
1807 (defvar org-section-numbers (make-vector org-level-max 0))
1809 (defun org-init-section-numbers ()
1810 "Initialize the vector for the section numbers."
1811 (let* ((level -1)
1812 (numbers (nreverse (org-split-string "" "\\.")))
1813 (depth (1- (length org-section-numbers)))
1814 (i depth) number-string)
1815 (while (>= i 0)
1816 (if (> i level)
1817 (aset org-section-numbers i 0)
1818 (setq number-string (or (car numbers) "0"))
1819 (if (string-match "\\`[A-Z]\\'" number-string)
1820 (aset org-section-numbers i
1821 (- (string-to-char number-string) ?A -1))
1822 (aset org-section-numbers i (string-to-number number-string)))
1823 (pop numbers))
1824 (setq i (1- i)))))
1826 (defun org-section-number (&optional level)
1827 "Return a string with the current section number.
1828 When LEVEL is non-nil, increase section numbers on that level."
1829 (let* ((depth (1- (length org-section-numbers)))
1830 (string "")
1831 (fmts (car org-export-section-number-format))
1832 (term (cdr org-export-section-number-format))
1833 (sep "")
1834 ctype fmt idx n)
1835 (when level
1836 (when (> level -1)
1837 (aset org-section-numbers
1838 level (1+ (aref org-section-numbers level))))
1839 (setq idx (1+ level))
1840 (while (<= idx depth)
1841 (if (not (= idx 1))
1842 (aset org-section-numbers idx 0))
1843 (setq idx (1+ idx))))
1844 (setq idx 0)
1845 (while (<= idx depth)
1846 (when (> (aref org-section-numbers idx) 0)
1847 (setq fmt (or (pop fmts) fmt)
1848 ctype (car fmt)
1849 n (aref org-section-numbers idx)
1850 string (if (> n 0)
1851 (concat string sep (org-number-to-counter n ctype))
1852 (concat string ".0"))
1853 sep (nth 1 fmt)))
1854 (setq idx (1+ idx)))
1855 (save-match-data
1856 (if (string-match "\\`\\([@0]\\.\\)+" string)
1857 (setq string (replace-match "" t nil string)))
1858 (if (string-match "\\(\\.0\\)+\\'" string)
1859 (setq string (replace-match "" t nil string))))
1860 (concat string term)))
1862 (defun org-number-to-counter (n type)
1863 "Concert number N to a string counter, according to TYPE.
1864 TYPE must be a string, any of:
1865 1 number
1866 A A,B,....
1867 a a,b,....
1868 I uppper case roman numeral
1869 i lower case roman numeral"
1870 (cond
1871 ((equal type "1") (number-to-string n))
1872 ((equal type "A") (char-to-string (+ ?A n -1)))
1873 ((equal type "a") (char-to-string (+ ?a n -1)))
1874 ((equal type "I") (org-number-to-roman n))
1875 ((equal type "i") (downcase (org-number-to-roman n)))
1876 (t (error "Invalid counter type `%s'" type))))
1878 (defun org-number-to-roman (n)
1879 "Convert integer N into a roman numeral."
1880 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1881 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1882 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1883 ( 1 . "I")))
1884 (res ""))
1885 (if (<= n 0)
1886 (number-to-string n)
1887 (while roman
1888 (if (>= n (caar roman))
1889 (setq n (- n (caar roman))
1890 res (concat res (cdar roman)))
1891 (pop roman)))
1892 res)))
1894 (org-number-to-roman 1961)
1897 ;;; Include files
1899 (defun org-export-handle-include-files ()
1900 "Include the contents of include files, with proper formatting."
1901 (let ((case-fold-search t)
1902 params file markup lang start end prefix prefix1)
1903 (goto-char (point-min))
1904 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
1905 (setq params (read (concat "(" (match-string 1) ")"))
1906 prefix (org-get-and-remove-property 'params :prefix)
1907 prefix1 (org-get-and-remove-property 'params :prefix1)
1908 file (org-symname-or-string (pop params))
1909 markup (org-symname-or-string (pop params))
1910 lang (org-symname-or-string (pop params)))
1911 (delete-region (match-beginning 0) (match-end 0))
1912 (if (or (not file)
1913 (not (file-exists-p file))
1914 (not (file-readable-p file)))
1915 (insert (format "CANNOT INCLUDE FILE %s" file))
1916 (when markup
1917 (if (equal (downcase markup) "src")
1918 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
1919 end "#+end_src")
1920 (setq start (format "#+begin_%s\n" markup)
1921 end (format "#+end_%s" markup))))
1922 (insert (or start ""))
1923 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
1924 (or (bolp) (newline))
1925 (insert (or end ""))))))
1927 (defun org-get-file-contents (file &optional prefix prefix1)
1928 "Get the contents of FILE and return them as a string.
1929 If PREFIX is a string, prepend it to each line. If PREFIX1
1930 is a string, prepend it to the first line instead of PREFIX."
1931 (with-temp-buffer
1932 (insert-file-contents file)
1933 (when (or prefix prefix1)
1934 (goto-char (point-min))
1935 (while (not (eobp))
1936 (insert (or prefix1 prefix))
1937 (setq prefix1 nil)
1938 (beginning-of-line 2)))
1939 (buffer-string)))
1941 (defun org-get-and-remove-property (listvar prop)
1942 "Check if the value of LISTVAR contains PROP as a property.
1943 If yes, return the value of that property (i.e. the element following
1944 in the list) and remove property and value from the list in LISTVAR."
1945 (let ((list (symbol-value listvar)) m v)
1946 (when (setq m (member prop list))
1947 (setq v (nth 1 m))
1948 (if (equal (car list) prop)
1949 (set listvar (cddr list))
1950 (setcdr (nthcdr (- (length list) (length m) 1) list)
1951 (cddr m))
1952 (set listvar list)))
1955 (defun org-symname-or-string (s)
1956 (if (symbolp s)
1957 (if s (symbol-name s) s)
1960 ;;; Fontification of code
1961 ;; Currently only for the HTML backend, but who knows....
1962 (defun org-export-replace-src-segments ()
1963 "Replace source code segments with special code for export."
1964 (let ((case-fold-search t)
1965 lang code trans)
1966 (goto-char (point-min))
1967 (while (re-search-forward
1968 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1969 nil t)
1970 (setq lang (match-string 1) code (match-string 2)
1971 trans (org-export-format-source-code lang code))
1972 (replace-match trans t t))))
1974 (defvar htmlp) ;; dynamically scoped from org-exp.el
1976 (defun org-export-format-source-code (lang code)
1977 "Format CODE from language LANG and return it formatted for export.
1978 Currently, this only does something for HTML export, for all other
1979 backends, it converts the segment into an EXAMPLE segment."
1980 (save-match-data
1981 (cond
1982 (htmlp
1983 ;; We are exporting to HTML
1984 (condition-case nil (require 'htmlize) (nil t))
1985 (if (not (fboundp 'htmlize-region-for-paste))
1986 (progn
1987 ;; we do not have htmlize.el, or an old version of it
1988 (message
1989 "htmlize.el 1.34 or later is needed for source code formatting")
1990 (concat "#+BEGIN_EXAMPLE\n" code
1991 (if (string-match "\n\\'" code) "" "\n")
1992 "#+END_EXAMPLE\n"))
1993 ;; ok, we are good to go
1994 (let* ((mode (and lang (intern (concat lang "-mode"))))
1995 (org-inhibit-startup t)
1996 (org-startup-folded nil)
1997 (htmltext
1998 (with-temp-buffer
1999 (insert code)
2000 ;; Free up the protected stuff
2001 (goto-char (point-min))
2002 (while (re-search-forward "^," nil t)
2003 (replace-match "")
2004 (end-of-line 1))
2005 (if (functionp mode)
2006 (funcall mode)
2007 (fundamental-mode))
2008 (font-lock-fontify-buffer)
2009 (org-export-htmlize-region-for-paste
2010 (point-min) (point-max)))))
2011 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2012 (setq htmltext (replace-match
2013 (format "<pre class=\"src src-%s\">" lang)
2014 t t htmltext)))
2015 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2017 ;; This is not HTML, so just make it an example.
2018 (when (equal lang "org")
2019 (while (string-match "^," code)
2020 (setq code (replace-match "" t t code))))
2021 (concat "#+BEGIN_EXAMPLE\n" code
2022 (if (string-match "\n\\'" code) "" "\n")
2023 "#+END_EXAMPLE\n")))))
2025 ;;; ASCII export
2027 (defvar org-last-level nil) ; dynamically scoped variable
2028 (defvar org-min-level nil) ; dynamically scoped variable
2029 (defvar org-levels-open nil) ; dynamically scoped parameter
2030 (defvar org-ascii-current-indentation nil) ; For communication
2032 ;;;###autoload
2033 (defun org-export-as-ascii (arg)
2034 "Export the outline as a pretty ASCII file.
2035 If there is an active region, export only the region.
2036 The prefix ARG specifies how many levels of the outline should become
2037 underlined headlines. The default is 3."
2038 (interactive "P")
2039 (setq-default org-todo-line-regexp org-todo-line-regexp)
2040 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2041 (org-infile-export-plist)))
2042 (region-p (org-region-active-p))
2043 (rbeg (and region-p (region-beginning)))
2044 (rend (and region-p (region-end)))
2045 (subtree-p
2046 (when region-p
2047 (save-excursion
2048 (goto-char rbeg)
2049 (and (org-at-heading-p)
2050 (>= (org-end-of-subtree t t) rend)))))
2051 (opt-plist (if subtree-p
2052 (org-export-add-subtree-options opt-plist rbeg)
2053 opt-plist))
2054 (custom-times org-display-custom-times)
2055 (org-ascii-current-indentation '(0 . 0))
2056 (level 0) line txt
2057 (umax nil)
2058 (umax-toc nil)
2059 (case-fold-search nil)
2060 (filename (concat (file-name-as-directory
2061 (org-export-directory :ascii opt-plist))
2062 (file-name-sans-extension
2063 (or (and subtree-p
2064 (org-entry-get (region-beginning)
2065 "EXPORT_FILE_NAME" t))
2066 (file-name-nondirectory buffer-file-name)))
2067 ".txt"))
2068 (filename (if (equal (file-truename filename)
2069 (file-truename buffer-file-name))
2070 (concat filename ".txt")
2071 filename))
2072 (buffer (find-file-noselect filename))
2073 (org-levels-open (make-vector org-level-max nil))
2074 (odd org-odd-levels-only)
2075 (date (plist-get opt-plist :date))
2076 (author (plist-get opt-plist :author))
2077 (title (or (and subtree-p (org-export-get-title-from-subtree))
2078 (plist-get opt-plist :title)
2079 (and (not
2080 (plist-get opt-plist :skip-before-1st-heading))
2081 (org-export-grab-title-from-buffer))
2082 (file-name-sans-extension
2083 (file-name-nondirectory buffer-file-name))))
2084 (email (plist-get opt-plist :email))
2085 (language (plist-get opt-plist :language))
2086 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2087 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2088 (todo nil)
2089 (lang-words nil)
2090 (region
2091 (buffer-substring
2092 (if (org-region-active-p) (region-beginning) (point-min))
2093 (if (org-region-active-p) (region-end) (point-max))))
2094 (lines (org-split-string
2095 (org-export-preprocess-string
2096 region
2097 :for-ascii t
2098 :skip-before-1st-heading
2099 (plist-get opt-plist :skip-before-1st-heading)
2100 :drawers (plist-get opt-plist :drawers)
2101 :verbatim-multiline t
2102 :archived-trees
2103 (plist-get opt-plist :archived-trees)
2104 :add-text (plist-get opt-plist :text))
2105 "\n"))
2106 thetoc have-headings first-heading-pos
2107 table-open table-buffer)
2109 (let ((inhibit-read-only t))
2110 (org-unmodified
2111 (remove-text-properties (point-min) (point-max)
2112 '(:org-license-to-kill t))))
2114 (setq org-min-level (org-get-min-level lines))
2115 (setq org-last-level org-min-level)
2116 (org-init-section-numbers)
2118 (find-file-noselect filename)
2120 (setq lang-words (or (assoc language org-export-language-setup)
2121 (assoc "en" org-export-language-setup)))
2122 (switch-to-buffer-other-window buffer)
2123 (erase-buffer)
2124 (fundamental-mode)
2125 ;; create local variables for all options, to make sure all called
2126 ;; functions get the correct information
2127 (mapc (lambda (x)
2128 (set (make-local-variable (cdr x))
2129 (plist-get opt-plist (car x))))
2130 org-export-plist-vars)
2131 (org-set-local 'org-odd-levels-only odd)
2132 (setq umax (if arg (prefix-numeric-value arg)
2133 org-export-headline-levels))
2134 (setq umax-toc (if (integerp org-export-with-toc)
2135 (min org-export-with-toc umax)
2136 umax))
2138 ;; File header
2139 (if title (org-insert-centered title ?=))
2140 (insert "\n")
2141 (if (and (or author email)
2142 org-export-author-info)
2143 (insert (concat (nth 1 lang-words) ": " (or author "")
2144 (if email (concat " <" email ">") "")
2145 "\n")))
2147 (cond
2148 ((and date (string-match "%" date))
2149 (setq date (format-time-string date)))
2150 (date)
2151 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2153 (if (and date org-export-time-stamp-file)
2154 (insert (concat (nth 2 lang-words) ": " date"\n")))
2156 (insert "\n\n")
2158 (if org-export-with-toc
2159 (progn
2160 (push (concat (nth 3 lang-words) "\n") thetoc)
2161 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2162 "\n") thetoc)
2163 (mapc '(lambda (line)
2164 (if (string-match org-todo-line-regexp
2165 line)
2166 ;; This is a headline
2167 (progn
2168 (setq have-headings t)
2169 (setq level (- (match-end 1) (match-beginning 1))
2170 level (org-tr-level level)
2171 txt (match-string 3 line)
2172 todo
2173 (or (and org-export-mark-todo-in-toc
2174 (match-beginning 2)
2175 (not (member (match-string 2 line)
2176 org-done-keywords)))
2177 ; TODO, not DONE
2178 (and org-export-mark-todo-in-toc
2179 (= level umax-toc)
2180 (org-search-todo-below
2181 line lines level))))
2182 (setq txt (org-html-expand-for-ascii txt))
2184 (while (string-match org-bracket-link-regexp txt)
2185 (setq txt
2186 (replace-match
2187 (match-string (if (match-end 2) 3 1) txt)
2188 t t txt)))
2190 (if (and (memq org-export-with-tags '(not-in-toc nil))
2191 (string-match
2192 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2193 txt))
2194 (setq txt (replace-match "" t t txt)))
2195 (if (string-match quote-re0 txt)
2196 (setq txt (replace-match "" t t txt)))
2198 (if org-export-with-section-numbers
2199 (setq txt (concat (org-section-number level)
2200 " " txt)))
2201 (if (<= level umax-toc)
2202 (progn
2203 (push
2204 (concat
2205 (make-string
2206 (* (max 0 (- level org-min-level)) 4) ?\ )
2207 (format (if todo "%s (*)\n" "%s\n") txt))
2208 thetoc)
2209 (setq org-last-level level))
2210 ))))
2211 lines)
2212 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2214 (org-init-section-numbers)
2215 (while (setq line (pop lines))
2216 ;; Remove the quoted HTML tags.
2217 (setq line (org-html-expand-for-ascii line))
2218 ;; Remove targets
2219 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2220 (setq line (replace-match "" t t line)))
2221 ;; Replace internal links
2222 (while (string-match org-bracket-link-regexp line)
2223 (setq line (replace-match
2224 (if (match-end 3) "[\\3]" "[\\1]")
2225 t nil line)))
2226 (when custom-times
2227 (setq line (org-translate-time line)))
2228 (cond
2229 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2230 ;; a Headline
2231 (setq first-heading-pos (or first-heading-pos (point)))
2232 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2233 txt (match-string 2 line))
2234 (org-ascii-level-start level txt umax lines))
2236 ((and org-export-with-tables
2237 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2238 (if (not table-open)
2239 ;; New table starts
2240 (setq table-open t table-buffer nil))
2241 ;; Accumulate lines
2242 (setq table-buffer (cons line table-buffer))
2243 (when (or (not lines)
2244 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2245 (car lines))))
2246 (setq table-open nil
2247 table-buffer (nreverse table-buffer))
2248 (insert (mapconcat
2249 (lambda (x)
2250 (org-fix-indentation x org-ascii-current-indentation))
2251 (org-format-table-ascii table-buffer)
2252 "\n") "\n")))
2254 (setq line (org-fix-indentation line org-ascii-current-indentation))
2255 (if (and org-export-with-fixed-width
2256 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2257 (setq line (replace-match "\\1" nil nil line)))
2258 (insert line "\n"))))
2260 (normal-mode)
2262 ;; insert the table of contents
2263 (when thetoc
2264 (goto-char (point-min))
2265 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2266 (progn
2267 (goto-char (match-beginning 0))
2268 (replace-match ""))
2269 (goto-char first-heading-pos))
2270 (mapc 'insert thetoc)
2271 (or (looking-at "[ \t]*\n[ \t]*\n")
2272 (insert "\n\n")))
2274 ;; Convert whitespace place holders
2275 (goto-char (point-min))
2276 (let (beg end)
2277 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2278 (setq end (next-single-property-change beg 'org-whitespace))
2279 (goto-char beg)
2280 (delete-region beg end)
2281 (insert (make-string (- end beg) ?\ ))))
2283 (save-buffer)
2284 ;; remove display and invisible chars
2285 (let (beg end)
2286 (goto-char (point-min))
2287 (while (setq beg (next-single-property-change (point) 'display))
2288 (setq end (next-single-property-change beg 'display))
2289 (delete-region beg end)
2290 (goto-char beg)
2291 (insert "=>"))
2292 (goto-char (point-min))
2293 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2294 (setq end (next-single-property-change beg 'org-cwidth))
2295 (delete-region beg end)
2296 (goto-char beg)))
2297 (goto-char (point-min))))
2299 (defun org-export-ascii-preprocess ()
2300 "Do extra work for ASCII export"
2301 (goto-char (point-min))
2302 (while (re-search-forward org-verbatim-re nil t)
2303 (goto-char (match-end 2))
2304 (backward-delete-char 1) (insert "'")
2305 (goto-char (match-beginning 2))
2306 (delete-char 1) (insert "`")
2307 (goto-char (match-end 2))))
2309 (defun org-search-todo-below (line lines level)
2310 "Search the subtree below LINE for any TODO entries."
2311 (let ((rest (cdr (memq line lines)))
2312 (re org-todo-line-regexp)
2313 line lv todo)
2314 (catch 'exit
2315 (while (setq line (pop rest))
2316 (if (string-match re line)
2317 (progn
2318 (setq lv (- (match-end 1) (match-beginning 1))
2319 todo (and (match-beginning 2)
2320 (not (member (match-string 2 line)
2321 org-done-keywords))))
2322 ; TODO, not DONE
2323 (if (<= lv level) (throw 'exit nil))
2324 (if todo (throw 'exit t))))))))
2326 (defun org-html-expand-for-ascii (line)
2327 "Handle quoted HTML for ASCII export."
2328 (if org-export-html-expand
2329 (while (string-match "@<[^<>\n]*>" line)
2330 ;; We just remove the tags for now.
2331 (setq line (replace-match "" nil nil line))))
2332 line)
2334 (defun org-insert-centered (s &optional underline)
2335 "Insert the string S centered and underline it with character UNDERLINE."
2336 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2337 (insert (make-string ind ?\ ) s "\n")
2338 (if underline
2339 (insert (make-string ind ?\ )
2340 (make-string (string-width s) underline)
2341 "\n"))))
2343 (defun org-ascii-level-start (level title umax &optional lines)
2344 "Insert a new level in ASCII export."
2345 (let (char (n (- level umax 1)) (ind 0))
2346 (if (> level umax)
2347 (progn
2348 (insert (make-string (* 2 n) ?\ )
2349 (char-to-string (nth (% n (length org-export-ascii-bullets))
2350 org-export-ascii-bullets))
2351 " " title "\n")
2352 ;; find the indentation of the next non-empty line
2353 (catch 'stop
2354 (while lines
2355 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2356 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2357 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2358 (pop lines)))
2359 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2360 (if (or (not (equal (char-before) ?\n))
2361 (not (equal (char-before (1- (point))) ?\n)))
2362 (insert "\n"))
2363 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2364 (unless org-export-with-tags
2365 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2366 (setq title (replace-match "" t t title))))
2367 (if org-export-with-section-numbers
2368 (setq title (concat (org-section-number level) " " title)))
2369 (insert title "\n" (make-string (string-width title) char) "\n")
2370 (setq org-ascii-current-indentation '(0 . 0)))))
2372 ;;;###autoload
2373 (defun org-export-visible (type arg)
2374 "Create a copy of the visible part of the current buffer, and export it.
2375 The copy is created in a temporary buffer and removed after use.
2376 TYPE is the final key (as a string) that also select the export command in
2377 the `C-c C-e' export dispatcher.
2378 As a special case, if the you type SPC at the prompt, the temporary
2379 org-mode file will not be removed but presented to you so that you can
2380 continue to use it. The prefix arg ARG is passed through to the exporting
2381 command."
2382 (interactive
2383 (list (progn
2384 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2385 (read-char-exclusive))
2386 current-prefix-arg))
2387 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2388 (error "Invalid export key"))
2389 (let* ((binding (cdr (assoc type
2390 '((?a . org-export-as-ascii)
2391 (?\C-a . org-export-as-ascii)
2392 (?b . org-export-as-html-and-open)
2393 (?\C-b . org-export-as-html-and-open)
2394 (?h . org-export-as-html)
2395 (?H . org-export-as-html-to-buffer)
2396 (?R . org-export-region-as-html)
2397 (?x . org-export-as-xoxo)))))
2398 (keepp (equal type ?\ ))
2399 (file buffer-file-name)
2400 (buffer (get-buffer-create "*Org Export Visible*"))
2401 s e)
2402 ;; Need to hack the drawers here.
2403 (save-excursion
2404 (goto-char (point-min))
2405 (while (re-search-forward org-drawer-regexp nil t)
2406 (goto-char (match-beginning 1))
2407 (or (org-invisible-p) (org-flag-drawer nil))))
2408 (with-current-buffer buffer (erase-buffer))
2409 (save-excursion
2410 (setq s (goto-char (point-min)))
2411 (while (not (= (point) (point-max)))
2412 (goto-char (org-find-invisible))
2413 (append-to-buffer buffer s (point))
2414 (setq s (goto-char (org-find-visible))))
2415 (org-cycle-hide-drawers 'all)
2416 (goto-char (point-min))
2417 (unless keepp
2418 ;; Copy all comment lines to the end, to make sure #+ settings are
2419 ;; still available for the second export step. Kind of a hack, but
2420 ;; does do the trick.
2421 (if (looking-at "#[^\r\n]*")
2422 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2423 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2424 (append-to-buffer buffer (1+ (match-beginning 0))
2425 (min (point-max) (1+ (match-end 0))))))
2426 (set-buffer buffer)
2427 (let ((buffer-file-name file)
2428 (org-inhibit-startup t))
2429 (org-mode)
2430 (show-all)
2431 (unless keepp (funcall binding arg))))
2432 (if (not keepp)
2433 (kill-buffer buffer)
2434 (switch-to-buffer-other-window buffer)
2435 (goto-char (point-min)))))
2437 (defun org-find-visible ()
2438 (let ((s (point)))
2439 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2440 (get-char-property s 'invisible)))
2442 (defun org-find-invisible ()
2443 (let ((s (point)))
2444 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2445 (not (get-char-property s 'invisible))))
2448 ;;; HTML export
2450 (defvar org-archive-location) ;; gets loades with the org-archive require.
2451 (defun org-get-current-options ()
2452 "Return a string with current options as keyword options.
2453 Does include HTML export options as well as TODO and CATEGORY stuff."
2454 (require 'org-archive)
2455 (format
2456 "#+TITLE: %s
2457 #+AUTHOR: %s
2458 #+EMAIL: %s
2459 #+DATE: %s
2460 #+LANGUAGE: %s
2461 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2462 #+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
2464 #+LINK_UP: %s
2465 #+LINK_HOME: %s
2466 #+CATEGORY: %s
2467 #+SEQ_TODO: %s
2468 #+TYP_TODO: %s
2469 #+PRIORITIES: %c %c %c
2470 #+DRAWERS: %s
2471 #+STARTUP: %s %s %s %s %s
2472 #+TAGS: %s
2473 #+FILETAGS: %s
2474 #+ARCHIVE: %s
2475 #+LINK: %s
2477 (buffer-name) (user-full-name) user-mail-address
2478 (format-time-string (car org-time-stamp-formats))
2479 org-export-default-language
2480 org-export-headline-levels
2481 org-export-with-section-numbers
2482 org-export-with-toc
2483 org-export-preserve-breaks
2484 org-export-html-expand
2485 org-export-with-fixed-width
2486 org-export-with-tables
2487 org-export-with-sub-superscripts
2488 org-export-with-special-strings
2489 org-export-with-footnotes
2490 org-export-with-emphasize
2491 org-export-with-TeX-macros
2492 org-export-with-LaTeX-fragments
2493 org-export-skip-text-before-1st-heading
2494 org-export-with-drawers
2495 org-export-with-tags
2496 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2497 org-export-html-link-up
2498 org-export-html-link-home
2499 (file-name-nondirectory buffer-file-name)
2500 "TODO FEEDBACK VERIFY DONE"
2501 "Me Jason Marie DONE"
2502 org-highest-priority org-lowest-priority org-default-priority
2503 (mapconcat 'identity org-drawers " ")
2504 (cdr (assoc org-startup-folded
2505 '((nil . "showall") (t . "overview") (content . "content"))))
2506 (if org-odd-levels-only "odd" "oddeven")
2507 (if org-hide-leading-stars "hidestars" "showstars")
2508 (if org-startup-align-all-tables "align" "noalign")
2509 (cond ((eq org-log-done t) "logdone")
2510 ((equal org-log-done 'note) "lognotedone")
2511 ((not org-log-done) "nologdone"))
2512 (or (mapconcat (lambda (x)
2513 (cond
2514 ((equal '(:startgroup) x) "{")
2515 ((equal '(:endgroup) x) "}")
2516 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2517 (t (car x))))
2518 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2519 (mapconcat 'identity org-file-tags " ")
2520 org-archive-location
2521 "org file:~/org/%s.org"
2524 (defun org-export-html-preprocess (parameters)
2525 ;; Convert LaTeX fragments to images
2526 (when (plist-get parameters :LaTeX-fragments)
2527 (org-format-latex
2528 (concat "ltxpng/" (file-name-sans-extension
2529 (file-name-nondirectory
2530 org-current-export-file)))
2531 org-current-export-dir nil "Creating LaTeX image %s"))
2532 (message "Exporting..."))
2534 ;;;###autoload
2535 (defun org-insert-export-options-template ()
2536 "Insert into the buffer a template with information for exporting."
2537 (interactive)
2538 (if (not (bolp)) (newline))
2539 (let ((s (org-get-current-options)))
2540 (and (string-match "#\\+CATEGORY" s)
2541 (setq s (substring s 0 (match-beginning 0))))
2542 (insert s)))
2544 ;;;###autoload
2545 (defun org-export-as-html-and-open (arg)
2546 "Export the outline as HTML and immediately open it with a browser.
2547 If there is an active region, export only the region.
2548 The prefix ARG specifies how many levels of the outline should become
2549 headlines. The default is 3. Lower levels will become bulleted lists."
2550 (interactive "P")
2551 (org-export-as-html arg 'hidden)
2552 (org-open-file buffer-file-name))
2554 ;;;###autoload
2555 (defun org-export-as-html-batch ()
2556 "Call `org-export-as-html', may be used in batch processing as
2557 emacs --batch
2558 --load=$HOME/lib/emacs/org.el
2559 --eval \"(setq org-export-headline-levels 2)\"
2560 --visit=MyFile --funcall org-export-as-html-batch"
2561 (org-export-as-html org-export-headline-levels 'hidden))
2563 ;;;###autoload
2564 (defun org-export-as-html-to-buffer (arg)
2565 "Call `org-exort-as-html` with output to a temporary buffer.
2566 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2567 (interactive "P")
2568 (org-export-as-html arg nil nil "*Org HTML Export*")
2569 (switch-to-buffer-other-window "*Org HTML Export*"))
2571 ;;;###autoload
2572 (defun org-replace-region-by-html (beg end)
2573 "Assume the current region has org-mode syntax, and convert it to HTML.
2574 This can be used in any buffer. For example, you could write an
2575 itemized list in org-mode syntax in an HTML buffer and then use this
2576 command to convert it."
2577 (interactive "r")
2578 (let (reg html buf pop-up-frames)
2579 (save-window-excursion
2580 (if (org-mode-p)
2581 (setq html (org-export-region-as-html
2582 beg end t 'string))
2583 (setq reg (buffer-substring beg end)
2584 buf (get-buffer-create "*Org tmp*"))
2585 (with-current-buffer buf
2586 (erase-buffer)
2587 (insert reg)
2588 (org-mode)
2589 (setq html (org-export-region-as-html
2590 (point-min) (point-max) t 'string)))
2591 (kill-buffer buf)))
2592 (delete-region beg end)
2593 (insert html)))
2595 ;;;###autoload
2596 (defun org-export-region-as-html (beg end &optional body-only buffer)
2597 "Convert region from BEG to END in org-mode buffer to HTML.
2598 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2599 contents, and only produce the region of converted text, useful for
2600 cut-and-paste operations.
2601 If BUFFER is a buffer or a string, use/create that buffer as a target
2602 of the converted HTML. If BUFFER is the symbol `string', return the
2603 produced HTML as a string and leave not buffer behind. For example,
2604 a Lisp program could call this function in the following way:
2606 (setq html (org-export-region-as-html beg end t 'string))
2608 When called interactively, the output buffer is selected, and shown
2609 in a window. A non-interactive call will only return the buffer."
2610 (interactive "r\nP")
2611 (when (interactive-p)
2612 (setq buffer "*Org HTML Export*"))
2613 (let ((transient-mark-mode t) (zmacs-regions t)
2614 ext-plist rtn)
2615 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2616 (goto-char end)
2617 (set-mark (point)) ;; to activate the region
2618 (goto-char beg)
2619 (setq rtn (org-export-as-html
2620 nil nil ext-plist
2621 buffer body-only))
2622 (if (fboundp 'deactivate-mark) (deactivate-mark))
2623 (if (and (interactive-p) (bufferp rtn))
2624 (switch-to-buffer-other-window rtn)
2625 rtn)))
2627 (defvar html-table-tag nil) ; dynamically scoped into this.
2628 ;;;###autoload
2629 (defun org-export-as-html (arg &optional hidden ext-plist
2630 to-buffer body-only pub-dir)
2631 "Export the outline as a pretty HTML file.
2632 If there is an active region, export only the region. The prefix
2633 ARG specifies how many levels of the outline should become
2634 headlines. The default is 3. Lower levels will become bulleted
2635 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2636 EXT-PLIST is a property list with external parameters overriding
2637 org-mode's default settings, but still inferior to file-local
2638 settings. When TO-BUFFER is non-nil, create a buffer with that
2639 name and export to that buffer. If TO-BUFFER is the symbol
2640 `string', don't leave any buffer behind but just return the
2641 resulting HTML as a string. When BODY-ONLY is set, don't produce
2642 the file header and footer, simply return the content of
2643 <body>...</body>, without even the body tags themselves. When
2644 PUB-DIR is set, use this as the publishing directory."
2645 (interactive "P")
2647 ;; Make sure we have a file name when we need it.
2648 (when (and (not (or to-buffer body-only))
2649 (not buffer-file-name))
2650 (if (buffer-base-buffer)
2651 (org-set-local 'buffer-file-name
2652 (with-current-buffer (buffer-base-buffer)
2653 buffer-file-name))
2654 (error "Need a file name to be able to export.")))
2656 (message "Exporting...")
2657 (setq-default org-todo-line-regexp org-todo-line-regexp)
2658 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2659 (setq-default org-done-keywords org-done-keywords)
2660 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2661 (let* ((opt-plist
2662 (org-export-process-option-filters
2663 (org-combine-plists (org-default-export-plist)
2664 ext-plist
2665 (org-infile-export-plist))))
2667 (style (concat org-export-html-style-default
2668 (plist-get opt-plist :style)
2669 (plist-get opt-plist :style-extra)))
2670 (html-extension (plist-get opt-plist :html-extension))
2671 (link-validate (plist-get opt-plist :link-validation-function))
2672 valid thetoc have-headings first-heading-pos
2673 (odd org-odd-levels-only)
2674 (region-p (org-region-active-p))
2675 (rbeg (and region-p (region-beginning)))
2676 (rend (and region-p (region-end)))
2677 (subtree-p
2678 (if (plist-get opt-plist :ignore-subree-p)
2680 (when region-p
2681 (save-excursion
2682 (goto-char rbeg)
2683 (and (org-at-heading-p)
2684 (>= (org-end-of-subtree t t) rend))))))
2685 (opt-plist (if subtree-p
2686 (org-export-add-subtree-options opt-plist rbeg)
2687 opt-plist))
2688 ;; The following two are dynamically scoped into other
2689 ;; routines below.
2690 (org-current-export-dir
2691 (or pub-dir (org-export-directory :html opt-plist)))
2692 (org-current-export-file buffer-file-name)
2693 (level 0) (line "") (origline "") txt todo
2694 (umax nil)
2695 (umax-toc nil)
2696 (filename (if to-buffer nil
2697 (expand-file-name
2698 (concat
2699 (file-name-sans-extension
2700 (or (and subtree-p
2701 (org-entry-get (region-beginning)
2702 "EXPORT_FILE_NAME" t))
2703 (file-name-nondirectory buffer-file-name)))
2704 "." html-extension)
2705 (file-name-as-directory
2706 (or pub-dir (org-export-directory :html opt-plist))))))
2707 (current-dir (if buffer-file-name
2708 (file-name-directory buffer-file-name)
2709 default-directory))
2710 (buffer (if to-buffer
2711 (cond
2712 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2713 (t (get-buffer-create to-buffer)))
2714 (find-file-noselect filename)))
2715 (org-levels-open (make-vector org-level-max nil))
2716 (date (plist-get opt-plist :date))
2717 (author (plist-get opt-plist :author))
2718 (title (or (and subtree-p (org-export-get-title-from-subtree))
2719 (plist-get opt-plist :title)
2720 (and (not
2721 (plist-get opt-plist :skip-before-1st-heading))
2722 (org-export-grab-title-from-buffer))
2723 (and buffer-file-name
2724 (file-name-sans-extension
2725 (file-name-nondirectory buffer-file-name)))
2726 "UNTITLED"))
2727 (html-table-tag (plist-get opt-plist :html-table-tag))
2728 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2729 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2730 (inquote nil)
2731 (infixed nil)
2732 (inverse nil)
2733 (in-local-list nil)
2734 (local-list-type nil)
2735 (local-list-indent nil)
2736 (llt org-plain-list-ordered-item-terminator)
2737 (email (plist-get opt-plist :email))
2738 (language (plist-get opt-plist :language))
2739 (lang-words nil)
2740 (head-count 0) cnt
2741 (start 0)
2742 (coding-system (and (boundp 'buffer-file-coding-system)
2743 buffer-file-coding-system))
2744 (coding-system-for-write (or org-export-html-coding-system
2745 coding-system))
2746 (save-buffer-coding-system (or org-export-html-coding-system
2747 coding-system))
2748 (charset (and coding-system-for-write
2749 (fboundp 'coding-system-get)
2750 (coding-system-get coding-system-for-write
2751 'mime-charset)))
2752 (region
2753 (buffer-substring
2754 (if region-p (region-beginning) (point-min))
2755 (if region-p (region-end) (point-max))))
2756 (lines
2757 (org-split-string
2758 (org-export-preprocess-string
2759 region
2760 :emph-multiline t
2761 :for-html t
2762 :skip-before-1st-heading
2763 (plist-get opt-plist :skip-before-1st-heading)
2764 :drawers (plist-get opt-plist :drawers)
2765 :archived-trees
2766 (plist-get opt-plist :archived-trees)
2767 :add-text
2768 (plist-get opt-plist :text)
2769 :LaTeX-fragments
2770 (plist-get opt-plist :LaTeX-fragments))
2771 "[\r\n]"))
2772 table-open type
2773 table-buffer table-orig-buffer
2774 ind item-type starter didclose
2775 rpl path attr desc descp desc1 desc2 link
2776 snumber fnc item-tag
2779 (let ((inhibit-read-only t))
2780 (org-unmodified
2781 (remove-text-properties (point-min) (point-max)
2782 '(:org-license-to-kill t))))
2784 (message "Exporting...")
2786 (setq org-min-level (org-get-min-level lines))
2787 (setq org-last-level org-min-level)
2788 (org-init-section-numbers)
2790 (cond
2791 ((and date (string-match "%" date))
2792 (setq date (format-time-string date)))
2793 (date)
2794 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2796 ;; Get the language-dependent settings
2797 (setq lang-words (or (assoc language org-export-language-setup)
2798 (assoc "en" org-export-language-setup)))
2800 ;; Switch to the output buffer
2801 (set-buffer buffer)
2802 (let ((inhibit-read-only t)) (erase-buffer))
2803 (fundamental-mode)
2805 (and (fboundp 'set-buffer-file-coding-system)
2806 (set-buffer-file-coding-system coding-system-for-write))
2808 (let ((case-fold-search nil)
2809 (org-odd-levels-only odd))
2810 ;; create local variables for all options, to make sure all called
2811 ;; functions get the correct information
2812 (mapc (lambda (x)
2813 (set (make-local-variable (cdr x))
2814 (plist-get opt-plist (car x))))
2815 org-export-plist-vars)
2816 (setq umax (if arg (prefix-numeric-value arg)
2817 org-export-headline-levels))
2818 (setq umax-toc (if (integerp org-export-with-toc)
2819 (min org-export-with-toc umax)
2820 umax))
2821 (unless body-only
2822 ;; File header
2823 (insert (format
2824 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2825 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2826 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2827 lang=\"%s\" xml:lang=\"%s\">
2828 <head>
2829 <title>%s</title>
2830 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2831 <meta name=\"generator\" content=\"Org-mode\"/>
2832 <meta name=\"generated\" content=\"%s\"/>
2833 <meta name=\"author\" content=\"%s\"/>
2835 </head><body>
2837 language language (org-html-expand title)
2838 (or charset "iso-8859-1") date author style))
2840 (insert (or (plist-get opt-plist :preamble) ""))
2842 (when (plist-get opt-plist :auto-preamble)
2843 (if title (insert (format org-export-html-title-format
2844 (org-html-expand title))))))
2846 (if (and org-export-with-toc (not body-only))
2847 (progn
2848 (push (format "<h%d>%s</h%d>\n"
2849 org-export-html-toplevel-hlevel
2850 (nth 3 lang-words)
2851 org-export-html-toplevel-hlevel)
2852 thetoc)
2853 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2854 (push "<ul>\n<li>" thetoc)
2855 (setq lines
2856 (mapcar '(lambda (line)
2857 (if (string-match org-todo-line-regexp line)
2858 ;; This is a headline
2859 (progn
2860 (setq have-headings t)
2861 (setq level (- (match-end 1) (match-beginning 1))
2862 level (org-tr-level level)
2863 txt (save-match-data
2864 (org-html-expand
2865 (org-export-cleanup-toc-line
2866 (match-string 3 line))))
2867 todo
2868 (or (and org-export-mark-todo-in-toc
2869 (match-beginning 2)
2870 (not (member (match-string 2 line)
2871 org-done-keywords)))
2872 ; TODO, not DONE
2873 (and org-export-mark-todo-in-toc
2874 (= level umax-toc)
2875 (org-search-todo-below
2876 line lines level))))
2877 (if (string-match
2878 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2879 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2880 (if (string-match quote-re0 txt)
2881 (setq txt (replace-match "" t t txt)))
2882 (setq snumber (org-section-number level))
2883 (if org-export-with-section-numbers
2884 (setq txt (concat snumber " " txt)))
2885 (if (<= level (max umax umax-toc))
2886 (setq head-count (+ head-count 1)))
2887 (if (<= level umax-toc)
2888 (progn
2889 (if (> level org-last-level)
2890 (progn
2891 (setq cnt (- level org-last-level))
2892 (while (>= (setq cnt (1- cnt)) 0)
2893 (push "\n<ul>\n<li>" thetoc))
2894 (push "\n" thetoc)))
2895 (if (< level org-last-level)
2896 (progn
2897 (setq cnt (- org-last-level level))
2898 (while (>= (setq cnt (1- cnt)) 0)
2899 (push "</li>\n</ul>" thetoc))
2900 (push "\n" thetoc)))
2901 ;; Check for targets
2902 (while (string-match org-any-target-regexp line)
2903 (setq line (replace-match
2904 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2905 t t line)))
2906 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2907 (setq txt (replace-match "" t t txt)))
2908 (push
2909 (format
2910 (if todo
2911 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2912 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2913 snumber txt) thetoc)
2915 (setq org-last-level level))
2917 line)
2918 lines))
2919 (while (> org-last-level (1- org-min-level))
2920 (setq org-last-level (1- org-last-level))
2921 (push "</li>\n</ul>\n" thetoc))
2922 (push "</div>\n" thetoc)
2923 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2925 (setq head-count 0)
2926 (org-init-section-numbers)
2928 (while (setq line (pop lines) origline line)
2929 (catch 'nextline
2931 ;; end of quote section?
2932 (when (and inquote (string-match "^\\*+ " line))
2933 (insert "</pre>\n")
2934 (setq inquote nil))
2935 ;; inside a quote section?
2936 (when inquote
2937 (insert (org-html-protect line) "\n")
2938 (throw 'nextline nil))
2940 ;; Fixed-width, verbatim lines (examples)
2941 (when (and org-export-with-fixed-width
2942 (string-match "^[ \t]*:\\(.*\\)" line))
2943 (when (not infixed)
2944 (setq infixed t)
2945 (insert "<pre class=\"example\">\n"))
2946 (insert (org-html-protect (match-string 1 line)) "\n")
2947 (when (or (not lines)
2948 (not (string-match "^[ \t]*\\(:.*\\)"
2949 (car lines))))
2950 (setq infixed nil)
2951 (insert "</pre>\n"))
2952 (throw 'nextline nil))
2954 ;; Protected HTML
2955 (when (get-text-property 0 'org-protected line)
2956 (let (par)
2957 (when (re-search-backward
2958 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2959 (setq par (match-string 1))
2960 (replace-match "\\2\n"))
2961 (insert line "\n")
2962 (while (and lines
2963 (not (string-match "^[ \t]*:" (car lines)))
2964 (or (= (length (car lines)) 0)
2965 (get-text-property 0 'org-protected (car lines))))
2966 (insert (pop lines) "\n"))
2967 (and par (insert "<p>\n")))
2968 (throw 'nextline nil))
2970 ;; Horizontal line
2971 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2972 (insert "\n<hr/>\n")
2973 (throw 'nextline nil))
2975 ;; Blockquotes and verse
2976 (when (equal "ORG-BLOCKQUOTE-START" line)
2977 (insert "<blockquote>\n<p>\n")
2978 (throw 'nextline nil))
2979 (when (equal "ORG-BLOCKQUOTE-END" line)
2980 (insert "</p>\n</blockquote>\n")
2981 (throw 'nextline nil))
2982 (when (equal "ORG-VERSE-START" line)
2983 (insert "\n<p class=\"verse\">\n")
2984 (setq inverse t)
2985 (throw 'nextline nil))
2986 (when (equal "ORG-VERSE-END" line)
2987 (insert "</p>\n")
2988 (setq inverse nil)
2989 (throw 'nextline nil))
2990 (when inverse
2991 (setq i (org-get-string-indentation line))
2992 (if (> i 0)
2993 (setq line (concat (mapconcat 'identity
2994 (make-list (* 2 i) "\\nbsp") "")
2995 " " (org-trim line))))
2996 (setq line (concat line " \\\\")))
2998 ;; make targets to anchors
2999 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3000 (cond
3001 ((match-end 2)
3002 (setq line (replace-match
3003 (concat "@<a name=\""
3004 (org-solidify-link-text (match-string 1 line))
3005 "\">\\nbsp@</a>")
3006 t t line)))
3007 ((and org-export-with-toc (equal (string-to-char line) ?*))
3008 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3009 (setq line (replace-match
3010 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3011 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3012 t t line)))
3014 (setq line (replace-match
3015 (concat "@<a name=\""
3016 (org-solidify-link-text (match-string 1 line))
3017 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3018 t t line)))))
3020 (setq line (org-html-handle-time-stamps line))
3022 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3023 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3024 ;; Also handle sub_superscripts and checkboxes
3025 (or (string-match org-table-hline-regexp line)
3026 (setq line (org-html-expand line)))
3028 ;; Format the links
3029 (setq start 0)
3030 (while (string-match org-bracket-link-analytic-regexp line start)
3031 (setq start (match-beginning 0))
3032 (setq path (save-match-data (org-link-unescape
3033 (match-string 3 line))))
3034 (setq type (cond
3035 ((match-end 2) (match-string 2 line))
3036 ((save-match-data
3037 (or (file-name-absolute-p path)
3038 (string-match "^\\.\\.?/" path)))
3039 "file")
3040 (t "internal")))
3041 (setq path (org-extract-attributes path))
3042 (setq attr (org-attributes-to-string
3043 (get-text-property 0 'org-attributes path)))
3044 (setq desc1 (if (match-end 5) (match-string 5 line))
3045 desc2 (if (match-end 2) (concat type ":" path) path)
3046 descp (and desc1 (not (equal desc1 desc2)))
3047 desc (or desc1 desc2))
3048 ;; Make an image out of the description if that is so wanted
3049 (when (and descp (org-file-image-p desc))
3050 (save-match-data
3051 (if (string-match "^file:" desc)
3052 (setq desc (substring desc (match-end 0)))))
3053 (setq desc (concat "<img src=\"" desc "\"/>")))
3054 ;; FIXME: do we need to unescape here somewhere?
3055 (cond
3056 ((equal type "internal")
3057 (setq rpl
3058 (concat
3059 "<a href=\"#"
3060 (org-solidify-link-text
3061 (save-match-data (org-link-unescape path)) nil)
3062 "\"" attr ">" desc "</a>")))
3063 ((member type '("http" "https"))
3064 ;; standard URL, just check if we need to inline an image
3065 (if (and (or (eq t org-export-html-inline-images)
3066 (and org-export-html-inline-images (not descp)))
3067 (org-file-image-p path))
3068 (setq rpl (concat "<img src=\"" type ":" path "\"" attr "/>"))
3069 (setq link (concat type ":" path))
3070 (setq rpl (concat "<a href=\"" link "\"" attr ">"
3071 desc "</a>"))))
3072 ((member type '("ftp" "mailto" "news"))
3073 ;; standard URL
3074 (setq link (concat type ":" path))
3075 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
3077 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3078 ;; The link protocol has a function for format the link
3079 (setq rpl
3080 (save-match-data
3081 (funcall fnc (org-link-unescape path) desc1 'html))))
3083 ((string= type "file")
3084 ;; FILE link
3085 (let* ((filename path)
3086 (abs-p (file-name-absolute-p filename))
3087 thefile file-is-image-p search)
3088 (save-match-data
3089 (if (string-match "::\\(.*\\)" filename)
3090 (setq search (match-string 1 filename)
3091 filename (replace-match "" t nil filename)))
3092 (setq valid
3093 (if (functionp link-validate)
3094 (funcall link-validate filename current-dir)
3096 (setq file-is-image-p (org-file-image-p filename))
3097 (setq thefile (if abs-p (expand-file-name filename) filename))
3098 (when (and org-export-html-link-org-files-as-html
3099 (string-match "\\.org$" thefile))
3100 (setq thefile (concat (substring thefile 0
3101 (match-beginning 0))
3102 "." html-extension))
3103 (if (and search
3104 ;; make sure this is can be used as target search
3105 (not (string-match "^[0-9]*$" search))
3106 (not (string-match "^\\*" search))
3107 (not (string-match "^/.*/$" search)))
3108 (setq thefile (concat thefile "#"
3109 (org-solidify-link-text
3110 (org-link-unescape search)))))
3111 (when (string-match "^file:" desc)
3112 (setq desc (replace-match "" t t desc))
3113 (if (string-match "\\.org$" desc)
3114 (setq desc (replace-match "" t t desc))))))
3115 (setq rpl (if (and file-is-image-p
3116 (or (eq t org-export-html-inline-images)
3117 (and org-export-html-inline-images
3118 (not descp))))
3119 (concat "<img src=\"" thefile "\"" attr "/>")
3120 (concat "<a href=\"" thefile "\"" attr ">"
3121 desc "</a>")))
3122 (if (not valid) (setq rpl desc))))
3125 ;; just publish the path, as default
3126 (setq rpl (concat "<i>&lt;" type ":"
3127 (save-match-data (org-link-unescape path))
3128 "&gt;</i>"))))
3129 (setq line (replace-match rpl t t line)
3130 start (+ start (length rpl))))
3132 ;; TODO items
3133 (if (and (string-match org-todo-line-regexp line)
3134 (match-beginning 2))
3136 (setq line
3137 (concat (substring line 0 (match-beginning 2))
3138 "<span class=\""
3139 (if (member (match-string 2 line)
3140 org-done-keywords)
3141 "done" "todo")
3142 "\">" (match-string 2 line)
3143 "</span>" (substring line (match-end 2)))))
3145 ;; Does this contain a reference to a footnote?
3146 (when org-export-with-footnotes
3147 (setq start 0)
3148 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3149 (if (get-text-property (match-beginning 2) 'org-protected line)
3150 (setq start (match-end 2))
3151 (let ((n (match-string 2 line)))
3152 (setq line
3153 (replace-match
3154 (format
3155 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3156 (match-string 1 line) n n n)
3157 t t line))))))
3159 (cond
3160 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3161 ;; This is a headline
3162 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3163 txt (match-string 2 line))
3164 (if (string-match quote-re0 txt)
3165 (setq txt (replace-match "" t t txt)))
3166 (if (<= level (max umax umax-toc))
3167 (setq head-count (+ head-count 1)))
3168 (when in-local-list
3169 ;; Close any local lists before inserting a new header line
3170 (while local-list-type
3171 (org-close-li (car local-list-type))
3172 (insert (format "</%sl>\n" (car local-list-type)))
3173 (pop local-list-type))
3174 (setq local-list-indent nil
3175 in-local-list nil))
3176 (setq first-heading-pos (or first-heading-pos (point)))
3177 (org-html-level-start level txt umax
3178 (and org-export-with-toc (<= level umax))
3179 head-count)
3180 ;; QUOTES
3181 (when (string-match quote-re line)
3182 (insert "<pre>")
3183 (setq inquote t)))
3185 ((and org-export-with-tables
3186 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3187 (if (not table-open)
3188 ;; New table starts
3189 (setq table-open t table-buffer nil table-orig-buffer nil))
3190 ;; Accumulate lines
3191 (setq table-buffer (cons line table-buffer)
3192 table-orig-buffer (cons origline table-orig-buffer))
3193 (when (or (not lines)
3194 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3195 (car lines))))
3196 (setq table-open nil
3197 table-buffer (nreverse table-buffer)
3198 table-orig-buffer (nreverse table-orig-buffer))
3199 (org-close-par-maybe)
3200 (insert (org-format-table-html table-buffer table-orig-buffer))))
3202 ;; Normal lines
3203 (when (string-match
3204 (cond
3205 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3206 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3207 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3208 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3209 line)
3210 (setq ind (org-get-string-indentation line)
3211 item-type (if (match-beginning 4) "o" "u")
3212 starter (if (match-beginning 2)
3213 (substring (match-string 2 line) 0 -1))
3214 line (substring line (match-beginning 5))
3215 item-tag nil)
3216 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3217 (setq item-type "d"
3218 item-tag (match-string 1 line)
3219 line (substring line (match-end 0))))
3220 (when (and (not (equal item-type "d"))
3221 (not (string-match "[^ \t]" line)))
3222 ;; empty line. Pretend indentation is large.
3223 (setq ind (if org-empty-line-terminates-plain-lists
3225 (1+ (or (car local-list-indent) 1)))))
3226 (setq didclose nil)
3227 (while (and in-local-list
3228 (or (and (= ind (car local-list-indent))
3229 (not starter))
3230 (< ind (car local-list-indent))))
3231 (setq didclose t)
3232 (org-close-li (car local-list-type))
3233 (insert (format "</%sl>\n" (car local-list-type)))
3234 (pop local-list-type) (pop local-list-indent)
3235 (setq in-local-list local-list-indent))
3236 (cond
3237 ((and starter
3238 (or (not in-local-list)
3239 (> ind (car local-list-indent))))
3240 ;; Start new (level of) list
3241 (org-close-par-maybe)
3242 (insert (cond
3243 ((equal item-type "u") "<ul>\n<li>\n")
3244 ((equal item-type "o") "<ol>\n<li>\n")
3245 ((equal item-type "d")
3246 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3247 (push item-type local-list-type)
3248 (push ind local-list-indent)
3249 (setq in-local-list t))
3250 (starter
3251 ;; continue current list
3252 (org-close-li (car local-list-type))
3253 (insert (cond
3254 ((equal (car local-list-type) "d")
3255 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3256 (t "<li>\n"))))
3257 (didclose
3258 ;; we did close a list, normal text follows: need <p>
3259 (org-open-par)))
3260 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3261 (setq line
3262 (replace-match
3263 (if (equal (match-string 1 line) "X")
3264 "<b>[X]</b>"
3265 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3266 t t line))))
3268 ;; Empty lines start a new paragraph. If hand-formatted lists
3269 ;; are not fully interpreted, lines starting with "-", "+", "*"
3270 ;; also start a new paragraph.
3271 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3273 ;; Is this the start of a footnote?
3274 (when org-export-with-footnotes
3275 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3276 (org-close-par-maybe)
3277 (let ((n (match-string 1 line)))
3278 (setq line (replace-match
3279 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3280 (setq line (concat line "</p>")))))
3282 ;; Check if the line break needs to be conserved
3283 (cond
3284 ((string-match "\\\\\\\\[ \t]*$" line)
3285 (setq line (replace-match "<br/>" t t line)))
3286 (org-export-preserve-breaks
3287 (setq line (concat line "<br/>"))))
3289 (insert line "\n")))))
3291 ;; Properly close all local lists and other lists
3292 (when inquote (insert "</pre>\n"))
3293 (when in-local-list
3294 ;; Close any local lists before inserting a new header line
3295 (while local-list-type
3296 (org-close-li (car local-list-type))
3297 (insert (format "</%sl>\n" (car local-list-type)))
3298 (pop local-list-type))
3299 (setq local-list-indent nil
3300 in-local-list nil))
3301 (org-html-level-start 1 nil umax
3302 (and org-export-with-toc (<= level umax))
3303 head-count)
3304 ;; the </div> to lose the last text-... div.
3305 (insert "</div>\n")
3307 (unless body-only
3308 (when (plist-get opt-plist :auto-postamble)
3309 (insert "<div id=\"postamble\">")
3310 (when (and org-export-author-info author)
3311 (insert "<p class=\"author\"> "
3312 (nth 1 lang-words) ": " author "\n")
3313 (when email
3314 (if (listp (split-string email ",+ *"))
3315 (mapc (lambda(e)
3316 (insert "<a href=\"mailto:" e "\">&lt;"
3317 e "&gt;</a>\n"))
3318 (split-string email ",+ *"))
3319 (insert "<a href=\"mailto:" email "\">&lt;"
3320 email "&gt;</a>\n")))
3321 (insert "</p>\n"))
3322 (when (and date org-export-time-stamp-file)
3323 (insert "<p class=\"date\"> "
3324 (nth 2 lang-words) ": "
3325 date "</p>\n"))
3326 (when org-export-creator-info
3327 (insert (format "<p>HTML generated by org-mode %s in emacs %s<\p>\n"
3328 org-version emacs-major-version)))
3329 (insert "</div>"))
3331 (if org-export-html-with-timestamp
3332 (insert org-export-html-html-helper-timestamp))
3333 (insert (or (plist-get opt-plist :postamble) ""))
3334 (insert "</body>\n</html>\n"))
3336 (normal-mode)
3337 (if (eq major-mode default-major-mode) (html-mode))
3339 ;; insert the table of contents
3340 (goto-char (point-min))
3341 (when thetoc
3342 (if (or (re-search-forward
3343 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3344 (re-search-forward
3345 "\\[TABLE-OF-CONTENTS\\]" nil t))
3346 (progn
3347 (goto-char (match-beginning 0))
3348 (replace-match ""))
3349 (goto-char first-heading-pos)
3350 (when (looking-at "\\s-*</p>")
3351 (goto-char (match-end 0))
3352 (insert "\n")))
3353 (insert "<div id=\"table-of-contents\">\n")
3354 (mapc 'insert thetoc)
3355 (insert "</div>\n"))
3356 ;; remove empty paragraphs and lists
3357 (goto-char (point-min))
3358 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3359 (replace-match ""))
3360 (goto-char (point-min))
3361 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3362 (replace-match ""))
3363 (goto-char (point-min))
3364 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3365 (replace-match ""))
3366 ;; Convert whitespace place holders
3367 (goto-char (point-min))
3368 (let (beg end n)
3369 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3370 (setq n (get-text-property beg 'org-whitespace)
3371 end (next-single-property-change beg 'org-whitespace))
3372 (goto-char beg)
3373 (delete-region beg end)
3374 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3375 (make-string n ?x)))))
3376 (or to-buffer (save-buffer))
3377 (goto-char (point-min))
3378 (message "Exporting... done")
3379 (if (eq to-buffer 'string)
3380 (prog1 (buffer-substring (point-min) (point-max))
3381 (kill-buffer (current-buffer)))
3382 (current-buffer)))))
3385 (defvar org-table-colgroup-info nil)
3386 (defun org-format-table-ascii (lines)
3387 "Format a table for ascii export."
3388 (if (stringp lines)
3389 (setq lines (org-split-string lines "\n")))
3390 (if (not (string-match "^[ \t]*|" (car lines)))
3391 ;; Table made by table.el - test for spanning
3392 lines
3394 ;; A normal org table
3395 ;; Get rid of hlines at beginning and end
3396 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3397 (setq lines (nreverse lines))
3398 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3399 (setq lines (nreverse lines))
3400 (when org-export-table-remove-special-lines
3401 ;; Check if the table has a marking column. If yes remove the
3402 ;; column and the special lines
3403 (setq lines (org-table-clean-before-export lines)))
3404 ;; Get rid of the vertical lines except for grouping
3405 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3406 rtn line vl1 start)
3407 (while (setq line (pop lines))
3408 (if (string-match org-table-hline-regexp line)
3409 (and (string-match "|\\(.*\\)|" line)
3410 (setq line (replace-match " \\1" t nil line)))
3411 (setq start 0 vl1 vl)
3412 (while (string-match "|" line start)
3413 (setq start (match-end 0))
3414 (or (pop vl1) (setq line (replace-match " " t t line)))))
3415 (push line rtn))
3416 (nreverse rtn))))
3418 (defun org-colgroup-info-to-vline-list (info)
3419 (let (vl new last)
3420 (while info
3421 (setq last new new (pop info))
3422 (if (or (memq last '(:end :startend))
3423 (memq new '(:start :startend)))
3424 (push t vl)
3425 (push nil vl)))
3426 (setq vl (nreverse vl))
3427 (and vl (setcar vl nil))
3428 vl))
3430 (defvar org-table-number-regexp) ; defined in org-table.el
3431 (defun org-format-table-html (lines olines)
3432 "Find out which HTML converter to use and return the HTML code."
3433 (if (stringp lines)
3434 (setq lines (org-split-string lines "\n")))
3435 (if (string-match "^[ \t]*|" (car lines))
3436 ;; A normal org table
3437 (org-format-org-table-html lines)
3438 ;; Table made by table.el - test for spanning
3439 (let* ((hlines (delq nil (mapcar
3440 (lambda (x)
3441 (if (string-match "^[ \t]*\\+-" x) x
3442 nil))
3443 lines)))
3444 (first (car hlines))
3445 (ll (and (string-match "\\S-+" first)
3446 (match-string 0 first)))
3447 (re (concat "^[ \t]*" (regexp-quote ll)))
3448 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3449 hlines))))
3450 (if (and (not spanning)
3451 (not org-export-prefer-native-exporter-for-tables))
3452 ;; We can use my own converter with HTML conversions
3453 (org-format-table-table-html lines)
3454 ;; Need to use the code generator in table.el, with the original text.
3455 (org-format-table-table-html-using-table-generate-source olines)))))
3457 (defvar org-table-number-fraction) ; defined in org-table.el
3458 (defun org-format-org-table-html (lines &optional splice)
3459 "Format a table into HTML."
3460 (require 'org-table)
3461 ;; Get rid of hlines at beginning and end
3462 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3463 (setq lines (nreverse lines))
3464 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3465 (setq lines (nreverse lines))
3466 (when org-export-table-remove-special-lines
3467 ;; Check if the table has a marking column. If yes remove the
3468 ;; column and the special lines
3469 (setq lines (org-table-clean-before-export lines)))
3471 (let ((head (and org-export-highlight-first-table-line
3472 (delq nil (mapcar
3473 (lambda (x) (string-match "^[ \t]*|-" x))
3474 (cdr lines)))))
3475 (nlines 0) fnum i
3476 tbopen line fields html gr colgropen)
3477 (if splice (setq head nil))
3478 (unless splice (push (if head "<thead>" "<tbody>") html))
3479 (setq tbopen t)
3480 (while (setq line (pop lines))
3481 (catch 'next-line
3482 (if (string-match "^[ \t]*|-" line)
3483 (progn
3484 (unless splice
3485 (push (if head "</thead>" "</tbody>") html)
3486 (if lines (push "<tbody>" html) (setq tbopen nil)))
3487 (setq head nil) ;; head ends here, first time around
3488 ;; ignore this line
3489 (throw 'next-line t)))
3490 ;; Break the line into fields
3491 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3492 (unless fnum (setq fnum (make-vector (length fields) 0)))
3493 (setq nlines (1+ nlines) i -1)
3494 (push (concat "<tr>"
3495 (mapconcat
3496 (lambda (x)
3497 (setq i (1+ i))
3498 (if (and (< i nlines)
3499 (string-match org-table-number-regexp x))
3500 (incf (aref fnum i)))
3501 (if head
3502 (concat (car org-export-table-header-tags) x
3503 (cdr org-export-table-header-tags))
3504 (concat (car org-export-table-data-tags) x
3505 (cdr org-export-table-data-tags))))
3506 fields "")
3507 "</tr>")
3508 html)))
3509 (unless splice (if tbopen (push "</tbody>" html)))
3510 (unless splice (push "</table>\n" html))
3511 (setq html (nreverse html))
3512 (unless splice
3513 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3514 (push (mapconcat
3515 (lambda (x)
3516 (setq gr (pop org-table-colgroup-info))
3517 (format "%s<col align=\"%s\"></col>%s"
3518 (if (memq gr '(:start :startend))
3519 (prog1
3520 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3521 (setq colgropen t))
3523 (if (> (/ (float x) nlines) org-table-number-fraction)
3524 "right" "left")
3525 (if (memq gr '(:end :startend))
3526 (progn (setq colgropen nil) "</colgroup>")
3527 "")))
3528 fnum "")
3529 html)
3530 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3531 (push html-table-tag html))
3532 (concat (mapconcat 'identity html "\n") "\n")))
3534 (defun org-table-clean-before-export (lines)
3535 "Check if the table has a marking column.
3536 If yes remove the column and the special lines."
3537 (setq org-table-colgroup-info nil)
3538 (if (memq nil
3539 (mapcar
3540 (lambda (x) (or (string-match "^[ \t]*|-" x)
3541 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3542 lines))
3543 (progn
3544 (setq org-table-clean-did-remove-column nil)
3545 (delq nil
3546 (mapcar
3547 (lambda (x)
3548 (cond
3549 ((string-match "^[ \t]*| */ *|" x)
3550 (setq org-table-colgroup-info
3551 (mapcar (lambda (x)
3552 (cond ((member x '("<" "&lt;")) :start)
3553 ((member x '(">" "&gt;")) :end)
3554 ((member x '("<>" "&lt;&gt;")) :startend)
3555 (t nil)))
3556 (org-split-string x "[ \t]*|[ \t]*")))
3557 nil)
3558 (t x)))
3559 lines)))
3560 (setq org-table-clean-did-remove-column t)
3561 (delq nil
3562 (mapcar
3563 (lambda (x)
3564 (cond
3565 ((string-match "^[ \t]*| */ *|" x)
3566 (setq org-table-colgroup-info
3567 (mapcar (lambda (x)
3568 (cond ((member x '("<" "&lt;")) :start)
3569 ((member x '(">" "&gt;")) :end)
3570 ((member x '("<>" "&lt;&gt;")) :startend)
3571 (t nil)))
3572 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3573 nil)
3574 ((string-match "^[ \t]*| *[!_^/] *|" x)
3575 nil) ; ignore this line
3576 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3577 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3578 ;; remove the first column
3579 (replace-match "\\1|" t nil x))))
3580 lines))))
3582 (defun org-format-table-table-html (lines)
3583 "Format a table generated by table.el into HTML.
3584 This conversion does *not* use `table-generate-source' from table.el.
3585 This has the advantage that Org-mode's HTML conversions can be used.
3586 But it has the disadvantage, that no cell- or row-spanning is allowed."
3587 (let (line field-buffer
3588 (head org-export-highlight-first-table-line)
3589 fields html empty)
3590 (setq html (concat html-table-tag "\n"))
3591 (while (setq line (pop lines))
3592 (setq empty "&nbsp;")
3593 (catch 'next-line
3594 (if (string-match "^[ \t]*\\+-" line)
3595 (progn
3596 (if field-buffer
3597 (progn
3598 (setq
3599 html
3600 (concat
3601 html
3602 "<tr>"
3603 (mapconcat
3604 (lambda (x)
3605 (if (equal x "") (setq x empty))
3606 (if head
3607 (concat (car org-export-table-header-tags) x
3608 (cdr org-export-table-header-tags))
3609 (concat (car org-export-table-data-tags) x
3610 (cdr org-export-table-data-tags))))
3611 field-buffer "\n")
3612 "</tr>\n"))
3613 (setq head nil)
3614 (setq field-buffer nil)))
3615 ;; Ignore this line
3616 (throw 'next-line t)))
3617 ;; Break the line into fields and store the fields
3618 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3619 (if field-buffer
3620 (setq field-buffer (mapcar
3621 (lambda (x)
3622 (concat x "<br/>" (pop fields)))
3623 field-buffer))
3624 (setq field-buffer fields))))
3625 (setq html (concat html "</table>\n"))
3626 html))
3628 (defun org-format-table-table-html-using-table-generate-source (lines)
3629 "Format a table into html, using `table-generate-source' from table.el.
3630 This has the advantage that cell- or row-spanning is allowed.
3631 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3632 (require 'table)
3633 (with-current-buffer (get-buffer-create " org-tmp1 ")
3634 (erase-buffer)
3635 (insert (mapconcat 'identity lines "\n"))
3636 (goto-char (point-min))
3637 (if (not (re-search-forward "|[^+]" nil t))
3638 (error "Error processing table"))
3639 (table-recognize-table)
3640 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3641 (table-generate-source 'html " org-tmp2 ")
3642 (set-buffer " org-tmp2 ")
3643 (buffer-substring (point-min) (point-max))))
3645 (defun org-export-splice-style (style extra)
3646 "Splice EXTRA into STYLE, just before \"</style>\"."
3647 (if (and (stringp extra)
3648 (string-match "\\S-" extra)
3649 (string-match "</style>" style))
3650 (concat (substring style 0 (match-beginning 0))
3651 "\n" extra "\n"
3652 (substring style (match-beginning 0)))
3653 style))
3655 (defun org-html-handle-time-stamps (s)
3656 "Format time stamps in string S, or remove them."
3657 (catch 'exit
3658 (let (r b)
3659 (while (string-match org-maybe-keyword-time-regexp s)
3660 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3661 ;; never export CLOCK
3662 (throw 'exit ""))
3663 (or b (setq b (substring s 0 (match-beginning 0))))
3664 (if (not org-export-with-timestamps)
3665 (setq r (concat r (substring s 0 (match-beginning 0)))
3666 s (substring s (match-end 0)))
3667 (setq r (concat
3668 r (substring s 0 (match-beginning 0))
3669 (if (match-end 1)
3670 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3671 (match-string 1 s)))
3672 (format " @<span class=\"timestamp\">%s@</span>"
3673 (substring
3674 (org-translate-time (match-string 3 s)) 1 -1)))
3675 s (substring s (match-end 0)))))
3676 ;; Line break if line started and ended with time stamp stuff
3677 (if (not r)
3679 (setq r (concat r s))
3680 (unless (string-match "\\S-" (concat b s))
3681 (setq r (concat r "@<br/>")))
3682 r))))
3684 (defun org-export-htmlize-region-for-paste (beg end)
3685 "Convert the region to HTML, using htmlize.el.
3686 This is much like `htmlize-region-for-paste', only that it uses
3687 the settings define in the org-... variables."
3688 (let* ((htmlize-output-type org-export-htmlize-output-type)
3689 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3690 (htmlbuf (htmlize-region beg end)))
3691 (unwind-protect
3692 (with-current-buffer htmlbuf
3693 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3694 (plist-get htmlize-buffer-places 'content-end)))
3695 (kill-buffer htmlbuf))))
3697 ;;;###autoload
3698 (defun org-export-htmlize-generate-css ()
3699 "Create the CSS for all font definitions in the current Emacs session.
3700 Use this to create face definitions in your CSS style file that can then
3701 be used by code snippets transformed by htmlize.
3702 This command just produces a buffer that contains class definitions for all
3703 faces used in the current Emacs session. You can copy and paste the ones you
3704 need into your CSS file.
3706 If you then set `org-export-htmlize-output-type' to `css', calls to
3707 the function `org-export-htmlize-region-for-paste' will produce code
3708 that uses these same face definitions."
3709 (interactive)
3710 (require 'htmlize)
3711 (and (get-buffer "*html*") (kill-buffer "*html*"))
3712 (with-temp-buffer
3713 (let ((fl (face-list))
3714 (htmlize-css-name-prefix "org-")
3715 (htmlize-output-type 'css)
3716 f i)
3717 (while (setq f (pop fl)
3718 i (and f (face-attribute f :inherit)))
3719 (when (and (symbolp f) (or (not i) (not (listp i))))
3720 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3721 (htmlize-region (point-min) (point-max))))
3722 (switch-to-buffer "*html*")
3723 (goto-char (point-min))
3724 (if (re-search-forward "<style" nil t)
3725 (delete-region (point-min) (match-beginning 0)))
3726 (if (re-search-forward "</style>" nil t)
3727 (delete-region (1+ (match-end 0)) (point-max)))
3728 (beginning-of-line 1)
3729 (if (looking-at " +") (replace-match ""))
3730 (goto-char (point-min)))
3732 (defun org-html-protect (s)
3733 ;; convert & to &amp;, < to &lt; and > to &gt;
3734 (let ((start 0))
3735 (while (string-match "&" s start)
3736 (setq s (replace-match "&amp;" t t s)
3737 start (1+ (match-beginning 0))))
3738 (while (string-match "<" s)
3739 (setq s (replace-match "&lt;" t t s)))
3740 (while (string-match ">" s)
3741 (setq s (replace-match "&gt;" t t s))))
3744 (defun org-export-cleanup-toc-line (s)
3745 "Remove tags and time staps from lines going into the toc."
3746 (when (memq org-export-with-tags '(not-in-toc nil))
3747 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3748 (setq s (replace-match "" t t s))))
3749 (when org-export-remove-timestamps-from-toc
3750 (while (string-match org-maybe-keyword-time-regexp s)
3751 (setq s (replace-match "" t t s))))
3752 (while (string-match org-bracket-link-regexp s)
3753 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3754 t t s)))
3757 (defun org-html-expand (string)
3758 "Prepare STRING for HTML export. Applies all active conversions.
3759 If there are links in the string, don't modify these."
3760 (let* ((re (concat org-bracket-link-regexp "\\|"
3761 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3762 m s l res)
3763 (while (setq m (string-match re string))
3764 (setq s (substring string 0 m)
3765 l (match-string 0 string)
3766 string (substring string (match-end 0)))
3767 (push (org-html-do-expand s) res)
3768 (push l res))
3769 (push (org-html-do-expand string) res)
3770 (apply 'concat (nreverse res))))
3772 (defun org-html-do-expand (s)
3773 "Apply all active conversions to translate special ASCII to HTML."
3774 (setq s (org-html-protect s))
3775 (if org-export-html-expand
3776 (let ((start 0))
3777 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3778 (setq s (replace-match "<\\1>" t nil s)))))
3779 (if org-export-with-emphasize
3780 (setq s (org-export-html-convert-emphasize s)))
3781 (if org-export-with-special-strings
3782 (setq s (org-export-html-convert-special-strings s)))
3783 (if org-export-with-sub-superscripts
3784 (setq s (org-export-html-convert-sub-super s)))
3785 (if org-export-with-TeX-macros
3786 (let ((start 0) wd ass)
3787 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3788 (if (get-text-property (match-beginning 0) 'org-protected s)
3789 (setq start (match-end 0))
3790 (setq wd (match-string 1 s))
3791 (if (setq ass (assoc wd org-html-entities))
3792 (setq s (replace-match (or (cdr ass)
3793 (concat "&" (car ass) ";"))
3794 t t s))
3795 (setq start (+ start (length wd))))))))
3798 (defun org-create-multibrace-regexp (left right n)
3799 "Create a regular expression which will match a balanced sexp.
3800 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3801 as single character strings.
3802 The regexp returned will match the entire expression including the
3803 delimiters. It will also define a single group which contains the
3804 match except for the outermost delimiters. The maximum depth of
3805 stacked delimiters is N. Escaping delimiters is not possible."
3806 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3807 (or "\\|")
3808 (re nothing)
3809 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3810 (while (> n 1)
3811 (setq n (1- n)
3812 re (concat re or next)
3813 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3814 (concat left "\\(" re "\\)" right)))
3816 (defvar org-match-substring-regexp
3817 (concat
3818 "\\([^\\]\\)\\([_^]\\)\\("
3819 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3820 "\\|"
3821 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3822 "\\|"
3823 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3824 "The regular expression matching a sub- or superscript.")
3826 (defvar org-match-substring-with-braces-regexp
3827 (concat
3828 "\\([^\\]\\)\\([_^]\\)\\("
3829 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3830 "\\)")
3831 "The regular expression matching a sub- or superscript, forcing braces.")
3833 (defconst org-export-html-special-string-regexps
3834 '(("\\\\-" . "&shy;")
3835 ("---\\([^-]\\)" . "&mdash;\\1")
3836 ("--\\([^-]\\)" . "&ndash;\\1")
3837 ("\\.\\.\\." . "&hellip;"))
3838 "Regular expressions for special string conversion.")
3840 (defun org-export-html-convert-special-strings (string)
3841 "Convert special characters in STRING to HTML."
3842 (let ((all org-export-html-special-string-regexps)
3843 e a re rpl start)
3844 (while (setq a (pop all))
3845 (setq re (car a) rpl (cdr a) start 0)
3846 (while (string-match re string start)
3847 (if (get-text-property (match-beginning 0) 'org-protected string)
3848 (setq start (match-end 0))
3849 (setq string (replace-match rpl t nil string)))))
3850 string))
3852 (defun org-export-html-convert-sub-super (string)
3853 "Convert sub- and superscripts in STRING to HTML."
3854 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3855 (while (string-match org-match-substring-regexp string s)
3856 (cond
3857 ((and requireb (match-end 8)) (setq s (match-end 2)))
3858 ((get-text-property (match-beginning 2) 'org-protected string)
3859 (setq s (match-end 2)))
3861 (setq s (match-end 1)
3862 key (if (string= (match-string 2 string) "_") "sub" "sup")
3863 c (or (match-string 8 string)
3864 (match-string 6 string)
3865 (match-string 5 string))
3866 string (replace-match
3867 (concat (match-string 1 string)
3868 "<" key ">" c "</" key ">")
3869 t t string)))))
3870 (while (string-match "\\\\\\([_^]\\)" string)
3871 (setq string (replace-match (match-string 1 string) t t string)))
3872 string))
3874 (defun org-export-html-convert-emphasize (string)
3875 "Apply emphasis."
3876 (let ((s 0) rpl)
3877 (while (string-match org-emph-re string s)
3878 (if (not (equal
3879 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3880 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3881 (setq s (match-beginning 0)
3883 (concat
3884 (match-string 1 string)
3885 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3886 (match-string 4 string)
3887 (nth 3 (assoc (match-string 3 string)
3888 org-emphasis-alist))
3889 (match-string 5 string))
3890 string (replace-match rpl t t string)
3891 s (+ s (- (length rpl) 2)))
3892 (setq s (1+ s))))
3893 string))
3895 (defvar org-par-open nil)
3896 (defun org-open-par ()
3897 "Insert <p>, but first close previous paragraph if any."
3898 (org-close-par-maybe)
3899 (insert "\n<p>")
3900 (setq org-par-open t))
3901 (defun org-close-par-maybe ()
3902 "Close paragraph if there is one open."
3903 (when org-par-open
3904 (insert "</p>")
3905 (setq org-par-open nil)))
3906 (defun org-close-li (&optional type)
3907 "Close <li> if necessary."
3908 (org-close-par-maybe)
3909 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
3911 (defvar body-only) ; dynamically scoped into this.
3912 (defun org-html-level-start (level title umax with-toc head-count)
3913 "Insert a new level in HTML export.
3914 When TITLE is nil, just close all open levels."
3915 (org-close-par-maybe)
3916 (let ((target (and title (org-get-text-property-any 0 'target title)))
3917 (l org-level-max)
3918 snumber)
3919 (while (>= l level)
3920 (if (aref org-levels-open (1- l))
3921 (progn
3922 (org-html-level-close l umax)
3923 (aset org-levels-open (1- l) nil)))
3924 (setq l (1- l)))
3925 (when title
3926 ;; If title is nil, this means this function is called to close
3927 ;; all levels, so the rest is done only if title is given
3928 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3929 (setq title (replace-match
3930 (if org-export-with-tags
3931 (save-match-data
3932 (concat
3933 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3934 (mapconcat 'identity (org-split-string
3935 (match-string 1 title) ":")
3936 "&nbsp;")
3937 "</span>"))
3939 t t title)))
3940 (if (> level umax)
3941 (progn
3942 (if (aref org-levels-open (1- level))
3943 (progn
3944 (org-close-li)
3945 (if target
3946 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3947 (insert "<li>" title "<br/>\n")))
3948 (aset org-levels-open (1- level) t)
3949 (org-close-par-maybe)
3950 (if target
3951 (insert (format "<ul>\n<li id=\"%s\">" target)
3952 title "<br/>\n")
3953 (insert "<ul>\n<li>" title "<br/>\n"))))
3954 (aset org-levels-open (1- level) t)
3955 (setq snumber (org-section-number level))
3956 (if (and org-export-with-section-numbers (not body-only))
3957 (setq title (concat snumber " " title)))
3958 (setq level (+ level org-export-html-toplevel-hlevel -1))
3959 (unless (= head-count 1) (insert "\n</div>\n"))
3960 (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"
3961 snumber level level snumber title level snumber))
3962 (org-open-par)))))
3964 (defun org-get-text-property-any (pos prop &optional object)
3965 (or (get-text-property pos prop object)
3966 (and (setq pos (next-single-property-change pos prop object))
3967 (get-text-property pos prop object))))
3969 (defun org-html-level-close (level max-outline-level)
3970 "Terminate one level in HTML export."
3971 (if (<= level max-outline-level)
3972 (insert "</div>\n")
3973 (org-close-li)
3974 (insert "</ul>\n")))
3976 ;;; iCalendar export
3978 ;;;###autoload
3979 (defun org-export-icalendar-this-file ()
3980 "Export current file as an iCalendar file.
3981 The iCalendar file will be located in the same directory as the Org-mode
3982 file, but with extension `.ics'."
3983 (interactive)
3984 (org-export-icalendar nil buffer-file-name))
3986 ;;;###autoload
3987 (defun org-export-icalendar-all-agenda-files ()
3988 "Export all files in `org-agenda-files' to iCalendar .ics files.
3989 Each iCalendar file will be located in the same directory as the Org-mode
3990 file, but with extension `.ics'."
3991 (interactive)
3992 (apply 'org-export-icalendar nil (org-agenda-files t)))
3994 ;;;###autoload
3995 (defun org-export-icalendar-combine-agenda-files ()
3996 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3997 The file is stored under the name `org-combined-agenda-icalendar-file'."
3998 (interactive)
3999 (apply 'org-export-icalendar t (org-agenda-files t)))
4001 (defun org-export-icalendar (combine &rest files)
4002 "Create iCalendar files for all elements of FILES.
4003 If COMBINE is non-nil, combine all calendar entries into a single large
4004 file and store it under the name `org-combined-agenda-icalendar-file'."
4005 (save-excursion
4006 (org-prepare-agenda-buffers files)
4007 (let* ((dir (org-export-directory
4008 :ical (list :publishing-directory
4009 org-export-publishing-directory)))
4010 file ical-file ical-buffer category started org-agenda-new-buffers)
4011 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4012 (when combine
4013 (setq ical-file
4014 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4015 org-combined-agenda-icalendar-file
4016 (expand-file-name org-combined-agenda-icalendar-file dir))
4017 ical-buffer (org-get-agenda-file-buffer ical-file))
4018 (set-buffer ical-buffer) (erase-buffer))
4019 (while (setq file (pop files))
4020 (catch 'nextfile
4021 (org-check-agenda-file file)
4022 (set-buffer (org-get-agenda-file-buffer file))
4023 (unless combine
4024 (setq ical-file (concat (file-name-as-directory dir)
4025 (file-name-sans-extension
4026 (file-name-nondirectory buffer-file-name))
4027 ".ics"))
4028 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4029 (with-current-buffer ical-buffer (erase-buffer)))
4030 (setq category (or org-category
4031 (file-name-sans-extension
4032 (file-name-nondirectory buffer-file-name))))
4033 (if (symbolp category) (setq category (symbol-name category)))
4034 (let ((standard-output ical-buffer))
4035 (if combine
4036 (and (not started) (setq started t)
4037 (org-start-icalendar-file org-icalendar-combined-name))
4038 (org-start-icalendar-file category))
4039 (org-print-icalendar-entries combine)
4040 (when (or (and combine (not files)) (not combine))
4041 (org-finish-icalendar-file)
4042 (set-buffer ical-buffer)
4043 (run-hooks 'org-before-save-iCalendar-file-hook)
4044 (save-buffer)
4045 (run-hooks 'org-after-save-iCalendar-file-hook)
4046 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4047 ))))
4048 (org-release-buffers org-agenda-new-buffers))))
4050 (defvar org-before-save-iCalendar-file-hook nil
4051 "Hook run before an iCalendar file has been saved.
4052 This can be used to modify the result of the export.")
4054 (defvar org-after-save-iCalendar-file-hook nil
4055 "Hook run after an iCalendar file has been saved.
4056 The iCalendar buffer is still current when this hook is run.
4057 A good way to use this is to tell a desktop calenndar application to re-read
4058 the iCalendar file.")
4060 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4061 (defun org-print-icalendar-entries (&optional combine)
4062 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4063 When COMBINE is non nil, add the category to each line."
4064 (require 'org-agenda)
4065 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4066 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4067 (dts (org-ical-ts-to-string
4068 (format-time-string (cdr org-time-stamp-formats) (current-time))
4069 "DTSTART"))
4070 hd ts ts2 state status (inc t) pos b sexp rrule
4071 scheduledp deadlinep todo prefix due start
4072 tmp pri category entry location summary desc uid
4073 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4074 (org-refresh-category-properties)
4075 (save-excursion
4076 (goto-char (point-min))
4077 (while (re-search-forward re1 nil t)
4078 (catch :skip
4079 (org-agenda-skip)
4080 (when (boundp 'org-icalendar-verify-function)
4081 (unless (funcall org-icalendar-verify-function)
4082 (outline-next-heading)
4083 (backward-char 1)
4084 (throw :skip nil)))
4085 (setq pos (match-beginning 0)
4086 ts (match-string 0)
4087 inc t
4088 hd (condition-case nil
4089 (org-icalendar-cleanup-string
4090 (org-get-heading))
4091 (error (throw :skip nil)))
4092 summary (org-icalendar-cleanup-string
4093 (org-entry-get nil "SUMMARY"))
4094 desc (org-icalendar-cleanup-string
4095 (or (org-entry-get nil "DESCRIPTION")
4096 (and org-icalendar-include-body (org-get-entry)))
4097 t org-icalendar-include-body)
4098 location (org-icalendar-cleanup-string
4099 (org-entry-get nil "LOCATION"))
4100 uid (if org-icalendar-store-UID
4101 (org-id-get-create)
4102 (or (org-id-get) (org-id-new)))
4103 category (org-get-category)
4104 deadlinep nil scheduledp nil)
4105 (if (looking-at re2)
4106 (progn
4107 (goto-char (match-end 0))
4108 (setq ts2 (match-string 1)
4109 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4110 (setq tmp (buffer-substring (max (point-min)
4111 (- pos org-ds-keyword-length))
4112 pos)
4113 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4114 (progn
4115 (setq inc nil)
4116 (replace-match "\\1" t nil ts))
4118 deadlinep (string-match org-deadline-regexp tmp)
4119 scheduledp (string-match org-scheduled-regexp tmp)
4120 todo (org-get-todo-state)
4121 ;; donep (org-entry-is-done-p)
4123 (when (and
4124 deadlinep
4125 (if todo
4126 (not (memq 'event-if-todo org-icalendar-use-deadline))
4127 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4128 (throw :skip t))
4129 (when (and
4130 scheduledp
4131 (if todo
4132 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4133 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4134 (throw :skip t))
4135 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4136 (if (or (string-match org-tr-regexp hd)
4137 (string-match org-ts-regexp hd))
4138 (setq hd (replace-match "" t t hd)))
4139 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4140 (setq rrule
4141 (concat "\nRRULE:FREQ="
4142 (cdr (assoc
4143 (match-string 2 ts)
4144 '(("d" . "DAILY")("w" . "WEEKLY")
4145 ("m" . "MONTHLY")("y" . "YEARLY"))))
4146 ";INTERVAL=" (match-string 1 ts)))
4147 (setq rrule ""))
4148 (setq summary (or summary hd))
4149 (if (string-match org-bracket-link-regexp summary)
4150 (setq summary
4151 (replace-match (if (match-end 3)
4152 (match-string 3 summary)
4153 (match-string 1 summary))
4154 t t summary)))
4155 (if deadlinep (setq summary (concat "DL: " summary)))
4156 (if scheduledp (setq summary (concat "S: " summary)))
4157 (if (string-match "\\`<%%" ts)
4158 (with-current-buffer sexp-buffer
4159 (insert (substring ts 1 -1) " " summary "\n"))
4160 (princ (format "BEGIN:VEVENT
4161 UID: %s
4163 %s%s
4164 SUMMARY:%s%s%s
4165 CATEGORIES:%s
4166 END:VEVENT\n"
4167 (concat prefix uid)
4168 (org-ical-ts-to-string ts "DTSTART")
4169 (org-ical-ts-to-string ts2 "DTEND" inc)
4170 rrule summary
4171 (if (and desc (string-match "\\S-" desc))
4172 (concat "\nDESCRIPTION: " desc) "")
4173 (if (and location (string-match "\\S-" location))
4174 (concat "\nLOCATION: " location) "")
4175 category)))))
4176 (when (and org-icalendar-include-sexps
4177 (condition-case nil (require 'icalendar) (error nil))
4178 (fboundp 'icalendar-export-region))
4179 ;; Get all the literal sexps
4180 (goto-char (point-min))
4181 (while (re-search-forward "^&?%%(" nil t)
4182 (catch :skip
4183 (org-agenda-skip)
4184 (setq b (match-beginning 0))
4185 (goto-char (1- (match-end 0)))
4186 (forward-sexp 1)
4187 (end-of-line 1)
4188 (setq sexp (buffer-substring b (point)))
4189 (with-current-buffer sexp-buffer
4190 (insert sexp "\n"))))
4191 (princ (org-diary-to-ical-string sexp-buffer))
4192 (kill-buffer sexp-buffer))
4194 (when org-icalendar-include-todo
4195 (setq prefix "TODO-")
4196 (goto-char (point-min))
4197 (while (re-search-forward org-todo-line-regexp nil t)
4198 (catch :skip
4199 (org-agenda-skip)
4200 (when (boundp 'org-icalendar-verify-function)
4201 (unless (funcall org-icalendar-verify-function)
4202 (outline-next-heading)
4203 (backward-char 1)
4204 (throw :skip nil)))
4205 (setq state (match-string 2))
4206 (setq status (if (member state org-done-keywords)
4207 "COMPLETED" "NEEDS-ACTION"))
4208 (when (and state
4209 (or (not (member state org-done-keywords))
4210 (eq org-icalendar-include-todo 'all))
4211 (not (member org-archive-tag (org-get-tags-at)))
4213 (setq hd (match-string 3)
4214 summary (org-icalendar-cleanup-string
4215 (org-entry-get nil "SUMMARY"))
4216 desc (org-icalendar-cleanup-string
4217 (or (org-entry-get nil "DESCRIPTION")
4218 (and org-icalendar-include-body (org-get-entry)))
4219 t org-icalendar-include-body)
4220 location (org-icalendar-cleanup-string
4221 (org-entry-get nil "LOCATION"))
4222 due (and (member 'todo-due org-icalendar-use-deadline)
4223 (org-entry-get nil "DEADLINE"))
4224 start (and (member 'todo-start org-icalendar-use-scheduled)
4225 (org-entry-get nil "SCHEDULED"))
4226 uid (if org-icalendar-store-UID
4227 (org-id-get-create)
4228 (or (org-id-get) (org-id-new))))
4229 (and due (setq due (org-ical-ts-to-string due "DUE")))
4230 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4232 (if (string-match org-bracket-link-regexp hd)
4233 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4234 (match-string 1 hd))
4235 t t hd)))
4236 (if (string-match org-priority-regexp hd)
4237 (setq pri (string-to-char (match-string 2 hd))
4238 hd (concat (substring hd 0 (match-beginning 1))
4239 (substring hd (match-end 1))))
4240 (setq pri org-default-priority))
4241 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4242 (- org-lowest-priority org-highest-priority))))))
4244 (princ (format "BEGIN:VTODO
4245 UID: %s
4247 SUMMARY:%s%s%s%s
4248 CATEGORIES:%s
4249 SEQUENCE:1
4250 PRIORITY:%d
4251 STATUS:%s
4252 END:VTODO\n"
4253 (concat prefix uid)
4254 (or start dts)
4255 (or summary hd)
4256 (if (and location (string-match "\\S-" location))
4257 (concat "\nLOCATION: " location) "")
4258 (if (and desc (string-match "\\S-" desc))
4259 (concat "\nDESCRIPTION: " desc) "")
4260 (if due (concat "\n" due) "")
4261 category
4262 pri status)))))))))
4264 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4265 "Take out stuff and quote what needs to be quoted.
4266 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4267 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4268 characters."
4269 (if (not s)
4271 (when is-body
4272 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4273 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4274 (while (string-match re s) (setq s (replace-match "" t t s)))
4275 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4276 (let ((start 0))
4277 (while (string-match "\\([,;]\\)" s start)
4278 (setq start (+ (match-beginning 0) 2)
4279 s (replace-match "\\\\\\1" nil nil s))))
4280 (when is-body
4281 (while (string-match "[ \t]*\n[ \t]*" s)
4282 (setq s (replace-match "\\n" t t s))))
4283 (setq s (org-trim s))
4284 (if is-body
4285 (if maxlength
4286 (if (and (numberp maxlength)
4287 (> (length s) maxlength))
4288 (setq s (substring s 0 maxlength)))))
4291 (defun org-get-entry ()
4292 "Clean-up description string."
4293 (save-excursion
4294 (org-back-to-heading t)
4295 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4297 (defun org-start-icalendar-file (name)
4298 "Start an iCalendar file by inserting the header."
4299 (let ((user user-full-name)
4300 (name (or name "unknown"))
4301 (timezone (cadr (current-time-zone))))
4302 (princ
4303 (format "BEGIN:VCALENDAR
4304 VERSION:2.0
4305 X-WR-CALNAME:%s
4306 PRODID:-//%s//Emacs with Org-mode//EN
4307 X-WR-TIMEZONE:%s
4308 CALSCALE:GREGORIAN\n" name user timezone))))
4310 (defun org-finish-icalendar-file ()
4311 "Finish an iCalendar file by inserting the END statement."
4312 (princ "END:VCALENDAR\n"))
4314 (defun org-ical-ts-to-string (s keyword &optional inc)
4315 "Take a time string S and convert it to iCalendar format.
4316 KEYWORD is added in front, to make a complete line like DTSTART....
4317 When INC is non-nil, increase the hour by two (if time string contains
4318 a time), or the day by one (if it does not contain a time)."
4319 (let ((t1 (org-parse-time-string s 'nodefault))
4320 t2 fmt have-time time)
4321 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4322 (setq t2 t1 have-time t)
4323 (setq t2 (org-parse-time-string s)))
4324 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4325 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4326 (when inc
4327 (if have-time
4328 (if org-agenda-default-appointment-duration
4329 (setq mi (+ org-agenda-default-appointment-duration mi))
4330 (setq h (+ 2 h)))
4331 (setq d (1+ d))))
4332 (setq time (encode-time s mi h d m y)))
4333 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4334 (concat keyword (format-time-string fmt time))))
4336 ;;; XOXO export
4338 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4339 (with-current-buffer buffer
4340 (apply 'insert output)))
4341 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4343 ;;;###autoload
4344 (defun org-export-as-xoxo (&optional buffer)
4345 "Export the org buffer as XOXO.
4346 The XOXO buffer is named *xoxo-<source buffer name>*"
4347 (interactive (list (current-buffer)))
4348 ;; A quickie abstraction
4350 ;; Output everything as XOXO
4351 (with-current-buffer (get-buffer buffer)
4352 (let* ((pos (point))
4353 (opt-plist (org-combine-plists (org-default-export-plist)
4354 (org-infile-export-plist)))
4355 (filename (concat (file-name-as-directory
4356 (org-export-directory :xoxo opt-plist))
4357 (file-name-sans-extension
4358 (file-name-nondirectory buffer-file-name))
4359 ".html"))
4360 (out (find-file-noselect filename))
4361 (last-level 1)
4362 (hanging-li nil))
4363 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4364 ;; Check the output buffer is empty.
4365 (with-current-buffer out (erase-buffer))
4366 ;; Kick off the output
4367 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4368 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4369 (let* ((hd (match-string-no-properties 1))
4370 (level (length hd))
4371 (text (concat
4372 (match-string-no-properties 2)
4373 (save-excursion
4374 (goto-char (match-end 0))
4375 (let ((str ""))
4376 (catch 'loop
4377 (while 't
4378 (forward-line)
4379 (if (looking-at "^[ \t]\\(.*\\)")
4380 (setq str (concat str (match-string-no-properties 1)))
4381 (throw 'loop str)))))))))
4383 ;; Handle level rendering
4384 (cond
4385 ((> level last-level)
4386 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4388 ((< level last-level)
4389 (dotimes (- (- last-level level) 1)
4390 (if hanging-li
4391 (org-export-as-xoxo-insert-into out "</li>\n"))
4392 (org-export-as-xoxo-insert-into out "</ol>\n"))
4393 (when hanging-li
4394 (org-export-as-xoxo-insert-into out "</li>\n")
4395 (setq hanging-li nil)))
4397 ((equal level last-level)
4398 (if hanging-li
4399 (org-export-as-xoxo-insert-into out "</li>\n")))
4402 (setq last-level level)
4404 ;; And output the new li
4405 (setq hanging-li 't)
4406 (if (equal ?+ (elt text 0))
4407 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4408 (org-export-as-xoxo-insert-into out "<li>" text))))
4410 ;; Finally finish off the ol
4411 (dotimes (- last-level 1)
4412 (if hanging-li
4413 (org-export-as-xoxo-insert-into out "</li>\n"))
4414 (org-export-as-xoxo-insert-into out "</ol>\n"))
4416 (goto-char pos)
4417 ;; Finish the buffer off and clean it up.
4418 (switch-to-buffer-other-window out)
4419 (indent-region (point-min) (point-max) nil)
4420 (save-buffer)
4421 (goto-char (point-min))
4424 (provide 'org-exp)
4426 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4428 ;;; org-exp.el ends here