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