Release 6.06b.
[org-mode.git] / lisp / org-exp.el
blobf24f4a14990a5dc87d6dae56ab067946becdb057
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.06b
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 ("creator" . :creator-info)
887 ("timestamp" . :time-stamp-file)))
889 (while (setq o (pop op))
890 (if (string-match (concat (regexp-quote (car o))
891 ":\\([^ \t\n\r;,.]*\\)")
892 options)
893 (setq p (plist-put p (cdr o)
894 (car (read-from-string
895 (match-string 1 options))))))))))
898 (defun org-export-add-subtree-options (p pos)
899 "Add options in subtree at position POS to property list P."
900 (save-excursion
901 (goto-char pos)
902 (when (org-at-heading-p)
903 (let (a)
904 ;; This is actually read in `org-export-get-title-from-subtree'
905 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
906 ;; (setq p (plist-put p :title a)))
907 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
908 (setq p (plist-put p :text a)))
909 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
910 (setq p (org-export-add-options-to-plist p a)))))
913 (defun org-export-directory (type plist)
914 (let* ((val (plist-get plist :publishing-directory))
915 (dir (if (listp val)
916 (or (cdr (assoc type val)) ".")
917 val)))
918 dir))
920 (defun org-export-process-option-filters (plist)
921 (let ((functions org-export-options-filters) f)
922 (while (setq f (pop functions))
923 (setq plist (funcall f plist))))
924 plist)
926 ;;;###autoload
927 (defun org-export (&optional arg)
928 "Export dispatcher for Org-mode.
929 When `org-export-run-in-background' is non-nil, try to run the command
930 in the background. This will be done only for commands that write
931 to a file. For details see the docstring of `org-export-run-in-background'.
933 The prefix argument ARG will be passed to the exporter. However, if
934 ARG is a double universal prefix `C-u C-u', that means to inverse the
935 value of `org-export-run-in-background'."
936 (interactive "P")
937 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
938 (help "[t] insert the export option template
939 \[v] limit export to visible part of outline tree
941 \[a] export as ASCII
943 \[h] export as HTML
944 \[H] export as HTML to temporary buffer
945 \[R] export region as HTML
946 \[b] export as HTML and browse immediately
947 \[x] export as XOXO
949 \[l] export as LaTeX
950 \[L] export as LaTeX to temporary buffer
952 \[i] export current file as iCalendar file
953 \[I] export all agenda files as iCalendar files
954 \[c] export agenda files into combined iCalendar file
956 \[F] publish current file
957 \[P] publish current project
958 \[X] publish... (project will be prompted for)
959 \[A] publish all projects")
960 (cmds
961 '((?t org-insert-export-options-template nil)
962 (?v org-export-visible nil)
963 (?a org-export-as-ascii t)
964 (?h org-export-as-html t)
965 (?b org-export-as-html-and-open t)
966 (?H org-export-as-html-to-buffer nil)
967 (?R org-export-region-as-html nil)
968 (?x org-export-as-xoxo t)
969 (?l org-export-as-latex t)
970 (?L org-export-as-latex-to-buffer nil)
971 (?i org-export-icalendar-this-file t)
972 (?I org-export-icalendar-all-agenda-files t)
973 (?c org-export-icalendar-combine-agenda-files t)
974 (?F org-publish-current-file t)
975 (?P org-publish-current-project t)
976 (?X org-publish t)
977 (?A org-publish-all t)))
978 r1 r2 ass)
979 (save-window-excursion
980 (delete-other-windows)
981 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
982 (princ help))
983 (message "Select command: ")
984 (setq r1 (read-char-exclusive)))
985 (setq r2 (if (< r1 27) (+ r1 96) r1))
986 (unless (setq ass (assq r2 cmds))
987 (error "No command associated with key %c" r1))
988 (if (and bg (nth 2 ass))
989 ;; execute in background
990 (let ((p (start-process
991 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
992 "*Org Processes*"
993 (expand-file-name invocation-name invocation-directory)
994 "-batch"
995 "-l" user-init-file
996 "--eval" "(require 'org-exp)"
997 "--eval" "(setq org-wait .2)"
998 (buffer-file-name)
999 "-f" (symbol-name (nth 1 ass)))))
1000 (set-process-sentinel p 'org-export-process-sentinel)
1001 (message "Background process \"%s\": started" p))
1002 ;; background processing not requested, or not possible
1003 (call-interactively (nth 1 ass)))))
1005 (defun org-export-process-sentinel (process status)
1006 (if (string-match "\n+\\'" status)
1007 (setq status (substring status 0 -1)))
1008 (message "Background process \"%s\": %s" process status))
1010 (defconst org-html-entities
1011 '(("nbsp")
1012 ("iexcl")
1013 ("cent")
1014 ("pound")
1015 ("curren")
1016 ("yen")
1017 ("brvbar")
1018 ("vert" . "&#124;")
1019 ("sect")
1020 ("uml")
1021 ("copy")
1022 ("ordf")
1023 ("laquo")
1024 ("not")
1025 ("shy")
1026 ("reg")
1027 ("macr")
1028 ("deg")
1029 ("plusmn")
1030 ("sup2")
1031 ("sup3")
1032 ("acute")
1033 ("micro")
1034 ("para")
1035 ("middot")
1036 ("odot"."o")
1037 ("star"."*")
1038 ("cedil")
1039 ("sup1")
1040 ("ordm")
1041 ("raquo")
1042 ("frac14")
1043 ("frac12")
1044 ("frac34")
1045 ("iquest")
1046 ("Agrave")
1047 ("Aacute")
1048 ("Acirc")
1049 ("Atilde")
1050 ("Auml")
1051 ("Aring") ("AA"."&Aring;")
1052 ("AElig")
1053 ("Ccedil")
1054 ("Egrave")
1055 ("Eacute")
1056 ("Ecirc")
1057 ("Euml")
1058 ("Igrave")
1059 ("Iacute")
1060 ("Icirc")
1061 ("Iuml")
1062 ("ETH")
1063 ("Ntilde")
1064 ("Ograve")
1065 ("Oacute")
1066 ("Ocirc")
1067 ("Otilde")
1068 ("Ouml")
1069 ("times")
1070 ("Oslash")
1071 ("Ugrave")
1072 ("Uacute")
1073 ("Ucirc")
1074 ("Uuml")
1075 ("Yacute")
1076 ("THORN")
1077 ("szlig")
1078 ("agrave")
1079 ("aacute")
1080 ("acirc")
1081 ("atilde")
1082 ("auml")
1083 ("aring")
1084 ("aelig")
1085 ("ccedil")
1086 ("egrave")
1087 ("eacute")
1088 ("ecirc")
1089 ("euml")
1090 ("igrave")
1091 ("iacute")
1092 ("icirc")
1093 ("iuml")
1094 ("eth")
1095 ("ntilde")
1096 ("ograve")
1097 ("oacute")
1098 ("ocirc")
1099 ("otilde")
1100 ("ouml")
1101 ("divide")
1102 ("oslash")
1103 ("ugrave")
1104 ("uacute")
1105 ("ucirc")
1106 ("uuml")
1107 ("yacute")
1108 ("thorn")
1109 ("yuml")
1110 ("fnof")
1111 ("Alpha")
1112 ("Beta")
1113 ("Gamma")
1114 ("Delta")
1115 ("Epsilon")
1116 ("Zeta")
1117 ("Eta")
1118 ("Theta")
1119 ("Iota")
1120 ("Kappa")
1121 ("Lambda")
1122 ("Mu")
1123 ("Nu")
1124 ("Xi")
1125 ("Omicron")
1126 ("Pi")
1127 ("Rho")
1128 ("Sigma")
1129 ("Tau")
1130 ("Upsilon")
1131 ("Phi")
1132 ("Chi")
1133 ("Psi")
1134 ("Omega")
1135 ("alpha")
1136 ("beta")
1137 ("gamma")
1138 ("delta")
1139 ("epsilon")
1140 ("varepsilon"."&epsilon;")
1141 ("zeta")
1142 ("eta")
1143 ("theta")
1144 ("iota")
1145 ("kappa")
1146 ("lambda")
1147 ("mu")
1148 ("nu")
1149 ("xi")
1150 ("omicron")
1151 ("pi")
1152 ("rho")
1153 ("sigmaf") ("varsigma"."&sigmaf;")
1154 ("sigma")
1155 ("tau")
1156 ("upsilon")
1157 ("phi")
1158 ("chi")
1159 ("psi")
1160 ("omega")
1161 ("thetasym") ("vartheta"."&thetasym;")
1162 ("upsih")
1163 ("piv")
1164 ("bull") ("bullet"."&bull;")
1165 ("hellip") ("dots"."&hellip;")
1166 ("prime")
1167 ("Prime")
1168 ("oline")
1169 ("frasl")
1170 ("weierp")
1171 ("image")
1172 ("real")
1173 ("trade")
1174 ("alefsym")
1175 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1176 ("uarr") ("uparrow"."&uarr;")
1177 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1178 ("darr")("downarrow"."&darr;")
1179 ("harr") ("leftrightarrow"."&harr;")
1180 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1181 ("lArr") ("Leftarrow"."&lArr;")
1182 ("uArr") ("Uparrow"."&uArr;")
1183 ("rArr") ("Rightarrow"."&rArr;")
1184 ("dArr") ("Downarrow"."&dArr;")
1185 ("hArr") ("Leftrightarrow"."&hArr;")
1186 ("forall")
1187 ("part") ("partial"."&part;")
1188 ("exist") ("exists"."&exist;")
1189 ("empty") ("emptyset"."&empty;")
1190 ("nabla")
1191 ("isin") ("in"."&isin;")
1192 ("notin")
1193 ("ni")
1194 ("prod")
1195 ("sum")
1196 ("minus")
1197 ("lowast") ("ast"."&lowast;")
1198 ("radic")
1199 ("prop") ("proptp"."&prop;")
1200 ("infin") ("infty"."&infin;")
1201 ("ang") ("angle"."&ang;")
1202 ("and") ("wedge"."&and;")
1203 ("or") ("vee"."&or;")
1204 ("cap")
1205 ("cup")
1206 ("int")
1207 ("there4")
1208 ("sim")
1209 ("cong") ("simeq"."&cong;")
1210 ("asymp")("approx"."&asymp;")
1211 ("ne") ("neq"."&ne;")
1212 ("equiv")
1213 ("le")
1214 ("ge")
1215 ("sub") ("subset"."&sub;")
1216 ("sup") ("supset"."&sup;")
1217 ("nsub")
1218 ("sube")
1219 ("supe")
1220 ("oplus")
1221 ("otimes")
1222 ("perp")
1223 ("sdot") ("cdot"."&sdot;")
1224 ("lceil")
1225 ("rceil")
1226 ("lfloor")
1227 ("rfloor")
1228 ("lang")
1229 ("rang")
1230 ("loz") ("Diamond"."&loz;")
1231 ("spades") ("spadesuit"."&spades;")
1232 ("clubs") ("clubsuit"."&clubs;")
1233 ("hearts") ("diamondsuit"."&hearts;")
1234 ("diams") ("diamondsuit"."&diams;")
1235 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1236 ("quot")
1237 ("amp")
1238 ("lt")
1239 ("gt")
1240 ("OElig")
1241 ("oelig")
1242 ("Scaron")
1243 ("scaron")
1244 ("Yuml")
1245 ("circ")
1246 ("tilde")
1247 ("ensp")
1248 ("emsp")
1249 ("thinsp")
1250 ("zwnj")
1251 ("zwj")
1252 ("lrm")
1253 ("rlm")
1254 ("ndash")
1255 ("mdash")
1256 ("lsquo")
1257 ("rsquo")
1258 ("sbquo")
1259 ("ldquo")
1260 ("rdquo")
1261 ("bdquo")
1262 ("dagger")
1263 ("Dagger")
1264 ("permil")
1265 ("lsaquo")
1266 ("rsaquo")
1267 ("euro")
1269 ("arccos"."arccos")
1270 ("arcsin"."arcsin")
1271 ("arctan"."arctan")
1272 ("arg"."arg")
1273 ("cos"."cos")
1274 ("cosh"."cosh")
1275 ("cot"."cot")
1276 ("coth"."coth")
1277 ("csc"."csc")
1278 ("deg"."deg")
1279 ("det"."det")
1280 ("dim"."dim")
1281 ("exp"."exp")
1282 ("gcd"."gcd")
1283 ("hom"."hom")
1284 ("inf"."inf")
1285 ("ker"."ker")
1286 ("lg"."lg")
1287 ("lim"."lim")
1288 ("liminf"."liminf")
1289 ("limsup"."limsup")
1290 ("ln"."ln")
1291 ("log"."log")
1292 ("max"."max")
1293 ("min"."min")
1294 ("Pr"."Pr")
1295 ("sec"."sec")
1296 ("sin"."sin")
1297 ("sinh"."sinh")
1298 ("sup"."sup")
1299 ("tan"."tan")
1300 ("tanh"."tanh")
1302 "Entities for TeX->HTML translation.
1303 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1304 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1305 In that case, \"\\ent\" will be translated to \"&other;\".
1306 The list contains HTML entities for Latin-1, Greek and other symbols.
1307 It is supplemented by a number of commonly used TeX macros with appropriate
1308 translations. There is currently no way for users to extend this.")
1310 ;;; General functions for all backends
1312 (defun org-export-preprocess-string (string &rest parameters)
1313 "Cleanup STRING so that that the true exported has a more consistent source.
1314 This function takes STRING, which should be a buffer-string of an org-file
1315 to export. It then creates a temporary buffer where it does its job.
1316 The result is then again returned as a string, and the exporter works
1317 on this string to produce the exported version."
1318 (interactive)
1319 (let* ((htmlp (plist-get parameters :for-html))
1320 (asciip (plist-get parameters :for-ascii))
1321 (latexp (plist-get parameters :for-LaTeX))
1322 (archived-trees (plist-get parameters :archived-trees))
1323 (inhibit-read-only t)
1324 (drawers org-drawers)
1325 (outline-regexp "\\*+ ")
1326 target-alist rtn)
1328 (with-current-buffer (get-buffer-create " org-mode-tmp")
1329 (erase-buffer)
1330 (insert string)
1331 (setq case-fold-search t)
1332 ;; Call the hook
1333 (run-hooks 'org-export-preprocess-hook)
1335 ;; Remove license-to-kill stuff
1336 ;; The caller markes some stuff fo killing, stuff that has been
1337 ;; used to create the page title, for example.
1338 (org-export-kill-licensed-text)
1340 (let ((org-inhibit-startup t)) (org-mode))
1341 (setq case-fold-search t)
1342 (untabify (point-min) (point-max))
1344 ;; Handle incude files
1345 (org-export-handle-include-files)
1347 ;; Handle source code snippets
1348 (org-export-replace-src-segments)
1350 ;; Get rid of drawers
1351 (org-export-remove-or-extract-drawers drawers
1352 (plist-get parameters :drawers))
1354 ;; Get the correct stuff before the first headline
1355 (when (plist-get parameters :skip-before-1st-heading)
1356 (goto-char (point-min))
1357 (when (re-search-forward "^\\*+[ \t]" nil t)
1358 (delete-region (point-min) (match-beginning 0))
1359 (goto-char (point-min))
1360 (insert "\n")))
1361 (when (plist-get parameters :add-text)
1362 (goto-char (point-min))
1363 (insert (plist-get parameters :add-text) "\n"))
1365 ;; Get rid of archived trees
1366 (org-export-remove-archived-trees archived-trees)
1368 ;; Find all headings and compute the targets for them
1369 (setq target-alist (org-export-define-heading-targets target-alist))
1371 ;; Find targets in comments and move them out of comments,
1372 ;; but mark them as targets that should be invisible
1373 (setq target-alist (org-export-handle-invisible-targets target-alist))
1375 ;; Protect examples
1376 (org-export-protect-examples)
1378 ;; Protect backend specific stuff, throw away the others.
1379 (org-export-select-backend-specific-text
1380 (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1382 ;; Protect quoted subtrees
1383 (org-export-protect-quoted-subtrees)
1385 ;; Protect verbatim elements
1386 (org-export-protect-verbatim)
1388 ;; Blockquotes and verse
1389 (org-export-mark-blockquote-and-verse)
1391 ;; Remove comment environment and comment subtrees
1392 (org-export-remove-comment-blocks-and-subtrees)
1394 ;; Remove special table lines
1395 (when org-export-table-remove-special-lines
1396 (org-export-remove-special-table-lines))
1398 ;; Specific LaTeX stuff
1399 (when latexp
1400 (require 'org-export-latex nil)
1401 (org-export-latex-preprocess))
1403 ;; Specific ASCII stuff
1404 (when asciip
1405 (org-export-ascii-preprocess))
1407 ;; Specific HTML stuff
1408 (when htmlp
1409 (org-export-html-preprocess parameters))
1411 ;; Remove or replace comments
1412 (org-export-handle-comments (plist-get parameters :comments))
1414 ;; Find matches for radio targets and turn them into internal links
1415 (org-export-mark-radio-links)
1417 ;; Find all links that contain a newline and put them into a single line
1418 (org-export-concatenate-multiline-links)
1420 ;; Normalize links: Convert angle and plain links into bracket links
1421 ;; and expand link abbreviations
1422 (org-export-normalize-links)
1424 ;; Find all internal links. If they have a fuzzy match (i.e. not
1425 ;; a *dedicated* target match, let the link point to the
1426 ;; corresponding section.
1427 (org-export-target-internal-links target-alist)
1429 ;; Find multiline emphasis and put them into single line
1430 (when (plist-get parameters :emph-multiline)
1431 (org-export-concatenate-multiline-emphasis))
1433 (setq rtn (buffer-string)))
1434 (kill-buffer " org-mode-tmp")
1435 rtn))
1437 (defun org-export-kill-licensed-text ()
1438 "Remove all text that is marked with a :org-license-to-kill property."
1439 (let (p q)
1440 (while (setq p (text-property-any (point-min) (point-max)
1441 :org-license-to-kill t))
1442 (delete-region
1443 p (or (next-single-property-change p :org-license-to-kill)
1444 (point-max))))))
1446 (defun org-export-define-heading-targets (target-alist)
1447 "Find all headings and define the targets for them.
1448 The new targets are added to TARGET-ALIST, which is also returned."
1449 (goto-char (point-min))
1450 (org-init-section-numbers)
1451 (let ((re (concat "^" org-outline-regexp))
1452 level target)
1453 (while (re-search-forward re nil t)
1454 (setq level (org-reduced-level
1455 (save-excursion (goto-char (point-at-bol))
1456 (org-outline-level))))
1457 (setq target (org-solidify-link-text
1458 (format "sec-%s" (org-section-number level))))
1459 (push (cons target target) target-alist)
1460 (add-text-properties
1461 (point-at-bol) (point-at-eol)
1462 (list 'target target))))
1463 target-alist)
1465 (defun org-export-handle-invisible-targets (target-alist)
1466 "Find targets in comments and move them out of comments.
1467 Mark them as invisible targets."
1468 (let (target tmp)
1469 (goto-char (point-min))
1470 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1471 ;; Check if the line before or after is a headline with a target
1472 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1473 (get-text-property (point-at-bol 2) 'target)))
1474 (progn
1475 ;; use the existing target in a neighboring line
1476 (setq tmp (match-string 2))
1477 (replace-match "")
1478 (and (looking-at "\n") (delete-char 1))
1479 (push (cons (org-solidify-link-text tmp) target)
1480 target-alist))
1481 ;; Make an invisible target
1482 (replace-match "\\1(INVISIBLE)"))))
1483 target-alist)
1485 (defun org-export-target-internal-links (target-alist)
1486 "Find all internal links and assign target to them.
1487 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1488 let the link point to the corresponding section."
1489 (goto-char (point-min))
1490 (while (re-search-forward org-bracket-link-regexp nil t)
1491 (org-if-unprotected
1492 (let* ((md (match-data))
1493 (desc (match-end 2))
1494 (link (org-link-unescape (match-string 1)))
1495 (slink (org-solidify-link-text link))
1496 found props pos
1497 (target
1498 (cond
1499 ((cdr (assoc slink target-alist)))
1500 ((string-match org-link-types-re link) nil)
1501 ((or (file-name-absolute-p link)
1502 (string-match "^\\." link))
1503 nil)
1505 (save-excursion
1506 (setq found (condition-case nil (org-link-search link)
1507 (error nil)))
1508 (when (and found
1509 (or (org-on-heading-p)
1510 (not (eq found 'dedicated))))
1511 (or (get-text-property (point) 'target)
1512 (get-text-property
1513 (max (point-min)
1514 (1- (previous-single-property-change
1515 (point) 'target)))
1516 'target))))))))
1517 (when target
1518 (set-match-data md)
1519 (goto-char (match-beginning 1))
1520 (setq props (text-properties-at (point)))
1521 (delete-region (match-beginning 1) (match-end 1))
1522 (setq pos (point))
1523 (insert target)
1524 (unless desc (insert "][" link))
1525 (add-text-properties pos (point) props))))))
1527 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1528 "Remove drawers, or extract the content.
1529 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1530 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1531 whose content to keep."
1532 (unless (eq t exp-drawers)
1533 (goto-char (point-min))
1534 (let ((re (concat "^[ \t]*:\\("
1535 (mapconcat
1536 'identity
1537 (org-delete-all exp-drawers
1538 (copy-sequence all-drawers))
1539 "\\|")
1540 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1541 (while (re-search-forward re nil t)
1542 (replace-match "")))))
1544 (defun org-export-remove-archived-trees (export-archived-trees)
1545 "Remove archived trees.
1546 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1547 When it is t, the entire archived tree will be exported.
1548 When it is nil the entire tree including the headline will be removed
1549 from the buffer."
1550 (let ((re-archive (concat ":" org-archive-tag ":"))
1551 a b)
1552 (when (not (eq export-archived-trees t))
1553 (goto-char (point-min))
1554 (while (re-search-forward re-archive nil t)
1555 (if (not (org-on-heading-p t))
1556 (org-end-of-subtree t)
1557 (beginning-of-line 1)
1558 (setq a (if export-archived-trees
1559 (1+ (point-at-eol)) (point))
1560 b (org-end-of-subtree t))
1561 (if (> b a) (delete-region a b)))))))
1563 (defun org-export-protect-quoted-subtrees ()
1564 "Mark quoted subtrees with the protection property."
1565 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1566 (goto-char (point-min))
1567 (while (re-search-forward re-quote nil t)
1568 (goto-char (match-beginning 0))
1569 (end-of-line 1)
1570 (add-text-properties (point) (org-end-of-subtree t)
1571 '(org-protected t)))))
1573 (defun org-export-protect-verbatim ()
1574 "Mark verbatim snippets with the protection property."
1575 (goto-char (point-min))
1576 (while (re-search-forward org-verbatim-re nil t)
1577 (add-text-properties (match-beginning 4) (match-end 4)
1578 '(org-protected t))
1579 (goto-char (1+ (match-end 4)))))
1581 (defun org-export-protect-examples ()
1582 "Protect code that should be exported as monospaced examples."
1583 (goto-char (point-min))
1584 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1585 (goto-char (match-end 0))
1586 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1587 (insert ": ")
1588 (beginning-of-line 2)))
1589 (goto-char (point-min))
1590 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1591 (add-text-properties (match-beginning 0) (match-end 0)
1592 '(org-protected t))))
1594 (defun org-export-select-backend-specific-text (backend)
1595 (let ((formatters
1596 '((html "HTML" "BEGIN_HTML" "END_HTML")
1597 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1598 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1599 fmt)
1601 (while formatters
1602 (setq fmt (pop formatters))
1603 (when (eq (car fmt) backend)
1604 ;; This is selected code, put it into the file for real
1605 (goto-char (point-min))
1606 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1607 ":[ \t]*\\(.*\\)") nil t)
1608 (replace-match "\\1" t)
1609 (add-text-properties
1610 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1611 '(org-protected t))))
1612 (goto-char (point-min))
1613 (while (re-search-forward
1614 (concat "^#\\+"
1615 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1616 (cadddr fmt) "\\>.*\n?") nil t)
1617 (if (eq (car fmt) backend)
1618 ;; yes, keep this
1619 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1620 '(org-protected t))
1621 ;; No, this is for a different backend, kill it
1622 (delete-region (match-beginning 0) (match-end 0)))))))
1624 (defun org-export-mark-blockquote-and-verse ()
1625 "Mark block quote and verse environments with special cookies.
1626 These special cookies will later be interpreted by the backend."
1627 ;; Blockquotes
1628 (goto-char (point-min))
1629 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1630 nil t)
1631 (replace-match (if (equal (downcase (match-string 1)) "end")
1632 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1633 t t))
1634 ;; Verse
1635 (goto-char (point-min))
1636 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1637 (replace-match (if (equal (downcase (match-string 1)) "end")
1638 "ORG-VERSE-END" "ORG-VERSE-START")
1639 t t)))
1641 (defun org-export-remove-comment-blocks-and-subtrees ()
1642 "Remove the comment environment, and also commented subtrees."
1643 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1644 (case-fold-search nil))
1645 ;; Remove comment environment
1646 (goto-char (point-min))
1647 (while (re-search-forward
1648 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1649 (replace-match "" t t))
1650 ;; Remove subtrees that are commented
1651 (goto-char (point-min))
1652 (while (re-search-forward re-commented nil t)
1653 (goto-char (match-beginning 0))
1654 (delete-region (point) (org-end-of-subtree t)))))
1656 (defun org-export-handle-comments (commentsp)
1657 "Remove comments, or convert to backend-specific format.
1658 COMMENTSP can be a format string for publishing comments.
1659 When it is nil, all comments will be removed."
1660 (let ((re "^#\\(.*\n?\\)")
1661 pos)
1662 (goto-char (point-min))
1663 (while (or (looking-at re)
1664 (re-search-forward re nil t))
1665 (setq pos (match-beginning 0))
1666 (if commentsp
1667 (progn (add-text-properties
1668 (match-beginning 0) (match-end 0) '(org-protected t))
1669 (replace-match (format commentsp (match-string 1)) t t))
1670 (goto-char (1+ pos))
1671 (org-if-unprotected
1672 (replace-match "")
1673 (goto-char (max (point-min) (1- pos))))))))
1675 (defun org-export-mark-radio-links ()
1676 "Find all matches for radio targets and turn them into internal links."
1677 (let ((re-radio (and org-target-link-regexp
1678 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1679 (goto-char (point-min))
1680 (when re-radio
1681 (while (re-search-forward re-radio nil t)
1682 (org-if-unprotected
1683 (replace-match "\\1[[\\2]]"))))))
1685 (defun org-export-remove-special-table-lines ()
1686 "Remove tables lines that are used for internal purposes."
1687 (goto-char (point-min))
1688 (while (re-search-forward "^[ \t]*|" nil t)
1689 (beginning-of-line 1)
1690 (if (or (looking-at "[ \t]*| *[!_^] *|")
1691 (and (looking-at ".*?| *<[0-9]+> *|")
1692 (not (looking-at ".*?| *[^ <|]"))))
1693 (delete-region (max (point-min) (1- (point-at-bol)))
1694 (point-at-eol))
1695 (end-of-line 1))))
1697 (defun org-export-normalize-links ()
1698 "Convert all links to bracket links, and expand link abbreviations."
1699 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1700 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1701 (goto-char (point-min))
1702 (while (re-search-forward re-plain-link nil t)
1703 (goto-char (1- (match-end 0)))
1704 (org-if-unprotected
1705 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1706 ":" (match-string 3) "]]")))
1707 ;; added 'org-link face to links
1708 (put-text-property 0 (length s) 'face 'org-link s)
1709 (replace-match s t t))))
1710 (goto-char (point-min))
1711 (while (re-search-forward re-angle-link nil t)
1712 (goto-char (1- (match-end 0)))
1713 (org-if-unprotected
1714 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1715 ":" (match-string 3) "]]")))
1716 (put-text-property 0 (length s) 'face 'org-link s)
1717 (replace-match s t t))))
1718 (goto-char (point-min))
1719 (while (re-search-forward org-bracket-link-regexp nil t)
1720 (goto-char (1- (match-end 0)))
1721 (org-if-unprotected
1722 (let* ((xx (save-match-data
1723 (org-link-expand-abbrev (match-string 1))))
1724 (s (concat
1725 "[[" xx "]"
1726 (if (match-end 3)
1727 (match-string 2)
1728 (concat "[" xx "]"))
1729 "]")))
1730 (put-text-property 0 (length s) 'face 'org-link s)
1731 (replace-match s t t))))))
1733 (defun org-export-concatenate-multiline-links ()
1734 "Find multi-line links and put it all into a single line.
1735 This is to make sure that the line-processing export backends
1736 can work correctly."
1737 (goto-char (point-min))
1738 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1739 (org-if-unprotected
1740 (replace-match "\\1 \\3")
1741 (goto-char (match-beginning 0)))))
1743 (defun org-export-concatenate-multiline-emphasis ()
1744 "Find multi-line emphasis and put it all into a single line.
1745 This is to make sure that the line-processing export backends
1746 can work correctly."
1747 (goto-char (point-min))
1748 (while (re-search-forward org-emph-re nil t)
1749 (if (not (= (char-after (match-beginning 3))
1750 (char-after (match-beginning 4))))
1751 (org-if-unprotected
1752 (subst-char-in-region (match-beginning 0) (match-end 0)
1753 ?\n ?\ t)
1754 (goto-char (1- (match-end 0))))
1755 (goto-char (1+ (match-beginning 0))))))
1757 (defun org-export-grab-title-from-buffer ()
1758 "Get a title for the current document, from looking at the buffer."
1759 (let ((inhibit-read-only t))
1760 (save-excursion
1761 (goto-char (point-min))
1762 (let ((end (save-excursion (outline-next-heading) (point))))
1763 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1764 ;; Mark the line so that it will not be exported as normal text.
1765 (org-unmodified
1766 (add-text-properties (match-beginning 0) (match-end 0)
1767 (list :org-license-to-kill t)))
1768 ;; Return the title string
1769 (org-trim (match-string 0)))))))
1771 (defun org-export-get-title-from-subtree ()
1772 "Return subtree title and exclude it from export."
1773 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1774 (save-excursion
1775 (goto-char rbeg)
1776 (when (and (org-at-heading-p)
1777 (>= (org-end-of-subtree t t) rend))
1778 ;; This is a subtree, we take the title from the first heading
1779 (goto-char rbeg)
1780 (looking-at org-todo-line-regexp)
1781 (setq title (match-string 3))
1782 (org-unmodified
1783 (add-text-properties (point) (1+ (point-at-eol))
1784 (list :org-license-to-kill t)))
1785 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1786 title))
1788 (defun org-solidify-link-text (s &optional alist)
1789 "Take link text and make a safe target out of it."
1790 (save-match-data
1791 (let* ((rtn
1792 (mapconcat
1793 'identity
1794 (org-split-string s "[ \t\r\n]+") "=="))
1795 (a (assoc rtn alist)))
1796 (or (cdr a) rtn))))
1798 (defun org-get-min-level (lines)
1799 "Get the minimum level in LINES."
1800 (let ((re "^\\(\\*+\\) ") l min)
1801 (catch 'exit
1802 (while (setq l (pop lines))
1803 (if (string-match re l)
1804 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1805 1)))
1807 ;; Variable holding the vector with section numbers
1808 (defvar org-section-numbers (make-vector org-level-max 0))
1810 (defun org-init-section-numbers ()
1811 "Initialize the vector for the section numbers."
1812 (let* ((level -1)
1813 (numbers (nreverse (org-split-string "" "\\.")))
1814 (depth (1- (length org-section-numbers)))
1815 (i depth) number-string)
1816 (while (>= i 0)
1817 (if (> i level)
1818 (aset org-section-numbers i 0)
1819 (setq number-string (or (car numbers) "0"))
1820 (if (string-match "\\`[A-Z]\\'" number-string)
1821 (aset org-section-numbers i
1822 (- (string-to-char number-string) ?A -1))
1823 (aset org-section-numbers i (string-to-number number-string)))
1824 (pop numbers))
1825 (setq i (1- i)))))
1827 (defun org-section-number (&optional level)
1828 "Return a string with the current section number.
1829 When LEVEL is non-nil, increase section numbers on that level."
1830 (let* ((depth (1- (length org-section-numbers)))
1831 (string "")
1832 (fmts (car org-export-section-number-format))
1833 (term (cdr org-export-section-number-format))
1834 (sep "")
1835 ctype fmt idx n)
1836 (when level
1837 (when (> level -1)
1838 (aset org-section-numbers
1839 level (1+ (aref org-section-numbers level))))
1840 (setq idx (1+ level))
1841 (while (<= idx depth)
1842 (if (not (= idx 1))
1843 (aset org-section-numbers idx 0))
1844 (setq idx (1+ idx))))
1845 (setq idx 0)
1846 (while (<= idx depth)
1847 (when (> (aref org-section-numbers idx) 0)
1848 (setq fmt (or (pop fmts) fmt)
1849 ctype (car fmt)
1850 n (aref org-section-numbers idx)
1851 string (if (> n 0)
1852 (concat string sep (org-number-to-counter n ctype))
1853 (concat string ".0"))
1854 sep (nth 1 fmt)))
1855 (setq idx (1+ idx)))
1856 (save-match-data
1857 (if (string-match "\\`\\([@0]\\.\\)+" string)
1858 (setq string (replace-match "" t nil string)))
1859 (if (string-match "\\(\\.0\\)+\\'" string)
1860 (setq string (replace-match "" t nil string))))
1861 (concat string term)))
1863 (defun org-number-to-counter (n type)
1864 "Concert number N to a string counter, according to TYPE.
1865 TYPE must be a string, any of:
1866 1 number
1867 A A,B,....
1868 a a,b,....
1869 I uppper case roman numeral
1870 i lower case roman numeral"
1871 (cond
1872 ((equal type "1") (number-to-string n))
1873 ((equal type "A") (char-to-string (+ ?A n -1)))
1874 ((equal type "a") (char-to-string (+ ?a n -1)))
1875 ((equal type "I") (org-number-to-roman n))
1876 ((equal type "i") (downcase (org-number-to-roman n)))
1877 (t (error "Invalid counter type `%s'" type))))
1879 (defun org-number-to-roman (n)
1880 "Convert integer N into a roman numeral."
1881 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1882 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1883 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1884 ( 1 . "I")))
1885 (res ""))
1886 (if (<= n 0)
1887 (number-to-string n)
1888 (while roman
1889 (if (>= n (caar roman))
1890 (setq n (- n (caar roman))
1891 res (concat res (cdar roman)))
1892 (pop roman)))
1893 res)))
1895 (org-number-to-roman 1961)
1898 ;;; Include files
1900 (defun org-export-handle-include-files ()
1901 "Include the contents of include files, with proper formatting."
1902 (let ((case-fold-search t)
1903 params file markup lang start end prefix prefix1)
1904 (goto-char (point-min))
1905 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
1906 (setq params (read (concat "(" (match-string 1) ")"))
1907 prefix (org-get-and-remove-property 'params :prefix)
1908 prefix1 (org-get-and-remove-property 'params :prefix1)
1909 file (org-symname-or-string (pop params))
1910 markup (org-symname-or-string (pop params))
1911 lang (org-symname-or-string (pop params)))
1912 (delete-region (match-beginning 0) (match-end 0))
1913 (if (or (not file)
1914 (not (file-exists-p file))
1915 (not (file-readable-p file)))
1916 (insert (format "CANNOT INCLUDE FILE %s" file))
1917 (when markup
1918 (if (equal (downcase markup) "src")
1919 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
1920 end "#+end_src")
1921 (setq start (format "#+begin_%s\n" markup)
1922 end (format "#+end_%s" markup))))
1923 (insert (or start ""))
1924 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
1925 (or (bolp) (newline))
1926 (insert (or end ""))))))
1928 (defun org-get-file-contents (file &optional prefix prefix1)
1929 "Get the contents of FILE and return them as a string.
1930 If PREFIX is a string, prepend it to each line. If PREFIX1
1931 is a string, prepend it to the first line instead of PREFIX."
1932 (with-temp-buffer
1933 (insert-file-contents file)
1934 (when (or prefix prefix1)
1935 (goto-char (point-min))
1936 (while (not (eobp))
1937 (insert (or prefix1 prefix))
1938 (setq prefix1 nil)
1939 (beginning-of-line 2)))
1940 (buffer-string)))
1942 (defun org-get-and-remove-property (listvar prop)
1943 "Check if the value of LISTVAR contains PROP as a property.
1944 If yes, return the value of that property (i.e. the element following
1945 in the list) and remove property and value from the list in LISTVAR."
1946 (let ((list (symbol-value listvar)) m v)
1947 (when (setq m (member prop list))
1948 (setq v (nth 1 m))
1949 (if (equal (car list) prop)
1950 (set listvar (cddr list))
1951 (setcdr (nthcdr (- (length list) (length m) 1) list)
1952 (cddr m))
1953 (set listvar list)))
1956 (defun org-symname-or-string (s)
1957 (if (symbolp s)
1958 (if s (symbol-name s) s)
1961 ;;; Fontification of code
1962 ;; Currently only for the HTML backend, but who knows....
1963 (defun org-export-replace-src-segments ()
1964 "Replace source code segments with special code for export."
1965 (let ((case-fold-search t)
1966 lang code trans)
1967 (goto-char (point-min))
1968 (while (re-search-forward
1969 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1970 nil t)
1971 (setq lang (match-string 1) code (match-string 2)
1972 trans (org-export-format-source-code lang code))
1973 (replace-match trans t t))))
1975 (defvar htmlp) ;; dynamically scoped from org-exp.el
1977 (defun org-export-format-source-code (lang code)
1978 "Format CODE from language LANG and return it formatted for export.
1979 Currently, this only does something for HTML export, for all other
1980 backends, it converts the segment into an EXAMPLE segment."
1981 (save-match-data
1982 (cond
1983 (htmlp
1984 ;; We are exporting to HTML
1985 (condition-case nil (require 'htmlize) (nil t))
1986 (if (not (fboundp 'htmlize-region-for-paste))
1987 (progn
1988 ;; we do not have htmlize.el, or an old version of it
1989 (message
1990 "htmlize.el 1.34 or later is needed for source code formatting")
1991 (concat "#+BEGIN_EXAMPLE\n" code
1992 (if (string-match "\n\\'" code) "" "\n")
1993 "#+END_EXAMPLE\n"))
1994 ;; ok, we are good to go
1995 (let* ((mode (and lang (intern (concat lang "-mode"))))
1996 (org-inhibit-startup t)
1997 (org-startup-folded nil)
1998 (htmltext
1999 (with-temp-buffer
2000 (insert code)
2001 ;; Free up the protected stuff
2002 (goto-char (point-min))
2003 (while (re-search-forward "^," nil t)
2004 (replace-match "")
2005 (end-of-line 1))
2006 (if (functionp mode)
2007 (funcall mode)
2008 (fundamental-mode))
2009 (font-lock-fontify-buffer)
2010 (org-export-htmlize-region-for-paste
2011 (point-min) (point-max)))))
2012 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2013 (setq htmltext (replace-match
2014 (format "<pre class=\"src src-%s\">" lang)
2015 t t htmltext)))
2016 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2018 ;; This is not HTML, so just make it an example.
2019 (when (equal lang "org")
2020 (while (string-match "^," code)
2021 (setq code (replace-match "" t t code))))
2022 (concat "#+BEGIN_EXAMPLE\n" code
2023 (if (string-match "\n\\'" code) "" "\n")
2024 "#+END_EXAMPLE\n")))))
2026 ;;; ASCII export
2028 (defvar org-last-level nil) ; dynamically scoped variable
2029 (defvar org-min-level nil) ; dynamically scoped variable
2030 (defvar org-levels-open nil) ; dynamically scoped parameter
2031 (defvar org-ascii-current-indentation nil) ; For communication
2033 ;;;###autoload
2034 (defun org-export-as-ascii (arg)
2035 "Export the outline as a pretty ASCII file.
2036 If there is an active region, export only the region.
2037 The prefix ARG specifies how many levels of the outline should become
2038 underlined headlines. The default is 3."
2039 (interactive "P")
2040 (setq-default org-todo-line-regexp org-todo-line-regexp)
2041 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2042 (org-infile-export-plist)))
2043 (region-p (org-region-active-p))
2044 (rbeg (and region-p (region-beginning)))
2045 (rend (and region-p (region-end)))
2046 (subtree-p
2047 (when region-p
2048 (save-excursion
2049 (goto-char rbeg)
2050 (and (org-at-heading-p)
2051 (>= (org-end-of-subtree t t) rend)))))
2052 (opt-plist (if subtree-p
2053 (org-export-add-subtree-options opt-plist rbeg)
2054 opt-plist))
2055 (custom-times org-display-custom-times)
2056 (org-ascii-current-indentation '(0 . 0))
2057 (level 0) line txt
2058 (umax nil)
2059 (umax-toc nil)
2060 (case-fold-search nil)
2061 (filename (concat (file-name-as-directory
2062 (org-export-directory :ascii opt-plist))
2063 (file-name-sans-extension
2064 (or (and subtree-p
2065 (org-entry-get (region-beginning)
2066 "EXPORT_FILE_NAME" t))
2067 (file-name-nondirectory buffer-file-name)))
2068 ".txt"))
2069 (filename (if (equal (file-truename filename)
2070 (file-truename buffer-file-name))
2071 (concat filename ".txt")
2072 filename))
2073 (buffer (find-file-noselect filename))
2074 (org-levels-open (make-vector org-level-max nil))
2075 (odd org-odd-levels-only)
2076 (date (plist-get opt-plist :date))
2077 (author (plist-get opt-plist :author))
2078 (title (or (and subtree-p (org-export-get-title-from-subtree))
2079 (plist-get opt-plist :title)
2080 (and (not
2081 (plist-get opt-plist :skip-before-1st-heading))
2082 (org-export-grab-title-from-buffer))
2083 (file-name-sans-extension
2084 (file-name-nondirectory buffer-file-name))))
2085 (email (plist-get opt-plist :email))
2086 (language (plist-get opt-plist :language))
2087 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2088 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2089 (todo nil)
2090 (lang-words nil)
2091 (region
2092 (buffer-substring
2093 (if (org-region-active-p) (region-beginning) (point-min))
2094 (if (org-region-active-p) (region-end) (point-max))))
2095 (lines (org-split-string
2096 (org-export-preprocess-string
2097 region
2098 :for-ascii t
2099 :skip-before-1st-heading
2100 (plist-get opt-plist :skip-before-1st-heading)
2101 :drawers (plist-get opt-plist :drawers)
2102 :verbatim-multiline t
2103 :archived-trees
2104 (plist-get opt-plist :archived-trees)
2105 :add-text (plist-get opt-plist :text))
2106 "\n"))
2107 thetoc have-headings first-heading-pos
2108 table-open table-buffer)
2110 (let ((inhibit-read-only t))
2111 (org-unmodified
2112 (remove-text-properties (point-min) (point-max)
2113 '(:org-license-to-kill t))))
2115 (setq org-min-level (org-get-min-level lines))
2116 (setq org-last-level org-min-level)
2117 (org-init-section-numbers)
2119 (find-file-noselect filename)
2121 (setq lang-words (or (assoc language org-export-language-setup)
2122 (assoc "en" org-export-language-setup)))
2123 (switch-to-buffer-other-window buffer)
2124 (erase-buffer)
2125 (fundamental-mode)
2126 ;; create local variables for all options, to make sure all called
2127 ;; functions get the correct information
2128 (mapc (lambda (x)
2129 (set (make-local-variable (cdr x))
2130 (plist-get opt-plist (car x))))
2131 org-export-plist-vars)
2132 (org-set-local 'org-odd-levels-only odd)
2133 (setq umax (if arg (prefix-numeric-value arg)
2134 org-export-headline-levels))
2135 (setq umax-toc (if (integerp org-export-with-toc)
2136 (min org-export-with-toc umax)
2137 umax))
2139 ;; File header
2140 (if title (org-insert-centered title ?=))
2141 (insert "\n")
2142 (if (and (or author email)
2143 org-export-author-info)
2144 (insert (concat (nth 1 lang-words) ": " (or author "")
2145 (if email (concat " <" email ">") "")
2146 "\n")))
2148 (cond
2149 ((and date (string-match "%" date))
2150 (setq date (format-time-string date)))
2151 (date)
2152 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2154 (if (and date org-export-time-stamp-file)
2155 (insert (concat (nth 2 lang-words) ": " date"\n")))
2157 (insert "\n\n")
2159 (if org-export-with-toc
2160 (progn
2161 (push (concat (nth 3 lang-words) "\n") thetoc)
2162 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2163 "\n") thetoc)
2164 (mapc '(lambda (line)
2165 (if (string-match org-todo-line-regexp
2166 line)
2167 ;; This is a headline
2168 (progn
2169 (setq have-headings t)
2170 (setq level (- (match-end 1) (match-beginning 1))
2171 level (org-tr-level level)
2172 txt (match-string 3 line)
2173 todo
2174 (or (and org-export-mark-todo-in-toc
2175 (match-beginning 2)
2176 (not (member (match-string 2 line)
2177 org-done-keywords)))
2178 ; TODO, not DONE
2179 (and org-export-mark-todo-in-toc
2180 (= level umax-toc)
2181 (org-search-todo-below
2182 line lines level))))
2183 (setq txt (org-html-expand-for-ascii txt))
2185 (while (string-match org-bracket-link-regexp txt)
2186 (setq txt
2187 (replace-match
2188 (match-string (if (match-end 2) 3 1) txt)
2189 t t txt)))
2191 (if (and (memq org-export-with-tags '(not-in-toc nil))
2192 (string-match
2193 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2194 txt))
2195 (setq txt (replace-match "" t t txt)))
2196 (if (string-match quote-re0 txt)
2197 (setq txt (replace-match "" t t txt)))
2199 (if org-export-with-section-numbers
2200 (setq txt (concat (org-section-number level)
2201 " " txt)))
2202 (if (<= level umax-toc)
2203 (progn
2204 (push
2205 (concat
2206 (make-string
2207 (* (max 0 (- level org-min-level)) 4) ?\ )
2208 (format (if todo "%s (*)\n" "%s\n") txt))
2209 thetoc)
2210 (setq org-last-level level))
2211 ))))
2212 lines)
2213 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2215 (org-init-section-numbers)
2216 (while (setq line (pop lines))
2217 ;; Remove the quoted HTML tags.
2218 (setq line (org-html-expand-for-ascii line))
2219 ;; Remove targets
2220 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2221 (setq line (replace-match "" t t line)))
2222 ;; Replace internal links
2223 (while (string-match org-bracket-link-regexp line)
2224 (setq line (replace-match
2225 (if (match-end 3) "[\\3]" "[\\1]")
2226 t nil line)))
2227 (when custom-times
2228 (setq line (org-translate-time line)))
2229 (cond
2230 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2231 ;; a Headline
2232 (setq first-heading-pos (or first-heading-pos (point)))
2233 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2234 txt (match-string 2 line))
2235 (org-ascii-level-start level txt umax lines))
2237 ((and org-export-with-tables
2238 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2239 (if (not table-open)
2240 ;; New table starts
2241 (setq table-open t table-buffer nil))
2242 ;; Accumulate lines
2243 (setq table-buffer (cons line table-buffer))
2244 (when (or (not lines)
2245 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2246 (car lines))))
2247 (setq table-open nil
2248 table-buffer (nreverse table-buffer))
2249 (insert (mapconcat
2250 (lambda (x)
2251 (org-fix-indentation x org-ascii-current-indentation))
2252 (org-format-table-ascii table-buffer)
2253 "\n") "\n")))
2255 (setq line (org-fix-indentation line org-ascii-current-indentation))
2256 (if (and org-export-with-fixed-width
2257 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2258 (setq line (replace-match "\\1" nil nil line)))
2259 (insert line "\n"))))
2261 (normal-mode)
2263 ;; insert the table of contents
2264 (when thetoc
2265 (goto-char (point-min))
2266 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2267 (progn
2268 (goto-char (match-beginning 0))
2269 (replace-match ""))
2270 (goto-char first-heading-pos))
2271 (mapc 'insert thetoc)
2272 (or (looking-at "[ \t]*\n[ \t]*\n")
2273 (insert "\n\n")))
2275 ;; Convert whitespace place holders
2276 (goto-char (point-min))
2277 (let (beg end)
2278 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2279 (setq end (next-single-property-change beg 'org-whitespace))
2280 (goto-char beg)
2281 (delete-region beg end)
2282 (insert (make-string (- end beg) ?\ ))))
2284 (save-buffer)
2285 ;; remove display and invisible chars
2286 (let (beg end)
2287 (goto-char (point-min))
2288 (while (setq beg (next-single-property-change (point) 'display))
2289 (setq end (next-single-property-change beg 'display))
2290 (delete-region beg end)
2291 (goto-char beg)
2292 (insert "=>"))
2293 (goto-char (point-min))
2294 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2295 (setq end (next-single-property-change beg 'org-cwidth))
2296 (delete-region beg end)
2297 (goto-char beg)))
2298 (goto-char (point-min))))
2300 (defun org-export-ascii-preprocess ()
2301 "Do extra work for ASCII export"
2302 (goto-char (point-min))
2303 (while (re-search-forward org-verbatim-re nil t)
2304 (goto-char (match-end 2))
2305 (backward-delete-char 1) (insert "'")
2306 (goto-char (match-beginning 2))
2307 (delete-char 1) (insert "`")
2308 (goto-char (match-end 2))))
2310 (defun org-search-todo-below (line lines level)
2311 "Search the subtree below LINE for any TODO entries."
2312 (let ((rest (cdr (memq line lines)))
2313 (re org-todo-line-regexp)
2314 line lv todo)
2315 (catch 'exit
2316 (while (setq line (pop rest))
2317 (if (string-match re line)
2318 (progn
2319 (setq lv (- (match-end 1) (match-beginning 1))
2320 todo (and (match-beginning 2)
2321 (not (member (match-string 2 line)
2322 org-done-keywords))))
2323 ; TODO, not DONE
2324 (if (<= lv level) (throw 'exit nil))
2325 (if todo (throw 'exit t))))))))
2327 (defun org-html-expand-for-ascii (line)
2328 "Handle quoted HTML for ASCII export."
2329 (if org-export-html-expand
2330 (while (string-match "@<[^<>\n]*>" line)
2331 ;; We just remove the tags for now.
2332 (setq line (replace-match "" nil nil line))))
2333 line)
2335 (defun org-insert-centered (s &optional underline)
2336 "Insert the string S centered and underline it with character UNDERLINE."
2337 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2338 (insert (make-string ind ?\ ) s "\n")
2339 (if underline
2340 (insert (make-string ind ?\ )
2341 (make-string (string-width s) underline)
2342 "\n"))))
2344 (defun org-ascii-level-start (level title umax &optional lines)
2345 "Insert a new level in ASCII export."
2346 (let (char (n (- level umax 1)) (ind 0))
2347 (if (> level umax)
2348 (progn
2349 (insert (make-string (* 2 n) ?\ )
2350 (char-to-string (nth (% n (length org-export-ascii-bullets))
2351 org-export-ascii-bullets))
2352 " " title "\n")
2353 ;; find the indentation of the next non-empty line
2354 (catch 'stop
2355 (while lines
2356 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2357 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2358 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2359 (pop lines)))
2360 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2361 (if (or (not (equal (char-before) ?\n))
2362 (not (equal (char-before (1- (point))) ?\n)))
2363 (insert "\n"))
2364 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2365 (unless org-export-with-tags
2366 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2367 (setq title (replace-match "" t t title))))
2368 (if org-export-with-section-numbers
2369 (setq title (concat (org-section-number level) " " title)))
2370 (insert title "\n" (make-string (string-width title) char) "\n")
2371 (setq org-ascii-current-indentation '(0 . 0)))))
2373 ;;;###autoload
2374 (defun org-export-visible (type arg)
2375 "Create a copy of the visible part of the current buffer, and export it.
2376 The copy is created in a temporary buffer and removed after use.
2377 TYPE is the final key (as a string) that also select the export command in
2378 the `C-c C-e' export dispatcher.
2379 As a special case, if the you type SPC at the prompt, the temporary
2380 org-mode file will not be removed but presented to you so that you can
2381 continue to use it. The prefix arg ARG is passed through to the exporting
2382 command."
2383 (interactive
2384 (list (progn
2385 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2386 (read-char-exclusive))
2387 current-prefix-arg))
2388 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2389 (error "Invalid export key"))
2390 (let* ((binding (cdr (assoc type
2391 '((?a . org-export-as-ascii)
2392 (?\C-a . org-export-as-ascii)
2393 (?b . org-export-as-html-and-open)
2394 (?\C-b . org-export-as-html-and-open)
2395 (?h . org-export-as-html)
2396 (?H . org-export-as-html-to-buffer)
2397 (?R . org-export-region-as-html)
2398 (?x . org-export-as-xoxo)))))
2399 (keepp (equal type ?\ ))
2400 (file buffer-file-name)
2401 (buffer (get-buffer-create "*Org Export Visible*"))
2402 s e)
2403 ;; Need to hack the drawers here.
2404 (save-excursion
2405 (goto-char (point-min))
2406 (while (re-search-forward org-drawer-regexp nil t)
2407 (goto-char (match-beginning 1))
2408 (or (org-invisible-p) (org-flag-drawer nil))))
2409 (with-current-buffer buffer (erase-buffer))
2410 (save-excursion
2411 (setq s (goto-char (point-min)))
2412 (while (not (= (point) (point-max)))
2413 (goto-char (org-find-invisible))
2414 (append-to-buffer buffer s (point))
2415 (setq s (goto-char (org-find-visible))))
2416 (org-cycle-hide-drawers 'all)
2417 (goto-char (point-min))
2418 (unless keepp
2419 ;; Copy all comment lines to the end, to make sure #+ settings are
2420 ;; still available for the second export step. Kind of a hack, but
2421 ;; does do the trick.
2422 (if (looking-at "#[^\r\n]*")
2423 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2424 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2425 (append-to-buffer buffer (1+ (match-beginning 0))
2426 (min (point-max) (1+ (match-end 0))))))
2427 (set-buffer buffer)
2428 (let ((buffer-file-name file)
2429 (org-inhibit-startup t))
2430 (org-mode)
2431 (show-all)
2432 (unless keepp (funcall binding arg))))
2433 (if (not keepp)
2434 (kill-buffer buffer)
2435 (switch-to-buffer-other-window buffer)
2436 (goto-char (point-min)))))
2438 (defun org-find-visible ()
2439 (let ((s (point)))
2440 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2441 (get-char-property s 'invisible)))
2443 (defun org-find-invisible ()
2444 (let ((s (point)))
2445 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2446 (not (get-char-property s 'invisible))))
2449 ;;; HTML export
2451 (defvar org-archive-location) ;; gets loades with the org-archive require.
2452 (defun org-get-current-options ()
2453 "Return a string with current options as keyword options.
2454 Does include HTML export options as well as TODO and CATEGORY stuff."
2455 (require 'org-archive)
2456 (format
2457 "#+TITLE: %s
2458 #+AUTHOR: %s
2459 #+EMAIL: %s
2460 #+DATE: %s
2461 #+LANGUAGE: %s
2462 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2463 #+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
2465 #+LINK_UP: %s
2466 #+LINK_HOME: %s
2467 #+CATEGORY: %s
2468 #+SEQ_TODO: %s
2469 #+TYP_TODO: %s
2470 #+PRIORITIES: %c %c %c
2471 #+DRAWERS: %s
2472 #+STARTUP: %s %s %s %s %s
2473 #+TAGS: %s
2474 #+FILETAGS: %s
2475 #+ARCHIVE: %s
2476 #+LINK: %s
2478 (buffer-name) (user-full-name) user-mail-address
2479 (format-time-string (car org-time-stamp-formats))
2480 org-export-default-language
2481 org-export-headline-levels
2482 org-export-with-section-numbers
2483 org-export-with-toc
2484 org-export-preserve-breaks
2485 org-export-html-expand
2486 org-export-with-fixed-width
2487 org-export-with-tables
2488 org-export-with-sub-superscripts
2489 org-export-with-special-strings
2490 org-export-with-footnotes
2491 org-export-with-emphasize
2492 org-export-with-TeX-macros
2493 org-export-with-LaTeX-fragments
2494 org-export-skip-text-before-1st-heading
2495 org-export-with-drawers
2496 org-export-with-tags
2497 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2498 org-export-html-link-up
2499 org-export-html-link-home
2500 (file-name-nondirectory buffer-file-name)
2501 "TODO FEEDBACK VERIFY DONE"
2502 "Me Jason Marie DONE"
2503 org-highest-priority org-lowest-priority org-default-priority
2504 (mapconcat 'identity org-drawers " ")
2505 (cdr (assoc org-startup-folded
2506 '((nil . "showall") (t . "overview") (content . "content"))))
2507 (if org-odd-levels-only "odd" "oddeven")
2508 (if org-hide-leading-stars "hidestars" "showstars")
2509 (if org-startup-align-all-tables "align" "noalign")
2510 (cond ((eq org-log-done t) "logdone")
2511 ((equal org-log-done 'note) "lognotedone")
2512 ((not org-log-done) "nologdone"))
2513 (or (mapconcat (lambda (x)
2514 (cond
2515 ((equal '(:startgroup) x) "{")
2516 ((equal '(:endgroup) x) "}")
2517 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2518 (t (car x))))
2519 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2520 (mapconcat 'identity org-file-tags " ")
2521 org-archive-location
2522 "org file:~/org/%s.org"
2525 (defun org-export-html-preprocess (parameters)
2526 ;; Convert LaTeX fragments to images
2527 (when (plist-get parameters :LaTeX-fragments)
2528 (org-format-latex
2529 (concat "ltxpng/" (file-name-sans-extension
2530 (file-name-nondirectory
2531 org-current-export-file)))
2532 org-current-export-dir nil "Creating LaTeX image %s"))
2533 (message "Exporting..."))
2535 ;;;###autoload
2536 (defun org-insert-export-options-template ()
2537 "Insert into the buffer a template with information for exporting."
2538 (interactive)
2539 (if (not (bolp)) (newline))
2540 (let ((s (org-get-current-options)))
2541 (and (string-match "#\\+CATEGORY" s)
2542 (setq s (substring s 0 (match-beginning 0))))
2543 (insert s)))
2545 ;;;###autoload
2546 (defun org-export-as-html-and-open (arg)
2547 "Export the outline as HTML and immediately open it with a browser.
2548 If there is an active region, export only the region.
2549 The prefix ARG specifies how many levels of the outline should become
2550 headlines. The default is 3. Lower levels will become bulleted lists."
2551 (interactive "P")
2552 (org-export-as-html arg 'hidden)
2553 (org-open-file buffer-file-name))
2555 ;;;###autoload
2556 (defun org-export-as-html-batch ()
2557 "Call `org-export-as-html', may be used in batch processing as
2558 emacs --batch
2559 --load=$HOME/lib/emacs/org.el
2560 --eval \"(setq org-export-headline-levels 2)\"
2561 --visit=MyFile --funcall org-export-as-html-batch"
2562 (org-export-as-html org-export-headline-levels 'hidden))
2564 ;;;###autoload
2565 (defun org-export-as-html-to-buffer (arg)
2566 "Call `org-exort-as-html` with output to a temporary buffer.
2567 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2568 (interactive "P")
2569 (org-export-as-html arg nil nil "*Org HTML Export*")
2570 (switch-to-buffer-other-window "*Org HTML Export*"))
2572 ;;;###autoload
2573 (defun org-replace-region-by-html (beg end)
2574 "Assume the current region has org-mode syntax, and convert it to HTML.
2575 This can be used in any buffer. For example, you could write an
2576 itemized list in org-mode syntax in an HTML buffer and then use this
2577 command to convert it."
2578 (interactive "r")
2579 (let (reg html buf pop-up-frames)
2580 (save-window-excursion
2581 (if (org-mode-p)
2582 (setq html (org-export-region-as-html
2583 beg end t 'string))
2584 (setq reg (buffer-substring beg end)
2585 buf (get-buffer-create "*Org tmp*"))
2586 (with-current-buffer buf
2587 (erase-buffer)
2588 (insert reg)
2589 (org-mode)
2590 (setq html (org-export-region-as-html
2591 (point-min) (point-max) t 'string)))
2592 (kill-buffer buf)))
2593 (delete-region beg end)
2594 (insert html)))
2596 ;;;###autoload
2597 (defun org-export-region-as-html (beg end &optional body-only buffer)
2598 "Convert region from BEG to END in org-mode buffer to HTML.
2599 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2600 contents, and only produce the region of converted text, useful for
2601 cut-and-paste operations.
2602 If BUFFER is a buffer or a string, use/create that buffer as a target
2603 of the converted HTML. If BUFFER is the symbol `string', return the
2604 produced HTML as a string and leave not buffer behind. For example,
2605 a Lisp program could call this function in the following way:
2607 (setq html (org-export-region-as-html beg end t 'string))
2609 When called interactively, the output buffer is selected, and shown
2610 in a window. A non-interactive call will only return the buffer."
2611 (interactive "r\nP")
2612 (when (interactive-p)
2613 (setq buffer "*Org HTML Export*"))
2614 (let ((transient-mark-mode t) (zmacs-regions t)
2615 ext-plist rtn)
2616 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2617 (goto-char end)
2618 (set-mark (point)) ;; to activate the region
2619 (goto-char beg)
2620 (setq rtn (org-export-as-html
2621 nil nil ext-plist
2622 buffer body-only))
2623 (if (fboundp 'deactivate-mark) (deactivate-mark))
2624 (if (and (interactive-p) (bufferp rtn))
2625 (switch-to-buffer-other-window rtn)
2626 rtn)))
2628 (defvar html-table-tag nil) ; dynamically scoped into this.
2629 ;;;###autoload
2630 (defun org-export-as-html (arg &optional hidden ext-plist
2631 to-buffer body-only pub-dir)
2632 "Export the outline as a pretty HTML file.
2633 If there is an active region, export only the region. The prefix
2634 ARG specifies how many levels of the outline should become
2635 headlines. The default is 3. Lower levels will become bulleted
2636 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2637 EXT-PLIST is a property list with external parameters overriding
2638 org-mode's default settings, but still inferior to file-local
2639 settings. When TO-BUFFER is non-nil, create a buffer with that
2640 name and export to that buffer. If TO-BUFFER is the symbol
2641 `string', don't leave any buffer behind but just return the
2642 resulting HTML as a string. When BODY-ONLY is set, don't produce
2643 the file header and footer, simply return the content of
2644 <body>...</body>, without even the body tags themselves. When
2645 PUB-DIR is set, use this as the publishing directory."
2646 (interactive "P")
2648 ;; Make sure we have a file name when we need it.
2649 (when (and (not (or to-buffer body-only))
2650 (not buffer-file-name))
2651 (if (buffer-base-buffer)
2652 (org-set-local 'buffer-file-name
2653 (with-current-buffer (buffer-base-buffer)
2654 buffer-file-name))
2655 (error "Need a file name to be able to export.")))
2657 (message "Exporting...")
2658 (setq-default org-todo-line-regexp org-todo-line-regexp)
2659 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2660 (setq-default org-done-keywords org-done-keywords)
2661 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2662 (let* ((opt-plist
2663 (org-export-process-option-filters
2664 (org-combine-plists (org-default-export-plist)
2665 ext-plist
2666 (org-infile-export-plist))))
2668 (style (concat org-export-html-style-default
2669 (plist-get opt-plist :style)
2670 (plist-get opt-plist :style-extra)))
2671 (html-extension (plist-get opt-plist :html-extension))
2672 (link-validate (plist-get opt-plist :link-validation-function))
2673 valid thetoc have-headings first-heading-pos
2674 (odd org-odd-levels-only)
2675 (region-p (org-region-active-p))
2676 (rbeg (and region-p (region-beginning)))
2677 (rend (and region-p (region-end)))
2678 (subtree-p
2679 (if (plist-get opt-plist :ignore-subree-p)
2681 (when region-p
2682 (save-excursion
2683 (goto-char rbeg)
2684 (and (org-at-heading-p)
2685 (>= (org-end-of-subtree t t) rend))))))
2686 (opt-plist (if subtree-p
2687 (org-export-add-subtree-options opt-plist rbeg)
2688 opt-plist))
2689 ;; The following two are dynamically scoped into other
2690 ;; routines below.
2691 (org-current-export-dir
2692 (or pub-dir (org-export-directory :html opt-plist)))
2693 (org-current-export-file buffer-file-name)
2694 (level 0) (line "") (origline "") txt todo
2695 (umax nil)
2696 (umax-toc nil)
2697 (filename (if to-buffer nil
2698 (expand-file-name
2699 (concat
2700 (file-name-sans-extension
2701 (or (and subtree-p
2702 (org-entry-get (region-beginning)
2703 "EXPORT_FILE_NAME" t))
2704 (file-name-nondirectory buffer-file-name)))
2705 "." html-extension)
2706 (file-name-as-directory
2707 (or pub-dir (org-export-directory :html opt-plist))))))
2708 (current-dir (if buffer-file-name
2709 (file-name-directory buffer-file-name)
2710 default-directory))
2711 (buffer (if to-buffer
2712 (cond
2713 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2714 (t (get-buffer-create to-buffer)))
2715 (find-file-noselect filename)))
2716 (org-levels-open (make-vector org-level-max nil))
2717 (date (plist-get opt-plist :date))
2718 (author (plist-get opt-plist :author))
2719 (title (or (and subtree-p (org-export-get-title-from-subtree))
2720 (plist-get opt-plist :title)
2721 (and (not
2722 (plist-get opt-plist :skip-before-1st-heading))
2723 (org-export-grab-title-from-buffer))
2724 (and buffer-file-name
2725 (file-name-sans-extension
2726 (file-name-nondirectory buffer-file-name)))
2727 "UNTITLED"))
2728 (html-table-tag (plist-get opt-plist :html-table-tag))
2729 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2730 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2731 (inquote nil)
2732 (infixed nil)
2733 (inverse nil)
2734 (in-local-list nil)
2735 (local-list-type nil)
2736 (local-list-indent nil)
2737 (llt org-plain-list-ordered-item-terminator)
2738 (email (plist-get opt-plist :email))
2739 (language (plist-get opt-plist :language))
2740 (lang-words nil)
2741 (head-count 0) cnt
2742 (start 0)
2743 (coding-system (and (boundp 'buffer-file-coding-system)
2744 buffer-file-coding-system))
2745 (coding-system-for-write (or org-export-html-coding-system
2746 coding-system))
2747 (save-buffer-coding-system (or org-export-html-coding-system
2748 coding-system))
2749 (charset (and coding-system-for-write
2750 (fboundp 'coding-system-get)
2751 (coding-system-get coding-system-for-write
2752 'mime-charset)))
2753 (region
2754 (buffer-substring
2755 (if region-p (region-beginning) (point-min))
2756 (if region-p (region-end) (point-max))))
2757 (lines
2758 (org-split-string
2759 (org-export-preprocess-string
2760 region
2761 :emph-multiline t
2762 :for-html t
2763 :skip-before-1st-heading
2764 (plist-get opt-plist :skip-before-1st-heading)
2765 :drawers (plist-get opt-plist :drawers)
2766 :archived-trees
2767 (plist-get opt-plist :archived-trees)
2768 :add-text
2769 (plist-get opt-plist :text)
2770 :LaTeX-fragments
2771 (plist-get opt-plist :LaTeX-fragments))
2772 "[\r\n]"))
2773 table-open type
2774 table-buffer table-orig-buffer
2775 ind item-type starter didclose
2776 rpl path attr desc descp desc1 desc2 link
2777 snumber fnc item-tag
2780 (let ((inhibit-read-only t))
2781 (org-unmodified
2782 (remove-text-properties (point-min) (point-max)
2783 '(:org-license-to-kill t))))
2785 (message "Exporting...")
2787 (setq org-min-level (org-get-min-level lines))
2788 (setq org-last-level org-min-level)
2789 (org-init-section-numbers)
2791 (cond
2792 ((and date (string-match "%" date))
2793 (setq date (format-time-string date)))
2794 (date)
2795 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2797 ;; Get the language-dependent settings
2798 (setq lang-words (or (assoc language org-export-language-setup)
2799 (assoc "en" org-export-language-setup)))
2801 ;; Switch to the output buffer
2802 (set-buffer buffer)
2803 (let ((inhibit-read-only t)) (erase-buffer))
2804 (fundamental-mode)
2806 (and (fboundp 'set-buffer-file-coding-system)
2807 (set-buffer-file-coding-system coding-system-for-write))
2809 (let ((case-fold-search nil)
2810 (org-odd-levels-only odd))
2811 ;; create local variables for all options, to make sure all called
2812 ;; functions get the correct information
2813 (mapc (lambda (x)
2814 (set (make-local-variable (cdr x))
2815 (plist-get opt-plist (car x))))
2816 org-export-plist-vars)
2817 (setq umax (if arg (prefix-numeric-value arg)
2818 org-export-headline-levels))
2819 (setq umax-toc (if (integerp org-export-with-toc)
2820 (min org-export-with-toc umax)
2821 umax))
2822 (unless body-only
2823 ;; File header
2824 (insert (format
2825 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2826 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2827 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2828 lang=\"%s\" xml:lang=\"%s\">
2829 <head>
2830 <title>%s</title>
2831 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2832 <meta name=\"generator\" content=\"Org-mode\"/>
2833 <meta name=\"generated\" content=\"%s\"/>
2834 <meta name=\"author\" content=\"%s\"/>
2836 </head><body>
2838 language language (org-html-expand title)
2839 (or charset "iso-8859-1") date author style))
2841 (insert (or (plist-get opt-plist :preamble) ""))
2843 (when (plist-get opt-plist :auto-preamble)
2844 (if title (insert (format org-export-html-title-format
2845 (org-html-expand title))))))
2847 (if (and org-export-with-toc (not body-only))
2848 (progn
2849 (push (format "<h%d>%s</h%d>\n"
2850 org-export-html-toplevel-hlevel
2851 (nth 3 lang-words)
2852 org-export-html-toplevel-hlevel)
2853 thetoc)
2854 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2855 (push "<ul>\n<li>" thetoc)
2856 (setq lines
2857 (mapcar '(lambda (line)
2858 (if (string-match org-todo-line-regexp line)
2859 ;; This is a headline
2860 (progn
2861 (setq have-headings t)
2862 (setq level (- (match-end 1) (match-beginning 1))
2863 level (org-tr-level level)
2864 txt (save-match-data
2865 (org-html-expand
2866 (org-export-cleanup-toc-line
2867 (match-string 3 line))))
2868 todo
2869 (or (and org-export-mark-todo-in-toc
2870 (match-beginning 2)
2871 (not (member (match-string 2 line)
2872 org-done-keywords)))
2873 ; TODO, not DONE
2874 (and org-export-mark-todo-in-toc
2875 (= level umax-toc)
2876 (org-search-todo-below
2877 line lines level))))
2878 (if (string-match
2879 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2880 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2881 (if (string-match quote-re0 txt)
2882 (setq txt (replace-match "" t t txt)))
2883 (setq snumber (org-section-number level))
2884 (if org-export-with-section-numbers
2885 (setq txt (concat snumber " " txt)))
2886 (if (<= level (max umax umax-toc))
2887 (setq head-count (+ head-count 1)))
2888 (if (<= level umax-toc)
2889 (progn
2890 (if (> level org-last-level)
2891 (progn
2892 (setq cnt (- level org-last-level))
2893 (while (>= (setq cnt (1- cnt)) 0)
2894 (push "\n<ul>\n<li>" thetoc))
2895 (push "\n" thetoc)))
2896 (if (< level org-last-level)
2897 (progn
2898 (setq cnt (- org-last-level level))
2899 (while (>= (setq cnt (1- cnt)) 0)
2900 (push "</li>\n</ul>" thetoc))
2901 (push "\n" thetoc)))
2902 ;; Check for targets
2903 (while (string-match org-any-target-regexp line)
2904 (setq line (replace-match
2905 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2906 t t line)))
2907 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2908 (setq txt (replace-match "" t t txt)))
2909 (push
2910 (format
2911 (if todo
2912 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2913 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2914 snumber txt) thetoc)
2916 (setq org-last-level level))
2918 line)
2919 lines))
2920 (while (> org-last-level (1- org-min-level))
2921 (setq org-last-level (1- org-last-level))
2922 (push "</li>\n</ul>\n" thetoc))
2923 (push "</div>\n" thetoc)
2924 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2926 (setq head-count 0)
2927 (org-init-section-numbers)
2929 (while (setq line (pop lines) origline line)
2930 (catch 'nextline
2932 ;; end of quote section?
2933 (when (and inquote (string-match "^\\*+ " line))
2934 (insert "</pre>\n")
2935 (setq inquote nil))
2936 ;; inside a quote section?
2937 (when inquote
2938 (insert (org-html-protect line) "\n")
2939 (throw 'nextline nil))
2941 ;; Fixed-width, verbatim lines (examples)
2942 (when (and org-export-with-fixed-width
2943 (string-match "^[ \t]*:\\(.*\\)" line))
2944 (when (not infixed)
2945 (setq infixed t)
2946 (insert "<pre class=\"example\">\n"))
2947 (insert (org-html-protect (match-string 1 line)) "\n")
2948 (when (or (not lines)
2949 (not (string-match "^[ \t]*\\(:.*\\)"
2950 (car lines))))
2951 (setq infixed nil)
2952 (insert "</pre>\n"))
2953 (throw 'nextline nil))
2955 ;; Protected HTML
2956 (when (get-text-property 0 'org-protected line)
2957 (let (par)
2958 (when (re-search-backward
2959 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2960 (setq par (match-string 1))
2961 (replace-match "\\2\n"))
2962 (insert line "\n")
2963 (while (and lines
2964 (not (string-match "^[ \t]*:" (car lines)))
2965 (or (= (length (car lines)) 0)
2966 (get-text-property 0 'org-protected (car lines))))
2967 (insert (pop lines) "\n"))
2968 (and par (insert "<p>\n")))
2969 (throw 'nextline nil))
2971 ;; Horizontal line
2972 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2973 (insert "\n<hr/>\n")
2974 (throw 'nextline nil))
2976 ;; Blockquotes and verse
2977 (when (equal "ORG-BLOCKQUOTE-START" line)
2978 (insert "<blockquote>\n<p>\n")
2979 (throw 'nextline nil))
2980 (when (equal "ORG-BLOCKQUOTE-END" line)
2981 (insert "</p>\n</blockquote>\n")
2982 (throw 'nextline nil))
2983 (when (equal "ORG-VERSE-START" line)
2984 (insert "\n<p class=\"verse\">\n")
2985 (setq inverse t)
2986 (throw 'nextline nil))
2987 (when (equal "ORG-VERSE-END" line)
2988 (insert "</p>\n")
2989 (setq inverse nil)
2990 (throw 'nextline nil))
2991 (when inverse
2992 (setq i (org-get-string-indentation line))
2993 (if (> i 0)
2994 (setq line (concat (mapconcat 'identity
2995 (make-list (* 2 i) "\\nbsp") "")
2996 " " (org-trim line))))
2997 (setq line (concat line " \\\\")))
2999 ;; make targets to anchors
3000 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3001 (cond
3002 ((match-end 2)
3003 (setq line (replace-match
3004 (concat "@<a name=\""
3005 (org-solidify-link-text (match-string 1 line))
3006 "\">\\nbsp@</a>")
3007 t t line)))
3008 ((and org-export-with-toc (equal (string-to-char line) ?*))
3009 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3010 (setq line (replace-match
3011 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3012 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3013 t t line)))
3015 (setq line (replace-match
3016 (concat "@<a name=\""
3017 (org-solidify-link-text (match-string 1 line))
3018 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3019 t t line)))))
3021 (setq line (org-html-handle-time-stamps line))
3023 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3024 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3025 ;; Also handle sub_superscripts and checkboxes
3026 (or (string-match org-table-hline-regexp line)
3027 (setq line (org-html-expand line)))
3029 ;; Format the links
3030 (setq start 0)
3031 (while (string-match org-bracket-link-analytic-regexp line start)
3032 (setq start (match-beginning 0))
3033 (setq path (save-match-data (org-link-unescape
3034 (match-string 3 line))))
3035 (setq type (cond
3036 ((match-end 2) (match-string 2 line))
3037 ((save-match-data
3038 (or (file-name-absolute-p path)
3039 (string-match "^\\.\\.?/" path)))
3040 "file")
3041 (t "internal")))
3042 (setq path (org-extract-attributes path))
3043 (setq attr (org-attributes-to-string
3044 (get-text-property 0 'org-attributes path)))
3045 (setq desc1 (if (match-end 5) (match-string 5 line))
3046 desc2 (if (match-end 2) (concat type ":" path) path)
3047 descp (and desc1 (not (equal desc1 desc2)))
3048 desc (or desc1 desc2))
3049 ;; Make an image out of the description if that is so wanted
3050 (when (and descp (org-file-image-p desc))
3051 (save-match-data
3052 (if (string-match "^file:" desc)
3053 (setq desc (substring desc (match-end 0)))))
3054 (setq desc (concat "<img src=\"" desc "\"/>")))
3055 ;; FIXME: do we need to unescape here somewhere?
3056 (cond
3057 ((equal type "internal")
3058 (setq rpl
3059 (concat
3060 "<a href=\"#"
3061 (org-solidify-link-text
3062 (save-match-data (org-link-unescape path)) nil)
3063 "\"" attr ">" desc "</a>")))
3064 ((member type '("http" "https"))
3065 ;; standard URL, just check if we need to inline an image
3066 (if (and (or (eq t org-export-html-inline-images)
3067 (and org-export-html-inline-images (not descp)))
3068 (org-file-image-p path))
3069 (setq rpl (concat "<img src=\"" type ":" path "\"" attr "/>"))
3070 (setq link (concat type ":" path))
3071 (setq rpl (concat "<a href=\"" link "\"" attr ">"
3072 desc "</a>"))))
3073 ((member type '("ftp" "mailto" "news"))
3074 ;; standard URL
3075 (setq link (concat type ":" path))
3076 (setq rpl (concat "<a href=\"" link "\"" attr ">" desc "</a>")))
3078 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3079 ;; The link protocol has a function for format the link
3080 (setq rpl
3081 (save-match-data
3082 (funcall fnc (org-link-unescape path) desc1 'html))))
3084 ((string= type "file")
3085 ;; FILE link
3086 (let* ((filename path)
3087 (abs-p (file-name-absolute-p filename))
3088 thefile file-is-image-p search)
3089 (save-match-data
3090 (if (string-match "::\\(.*\\)" filename)
3091 (setq search (match-string 1 filename)
3092 filename (replace-match "" t nil filename)))
3093 (setq valid
3094 (if (functionp link-validate)
3095 (funcall link-validate filename current-dir)
3097 (setq file-is-image-p (org-file-image-p filename))
3098 (setq thefile (if abs-p (expand-file-name filename) filename))
3099 (when (and org-export-html-link-org-files-as-html
3100 (string-match "\\.org$" thefile))
3101 (setq thefile (concat (substring thefile 0
3102 (match-beginning 0))
3103 "." html-extension))
3104 (if (and search
3105 ;; make sure this is can be used as target search
3106 (not (string-match "^[0-9]*$" search))
3107 (not (string-match "^\\*" search))
3108 (not (string-match "^/.*/$" search)))
3109 (setq thefile (concat thefile "#"
3110 (org-solidify-link-text
3111 (org-link-unescape search)))))
3112 (when (string-match "^file:" desc)
3113 (setq desc (replace-match "" t t desc))
3114 (if (string-match "\\.org$" desc)
3115 (setq desc (replace-match "" t t desc))))))
3116 (setq rpl (if (and file-is-image-p
3117 (or (eq t org-export-html-inline-images)
3118 (and org-export-html-inline-images
3119 (not descp))))
3120 (concat "<img src=\"" thefile "\"" attr "/>")
3121 (concat "<a href=\"" thefile "\"" attr ">"
3122 desc "</a>")))
3123 (if (not valid) (setq rpl desc))))
3126 ;; just publish the path, as default
3127 (setq rpl (concat "<i>&lt;" type ":"
3128 (save-match-data (org-link-unescape path))
3129 "&gt;</i>"))))
3130 (setq line (replace-match rpl t t line)
3131 start (+ start (length rpl))))
3133 ;; TODO items
3134 (if (and (string-match org-todo-line-regexp line)
3135 (match-beginning 2))
3137 (setq line
3138 (concat (substring line 0 (match-beginning 2))
3139 "<span class=\""
3140 (if (member (match-string 2 line)
3141 org-done-keywords)
3142 "done" "todo")
3143 "\">" (match-string 2 line)
3144 "</span>" (substring line (match-end 2)))))
3146 ;; Does this contain a reference to a footnote?
3147 (when org-export-with-footnotes
3148 (setq start 0)
3149 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3150 (if (get-text-property (match-beginning 2) 'org-protected line)
3151 (setq start (match-end 2))
3152 (let ((n (match-string 2 line)))
3153 (setq line
3154 (replace-match
3155 (format
3156 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3157 (match-string 1 line) n n n)
3158 t t line))))))
3160 (cond
3161 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3162 ;; This is a headline
3163 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3164 txt (match-string 2 line))
3165 (if (string-match quote-re0 txt)
3166 (setq txt (replace-match "" t t txt)))
3167 (if (<= level (max umax umax-toc))
3168 (setq head-count (+ head-count 1)))
3169 (when in-local-list
3170 ;; Close any local lists before inserting a new header line
3171 (while local-list-type
3172 (org-close-li (car local-list-type))
3173 (insert (format "</%sl>\n" (car local-list-type)))
3174 (pop local-list-type))
3175 (setq local-list-indent nil
3176 in-local-list nil))
3177 (setq first-heading-pos (or first-heading-pos (point)))
3178 (org-html-level-start level txt umax
3179 (and org-export-with-toc (<= level umax))
3180 head-count)
3181 ;; QUOTES
3182 (when (string-match quote-re line)
3183 (insert "<pre>")
3184 (setq inquote t)))
3186 ((and org-export-with-tables
3187 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3188 (if (not table-open)
3189 ;; New table starts
3190 (setq table-open t table-buffer nil table-orig-buffer nil))
3191 ;; Accumulate lines
3192 (setq table-buffer (cons line table-buffer)
3193 table-orig-buffer (cons origline table-orig-buffer))
3194 (when (or (not lines)
3195 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3196 (car lines))))
3197 (setq table-open nil
3198 table-buffer (nreverse table-buffer)
3199 table-orig-buffer (nreverse table-orig-buffer))
3200 (org-close-par-maybe)
3201 (insert (org-format-table-html table-buffer table-orig-buffer))))
3203 ;; Normal lines
3204 (when (string-match
3205 (cond
3206 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3207 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3208 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3209 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3210 line)
3211 (setq ind (org-get-string-indentation line)
3212 item-type (if (match-beginning 4) "o" "u")
3213 starter (if (match-beginning 2)
3214 (substring (match-string 2 line) 0 -1))
3215 line (substring line (match-beginning 5))
3216 item-tag nil)
3217 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3218 (setq item-type "d"
3219 item-tag (match-string 1 line)
3220 line (substring line (match-end 0))))
3221 (when (and (not (equal item-type "d"))
3222 (not (string-match "[^ \t]" line)))
3223 ;; empty line. Pretend indentation is large.
3224 (setq ind (if org-empty-line-terminates-plain-lists
3226 (1+ (or (car local-list-indent) 1)))))
3227 (setq didclose nil)
3228 (while (and in-local-list
3229 (or (and (= ind (car local-list-indent))
3230 (not starter))
3231 (< ind (car local-list-indent))))
3232 (setq didclose t)
3233 (org-close-li (car local-list-type))
3234 (insert (format "</%sl>\n" (car local-list-type)))
3235 (pop local-list-type) (pop local-list-indent)
3236 (setq in-local-list local-list-indent))
3237 (cond
3238 ((and starter
3239 (or (not in-local-list)
3240 (> ind (car local-list-indent))))
3241 ;; Start new (level of) list
3242 (org-close-par-maybe)
3243 (insert (cond
3244 ((equal item-type "u") "<ul>\n<li>\n")
3245 ((equal item-type "o") "<ol>\n<li>\n")
3246 ((equal item-type "d")
3247 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3248 (push item-type local-list-type)
3249 (push ind local-list-indent)
3250 (setq in-local-list t))
3251 (starter
3252 ;; continue current list
3253 (org-close-li (car local-list-type))
3254 (insert (cond
3255 ((equal (car local-list-type) "d")
3256 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3257 (t "<li>\n"))))
3258 (didclose
3259 ;; we did close a list, normal text follows: need <p>
3260 (org-open-par)))
3261 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3262 (setq line
3263 (replace-match
3264 (if (equal (match-string 1 line) "X")
3265 "<b>[X]</b>"
3266 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3267 t t line))))
3269 ;; Empty lines start a new paragraph. If hand-formatted lists
3270 ;; are not fully interpreted, lines starting with "-", "+", "*"
3271 ;; also start a new paragraph.
3272 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3274 ;; Is this the start of a footnote?
3275 (when org-export-with-footnotes
3276 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3277 (org-close-par-maybe)
3278 (let ((n (match-string 1 line)))
3279 (setq line (replace-match
3280 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3281 (setq line (concat line "</p>")))))
3283 ;; Check if the line break needs to be conserved
3284 (cond
3285 ((string-match "\\\\\\\\[ \t]*$" line)
3286 (setq line (replace-match "<br/>" t t line)))
3287 (org-export-preserve-breaks
3288 (setq line (concat line "<br/>"))))
3290 (insert line "\n")))))
3292 ;; Properly close all local lists and other lists
3293 (when inquote (insert "</pre>\n"))
3294 (when in-local-list
3295 ;; Close any local lists before inserting a new header line
3296 (while local-list-type
3297 (org-close-li (car local-list-type))
3298 (insert (format "</%sl>\n" (car local-list-type)))
3299 (pop local-list-type))
3300 (setq local-list-indent nil
3301 in-local-list nil))
3302 (org-html-level-start 1 nil umax
3303 (and org-export-with-toc (<= level umax))
3304 head-count)
3305 ;; the </div> to lose the last text-... div.
3306 (insert "</div>\n")
3308 (unless body-only
3309 (when (plist-get opt-plist :auto-postamble)
3310 (insert "<div id=\"postamble\">")
3311 (when (and org-export-author-info author)
3312 (insert "<p class=\"author\"> "
3313 (nth 1 lang-words) ": " author "\n")
3314 (when email
3315 (if (listp (split-string email ",+ *"))
3316 (mapc (lambda(e)
3317 (insert "<a href=\"mailto:" e "\">&lt;"
3318 e "&gt;</a>\n"))
3319 (split-string email ",+ *"))
3320 (insert "<a href=\"mailto:" email "\">&lt;"
3321 email "&gt;</a>\n")))
3322 (insert "</p>\n"))
3323 (when (and date org-export-time-stamp-file)
3324 (insert "<p class=\"date\"> "
3325 (nth 2 lang-words) ": "
3326 date "</p>\n"))
3327 (when org-export-creator-info
3328 (insert (format "<p>HTML generated by org-mode %s in emacs %s<\p>\n"
3329 org-version emacs-major-version)))
3330 (insert "</div>"))
3332 (if org-export-html-with-timestamp
3333 (insert org-export-html-html-helper-timestamp))
3334 (insert (or (plist-get opt-plist :postamble) ""))
3335 (insert "</body>\n</html>\n"))
3337 (normal-mode)
3338 (if (eq major-mode default-major-mode) (html-mode))
3340 ;; insert the table of contents
3341 (goto-char (point-min))
3342 (when thetoc
3343 (if (or (re-search-forward
3344 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3345 (re-search-forward
3346 "\\[TABLE-OF-CONTENTS\\]" nil t))
3347 (progn
3348 (goto-char (match-beginning 0))
3349 (replace-match ""))
3350 (goto-char first-heading-pos)
3351 (when (looking-at "\\s-*</p>")
3352 (goto-char (match-end 0))
3353 (insert "\n")))
3354 (insert "<div id=\"table-of-contents\">\n")
3355 (mapc 'insert thetoc)
3356 (insert "</div>\n"))
3357 ;; remove empty paragraphs and lists
3358 (goto-char (point-min))
3359 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3360 (replace-match ""))
3361 (goto-char (point-min))
3362 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3363 (replace-match ""))
3364 (goto-char (point-min))
3365 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3366 (replace-match ""))
3367 ;; Convert whitespace place holders
3368 (goto-char (point-min))
3369 (let (beg end n)
3370 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3371 (setq n (get-text-property beg 'org-whitespace)
3372 end (next-single-property-change beg 'org-whitespace))
3373 (goto-char beg)
3374 (delete-region beg end)
3375 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3376 (make-string n ?x)))))
3377 (or to-buffer (save-buffer))
3378 (goto-char (point-min))
3379 (message "Exporting... done")
3380 (if (eq to-buffer 'string)
3381 (prog1 (buffer-substring (point-min) (point-max))
3382 (kill-buffer (current-buffer)))
3383 (current-buffer)))))
3386 (defvar org-table-colgroup-info nil)
3387 (defun org-format-table-ascii (lines)
3388 "Format a table for ascii export."
3389 (if (stringp lines)
3390 (setq lines (org-split-string lines "\n")))
3391 (if (not (string-match "^[ \t]*|" (car lines)))
3392 ;; Table made by table.el - test for spanning
3393 lines
3395 ;; A normal org table
3396 ;; Get rid of hlines at beginning and end
3397 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3398 (setq lines (nreverse lines))
3399 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3400 (setq lines (nreverse lines))
3401 (when org-export-table-remove-special-lines
3402 ;; Check if the table has a marking column. If yes remove the
3403 ;; column and the special lines
3404 (setq lines (org-table-clean-before-export lines)))
3405 ;; Get rid of the vertical lines except for grouping
3406 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3407 rtn line vl1 start)
3408 (while (setq line (pop lines))
3409 (if (string-match org-table-hline-regexp line)
3410 (and (string-match "|\\(.*\\)|" line)
3411 (setq line (replace-match " \\1" t nil line)))
3412 (setq start 0 vl1 vl)
3413 (while (string-match "|" line start)
3414 (setq start (match-end 0))
3415 (or (pop vl1) (setq line (replace-match " " t t line)))))
3416 (push line rtn))
3417 (nreverse rtn))))
3419 (defun org-colgroup-info-to-vline-list (info)
3420 (let (vl new last)
3421 (while info
3422 (setq last new new (pop info))
3423 (if (or (memq last '(:end :startend))
3424 (memq new '(:start :startend)))
3425 (push t vl)
3426 (push nil vl)))
3427 (setq vl (nreverse vl))
3428 (and vl (setcar vl nil))
3429 vl))
3431 (defvar org-table-number-regexp) ; defined in org-table.el
3432 (defun org-format-table-html (lines olines)
3433 "Find out which HTML converter to use and return the HTML code."
3434 (if (stringp lines)
3435 (setq lines (org-split-string lines "\n")))
3436 (if (string-match "^[ \t]*|" (car lines))
3437 ;; A normal org table
3438 (org-format-org-table-html lines)
3439 ;; Table made by table.el - test for spanning
3440 (let* ((hlines (delq nil (mapcar
3441 (lambda (x)
3442 (if (string-match "^[ \t]*\\+-" x) x
3443 nil))
3444 lines)))
3445 (first (car hlines))
3446 (ll (and (string-match "\\S-+" first)
3447 (match-string 0 first)))
3448 (re (concat "^[ \t]*" (regexp-quote ll)))
3449 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3450 hlines))))
3451 (if (and (not spanning)
3452 (not org-export-prefer-native-exporter-for-tables))
3453 ;; We can use my own converter with HTML conversions
3454 (org-format-table-table-html lines)
3455 ;; Need to use the code generator in table.el, with the original text.
3456 (org-format-table-table-html-using-table-generate-source olines)))))
3458 (defvar org-table-number-fraction) ; defined in org-table.el
3459 (defun org-format-org-table-html (lines &optional splice)
3460 "Format a table into HTML."
3461 (require 'org-table)
3462 ;; Get rid of hlines at beginning and end
3463 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3464 (setq lines (nreverse lines))
3465 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3466 (setq lines (nreverse lines))
3467 (when org-export-table-remove-special-lines
3468 ;; Check if the table has a marking column. If yes remove the
3469 ;; column and the special lines
3470 (setq lines (org-table-clean-before-export lines)))
3472 (let ((head (and org-export-highlight-first-table-line
3473 (delq nil (mapcar
3474 (lambda (x) (string-match "^[ \t]*|-" x))
3475 (cdr lines)))))
3476 (nlines 0) fnum i
3477 tbopen line fields html gr colgropen)
3478 (if splice (setq head nil))
3479 (unless splice (push (if head "<thead>" "<tbody>") html))
3480 (setq tbopen t)
3481 (while (setq line (pop lines))
3482 (catch 'next-line
3483 (if (string-match "^[ \t]*|-" line)
3484 (progn
3485 (unless splice
3486 (push (if head "</thead>" "</tbody>") html)
3487 (if lines (push "<tbody>" html) (setq tbopen nil)))
3488 (setq head nil) ;; head ends here, first time around
3489 ;; ignore this line
3490 (throw 'next-line t)))
3491 ;; Break the line into fields
3492 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3493 (unless fnum (setq fnum (make-vector (length fields) 0)))
3494 (setq nlines (1+ nlines) i -1)
3495 (push (concat "<tr>"
3496 (mapconcat
3497 (lambda (x)
3498 (setq i (1+ i))
3499 (if (and (< i nlines)
3500 (string-match org-table-number-regexp x))
3501 (incf (aref fnum i)))
3502 (if head
3503 (concat (car org-export-table-header-tags) x
3504 (cdr org-export-table-header-tags))
3505 (concat (car org-export-table-data-tags) x
3506 (cdr org-export-table-data-tags))))
3507 fields "")
3508 "</tr>")
3509 html)))
3510 (unless splice (if tbopen (push "</tbody>" html)))
3511 (unless splice (push "</table>\n" html))
3512 (setq html (nreverse html))
3513 (unless splice
3514 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3515 (push (mapconcat
3516 (lambda (x)
3517 (setq gr (pop org-table-colgroup-info))
3518 (format "%s<col align=\"%s\"></col>%s"
3519 (if (memq gr '(:start :startend))
3520 (prog1
3521 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3522 (setq colgropen t))
3524 (if (> (/ (float x) nlines) org-table-number-fraction)
3525 "right" "left")
3526 (if (memq gr '(:end :startend))
3527 (progn (setq colgropen nil) "</colgroup>")
3528 "")))
3529 fnum "")
3530 html)
3531 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3532 (push html-table-tag html))
3533 (concat (mapconcat 'identity html "\n") "\n")))
3535 (defun org-table-clean-before-export (lines)
3536 "Check if the table has a marking column.
3537 If yes remove the column and the special lines."
3538 (setq org-table-colgroup-info nil)
3539 (if (memq nil
3540 (mapcar
3541 (lambda (x) (or (string-match "^[ \t]*|-" x)
3542 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3543 lines))
3544 (progn
3545 (setq org-table-clean-did-remove-column nil)
3546 (delq nil
3547 (mapcar
3548 (lambda (x)
3549 (cond
3550 ((string-match "^[ \t]*| */ *|" x)
3551 (setq org-table-colgroup-info
3552 (mapcar (lambda (x)
3553 (cond ((member x '("<" "&lt;")) :start)
3554 ((member x '(">" "&gt;")) :end)
3555 ((member x '("<>" "&lt;&gt;")) :startend)
3556 (t nil)))
3557 (org-split-string x "[ \t]*|[ \t]*")))
3558 nil)
3559 (t x)))
3560 lines)))
3561 (setq org-table-clean-did-remove-column t)
3562 (delq nil
3563 (mapcar
3564 (lambda (x)
3565 (cond
3566 ((string-match "^[ \t]*| */ *|" x)
3567 (setq org-table-colgroup-info
3568 (mapcar (lambda (x)
3569 (cond ((member x '("<" "&lt;")) :start)
3570 ((member x '(">" "&gt;")) :end)
3571 ((member x '("<>" "&lt;&gt;")) :startend)
3572 (t nil)))
3573 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3574 nil)
3575 ((string-match "^[ \t]*| *[!_^/] *|" x)
3576 nil) ; ignore this line
3577 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3578 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3579 ;; remove the first column
3580 (replace-match "\\1|" t nil x))))
3581 lines))))
3583 (defun org-format-table-table-html (lines)
3584 "Format a table generated by table.el into HTML.
3585 This conversion does *not* use `table-generate-source' from table.el.
3586 This has the advantage that Org-mode's HTML conversions can be used.
3587 But it has the disadvantage, that no cell- or row-spanning is allowed."
3588 (let (line field-buffer
3589 (head org-export-highlight-first-table-line)
3590 fields html empty)
3591 (setq html (concat html-table-tag "\n"))
3592 (while (setq line (pop lines))
3593 (setq empty "&nbsp;")
3594 (catch 'next-line
3595 (if (string-match "^[ \t]*\\+-" line)
3596 (progn
3597 (if field-buffer
3598 (progn
3599 (setq
3600 html
3601 (concat
3602 html
3603 "<tr>"
3604 (mapconcat
3605 (lambda (x)
3606 (if (equal x "") (setq x empty))
3607 (if head
3608 (concat (car org-export-table-header-tags) x
3609 (cdr org-export-table-header-tags))
3610 (concat (car org-export-table-data-tags) x
3611 (cdr org-export-table-data-tags))))
3612 field-buffer "\n")
3613 "</tr>\n"))
3614 (setq head nil)
3615 (setq field-buffer nil)))
3616 ;; Ignore this line
3617 (throw 'next-line t)))
3618 ;; Break the line into fields and store the fields
3619 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3620 (if field-buffer
3621 (setq field-buffer (mapcar
3622 (lambda (x)
3623 (concat x "<br/>" (pop fields)))
3624 field-buffer))
3625 (setq field-buffer fields))))
3626 (setq html (concat html "</table>\n"))
3627 html))
3629 (defun org-format-table-table-html-using-table-generate-source (lines)
3630 "Format a table into html, using `table-generate-source' from table.el.
3631 This has the advantage that cell- or row-spanning is allowed.
3632 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3633 (require 'table)
3634 (with-current-buffer (get-buffer-create " org-tmp1 ")
3635 (erase-buffer)
3636 (insert (mapconcat 'identity lines "\n"))
3637 (goto-char (point-min))
3638 (if (not (re-search-forward "|[^+]" nil t))
3639 (error "Error processing table"))
3640 (table-recognize-table)
3641 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3642 (table-generate-source 'html " org-tmp2 ")
3643 (set-buffer " org-tmp2 ")
3644 (buffer-substring (point-min) (point-max))))
3646 (defun org-export-splice-style (style extra)
3647 "Splice EXTRA into STYLE, just before \"</style>\"."
3648 (if (and (stringp extra)
3649 (string-match "\\S-" extra)
3650 (string-match "</style>" style))
3651 (concat (substring style 0 (match-beginning 0))
3652 "\n" extra "\n"
3653 (substring style (match-beginning 0)))
3654 style))
3656 (defun org-html-handle-time-stamps (s)
3657 "Format time stamps in string S, or remove them."
3658 (catch 'exit
3659 (let (r b)
3660 (while (string-match org-maybe-keyword-time-regexp s)
3661 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3662 ;; never export CLOCK
3663 (throw 'exit ""))
3664 (or b (setq b (substring s 0 (match-beginning 0))))
3665 (if (not org-export-with-timestamps)
3666 (setq r (concat r (substring s 0 (match-beginning 0)))
3667 s (substring s (match-end 0)))
3668 (setq r (concat
3669 r (substring s 0 (match-beginning 0))
3670 (if (match-end 1)
3671 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3672 (match-string 1 s)))
3673 (format " @<span class=\"timestamp\">%s@</span>"
3674 (substring
3675 (org-translate-time (match-string 3 s)) 1 -1)))
3676 s (substring s (match-end 0)))))
3677 ;; Line break if line started and ended with time stamp stuff
3678 (if (not r)
3680 (setq r (concat r s))
3681 (unless (string-match "\\S-" (concat b s))
3682 (setq r (concat r "@<br/>")))
3683 r))))
3685 (defun org-export-htmlize-region-for-paste (beg end)
3686 "Convert the region to HTML, using htmlize.el.
3687 This is much like `htmlize-region-for-paste', only that it uses
3688 the settings define in the org-... variables."
3689 (let* ((htmlize-output-type org-export-htmlize-output-type)
3690 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3691 (htmlbuf (htmlize-region beg end)))
3692 (unwind-protect
3693 (with-current-buffer htmlbuf
3694 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3695 (plist-get htmlize-buffer-places 'content-end)))
3696 (kill-buffer htmlbuf))))
3698 ;;;###autoload
3699 (defun org-export-htmlize-generate-css ()
3700 "Create the CSS for all font definitions in the current Emacs session.
3701 Use this to create face definitions in your CSS style file that can then
3702 be used by code snippets transformed by htmlize.
3703 This command just produces a buffer that contains class definitions for all
3704 faces used in the current Emacs session. You can copy and paste the ones you
3705 need into your CSS file.
3707 If you then set `org-export-htmlize-output-type' to `css', calls to
3708 the function `org-export-htmlize-region-for-paste' will produce code
3709 that uses these same face definitions."
3710 (interactive)
3711 (require 'htmlize)
3712 (and (get-buffer "*html*") (kill-buffer "*html*"))
3713 (with-temp-buffer
3714 (let ((fl (face-list))
3715 (htmlize-css-name-prefix "org-")
3716 (htmlize-output-type 'css)
3717 f i)
3718 (while (setq f (pop fl)
3719 i (and f (face-attribute f :inherit)))
3720 (when (and (symbolp f) (or (not i) (not (listp i))))
3721 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3722 (htmlize-region (point-min) (point-max))))
3723 (switch-to-buffer "*html*")
3724 (goto-char (point-min))
3725 (if (re-search-forward "<style" nil t)
3726 (delete-region (point-min) (match-beginning 0)))
3727 (if (re-search-forward "</style>" nil t)
3728 (delete-region (1+ (match-end 0)) (point-max)))
3729 (beginning-of-line 1)
3730 (if (looking-at " +") (replace-match ""))
3731 (goto-char (point-min)))
3733 (defun org-html-protect (s)
3734 ;; convert & to &amp;, < to &lt; and > to &gt;
3735 (let ((start 0))
3736 (while (string-match "&" s start)
3737 (setq s (replace-match "&amp;" t t s)
3738 start (1+ (match-beginning 0))))
3739 (while (string-match "<" s)
3740 (setq s (replace-match "&lt;" t t s)))
3741 (while (string-match ">" s)
3742 (setq s (replace-match "&gt;" t t s))))
3745 (defun org-export-cleanup-toc-line (s)
3746 "Remove tags and time staps from lines going into the toc."
3747 (when (memq org-export-with-tags '(not-in-toc nil))
3748 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3749 (setq s (replace-match "" t t s))))
3750 (when org-export-remove-timestamps-from-toc
3751 (while (string-match org-maybe-keyword-time-regexp s)
3752 (setq s (replace-match "" t t s))))
3753 (while (string-match org-bracket-link-regexp s)
3754 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3755 t t s)))
3758 (defun org-html-expand (string)
3759 "Prepare STRING for HTML export. Applies all active conversions.
3760 If there are links in the string, don't modify these."
3761 (let* ((re (concat org-bracket-link-regexp "\\|"
3762 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3763 m s l res)
3764 (while (setq m (string-match re string))
3765 (setq s (substring string 0 m)
3766 l (match-string 0 string)
3767 string (substring string (match-end 0)))
3768 (push (org-html-do-expand s) res)
3769 (push l res))
3770 (push (org-html-do-expand string) res)
3771 (apply 'concat (nreverse res))))
3773 (defun org-html-do-expand (s)
3774 "Apply all active conversions to translate special ASCII to HTML."
3775 (setq s (org-html-protect s))
3776 (if org-export-html-expand
3777 (let ((start 0))
3778 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3779 (setq s (replace-match "<\\1>" t nil s)))))
3780 (if org-export-with-emphasize
3781 (setq s (org-export-html-convert-emphasize s)))
3782 (if org-export-with-special-strings
3783 (setq s (org-export-html-convert-special-strings s)))
3784 (if org-export-with-sub-superscripts
3785 (setq s (org-export-html-convert-sub-super s)))
3786 (if org-export-with-TeX-macros
3787 (let ((start 0) wd ass)
3788 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3789 (if (get-text-property (match-beginning 0) 'org-protected s)
3790 (setq start (match-end 0))
3791 (setq wd (match-string 1 s))
3792 (if (setq ass (assoc wd org-html-entities))
3793 (setq s (replace-match (or (cdr ass)
3794 (concat "&" (car ass) ";"))
3795 t t s))
3796 (setq start (+ start (length wd))))))))
3799 (defun org-create-multibrace-regexp (left right n)
3800 "Create a regular expression which will match a balanced sexp.
3801 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3802 as single character strings.
3803 The regexp returned will match the entire expression including the
3804 delimiters. It will also define a single group which contains the
3805 match except for the outermost delimiters. The maximum depth of
3806 stacked delimiters is N. Escaping delimiters is not possible."
3807 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3808 (or "\\|")
3809 (re nothing)
3810 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3811 (while (> n 1)
3812 (setq n (1- n)
3813 re (concat re or next)
3814 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3815 (concat left "\\(" re "\\)" right)))
3817 (defvar org-match-substring-regexp
3818 (concat
3819 "\\([^\\]\\)\\([_^]\\)\\("
3820 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3821 "\\|"
3822 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3823 "\\|"
3824 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3825 "The regular expression matching a sub- or superscript.")
3827 (defvar org-match-substring-with-braces-regexp
3828 (concat
3829 "\\([^\\]\\)\\([_^]\\)\\("
3830 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3831 "\\)")
3832 "The regular expression matching a sub- or superscript, forcing braces.")
3834 (defconst org-export-html-special-string-regexps
3835 '(("\\\\-" . "&shy;")
3836 ("---\\([^-]\\)" . "&mdash;\\1")
3837 ("--\\([^-]\\)" . "&ndash;\\1")
3838 ("\\.\\.\\." . "&hellip;"))
3839 "Regular expressions for special string conversion.")
3841 (defun org-export-html-convert-special-strings (string)
3842 "Convert special characters in STRING to HTML."
3843 (let ((all org-export-html-special-string-regexps)
3844 e a re rpl start)
3845 (while (setq a (pop all))
3846 (setq re (car a) rpl (cdr a) start 0)
3847 (while (string-match re string start)
3848 (if (get-text-property (match-beginning 0) 'org-protected string)
3849 (setq start (match-end 0))
3850 (setq string (replace-match rpl t nil string)))))
3851 string))
3853 (defun org-export-html-convert-sub-super (string)
3854 "Convert sub- and superscripts in STRING to HTML."
3855 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3856 (while (string-match org-match-substring-regexp string s)
3857 (cond
3858 ((and requireb (match-end 8)) (setq s (match-end 2)))
3859 ((get-text-property (match-beginning 2) 'org-protected string)
3860 (setq s (match-end 2)))
3862 (setq s (match-end 1)
3863 key (if (string= (match-string 2 string) "_") "sub" "sup")
3864 c (or (match-string 8 string)
3865 (match-string 6 string)
3866 (match-string 5 string))
3867 string (replace-match
3868 (concat (match-string 1 string)
3869 "<" key ">" c "</" key ">")
3870 t t string)))))
3871 (while (string-match "\\\\\\([_^]\\)" string)
3872 (setq string (replace-match (match-string 1 string) t t string)))
3873 string))
3875 (defun org-export-html-convert-emphasize (string)
3876 "Apply emphasis."
3877 (let ((s 0) rpl)
3878 (while (string-match org-emph-re string s)
3879 (if (not (equal
3880 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3881 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3882 (setq s (match-beginning 0)
3884 (concat
3885 (match-string 1 string)
3886 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3887 (match-string 4 string)
3888 (nth 3 (assoc (match-string 3 string)
3889 org-emphasis-alist))
3890 (match-string 5 string))
3891 string (replace-match rpl t t string)
3892 s (+ s (- (length rpl) 2)))
3893 (setq s (1+ s))))
3894 string))
3896 (defvar org-par-open nil)
3897 (defun org-open-par ()
3898 "Insert <p>, but first close previous paragraph if any."
3899 (org-close-par-maybe)
3900 (insert "\n<p>")
3901 (setq org-par-open t))
3902 (defun org-close-par-maybe ()
3903 "Close paragraph if there is one open."
3904 (when org-par-open
3905 (insert "</p>")
3906 (setq org-par-open nil)))
3907 (defun org-close-li (&optional type)
3908 "Close <li> if necessary."
3909 (org-close-par-maybe)
3910 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
3912 (defvar body-only) ; dynamically scoped into this.
3913 (defun org-html-level-start (level title umax with-toc head-count)
3914 "Insert a new level in HTML export.
3915 When TITLE is nil, just close all open levels."
3916 (org-close-par-maybe)
3917 (let ((target (and title (org-get-text-property-any 0 'target title)))
3918 (l org-level-max)
3919 snumber)
3920 (while (>= l level)
3921 (if (aref org-levels-open (1- l))
3922 (progn
3923 (org-html-level-close l umax)
3924 (aset org-levels-open (1- l) nil)))
3925 (setq l (1- l)))
3926 (when title
3927 ;; If title is nil, this means this function is called to close
3928 ;; all levels, so the rest is done only if title is given
3929 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3930 (setq title (replace-match
3931 (if org-export-with-tags
3932 (save-match-data
3933 (concat
3934 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3935 (mapconcat 'identity (org-split-string
3936 (match-string 1 title) ":")
3937 "&nbsp;")
3938 "</span>"))
3940 t t title)))
3941 (if (> level umax)
3942 (progn
3943 (if (aref org-levels-open (1- level))
3944 (progn
3945 (org-close-li)
3946 (if target
3947 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3948 (insert "<li>" title "<br/>\n")))
3949 (aset org-levels-open (1- level) t)
3950 (org-close-par-maybe)
3951 (if target
3952 (insert (format "<ul>\n<li id=\"%s\">" target)
3953 title "<br/>\n")
3954 (insert "<ul>\n<li>" title "<br/>\n"))))
3955 (aset org-levels-open (1- level) t)
3956 (setq snumber (org-section-number level))
3957 (if (and org-export-with-section-numbers (not body-only))
3958 (setq title (concat snumber " " title)))
3959 (setq level (+ level org-export-html-toplevel-hlevel -1))
3960 (unless (= head-count 1) (insert "\n</div>\n"))
3961 (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"
3962 snumber level level snumber title level snumber))
3963 (org-open-par)))))
3965 (defun org-get-text-property-any (pos prop &optional object)
3966 (or (get-text-property pos prop object)
3967 (and (setq pos (next-single-property-change pos prop object))
3968 (get-text-property pos prop object))))
3970 (defun org-html-level-close (level max-outline-level)
3971 "Terminate one level in HTML export."
3972 (if (<= level max-outline-level)
3973 (insert "</div>\n")
3974 (org-close-li)
3975 (insert "</ul>\n")))
3977 ;;; iCalendar export
3979 ;;;###autoload
3980 (defun org-export-icalendar-this-file ()
3981 "Export current file as an iCalendar file.
3982 The iCalendar file will be located in the same directory as the Org-mode
3983 file, but with extension `.ics'."
3984 (interactive)
3985 (org-export-icalendar nil buffer-file-name))
3987 ;;;###autoload
3988 (defun org-export-icalendar-all-agenda-files ()
3989 "Export all files in `org-agenda-files' to iCalendar .ics files.
3990 Each iCalendar file will be located in the same directory as the Org-mode
3991 file, but with extension `.ics'."
3992 (interactive)
3993 (apply 'org-export-icalendar nil (org-agenda-files t)))
3995 ;;;###autoload
3996 (defun org-export-icalendar-combine-agenda-files ()
3997 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3998 The file is stored under the name `org-combined-agenda-icalendar-file'."
3999 (interactive)
4000 (apply 'org-export-icalendar t (org-agenda-files t)))
4002 (defun org-export-icalendar (combine &rest files)
4003 "Create iCalendar files for all elements of FILES.
4004 If COMBINE is non-nil, combine all calendar entries into a single large
4005 file and store it under the name `org-combined-agenda-icalendar-file'."
4006 (save-excursion
4007 (org-prepare-agenda-buffers files)
4008 (let* ((dir (org-export-directory
4009 :ical (list :publishing-directory
4010 org-export-publishing-directory)))
4011 file ical-file ical-buffer category started org-agenda-new-buffers)
4012 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4013 (when combine
4014 (setq ical-file
4015 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4016 org-combined-agenda-icalendar-file
4017 (expand-file-name org-combined-agenda-icalendar-file dir))
4018 ical-buffer (org-get-agenda-file-buffer ical-file))
4019 (set-buffer ical-buffer) (erase-buffer))
4020 (while (setq file (pop files))
4021 (catch 'nextfile
4022 (org-check-agenda-file file)
4023 (set-buffer (org-get-agenda-file-buffer file))
4024 (unless combine
4025 (setq ical-file (concat (file-name-as-directory dir)
4026 (file-name-sans-extension
4027 (file-name-nondirectory buffer-file-name))
4028 ".ics"))
4029 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4030 (with-current-buffer ical-buffer (erase-buffer)))
4031 (setq category (or org-category
4032 (file-name-sans-extension
4033 (file-name-nondirectory buffer-file-name))))
4034 (if (symbolp category) (setq category (symbol-name category)))
4035 (let ((standard-output ical-buffer))
4036 (if combine
4037 (and (not started) (setq started t)
4038 (org-start-icalendar-file org-icalendar-combined-name))
4039 (org-start-icalendar-file category))
4040 (org-print-icalendar-entries combine)
4041 (when (or (and combine (not files)) (not combine))
4042 (org-finish-icalendar-file)
4043 (set-buffer ical-buffer)
4044 (run-hooks 'org-before-save-iCalendar-file-hook)
4045 (save-buffer)
4046 (run-hooks 'org-after-save-iCalendar-file-hook)
4047 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4048 ))))
4049 (org-release-buffers org-agenda-new-buffers))))
4051 (defvar org-before-save-iCalendar-file-hook nil
4052 "Hook run before an iCalendar file has been saved.
4053 This can be used to modify the result of the export.")
4055 (defvar org-after-save-iCalendar-file-hook nil
4056 "Hook run after an iCalendar file has been saved.
4057 The iCalendar buffer is still current when this hook is run.
4058 A good way to use this is to tell a desktop calenndar application to re-read
4059 the iCalendar file.")
4061 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4062 (defun org-print-icalendar-entries (&optional combine)
4063 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4064 When COMBINE is non nil, add the category to each line."
4065 (require 'org-agenda)
4066 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4067 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4068 (dts (org-ical-ts-to-string
4069 (format-time-string (cdr org-time-stamp-formats) (current-time))
4070 "DTSTART"))
4071 hd ts ts2 state status (inc t) pos b sexp rrule
4072 scheduledp deadlinep todo prefix due start
4073 tmp pri category entry location summary desc uid
4074 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4075 (org-refresh-category-properties)
4076 (save-excursion
4077 (goto-char (point-min))
4078 (while (re-search-forward re1 nil t)
4079 (catch :skip
4080 (org-agenda-skip)
4081 (when (boundp 'org-icalendar-verify-function)
4082 (unless (funcall org-icalendar-verify-function)
4083 (outline-next-heading)
4084 (backward-char 1)
4085 (throw :skip nil)))
4086 (setq pos (match-beginning 0)
4087 ts (match-string 0)
4088 inc t
4089 hd (condition-case nil
4090 (org-icalendar-cleanup-string
4091 (org-get-heading))
4092 (error (throw :skip nil)))
4093 summary (org-icalendar-cleanup-string
4094 (org-entry-get nil "SUMMARY"))
4095 desc (org-icalendar-cleanup-string
4096 (or (org-entry-get nil "DESCRIPTION")
4097 (and org-icalendar-include-body (org-get-entry)))
4098 t org-icalendar-include-body)
4099 location (org-icalendar-cleanup-string
4100 (org-entry-get nil "LOCATION"))
4101 uid (if org-icalendar-store-UID
4102 (org-id-get-create)
4103 (or (org-id-get) (org-id-new)))
4104 category (org-get-category)
4105 deadlinep nil scheduledp nil)
4106 (if (looking-at re2)
4107 (progn
4108 (goto-char (match-end 0))
4109 (setq ts2 (match-string 1)
4110 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4111 (setq tmp (buffer-substring (max (point-min)
4112 (- pos org-ds-keyword-length))
4113 pos)
4114 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4115 (progn
4116 (setq inc nil)
4117 (replace-match "\\1" t nil ts))
4119 deadlinep (string-match org-deadline-regexp tmp)
4120 scheduledp (string-match org-scheduled-regexp tmp)
4121 todo (org-get-todo-state)
4122 ;; donep (org-entry-is-done-p)
4124 (when (and
4125 deadlinep
4126 (if todo
4127 (not (memq 'event-if-todo org-icalendar-use-deadline))
4128 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4129 (throw :skip t))
4130 (when (and
4131 scheduledp
4132 (if todo
4133 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4134 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4135 (throw :skip t))
4136 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4137 (if (or (string-match org-tr-regexp hd)
4138 (string-match org-ts-regexp hd))
4139 (setq hd (replace-match "" t t hd)))
4140 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4141 (setq rrule
4142 (concat "\nRRULE:FREQ="
4143 (cdr (assoc
4144 (match-string 2 ts)
4145 '(("d" . "DAILY")("w" . "WEEKLY")
4146 ("m" . "MONTHLY")("y" . "YEARLY"))))
4147 ";INTERVAL=" (match-string 1 ts)))
4148 (setq rrule ""))
4149 (setq summary (or summary hd))
4150 (if (string-match org-bracket-link-regexp summary)
4151 (setq summary
4152 (replace-match (if (match-end 3)
4153 (match-string 3 summary)
4154 (match-string 1 summary))
4155 t t summary)))
4156 (if deadlinep (setq summary (concat "DL: " summary)))
4157 (if scheduledp (setq summary (concat "S: " summary)))
4158 (if (string-match "\\`<%%" ts)
4159 (with-current-buffer sexp-buffer
4160 (insert (substring ts 1 -1) " " summary "\n"))
4161 (princ (format "BEGIN:VEVENT
4162 UID: %s
4164 %s%s
4165 SUMMARY:%s%s%s
4166 CATEGORIES:%s
4167 END:VEVENT\n"
4168 (concat prefix uid)
4169 (org-ical-ts-to-string ts "DTSTART")
4170 (org-ical-ts-to-string ts2 "DTEND" inc)
4171 rrule summary
4172 (if (and desc (string-match "\\S-" desc))
4173 (concat "\nDESCRIPTION: " desc) "")
4174 (if (and location (string-match "\\S-" location))
4175 (concat "\nLOCATION: " location) "")
4176 category)))))
4177 (when (and org-icalendar-include-sexps
4178 (condition-case nil (require 'icalendar) (error nil))
4179 (fboundp 'icalendar-export-region))
4180 ;; Get all the literal sexps
4181 (goto-char (point-min))
4182 (while (re-search-forward "^&?%%(" nil t)
4183 (catch :skip
4184 (org-agenda-skip)
4185 (setq b (match-beginning 0))
4186 (goto-char (1- (match-end 0)))
4187 (forward-sexp 1)
4188 (end-of-line 1)
4189 (setq sexp (buffer-substring b (point)))
4190 (with-current-buffer sexp-buffer
4191 (insert sexp "\n"))))
4192 (princ (org-diary-to-ical-string sexp-buffer))
4193 (kill-buffer sexp-buffer))
4195 (when org-icalendar-include-todo
4196 (setq prefix "TODO-")
4197 (goto-char (point-min))
4198 (while (re-search-forward org-todo-line-regexp nil t)
4199 (catch :skip
4200 (org-agenda-skip)
4201 (when (boundp 'org-icalendar-verify-function)
4202 (unless (funcall org-icalendar-verify-function)
4203 (outline-next-heading)
4204 (backward-char 1)
4205 (throw :skip nil)))
4206 (setq state (match-string 2))
4207 (setq status (if (member state org-done-keywords)
4208 "COMPLETED" "NEEDS-ACTION"))
4209 (when (and state
4210 (or (not (member state org-done-keywords))
4211 (eq org-icalendar-include-todo 'all))
4212 (not (member org-archive-tag (org-get-tags-at)))
4214 (setq hd (match-string 3)
4215 summary (org-icalendar-cleanup-string
4216 (org-entry-get nil "SUMMARY"))
4217 desc (org-icalendar-cleanup-string
4218 (or (org-entry-get nil "DESCRIPTION")
4219 (and org-icalendar-include-body (org-get-entry)))
4220 t org-icalendar-include-body)
4221 location (org-icalendar-cleanup-string
4222 (org-entry-get nil "LOCATION"))
4223 due (and (member 'todo-due org-icalendar-use-deadline)
4224 (org-entry-get nil "DEADLINE"))
4225 start (and (member 'todo-start org-icalendar-use-scheduled)
4226 (org-entry-get nil "SCHEDULED"))
4227 uid (if org-icalendar-store-UID
4228 (org-id-get-create)
4229 (or (org-id-get) (org-id-new))))
4230 (and due (setq due (org-ical-ts-to-string due "DUE")))
4231 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4233 (if (string-match org-bracket-link-regexp hd)
4234 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4235 (match-string 1 hd))
4236 t t hd)))
4237 (if (string-match org-priority-regexp hd)
4238 (setq pri (string-to-char (match-string 2 hd))
4239 hd (concat (substring hd 0 (match-beginning 1))
4240 (substring hd (match-end 1))))
4241 (setq pri org-default-priority))
4242 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4243 (- org-lowest-priority org-highest-priority))))))
4245 (princ (format "BEGIN:VTODO
4246 UID: %s
4248 SUMMARY:%s%s%s%s
4249 CATEGORIES:%s
4250 SEQUENCE:1
4251 PRIORITY:%d
4252 STATUS:%s
4253 END:VTODO\n"
4254 (concat prefix uid)
4255 (or start dts)
4256 (or summary hd)
4257 (if (and location (string-match "\\S-" location))
4258 (concat "\nLOCATION: " location) "")
4259 (if (and desc (string-match "\\S-" desc))
4260 (concat "\nDESCRIPTION: " desc) "")
4261 (if due (concat "\n" due) "")
4262 category
4263 pri status)))))))))
4265 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4266 "Take out stuff and quote what needs to be quoted.
4267 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4268 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4269 characters."
4270 (if (not s)
4272 (when is-body
4273 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4274 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4275 (while (string-match re s) (setq s (replace-match "" t t s)))
4276 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4277 (let ((start 0))
4278 (while (string-match "\\([,;]\\)" s start)
4279 (setq start (+ (match-beginning 0) 2)
4280 s (replace-match "\\\\\\1" nil nil s))))
4281 (when is-body
4282 (while (string-match "[ \t]*\n[ \t]*" s)
4283 (setq s (replace-match "\\n" t t s))))
4284 (setq s (org-trim s))
4285 (if is-body
4286 (if maxlength
4287 (if (and (numberp maxlength)
4288 (> (length s) maxlength))
4289 (setq s (substring s 0 maxlength)))))
4292 (defun org-get-entry ()
4293 "Clean-up description string."
4294 (save-excursion
4295 (org-back-to-heading t)
4296 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4298 (defun org-start-icalendar-file (name)
4299 "Start an iCalendar file by inserting the header."
4300 (let ((user user-full-name)
4301 (name (or name "unknown"))
4302 (timezone (cadr (current-time-zone))))
4303 (princ
4304 (format "BEGIN:VCALENDAR
4305 VERSION:2.0
4306 X-WR-CALNAME:%s
4307 PRODID:-//%s//Emacs with Org-mode//EN
4308 X-WR-TIMEZONE:%s
4309 CALSCALE:GREGORIAN\n" name user timezone))))
4311 (defun org-finish-icalendar-file ()
4312 "Finish an iCalendar file by inserting the END statement."
4313 (princ "END:VCALENDAR\n"))
4315 (defun org-ical-ts-to-string (s keyword &optional inc)
4316 "Take a time string S and convert it to iCalendar format.
4317 KEYWORD is added in front, to make a complete line like DTSTART....
4318 When INC is non-nil, increase the hour by two (if time string contains
4319 a time), or the day by one (if it does not contain a time)."
4320 (let ((t1 (org-parse-time-string s 'nodefault))
4321 t2 fmt have-time time)
4322 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4323 (setq t2 t1 have-time t)
4324 (setq t2 (org-parse-time-string s)))
4325 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4326 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4327 (when inc
4328 (if have-time
4329 (if org-agenda-default-appointment-duration
4330 (setq mi (+ org-agenda-default-appointment-duration mi))
4331 (setq h (+ 2 h)))
4332 (setq d (1+ d))))
4333 (setq time (encode-time s mi h d m y)))
4334 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4335 (concat keyword (format-time-string fmt time))))
4337 ;;; XOXO export
4339 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4340 (with-current-buffer buffer
4341 (apply 'insert output)))
4342 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4344 ;;;###autoload
4345 (defun org-export-as-xoxo (&optional buffer)
4346 "Export the org buffer as XOXO.
4347 The XOXO buffer is named *xoxo-<source buffer name>*"
4348 (interactive (list (current-buffer)))
4349 ;; A quickie abstraction
4351 ;; Output everything as XOXO
4352 (with-current-buffer (get-buffer buffer)
4353 (let* ((pos (point))
4354 (opt-plist (org-combine-plists (org-default-export-plist)
4355 (org-infile-export-plist)))
4356 (filename (concat (file-name-as-directory
4357 (org-export-directory :xoxo opt-plist))
4358 (file-name-sans-extension
4359 (file-name-nondirectory buffer-file-name))
4360 ".html"))
4361 (out (find-file-noselect filename))
4362 (last-level 1)
4363 (hanging-li nil))
4364 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4365 ;; Check the output buffer is empty.
4366 (with-current-buffer out (erase-buffer))
4367 ;; Kick off the output
4368 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4369 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4370 (let* ((hd (match-string-no-properties 1))
4371 (level (length hd))
4372 (text (concat
4373 (match-string-no-properties 2)
4374 (save-excursion
4375 (goto-char (match-end 0))
4376 (let ((str ""))
4377 (catch 'loop
4378 (while 't
4379 (forward-line)
4380 (if (looking-at "^[ \t]\\(.*\\)")
4381 (setq str (concat str (match-string-no-properties 1)))
4382 (throw 'loop str)))))))))
4384 ;; Handle level rendering
4385 (cond
4386 ((> level last-level)
4387 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4389 ((< level last-level)
4390 (dotimes (- (- last-level level) 1)
4391 (if hanging-li
4392 (org-export-as-xoxo-insert-into out "</li>\n"))
4393 (org-export-as-xoxo-insert-into out "</ol>\n"))
4394 (when hanging-li
4395 (org-export-as-xoxo-insert-into out "</li>\n")
4396 (setq hanging-li nil)))
4398 ((equal level last-level)
4399 (if hanging-li
4400 (org-export-as-xoxo-insert-into out "</li>\n")))
4403 (setq last-level level)
4405 ;; And output the new li
4406 (setq hanging-li 't)
4407 (if (equal ?+ (elt text 0))
4408 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4409 (org-export-as-xoxo-insert-into out "<li>" text))))
4411 ;; Finally finish off the ol
4412 (dotimes (- last-level 1)
4413 (if hanging-li
4414 (org-export-as-xoxo-insert-into out "</li>\n"))
4415 (org-export-as-xoxo-insert-into out "</ol>\n"))
4417 (goto-char pos)
4418 ;; Finish the buffer off and clean it up.
4419 (switch-to-buffer-other-window out)
4420 (indent-region (point-min) (point-max) nil)
4421 (save-buffer)
4422 (goto-char (point-min))
4425 (provide 'org-exp)
4427 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4429 ;;; org-exp.el ends here