Cleanup after name change.
[org-mode/org-tableheadings.git] / lisp / org-exp.el
blob1ec1ebaf50628a946a4cf885eb86c8eb79096da3
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.02b
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
29 (require 'org-agenda)
30 (eval-and-compile
31 (require 'cl))
33 (declare-function org-export-latex-preprocess "org-export-latex" ())
34 (declare-function org-agenda-skip "org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template "org-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-startup-folded nil)
1656 (htmltext
1657 (with-temp-buffer
1658 (insert code)
1659 (if (functionp mode)
1660 (funcall mode)
1661 (fundamental-mode))
1662 (when (eq major-mode 'org-mode)
1663 ;; Free up the protected stuff
1664 (goto-char (point-min))
1665 (while (re-search-forward "^@\\([*#]\\|[ \t]*:\\)" nil t)
1666 (replace-match "\\1"))
1667 (org-mode))
1668 (font-lock-fontify-buffer)
1669 ;; silence the byte-compiler
1670 (when (fboundp 'htmlize-region-for-paste)
1671 ;; transform the region to HTML
1672 (htmlize-region-for-paste (point-min) (point-max))))))
1673 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
1674 (setq htmltext (replace-match "<pre class=\"src\">"
1675 t t htmltext)))
1676 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
1678 ;; This is not HTML, so just make it an example.
1679 (concat "#+BEGIN_EXAMPLE\n" code
1680 (if (string-match "\n\\'" code) "" "\n")
1681 "#+END_EXAMPLE\n")))))
1683 ;;; ASCII export
1685 (defvar org-last-level nil) ; dynamically scoped variable
1686 (defvar org-min-level nil) ; dynamically scoped variable
1687 (defvar org-levels-open nil) ; dynamically scoped parameter
1688 (defvar org-ascii-current-indentation nil) ; For communication
1690 ;;;###autoload
1691 (defun org-export-as-ascii (arg)
1692 "Export the outline as a pretty ASCII file.
1693 If there is an active region, export only the region.
1694 The prefix ARG specifies how many levels of the outline should become
1695 underlined headlines. The default is 3."
1696 (interactive "P")
1697 (setq-default org-todo-line-regexp org-todo-line-regexp)
1698 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1699 (org-infile-export-plist)))
1700 (region-p (org-region-active-p))
1701 (subtree-p
1702 (when region-p
1703 (save-excursion
1704 (goto-char (region-beginning))
1705 (and (org-at-heading-p)
1706 (>= (org-end-of-subtree t t) (region-end))))))
1707 (custom-times org-display-custom-times)
1708 (org-ascii-current-indentation '(0 . 0))
1709 (level 0) line txt
1710 (umax nil)
1711 (umax-toc nil)
1712 (case-fold-search nil)
1713 (filename (concat (file-name-as-directory
1714 (org-export-directory :ascii opt-plist))
1715 (file-name-sans-extension
1716 (or (and subtree-p
1717 (org-entry-get (region-beginning)
1718 "EXPORT_FILE_NAME" t))
1719 (file-name-nondirectory buffer-file-name)))
1720 ".txt"))
1721 (filename (if (equal (file-truename filename)
1722 (file-truename buffer-file-name))
1723 (concat filename ".txt")
1724 filename))
1725 (buffer (find-file-noselect filename))
1726 (org-levels-open (make-vector org-level-max nil))
1727 (odd org-odd-levels-only)
1728 (date (plist-get opt-plist :date))
1729 (author (plist-get opt-plist :author))
1730 (title (or (and subtree-p (org-export-get-title-from-subtree))
1731 (plist-get opt-plist :title)
1732 (and (not
1733 (plist-get opt-plist :skip-before-1st-heading))
1734 (org-export-grab-title-from-buffer))
1735 (file-name-sans-extension
1736 (file-name-nondirectory buffer-file-name))))
1737 (email (plist-get opt-plist :email))
1738 (language (plist-get opt-plist :language))
1739 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1740 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1741 (todo nil)
1742 (lang-words nil)
1743 (region
1744 (buffer-substring
1745 (if (org-region-active-p) (region-beginning) (point-min))
1746 (if (org-region-active-p) (region-end) (point-max))))
1747 (lines (org-split-string
1748 (org-export-preprocess-string
1749 region
1750 :for-ascii t
1751 :skip-before-1st-heading
1752 (plist-get opt-plist :skip-before-1st-heading)
1753 :drawers (plist-get opt-plist :drawers)
1754 :verbatim-multiline t
1755 :archived-trees
1756 (plist-get opt-plist :archived-trees)
1757 :add-text (plist-get opt-plist :text))
1758 "\n"))
1759 thetoc have-headings first-heading-pos
1760 table-open table-buffer)
1762 (let ((inhibit-read-only t))
1763 (org-unmodified
1764 (remove-text-properties (point-min) (point-max)
1765 '(:org-license-to-kill t))))
1767 (setq org-min-level (org-get-min-level lines))
1768 (setq org-last-level org-min-level)
1769 (org-init-section-numbers)
1771 (find-file-noselect filename)
1773 (setq lang-words (or (assoc language org-export-language-setup)
1774 (assoc "en" org-export-language-setup)))
1775 (switch-to-buffer-other-window buffer)
1776 (erase-buffer)
1777 (fundamental-mode)
1778 ;; create local variables for all options, to make sure all called
1779 ;; functions get the correct information
1780 (mapc (lambda (x)
1781 (set (make-local-variable (cdr x))
1782 (plist-get opt-plist (car x))))
1783 org-export-plist-vars)
1784 (org-set-local 'org-odd-levels-only odd)
1785 (setq umax (if arg (prefix-numeric-value arg)
1786 org-export-headline-levels))
1787 (setq umax-toc (if (integerp org-export-with-toc)
1788 (min org-export-with-toc umax)
1789 umax))
1791 ;; File header
1792 (if title (org-insert-centered title ?=))
1793 (insert "\n")
1794 (if (and (or author email)
1795 org-export-author-info)
1796 (insert (concat (nth 1 lang-words) ": " (or author "")
1797 (if email (concat " <" email ">") "")
1798 "\n")))
1800 (cond
1801 ((and date (string-match "%" date))
1802 (setq date (format-time-string date)))
1803 (date)
1804 (t (setq date (format-time-string "%Y/%m/%d %X"))))
1806 (if (and date org-export-time-stamp-file)
1807 (insert (concat (nth 2 lang-words) ": " date"\n")))
1809 (insert "\n\n")
1811 (if org-export-with-toc
1812 (progn
1813 (push (concat (nth 3 lang-words) "\n") thetoc)
1814 (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
1815 (mapc '(lambda (line)
1816 (if (string-match org-todo-line-regexp
1817 line)
1818 ;; This is a headline
1819 (progn
1820 (setq have-headings t)
1821 (setq level (- (match-end 1) (match-beginning 1))
1822 level (org-tr-level level)
1823 txt (match-string 3 line)
1824 todo
1825 (or (and org-export-mark-todo-in-toc
1826 (match-beginning 2)
1827 (not (member (match-string 2 line)
1828 org-done-keywords)))
1829 ; TODO, not DONE
1830 (and org-export-mark-todo-in-toc
1831 (= level umax-toc)
1832 (org-search-todo-below
1833 line lines level))))
1834 (setq txt (org-html-expand-for-ascii txt))
1836 (while (string-match org-bracket-link-regexp txt)
1837 (setq txt
1838 (replace-match
1839 (match-string (if (match-end 2) 3 1) txt)
1840 t t txt)))
1842 (if (and (memq org-export-with-tags '(not-in-toc nil))
1843 (string-match
1844 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1845 txt))
1846 (setq txt (replace-match "" t t txt)))
1847 (if (string-match quote-re0 txt)
1848 (setq txt (replace-match "" t t txt)))
1850 (if org-export-with-section-numbers
1851 (setq txt (concat (org-section-number level)
1852 " " txt)))
1853 (if (<= level umax-toc)
1854 (progn
1855 (push
1856 (concat
1857 (make-string
1858 (* (max 0 (- level org-min-level)) 4) ?\ )
1859 (format (if todo "%s (*)\n" "%s\n") txt))
1860 thetoc)
1861 (setq org-last-level level))
1862 ))))
1863 lines)
1864 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1866 (org-init-section-numbers)
1867 (while (setq line (pop lines))
1868 ;; Remove the quoted HTML tags.
1869 (setq line (org-html-expand-for-ascii line))
1870 ;; Remove targets
1871 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
1872 (setq line (replace-match "" t t line)))
1873 ;; Replace internal links
1874 (while (string-match org-bracket-link-regexp line)
1875 (setq line (replace-match
1876 (if (match-end 3) "[\\3]" "[\\1]")
1877 t nil line)))
1878 (when custom-times
1879 (setq line (org-translate-time line)))
1880 (cond
1881 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1882 ;; a Headline
1883 (setq first-heading-pos (or first-heading-pos (point)))
1884 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
1885 txt (match-string 2 line))
1886 (org-ascii-level-start level txt umax lines))
1888 ((and org-export-with-tables
1889 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1890 (if (not table-open)
1891 ;; New table starts
1892 (setq table-open t table-buffer nil))
1893 ;; Accumulate lines
1894 (setq table-buffer (cons line table-buffer))
1895 (when (or (not lines)
1896 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1897 (car lines))))
1898 (setq table-open nil
1899 table-buffer (nreverse table-buffer))
1900 (insert (mapconcat
1901 (lambda (x)
1902 (org-fix-indentation x org-ascii-current-indentation))
1903 (org-format-table-ascii table-buffer)
1904 "\n") "\n")))
1906 (setq line (org-fix-indentation line org-ascii-current-indentation))
1907 (if (and org-export-with-fixed-width
1908 (string-match "^\\([ \t]*\\)\\(:\\)" line))
1909 (setq line (replace-match "\\1" nil nil line)))
1910 (insert line "\n"))))
1912 (normal-mode)
1914 ;; insert the table of contents
1915 (when thetoc
1916 (goto-char (point-min))
1917 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
1918 (progn
1919 (goto-char (match-beginning 0))
1920 (replace-match ""))
1921 (goto-char first-heading-pos))
1922 (mapc 'insert thetoc)
1923 (or (looking-at "[ \t]*\n[ \t]*\n")
1924 (insert "\n\n")))
1926 ;; Convert whitespace place holders
1927 (goto-char (point-min))
1928 (let (beg end)
1929 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1930 (setq end (next-single-property-change beg 'org-whitespace))
1931 (goto-char beg)
1932 (delete-region beg end)
1933 (insert (make-string (- end beg) ?\ ))))
1935 (save-buffer)
1936 ;; remove display and invisible chars
1937 (let (beg end)
1938 (goto-char (point-min))
1939 (while (setq beg (next-single-property-change (point) 'display))
1940 (setq end (next-single-property-change beg 'display))
1941 (delete-region beg end)
1942 (goto-char beg)
1943 (insert "=>"))
1944 (goto-char (point-min))
1945 (while (setq beg (next-single-property-change (point) 'org-cwidth))
1946 (setq end (next-single-property-change beg 'org-cwidth))
1947 (delete-region beg end)
1948 (goto-char beg)))
1949 (goto-char (point-min))))
1951 (defun org-export-ascii-clean-string ()
1952 "Do extra work for ASCII export"
1953 (goto-char (point-min))
1954 (while (re-search-forward org-verbatim-re nil t)
1955 (goto-char (match-end 2))
1956 (backward-delete-char 1) (insert "'")
1957 (goto-char (match-beginning 2))
1958 (delete-char 1) (insert "`")
1959 (goto-char (match-end 2))))
1961 (defun org-search-todo-below (line lines level)
1962 "Search the subtree below LINE for any TODO entries."
1963 (let ((rest (cdr (memq line lines)))
1964 (re org-todo-line-regexp)
1965 line lv todo)
1966 (catch 'exit
1967 (while (setq line (pop rest))
1968 (if (string-match re line)
1969 (progn
1970 (setq lv (- (match-end 1) (match-beginning 1))
1971 todo (and (match-beginning 2)
1972 (not (member (match-string 2 line)
1973 org-done-keywords))))
1974 ; TODO, not DONE
1975 (if (<= lv level) (throw 'exit nil))
1976 (if todo (throw 'exit t))))))))
1978 (defun org-html-expand-for-ascii (line)
1979 "Handle quoted HTML for ASCII export."
1980 (if org-export-html-expand
1981 (while (string-match "@<[^<>\n]*>" line)
1982 ;; We just remove the tags for now.
1983 (setq line (replace-match "" nil nil line))))
1984 line)
1986 (defun org-insert-centered (s &optional underline)
1987 "Insert the string S centered and underline it with character UNDERLINE."
1988 (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
1989 (insert (make-string ind ?\ ) s "\n")
1990 (if underline
1991 (insert (make-string ind ?\ )
1992 (make-string (string-width s) underline)
1993 "\n"))))
1995 (defun org-ascii-level-start (level title umax &optional lines)
1996 "Insert a new level in ASCII export."
1997 (let (char (n (- level umax 1)) (ind 0))
1998 (if (> level umax)
1999 (progn
2000 (insert (make-string (* 2 n) ?\ )
2001 (char-to-string (nth (% n (length org-export-ascii-bullets))
2002 org-export-ascii-bullets))
2003 " " title "\n")
2004 ;; find the indentation of the next non-empty line
2005 (catch 'stop
2006 (while lines
2007 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2008 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2009 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2010 (pop lines)))
2011 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2012 (if (or (not (equal (char-before) ?\n))
2013 (not (equal (char-before (1- (point))) ?\n)))
2014 (insert "\n"))
2015 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2016 (unless org-export-with-tags
2017 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2018 (setq title (replace-match "" t t title))))
2019 (if org-export-with-section-numbers
2020 (setq title (concat (org-section-number level) " " title)))
2021 (insert title "\n" (make-string (string-width title) char) "\n")
2022 (setq org-ascii-current-indentation '(0 . 0)))))
2024 ;;;###autoload
2025 (defun org-export-visible (type arg)
2026 "Create a copy of the visible part of the current buffer, and export it.
2027 The copy is created in a temporary buffer and removed after use.
2028 TYPE is the final key (as a string) that also select the export command in
2029 the `C-c C-e' export dispatcher.
2030 As a special case, if the you type SPC at the prompt, the temporary
2031 org-mode file will not be removed but presented to you so that you can
2032 continue to use it. The prefix arg ARG is passed through to the exporting
2033 command."
2034 (interactive
2035 (list (progn
2036 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2037 (read-char-exclusive))
2038 current-prefix-arg))
2039 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2040 (error "Invalid export key"))
2041 (let* ((binding (cdr (assoc type
2042 '((?a . org-export-as-ascii)
2043 (?\C-a . org-export-as-ascii)
2044 (?b . org-export-as-html-and-open)
2045 (?\C-b . org-export-as-html-and-open)
2046 (?h . org-export-as-html)
2047 (?H . org-export-as-html-to-buffer)
2048 (?R . org-export-region-as-html)
2049 (?x . org-export-as-xoxo)))))
2050 (keepp (equal type ?\ ))
2051 (file buffer-file-name)
2052 (buffer (get-buffer-create "*Org Export Visible*"))
2053 s e)
2054 ;; Need to hack the drawers here.
2055 (save-excursion
2056 (goto-char (point-min))
2057 (while (re-search-forward org-drawer-regexp nil t)
2058 (goto-char (match-beginning 1))
2059 (or (org-invisible-p) (org-flag-drawer nil))))
2060 (with-current-buffer buffer (erase-buffer))
2061 (save-excursion
2062 (setq s (goto-char (point-min)))
2063 (while (not (= (point) (point-max)))
2064 (goto-char (org-find-invisible))
2065 (append-to-buffer buffer s (point))
2066 (setq s (goto-char (org-find-visible))))
2067 (org-cycle-hide-drawers 'all)
2068 (goto-char (point-min))
2069 (unless keepp
2070 ;; Copy all comment lines to the end, to make sure #+ settings are
2071 ;; still available for the second export step. Kind of a hack, but
2072 ;; does do the trick.
2073 (if (looking-at "#[^\r\n]*")
2074 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2075 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2076 (append-to-buffer buffer (1+ (match-beginning 0))
2077 (min (point-max) (1+ (match-end 0))))))
2078 (set-buffer buffer)
2079 (let ((buffer-file-name file)
2080 (org-inhibit-startup t))
2081 (org-mode)
2082 (show-all)
2083 (unless keepp (funcall binding arg))))
2084 (if (not keepp)
2085 (kill-buffer buffer)
2086 (switch-to-buffer-other-window buffer)
2087 (goto-char (point-min)))))
2089 (defun org-find-visible ()
2090 (let ((s (point)))
2091 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2092 (get-char-property s 'invisible)))
2094 (defun org-find-invisible ()
2095 (let ((s (point)))
2096 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2097 (not (get-char-property s 'invisible))))
2100 ;;; HTML export
2102 (defvar org-archive-location) ;; gets loades with the org-archive require.
2103 (defun org-get-current-options ()
2104 "Return a string with current options as keyword options.
2105 Does include HTML export options as well as TODO and CATEGORY stuff."
2106 (require 'org-archive)
2107 (format
2108 "#+TITLE: %s
2109 #+AUTHOR: %s
2110 #+EMAIL: %s
2111 #+DATE: %s
2112 #+LANGUAGE: %s
2113 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2114 #+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
2116 #+LINK_UP: %s
2117 #+LINK_HOME: %s
2118 #+CATEGORY: %s
2119 #+SEQ_TODO: %s
2120 #+TYP_TODO: %s
2121 #+PRIORITIES: %c %c %c
2122 #+DRAWERS: %s
2123 #+STARTUP: %s %s %s %s %s
2124 #+TAGS: %s
2125 #+ARCHIVE: %s
2126 #+LINK: %s
2128 (buffer-name) (user-full-name) user-mail-address
2129 (format-time-string (car org-time-stamp-formats))
2130 org-export-default-language
2131 org-export-headline-levels
2132 org-export-with-section-numbers
2133 org-export-with-toc
2134 org-export-preserve-breaks
2135 org-export-html-expand
2136 org-export-with-fixed-width
2137 org-export-with-tables
2138 org-export-with-sub-superscripts
2139 org-export-with-special-strings
2140 org-export-with-footnotes
2141 org-export-with-emphasize
2142 org-export-with-TeX-macros
2143 org-export-with-LaTeX-fragments
2144 org-export-skip-text-before-1st-heading
2145 org-export-with-drawers
2146 org-export-with-tags
2147 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2148 org-export-html-link-up
2149 org-export-html-link-home
2150 (file-name-nondirectory buffer-file-name)
2151 "TODO FEEDBACK VERIFY DONE"
2152 "Me Jason Marie DONE"
2153 org-highest-priority org-lowest-priority org-default-priority
2154 (mapconcat 'identity org-drawers " ")
2155 (cdr (assoc org-startup-folded
2156 '((nil . "showall") (t . "overview") (content . "content"))))
2157 (if org-odd-levels-only "odd" "oddeven")
2158 (if org-hide-leading-stars "hidestars" "showstars")
2159 (if org-startup-align-all-tables "align" "noalign")
2160 (cond ((eq org-log-done t) "logdone")
2161 ((equal org-log-done 'note) "lognotedone")
2162 ((not org-log-done) "nologdone"))
2163 (or (mapconcat (lambda (x)
2164 (cond
2165 ((equal '(:startgroup) x) "{")
2166 ((equal '(:endgroup) x) "}")
2167 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2168 (t (car x))))
2169 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2170 org-archive-location
2171 "org file:~/org/%s.org"
2174 ;;;###autoload
2175 (defun org-insert-export-options-template ()
2176 "Insert into the buffer a template with information for exporting."
2177 (interactive)
2178 (if (not (bolp)) (newline))
2179 (let ((s (org-get-current-options)))
2180 (and (string-match "#\\+CATEGORY" s)
2181 (setq s (substring s 0 (match-beginning 0))))
2182 (insert s)))
2184 ;;;###autoload
2185 (defun org-export-as-html-and-open (arg)
2186 "Export the outline as HTML and immediately open it with a browser.
2187 If there is an active region, export only the region.
2188 The prefix ARG specifies how many levels of the outline should become
2189 headlines. The default is 3. Lower levels will become bulleted lists."
2190 (interactive "P")
2191 (org-export-as-html arg 'hidden)
2192 (org-open-file buffer-file-name))
2194 ;;;###autoload
2195 (defun org-export-as-html-batch ()
2196 "Call `org-export-as-html', may be used in batch processing as
2197 emacs --batch
2198 --load=$HOME/lib/emacs/org.el
2199 --eval \"(setq org-export-headline-levels 2)\"
2200 --visit=MyFile --funcall org-export-as-html-batch"
2201 (org-export-as-html org-export-headline-levels 'hidden))
2203 ;;;###autoload
2204 (defun org-export-as-html-to-buffer (arg)
2205 "Call `org-exort-as-html` with output to a temporary buffer.
2206 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2207 (interactive "P")
2208 (org-export-as-html arg nil nil "*Org HTML Export*")
2209 (switch-to-buffer-other-window "*Org HTML Export*"))
2211 ;;;###autoload
2212 (defun org-replace-region-by-html (beg end)
2213 "Assume the current region has org-mode syntax, and convert it to HTML.
2214 This can be used in any buffer. For example, you could write an
2215 itemized list in org-mode syntax in an HTML buffer and then use this
2216 command to convert it."
2217 (interactive "r")
2218 (let (reg html buf pop-up-frames)
2219 (save-window-excursion
2220 (if (org-mode-p)
2221 (setq html (org-export-region-as-html
2222 beg end t 'string))
2223 (setq reg (buffer-substring beg end)
2224 buf (get-buffer-create "*Org tmp*"))
2225 (with-current-buffer buf
2226 (erase-buffer)
2227 (insert reg)
2228 (org-mode)
2229 (setq html (org-export-region-as-html
2230 (point-min) (point-max) t 'string)))
2231 (kill-buffer buf)))
2232 (delete-region beg end)
2233 (insert html)))
2235 ;;;###autoload
2236 (defun org-export-region-as-html (beg end &optional body-only buffer)
2237 "Convert region from BEG to END in org-mode buffer to HTML.
2238 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2239 contents, and only produce the region of converted text, useful for
2240 cut-and-paste operations.
2241 If BUFFER is a buffer or a string, use/create that buffer as a target
2242 of the converted HTML. If BUFFER is the symbol `string', return the
2243 produced HTML as a string and leave not buffer behind. For example,
2244 a Lisp program could call this function in the following way:
2246 (setq html (org-export-region-as-html beg end t 'string))
2248 When called interactively, the output buffer is selected, and shown
2249 in a window. A non-interactive call will only return the buffer."
2250 (interactive "r\nP")
2251 (when (interactive-p)
2252 (setq buffer "*Org HTML Export*"))
2253 (let ((transient-mark-mode t) (zmacs-regions t)
2254 rtn)
2255 (goto-char end)
2256 (set-mark (point)) ;; to activate the region
2257 (goto-char beg)
2258 (setq rtn (org-export-as-html
2259 nil nil nil
2260 buffer body-only))
2261 (if (fboundp 'deactivate-mark) (deactivate-mark))
2262 (if (and (interactive-p) (bufferp rtn))
2263 (switch-to-buffer-other-window rtn)
2264 rtn)))
2266 (defvar html-table-tag nil) ; dynamically scoped into this.
2267 ;;;###autoload
2268 (defun org-export-as-html (arg &optional hidden ext-plist
2269 to-buffer body-only pub-dir)
2270 "Export the outline as a pretty HTML file.
2271 If there is an active region, export only the region. The prefix
2272 ARG specifies how many levels of the outline should become
2273 headlines. The default is 3. Lower levels will become bulleted
2274 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2275 EXT-PLIST is a property list with external parameters overriding
2276 org-mode's default settings, but still inferior to file-local
2277 settings. When TO-BUFFER is non-nil, create a buffer with that
2278 name and export to that buffer. If TO-BUFFER is the symbol
2279 `string', don't leave any buffer behind but just return the
2280 resulting HTML as a string. When BODY-ONLY is set, don't produce
2281 the file header and footer, simply return the content of
2282 <body>...</body>, without even the body tags themselves. When
2283 PUB-DIR is set, use this as the publishing directory."
2284 (interactive "P")
2286 ;; Make sure we have a file name when we need it.
2287 (when (and (not (or to-buffer body-only))
2288 (not buffer-file-name))
2289 (if (buffer-base-buffer)
2290 (org-set-local 'buffer-file-name
2291 (with-current-buffer (buffer-base-buffer)
2292 buffer-file-name))
2293 (error "Need a file name to be able to export.")))
2295 (message "Exporting...")
2296 (setq-default org-todo-line-regexp org-todo-line-regexp)
2297 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2298 (setq-default org-done-keywords org-done-keywords)
2299 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2300 (let* ((opt-plist
2301 (org-export-process-option-filters
2302 (org-combine-plists (org-default-export-plist)
2303 ext-plist
2304 (org-infile-export-plist))))
2306 (style (plist-get opt-plist :style))
2307 (html-extension (plist-get opt-plist :html-extension))
2308 (link-validate (plist-get opt-plist :link-validation-function))
2309 valid thetoc have-headings first-heading-pos
2310 (odd org-odd-levels-only)
2311 (region-p (org-region-active-p))
2312 (subtree-p
2313 (when region-p
2314 (save-excursion
2315 (goto-char (region-beginning))
2316 (and (org-at-heading-p)
2317 (>= (org-end-of-subtree t t) (region-end))))))
2318 ;; The following two are dynamically scoped into other
2319 ;; routines below.
2320 (org-current-export-dir
2321 (or pub-dir (org-export-directory :html opt-plist)))
2322 (org-current-export-file buffer-file-name)
2323 (level 0) (line "") (origline "") txt todo
2324 (umax nil)
2325 (umax-toc nil)
2326 (filename (if to-buffer nil
2327 (expand-file-name
2328 (concat
2329 (file-name-sans-extension
2330 (or (and subtree-p
2331 (org-entry-get (region-beginning)
2332 "EXPORT_FILE_NAME" t))
2333 (file-name-nondirectory buffer-file-name)))
2334 "." html-extension)
2335 (file-name-as-directory
2336 (or pub-dir (org-export-directory :html opt-plist))))))
2337 (current-dir (if buffer-file-name
2338 (file-name-directory buffer-file-name)
2339 default-directory))
2340 (buffer (if to-buffer
2341 (cond
2342 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2343 (t (get-buffer-create to-buffer)))
2344 (find-file-noselect filename)))
2345 (org-levels-open (make-vector org-level-max nil))
2346 (date (plist-get opt-plist :date))
2347 (author (plist-get opt-plist :author))
2348 (title (or (and subtree-p (org-export-get-title-from-subtree))
2349 (plist-get opt-plist :title)
2350 (and (not
2351 (plist-get opt-plist :skip-before-1st-heading))
2352 (org-export-grab-title-from-buffer))
2353 (and buffer-file-name
2354 (file-name-sans-extension
2355 (file-name-nondirectory buffer-file-name)))
2356 "UNTITLED"))
2357 (html-table-tag (plist-get opt-plist :html-table-tag))
2358 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2359 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2360 (inquote nil)
2361 (infixed nil)
2362 (in-local-list nil)
2363 (local-list-type nil)
2364 (local-list-indent nil)
2365 (llt org-plain-list-ordered-item-terminator)
2366 (email (plist-get opt-plist :email))
2367 (language (plist-get opt-plist :language))
2368 (lang-words nil)
2369 (head-count 0) cnt
2370 (start 0)
2371 (coding-system (and (boundp 'buffer-file-coding-system)
2372 buffer-file-coding-system))
2373 (coding-system-for-write (or org-export-html-coding-system
2374 coding-system))
2375 (save-buffer-coding-system (or org-export-html-coding-system
2376 coding-system))
2377 (charset (and coding-system-for-write
2378 (fboundp 'coding-system-get)
2379 (coding-system-get coding-system-for-write
2380 'mime-charset)))
2381 (region
2382 (buffer-substring
2383 (if region-p (region-beginning) (point-min))
2384 (if region-p (region-end) (point-max))))
2385 (lines
2386 (org-split-string
2387 (org-export-preprocess-string
2388 region
2389 :emph-multiline t
2390 :for-html t
2391 :skip-before-1st-heading
2392 (plist-get opt-plist :skip-before-1st-heading)
2393 :drawers (plist-get opt-plist :drawers)
2394 :archived-trees
2395 (plist-get opt-plist :archived-trees)
2396 :add-text
2397 (plist-get opt-plist :text)
2398 :LaTeX-fragments
2399 (plist-get opt-plist :LaTeX-fragments))
2400 "[\r\n]"))
2401 table-open type
2402 table-buffer table-orig-buffer
2403 ind item-type starter didclose
2404 rpl path desc descp desc1 desc2 link
2405 snumber fnc item-tag
2408 (let ((inhibit-read-only t))
2409 (org-unmodified
2410 (remove-text-properties (point-min) (point-max)
2411 '(:org-license-to-kill t))))
2413 (message "Exporting...")
2415 (setq org-min-level (org-get-min-level lines))
2416 (setq org-last-level org-min-level)
2417 (org-init-section-numbers)
2419 (cond
2420 ((and date (string-match "%" date))
2421 (setq date (format-time-string date)))
2422 (date)
2423 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2425 ;; Get the language-dependent settings
2426 (setq lang-words (or (assoc language org-export-language-setup)
2427 (assoc "en" org-export-language-setup)))
2429 ;; Switch to the output buffer
2430 (set-buffer buffer)
2431 (let ((inhibit-read-only t)) (erase-buffer))
2432 (fundamental-mode)
2434 (and (fboundp 'set-buffer-file-coding-system)
2435 (set-buffer-file-coding-system coding-system-for-write))
2437 (let ((case-fold-search nil)
2438 (org-odd-levels-only odd))
2439 ;; create local variables for all options, to make sure all called
2440 ;; functions get the correct information
2441 (mapc (lambda (x)
2442 (set (make-local-variable (cdr x))
2443 (plist-get opt-plist (car x))))
2444 org-export-plist-vars)
2445 (setq umax (if arg (prefix-numeric-value arg)
2446 org-export-headline-levels))
2447 (setq umax-toc (if (integerp org-export-with-toc)
2448 (min org-export-with-toc umax)
2449 umax))
2450 (unless body-only
2451 ;; File header
2452 (insert (format
2453 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2454 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2455 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2456 lang=\"%s\" xml:lang=\"%s\">
2457 <head>
2458 <title>%s</title>
2459 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2460 <meta name=\"generator\" content=\"Org-mode\"/>
2461 <meta name=\"generated\" content=\"%s\"/>
2462 <meta name=\"author\" content=\"%s\"/>
2464 </head><body>
2466 language language (org-html-expand title)
2467 (or charset "iso-8859-1") date author style))
2469 (insert (or (plist-get opt-plist :preamble) ""))
2471 (when (plist-get opt-plist :auto-preamble)
2472 (if title (insert (format org-export-html-title-format
2473 (org-html-expand title))))))
2475 (if (and org-export-with-toc (not body-only))
2476 (progn
2477 (push (format "<h%d>%s</h%d>\n"
2478 org-export-html-toplevel-hlevel
2479 (nth 3 lang-words)
2480 org-export-html-toplevel-hlevel)
2481 thetoc)
2482 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2483 (push "<ul>\n<li>" thetoc)
2484 (setq lines
2485 (mapcar '(lambda (line)
2486 (if (string-match org-todo-line-regexp line)
2487 ;; This is a headline
2488 (progn
2489 (setq have-headings t)
2490 (setq level (- (match-end 1) (match-beginning 1))
2491 level (org-tr-level level)
2492 txt (save-match-data
2493 (org-html-expand
2494 (org-export-cleanup-toc-line
2495 (match-string 3 line))))
2496 todo
2497 (or (and org-export-mark-todo-in-toc
2498 (match-beginning 2)
2499 (not (member (match-string 2 line)
2500 org-done-keywords)))
2501 ; TODO, not DONE
2502 (and org-export-mark-todo-in-toc
2503 (= level umax-toc)
2504 (org-search-todo-below
2505 line lines level))))
2506 (if (string-match
2507 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2508 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2509 (if (string-match quote-re0 txt)
2510 (setq txt (replace-match "" t t txt)))
2511 (setq snumber (org-section-number level))
2512 (if org-export-with-section-numbers
2513 (setq txt (concat snumber " " txt)))
2514 (if (<= level (max umax umax-toc))
2515 (setq head-count (+ head-count 1)))
2516 (if (<= level umax-toc)
2517 (progn
2518 (if (> level org-last-level)
2519 (progn
2520 (setq cnt (- level org-last-level))
2521 (while (>= (setq cnt (1- cnt)) 0)
2522 (push "\n<ul>\n<li>" thetoc))
2523 (push "\n" thetoc)))
2524 (if (< level org-last-level)
2525 (progn
2526 (setq cnt (- org-last-level level))
2527 (while (>= (setq cnt (1- cnt)) 0)
2528 (push "</li>\n</ul>" thetoc))
2529 (push "\n" thetoc)))
2530 ;; Check for targets
2531 (while (string-match org-any-target-regexp line)
2532 (setq line (replace-match
2533 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2534 t t line)))
2535 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2536 (setq txt (replace-match "" t t txt)))
2537 (push
2538 (format
2539 (if todo
2540 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2541 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2542 snumber txt) thetoc)
2544 (setq org-last-level level))
2546 line)
2547 lines))
2548 (while (> org-last-level (1- org-min-level))
2549 (setq org-last-level (1- org-last-level))
2550 (push "</li>\n</ul>\n" thetoc))
2551 (push "</div>\n" thetoc)
2552 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2554 (setq head-count 0)
2555 (org-init-section-numbers)
2557 (while (setq line (pop lines) origline line)
2558 (catch 'nextline
2560 ;; end of quote section?
2561 (when (and inquote (string-match "^\\*+ " line))
2562 (insert "</pre>\n")
2563 (setq inquote nil))
2564 ;; inside a quote section?
2565 (when inquote
2566 (insert (org-html-protect line) "\n")
2567 (throw 'nextline nil))
2569 ;; verbatim lines
2570 (when (and org-export-with-fixed-width
2571 (string-match "^[ \t]*:\\(.*\\)" line))
2572 (when (not infixed)
2573 (setq infixed t)
2574 (insert "<pre>\n"))
2575 (insert (org-html-protect (match-string 1 line)) "\n")
2576 (when (and lines
2577 (not (string-match "^[ \t]*\\(:.*\\)"
2578 (car lines))))
2579 (setq infixed nil)
2580 (insert "</pre>\n"))
2581 (throw 'nextline nil))
2583 ;; Protected HTML
2584 (when (get-text-property 0 'org-protected line)
2585 (let (par)
2586 (when (re-search-backward
2587 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2588 (setq par (match-string 1))
2589 (replace-match "\\2\n"))
2590 (insert line "\n")
2591 (while (and lines
2592 (not (string-match "^[ \t]*:" (car lines)))
2593 (or (= (length (car lines)) 0)
2594 (get-text-property 0 'org-protected (car lines))))
2595 (insert (pop lines) "\n"))
2596 (and par (insert "<p>\n")))
2597 (throw 'nextline nil))
2599 ;; Horizontal line
2600 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2601 (insert "\n<hr/>\n")
2602 (throw 'nextline nil))
2604 ;; Blockquotes
2605 (when (equal "ORG-BLOCKQUOTE-START" line)
2606 (insert "<blockquote>\n<p>\n")
2607 (throw 'nextline nil))
2608 (when (equal "ORG-BLOCKQUOTE-END" line)
2609 (insert "</p>\n</blockquote>\n")
2610 (throw 'nextline nil))
2612 ;; make targets to anchors
2613 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2614 (cond
2615 ((match-end 2)
2616 (setq line (replace-match
2617 (concat "@<a name=\""
2618 (org-solidify-link-text (match-string 1 line))
2619 "\">\\nbsp@</a>")
2620 t t line)))
2621 ((and org-export-with-toc (equal (string-to-char line) ?*))
2622 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2623 (setq line (replace-match
2624 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2625 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2626 t t line)))
2628 (setq line (replace-match
2629 (concat "@<a name=\""
2630 (org-solidify-link-text (match-string 1 line))
2631 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2632 t t line)))))
2634 (setq line (org-html-handle-time-stamps line))
2636 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2637 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2638 ;; Also handle sub_superscripts and checkboxes
2639 (or (string-match org-table-hline-regexp line)
2640 (setq line (org-html-expand line)))
2642 ;; Format the links
2643 (setq start 0)
2644 (while (string-match org-bracket-link-analytic-regexp line start)
2645 (setq start (match-beginning 0))
2646 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2647 (setq path (match-string 3 line))
2648 (setq desc1 (if (match-end 5) (match-string 5 line))
2649 desc2 (if (match-end 2) (concat type ":" path) path)
2650 descp (and desc1 (not (equal desc1 desc2)))
2651 desc (or desc1 desc2))
2652 ;; Make an image out of the description if that is so wanted
2653 (when (and descp (org-file-image-p desc))
2654 (save-match-data
2655 (if (string-match "^file:" desc)
2656 (setq desc (substring desc (match-end 0)))))
2657 (setq desc (concat "<img src=\"" desc "\"/>")))
2658 ;; FIXME: do we need to unescape here somewhere?
2659 (cond
2660 ((equal type "internal")
2661 (setq rpl
2662 (concat
2663 "<a href=\"#"
2664 (org-solidify-link-text
2665 (save-match-data (org-link-unescape path)) nil)
2666 "\">" desc "</a>")))
2667 ((member type '("http" "https"))
2668 ;; standard URL, just check if we need to inline an image
2669 (if (and (or (eq t org-export-html-inline-images)
2670 (and org-export-html-inline-images (not descp)))
2671 (org-file-image-p path))
2672 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2673 (setq link (concat type ":" path))
2674 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2675 ((member type '("ftp" "mailto" "news"))
2676 ;; standard URL
2677 (setq link (concat type ":" path))
2678 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2679 ((string= type "file")
2680 ;; FILE link
2681 (let* ((filename path)
2682 (abs-p (file-name-absolute-p filename))
2683 thefile file-is-image-p search)
2684 (save-match-data
2685 (if (string-match "::\\(.*\\)" filename)
2686 (setq search (match-string 1 filename)
2687 filename (replace-match "" t nil filename)))
2688 (setq valid
2689 (if (functionp link-validate)
2690 (funcall link-validate filename current-dir)
2692 (setq file-is-image-p (org-file-image-p filename))
2693 (setq thefile (if abs-p (expand-file-name filename) filename))
2694 (when (and org-export-html-link-org-files-as-html
2695 (string-match "\\.org$" thefile))
2696 (setq thefile (concat (substring thefile 0
2697 (match-beginning 0))
2698 "." html-extension))
2699 (if (and search
2700 ;; make sure this is can be used as target search
2701 (not (string-match "^[0-9]*$" search))
2702 (not (string-match "^\\*" search))
2703 (not (string-match "^/.*/$" search)))
2704 (setq thefile (concat thefile "#"
2705 (org-solidify-link-text
2706 (org-link-unescape search)))))
2707 (when (string-match "^file:" desc)
2708 (setq desc (replace-match "" t t desc))
2709 (if (string-match "\\.org$" desc)
2710 (setq desc (replace-match "" t t desc))))))
2711 (setq rpl (if (and file-is-image-p
2712 (or (eq t org-export-html-inline-images)
2713 (and org-export-html-inline-images
2714 (not descp))))
2715 (concat "<img src=\"" thefile "\"/>")
2716 (concat "<a href=\"" thefile "\">" desc "</a>")))
2717 (if (not valid) (setq rpl desc))))
2719 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2720 (setq rpl
2721 (save-match-data
2722 (funcall fnc (org-link-unescape path) desc1 'html))))
2725 ;; just publish the path, as default
2726 (setq rpl (concat "<i>&lt;" type ":"
2727 (save-match-data (org-link-unescape path))
2728 "&gt;</i>"))))
2729 (setq line (replace-match rpl t t line)
2730 start (+ start (length rpl))))
2732 ;; TODO items
2733 (if (and (string-match org-todo-line-regexp line)
2734 (match-beginning 2))
2736 (setq line
2737 (concat (substring line 0 (match-beginning 2))
2738 "<span class=\""
2739 (if (member (match-string 2 line)
2740 org-done-keywords)
2741 "done" "todo")
2742 "\">" (match-string 2 line)
2743 "</span>" (substring line (match-end 2)))))
2745 ;; Does this contain a reference to a footnote?
2746 (when org-export-with-footnotes
2747 (setq start 0)
2748 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
2749 (if (get-text-property (match-beginning 2) 'org-protected line)
2750 (setq start (match-end 2))
2751 (let ((n (match-string 2 line)))
2752 (setq line
2753 (replace-match
2754 (format
2755 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2756 (match-string 1 line) n n n)
2757 t t line))))))
2759 (cond
2760 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2761 ;; This is a headline
2762 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2763 txt (match-string 2 line))
2764 (if (string-match quote-re0 txt)
2765 (setq txt (replace-match "" t t txt)))
2766 (if (<= level (max umax umax-toc))
2767 (setq head-count (+ head-count 1)))
2768 (when in-local-list
2769 ;; Close any local lists before inserting a new header line
2770 (while local-list-type
2771 (org-close-li (car local-list-type))
2772 (insert (format "</%sl>\n" (car local-list-type)))
2773 (pop local-list-type))
2774 (setq local-list-indent nil
2775 in-local-list nil))
2776 (setq first-heading-pos (or first-heading-pos (point)))
2777 (org-html-level-start level txt umax
2778 (and org-export-with-toc (<= level umax))
2779 head-count)
2780 ;; QUOTES
2781 (when (string-match quote-re line)
2782 (insert "<pre>")
2783 (setq inquote t)))
2785 ((and org-export-with-tables
2786 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2787 (if (not table-open)
2788 ;; New table starts
2789 (setq table-open t table-buffer nil table-orig-buffer nil))
2790 ;; Accumulate lines
2791 (setq table-buffer (cons line table-buffer)
2792 table-orig-buffer (cons origline table-orig-buffer))
2793 (when (or (not lines)
2794 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2795 (car lines))))
2796 (setq table-open nil
2797 table-buffer (nreverse table-buffer)
2798 table-orig-buffer (nreverse table-orig-buffer))
2799 (org-close-par-maybe)
2800 (insert (org-format-table-html table-buffer table-orig-buffer))))
2802 ;; Normal lines
2803 (when (string-match
2804 (cond
2805 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2806 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2807 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2808 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2809 line)
2810 (setq ind (org-get-string-indentation line)
2811 item-type (if (match-beginning 4) "o" "u")
2812 starter (if (match-beginning 2)
2813 (substring (match-string 2 line) 0 -1))
2814 line (substring line (match-beginning 5))
2815 item-tag nil)
2816 (if (string-match "\\(.*?\\) ::[ \t]*" line)
2817 (setq item-type "d"
2818 item-tag (match-string 1 line)
2819 line (substring line (match-end 0))))
2820 (unless (string-match "[^ \t]" line)
2821 ;; empty line. Pretend indentation is large.
2822 (setq ind (if org-empty-line-terminates-plain-lists
2824 (1+ (or (car local-list-indent) 1)))))
2825 (setq didclose nil)
2826 (while (and in-local-list
2827 (or (and (= ind (car local-list-indent))
2828 (not starter))
2829 (< ind (car local-list-indent))))
2830 (setq didclose t)
2831 (org-close-li (car local-list-type))
2832 (insert (format "</%sl>\n" (car local-list-type)))
2833 (pop local-list-type) (pop local-list-indent)
2834 (setq in-local-list local-list-indent))
2835 (cond
2836 ((and starter
2837 (or (not in-local-list)
2838 (> ind (car local-list-indent))))
2839 ;; Start new (level of) list
2840 (org-close-par-maybe)
2841 (insert (cond
2842 ((equal item-type "u") "<ul>\n<li>\n")
2843 ((equal item-type "o") "<ol>\n<li>\n")
2844 ((equal item-type "d")
2845 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
2846 (push item-type local-list-type)
2847 (push ind local-list-indent)
2848 (setq in-local-list t))
2849 (starter
2850 ;; continue current list
2851 (org-close-li (car local-list-type))
2852 (insert (cond
2853 ((equal (car local-list-type) "d")
2854 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
2855 (t "<li>\n"))))
2856 (didclose
2857 ;; we did close a list, normal text follows: need <p>
2858 (org-open-par)))
2859 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
2860 (setq line
2861 (replace-match
2862 (if (equal (match-string 1 line) "X")
2863 "<b>[X]</b>"
2864 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2865 t t line))))
2867 ;; Empty lines start a new paragraph. If hand-formatted lists
2868 ;; are not fully interpreted, lines starting with "-", "+", "*"
2869 ;; also start a new paragraph.
2870 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
2872 ;; Is this the start of a footnote?
2873 (when org-export-with-footnotes
2874 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
2875 (org-close-par-maybe)
2876 (let ((n (match-string 1 line)))
2877 (setq line (replace-match
2878 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
2880 ;; Check if the line break needs to be conserved
2881 (cond
2882 ((string-match "\\\\\\\\[ \t]*$" line)
2883 (setq line (replace-match "<br/>" t t line)))
2884 (org-export-preserve-breaks
2885 (setq line (concat line "<br/>"))))
2887 (insert line "\n")))))
2889 ;; Properly close all local lists and other lists
2890 (when inquote (insert "</pre>\n"))
2891 (when in-local-list
2892 ;; Close any local lists before inserting a new header line
2893 (while local-list-type
2894 (org-close-li (car local-list-type))
2895 (insert (format "</%sl>\n" (car local-list-type)))
2896 (pop local-list-type))
2897 (setq local-list-indent nil
2898 in-local-list nil))
2899 (org-html-level-start 1 nil umax
2900 (and org-export-with-toc (<= level umax))
2901 head-count)
2902 ;; the </div> to lose the last text-... div.
2903 (insert "</div>\n")
2905 (unless body-only
2906 (when (plist-get opt-plist :auto-postamble)
2907 (insert "<div id=\"postamble\">")
2908 (when (and org-export-author-info author)
2909 (insert "<p class=\"author\"> "
2910 (nth 1 lang-words) ": " author "\n")
2911 (when email
2912 (if (listp (split-string email ",+ *"))
2913 (mapc (lambda(e)
2914 (insert "<a href=\"mailto:" e "\">&lt;"
2915 e "&gt;</a>\n"))
2916 (split-string email ",+ *"))
2917 (insert "<a href=\"mailto:" email "\">&lt;"
2918 email "&gt;</a>\n")))
2919 (insert "</p>\n"))
2920 (when (and date org-export-time-stamp-file)
2921 (insert "<p class=\"date\"> "
2922 (nth 2 lang-words) ": "
2923 date "</p>\n"))
2924 (insert "</div>"))
2926 (if org-export-html-with-timestamp
2927 (insert org-export-html-html-helper-timestamp))
2928 (insert (or (plist-get opt-plist :postamble) ""))
2929 (insert "</body>\n</html>\n"))
2931 (normal-mode)
2932 (if (eq major-mode default-major-mode) (html-mode))
2934 ;; insert the table of contents
2935 (goto-char (point-min))
2936 (when thetoc
2937 (if (or (re-search-forward
2938 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
2939 (re-search-forward
2940 "\\[TABLE-OF-CONTENTS\\]" nil t))
2941 (progn
2942 (goto-char (match-beginning 0))
2943 (replace-match ""))
2944 (goto-char first-heading-pos)
2945 (when (looking-at "\\s-*</p>")
2946 (goto-char (match-end 0))
2947 (insert "\n")))
2948 (insert "<div id=\"table-of-contents\">\n")
2949 (mapc 'insert thetoc)
2950 (insert "</div>\n"))
2951 ;; remove empty paragraphs and lists
2952 (goto-char (point-min))
2953 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2954 (replace-match ""))
2955 (goto-char (point-min))
2956 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
2957 (replace-match ""))
2958 (goto-char (point-min))
2959 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
2960 (replace-match ""))
2961 ;; Convert whitespace place holders
2962 (goto-char (point-min))
2963 (let (beg end n)
2964 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2965 (setq n (get-text-property beg 'org-whitespace)
2966 end (next-single-property-change beg 'org-whitespace))
2967 (goto-char beg)
2968 (delete-region beg end)
2969 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2970 (make-string n ?x)))))
2971 (or to-buffer (save-buffer))
2972 (goto-char (point-min))
2973 (message "Exporting... done")
2974 (if (eq to-buffer 'string)
2975 (prog1 (buffer-substring (point-min) (point-max))
2976 (kill-buffer (current-buffer)))
2977 (current-buffer)))))
2979 (defvar org-table-colgroup-info nil)
2980 (defun org-format-table-ascii (lines)
2981 "Format a table for ascii export."
2982 (if (stringp lines)
2983 (setq lines (org-split-string lines "\n")))
2984 (if (not (string-match "^[ \t]*|" (car lines)))
2985 ;; Table made by table.el - test for spanning
2986 lines
2988 ;; A normal org table
2989 ;; Get rid of hlines at beginning and end
2990 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2991 (setq lines (nreverse lines))
2992 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2993 (setq lines (nreverse lines))
2994 (when org-export-table-remove-special-lines
2995 ;; Check if the table has a marking column. If yes remove the
2996 ;; column and the special lines
2997 (setq lines (org-table-clean-before-export lines)))
2998 ;; Get rid of the vertical lines except for grouping
2999 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3000 rtn line vl1 start)
3001 (while (setq line (pop lines))
3002 (if (string-match org-table-hline-regexp line)
3003 (and (string-match "|\\(.*\\)|" line)
3004 (setq line (replace-match " \\1" t nil line)))
3005 (setq start 0 vl1 vl)
3006 (while (string-match "|" line start)
3007 (setq start (match-end 0))
3008 (or (pop vl1) (setq line (replace-match " " t t line)))))
3009 (push line rtn))
3010 (nreverse rtn))))
3012 (defun org-colgroup-info-to-vline-list (info)
3013 (let (vl new last)
3014 (while info
3015 (setq last new new (pop info))
3016 (if (or (memq last '(:end :startend))
3017 (memq new '(:start :startend)))
3018 (push t vl)
3019 (push nil vl)))
3020 (setq vl (nreverse vl))
3021 (and vl (setcar vl nil))
3022 vl))
3024 (defvar org-table-number-regexp) ; defined in org-table.el
3025 (defun org-format-table-html (lines olines)
3026 "Find out which HTML converter to use and return the HTML code."
3027 (if (stringp lines)
3028 (setq lines (org-split-string lines "\n")))
3029 (if (string-match "^[ \t]*|" (car lines))
3030 ;; A normal org table
3031 (org-format-org-table-html lines)
3032 ;; Table made by table.el - test for spanning
3033 (let* ((hlines (delq nil (mapcar
3034 (lambda (x)
3035 (if (string-match "^[ \t]*\\+-" x) x
3036 nil))
3037 lines)))
3038 (first (car hlines))
3039 (ll (and (string-match "\\S-+" first)
3040 (match-string 0 first)))
3041 (re (concat "^[ \t]*" (regexp-quote ll)))
3042 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3043 hlines))))
3044 (if (and (not spanning)
3045 (not org-export-prefer-native-exporter-for-tables))
3046 ;; We can use my own converter with HTML conversions
3047 (org-format-table-table-html lines)
3048 ;; Need to use the code generator in table.el, with the original text.
3049 (org-format-table-table-html-using-table-generate-source olines)))))
3051 (defvar org-table-number-fraction) ; defined in org-table.el
3052 (defun org-format-org-table-html (lines &optional splice)
3053 "Format a table into HTML."
3054 (require 'org-table)
3055 ;; Get rid of hlines at beginning and end
3056 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3057 (setq lines (nreverse lines))
3058 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3059 (setq lines (nreverse lines))
3060 (when org-export-table-remove-special-lines
3061 ;; Check if the table has a marking column. If yes remove the
3062 ;; column and the special lines
3063 (setq lines (org-table-clean-before-export lines)))
3065 (let ((head (and org-export-highlight-first-table-line
3066 (delq nil (mapcar
3067 (lambda (x) (string-match "^[ \t]*|-" x))
3068 (cdr lines)))))
3069 (nlines 0) fnum i
3070 tbopen line fields html gr colgropen)
3071 (if splice (setq head nil))
3072 (unless splice (push (if head "<thead>" "<tbody>") html))
3073 (setq tbopen t)
3074 (while (setq line (pop lines))
3075 (catch 'next-line
3076 (if (string-match "^[ \t]*|-" line)
3077 (progn
3078 (unless splice
3079 (push (if head "</thead>" "</tbody>") html)
3080 (if lines (push "<tbody>" html) (setq tbopen nil)))
3081 (setq head nil) ;; head ends here, first time around
3082 ;; ignore this line
3083 (throw 'next-line t)))
3084 ;; Break the line into fields
3085 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3086 (unless fnum (setq fnum (make-vector (length fields) 0)))
3087 (setq nlines (1+ nlines) i -1)
3088 (push (concat "<tr>"
3089 (mapconcat
3090 (lambda (x)
3091 (setq i (1+ i))
3092 (if (and (< i nlines)
3093 (string-match org-table-number-regexp x))
3094 (incf (aref fnum i)))
3095 (if head
3096 (concat (car org-export-table-header-tags) x
3097 (cdr org-export-table-header-tags))
3098 (concat (car org-export-table-data-tags) x
3099 (cdr org-export-table-data-tags))))
3100 fields "")
3101 "</tr>")
3102 html)))
3103 (unless splice (if tbopen (push "</tbody>" html)))
3104 (unless splice (push "</table>\n" html))
3105 (setq html (nreverse html))
3106 (unless splice
3107 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3108 (push (mapconcat
3109 (lambda (x)
3110 (setq gr (pop org-table-colgroup-info))
3111 (format "%s<col align=\"%s\"></col>%s"
3112 (if (memq gr '(:start :startend))
3113 (prog1
3114 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3115 (setq colgropen t))
3117 (if (> (/ (float x) nlines) org-table-number-fraction)
3118 "right" "left")
3119 (if (memq gr '(:end :startend))
3120 (progn (setq colgropen nil) "</colgroup>")
3121 "")))
3122 fnum "")
3123 html)
3124 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3125 (push html-table-tag html))
3126 (concat (mapconcat 'identity html "\n") "\n")))
3128 (defun org-table-clean-before-export (lines)
3129 "Check if the table has a marking column.
3130 If yes remove the column and the special lines."
3131 (setq org-table-colgroup-info nil)
3132 (if (memq nil
3133 (mapcar
3134 (lambda (x) (or (string-match "^[ \t]*|-" x)
3135 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3136 lines))
3137 (progn
3138 (setq org-table-clean-did-remove-column nil)
3139 (delq nil
3140 (mapcar
3141 (lambda (x)
3142 (cond
3143 ((string-match "^[ \t]*| */ *|" x)
3144 (setq org-table-colgroup-info
3145 (mapcar (lambda (x)
3146 (cond ((member x '("<" "&lt;")) :start)
3147 ((member x '(">" "&gt;")) :end)
3148 ((member x '("<>" "&lt;&gt;")) :startend)
3149 (t nil)))
3150 (org-split-string x "[ \t]*|[ \t]*")))
3151 nil)
3152 (t x)))
3153 lines)))
3154 (setq org-table-clean-did-remove-column t)
3155 (delq nil
3156 (mapcar
3157 (lambda (x)
3158 (cond
3159 ((string-match "^[ \t]*| */ *|" x)
3160 (setq org-table-colgroup-info
3161 (mapcar (lambda (x)
3162 (cond ((member x '("<" "&lt;")) :start)
3163 ((member x '(">" "&gt;")) :end)
3164 ((member x '("<>" "&lt;&gt;")) :startend)
3165 (t nil)))
3166 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3167 nil)
3168 ((string-match "^[ \t]*| *[!_^/] *|" x)
3169 nil) ; ignore this line
3170 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3171 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3172 ;; remove the first column
3173 (replace-match "\\1|" t nil x))))
3174 lines))))
3176 (defun org-format-table-table-html (lines)
3177 "Format a table generated by table.el into HTML.
3178 This conversion does *not* use `table-generate-source' from table.el.
3179 This has the advantage that Org-mode's HTML conversions can be used.
3180 But it has the disadvantage, that no cell- or row-spanning is allowed."
3181 (let (line field-buffer
3182 (head org-export-highlight-first-table-line)
3183 fields html empty)
3184 (setq html (concat html-table-tag "\n"))
3185 (while (setq line (pop lines))
3186 (setq empty "&nbsp;")
3187 (catch 'next-line
3188 (if (string-match "^[ \t]*\\+-" line)
3189 (progn
3190 (if field-buffer
3191 (progn
3192 (setq
3193 html
3194 (concat
3195 html
3196 "<tr>"
3197 (mapconcat
3198 (lambda (x)
3199 (if (equal x "") (setq x empty))
3200 (if head
3201 (concat (car org-export-table-header-tags) x
3202 (cdr org-export-table-header-tags))
3203 (concat (car org-export-table-data-tags) x
3204 (cdr org-export-table-data-tags))))
3205 field-buffer "\n")
3206 "</tr>\n"))
3207 (setq head nil)
3208 (setq field-buffer nil)))
3209 ;; Ignore this line
3210 (throw 'next-line t)))
3211 ;; Break the line into fields and store the fields
3212 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3213 (if field-buffer
3214 (setq field-buffer (mapcar
3215 (lambda (x)
3216 (concat x "<br/>" (pop fields)))
3217 field-buffer))
3218 (setq field-buffer fields))))
3219 (setq html (concat html "</table>\n"))
3220 html))
3222 (defun org-format-table-table-html-using-table-generate-source (lines)
3223 "Format a table into html, using `table-generate-source' from table.el.
3224 This has the advantage that cell- or row-spanning is allowed.
3225 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3226 (require 'table)
3227 (with-current-buffer (get-buffer-create " org-tmp1 ")
3228 (erase-buffer)
3229 (insert (mapconcat 'identity lines "\n"))
3230 (goto-char (point-min))
3231 (if (not (re-search-forward "|[^+]" nil t))
3232 (error "Error processing table"))
3233 (table-recognize-table)
3234 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3235 (table-generate-source 'html " org-tmp2 ")
3236 (set-buffer " org-tmp2 ")
3237 (buffer-substring (point-min) (point-max))))
3239 (defun org-html-handle-time-stamps (s)
3240 "Format time stamps in string S, or remove them."
3241 (catch 'exit
3242 (let (r b)
3243 (while (string-match org-maybe-keyword-time-regexp s)
3244 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3245 ;; never export CLOCK
3246 (throw 'exit ""))
3247 (or b (setq b (substring s 0 (match-beginning 0))))
3248 (if (not org-export-with-timestamps)
3249 (setq r (concat r (substring s 0 (match-beginning 0)))
3250 s (substring s (match-end 0)))
3251 (setq r (concat
3252 r (substring s 0 (match-beginning 0))
3253 (if (match-end 1)
3254 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3255 (match-string 1 s)))
3256 (format " @<span class=\"timestamp\">%s@</span>"
3257 (substring
3258 (org-translate-time (match-string 3 s)) 1 -1)))
3259 s (substring s (match-end 0)))))
3260 ;; Line break if line started and ended with time stamp stuff
3261 (if (not r)
3263 (setq r (concat r s))
3264 (unless (string-match "\\S-" (concat b s))
3265 (setq r (concat r "@<br/>")))
3266 r))))
3268 (defun org-html-protect (s)
3269 ;; convert & to &amp;, < to &lt; and > to &gt;
3270 (let ((start 0))
3271 (while (string-match "&" s start)
3272 (setq s (replace-match "&amp;" t t s)
3273 start (1+ (match-beginning 0))))
3274 (while (string-match "<" s)
3275 (setq s (replace-match "&lt;" t t s)))
3276 (while (string-match ">" s)
3277 (setq s (replace-match "&gt;" t t s))))
3280 (defun org-export-cleanup-toc-line (s)
3281 "Remove tags and time staps from lines going into the toc."
3282 (when (memq org-export-with-tags '(not-in-toc nil))
3283 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3284 (setq s (replace-match "" t t s))))
3285 (when org-export-remove-timestamps-from-toc
3286 (while (string-match org-maybe-keyword-time-regexp s)
3287 (setq s (replace-match "" t t s))))
3288 (while (string-match org-bracket-link-regexp s)
3289 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3290 t t s)))
3293 (defun org-html-expand (string)
3294 "Prepare STRING for HTML export. Applies all active conversions.
3295 If there are links in the string, don't modify these."
3296 (let* ((re (concat org-bracket-link-regexp "\\|"
3297 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3298 m s l res)
3299 (while (setq m (string-match re string))
3300 (setq s (substring string 0 m)
3301 l (match-string 0 string)
3302 string (substring string (match-end 0)))
3303 (push (org-html-do-expand s) res)
3304 (push l res))
3305 (push (org-html-do-expand string) res)
3306 (apply 'concat (nreverse res))))
3308 (defun org-html-do-expand (s)
3309 "Apply all active conversions to translate special ASCII to HTML."
3310 (setq s (org-html-protect s))
3311 (if org-export-html-expand
3312 (let ((start 0))
3313 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3314 (setq s (replace-match "<\\1>" t nil s)))))
3315 (if org-export-with-emphasize
3316 (setq s (org-export-html-convert-emphasize s)))
3317 (if org-export-with-special-strings
3318 (setq s (org-export-html-convert-special-strings s)))
3319 (if org-export-with-sub-superscripts
3320 (setq s (org-export-html-convert-sub-super s)))
3321 (if org-export-with-TeX-macros
3322 (let ((start 0) wd ass)
3323 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3324 (if (get-text-property (match-beginning 0) 'org-protected s)
3325 (setq start (match-end 0))
3326 (setq wd (match-string 1 s))
3327 (if (setq ass (assoc wd org-html-entities))
3328 (setq s (replace-match (or (cdr ass)
3329 (concat "&" (car ass) ";"))
3330 t t s))
3331 (setq start (+ start (length wd))))))))
3334 (defun org-create-multibrace-regexp (left right n)
3335 "Create a regular expression which will match a balanced sexp.
3336 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3337 as single character strings.
3338 The regexp returned will match the entire expression including the
3339 delimiters. It will also define a single group which contains the
3340 match except for the outermost delimiters. The maximum depth of
3341 stacked delimiters is N. Escaping delimiters is not possible."
3342 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3343 (or "\\|")
3344 (re nothing)
3345 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3346 (while (> n 1)
3347 (setq n (1- n)
3348 re (concat re or next)
3349 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3350 (concat left "\\(" re "\\)" right)))
3352 (defvar org-match-substring-regexp
3353 (concat
3354 "\\([^\\]\\)\\([_^]\\)\\("
3355 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3356 "\\|"
3357 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3358 "\\|"
3359 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3360 "The regular expression matching a sub- or superscript.")
3362 (defvar org-match-substring-with-braces-regexp
3363 (concat
3364 "\\([^\\]\\)\\([_^]\\)\\("
3365 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3366 "\\)")
3367 "The regular expression matching a sub- or superscript, forcing braces.")
3369 (defconst org-export-html-special-string-regexps
3370 '(("\\\\-" . "&shy;")
3371 ("---\\([^-]\\)" . "&mdash;\\1")
3372 ("--\\([^-]\\)" . "&ndash;\\1")
3373 ("\\.\\.\\." . "&hellip;"))
3374 "Regular expressions for special string conversion.")
3376 (defun org-export-html-convert-special-strings (string)
3377 "Convert special characters in STRING to HTML."
3378 (let ((all org-export-html-special-string-regexps)
3379 e a re rpl start)
3380 (while (setq a (pop all))
3381 (setq re (car a) rpl (cdr a) start 0)
3382 (while (string-match re string start)
3383 (if (get-text-property (match-beginning 0) 'org-protected string)
3384 (setq start (match-end 0))
3385 (setq string (replace-match rpl t nil string)))))
3386 string))
3388 (defun org-export-html-convert-sub-super (string)
3389 "Convert sub- and superscripts in STRING to HTML."
3390 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3391 (while (string-match org-match-substring-regexp string s)
3392 (cond
3393 ((and requireb (match-end 8)) (setq s (match-end 2)))
3394 ((get-text-property (match-beginning 2) 'org-protected string)
3395 (setq s (match-end 2)))
3397 (setq s (match-end 1)
3398 key (if (string= (match-string 2 string) "_") "sub" "sup")
3399 c (or (match-string 8 string)
3400 (match-string 6 string)
3401 (match-string 5 string))
3402 string (replace-match
3403 (concat (match-string 1 string)
3404 "<" key ">" c "</" key ">")
3405 t t string)))))
3406 (while (string-match "\\\\\\([_^]\\)" string)
3407 (setq string (replace-match (match-string 1 string) t t string)))
3408 string))
3410 (defun org-export-html-convert-emphasize (string)
3411 "Apply emphasis."
3412 (let ((s 0) rpl)
3413 (while (string-match org-emph-re string s)
3414 (if (not (equal
3415 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3416 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3417 (setq s (match-beginning 0)
3419 (concat
3420 (match-string 1 string)
3421 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3422 (match-string 4 string)
3423 (nth 3 (assoc (match-string 3 string)
3424 org-emphasis-alist))
3425 (match-string 5 string))
3426 string (replace-match rpl t t string)
3427 s (+ s (- (length rpl) 2)))
3428 (setq s (1+ s))))
3429 string))
3431 (defvar org-par-open nil)
3432 (defun org-open-par ()
3433 "Insert <p>, but first close previous paragraph if any."
3434 (org-close-par-maybe)
3435 (insert "\n<p>")
3436 (setq org-par-open t))
3437 (defun org-close-par-maybe ()
3438 "Close paragraph if there is one open."
3439 (when org-par-open
3440 (insert "</p>")
3441 (setq org-par-open nil)))
3442 (defun org-close-li (&optional type)
3443 "Close <li> if necessary."
3444 (org-close-par-maybe)
3445 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
3447 (defvar body-only) ; dynamically scoped into this.
3448 (defun org-html-level-start (level title umax with-toc head-count)
3449 "Insert a new level in HTML export.
3450 When TITLE is nil, just close all open levels."
3451 (org-close-par-maybe)
3452 (let ((target (and title (org-get-text-property-any 0 'target title)))
3453 (l org-level-max)
3454 snumber)
3455 (while (>= l level)
3456 (if (aref org-levels-open (1- l))
3457 (progn
3458 (org-html-level-close l umax)
3459 (aset org-levels-open (1- l) nil)))
3460 (setq l (1- l)))
3461 (when title
3462 ;; If title is nil, this means this function is called to close
3463 ;; all levels, so the rest is done only if title is given
3464 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3465 (setq title (replace-match
3466 (if org-export-with-tags
3467 (save-match-data
3468 (concat
3469 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3470 (mapconcat 'identity (org-split-string
3471 (match-string 1 title) ":")
3472 "&nbsp;")
3473 "</span>"))
3475 t t title)))
3476 (if (> level umax)
3477 (progn
3478 (if (aref org-levels-open (1- level))
3479 (progn
3480 (org-close-li)
3481 (if target
3482 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3483 (insert "<li>" title "<br/>\n")))
3484 (aset org-levels-open (1- level) t)
3485 (org-close-par-maybe)
3486 (if target
3487 (insert (format "<ul>\n<li id=\"%s\">" target)
3488 title "<br/>\n")
3489 (insert "<ul>\n<li>" title "<br/>\n"))))
3490 (aset org-levels-open (1- level) t)
3491 (setq snumber (org-section-number level))
3492 (if (and org-export-with-section-numbers (not body-only))
3493 (setq title (concat snumber " " title)))
3494 (setq level (+ level org-export-html-toplevel-hlevel -1))
3495 (unless (= head-count 1) (insert "\n</div>\n"))
3496 (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"
3497 snumber level level snumber title level snumber))
3498 (org-open-par)))))
3500 (defun org-get-text-property-any (pos prop &optional object)
3501 (or (get-text-property pos prop object)
3502 (and (setq pos (next-single-property-change pos prop object))
3503 (get-text-property pos prop object))))
3505 (defun org-html-level-close (level max-outline-level)
3506 "Terminate one level in HTML export."
3507 (if (<= level max-outline-level)
3508 (insert "</div>\n")
3509 (org-close-li)
3510 (insert "</ul>\n")))
3512 ;;; iCalendar export
3514 ;;;###autoload
3515 (defun org-export-icalendar-this-file ()
3516 "Export current file as an iCalendar file.
3517 The iCalendar file will be located in the same directory as the Org-mode
3518 file, but with extension `.ics'."
3519 (interactive)
3520 (org-export-icalendar nil buffer-file-name))
3522 ;;;###autoload
3523 (defun org-export-icalendar-all-agenda-files ()
3524 "Export all files in `org-agenda-files' to iCalendar .ics files.
3525 Each iCalendar file will be located in the same directory as the Org-mode
3526 file, but with extension `.ics'."
3527 (interactive)
3528 (apply 'org-export-icalendar nil (org-agenda-files t)))
3530 ;;;###autoload
3531 (defun org-export-icalendar-combine-agenda-files ()
3532 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3533 The file is stored under the name `org-combined-agenda-icalendar-file'."
3534 (interactive)
3535 (apply 'org-export-icalendar t (org-agenda-files t)))
3537 (defun org-export-icalendar (combine &rest files)
3538 "Create iCalendar files for all elements of FILES.
3539 If COMBINE is non-nil, combine all calendar entries into a single large
3540 file and store it under the name `org-combined-agenda-icalendar-file'."
3541 (save-excursion
3542 (org-prepare-agenda-buffers files)
3543 (let* ((dir (org-export-directory
3544 :ical (list :publishing-directory
3545 org-export-publishing-directory)))
3546 file ical-file ical-buffer category started org-agenda-new-buffers)
3547 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3548 (when combine
3549 (setq ical-file
3550 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3551 org-combined-agenda-icalendar-file
3552 (expand-file-name org-combined-agenda-icalendar-file dir))
3553 ical-buffer (org-get-agenda-file-buffer ical-file))
3554 (set-buffer ical-buffer) (erase-buffer))
3555 (while (setq file (pop files))
3556 (catch 'nextfile
3557 (org-check-agenda-file file)
3558 (set-buffer (org-get-agenda-file-buffer file))
3559 (unless combine
3560 (setq ical-file (concat (file-name-as-directory dir)
3561 (file-name-sans-extension
3562 (file-name-nondirectory buffer-file-name))
3563 ".ics"))
3564 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3565 (with-current-buffer ical-buffer (erase-buffer)))
3566 (setq category (or org-category
3567 (file-name-sans-extension
3568 (file-name-nondirectory buffer-file-name))))
3569 (if (symbolp category) (setq category (symbol-name category)))
3570 (let ((standard-output ical-buffer))
3571 (if combine
3572 (and (not started) (setq started t)
3573 (org-start-icalendar-file org-icalendar-combined-name))
3574 (org-start-icalendar-file category))
3575 (org-print-icalendar-entries combine)
3576 (when (or (and combine (not files)) (not combine))
3577 (org-finish-icalendar-file)
3578 (set-buffer ical-buffer)
3579 (save-buffer)
3580 (run-hooks 'org-after-save-iCalendar-file-hook)
3581 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
3582 ))))
3583 (org-release-buffers org-agenda-new-buffers))))
3585 (defvar org-after-save-iCalendar-file-hook nil
3586 "Hook run after an iCalendar file has been saved.
3587 The iCalendar buffer is still current when this hook is run.
3588 A good way to use this is to tell a desktop calenndar application to re-read
3589 the iCalendar file.")
3591 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3592 (defun org-print-icalendar-entries (&optional combine)
3593 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3594 When COMBINE is non nil, add the category to each line."
3595 (require 'org-agenda)
3596 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3597 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3598 (dts (org-ical-ts-to-string
3599 (format-time-string (cdr org-time-stamp-formats) (current-time))
3600 "DTSTART"))
3601 hd ts ts2 state status (inc t) pos b sexp rrule
3602 scheduledp deadlinep tmp pri category entry location summary desc
3603 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3604 (org-refresh-category-properties)
3605 (save-excursion
3606 (goto-char (point-min))
3607 (while (re-search-forward re1 nil t)
3608 (catch :skip
3609 (org-agenda-skip)
3610 (when (boundp 'org-icalendar-verify-function)
3611 (unless (funcall org-icalendar-verify-function)
3612 (outline-next-heading)
3613 (backward-char 1)
3614 (throw :skip nil)))
3615 (setq pos (match-beginning 0)
3616 ts (match-string 0)
3617 inc t
3618 hd (condition-case nil
3619 (org-icalendar-cleanup-string
3620 (org-get-heading))
3621 (error (throw :skip nil)))
3622 summary (org-icalendar-cleanup-string
3623 (org-entry-get nil "SUMMARY"))
3624 desc (org-icalendar-cleanup-string
3625 (or (org-entry-get nil "DESCRIPTION")
3626 (and org-icalendar-include-body (org-get-entry)))
3627 t org-icalendar-include-body)
3628 location (org-icalendar-cleanup-string
3629 (org-entry-get nil "LOCATION"))
3630 category (org-get-category))
3631 (if (looking-at re2)
3632 (progn
3633 (goto-char (match-end 0))
3634 (setq ts2 (match-string 1) inc nil))
3635 (setq tmp (buffer-substring (max (point-min)
3636 (- pos org-ds-keyword-length))
3637 pos)
3638 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3639 (progn
3640 (setq inc nil)
3641 (replace-match "\\1" t nil ts))
3643 deadlinep (string-match org-deadline-regexp tmp)
3644 scheduledp (string-match org-scheduled-regexp tmp)
3645 ;; donep (org-entry-is-done-p)
3647 (if (or (string-match org-tr-regexp hd)
3648 (string-match org-ts-regexp hd))
3649 (setq hd (replace-match "" t t hd)))
3650 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3651 (setq rrule
3652 (concat "\nRRULE:FREQ="
3653 (cdr (assoc
3654 (match-string 2 ts)
3655 '(("d" . "DAILY")("w" . "WEEKLY")
3656 ("m" . "MONTHLY")("y" . "YEARLY"))))
3657 ";INTERVAL=" (match-string 1 ts)))
3658 (setq rrule ""))
3659 (setq summary (or summary hd))
3660 (if (string-match org-bracket-link-regexp summary)
3661 (setq summary
3662 (replace-match (if (match-end 3)
3663 (match-string 3 summary)
3664 (match-string 1 summary))
3665 t t summary)))
3666 (if deadlinep (setq summary (concat "DL: " summary)))
3667 (if scheduledp (setq summary (concat "S: " summary)))
3668 (if (string-match "\\`<%%" ts)
3669 (with-current-buffer sexp-buffer
3670 (insert (substring ts 1 -1) " " summary "\n"))
3671 (princ (format "BEGIN:VEVENT
3673 %s%s
3674 SUMMARY:%s%s%s
3675 CATEGORIES:%s
3676 END:VEVENT\n"
3677 (org-ical-ts-to-string ts "DTSTART")
3678 (org-ical-ts-to-string ts2 "DTEND" inc)
3679 rrule summary
3680 (if (and desc (string-match "\\S-" desc))
3681 (concat "\nDESCRIPTION: " desc) "")
3682 (if (and location (string-match "\\S-" location))
3683 (concat "\nLOCATION: " location) "")
3684 category)))))
3686 (when (and org-icalendar-include-sexps
3687 (condition-case nil (require 'icalendar) (error nil))
3688 (fboundp 'icalendar-export-region))
3689 ;; Get all the literal sexps
3690 (goto-char (point-min))
3691 (while (re-search-forward "^&?%%(" nil t)
3692 (catch :skip
3693 (org-agenda-skip)
3694 (setq b (match-beginning 0))
3695 (goto-char (1- (match-end 0)))
3696 (forward-sexp 1)
3697 (end-of-line 1)
3698 (setq sexp (buffer-substring b (point)))
3699 (with-current-buffer sexp-buffer
3700 (insert sexp "\n"))
3701 (princ (org-diary-to-ical-string sexp-buffer)))))
3703 (when org-icalendar-include-todo
3704 (goto-char (point-min))
3705 (while (re-search-forward org-todo-line-regexp nil t)
3706 (catch :skip
3707 (org-agenda-skip)
3708 (when (boundp 'org-icalendar-verify-function)
3709 (unless (funcall org-icalendar-verify-function)
3710 (outline-next-heading)
3711 (backward-char 1)
3712 (throw :skip nil)))
3713 (setq state (match-string 2))
3714 (setq status (if (member state org-done-keywords)
3715 "COMPLETED" "NEEDS-ACTION"))
3716 (when (and state
3717 (or (not (member state org-done-keywords))
3718 (eq org-icalendar-include-todo 'all))
3719 (not (member org-archive-tag (org-get-tags-at)))
3721 (setq hd (match-string 3)
3722 summary (org-icalendar-cleanup-string
3723 (org-entry-get nil "SUMMARY"))
3724 desc (org-icalendar-cleanup-string
3725 (or (org-entry-get nil "DESCRIPTION")
3726 (and org-icalendar-include-body (org-get-entry)))
3727 t org-icalendar-include-body)
3728 location (org-icalendar-cleanup-string
3729 (org-entry-get nil "LOCATION")))
3730 (if (string-match org-bracket-link-regexp hd)
3731 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
3732 (match-string 1 hd))
3733 t t hd)))
3734 (if (string-match org-priority-regexp hd)
3735 (setq pri (string-to-char (match-string 2 hd))
3736 hd (concat (substring hd 0 (match-beginning 1))
3737 (substring hd (match-end 1))))
3738 (setq pri org-default-priority))
3739 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
3740 (- org-lowest-priority org-highest-priority))))))
3742 (princ (format "BEGIN:VTODO
3744 SUMMARY:%s%s%s
3745 CATEGORIES:%s
3746 SEQUENCE:1
3747 PRIORITY:%d
3748 STATUS:%s
3749 END:VTODO\n"
3751 (or summary hd)
3752 (if (and location (string-match "\\S-" location))
3753 (concat "\nLOCATION: " location) "")
3754 (if (and desc (string-match "\\S-" desc))
3755 (concat "\nDESCRIPTION: " desc) "")
3756 category pri status)))))))))
3758 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
3759 "Take out stuff and quote what needs to be quoted.
3760 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3761 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3762 characters."
3763 (if (not s)
3765 (when is-body
3766 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
3767 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
3768 (while (string-match re s) (setq s (replace-match "" t t s)))
3769 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
3770 (let ((start 0))
3771 (while (string-match "\\([,;]\\)" s start)
3772 (setq start (+ (match-beginning 0) 2)
3773 s (replace-match "\\\\\\1" nil nil s))))
3774 (when is-body
3775 (while (string-match "[ \t]*\n[ \t]*" s)
3776 (setq s (replace-match "\\n" t t s))))
3777 (setq s (org-trim s))
3778 (if is-body
3779 (if maxlength
3780 (if (and (numberp maxlength)
3781 (> (length s) maxlength))
3782 (setq s (substring s 0 maxlength)))))
3785 (defun org-get-entry ()
3786 "Clean-up description string."
3787 (save-excursion
3788 (org-back-to-heading t)
3789 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
3791 (defun org-start-icalendar-file (name)
3792 "Start an iCalendar file by inserting the header."
3793 (let ((user user-full-name)
3794 (name (or name "unknown"))
3795 (timezone (cadr (current-time-zone))))
3796 (princ
3797 (format "BEGIN:VCALENDAR
3798 VERSION:2.0
3799 X-WR-CALNAME:%s
3800 PRODID:-//%s//Emacs with Org-mode//EN
3801 X-WR-TIMEZONE:%s
3802 CALSCALE:GREGORIAN\n" name user timezone))))
3804 (defun org-finish-icalendar-file ()
3805 "Finish an iCalendar file by inserting the END statement."
3806 (princ "END:VCALENDAR\n"))
3808 (defun org-ical-ts-to-string (s keyword &optional inc)
3809 "Take a time string S and convert it to iCalendar format.
3810 KEYWORD is added in front, to make a complete line like DTSTART....
3811 When INC is non-nil, increase the hour by two (if time string contains
3812 a time), or the day by one (if it does not contain a time)."
3813 (let ((t1 (org-parse-time-string s 'nodefault))
3814 t2 fmt have-time time)
3815 (if (and (car t1) (nth 1 t1) (nth 2 t1))
3816 (setq t2 t1 have-time t)
3817 (setq t2 (org-parse-time-string s)))
3818 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
3819 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
3820 (when inc
3821 (if have-time
3822 (if org-agenda-default-appointment-duration
3823 (setq mi (+ org-agenda-default-appointment-duration mi))
3824 (setq h (+ 2 h)))
3825 (setq d (1+ d))))
3826 (setq time (encode-time s mi h d m y)))
3827 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3828 (concat keyword (format-time-string fmt time))))
3830 ;;; XOXO export
3832 (defun org-export-as-xoxo-insert-into (buffer &rest output)
3833 (with-current-buffer buffer
3834 (apply 'insert output)))
3835 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
3837 ;;;###autoload
3838 (defun org-export-as-xoxo (&optional buffer)
3839 "Export the org buffer as XOXO.
3840 The XOXO buffer is named *xoxo-<source buffer name>*"
3841 (interactive (list (current-buffer)))
3842 ;; A quickie abstraction
3844 ;; Output everything as XOXO
3845 (with-current-buffer (get-buffer buffer)
3846 (let* ((pos (point))
3847 (opt-plist (org-combine-plists (org-default-export-plist)
3848 (org-infile-export-plist)))
3849 (filename (concat (file-name-as-directory
3850 (org-export-directory :xoxo opt-plist))
3851 (file-name-sans-extension
3852 (file-name-nondirectory buffer-file-name))
3853 ".html"))
3854 (out (find-file-noselect filename))
3855 (last-level 1)
3856 (hanging-li nil))
3857 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3858 ;; Check the output buffer is empty.
3859 (with-current-buffer out (erase-buffer))
3860 ;; Kick off the output
3861 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
3862 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
3863 (let* ((hd (match-string-no-properties 1))
3864 (level (length hd))
3865 (text (concat
3866 (match-string-no-properties 2)
3867 (save-excursion
3868 (goto-char (match-end 0))
3869 (let ((str ""))
3870 (catch 'loop
3871 (while 't
3872 (forward-line)
3873 (if (looking-at "^[ \t]\\(.*\\)")
3874 (setq str (concat str (match-string-no-properties 1)))
3875 (throw 'loop str)))))))))
3877 ;; Handle level rendering
3878 (cond
3879 ((> level last-level)
3880 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
3882 ((< level last-level)
3883 (dotimes (- (- last-level level) 1)
3884 (if hanging-li
3885 (org-export-as-xoxo-insert-into out "</li>\n"))
3886 (org-export-as-xoxo-insert-into out "</ol>\n"))
3887 (when hanging-li
3888 (org-export-as-xoxo-insert-into out "</li>\n")
3889 (setq hanging-li nil)))
3891 ((equal level last-level)
3892 (if hanging-li
3893 (org-export-as-xoxo-insert-into out "</li>\n")))
3896 (setq last-level level)
3898 ;; And output the new li
3899 (setq hanging-li 't)
3900 (if (equal ?+ (elt text 0))
3901 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
3902 (org-export-as-xoxo-insert-into out "<li>" text))))
3904 ;; Finally finish off the ol
3905 (dotimes (- last-level 1)
3906 (if hanging-li
3907 (org-export-as-xoxo-insert-into out "</li>\n"))
3908 (org-export-as-xoxo-insert-into out "</ol>\n"))
3910 (goto-char pos)
3911 ;; Finish the buffer off and clean it up.
3912 (switch-to-buffer-other-window out)
3913 (indent-region (point-min) (point-max) nil)
3914 (save-buffer)
3915 (goto-char (point-min))
3918 (provide 'org-exp)
3920 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3922 ;;; org-exp.el ends here