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