Organize Changes.org.
[org-mode/org-tableheadings.git] / lisp / org-exp.el
blob6247bf10492521405bb1684623c207936e3982cc
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.03pre01
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
29 (require 'org-agenda)
30 (eval-and-compile
31 (require 'cl))
33 (declare-function org-export-latex-preprocess "org-export-latex" ())
34 (declare-function org-agenda-skip "org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
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 (point-min))
703 (let ((re (org-make-options-regexp
704 (append
705 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
706 "LINK_UP" "LINK_HOME" "SETUPFILE")
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 ext-setup-or-nil setup-contents (start 0))
710 (while (or (and ext-setup-or-nil
711 (string-match re ext-setup-or-nil start)
712 (setq start (match-end 0)))
713 (and (setq ext-setup-or-nil nil start 0)
714 (re-search-forward re nil t)))
715 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
716 val (org-match-string-no-properties 2 ext-setup-or-nil))
717 (cond
718 ((setq a (assoc key org-export-inbuffer-options-extra))
719 (setq pr (nth 1 a))
720 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
721 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
722 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
723 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
724 ((string-equal key "DATE") (setq p (plist-put p :date val)))
725 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
726 ((string-equal key "TEXT")
727 (setq text (if text (concat text "\n" val) val)))
728 ((string-equal key "OPTIONS")
729 (setq options (concat val " " options)))
730 ((string-equal key "LINK_UP")
731 (setq p (plist-put p :link-up val)))
732 ((string-equal key "LINK_HOME")
733 (setq p (plist-put p :link-home val)))
734 ((equal key "SETUPFILE")
735 (setq setup-contents (org-file-contents
736 (expand-file-name
737 (org-remove-double-quotes
738 (org-trim val)))
739 'noerror))
740 (if (not ext-setup-or-nil)
741 (setq ext-setup-or-nil setup-contents start 0)
742 (setq ext-setup-or-nil
743 (concat (substring ext-setup-or-nil 0 start)
744 "\n" setup-contents "\n"
745 (substring ext-setup-or-nil start)))))))
746 (setq p (plist-put p :text text))
747 (when options
748 (let ((op '(("H" . :headline-levels)
749 ("num" . :section-numbers)
750 ("toc" . :table-of-contents)
751 ("\\n" . :preserve-breaks)
752 ("@" . :expand-quoted-html)
753 (":" . :fixed-width)
754 ("|" . :tables)
755 ("^" . :sub-superscript)
756 ("-" . :special-strings)
757 ("f" . :footnotes)
758 ("d" . :drawers)
759 ("tags" . :tags)
760 ("*" . :emphasize)
761 ("TeX" . :TeX-macros)
762 ("LaTeX" . :LaTeX-fragments)
763 ("skip" . :skip-before-1st-heading)
764 ("author" . :author-info)
765 ("timestamp" . :time-stamp-file)))
767 (while (setq o (pop op))
768 (if (string-match (concat (regexp-quote (car o))
769 ":\\([^ \t\n\r;,.]*\\)")
770 options)
771 (setq p (plist-put p (cdr o)
772 (car (read-from-string
773 (match-string 1 options)))))))))
774 p))))
776 (defun org-export-directory (type plist)
777 (let* ((val (plist-get plist :publishing-directory))
778 (dir (if (listp val)
779 (or (cdr (assoc type val)) ".")
780 val)))
781 dir))
783 (defun org-export-process-option-filters (plist)
784 (let ((functions org-export-options-filters) f)
785 (while (setq f (pop functions))
786 (setq plist (funcall f plist))))
787 plist)
789 ;;;###autoload
790 (defun org-export (&optional arg)
791 "Export dispatcher for Org-mode.
792 When `org-export-run-in-background' is non-nil, try to run the command
793 in the background. This will be done only for commands that write
794 to a file. For details see the docstring of `org-export-run-in-background'.
796 The prefix argument ARG will be passed to the exporter. However, if
797 ARG is a double universal prefix `C-u C-u', that means to inverse the
798 value of `org-export-run-in-background'."
799 (interactive "P")
800 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
801 (help "[t] insert the export option template
802 \[v] limit export to visible part of outline tree
804 \[a] export as ASCII
806 \[h] export as HTML
807 \[H] export as HTML to temporary buffer
808 \[R] export region as HTML
809 \[b] export as HTML and browse immediately
810 \[x] export as XOXO
812 \[l] export as LaTeX
813 \[L] export as LaTeX to temporary buffer
815 \[i] export current file as iCalendar file
816 \[I] export all agenda files as iCalendar files
817 \[c] export agenda files into combined iCalendar file
819 \[F] publish current file
820 \[P] publish current project
821 \[X] publish... (project will be prompted for)
822 \[A] publish all projects")
823 (cmds
824 '((?t org-insert-export-options-template nil)
825 (?v org-export-visible nil)
826 (?a org-export-as-ascii t)
827 (?h org-export-as-html t)
828 (?b org-export-as-html-and-open t)
829 (?H org-export-as-html-to-buffer nil)
830 (?R org-export-region-as-html nil)
831 (?x org-export-as-xoxo t)
832 (?l org-export-as-latex t)
833 (?L org-export-as-latex-to-buffer nil)
834 (?i org-export-icalendar-this-file t)
835 (?I org-export-icalendar-all-agenda-files t)
836 (?c org-export-icalendar-combine-agenda-files t)
837 (?F org-publish-current-file t)
838 (?P org-publish-current-project t)
839 (?X org-publish t)
840 (?A org-publish-all t)))
841 r1 r2 ass)
842 (save-window-excursion
843 (delete-other-windows)
844 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
845 (princ help))
846 (message "Select command: ")
847 (setq r1 (read-char-exclusive)))
848 (setq r2 (if (< r1 27) (+ r1 96) r1))
849 (unless (setq ass (assq r2 cmds))
850 (error "No command associated with key %c" r1))
851 (if (and bg (nth 2 ass))
852 ;; execute in background
853 (let ((p (start-process
854 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
855 "*Org Processes*"
856 (expand-file-name invocation-name invocation-directory)
857 "-batch"
858 "-l" user-init-file
859 "--eval" "(require 'org-exp)"
860 "--eval" "(setq org-wait .2)"
861 (buffer-file-name)
862 "-f" (symbol-name (nth 1 ass)))))
863 (set-process-sentinel p 'org-export-process-sentinel)
864 (message "Background process \"%s\": started" p))
865 ;; background processing not requested, or not possible
866 (call-interactively (nth 1 ass)))))
868 (defun org-export-process-sentinel (process status)
869 (if (string-match "\n+\\'" status)
870 (setq status (substring status 0 -1)))
871 (message "Background process \"%s\": %s" process status))
873 (defconst org-html-entities
874 '(("nbsp")
875 ("iexcl")
876 ("cent")
877 ("pound")
878 ("curren")
879 ("yen")
880 ("brvbar")
881 ("vert" . "&#124;")
882 ("sect")
883 ("uml")
884 ("copy")
885 ("ordf")
886 ("laquo")
887 ("not")
888 ("shy")
889 ("reg")
890 ("macr")
891 ("deg")
892 ("plusmn")
893 ("sup2")
894 ("sup3")
895 ("acute")
896 ("micro")
897 ("para")
898 ("middot")
899 ("odot"."o")
900 ("star"."*")
901 ("cedil")
902 ("sup1")
903 ("ordm")
904 ("raquo")
905 ("frac14")
906 ("frac12")
907 ("frac34")
908 ("iquest")
909 ("Agrave")
910 ("Aacute")
911 ("Acirc")
912 ("Atilde")
913 ("Auml")
914 ("Aring") ("AA"."&Aring;")
915 ("AElig")
916 ("Ccedil")
917 ("Egrave")
918 ("Eacute")
919 ("Ecirc")
920 ("Euml")
921 ("Igrave")
922 ("Iacute")
923 ("Icirc")
924 ("Iuml")
925 ("ETH")
926 ("Ntilde")
927 ("Ograve")
928 ("Oacute")
929 ("Ocirc")
930 ("Otilde")
931 ("Ouml")
932 ("times")
933 ("Oslash")
934 ("Ugrave")
935 ("Uacute")
936 ("Ucirc")
937 ("Uuml")
938 ("Yacute")
939 ("THORN")
940 ("szlig")
941 ("agrave")
942 ("aacute")
943 ("acirc")
944 ("atilde")
945 ("auml")
946 ("aring")
947 ("aelig")
948 ("ccedil")
949 ("egrave")
950 ("eacute")
951 ("ecirc")
952 ("euml")
953 ("igrave")
954 ("iacute")
955 ("icirc")
956 ("iuml")
957 ("eth")
958 ("ntilde")
959 ("ograve")
960 ("oacute")
961 ("ocirc")
962 ("otilde")
963 ("ouml")
964 ("divide")
965 ("oslash")
966 ("ugrave")
967 ("uacute")
968 ("ucirc")
969 ("uuml")
970 ("yacute")
971 ("thorn")
972 ("yuml")
973 ("fnof")
974 ("Alpha")
975 ("Beta")
976 ("Gamma")
977 ("Delta")
978 ("Epsilon")
979 ("Zeta")
980 ("Eta")
981 ("Theta")
982 ("Iota")
983 ("Kappa")
984 ("Lambda")
985 ("Mu")
986 ("Nu")
987 ("Xi")
988 ("Omicron")
989 ("Pi")
990 ("Rho")
991 ("Sigma")
992 ("Tau")
993 ("Upsilon")
994 ("Phi")
995 ("Chi")
996 ("Psi")
997 ("Omega")
998 ("alpha")
999 ("beta")
1000 ("gamma")
1001 ("delta")
1002 ("epsilon")
1003 ("varepsilon"."&epsilon;")
1004 ("zeta")
1005 ("eta")
1006 ("theta")
1007 ("iota")
1008 ("kappa")
1009 ("lambda")
1010 ("mu")
1011 ("nu")
1012 ("xi")
1013 ("omicron")
1014 ("pi")
1015 ("rho")
1016 ("sigmaf") ("varsigma"."&sigmaf;")
1017 ("sigma")
1018 ("tau")
1019 ("upsilon")
1020 ("phi")
1021 ("chi")
1022 ("psi")
1023 ("omega")
1024 ("thetasym") ("vartheta"."&thetasym;")
1025 ("upsih")
1026 ("piv")
1027 ("bull") ("bullet"."&bull;")
1028 ("hellip") ("dots"."&hellip;")
1029 ("prime")
1030 ("Prime")
1031 ("oline")
1032 ("frasl")
1033 ("weierp")
1034 ("image")
1035 ("real")
1036 ("trade")
1037 ("alefsym")
1038 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1039 ("uarr") ("uparrow"."&uarr;")
1040 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1041 ("darr")("downarrow"."&darr;")
1042 ("harr") ("leftrightarrow"."&harr;")
1043 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1044 ("lArr") ("Leftarrow"."&lArr;")
1045 ("uArr") ("Uparrow"."&uArr;")
1046 ("rArr") ("Rightarrow"."&rArr;")
1047 ("dArr") ("Downarrow"."&dArr;")
1048 ("hArr") ("Leftrightarrow"."&hArr;")
1049 ("forall")
1050 ("part") ("partial"."&part;")
1051 ("exist") ("exists"."&exist;")
1052 ("empty") ("emptyset"."&empty;")
1053 ("nabla")
1054 ("isin") ("in"."&isin;")
1055 ("notin")
1056 ("ni")
1057 ("prod")
1058 ("sum")
1059 ("minus")
1060 ("lowast") ("ast"."&lowast;")
1061 ("radic")
1062 ("prop") ("proptp"."&prop;")
1063 ("infin") ("infty"."&infin;")
1064 ("ang") ("angle"."&ang;")
1065 ("and") ("wedge"."&and;")
1066 ("or") ("vee"."&or;")
1067 ("cap")
1068 ("cup")
1069 ("int")
1070 ("there4")
1071 ("sim")
1072 ("cong") ("simeq"."&cong;")
1073 ("asymp")("approx"."&asymp;")
1074 ("ne") ("neq"."&ne;")
1075 ("equiv")
1076 ("le")
1077 ("ge")
1078 ("sub") ("subset"."&sub;")
1079 ("sup") ("supset"."&sup;")
1080 ("nsub")
1081 ("sube")
1082 ("supe")
1083 ("oplus")
1084 ("otimes")
1085 ("perp")
1086 ("sdot") ("cdot"."&sdot;")
1087 ("lceil")
1088 ("rceil")
1089 ("lfloor")
1090 ("rfloor")
1091 ("lang")
1092 ("rang")
1093 ("loz") ("Diamond"."&loz;")
1094 ("spades") ("spadesuit"."&spades;")
1095 ("clubs") ("clubsuit"."&clubs;")
1096 ("hearts") ("diamondsuit"."&hearts;")
1097 ("diams") ("diamondsuit"."&diams;")
1098 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1099 ("quot")
1100 ("amp")
1101 ("lt")
1102 ("gt")
1103 ("OElig")
1104 ("oelig")
1105 ("Scaron")
1106 ("scaron")
1107 ("Yuml")
1108 ("circ")
1109 ("tilde")
1110 ("ensp")
1111 ("emsp")
1112 ("thinsp")
1113 ("zwnj")
1114 ("zwj")
1115 ("lrm")
1116 ("rlm")
1117 ("ndash")
1118 ("mdash")
1119 ("lsquo")
1120 ("rsquo")
1121 ("sbquo")
1122 ("ldquo")
1123 ("rdquo")
1124 ("bdquo")
1125 ("dagger")
1126 ("Dagger")
1127 ("permil")
1128 ("lsaquo")
1129 ("rsaquo")
1130 ("euro")
1132 ("arccos"."arccos")
1133 ("arcsin"."arcsin")
1134 ("arctan"."arctan")
1135 ("arg"."arg")
1136 ("cos"."cos")
1137 ("cosh"."cosh")
1138 ("cot"."cot")
1139 ("coth"."coth")
1140 ("csc"."csc")
1141 ("deg"."deg")
1142 ("det"."det")
1143 ("dim"."dim")
1144 ("exp"."exp")
1145 ("gcd"."gcd")
1146 ("hom"."hom")
1147 ("inf"."inf")
1148 ("ker"."ker")
1149 ("lg"."lg")
1150 ("lim"."lim")
1151 ("liminf"."liminf")
1152 ("limsup"."limsup")
1153 ("ln"."ln")
1154 ("log"."log")
1155 ("max"."max")
1156 ("min"."min")
1157 ("Pr"."Pr")
1158 ("sec"."sec")
1159 ("sin"."sin")
1160 ("sinh"."sinh")
1161 ("sup"."sup")
1162 ("tan"."tan")
1163 ("tanh"."tanh")
1165 "Entities for TeX->HTML translation.
1166 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1167 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1168 In that case, \"\\ent\" will be translated to \"&other;\".
1169 The list contains HTML entities for Latin-1, Greek and other symbols.
1170 It is supplemented by a number of commonly used TeX macros with appropriate
1171 translations. There is currently no way for users to extend this.")
1173 ;;; General functions for all backends
1175 (defun org-export-preprocess-string (string &rest parameters)
1176 "Cleanup STRING so that that the true exported has a more consistent source.
1177 This function takes STRING, which should be a buffer-string of an org-file
1178 to export. It then creates a temporary buffer where it does its job.
1179 The result is then again returned as a string, and the exporter works
1180 on this string to produce the exported version."
1181 (interactive)
1182 (let* ((re-radio (and org-target-link-regexp
1183 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
1184 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1185 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1186 (re-archive (concat ":" org-archive-tag ":"))
1187 (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
1188 (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1189 (htmlp (plist-get parameters :for-html))
1190 (asciip (plist-get parameters :for-ascii))
1191 (latexp (plist-get parameters :for-LaTeX))
1192 (commentsp (plist-get parameters :comments))
1193 (archived-trees (plist-get parameters :archived-trees))
1194 (inhibit-read-only t)
1195 (drawers org-drawers)
1196 (exp-drawers (plist-get parameters :drawers))
1197 (outline-regexp "\\*+ ")
1198 target-alist tmp target level
1199 a b xx rtn p)
1201 (with-current-buffer (get-buffer-create " org-mode-tmp")
1202 (erase-buffer)
1203 (insert string)
1204 ;; Call the hook
1205 (run-hooks 'org-export-preprocess-hook)
1207 ;; Remove license-to-kill stuff
1208 ;; The caller markes some stuff fo killing, stuff that has been
1209 ;; used to create the page title, for example.
1210 (while (setq p (text-property-any (point-min) (point-max)
1211 :org-license-to-kill t))
1212 (delete-region p (next-single-property-change p :org-license-to-kill)))
1214 (let ((org-inhibit-startup t)) (org-mode))
1215 (untabify (point-min) (point-max))
1217 ;; Handle incude files
1218 (org-export-handle-include-files)
1220 ;; Handle source code snippets
1221 (org-export-replace-src-segments)
1223 ;; Get rid of drawers
1224 (unless (eq t exp-drawers)
1225 (goto-char (point-min))
1226 (let ((re (concat "^[ \t]*:\\("
1227 (mapconcat
1228 'identity
1229 (org-delete-all exp-drawers
1230 (copy-sequence drawers))
1231 "\\|")
1232 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1233 (while (re-search-forward re nil t)
1234 (replace-match ""))))
1236 ;; Get the correct stuff before the first headline
1237 (when (plist-get parameters :skip-before-1st-heading)
1238 (goto-char (point-min))
1239 (when (re-search-forward "^\\*+[ \t]" nil t)
1240 (delete-region (point-min) (match-beginning 0))
1241 (goto-char (point-min))
1242 (insert "\n")))
1243 (when (plist-get parameters :add-text)
1244 (goto-char (point-min))
1245 (insert (plist-get parameters :add-text) "\n"))
1247 ;; Get rid of archived trees
1248 (when (not (eq archived-trees t))
1249 (goto-char (point-min))
1250 (while (re-search-forward re-archive nil t)
1251 (if (not (org-on-heading-p t))
1252 (org-end-of-subtree t)
1253 (beginning-of-line 1)
1254 (setq a (if archived-trees
1255 (1+ (point-at-eol)) (point))
1256 b (org-end-of-subtree t))
1257 (if (> b a) (delete-region a b)))))
1259 ;; Find all headings and compute the targets for them
1260 (goto-char (point-min))
1261 (org-init-section-numbers)
1262 (let ((re (concat "^" org-outline-regexp)))
1263 (while (re-search-forward re nil t)
1264 (setq level (org-reduced-level
1265 (save-excursion (goto-char (point-at-bol))
1266 (org-outline-level))))
1267 (setq target (org-solidify-link-text
1268 (format "sec-%s" (org-section-number level))))
1269 (push (cons target target) target-alist)
1270 (add-text-properties
1271 (point-at-bol) (point-at-eol)
1272 (list 'target target))))
1274 ;; Find targets in comments and move them out of comments,
1275 ;; but mark them as targets that should be invisible
1276 (goto-char (point-min))
1277 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1278 ;; Check if the line before or after is a headline with a target
1279 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1280 (get-text-property (point-at-bol 2) 'target)))
1281 (progn
1282 ;; use the existing target in a neighboring line
1283 (setq tmp (match-string 2))
1284 (replace-match "")
1285 (and (looking-at "\n") (delete-char 1))
1286 (push (cons (org-solidify-link-text tmp) target)
1287 target-alist))
1288 ;; Make an invisible target
1289 (replace-match "\\1(INVISIBLE)")))
1291 ;; Protect backend specific stuff, throw away the others.
1292 (let ((formatters
1293 `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
1294 (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
1295 (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1296 fmt)
1297 (goto-char (point-min))
1298 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1299 (goto-char (match-end 0))
1300 (while (not (looking-at "#\\+END_EXAMPLE"))
1301 (insert ": ")
1302 (beginning-of-line 2)))
1303 (goto-char (point-min))
1304 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1305 (add-text-properties (match-beginning 0) (match-end 0)
1306 '(org-protected t)))
1307 (while formatters
1308 (setq fmt (pop formatters))
1309 (when (car fmt)
1310 (goto-char (point-min))
1311 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1312 ":[ \t]*\\(.*\\)") nil t)
1313 (replace-match "\\1" t)
1314 (add-text-properties
1315 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1316 '(org-protected t))))
1317 (goto-char (point-min))
1318 (while (re-search-forward
1319 (concat "^#\\+"
1320 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1321 (cadddr fmt) "\\>.*\n?") nil t)
1322 (if (car fmt)
1323 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1324 '(org-protected t))
1325 (delete-region (match-beginning 0) (match-end 0))))))
1327 ;; Protect quoted subtrees
1328 (goto-char (point-min))
1329 (while (re-search-forward re-quote nil t)
1330 (goto-char (match-beginning 0))
1331 (end-of-line 1)
1332 (add-text-properties (point) (org-end-of-subtree t)
1333 '(org-protected t)))
1335 ;; Protect verbatim elements
1336 (goto-char (point-min))
1337 (while (re-search-forward org-verbatim-re nil t)
1338 (add-text-properties (match-beginning 4) (match-end 4)
1339 '(org-protected t))
1340 (goto-char (1+ (match-end 4))))
1342 ;; Blockquotes
1343 (goto-char (point-min))
1344 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t)
1345 (replace-match (if (equal (downcase (match-string 1)) "end")
1346 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1347 t t))
1349 ;; Remove subtrees that are commented
1350 (goto-char (point-min))
1351 (while (re-search-forward re-commented nil t)
1352 (goto-char (match-beginning 0))
1353 (delete-region (point) (org-end-of-subtree t)))
1355 ;; Remove special table lines
1356 (when org-export-table-remove-special-lines
1357 (goto-char (point-min))
1358 (while (re-search-forward "^[ \t]*|" nil t)
1359 (beginning-of-line 1)
1360 (if (or (looking-at "[ \t]*| *[!_^] *|")
1361 (and (looking-at ".*?| *<[0-9]+> *|")
1362 (not (looking-at ".*?| *[^ <|]"))))
1363 (delete-region (max (point-min) (1- (point-at-bol)))
1364 (point-at-eol))
1365 (end-of-line 1))))
1367 ;; Specific LaTeX stuff
1368 (when latexp
1369 (require 'org-export-latex nil)
1370 (org-export-latex-preprocess))
1372 (when asciip
1373 (org-export-ascii-clean-string))
1375 ;; Specific HTML stuff
1376 (when htmlp
1377 ;; Convert LaTeX fragments to images
1378 (when (plist-get parameters :LaTeX-fragments)
1379 (org-format-latex
1380 (concat "ltxpng/" (file-name-sans-extension
1381 (file-name-nondirectory
1382 org-current-export-file)))
1383 org-current-export-dir nil "Creating LaTeX image %s"))
1384 (message "Exporting..."))
1386 ;; Remove or replace comments
1387 (goto-char (point-min))
1388 (while (re-search-forward "^#\\(.*\n?\\)" nil t)
1389 (if commentsp
1390 (progn (add-text-properties
1391 (match-beginning 0) (match-end 0) '(org-protected t))
1392 (replace-match (format commentsp (match-string 1)) t t))
1393 (replace-match "")))
1395 ;; Find matches for radio targets and turn them into internal links
1396 (goto-char (point-min))
1397 (when re-radio
1398 (while (re-search-forward re-radio nil t)
1399 (org-if-unprotected
1400 (replace-match "\\1[[\\2]]"))))
1402 ;; Find all links that contain a newline and put them into a single line
1403 (goto-char (point-min))
1404 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1405 (org-if-unprotected
1406 (replace-match "\\1 \\3")
1407 (goto-char (match-beginning 0))))
1409 ;; Find all internal links. If they have a fuzzy match (i.e. not
1410 ;; a *dedicated* target match, let the link point to the
1411 ;; correspinding section.
1413 (goto-char (point-min))
1414 (while (re-search-forward org-bracket-link-regexp nil t)
1415 (org-if-unprotected
1416 (let* ((md (match-data))
1417 (desc (match-end 2))
1418 (link (org-link-unescape (match-string 1)))
1419 (slink (org-solidify-link-text link))
1420 found props pos
1421 (target
1422 (or (cdr (assoc slink target-alist))
1423 (save-excursion
1424 (unless (string-match org-link-types-re link)
1425 (setq found (condition-case nil (org-link-search link)
1426 (error nil)))
1427 (when (and found
1428 (or (org-on-heading-p)
1429 (not (eq found 'dedicated))))
1430 (or (get-text-property (point) 'target)
1431 (get-text-property
1432 (max (point-min)
1433 (1- (previous-single-property-change
1434 (point) 'target)))
1435 'target))))))))
1436 (when target
1437 (set-match-data md)
1438 (goto-char (match-beginning 1))
1439 (setq props (text-properties-at (point)))
1440 (delete-region (match-beginning 1) (match-end 1))
1441 (setq pos (point))
1442 (insert target)
1443 (unless desc (insert "][" link))
1444 (add-text-properties pos (point) props)))))
1446 ;; Normalize links: Convert angle and plain links into bracket links
1447 ;; Expand link abbreviations
1448 (goto-char (point-min))
1449 (while (re-search-forward re-plain-link nil t)
1450 (goto-char (1- (match-end 0)))
1451 (org-if-unprotected
1452 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1453 ":" (match-string 3) "]]")))
1454 ;; added 'org-link face to links
1455 (put-text-property 0 (length s) 'face 'org-link s)
1456 (replace-match s t t))))
1457 (goto-char (point-min))
1458 (while (re-search-forward re-angle-link nil t)
1459 (goto-char (1- (match-end 0)))
1460 (org-if-unprotected
1461 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1462 ":" (match-string 3) "]]")))
1463 (put-text-property 0 (length s) 'face 'org-link s)
1464 (replace-match s t t))))
1465 (goto-char (point-min))
1466 (while (re-search-forward org-bracket-link-regexp nil t)
1467 (org-if-unprotected
1468 (let* ((s (concat "[[" (setq xx (save-match-data
1469 (org-link-expand-abbrev (match-string 1))))
1471 (if (match-end 3)
1472 (match-string 2)
1473 (concat "[" xx "]"))
1474 "]")))
1475 (put-text-property 0 (length s) 'face 'org-link s)
1476 (replace-match s t t))))
1478 ;; Find multiline emphasis and put them into single line
1479 (when (plist-get parameters :emph-multiline)
1480 (goto-char (point-min))
1481 (while (re-search-forward org-emph-re nil t)
1482 (if (not (= (char-after (match-beginning 3))
1483 (char-after (match-beginning 4))))
1484 (org-if-unprotected
1485 (subst-char-in-region (match-beginning 0) (match-end 0)
1486 ?\n ?\ t)
1487 (goto-char (1- (match-end 0))))
1488 (goto-char (1+ (match-beginning 0))))))
1490 (setq rtn (buffer-string)))
1491 (kill-buffer " org-mode-tmp")
1492 rtn))
1494 (defun org-export-grab-title-from-buffer ()
1495 "Get a title for the current document, from looking at the buffer."
1496 (let ((inhibit-read-only t))
1497 (save-excursion
1498 (goto-char (point-min))
1499 (let ((end (save-excursion (outline-next-heading) (point))))
1500 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1501 ;; Mark the line so that it will not be exported as normal text.
1502 (org-unmodified
1503 (add-text-properties (match-beginning 0) (match-end 0)
1504 (list :org-license-to-kill t)))
1505 ;; Return the title string
1506 (org-trim (match-string 0)))))))
1508 (defun org-export-get-title-from-subtree ()
1509 "Return subtree title and exclude it from export."
1510 (let (title (m (mark)))
1511 (save-excursion
1512 (goto-char (region-beginning))
1513 (when (and (org-at-heading-p)
1514 (>= (org-end-of-subtree t t) (region-end)))
1515 ;; This is a subtree, we take the title from the first heading
1516 (goto-char (region-beginning))
1517 (looking-at org-todo-line-regexp)
1518 (setq title (match-string 3))
1519 (org-unmodified
1520 (add-text-properties (point) (1+ (point-at-eol))
1521 (list :org-license-to-kill t)))))
1522 title))
1524 (defun org-solidify-link-text (s &optional alist)
1525 "Take link text and make a safe target out of it."
1526 (save-match-data
1527 (let* ((rtn
1528 (mapconcat
1529 'identity
1530 (org-split-string s "[ \t\r\n]+") "=="))
1531 (a (assoc rtn alist)))
1532 (or (cdr a) rtn))))
1534 (defun org-get-min-level (lines)
1535 "Get the minimum level in LINES."
1536 (let ((re "^\\(\\*+\\) ") l min)
1537 (catch 'exit
1538 (while (setq l (pop lines))
1539 (if (string-match re l)
1540 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1541 1)))
1543 ;; Variable holding the vector with section numbers
1544 (defvar org-section-numbers (make-vector org-level-max 0))
1546 (defun org-init-section-numbers ()
1547 "Initialize the vector for the section numbers."
1548 (let* ((level -1)
1549 (numbers (nreverse (org-split-string "" "\\.")))
1550 (depth (1- (length org-section-numbers)))
1551 (i depth) number-string)
1552 (while (>= i 0)
1553 (if (> i level)
1554 (aset org-section-numbers i 0)
1555 (setq number-string (or (car numbers) "0"))
1556 (if (string-match "\\`[A-Z]\\'" number-string)
1557 (aset org-section-numbers i
1558 (- (string-to-char number-string) ?A -1))
1559 (aset org-section-numbers i (string-to-number number-string)))
1560 (pop numbers))
1561 (setq i (1- i)))))
1563 (defun org-section-number (&optional level)
1564 "Return a string with the current section number.
1565 When LEVEL is non-nil, increase section numbers on that level."
1566 (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
1567 (when level
1568 (when (> level -1)
1569 (aset org-section-numbers
1570 level (1+ (aref org-section-numbers level))))
1571 (setq idx (1+ level))
1572 (while (<= idx depth)
1573 (if (not (= idx 1))
1574 (aset org-section-numbers idx 0))
1575 (setq idx (1+ idx))))
1576 (setq idx 0)
1577 (while (<= idx depth)
1578 (setq n (aref org-section-numbers idx))
1579 (setq string (concat string (if (not (string= string "")) "." "")
1580 (int-to-string n)))
1581 (setq idx (1+ idx)))
1582 (save-match-data
1583 (if (string-match "\\`\\([@0]\\.\\)+" string)
1584 (setq string (replace-match "" t nil string)))
1585 (if (string-match "\\(\\.0\\)+\\'" string)
1586 (setq string (replace-match "" t nil string))))
1587 string))
1589 ;;; Include files
1591 (defun org-export-handle-include-files ()
1592 "Include the contents of include files, with proper formatting."
1593 (let (params file markup lang start end)
1594 (goto-char (point-min))
1595 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
1596 (setq params (read (concat "(" (match-string 1) ")"))
1597 file (org-symname-or-string (pop params))
1598 markup (org-symname-or-string (pop params))
1599 lang (org-symname-or-string (pop params)))
1600 (delete-region (match-beginning 0) (match-end 0))
1601 (if (or (not file)
1602 (not (file-exists-p file))
1603 (not (file-readable-p file)))
1604 (insert (format "CANNOT INCLUDE FILE %s" file))
1605 (when markup
1606 (if (equal (downcase markup) "src")
1607 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
1608 end "#+end_src")
1609 (setq start (format "#+begin_%s\n" markup)
1610 end (format "#+end_%s" markup))))
1611 (insert (or start ""))
1612 (forward-char (nth 1 (insert-file-contents (expand-file-name file))))
1613 (or (bolp) (newline))
1614 (insert (or end ""))))))
1616 (defun org-symname-or-string (s)
1617 (if (symbolp s)
1618 (if s (symbol-name s) s)
1621 ;;; Fontification of code
1622 ;; Currently only for th HTML backend, but who knows....
1623 (defun org-export-replace-src-segments ()
1624 "Replace source code segments with special code for export."
1625 (let (lang code trans)
1626 (goto-char (point-min))
1627 (while (re-search-forward
1628 "^#\\+BEGIN_SRC[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1629 nil t)
1630 (setq lang (match-string 1) code (match-string 2)
1631 trans (org-export-format-source-code lang code))
1632 (replace-match trans t t))))
1634 (defvar htmlp) ;; dynamically scoped from org-exp.el
1636 (defun org-export-format-source-code (lang code)
1637 "Format CODE from language LANG and return it formatted for export.
1638 Currently, this only does something for HTML export, for all other
1639 backends, it converts the segment into an EXAMPLE segment."
1640 (save-match-data
1641 (cond
1642 (htmlp
1643 ;; We are exporting to HTML
1644 (condition-case nil (require 'htmlize) (nil t))
1645 (if (not (fboundp 'htmlize-region-for-paste))
1646 (progn
1647 ;; we do not have htmlize.el, or an old version of it
1648 (message
1649 "htmlize.el 1.34 or later is needed for source code formatting")
1650 (concat "#+BEGIN_EXAMPLE\n" code
1651 (if (string-match "\n\\'" code) "" "\n")
1652 "#+END_EXAMPLE\n"))
1653 ;; ok, we are good to go
1654 (let* ((mode (and lang (intern (concat lang "-mode"))))
1655 (org-inhibit-startup t)
1656 (org-startup-folded nil)
1657 (htmltext
1658 (with-temp-buffer
1659 (insert code)
1660 ;; Free up the protected stuff
1661 (goto-char (point-min))
1662 (while (re-search-forward "^," nil t)
1663 (replace-match ""))
1664 (if (functionp mode)
1665 (funcall mode)
1666 (fundamental-mode))
1667 (font-lock-fontify-buffer)
1668 ;; silence the byte-compiler
1669 (when (fboundp 'htmlize-region-for-paste)
1670 ;; transform the region to HTML
1671 (htmlize-region-for-paste (point-min) (point-max))))))
1672 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
1673 (setq htmltext (replace-match "<pre class=\"src\">"
1674 t t htmltext)))
1675 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
1677 ;; This is not HTML, so just make it an example.
1678 (concat "#+BEGIN_EXAMPLE\n" code
1679 (if (string-match "\n\\'" code) "" "\n")
1680 "#+END_EXAMPLE\n")))))
1682 ;;; ASCII export
1684 (defvar org-last-level nil) ; dynamically scoped variable
1685 (defvar org-min-level nil) ; dynamically scoped variable
1686 (defvar org-levels-open nil) ; dynamically scoped parameter
1687 (defvar org-ascii-current-indentation nil) ; For communication
1689 ;;;###autoload
1690 (defun org-export-as-ascii (arg)
1691 "Export the outline as a pretty ASCII file.
1692 If there is an active region, export only the region.
1693 The prefix ARG specifies how many levels of the outline should become
1694 underlined headlines. The default is 3."
1695 (interactive "P")
1696 (setq-default org-todo-line-regexp org-todo-line-regexp)
1697 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1698 (org-infile-export-plist)))
1699 (region-p (org-region-active-p))
1700 (subtree-p
1701 (when region-p
1702 (save-excursion
1703 (goto-char (region-beginning))
1704 (and (org-at-heading-p)
1705 (>= (org-end-of-subtree t t) (region-end))))))
1706 (custom-times org-display-custom-times)
1707 (org-ascii-current-indentation '(0 . 0))
1708 (level 0) line txt
1709 (umax nil)
1710 (umax-toc nil)
1711 (case-fold-search nil)
1712 (filename (concat (file-name-as-directory
1713 (org-export-directory :ascii opt-plist))
1714 (file-name-sans-extension
1715 (or (and subtree-p
1716 (org-entry-get (region-beginning)
1717 "EXPORT_FILE_NAME" t))
1718 (file-name-nondirectory buffer-file-name)))
1719 ".txt"))
1720 (filename (if (equal (file-truename filename)
1721 (file-truename buffer-file-name))
1722 (concat filename ".txt")
1723 filename))
1724 (buffer (find-file-noselect filename))
1725 (org-levels-open (make-vector org-level-max nil))
1726 (odd org-odd-levels-only)
1727 (date (plist-get opt-plist :date))
1728 (author (plist-get opt-plist :author))
1729 (title (or (and subtree-p (org-export-get-title-from-subtree))
1730 (plist-get opt-plist :title)
1731 (and (not
1732 (plist-get opt-plist :skip-before-1st-heading))
1733 (org-export-grab-title-from-buffer))
1734 (file-name-sans-extension
1735 (file-name-nondirectory buffer-file-name))))
1736 (email (plist-get opt-plist :email))
1737 (language (plist-get opt-plist :language))
1738 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1739 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1740 (todo nil)
1741 (lang-words nil)
1742 (region
1743 (buffer-substring
1744 (if (org-region-active-p) (region-beginning) (point-min))
1745 (if (org-region-active-p) (region-end) (point-max))))
1746 (lines (org-split-string
1747 (org-export-preprocess-string
1748 region
1749 :for-ascii t
1750 :skip-before-1st-heading
1751 (plist-get opt-plist :skip-before-1st-heading)
1752 :drawers (plist-get opt-plist :drawers)
1753 :verbatim-multiline t
1754 :archived-trees
1755 (plist-get opt-plist :archived-trees)
1756 :add-text (plist-get opt-plist :text))
1757 "\n"))
1758 thetoc have-headings first-heading-pos
1759 table-open table-buffer)
1761 (let ((inhibit-read-only t))
1762 (org-unmodified
1763 (remove-text-properties (point-min) (point-max)
1764 '(:org-license-to-kill t))))
1766 (setq org-min-level (org-get-min-level lines))
1767 (setq org-last-level org-min-level)
1768 (org-init-section-numbers)
1770 (find-file-noselect filename)
1772 (setq lang-words (or (assoc language org-export-language-setup)
1773 (assoc "en" org-export-language-setup)))
1774 (switch-to-buffer-other-window buffer)
1775 (erase-buffer)
1776 (fundamental-mode)
1777 ;; create local variables for all options, to make sure all called
1778 ;; functions get the correct information
1779 (mapc (lambda (x)
1780 (set (make-local-variable (cdr x))
1781 (plist-get opt-plist (car x))))
1782 org-export-plist-vars)
1783 (org-set-local 'org-odd-levels-only odd)
1784 (setq umax (if arg (prefix-numeric-value arg)
1785 org-export-headline-levels))
1786 (setq umax-toc (if (integerp org-export-with-toc)
1787 (min org-export-with-toc umax)
1788 umax))
1790 ;; File header
1791 (if title (org-insert-centered title ?=))
1792 (insert "\n")
1793 (if (and (or author email)
1794 org-export-author-info)
1795 (insert (concat (nth 1 lang-words) ": " (or author "")
1796 (if email (concat " <" email ">") "")
1797 "\n")))
1799 (cond
1800 ((and date (string-match "%" date))
1801 (setq date (format-time-string date)))
1802 (date)
1803 (t (setq date (format-time-string "%Y/%m/%d %X"))))
1805 (if (and date org-export-time-stamp-file)
1806 (insert (concat (nth 2 lang-words) ": " date"\n")))
1808 (insert "\n\n")
1810 (if org-export-with-toc
1811 (progn
1812 (push (concat (nth 3 lang-words) "\n") thetoc)
1813 (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
1814 (mapc '(lambda (line)
1815 (if (string-match org-todo-line-regexp
1816 line)
1817 ;; This is a headline
1818 (progn
1819 (setq have-headings t)
1820 (setq level (- (match-end 1) (match-beginning 1))
1821 level (org-tr-level level)
1822 txt (match-string 3 line)
1823 todo
1824 (or (and org-export-mark-todo-in-toc
1825 (match-beginning 2)
1826 (not (member (match-string 2 line)
1827 org-done-keywords)))
1828 ; TODO, not DONE
1829 (and org-export-mark-todo-in-toc
1830 (= level umax-toc)
1831 (org-search-todo-below
1832 line lines level))))
1833 (setq txt (org-html-expand-for-ascii txt))
1835 (while (string-match org-bracket-link-regexp txt)
1836 (setq txt
1837 (replace-match
1838 (match-string (if (match-end 2) 3 1) txt)
1839 t t txt)))
1841 (if (and (memq org-export-with-tags '(not-in-toc nil))
1842 (string-match
1843 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1844 txt))
1845 (setq txt (replace-match "" t t txt)))
1846 (if (string-match quote-re0 txt)
1847 (setq txt (replace-match "" t t txt)))
1849 (if org-export-with-section-numbers
1850 (setq txt (concat (org-section-number level)
1851 " " txt)))
1852 (if (<= level umax-toc)
1853 (progn
1854 (push
1855 (concat
1856 (make-string
1857 (* (max 0 (- level org-min-level)) 4) ?\ )
1858 (format (if todo "%s (*)\n" "%s\n") txt))
1859 thetoc)
1860 (setq org-last-level level))
1861 ))))
1862 lines)
1863 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1865 (org-init-section-numbers)
1866 (while (setq line (pop lines))
1867 ;; Remove the quoted HTML tags.
1868 (setq line (org-html-expand-for-ascii line))
1869 ;; Remove targets
1870 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
1871 (setq line (replace-match "" t t line)))
1872 ;; Replace internal links
1873 (while (string-match org-bracket-link-regexp line)
1874 (setq line (replace-match
1875 (if (match-end 3) "[\\3]" "[\\1]")
1876 t nil line)))
1877 (when custom-times
1878 (setq line (org-translate-time line)))
1879 (cond
1880 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1881 ;; a Headline
1882 (setq first-heading-pos (or first-heading-pos (point)))
1883 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
1884 txt (match-string 2 line))
1885 (org-ascii-level-start level txt umax lines))
1887 ((and org-export-with-tables
1888 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1889 (if (not table-open)
1890 ;; New table starts
1891 (setq table-open t table-buffer nil))
1892 ;; Accumulate lines
1893 (setq table-buffer (cons line table-buffer))
1894 (when (or (not lines)
1895 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1896 (car lines))))
1897 (setq table-open nil
1898 table-buffer (nreverse table-buffer))
1899 (insert (mapconcat
1900 (lambda (x)
1901 (org-fix-indentation x org-ascii-current-indentation))
1902 (org-format-table-ascii table-buffer)
1903 "\n") "\n")))
1905 (setq line (org-fix-indentation line org-ascii-current-indentation))
1906 (if (and org-export-with-fixed-width
1907 (string-match "^\\([ \t]*\\)\\(:\\)" line))
1908 (setq line (replace-match "\\1" nil nil line)))
1909 (insert line "\n"))))
1911 (normal-mode)
1913 ;; insert the table of contents
1914 (when thetoc
1915 (goto-char (point-min))
1916 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
1917 (progn
1918 (goto-char (match-beginning 0))
1919 (replace-match ""))
1920 (goto-char first-heading-pos))
1921 (mapc 'insert thetoc)
1922 (or (looking-at "[ \t]*\n[ \t]*\n")
1923 (insert "\n\n")))
1925 ;; Convert whitespace place holders
1926 (goto-char (point-min))
1927 (let (beg end)
1928 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1929 (setq end (next-single-property-change beg 'org-whitespace))
1930 (goto-char beg)
1931 (delete-region beg end)
1932 (insert (make-string (- end beg) ?\ ))))
1934 (save-buffer)
1935 ;; remove display and invisible chars
1936 (let (beg end)
1937 (goto-char (point-min))
1938 (while (setq beg (next-single-property-change (point) 'display))
1939 (setq end (next-single-property-change beg 'display))
1940 (delete-region beg end)
1941 (goto-char beg)
1942 (insert "=>"))
1943 (goto-char (point-min))
1944 (while (setq beg (next-single-property-change (point) 'org-cwidth))
1945 (setq end (next-single-property-change beg 'org-cwidth))
1946 (delete-region beg end)
1947 (goto-char beg)))
1948 (goto-char (point-min))))
1950 (defun org-export-ascii-clean-string ()
1951 "Do extra work for ASCII export"
1952 (goto-char (point-min))
1953 (while (re-search-forward org-verbatim-re nil t)
1954 (goto-char (match-end 2))
1955 (backward-delete-char 1) (insert "'")
1956 (goto-char (match-beginning 2))
1957 (delete-char 1) (insert "`")
1958 (goto-char (match-end 2))))
1960 (defun org-search-todo-below (line lines level)
1961 "Search the subtree below LINE for any TODO entries."
1962 (let ((rest (cdr (memq line lines)))
1963 (re org-todo-line-regexp)
1964 line lv todo)
1965 (catch 'exit
1966 (while (setq line (pop rest))
1967 (if (string-match re line)
1968 (progn
1969 (setq lv (- (match-end 1) (match-beginning 1))
1970 todo (and (match-beginning 2)
1971 (not (member (match-string 2 line)
1972 org-done-keywords))))
1973 ; TODO, not DONE
1974 (if (<= lv level) (throw 'exit nil))
1975 (if todo (throw 'exit t))))))))
1977 (defun org-html-expand-for-ascii (line)
1978 "Handle quoted HTML for ASCII export."
1979 (if org-export-html-expand
1980 (while (string-match "@<[^<>\n]*>" line)
1981 ;; We just remove the tags for now.
1982 (setq line (replace-match "" nil nil line))))
1983 line)
1985 (defun org-insert-centered (s &optional underline)
1986 "Insert the string S centered and underline it with character UNDERLINE."
1987 (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
1988 (insert (make-string ind ?\ ) s "\n")
1989 (if underline
1990 (insert (make-string ind ?\ )
1991 (make-string (string-width s) underline)
1992 "\n"))))
1994 (defun org-ascii-level-start (level title umax &optional lines)
1995 "Insert a new level in ASCII export."
1996 (let (char (n (- level umax 1)) (ind 0))
1997 (if (> level umax)
1998 (progn
1999 (insert (make-string (* 2 n) ?\ )
2000 (char-to-string (nth (% n (length org-export-ascii-bullets))
2001 org-export-ascii-bullets))
2002 " " title "\n")
2003 ;; find the indentation of the next non-empty line
2004 (catch 'stop
2005 (while lines
2006 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2007 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2008 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2009 (pop lines)))
2010 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2011 (if (or (not (equal (char-before) ?\n))
2012 (not (equal (char-before (1- (point))) ?\n)))
2013 (insert "\n"))
2014 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2015 (unless org-export-with-tags
2016 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2017 (setq title (replace-match "" t t title))))
2018 (if org-export-with-section-numbers
2019 (setq title (concat (org-section-number level) " " title)))
2020 (insert title "\n" (make-string (string-width title) char) "\n")
2021 (setq org-ascii-current-indentation '(0 . 0)))))
2023 ;;;###autoload
2024 (defun org-export-visible (type arg)
2025 "Create a copy of the visible part of the current buffer, and export it.
2026 The copy is created in a temporary buffer and removed after use.
2027 TYPE is the final key (as a string) that also select the export command in
2028 the `C-c C-e' export dispatcher.
2029 As a special case, if the you type SPC at the prompt, the temporary
2030 org-mode file will not be removed but presented to you so that you can
2031 continue to use it. The prefix arg ARG is passed through to the exporting
2032 command."
2033 (interactive
2034 (list (progn
2035 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2036 (read-char-exclusive))
2037 current-prefix-arg))
2038 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2039 (error "Invalid export key"))
2040 (let* ((binding (cdr (assoc type
2041 '((?a . org-export-as-ascii)
2042 (?\C-a . org-export-as-ascii)
2043 (?b . org-export-as-html-and-open)
2044 (?\C-b . org-export-as-html-and-open)
2045 (?h . org-export-as-html)
2046 (?H . org-export-as-html-to-buffer)
2047 (?R . org-export-region-as-html)
2048 (?x . org-export-as-xoxo)))))
2049 (keepp (equal type ?\ ))
2050 (file buffer-file-name)
2051 (buffer (get-buffer-create "*Org Export Visible*"))
2052 s e)
2053 ;; Need to hack the drawers here.
2054 (save-excursion
2055 (goto-char (point-min))
2056 (while (re-search-forward org-drawer-regexp nil t)
2057 (goto-char (match-beginning 1))
2058 (or (org-invisible-p) (org-flag-drawer nil))))
2059 (with-current-buffer buffer (erase-buffer))
2060 (save-excursion
2061 (setq s (goto-char (point-min)))
2062 (while (not (= (point) (point-max)))
2063 (goto-char (org-find-invisible))
2064 (append-to-buffer buffer s (point))
2065 (setq s (goto-char (org-find-visible))))
2066 (org-cycle-hide-drawers 'all)
2067 (goto-char (point-min))
2068 (unless keepp
2069 ;; Copy all comment lines to the end, to make sure #+ settings are
2070 ;; still available for the second export step. Kind of a hack, but
2071 ;; does do the trick.
2072 (if (looking-at "#[^\r\n]*")
2073 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2074 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2075 (append-to-buffer buffer (1+ (match-beginning 0))
2076 (min (point-max) (1+ (match-end 0))))))
2077 (set-buffer buffer)
2078 (let ((buffer-file-name file)
2079 (org-inhibit-startup t))
2080 (org-mode)
2081 (show-all)
2082 (unless keepp (funcall binding arg))))
2083 (if (not keepp)
2084 (kill-buffer buffer)
2085 (switch-to-buffer-other-window buffer)
2086 (goto-char (point-min)))))
2088 (defun org-find-visible ()
2089 (let ((s (point)))
2090 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2091 (get-char-property s 'invisible)))
2093 (defun org-find-invisible ()
2094 (let ((s (point)))
2095 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2096 (not (get-char-property s 'invisible))))
2099 ;;; HTML export
2101 (defvar org-archive-location) ;; gets loades with the org-archive require.
2102 (defun org-get-current-options ()
2103 "Return a string with current options as keyword options.
2104 Does include HTML export options as well as TODO and CATEGORY stuff."
2105 (require 'org-archive)
2106 (format
2107 "#+TITLE: %s
2108 #+AUTHOR: %s
2109 #+EMAIL: %s
2110 #+DATE: %s
2111 #+LANGUAGE: %s
2112 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2113 #+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
2115 #+LINK_UP: %s
2116 #+LINK_HOME: %s
2117 #+CATEGORY: %s
2118 #+SEQ_TODO: %s
2119 #+TYP_TODO: %s
2120 #+PRIORITIES: %c %c %c
2121 #+DRAWERS: %s
2122 #+STARTUP: %s %s %s %s %s
2123 #+TAGS: %s
2124 #+ARCHIVE: %s
2125 #+LINK: %s
2127 (buffer-name) (user-full-name) user-mail-address
2128 (format-time-string (car org-time-stamp-formats))
2129 org-export-default-language
2130 org-export-headline-levels
2131 org-export-with-section-numbers
2132 org-export-with-toc
2133 org-export-preserve-breaks
2134 org-export-html-expand
2135 org-export-with-fixed-width
2136 org-export-with-tables
2137 org-export-with-sub-superscripts
2138 org-export-with-special-strings
2139 org-export-with-footnotes
2140 org-export-with-emphasize
2141 org-export-with-TeX-macros
2142 org-export-with-LaTeX-fragments
2143 org-export-skip-text-before-1st-heading
2144 org-export-with-drawers
2145 org-export-with-tags
2146 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2147 org-export-html-link-up
2148 org-export-html-link-home
2149 (file-name-nondirectory buffer-file-name)
2150 "TODO FEEDBACK VERIFY DONE"
2151 "Me Jason Marie DONE"
2152 org-highest-priority org-lowest-priority org-default-priority
2153 (mapconcat 'identity org-drawers " ")
2154 (cdr (assoc org-startup-folded
2155 '((nil . "showall") (t . "overview") (content . "content"))))
2156 (if org-odd-levels-only "odd" "oddeven")
2157 (if org-hide-leading-stars "hidestars" "showstars")
2158 (if org-startup-align-all-tables "align" "noalign")
2159 (cond ((eq org-log-done t) "logdone")
2160 ((equal org-log-done 'note) "lognotedone")
2161 ((not org-log-done) "nologdone"))
2162 (or (mapconcat (lambda (x)
2163 (cond
2164 ((equal '(:startgroup) x) "{")
2165 ((equal '(:endgroup) x) "}")
2166 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2167 (t (car x))))
2168 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2169 org-archive-location
2170 "org file:~/org/%s.org"
2173 ;;;###autoload
2174 (defun org-insert-export-options-template ()
2175 "Insert into the buffer a template with information for exporting."
2176 (interactive)
2177 (if (not (bolp)) (newline))
2178 (let ((s (org-get-current-options)))
2179 (and (string-match "#\\+CATEGORY" s)
2180 (setq s (substring s 0 (match-beginning 0))))
2181 (insert s)))
2183 ;;;###autoload
2184 (defun org-export-as-html-and-open (arg)
2185 "Export the outline as HTML and immediately open it with a browser.
2186 If there is an active region, export only the region.
2187 The prefix ARG specifies how many levels of the outline should become
2188 headlines. The default is 3. Lower levels will become bulleted lists."
2189 (interactive "P")
2190 (org-export-as-html arg 'hidden)
2191 (org-open-file buffer-file-name))
2193 ;;;###autoload
2194 (defun org-export-as-html-batch ()
2195 "Call `org-export-as-html', may be used in batch processing as
2196 emacs --batch
2197 --load=$HOME/lib/emacs/org.el
2198 --eval \"(setq org-export-headline-levels 2)\"
2199 --visit=MyFile --funcall org-export-as-html-batch"
2200 (org-export-as-html org-export-headline-levels 'hidden))
2202 ;;;###autoload
2203 (defun org-export-as-html-to-buffer (arg)
2204 "Call `org-exort-as-html` with output to a temporary buffer.
2205 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2206 (interactive "P")
2207 (org-export-as-html arg nil nil "*Org HTML Export*")
2208 (switch-to-buffer-other-window "*Org HTML Export*"))
2210 ;;;###autoload
2211 (defun org-replace-region-by-html (beg end)
2212 "Assume the current region has org-mode syntax, and convert it to HTML.
2213 This can be used in any buffer. For example, you could write an
2214 itemized list in org-mode syntax in an HTML buffer and then use this
2215 command to convert it."
2216 (interactive "r")
2217 (let (reg html buf pop-up-frames)
2218 (save-window-excursion
2219 (if (org-mode-p)
2220 (setq html (org-export-region-as-html
2221 beg end t 'string))
2222 (setq reg (buffer-substring beg end)
2223 buf (get-buffer-create "*Org tmp*"))
2224 (with-current-buffer buf
2225 (erase-buffer)
2226 (insert reg)
2227 (org-mode)
2228 (setq html (org-export-region-as-html
2229 (point-min) (point-max) t 'string)))
2230 (kill-buffer buf)))
2231 (delete-region beg end)
2232 (insert html)))
2234 ;;;###autoload
2235 (defun org-export-region-as-html (beg end &optional body-only buffer)
2236 "Convert region from BEG to END in org-mode buffer to HTML.
2237 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2238 contents, and only produce the region of converted text, useful for
2239 cut-and-paste operations.
2240 If BUFFER is a buffer or a string, use/create that buffer as a target
2241 of the converted HTML. If BUFFER is the symbol `string', return the
2242 produced HTML as a string and leave not buffer behind. For example,
2243 a Lisp program could call this function in the following way:
2245 (setq html (org-export-region-as-html beg end t 'string))
2247 When called interactively, the output buffer is selected, and shown
2248 in a window. A non-interactive call will only return the buffer."
2249 (interactive "r\nP")
2250 (when (interactive-p)
2251 (setq buffer "*Org HTML Export*"))
2252 (let ((transient-mark-mode t) (zmacs-regions t)
2253 rtn)
2254 (goto-char end)
2255 (set-mark (point)) ;; to activate the region
2256 (goto-char beg)
2257 (setq rtn (org-export-as-html
2258 nil nil nil
2259 buffer body-only))
2260 (if (fboundp 'deactivate-mark) (deactivate-mark))
2261 (if (and (interactive-p) (bufferp rtn))
2262 (switch-to-buffer-other-window rtn)
2263 rtn)))
2265 (defvar html-table-tag nil) ; dynamically scoped into this.
2266 ;;;###autoload
2267 (defun org-export-as-html (arg &optional hidden ext-plist
2268 to-buffer body-only pub-dir)
2269 "Export the outline as a pretty HTML file.
2270 If there is an active region, export only the region. The prefix
2271 ARG specifies how many levels of the outline should become
2272 headlines. The default is 3. Lower levels will become bulleted
2273 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2274 EXT-PLIST is a property list with external parameters overriding
2275 org-mode's default settings, but still inferior to file-local
2276 settings. When TO-BUFFER is non-nil, create a buffer with that
2277 name and export to that buffer. If TO-BUFFER is the symbol
2278 `string', don't leave any buffer behind but just return the
2279 resulting HTML as a string. When BODY-ONLY is set, don't produce
2280 the file header and footer, simply return the content of
2281 <body>...</body>, without even the body tags themselves. When
2282 PUB-DIR is set, use this as the publishing directory."
2283 (interactive "P")
2285 ;; Make sure we have a file name when we need it.
2286 (when (and (not (or to-buffer body-only))
2287 (not buffer-file-name))
2288 (if (buffer-base-buffer)
2289 (org-set-local 'buffer-file-name
2290 (with-current-buffer (buffer-base-buffer)
2291 buffer-file-name))
2292 (error "Need a file name to be able to export.")))
2294 (message "Exporting...")
2295 (setq-default org-todo-line-regexp org-todo-line-regexp)
2296 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2297 (setq-default org-done-keywords org-done-keywords)
2298 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2299 (let* ((opt-plist
2300 (org-export-process-option-filters
2301 (org-combine-plists (org-default-export-plist)
2302 ext-plist
2303 (org-infile-export-plist))))
2305 (style (plist-get opt-plist :style))
2306 (html-extension (plist-get opt-plist :html-extension))
2307 (link-validate (plist-get opt-plist :link-validation-function))
2308 valid thetoc have-headings first-heading-pos
2309 (odd org-odd-levels-only)
2310 (region-p (org-region-active-p))
2311 (subtree-p
2312 (when region-p
2313 (save-excursion
2314 (goto-char (region-beginning))
2315 (and (org-at-heading-p)
2316 (>= (org-end-of-subtree t t) (region-end))))))
2317 ;; The following two are dynamically scoped into other
2318 ;; routines below.
2319 (org-current-export-dir
2320 (or pub-dir (org-export-directory :html opt-plist)))
2321 (org-current-export-file buffer-file-name)
2322 (level 0) (line "") (origline "") txt todo
2323 (umax nil)
2324 (umax-toc nil)
2325 (filename (if to-buffer nil
2326 (expand-file-name
2327 (concat
2328 (file-name-sans-extension
2329 (or (and subtree-p
2330 (org-entry-get (region-beginning)
2331 "EXPORT_FILE_NAME" t))
2332 (file-name-nondirectory buffer-file-name)))
2333 "." html-extension)
2334 (file-name-as-directory
2335 (or pub-dir (org-export-directory :html opt-plist))))))
2336 (current-dir (if buffer-file-name
2337 (file-name-directory buffer-file-name)
2338 default-directory))
2339 (buffer (if to-buffer
2340 (cond
2341 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2342 (t (get-buffer-create to-buffer)))
2343 (find-file-noselect filename)))
2344 (org-levels-open (make-vector org-level-max nil))
2345 (date (plist-get opt-plist :date))
2346 (author (plist-get opt-plist :author))
2347 (title (or (and subtree-p (org-export-get-title-from-subtree))
2348 (plist-get opt-plist :title)
2349 (and (not
2350 (plist-get opt-plist :skip-before-1st-heading))
2351 (org-export-grab-title-from-buffer))
2352 (and buffer-file-name
2353 (file-name-sans-extension
2354 (file-name-nondirectory buffer-file-name)))
2355 "UNTITLED"))
2356 (html-table-tag (plist-get opt-plist :html-table-tag))
2357 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2358 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2359 (inquote nil)
2360 (infixed nil)
2361 (in-local-list nil)
2362 (local-list-type nil)
2363 (local-list-indent nil)
2364 (llt org-plain-list-ordered-item-terminator)
2365 (email (plist-get opt-plist :email))
2366 (language (plist-get opt-plist :language))
2367 (lang-words nil)
2368 (head-count 0) cnt
2369 (start 0)
2370 (coding-system (and (boundp 'buffer-file-coding-system)
2371 buffer-file-coding-system))
2372 (coding-system-for-write (or org-export-html-coding-system
2373 coding-system))
2374 (save-buffer-coding-system (or org-export-html-coding-system
2375 coding-system))
2376 (charset (and coding-system-for-write
2377 (fboundp 'coding-system-get)
2378 (coding-system-get coding-system-for-write
2379 'mime-charset)))
2380 (region
2381 (buffer-substring
2382 (if region-p (region-beginning) (point-min))
2383 (if region-p (region-end) (point-max))))
2384 (lines
2385 (org-split-string
2386 (org-export-preprocess-string
2387 region
2388 :emph-multiline t
2389 :for-html t
2390 :skip-before-1st-heading
2391 (plist-get opt-plist :skip-before-1st-heading)
2392 :drawers (plist-get opt-plist :drawers)
2393 :archived-trees
2394 (plist-get opt-plist :archived-trees)
2395 :add-text
2396 (plist-get opt-plist :text)
2397 :LaTeX-fragments
2398 (plist-get opt-plist :LaTeX-fragments))
2399 "[\r\n]"))
2400 table-open type
2401 table-buffer table-orig-buffer
2402 ind item-type starter didclose
2403 rpl path desc descp desc1 desc2 link
2404 snumber fnc item-tag
2407 (let ((inhibit-read-only t))
2408 (org-unmodified
2409 (remove-text-properties (point-min) (point-max)
2410 '(:org-license-to-kill t))))
2412 (message "Exporting...")
2414 (setq org-min-level (org-get-min-level lines))
2415 (setq org-last-level org-min-level)
2416 (org-init-section-numbers)
2418 (cond
2419 ((and date (string-match "%" date))
2420 (setq date (format-time-string date)))
2421 (date)
2422 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2424 ;; Get the language-dependent settings
2425 (setq lang-words (or (assoc language org-export-language-setup)
2426 (assoc "en" org-export-language-setup)))
2428 ;; Switch to the output buffer
2429 (set-buffer buffer)
2430 (let ((inhibit-read-only t)) (erase-buffer))
2431 (fundamental-mode)
2433 (and (fboundp 'set-buffer-file-coding-system)
2434 (set-buffer-file-coding-system coding-system-for-write))
2436 (let ((case-fold-search nil)
2437 (org-odd-levels-only odd))
2438 ;; create local variables for all options, to make sure all called
2439 ;; functions get the correct information
2440 (mapc (lambda (x)
2441 (set (make-local-variable (cdr x))
2442 (plist-get opt-plist (car x))))
2443 org-export-plist-vars)
2444 (setq umax (if arg (prefix-numeric-value arg)
2445 org-export-headline-levels))
2446 (setq umax-toc (if (integerp org-export-with-toc)
2447 (min org-export-with-toc umax)
2448 umax))
2449 (unless body-only
2450 ;; File header
2451 (insert (format
2452 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2453 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2454 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2455 lang=\"%s\" xml:lang=\"%s\">
2456 <head>
2457 <title>%s</title>
2458 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2459 <meta name=\"generator\" content=\"Org-mode\"/>
2460 <meta name=\"generated\" content=\"%s\"/>
2461 <meta name=\"author\" content=\"%s\"/>
2463 </head><body>
2465 language language (org-html-expand title)
2466 (or charset "iso-8859-1") date author style))
2468 (insert (or (plist-get opt-plist :preamble) ""))
2470 (when (plist-get opt-plist :auto-preamble)
2471 (if title (insert (format org-export-html-title-format
2472 (org-html-expand title))))))
2474 (if (and org-export-with-toc (not body-only))
2475 (progn
2476 (push (format "<h%d>%s</h%d>\n"
2477 org-export-html-toplevel-hlevel
2478 (nth 3 lang-words)
2479 org-export-html-toplevel-hlevel)
2480 thetoc)
2481 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2482 (push "<ul>\n<li>" thetoc)
2483 (setq lines
2484 (mapcar '(lambda (line)
2485 (if (string-match org-todo-line-regexp line)
2486 ;; This is a headline
2487 (progn
2488 (setq have-headings t)
2489 (setq level (- (match-end 1) (match-beginning 1))
2490 level (org-tr-level level)
2491 txt (save-match-data
2492 (org-html-expand
2493 (org-export-cleanup-toc-line
2494 (match-string 3 line))))
2495 todo
2496 (or (and org-export-mark-todo-in-toc
2497 (match-beginning 2)
2498 (not (member (match-string 2 line)
2499 org-done-keywords)))
2500 ; TODO, not DONE
2501 (and org-export-mark-todo-in-toc
2502 (= level umax-toc)
2503 (org-search-todo-below
2504 line lines level))))
2505 (if (string-match
2506 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2507 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2508 (if (string-match quote-re0 txt)
2509 (setq txt (replace-match "" t t txt)))
2510 (setq snumber (org-section-number level))
2511 (if org-export-with-section-numbers
2512 (setq txt (concat snumber " " txt)))
2513 (if (<= level (max umax umax-toc))
2514 (setq head-count (+ head-count 1)))
2515 (if (<= level umax-toc)
2516 (progn
2517 (if (> level org-last-level)
2518 (progn
2519 (setq cnt (- level org-last-level))
2520 (while (>= (setq cnt (1- cnt)) 0)
2521 (push "\n<ul>\n<li>" thetoc))
2522 (push "\n" thetoc)))
2523 (if (< level org-last-level)
2524 (progn
2525 (setq cnt (- org-last-level level))
2526 (while (>= (setq cnt (1- cnt)) 0)
2527 (push "</li>\n</ul>" thetoc))
2528 (push "\n" thetoc)))
2529 ;; Check for targets
2530 (while (string-match org-any-target-regexp line)
2531 (setq line (replace-match
2532 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2533 t t line)))
2534 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2535 (setq txt (replace-match "" t t txt)))
2536 (push
2537 (format
2538 (if todo
2539 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2540 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2541 snumber txt) thetoc)
2543 (setq org-last-level level))
2545 line)
2546 lines))
2547 (while (> org-last-level (1- org-min-level))
2548 (setq org-last-level (1- org-last-level))
2549 (push "</li>\n</ul>\n" thetoc))
2550 (push "</div>\n" thetoc)
2551 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2553 (setq head-count 0)
2554 (org-init-section-numbers)
2556 (while (setq line (pop lines) origline line)
2557 (catch 'nextline
2559 ;; end of quote section?
2560 (when (and inquote (string-match "^\\*+ " line))
2561 (insert "</pre>\n")
2562 (setq inquote nil))
2563 ;; inside a quote section?
2564 (when inquote
2565 (insert (org-html-protect line) "\n")
2566 (throw 'nextline nil))
2568 ;; verbatim lines
2569 (when (and org-export-with-fixed-width
2570 (string-match "^[ \t]*:\\(.*\\)" line))
2571 (when (not infixed)
2572 (setq infixed t)
2573 (insert "<pre>\n"))
2574 (insert (org-html-protect (match-string 1 line)) "\n")
2575 (when (and lines
2576 (not (string-match "^[ \t]*\\(:.*\\)"
2577 (car lines))))
2578 (setq infixed nil)
2579 (insert "</pre>\n"))
2580 (throw 'nextline nil))
2582 ;; Protected HTML
2583 (when (get-text-property 0 'org-protected line)
2584 (let (par)
2585 (when (re-search-backward
2586 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2587 (setq par (match-string 1))
2588 (replace-match "\\2\n"))
2589 (insert line "\n")
2590 (while (and lines
2591 (not (string-match "^[ \t]*:" (car lines)))
2592 (or (= (length (car lines)) 0)
2593 (get-text-property 0 'org-protected (car lines))))
2594 (insert (pop lines) "\n"))
2595 (and par (insert "<p>\n")))
2596 (throw 'nextline nil))
2598 ;; Horizontal line
2599 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2600 (insert "\n<hr/>\n")
2601 (throw 'nextline nil))
2603 ;; Blockquotes
2604 (when (equal "ORG-BLOCKQUOTE-START" line)
2605 (insert "<blockquote>\n<p>\n")
2606 (throw 'nextline nil))
2607 (when (equal "ORG-BLOCKQUOTE-END" line)
2608 (insert "</p>\n</blockquote>\n")
2609 (throw 'nextline nil))
2611 ;; make targets to anchors
2612 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2613 (cond
2614 ((match-end 2)
2615 (setq line (replace-match
2616 (concat "@<a name=\""
2617 (org-solidify-link-text (match-string 1 line))
2618 "\">\\nbsp@</a>")
2619 t t line)))
2620 ((and org-export-with-toc (equal (string-to-char line) ?*))
2621 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2622 (setq line (replace-match
2623 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2624 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2625 t t line)))
2627 (setq line (replace-match
2628 (concat "@<a name=\""
2629 (org-solidify-link-text (match-string 1 line))
2630 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2631 t t line)))))
2633 (setq line (org-html-handle-time-stamps line))
2635 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2636 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2637 ;; Also handle sub_superscripts and checkboxes
2638 (or (string-match org-table-hline-regexp line)
2639 (setq line (org-html-expand line)))
2641 ;; Format the links
2642 (setq start 0)
2643 (while (string-match org-bracket-link-analytic-regexp line start)
2644 (setq start (match-beginning 0))
2645 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2646 (setq path (match-string 3 line))
2647 (setq desc1 (if (match-end 5) (match-string 5 line))
2648 desc2 (if (match-end 2) (concat type ":" path) path)
2649 descp (and desc1 (not (equal desc1 desc2)))
2650 desc (or desc1 desc2))
2651 ;; Make an image out of the description if that is so wanted
2652 (when (and descp (org-file-image-p desc))
2653 (save-match-data
2654 (if (string-match "^file:" desc)
2655 (setq desc (substring desc (match-end 0)))))
2656 (setq desc (concat "<img src=\"" desc "\"/>")))
2657 ;; FIXME: do we need to unescape here somewhere?
2658 (cond
2659 ((equal type "internal")
2660 (setq rpl
2661 (concat
2662 "<a href=\"#"
2663 (org-solidify-link-text
2664 (save-match-data (org-link-unescape path)) nil)
2665 "\">" desc "</a>")))
2666 ((member type '("http" "https"))
2667 ;; standard URL, just check if we need to inline an image
2668 (if (and (or (eq t org-export-html-inline-images)
2669 (and org-export-html-inline-images (not descp)))
2670 (org-file-image-p path))
2671 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2672 (setq link (concat type ":" path))
2673 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2674 ((member type '("ftp" "mailto" "news"))
2675 ;; standard URL
2676 (setq link (concat type ":" path))
2677 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2678 ((string= type "file")
2679 ;; FILE link
2680 (let* ((filename path)
2681 (abs-p (file-name-absolute-p filename))
2682 thefile file-is-image-p search)
2683 (save-match-data
2684 (if (string-match "::\\(.*\\)" filename)
2685 (setq search (match-string 1 filename)
2686 filename (replace-match "" t nil filename)))
2687 (setq valid
2688 (if (functionp link-validate)
2689 (funcall link-validate filename current-dir)
2691 (setq file-is-image-p (org-file-image-p filename))
2692 (setq thefile (if abs-p (expand-file-name filename) filename))
2693 (when (and org-export-html-link-org-files-as-html
2694 (string-match "\\.org$" thefile))
2695 (setq thefile (concat (substring thefile 0
2696 (match-beginning 0))
2697 "." html-extension))
2698 (if (and search
2699 ;; make sure this is can be used as target search
2700 (not (string-match "^[0-9]*$" search))
2701 (not (string-match "^\\*" search))
2702 (not (string-match "^/.*/$" search)))
2703 (setq thefile (concat thefile "#"
2704 (org-solidify-link-text
2705 (org-link-unescape search)))))
2706 (when (string-match "^file:" desc)
2707 (setq desc (replace-match "" t t desc))
2708 (if (string-match "\\.org$" desc)
2709 (setq desc (replace-match "" t t desc))))))
2710 (setq rpl (if (and file-is-image-p
2711 (or (eq t org-export-html-inline-images)
2712 (and org-export-html-inline-images
2713 (not descp))))
2714 (concat "<img src=\"" thefile "\"/>")
2715 (concat "<a href=\"" thefile "\">" desc "</a>")))
2716 (if (not valid) (setq rpl desc))))
2718 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2719 (setq rpl
2720 (save-match-data
2721 (funcall fnc (org-link-unescape path) desc1 'html))))
2724 ;; just publish the path, as default
2725 (setq rpl (concat "<i>&lt;" type ":"
2726 (save-match-data (org-link-unescape path))
2727 "&gt;</i>"))))
2728 (setq line (replace-match rpl t t line)
2729 start (+ start (length rpl))))
2731 ;; TODO items
2732 (if (and (string-match org-todo-line-regexp line)
2733 (match-beginning 2))
2735 (setq line
2736 (concat (substring line 0 (match-beginning 2))
2737 "<span class=\""
2738 (if (member (match-string 2 line)
2739 org-done-keywords)
2740 "done" "todo")
2741 "\">" (match-string 2 line)
2742 "</span>" (substring line (match-end 2)))))
2744 ;; Does this contain a reference to a footnote?
2745 (when org-export-with-footnotes
2746 (setq start 0)
2747 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
2748 (if (get-text-property (match-beginning 2) 'org-protected line)
2749 (setq start (match-end 2))
2750 (let ((n (match-string 2 line)))
2751 (setq line
2752 (replace-match
2753 (format
2754 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2755 (match-string 1 line) n n n)
2756 t t line))))))
2758 (cond
2759 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2760 ;; This is a headline
2761 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2762 txt (match-string 2 line))
2763 (if (string-match quote-re0 txt)
2764 (setq txt (replace-match "" t t txt)))
2765 (if (<= level (max umax umax-toc))
2766 (setq head-count (+ head-count 1)))
2767 (when in-local-list
2768 ;; Close any local lists before inserting a new header line
2769 (while local-list-type
2770 (org-close-li (car local-list-type))
2771 (insert (format "</%sl>\n" (car local-list-type)))
2772 (pop local-list-type))
2773 (setq local-list-indent nil
2774 in-local-list nil))
2775 (setq first-heading-pos (or first-heading-pos (point)))
2776 (org-html-level-start level txt umax
2777 (and org-export-with-toc (<= level umax))
2778 head-count)
2779 ;; QUOTES
2780 (when (string-match quote-re line)
2781 (insert "<pre>")
2782 (setq inquote t)))
2784 ((and org-export-with-tables
2785 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2786 (if (not table-open)
2787 ;; New table starts
2788 (setq table-open t table-buffer nil table-orig-buffer nil))
2789 ;; Accumulate lines
2790 (setq table-buffer (cons line table-buffer)
2791 table-orig-buffer (cons origline table-orig-buffer))
2792 (when (or (not lines)
2793 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2794 (car lines))))
2795 (setq table-open nil
2796 table-buffer (nreverse table-buffer)
2797 table-orig-buffer (nreverse table-orig-buffer))
2798 (org-close-par-maybe)
2799 (insert (org-format-table-html table-buffer table-orig-buffer))))
2801 ;; Normal lines
2802 (when (string-match
2803 (cond
2804 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2805 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2806 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2807 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2808 line)
2809 (setq ind (org-get-string-indentation line)
2810 item-type (if (match-beginning 4) "o" "u")
2811 starter (if (match-beginning 2)
2812 (substring (match-string 2 line) 0 -1))
2813 line (substring line (match-beginning 5))
2814 item-tag nil)
2815 (if (string-match "\\(.*?\\) ::[ \t]*" line)
2816 (setq item-type "d"
2817 item-tag (match-string 1 line)
2818 line (substring line (match-end 0))))
2819 (unless (string-match "[^ \t]" line)
2820 ;; empty line. Pretend indentation is large.
2821 (setq ind (if org-empty-line-terminates-plain-lists
2823 (1+ (or (car local-list-indent) 1)))))
2824 (setq didclose nil)
2825 (while (and in-local-list
2826 (or (and (= ind (car local-list-indent))
2827 (not starter))
2828 (< ind (car local-list-indent))))
2829 (setq didclose t)
2830 (org-close-li (car local-list-type))
2831 (insert (format "</%sl>\n" (car local-list-type)))
2832 (pop local-list-type) (pop local-list-indent)
2833 (setq in-local-list local-list-indent))
2834 (cond
2835 ((and starter
2836 (or (not in-local-list)
2837 (> ind (car local-list-indent))))
2838 ;; Start new (level of) list
2839 (org-close-par-maybe)
2840 (insert (cond
2841 ((equal item-type "u") "<ul>\n<li>\n")
2842 ((equal item-type "o") "<ol>\n<li>\n")
2843 ((equal item-type "d")
2844 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
2845 (push item-type local-list-type)
2846 (push ind local-list-indent)
2847 (setq in-local-list t))
2848 (starter
2849 ;; continue current list
2850 (org-close-li (car local-list-type))
2851 (insert (cond
2852 ((equal (car local-list-type) "d")
2853 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
2854 (t "<li>\n"))))
2855 (didclose
2856 ;; we did close a list, normal text follows: need <p>
2857 (org-open-par)))
2858 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
2859 (setq line
2860 (replace-match
2861 (if (equal (match-string 1 line) "X")
2862 "<b>[X]</b>"
2863 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2864 t t line))))
2866 ;; Empty lines start a new paragraph. If hand-formatted lists
2867 ;; are not fully interpreted, lines starting with "-", "+", "*"
2868 ;; also start a new paragraph.
2869 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
2871 ;; Is this the start of a footnote?
2872 (when org-export-with-footnotes
2873 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
2874 (org-close-par-maybe)
2875 (let ((n (match-string 1 line)))
2876 (setq line (replace-match
2877 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
2879 ;; Check if the line break needs to be conserved
2880 (cond
2881 ((string-match "\\\\\\\\[ \t]*$" line)
2882 (setq line (replace-match "<br/>" t t line)))
2883 (org-export-preserve-breaks
2884 (setq line (concat line "<br/>"))))
2886 (insert line "\n")))))
2888 ;; Properly close all local lists and other lists
2889 (when inquote (insert "</pre>\n"))
2890 (when in-local-list
2891 ;; Close any local lists before inserting a new header line
2892 (while local-list-type
2893 (org-close-li (car local-list-type))
2894 (insert (format "</%sl>\n" (car local-list-type)))
2895 (pop local-list-type))
2896 (setq local-list-indent nil
2897 in-local-list nil))
2898 (org-html-level-start 1 nil umax
2899 (and org-export-with-toc (<= level umax))
2900 head-count)
2901 ;; the </div> to lose the last text-... div.
2902 (insert "</div>\n")
2904 (unless body-only
2905 (when (plist-get opt-plist :auto-postamble)
2906 (insert "<div id=\"postamble\">")
2907 (when (and org-export-author-info author)
2908 (insert "<p class=\"author\"> "
2909 (nth 1 lang-words) ": " author "\n")
2910 (when email
2911 (if (listp (split-string email ",+ *"))
2912 (mapc (lambda(e)
2913 (insert "<a href=\"mailto:" e "\">&lt;"
2914 e "&gt;</a>\n"))
2915 (split-string email ",+ *"))
2916 (insert "<a href=\"mailto:" email "\">&lt;"
2917 email "&gt;</a>\n")))
2918 (insert "</p>\n"))
2919 (when (and date org-export-time-stamp-file)
2920 (insert "<p class=\"date\"> "
2921 (nth 2 lang-words) ": "
2922 date "</p>\n"))
2923 (insert "</div>"))
2925 (if org-export-html-with-timestamp
2926 (insert org-export-html-html-helper-timestamp))
2927 (insert (or (plist-get opt-plist :postamble) ""))
2928 (insert "</body>\n</html>\n"))
2930 (normal-mode)
2931 (if (eq major-mode default-major-mode) (html-mode))
2933 ;; insert the table of contents
2934 (goto-char (point-min))
2935 (when thetoc
2936 (if (or (re-search-forward
2937 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
2938 (re-search-forward
2939 "\\[TABLE-OF-CONTENTS\\]" nil t))
2940 (progn
2941 (goto-char (match-beginning 0))
2942 (replace-match ""))
2943 (goto-char first-heading-pos)
2944 (when (looking-at "\\s-*</p>")
2945 (goto-char (match-end 0))
2946 (insert "\n")))
2947 (insert "<div id=\"table-of-contents\">\n")
2948 (mapc 'insert thetoc)
2949 (insert "</div>\n"))
2950 ;; remove empty paragraphs and lists
2951 (goto-char (point-min))
2952 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2953 (replace-match ""))
2954 (goto-char (point-min))
2955 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
2956 (replace-match ""))
2957 (goto-char (point-min))
2958 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
2959 (replace-match ""))
2960 ;; Convert whitespace place holders
2961 (goto-char (point-min))
2962 (let (beg end n)
2963 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2964 (setq n (get-text-property beg 'org-whitespace)
2965 end (next-single-property-change beg 'org-whitespace))
2966 (goto-char beg)
2967 (delete-region beg end)
2968 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2969 (make-string n ?x)))))
2970 (or to-buffer (save-buffer))
2971 (goto-char (point-min))
2972 (message "Exporting... done")
2973 (if (eq to-buffer 'string)
2974 (prog1 (buffer-substring (point-min) (point-max))
2975 (kill-buffer (current-buffer)))
2976 (current-buffer)))))
2978 (defvar org-table-colgroup-info nil)
2979 (defun org-format-table-ascii (lines)
2980 "Format a table for ascii export."
2981 (if (stringp lines)
2982 (setq lines (org-split-string lines "\n")))
2983 (if (not (string-match "^[ \t]*|" (car lines)))
2984 ;; Table made by table.el - test for spanning
2985 lines
2987 ;; A normal org table
2988 ;; Get rid of hlines at beginning and end
2989 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2990 (setq lines (nreverse lines))
2991 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2992 (setq lines (nreverse lines))
2993 (when org-export-table-remove-special-lines
2994 ;; Check if the table has a marking column. If yes remove the
2995 ;; column and the special lines
2996 (setq lines (org-table-clean-before-export lines)))
2997 ;; Get rid of the vertical lines except for grouping
2998 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
2999 rtn line vl1 start)
3000 (while (setq line (pop lines))
3001 (if (string-match org-table-hline-regexp line)
3002 (and (string-match "|\\(.*\\)|" line)
3003 (setq line (replace-match " \\1" t nil line)))
3004 (setq start 0 vl1 vl)
3005 (while (string-match "|" line start)
3006 (setq start (match-end 0))
3007 (or (pop vl1) (setq line (replace-match " " t t line)))))
3008 (push line rtn))
3009 (nreverse rtn))))
3011 (defun org-colgroup-info-to-vline-list (info)
3012 (let (vl new last)
3013 (while info
3014 (setq last new new (pop info))
3015 (if (or (memq last '(:end :startend))
3016 (memq new '(:start :startend)))
3017 (push t vl)
3018 (push nil vl)))
3019 (setq vl (nreverse vl))
3020 (and vl (setcar vl nil))
3021 vl))
3023 (defvar org-table-number-regexp) ; defined in org-table.el
3024 (defun org-format-table-html (lines olines)
3025 "Find out which HTML converter to use and return the HTML code."
3026 (if (stringp lines)
3027 (setq lines (org-split-string lines "\n")))
3028 (if (string-match "^[ \t]*|" (car lines))
3029 ;; A normal org table
3030 (org-format-org-table-html lines)
3031 ;; Table made by table.el - test for spanning
3032 (let* ((hlines (delq nil (mapcar
3033 (lambda (x)
3034 (if (string-match "^[ \t]*\\+-" x) x
3035 nil))
3036 lines)))
3037 (first (car hlines))
3038 (ll (and (string-match "\\S-+" first)
3039 (match-string 0 first)))
3040 (re (concat "^[ \t]*" (regexp-quote ll)))
3041 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3042 hlines))))
3043 (if (and (not spanning)
3044 (not org-export-prefer-native-exporter-for-tables))
3045 ;; We can use my own converter with HTML conversions
3046 (org-format-table-table-html lines)
3047 ;; Need to use the code generator in table.el, with the original text.
3048 (org-format-table-table-html-using-table-generate-source olines)))))
3050 (defvar org-table-number-fraction) ; defined in org-table.el
3051 (defun org-format-org-table-html (lines &optional splice)
3052 "Format a table into HTML."
3053 (require 'org-table)
3054 ;; Get rid of hlines at beginning and end
3055 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3056 (setq lines (nreverse lines))
3057 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3058 (setq lines (nreverse lines))
3059 (when org-export-table-remove-special-lines
3060 ;; Check if the table has a marking column. If yes remove the
3061 ;; column and the special lines
3062 (setq lines (org-table-clean-before-export lines)))
3064 (let ((head (and org-export-highlight-first-table-line
3065 (delq nil (mapcar
3066 (lambda (x) (string-match "^[ \t]*|-" x))
3067 (cdr lines)))))
3068 (nlines 0) fnum i
3069 tbopen line fields html gr colgropen)
3070 (if splice (setq head nil))
3071 (unless splice (push (if head "<thead>" "<tbody>") html))
3072 (setq tbopen t)
3073 (while (setq line (pop lines))
3074 (catch 'next-line
3075 (if (string-match "^[ \t]*|-" line)
3076 (progn
3077 (unless splice
3078 (push (if head "</thead>" "</tbody>") html)
3079 (if lines (push "<tbody>" html) (setq tbopen nil)))
3080 (setq head nil) ;; head ends here, first time around
3081 ;; ignore this line
3082 (throw 'next-line t)))
3083 ;; Break the line into fields
3084 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3085 (unless fnum (setq fnum (make-vector (length fields) 0)))
3086 (setq nlines (1+ nlines) i -1)
3087 (push (concat "<tr>"
3088 (mapconcat
3089 (lambda (x)
3090 (setq i (1+ i))
3091 (if (and (< i nlines)
3092 (string-match org-table-number-regexp x))
3093 (incf (aref fnum i)))
3094 (if head
3095 (concat (car org-export-table-header-tags) x
3096 (cdr org-export-table-header-tags))
3097 (concat (car org-export-table-data-tags) x
3098 (cdr org-export-table-data-tags))))
3099 fields "")
3100 "</tr>")
3101 html)))
3102 (unless splice (if tbopen (push "</tbody>" html)))
3103 (unless splice (push "</table>\n" html))
3104 (setq html (nreverse html))
3105 (unless splice
3106 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3107 (push (mapconcat
3108 (lambda (x)
3109 (setq gr (pop org-table-colgroup-info))
3110 (format "%s<col align=\"%s\"></col>%s"
3111 (if (memq gr '(:start :startend))
3112 (prog1
3113 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3114 (setq colgropen t))
3116 (if (> (/ (float x) nlines) org-table-number-fraction)
3117 "right" "left")
3118 (if (memq gr '(:end :startend))
3119 (progn (setq colgropen nil) "</colgroup>")
3120 "")))
3121 fnum "")
3122 html)
3123 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3124 (push html-table-tag html))
3125 (concat (mapconcat 'identity html "\n") "\n")))
3127 (defun org-table-clean-before-export (lines)
3128 "Check if the table has a marking column.
3129 If yes remove the column and the special lines."
3130 (setq org-table-colgroup-info nil)
3131 (if (memq nil
3132 (mapcar
3133 (lambda (x) (or (string-match "^[ \t]*|-" x)
3134 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3135 lines))
3136 (progn
3137 (setq org-table-clean-did-remove-column nil)
3138 (delq nil
3139 (mapcar
3140 (lambda (x)
3141 (cond
3142 ((string-match "^[ \t]*| */ *|" x)
3143 (setq org-table-colgroup-info
3144 (mapcar (lambda (x)
3145 (cond ((member x '("<" "&lt;")) :start)
3146 ((member x '(">" "&gt;")) :end)
3147 ((member x '("<>" "&lt;&gt;")) :startend)
3148 (t nil)))
3149 (org-split-string x "[ \t]*|[ \t]*")))
3150 nil)
3151 (t x)))
3152 lines)))
3153 (setq org-table-clean-did-remove-column t)
3154 (delq nil
3155 (mapcar
3156 (lambda (x)
3157 (cond
3158 ((string-match "^[ \t]*| */ *|" x)
3159 (setq org-table-colgroup-info
3160 (mapcar (lambda (x)
3161 (cond ((member x '("<" "&lt;")) :start)
3162 ((member x '(">" "&gt;")) :end)
3163 ((member x '("<>" "&lt;&gt;")) :startend)
3164 (t nil)))
3165 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3166 nil)
3167 ((string-match "^[ \t]*| *[!_^/] *|" x)
3168 nil) ; ignore this line
3169 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3170 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3171 ;; remove the first column
3172 (replace-match "\\1|" t nil x))))
3173 lines))))
3175 (defun org-format-table-table-html (lines)
3176 "Format a table generated by table.el into HTML.
3177 This conversion does *not* use `table-generate-source' from table.el.
3178 This has the advantage that Org-mode's HTML conversions can be used.
3179 But it has the disadvantage, that no cell- or row-spanning is allowed."
3180 (let (line field-buffer
3181 (head org-export-highlight-first-table-line)
3182 fields html empty)
3183 (setq html (concat html-table-tag "\n"))
3184 (while (setq line (pop lines))
3185 (setq empty "&nbsp;")
3186 (catch 'next-line
3187 (if (string-match "^[ \t]*\\+-" line)
3188 (progn
3189 (if field-buffer
3190 (progn
3191 (setq
3192 html
3193 (concat
3194 html
3195 "<tr>"
3196 (mapconcat
3197 (lambda (x)
3198 (if (equal x "") (setq x empty))
3199 (if head
3200 (concat (car org-export-table-header-tags) x
3201 (cdr org-export-table-header-tags))
3202 (concat (car org-export-table-data-tags) x
3203 (cdr org-export-table-data-tags))))
3204 field-buffer "\n")
3205 "</tr>\n"))
3206 (setq head nil)
3207 (setq field-buffer nil)))
3208 ;; Ignore this line
3209 (throw 'next-line t)))
3210 ;; Break the line into fields and store the fields
3211 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3212 (if field-buffer
3213 (setq field-buffer (mapcar
3214 (lambda (x)
3215 (concat x "<br/>" (pop fields)))
3216 field-buffer))
3217 (setq field-buffer fields))))
3218 (setq html (concat html "</table>\n"))
3219 html))
3221 (defun org-format-table-table-html-using-table-generate-source (lines)
3222 "Format a table into html, using `table-generate-source' from table.el.
3223 This has the advantage that cell- or row-spanning is allowed.
3224 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3225 (require 'table)
3226 (with-current-buffer (get-buffer-create " org-tmp1 ")
3227 (erase-buffer)
3228 (insert (mapconcat 'identity lines "\n"))
3229 (goto-char (point-min))
3230 (if (not (re-search-forward "|[^+]" nil t))
3231 (error "Error processing table"))
3232 (table-recognize-table)
3233 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3234 (table-generate-source 'html " org-tmp2 ")
3235 (set-buffer " org-tmp2 ")
3236 (buffer-substring (point-min) (point-max))))
3238 (defun org-html-handle-time-stamps (s)
3239 "Format time stamps in string S, or remove them."
3240 (catch 'exit
3241 (let (r b)
3242 (while (string-match org-maybe-keyword-time-regexp s)
3243 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3244 ;; never export CLOCK
3245 (throw 'exit ""))
3246 (or b (setq b (substring s 0 (match-beginning 0))))
3247 (if (not org-export-with-timestamps)
3248 (setq r (concat r (substring s 0 (match-beginning 0)))
3249 s (substring s (match-end 0)))
3250 (setq r (concat
3251 r (substring s 0 (match-beginning 0))
3252 (if (match-end 1)
3253 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3254 (match-string 1 s)))
3255 (format " @<span class=\"timestamp\">%s@</span>"
3256 (substring
3257 (org-translate-time (match-string 3 s)) 1 -1)))
3258 s (substring s (match-end 0)))))
3259 ;; Line break if line started and ended with time stamp stuff
3260 (if (not r)
3262 (setq r (concat r s))
3263 (unless (string-match "\\S-" (concat b s))
3264 (setq r (concat r "@<br/>")))
3265 r))))
3267 (defun org-html-protect (s)
3268 ;; convert & to &amp;, < to &lt; and > to &gt;
3269 (let ((start 0))
3270 (while (string-match "&" s start)
3271 (setq s (replace-match "&amp;" t t s)
3272 start (1+ (match-beginning 0))))
3273 (while (string-match "<" s)
3274 (setq s (replace-match "&lt;" t t s)))
3275 (while (string-match ">" s)
3276 (setq s (replace-match "&gt;" t t s))))
3279 (defun org-export-cleanup-toc-line (s)
3280 "Remove tags and time staps from lines going into the toc."
3281 (when (memq org-export-with-tags '(not-in-toc nil))
3282 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3283 (setq s (replace-match "" t t s))))
3284 (when org-export-remove-timestamps-from-toc
3285 (while (string-match org-maybe-keyword-time-regexp s)
3286 (setq s (replace-match "" t t s))))
3287 (while (string-match org-bracket-link-regexp s)
3288 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3289 t t s)))
3292 (defun org-html-expand (string)
3293 "Prepare STRING for HTML export. Applies all active conversions.
3294 If there are links in the string, don't modify these."
3295 (let* ((re (concat org-bracket-link-regexp "\\|"
3296 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3297 m s l res)
3298 (while (setq m (string-match re string))
3299 (setq s (substring string 0 m)
3300 l (match-string 0 string)
3301 string (substring string (match-end 0)))
3302 (push (org-html-do-expand s) res)
3303 (push l res))
3304 (push (org-html-do-expand string) res)
3305 (apply 'concat (nreverse res))))
3307 (defun org-html-do-expand (s)
3308 "Apply all active conversions to translate special ASCII to HTML."
3309 (setq s (org-html-protect s))
3310 (if org-export-html-expand
3311 (let ((start 0))
3312 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3313 (setq s (replace-match "<\\1>" t nil s)))))
3314 (if org-export-with-emphasize
3315 (setq s (org-export-html-convert-emphasize s)))
3316 (if org-export-with-special-strings
3317 (setq s (org-export-html-convert-special-strings s)))
3318 (if org-export-with-sub-superscripts
3319 (setq s (org-export-html-convert-sub-super s)))
3320 (if org-export-with-TeX-macros
3321 (let ((start 0) wd ass)
3322 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3323 (if (get-text-property (match-beginning 0) 'org-protected s)
3324 (setq start (match-end 0))
3325 (setq wd (match-string 1 s))
3326 (if (setq ass (assoc wd org-html-entities))
3327 (setq s (replace-match (or (cdr ass)
3328 (concat "&" (car ass) ";"))
3329 t t s))
3330 (setq start (+ start (length wd))))))))
3333 (defun org-create-multibrace-regexp (left right n)
3334 "Create a regular expression which will match a balanced sexp.
3335 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3336 as single character strings.
3337 The regexp returned will match the entire expression including the
3338 delimiters. It will also define a single group which contains the
3339 match except for the outermost delimiters. The maximum depth of
3340 stacked delimiters is N. Escaping delimiters is not possible."
3341 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3342 (or "\\|")
3343 (re nothing)
3344 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3345 (while (> n 1)
3346 (setq n (1- n)
3347 re (concat re or next)
3348 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3349 (concat left "\\(" re "\\)" right)))
3351 (defvar org-match-substring-regexp
3352 (concat
3353 "\\([^\\]\\)\\([_^]\\)\\("
3354 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3355 "\\|"
3356 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3357 "\\|"
3358 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3359 "The regular expression matching a sub- or superscript.")
3361 (defvar org-match-substring-with-braces-regexp
3362 (concat
3363 "\\([^\\]\\)\\([_^]\\)\\("
3364 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3365 "\\)")
3366 "The regular expression matching a sub- or superscript, forcing braces.")
3368 (defconst org-export-html-special-string-regexps
3369 '(("\\\\-" . "&shy;")
3370 ("---\\([^-]\\)" . "&mdash;\\1")
3371 ("--\\([^-]\\)" . "&ndash;\\1")
3372 ("\\.\\.\\." . "&hellip;"))
3373 "Regular expressions for special string conversion.")
3375 (defun org-export-html-convert-special-strings (string)
3376 "Convert special characters in STRING to HTML."
3377 (let ((all org-export-html-special-string-regexps)
3378 e a re rpl start)
3379 (while (setq a (pop all))
3380 (setq re (car a) rpl (cdr a) start 0)
3381 (while (string-match re string start)
3382 (if (get-text-property (match-beginning 0) 'org-protected string)
3383 (setq start (match-end 0))
3384 (setq string (replace-match rpl t nil string)))))
3385 string))
3387 (defun org-export-html-convert-sub-super (string)
3388 "Convert sub- and superscripts in STRING to HTML."
3389 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3390 (while (string-match org-match-substring-regexp string s)
3391 (cond
3392 ((and requireb (match-end 8)) (setq s (match-end 2)))
3393 ((get-text-property (match-beginning 2) 'org-protected string)
3394 (setq s (match-end 2)))
3396 (setq s (match-end 1)
3397 key (if (string= (match-string 2 string) "_") "sub" "sup")
3398 c (or (match-string 8 string)
3399 (match-string 6 string)
3400 (match-string 5 string))
3401 string (replace-match
3402 (concat (match-string 1 string)
3403 "<" key ">" c "</" key ">")
3404 t t string)))))
3405 (while (string-match "\\\\\\([_^]\\)" string)
3406 (setq string (replace-match (match-string 1 string) t t string)))
3407 string))
3409 (defun org-export-html-convert-emphasize (string)
3410 "Apply emphasis."
3411 (let ((s 0) rpl)
3412 (while (string-match org-emph-re string s)
3413 (if (not (equal
3414 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3415 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3416 (setq s (match-beginning 0)
3418 (concat
3419 (match-string 1 string)
3420 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3421 (match-string 4 string)
3422 (nth 3 (assoc (match-string 3 string)
3423 org-emphasis-alist))
3424 (match-string 5 string))
3425 string (replace-match rpl t t string)
3426 s (+ s (- (length rpl) 2)))
3427 (setq s (1+ s))))
3428 string))
3430 (defvar org-par-open nil)
3431 (defun org-open-par ()
3432 "Insert <p>, but first close previous paragraph if any."
3433 (org-close-par-maybe)
3434 (insert "\n<p>")
3435 (setq org-par-open t))
3436 (defun org-close-par-maybe ()
3437 "Close paragraph if there is one open."
3438 (when org-par-open
3439 (insert "</p>")
3440 (setq org-par-open nil)))
3441 (defun org-close-li (&optional type)
3442 "Close <li> if necessary."
3443 (org-close-par-maybe)
3444 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
3446 (defvar body-only) ; dynamically scoped into this.
3447 (defun org-html-level-start (level title umax with-toc head-count)
3448 "Insert a new level in HTML export.
3449 When TITLE is nil, just close all open levels."
3450 (org-close-par-maybe)
3451 (let ((target (and title (org-get-text-property-any 0 'target title)))
3452 (l org-level-max)
3453 snumber)
3454 (while (>= l level)
3455 (if (aref org-levels-open (1- l))
3456 (progn
3457 (org-html-level-close l umax)
3458 (aset org-levels-open (1- l) nil)))
3459 (setq l (1- l)))
3460 (when title
3461 ;; If title is nil, this means this function is called to close
3462 ;; all levels, so the rest is done only if title is given
3463 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3464 (setq title (replace-match
3465 (if org-export-with-tags
3466 (save-match-data
3467 (concat
3468 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3469 (mapconcat 'identity (org-split-string
3470 (match-string 1 title) ":")
3471 "&nbsp;")
3472 "</span>"))
3474 t t title)))
3475 (if (> level umax)
3476 (progn
3477 (if (aref org-levels-open (1- level))
3478 (progn
3479 (org-close-li)
3480 (if target
3481 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3482 (insert "<li>" title "<br/>\n")))
3483 (aset org-levels-open (1- level) t)
3484 (org-close-par-maybe)
3485 (if target
3486 (insert (format "<ul>\n<li id=\"%s\">" target)
3487 title "<br/>\n")
3488 (insert "<ul>\n<li>" title "<br/>\n"))))
3489 (aset org-levels-open (1- level) t)
3490 (setq snumber (org-section-number level))
3491 (if (and org-export-with-section-numbers (not body-only))
3492 (setq title (concat snumber " " title)))
3493 (setq level (+ level org-export-html-toplevel-hlevel -1))
3494 (unless (= head-count 1) (insert "\n</div>\n"))
3495 (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"
3496 snumber level level snumber title level snumber))
3497 (org-open-par)))))
3499 (defun org-get-text-property-any (pos prop &optional object)
3500 (or (get-text-property pos prop object)
3501 (and (setq pos (next-single-property-change pos prop object))
3502 (get-text-property pos prop object))))
3504 (defun org-html-level-close (level max-outline-level)
3505 "Terminate one level in HTML export."
3506 (if (<= level max-outline-level)
3507 (insert "</div>\n")
3508 (org-close-li)
3509 (insert "</ul>\n")))
3511 ;;; iCalendar export
3513 ;;;###autoload
3514 (defun org-export-icalendar-this-file ()
3515 "Export current file as an iCalendar file.
3516 The iCalendar file will be located in the same directory as the Org-mode
3517 file, but with extension `.ics'."
3518 (interactive)
3519 (org-export-icalendar nil buffer-file-name))
3521 ;;;###autoload
3522 (defun org-export-icalendar-all-agenda-files ()
3523 "Export all files in `org-agenda-files' to iCalendar .ics files.
3524 Each iCalendar file will be located in the same directory as the Org-mode
3525 file, but with extension `.ics'."
3526 (interactive)
3527 (apply 'org-export-icalendar nil (org-agenda-files t)))
3529 ;;;###autoload
3530 (defun org-export-icalendar-combine-agenda-files ()
3531 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3532 The file is stored under the name `org-combined-agenda-icalendar-file'."
3533 (interactive)
3534 (apply 'org-export-icalendar t (org-agenda-files t)))
3536 (defun org-export-icalendar (combine &rest files)
3537 "Create iCalendar files for all elements of FILES.
3538 If COMBINE is non-nil, combine all calendar entries into a single large
3539 file and store it under the name `org-combined-agenda-icalendar-file'."
3540 (save-excursion
3541 (org-prepare-agenda-buffers files)
3542 (let* ((dir (org-export-directory
3543 :ical (list :publishing-directory
3544 org-export-publishing-directory)))
3545 file ical-file ical-buffer category started org-agenda-new-buffers)
3546 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3547 (when combine
3548 (setq ical-file
3549 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3550 org-combined-agenda-icalendar-file
3551 (expand-file-name org-combined-agenda-icalendar-file dir))
3552 ical-buffer (org-get-agenda-file-buffer ical-file))
3553 (set-buffer ical-buffer) (erase-buffer))
3554 (while (setq file (pop files))
3555 (catch 'nextfile
3556 (org-check-agenda-file file)
3557 (set-buffer (org-get-agenda-file-buffer file))
3558 (unless combine
3559 (setq ical-file (concat (file-name-as-directory dir)
3560 (file-name-sans-extension
3561 (file-name-nondirectory buffer-file-name))
3562 ".ics"))
3563 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3564 (with-current-buffer ical-buffer (erase-buffer)))
3565 (setq category (or org-category
3566 (file-name-sans-extension
3567 (file-name-nondirectory buffer-file-name))))
3568 (if (symbolp category) (setq category (symbol-name category)))
3569 (let ((standard-output ical-buffer))
3570 (if combine
3571 (and (not started) (setq started t)
3572 (org-start-icalendar-file org-icalendar-combined-name))
3573 (org-start-icalendar-file category))
3574 (org-print-icalendar-entries combine)
3575 (when (or (and combine (not files)) (not combine))
3576 (org-finish-icalendar-file)
3577 (set-buffer ical-buffer)
3578 (save-buffer)
3579 (run-hooks 'org-after-save-iCalendar-file-hook)
3580 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
3581 ))))
3582 (org-release-buffers org-agenda-new-buffers))))
3584 (defvar org-after-save-iCalendar-file-hook nil
3585 "Hook run after an iCalendar file has been saved.
3586 The iCalendar buffer is still current when this hook is run.
3587 A good way to use this is to tell a desktop calenndar application to re-read
3588 the iCalendar file.")
3590 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3591 (defun org-print-icalendar-entries (&optional combine)
3592 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3593 When COMBINE is non nil, add the category to each line."
3594 (require 'org-agenda)
3595 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3596 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3597 (dts (org-ical-ts-to-string
3598 (format-time-string (cdr org-time-stamp-formats) (current-time))
3599 "DTSTART"))
3600 hd ts ts2 state status (inc t) pos b sexp rrule
3601 scheduledp deadlinep tmp pri category entry location summary desc
3602 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3603 (org-refresh-category-properties)
3604 (save-excursion
3605 (goto-char (point-min))
3606 (while (re-search-forward re1 nil t)
3607 (catch :skip
3608 (org-agenda-skip)
3609 (when (boundp 'org-icalendar-verify-function)
3610 (unless (funcall org-icalendar-verify-function)
3611 (outline-next-heading)
3612 (backward-char 1)
3613 (throw :skip nil)))
3614 (setq pos (match-beginning 0)
3615 ts (match-string 0)
3616 inc t
3617 hd (condition-case nil
3618 (org-icalendar-cleanup-string
3619 (org-get-heading))
3620 (error (throw :skip nil)))
3621 summary (org-icalendar-cleanup-string
3622 (org-entry-get nil "SUMMARY"))
3623 desc (org-icalendar-cleanup-string
3624 (or (org-entry-get nil "DESCRIPTION")
3625 (and org-icalendar-include-body (org-get-entry)))
3626 t org-icalendar-include-body)
3627 location (org-icalendar-cleanup-string
3628 (org-entry-get nil "LOCATION"))
3629 category (org-get-category))
3630 (if (looking-at re2)
3631 (progn
3632 (goto-char (match-end 0))
3633 (setq ts2 (match-string 1) inc nil))
3634 (setq tmp (buffer-substring (max (point-min)
3635 (- pos org-ds-keyword-length))
3636 pos)
3637 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3638 (progn
3639 (setq inc nil)
3640 (replace-match "\\1" t nil ts))
3642 deadlinep (string-match org-deadline-regexp tmp)
3643 scheduledp (string-match org-scheduled-regexp tmp)
3644 ;; donep (org-entry-is-done-p)
3646 (if (or (string-match org-tr-regexp hd)
3647 (string-match org-ts-regexp hd))
3648 (setq hd (replace-match "" t t hd)))
3649 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3650 (setq rrule
3651 (concat "\nRRULE:FREQ="
3652 (cdr (assoc
3653 (match-string 2 ts)
3654 '(("d" . "DAILY")("w" . "WEEKLY")
3655 ("m" . "MONTHLY")("y" . "YEARLY"))))
3656 ";INTERVAL=" (match-string 1 ts)))
3657 (setq rrule ""))
3658 (setq summary (or summary hd))
3659 (if (string-match org-bracket-link-regexp summary)
3660 (setq summary
3661 (replace-match (if (match-end 3)
3662 (match-string 3 summary)
3663 (match-string 1 summary))
3664 t t summary)))
3665 (if deadlinep (setq summary (concat "DL: " summary)))
3666 (if scheduledp (setq summary (concat "S: " summary)))
3667 (if (string-match "\\`<%%" ts)
3668 (with-current-buffer sexp-buffer
3669 (insert (substring ts 1 -1) " " summary "\n"))
3670 (princ (format "BEGIN:VEVENT
3672 %s%s
3673 SUMMARY:%s%s%s
3674 CATEGORIES:%s
3675 END:VEVENT\n"
3676 (org-ical-ts-to-string ts "DTSTART")
3677 (org-ical-ts-to-string ts2 "DTEND" inc)
3678 rrule summary
3679 (if (and desc (string-match "\\S-" desc))
3680 (concat "\nDESCRIPTION: " desc) "")
3681 (if (and location (string-match "\\S-" location))
3682 (concat "\nLOCATION: " location) "")
3683 category)))))
3685 (when (and org-icalendar-include-sexps
3686 (condition-case nil (require 'icalendar) (error nil))
3687 (fboundp 'icalendar-export-region))
3688 ;; Get all the literal sexps
3689 (goto-char (point-min))
3690 (while (re-search-forward "^&?%%(" nil t)
3691 (catch :skip
3692 (org-agenda-skip)
3693 (setq b (match-beginning 0))
3694 (goto-char (1- (match-end 0)))
3695 (forward-sexp 1)
3696 (end-of-line 1)
3697 (setq sexp (buffer-substring b (point)))
3698 (with-current-buffer sexp-buffer
3699 (insert sexp "\n"))
3700 (princ (org-diary-to-ical-string sexp-buffer)))))
3702 (when org-icalendar-include-todo
3703 (goto-char (point-min))
3704 (while (re-search-forward org-todo-line-regexp nil t)
3705 (catch :skip
3706 (org-agenda-skip)
3707 (when (boundp 'org-icalendar-verify-function)
3708 (unless (funcall org-icalendar-verify-function)
3709 (outline-next-heading)
3710 (backward-char 1)
3711 (throw :skip nil)))
3712 (setq state (match-string 2))
3713 (setq status (if (member state org-done-keywords)
3714 "COMPLETED" "NEEDS-ACTION"))
3715 (when (and state
3716 (or (not (member state org-done-keywords))
3717 (eq org-icalendar-include-todo 'all))
3718 (not (member org-archive-tag (org-get-tags-at)))
3720 (setq hd (match-string 3)
3721 summary (org-icalendar-cleanup-string
3722 (org-entry-get nil "SUMMARY"))
3723 desc (org-icalendar-cleanup-string
3724 (or (org-entry-get nil "DESCRIPTION")
3725 (and org-icalendar-include-body (org-get-entry)))
3726 t org-icalendar-include-body)
3727 location (org-icalendar-cleanup-string
3728 (org-entry-get nil "LOCATION")))
3729 (if (string-match org-bracket-link-regexp hd)
3730 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
3731 (match-string 1 hd))
3732 t t hd)))
3733 (if (string-match org-priority-regexp hd)
3734 (setq pri (string-to-char (match-string 2 hd))
3735 hd (concat (substring hd 0 (match-beginning 1))
3736 (substring hd (match-end 1))))
3737 (setq pri org-default-priority))
3738 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
3739 (- org-lowest-priority org-highest-priority))))))
3741 (princ (format "BEGIN:VTODO
3743 SUMMARY:%s%s%s
3744 CATEGORIES:%s
3745 SEQUENCE:1
3746 PRIORITY:%d
3747 STATUS:%s
3748 END:VTODO\n"
3750 (or summary hd)
3751 (if (and location (string-match "\\S-" location))
3752 (concat "\nLOCATION: " location) "")
3753 (if (and desc (string-match "\\S-" desc))
3754 (concat "\nDESCRIPTION: " desc) "")
3755 category pri status)))))))))
3757 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
3758 "Take out stuff and quote what needs to be quoted.
3759 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3760 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3761 characters."
3762 (if (not s)
3764 (when is-body
3765 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
3766 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
3767 (while (string-match re s) (setq s (replace-match "" t t s)))
3768 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
3769 (let ((start 0))
3770 (while (string-match "\\([,;]\\)" s start)
3771 (setq start (+ (match-beginning 0) 2)
3772 s (replace-match "\\\\\\1" nil nil s))))
3773 (when is-body
3774 (while (string-match "[ \t]*\n[ \t]*" s)
3775 (setq s (replace-match "\\n" t t s))))
3776 (setq s (org-trim s))
3777 (if is-body
3778 (if maxlength
3779 (if (and (numberp maxlength)
3780 (> (length s) maxlength))
3781 (setq s (substring s 0 maxlength)))))
3784 (defun org-get-entry ()
3785 "Clean-up description string."
3786 (save-excursion
3787 (org-back-to-heading t)
3788 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
3790 (defun org-start-icalendar-file (name)
3791 "Start an iCalendar file by inserting the header."
3792 (let ((user user-full-name)
3793 (name (or name "unknown"))
3794 (timezone (cadr (current-time-zone))))
3795 (princ
3796 (format "BEGIN:VCALENDAR
3797 VERSION:2.0
3798 X-WR-CALNAME:%s
3799 PRODID:-//%s//Emacs with Org-mode//EN
3800 X-WR-TIMEZONE:%s
3801 CALSCALE:GREGORIAN\n" name user timezone))))
3803 (defun org-finish-icalendar-file ()
3804 "Finish an iCalendar file by inserting the END statement."
3805 (princ "END:VCALENDAR\n"))
3807 (defun org-ical-ts-to-string (s keyword &optional inc)
3808 "Take a time string S and convert it to iCalendar format.
3809 KEYWORD is added in front, to make a complete line like DTSTART....
3810 When INC is non-nil, increase the hour by two (if time string contains
3811 a time), or the day by one (if it does not contain a time)."
3812 (let ((t1 (org-parse-time-string s 'nodefault))
3813 t2 fmt have-time time)
3814 (if (and (car t1) (nth 1 t1) (nth 2 t1))
3815 (setq t2 t1 have-time t)
3816 (setq t2 (org-parse-time-string s)))
3817 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
3818 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
3819 (when inc
3820 (if have-time
3821 (if org-agenda-default-appointment-duration
3822 (setq mi (+ org-agenda-default-appointment-duration mi))
3823 (setq h (+ 2 h)))
3824 (setq d (1+ d))))
3825 (setq time (encode-time s mi h d m y)))
3826 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3827 (concat keyword (format-time-string fmt time))))
3829 ;;; XOXO export
3831 (defun org-export-as-xoxo-insert-into (buffer &rest output)
3832 (with-current-buffer buffer
3833 (apply 'insert output)))
3834 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
3836 ;;;###autoload
3837 (defun org-export-as-xoxo (&optional buffer)
3838 "Export the org buffer as XOXO.
3839 The XOXO buffer is named *xoxo-<source buffer name>*"
3840 (interactive (list (current-buffer)))
3841 ;; A quickie abstraction
3843 ;; Output everything as XOXO
3844 (with-current-buffer (get-buffer buffer)
3845 (let* ((pos (point))
3846 (opt-plist (org-combine-plists (org-default-export-plist)
3847 (org-infile-export-plist)))
3848 (filename (concat (file-name-as-directory
3849 (org-export-directory :xoxo opt-plist))
3850 (file-name-sans-extension
3851 (file-name-nondirectory buffer-file-name))
3852 ".html"))
3853 (out (find-file-noselect filename))
3854 (last-level 1)
3855 (hanging-li nil))
3856 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3857 ;; Check the output buffer is empty.
3858 (with-current-buffer out (erase-buffer))
3859 ;; Kick off the output
3860 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
3861 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
3862 (let* ((hd (match-string-no-properties 1))
3863 (level (length hd))
3864 (text (concat
3865 (match-string-no-properties 2)
3866 (save-excursion
3867 (goto-char (match-end 0))
3868 (let ((str ""))
3869 (catch 'loop
3870 (while 't
3871 (forward-line)
3872 (if (looking-at "^[ \t]\\(.*\\)")
3873 (setq str (concat str (match-string-no-properties 1)))
3874 (throw 'loop str)))))))))
3876 ;; Handle level rendering
3877 (cond
3878 ((> level last-level)
3879 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
3881 ((< level last-level)
3882 (dotimes (- (- last-level level) 1)
3883 (if hanging-li
3884 (org-export-as-xoxo-insert-into out "</li>\n"))
3885 (org-export-as-xoxo-insert-into out "</ol>\n"))
3886 (when hanging-li
3887 (org-export-as-xoxo-insert-into out "</li>\n")
3888 (setq hanging-li nil)))
3890 ((equal level last-level)
3891 (if hanging-li
3892 (org-export-as-xoxo-insert-into out "</li>\n")))
3895 (setq last-level level)
3897 ;; And output the new li
3898 (setq hanging-li 't)
3899 (if (equal ?+ (elt text 0))
3900 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
3901 (org-export-as-xoxo-insert-into out "<li>" text))))
3903 ;; Finally finish off the ol
3904 (dotimes (- last-level 1)
3905 (if hanging-li
3906 (org-export-as-xoxo-insert-into out "</li>\n"))
3907 (org-export-as-xoxo-insert-into out "</ol>\n"))
3909 (goto-char pos)
3910 ;; Finish the buffer off and clean it up.
3911 (switch-to-buffer-other-window out)
3912 (indent-region (point-min) (point-max) nil)
3913 (save-buffer)
3914 (goto-char (point-min))
3917 (provide 'org-exp)
3919 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3921 ;;; org-exp.el ends here