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