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