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