More options for categories in iCalendar export.
[org-mode.git] / lisp / org-exp.el
bloba5528ec48eef74a3523ebd84b124750411e02c5d
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.06b
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
29 (require 'org-agenda)
30 (eval-and-compile
31 (require 'cl))
33 (declare-function org-export-latex-preprocess "org-export-latex" ())
34 (declare-function org-agenda-skip "org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
36 (declare-function htmlize-region "ext:htmlize" (beg end))
37 (defvar htmlize-buffer-places) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
41 :tag "Org Export"
42 :group 'org)
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag "Org Export General"
47 :group 'org-export)
49 ;; FIXME
50 (defvar org-export-publishing-directory nil)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group 'org-export-general
65 :type 'boolean)
68 (defcustom org-export-select-tags '("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-excude-tags'."
74 :group 'org-export-general
75 :type '(repeat (string :tag "Tag")))
77 (defcustom org-export-exclude-tags '("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without contition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group 'org-export-general
83 :type '(repeat (string :tag "Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
89 Org HTML LaTeX
90 -----+----------+--------
91 \\- &shy; \\-
92 -- &ndash; --
93 --- &mdash; ---
94 ... &hellip; \ldots
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group 'org-export-translation
98 :type 'boolean)
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents")
102 ("cs" "Autor" "Datum" "Obsah")
103 ("da" "Ophavsmand" "Dato" "Indhold")
104 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
105 ("es" "Autor" "Fecha" "\xcdndice")
106 ("fr" "Auteur" "Date" "Table des mati\xe8res")
107 ("it" "Autore" "Data" "Indice")
108 ("nl" "Auteur" "Datum" "Inhoudsopgave")
109 ("no" "Forfatter" "Dato" "Innhold")
110 ("nb" "Forfatter" "Dato" "Innhold") ;; nb = Norsk (bokm.l)
111 ("nn" "Forfattar" "Dato" "Innhald") ;; nn = Norsk (nynorsk)
112 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
113 "Terms used in export text, translated to different languages.
114 Use the variable `org-export-default-language' to set the language,
115 or use the +OPTION lines for a per-file setting."
116 :group 'org-export-general
117 :type '(repeat
118 (list
119 (string :tag "HTML language tag")
120 (string :tag "Author")
121 (string :tag "Date")
122 (string :tag "Table of Contents"))))
124 (defcustom org-export-default-language "en"
125 "The default language of HTML export, as a string.
126 This should have an association in `org-export-language-setup'."
127 :group 'org-export-general
128 :type 'string)
130 (defcustom org-export-skip-text-before-1st-heading nil
131 "Non-nil means, skip all text before the first headline when exporting.
132 When nil, that text is exported as well."
133 :group 'org-export-general
134 :type 'boolean)
136 (defcustom org-export-headline-levels 3
137 "The last level which is still exported as a headline.
138 Inferior levels will produce itemize lists when exported.
139 Note that a numeric prefix argument to an exporter function overrides
140 this setting.
142 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
143 :group 'org-export-general
144 :type 'number)
146 (defcustom org-export-with-section-numbers t
147 "Non-nil means, add section numbers to headlines when exporting.
149 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
150 :group 'org-export-general
151 :type 'boolean)
153 (defcustom org-export-section-number-format '((("1" ".")) . "")
154 "Format of section numbers for export.
155 The variable has two components.
156 1. A list of lists, each indicating a counter type and a separator.
157 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
158 It causes causes numeric, alphabetic, or roman counters, respectively.
159 The separator is only used if another counter for a subsection is being
160 added.
161 If there are more numbered section levels than entries in this lists,
162 then the last entry will be reused.
163 2. A terminator string that will be added after the entire
164 section number."
165 :group 'org-export-general
166 :type '(cons
167 (repeat
168 (list
169 (string :tag "Counter Type")
170 (string :tag "Separator ")))
171 (string :tag "Terminator")))
173 (defcustom org-export-with-toc t
174 "Non-nil means, create a table of contents in exported files.
175 The TOC contains headlines with levels up to`org-export-headline-levels'.
176 When an integer, include levels up to N in the toc, this may then be
177 different from `org-export-headline-levels', but it will not be allowed
178 to be larger than the number of headline levels.
179 When nil, no table of contents is made.
181 Headlines which contain any TODO items will be marked with \"(*)\" in
182 ASCII export, and with red color in HTML output, if the option
183 `org-export-mark-todo-in-toc' is set.
185 In HTML output, the TOC will be clickable.
187 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
188 or \"toc:3\"."
189 :group 'org-export-general
190 :type '(choice
191 (const :tag "No Table of Contents" nil)
192 (const :tag "Full Table of Contents" t)
193 (integer :tag "TOC to level")))
195 (defcustom org-export-mark-todo-in-toc nil
196 "Non-nil means, mark TOC lines that contain any open TODO items."
197 :group 'org-export-general
198 :type 'boolean)
200 (defcustom org-export-preserve-breaks nil
201 "Non-nil means, preserve all line breaks when exporting.
202 Normally, in HTML output paragraphs will be reformatted. In ASCII
203 export, line breaks will always be preserved, regardless of this variable.
205 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
206 :group 'org-export-general
207 :type 'boolean)
209 (defcustom org-export-with-archived-trees 'headline
210 "Whether subtrees with the ARCHIVE tag should be exported.
211 This can have three different values
212 nil Do not export, pretend this tree is not present
213 t Do export the entire tree
214 headline Only export the headline, but skip the tree below it."
215 :group 'org-export-general
216 :group 'org-archive
217 :type '(choice
218 (const :tag "not at all" nil)
219 (const :tag "headline only" 'headline)
220 (const :tag "entirely" t)))
222 (defcustom org-export-author-info t
223 "Non-nil means, insert author name and email into the exported file.
225 This option can also be set with the +OPTIONS line,
226 e.g. \"author-info:nil\"."
227 :group 'org-export-general
228 :type 'boolean)
230 (defcustom org-export-creator-info t
231 "Non-nil means, the postamle should contain a creator sentence.
232 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
233 :group 'org-export-general
234 :type 'boolean)
236 (defcustom org-export-time-stamp-file t
237 "Non-nil means, insert a time stamp into the exported file.
238 The time stamp shows when the file was created.
240 This option can also be set with the +OPTIONS line,
241 e.g. \"timestamp:nil\"."
242 :group 'org-export-general
243 :type 'boolean)
245 (defcustom org-export-with-timestamps t
246 "If nil, do not export time stamps and associated keywords."
247 :group 'org-export-general
248 :type 'boolean)
250 (defcustom org-export-remove-timestamps-from-toc t
251 "If nil, remove timestamps from the table of contents entries."
252 :group 'org-export-general
253 :type 'boolean)
255 (defcustom org-export-with-tags 'not-in-toc
256 "If nil, do not export tags, just remove them from headlines.
257 If this is the symbol `not-in-toc', tags will be removed from table of
258 contents entries, but still be shown in the headlines of the document.
260 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
261 :group 'org-export-general
262 :type '(choice
263 (const :tag "Off" nil)
264 (const :tag "Not in TOC" not-in-toc)
265 (const :tag "On" t)))
267 (defcustom org-export-with-drawers nil
268 "Non-nil means, export with drawers like the property drawer.
269 When t, all drawers are exported. This may also be a list of
270 drawer names to export."
271 :group 'org-export-general
272 :type '(choice
273 (const :tag "All drawers" t)
274 (const :tag "None" nil)
275 (repeat :tag "Selected drawers"
276 (string :tag "Drawer name"))))
278 (defvar org-export-preprocess-hook nil
279 "Hook for preprocessing an export buffer.
280 Pretty much the first thing when exporting is running this hook.")
282 (defgroup org-export-translation nil
283 "Options for translating special ascii sequences for the export backends."
284 :tag "Org Export Translation"
285 :group 'org-export)
287 (defcustom org-export-with-emphasize t
288 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
289 If the export target supports emphasizing text, the word will be
290 typeset in bold, italic, or underlined, respectively. Works only for
291 single words, but you can say: I *really* *mean* *this*.
292 Not all export backends support this.
294 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
295 :group 'org-export-translation
296 :type 'boolean)
298 (defcustom org-export-with-footnotes t
299 "If nil, export [1] as a footnote marker.
300 Lines starting with [1] will be formatted as footnotes.
302 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
303 :group 'org-export-translation
304 :type 'boolean)
306 (defcustom org-export-with-sub-superscripts t
307 "Non-nil means, interpret \"_\" and \"^\" for export.
308 When this option is turned on, you can use TeX-like syntax for sub- and
309 superscripts. Several characters after \"_\" or \"^\" will be
310 considered as a single item - so grouping with {} is normally not
311 needed. For example, the following things will be parsed as single
312 sub- or superscripts.
314 10^24 or 10^tau several digits will be considered 1 item.
315 10^-12 or 10^-tau a leading sign with digits or a word
316 x^2-y^3 will be read as x^2 - y^3, because items are
317 terminated by almost any nonword/nondigit char.
318 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
320 Still, ambiguity is possible - so when in doubt use {} to enclose the
321 sub/superscript. If you set this variable to the symbol `{}',
322 the braces are *required* in order to trigger interpretations as
323 sub/superscript. This can be helpful in documents that need \"_\"
324 frequently in plain text.
326 Not all export backends support this, but HTML does.
328 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
329 :group 'org-export-translation
330 :type '(choice
331 (const :tag "Always interpret" t)
332 (const :tag "Only with braces" {})
333 (const :tag "Never interpret" nil)))
335 (defcustom org-export-with-special-strings t
336 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
337 When this option is turned on, these strings will be exported as:
339 \\- : &shy;
340 -- : &ndash;
341 --- : &mdash;
343 Not all export backends support this, but HTML does.
345 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
346 :group 'org-export-translation
347 :type 'boolean)
349 (defcustom org-export-with-TeX-macros t
350 "Non-nil means, interpret simple TeX-like macros when exporting.
351 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
352 No only real TeX macros will work here, but the standard HTML entities
353 for math can be used as macro names as well. For a list of supported
354 names in HTML export, see the constant `org-html-entities'.
355 Not all export backends support this.
357 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
358 :group 'org-export-translation
359 :group 'org-export-latex
360 :type 'boolean)
362 (defcustom org-export-with-LaTeX-fragments nil
363 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
364 When set, the exporter will find LaTeX environments if the \\begin line is
365 the first non-white thing on a line. It will also find the math delimiters
366 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
367 display math.
369 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
370 :group 'org-export-translation
371 :group 'org-export-latex
372 :type 'boolean)
374 (defcustom org-export-with-fixed-width t
375 "Non-nil means, lines starting with \":\" will be in fixed width font.
376 This can be used to have pre-formatted text, fragments of code etc. For
377 example:
378 : ;; Some Lisp examples
379 : (while (defc cnt)
380 : (ding))
381 will be looking just like this in also HTML. See also the QUOTE keyword.
382 Not all export backends support this.
384 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
385 :group 'org-export-translation
386 :type 'boolean)
388 (defcustom org-match-sexp-depth 3
389 "Number of stacked braces for sub/superscript matching.
390 This has to be set before loading org.el to be effective."
391 :group 'org-export-translation
392 :type 'integer)
394 (defgroup org-export-tables nil
395 "Options for exporting tables in Org-mode."
396 :tag "Org Export Tables"
397 :group 'org-export)
399 (defcustom org-export-with-tables t
400 "If non-nil, lines starting with \"|\" define a table.
401 For example:
403 | Name | Address | Birthday |
404 |-------------+----------+-----------|
405 | Arthur Dent | England | 29.2.2100 |
407 Not all export backends support this.
409 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
410 :group 'org-export-tables
411 :type 'boolean)
413 (defcustom org-export-highlight-first-table-line t
414 "Non-nil means, highlight the first table line.
415 In HTML export, this means use <th> instead of <td>.
416 In tables created with table.el, this applies to the first table line.
417 In Org-mode tables, all lines before the first horizontal separator
418 line will be formatted with <th> tags."
419 :group 'org-export-tables
420 :type 'boolean)
422 (defcustom org-export-table-remove-special-lines t
423 "Remove special lines and marking characters in calculating tables.
424 This removes the special marking character column from tables that are set
425 up for spreadsheet calculations. It also removes the entire lines
426 marked with `!', `_', or `^'. The lines with `$' are kept, because
427 the values of constants may be useful to have."
428 :group 'org-export-tables
429 :type 'boolean)
431 (defcustom org-export-prefer-native-exporter-for-tables nil
432 "Non-nil means, always export tables created with table.el natively.
433 Natively means, use the HTML code generator in table.el.
434 When nil, Org-mode's own HTML generator is used when possible (i.e. if
435 the table does not use row- or column-spanning). This has the
436 advantage, that the automatic HTML conversions for math symbols and
437 sub/superscripts can be applied. Org-mode's HTML generator is also
438 much faster."
439 :group 'org-export-tables
440 :type 'boolean)
442 (defgroup org-export-ascii nil
443 "Options specific for ASCII export of Org-mode files."
444 :tag "Org Export ASCII"
445 :group 'org-export)
447 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
448 "Characters for underlining headings in ASCII export.
449 In the given sequence, these characters will be used for level 1, 2, ..."
450 :group 'org-export-ascii
451 :type '(repeat character))
453 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
454 "Bullet characters for headlines converted to lists in ASCII export.
455 The first character is used for the first lest level generated in this
456 way, and so on. If there are more levels than characters given here,
457 the list will be repeated.
458 Note that plain lists will keep the same bullets as the have in the
459 Org-mode file."
460 :group 'org-export-ascii
461 :type '(repeat character))
463 (defgroup org-export-xml nil
464 "Options specific for XML export of Org-mode files."
465 :tag "Org Export XML"
466 :group 'org-export)
468 (defgroup org-export-html nil
469 "Options specific for HTML export of Org-mode files."
470 :tag "Org Export HTML"
471 :group 'org-export)
473 (defcustom org-export-html-coding-system nil
474 "Coding system for HTML export, defaults to buffer-file-coding-system."
475 :group 'org-export-html
476 :type 'coding-system)
478 (defcustom org-export-html-extension "html"
479 "The extension for exported HTML files."
480 :group 'org-export-html
481 :type 'string)
483 (defcustom org-export-html-link-up ""
484 "Where should the \"UP\" link of exported HTML pages lead?"
485 :group 'org-export-html
486 :type '(string :tag "File or URL"))
488 (defcustom org-export-html-link-home ""
489 "Where should the \"HOME\" link of exported HTML pages lead?"
490 :group 'org-export-html
491 :type '(string :tag "File or URL"))
493 (defconst org-export-html-style-default
494 "<style type=\"text/css\">
495 html { font-family: Times, serif; font-size: 12pt; }
496 .title { text-align: center; }
497 .todo { color: red; }
498 .done { color: green; }
499 .tag { background-color:lightblue; font-weight:normal }
500 .target { }
501 .timestamp { color: grey }
502 .timestamp-kwd { color: CadetBlue }
503 p.verse { margin-left: 3% }
504 pre {
505 border: 1pt solid #AEBDCC;
506 background-color: #F3F5F7;
507 padding: 5pt;
508 font-family: courier, monospace;
509 font-size: 90%;
510 overflow:auto;
512 table { border-collapse: collapse; }
513 td, th { vertical-align: top; }
514 dt { font-weight: bold; }
516 .org-info-js_info-navigation { border-style:none; }
517 #org-info-js_console-label { font-size:10px; font-weight:bold;
518 white-space:nowrap; }
519 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
520 font-weight:bold; }
522 </style>"
523 "The default style specification for exported HTML files.
524 Please use the variables `org-export-html-style' and
525 `org-export-html-style-extra' to add to this style.")
527 (defcustom org-export-html-style ""
528 "Org-wide style definitions for exported HTML files.
530 This variable needs to contain the full HTML structure to provide a style,
531 including the surrounding HTML tags. If you set the value of this variable,
532 you should consider to include definitions for the following classes:
533 title, todo, done, timestamp, timestamp-kwd, tag, target.
535 For example, a valid value would be:
537 <style type=\"text/css\">
538 p { font-weight: normal; color: gray; }
539 h1 { color: black; }
540 .title { text-align: center; }
541 .todo, .timestamp-kwd { color: red; }
542 .done { color: green; }
543 </style>
545 If you'd like to refer to en external style file, use something like
547 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
549 As the value of this option simply gets inserted into the HTML <head> header,
550 you can \"misuse\" it to add arbitrary text to the header.
551 See also the variable `org-export-html-style-extra'."
552 :group 'org-export-html
553 :type 'string)
554 ;;;###autoload
555 (put 'org-export-html-style 'safe-local-variable 'stringp)
557 (defcustom org-export-html-style-extra ""
558 "Additional style information for HTML export.
559 The value of this variable is inserted into the HTML buffer right after
560 the value of `org-export-html-style'. Use this variable for per-file
561 settings of style information, and do not forget to surround the style
562 settings with <style>...</style> tags."
563 :group 'org-export-html
564 :type 'string)
565 ;;;###autoload
566 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
569 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
570 "Format for typesetting the document title in HTML export."
571 :group 'org-export-html
572 :type 'string)
574 (defcustom org-export-html-toplevel-hlevel 2
575 "The <H> level for level 1 headings in HTML export."
576 :group 'org-export-html
577 :type 'string)
579 (defcustom org-export-html-link-org-files-as-html t
580 "Non-nil means, make file links to `file.org' point to `file.html'.
581 When org-mode is exporting an org-mode file to HTML, links to
582 non-html files are directly put into a href tag in HTML.
583 However, links to other Org-mode files (recognized by the
584 extension `.org.) should become links to the corresponding html
585 file, assuming that the linked org-mode file will also be
586 converted to HTML.
587 When nil, the links still point to the plain `.org' file."
588 :group 'org-export-html
589 :type 'boolean)
591 (defcustom org-export-html-inline-images 'maybe
592 "Non-nil means, inline images into exported HTML pages.
593 This is done using an <img> tag. When nil, an anchor with href is used to
594 link to the image. If this option is `maybe', then images in links with
595 an empty description will be inlined, while images with a description will
596 be linked only."
597 :group 'org-export-html
598 :type '(choice (const :tag "Never" nil)
599 (const :tag "Always" t)
600 (const :tag "When there is no description" maybe)))
602 ;; FIXME: rename
603 (defcustom org-export-html-expand t
604 "Non-nil means, for HTML export, treat @<...> as HTML tag.
605 When nil, these tags will be exported as plain text and therefore
606 not be interpreted by a browser.
608 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
609 :group 'org-export-html
610 :type 'boolean)
612 (defcustom org-export-html-table-tag
613 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
614 "The HTML tag that is used to start a table.
615 This must be a <table> tag, but you may change the options like
616 borders and spacing."
617 :group 'org-export-html
618 :type 'string)
620 (defcustom org-export-table-header-tags '("<th>" . "</th>")
621 "The opening tag for table header fields.
622 This is customizable so that alignment options can be specified."
623 :group 'org-export-tables
624 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
626 (defcustom org-export-table-data-tags '("<td>" . "</td>")
627 "The opening tag for table data fields.
628 This is customizable so that alignment options can be specified."
629 :group 'org-export-tables
630 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
632 (defcustom org-export-html-with-timestamp nil
633 "If non-nil, write `org-export-html-html-helper-timestamp'
634 into the exported HTML text. Otherwise, the buffer will just be saved
635 to a file."
636 :group 'org-export-html
637 :type 'boolean)
639 (defcustom org-export-html-html-helper-timestamp
640 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
641 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
642 :group 'org-export-html
643 :type 'string)
645 (defgroup org-export-htmlize nil
646 "Options for processing examples with htmlize.el."
647 :tag "Org Export Htmlize"
648 :group 'org-export-html)
650 (defcustom org-export-htmlize-output-type 'inline-css
651 "Output type to be used by htmlize when formatting code snippets.
652 Normally this is `inline-css', but if you have defined to appropriate
653 classes in your css style file, setting this to `css' means that the
654 fontification will use the class names.
655 See also the function `org-export-htmlize-generate-css'."
656 :group 'org-export-htmlize
657 :type '(choice (const css) (const inline-css)))
659 (defcustom org-export-htmlize-css-font-prefix "org-"
660 "The prefix for CSS class names for htmlize font specifications."
661 :group 'org-export-htmlize
662 :type 'string)
664 (defgroup org-export-icalendar nil
665 "Options specific for iCalendar export of Org-mode files."
666 :tag "Org Export iCalendar"
667 :group 'org-export)
669 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
670 "The file name for the iCalendar file covering all agenda files.
671 This file is created with the command \\[org-export-icalendar-all-agenda-files].
672 The file name should be absolute, the file will be overwritten without warning."
673 :group 'org-export-icalendar
674 :type 'file)
676 (defcustom org-icalendar-combined-name "OrgMode"
677 "Calendar name for the combined iCalendar representing all agenda files."
678 :group 'org-export-icalendar
679 :type 'string)
681 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
682 "Contexts where iCalendar export should use a deadline time stamp.
683 This is a list with several symbols in it. Valid symbol are:
685 event-if-todo Deadlines in TODO entries become calendar events.
686 event-if-not-todo Deadlines in non-TODO entries become calendar events.
687 todo-due Use deadlines in TODO entries as due-dates"
688 :group 'org-export-icalendar
689 :type '(set :greedy t
690 (const :tag "Deadlines in non-TODO entries become events"
691 event-if-not-todo)
692 (const :tag "Deadline in TODO entries become events"
693 event-if-todo)
694 (const :tag "Deadlines in TODO entries become due-dates"
695 todo-due)))
697 (defcustom org-icalendar-use-scheduled '(todo-start)
698 "Contexts where iCalendar export should use a scheduling time stamp.
699 This is a list with several symbols in it. Valid symbol are:
701 event-if-todo Scheduling time stamps in TODO entries become an event.
702 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
703 todo-start Scheduling time stamps in TODO entries become start date.
704 Some calendar applications show TODO entries only after
705 that date."
706 :group 'org-export-icalendar
707 :type '(set :greedy t
708 (const :tag
709 "SCHEDULED timestamps in non-TODO entries become events"
710 event-if-not-todo)
711 (const :tag "SCHEDULED timestamps in TODO entries become events"
712 event-if-todo)
713 (const :tag "SCHEDULED in TODO entries become start date"
714 todo-start)))
716 (defcustom org-icalendar-categories '(local-tags category)
717 "Items that should be entered into the categories field.
718 This is a list of symbols, the following are valid:
720 category The Org-mode category of the current file or tree
721 todo-state The todo state, if any
722 local-tags The tags, defined in the current line
723 all-tags All tags, including inherited ones."
724 :group 'org-export-icalendar
725 :type '(repeat
726 (choice
727 (const :tag "The file or tree category" category)
728 (const :tag "The TODO state" todo-state)
729 (const :tag "Tags defined in current line" local-tags)
730 (const :tag "All tags, including inherited ones" all-tags))))
732 (defcustom org-icalendar-include-todo nil
733 "Non-nil means, export to iCalendar files should also cover TODO items."
734 :group 'org-export-icalendar
735 :type '(choice
736 (const :tag "None" nil)
737 (const :tag "Unfinished" t)
738 (const :tag "All" all)))
740 (defcustom org-icalendar-include-sexps t
741 "Non-nil means, export to iCalendar files should also cover sexp entries.
742 These are entries like in the diary, but directly in an Org-mode file."
743 :group 'org-export-icalendar
744 :type 'boolean)
746 (defcustom org-icalendar-include-body 100
747 "Amount of text below headline to be included in iCalendar export.
748 This is a number of characters that should maximally be included.
749 Properties, scheduling and clocking lines will always be removed.
750 The text will be inserted into the DESCRIPTION field."
751 :group 'org-export-icalendar
752 :type '(choice
753 (const :tag "Nothing" nil)
754 (const :tag "Everything" t)
755 (integer :tag "Max characters")))
757 (defcustom org-icalendar-store-UID nil
758 "Non-nil means, store any created UIDs in properties.
759 The iCalendar standard requires that all entries have a unique identifyer.
760 Org will create these identifiers as needed. When this variable is non-nil,
761 the created UIDs will be stored in the ID property of the entry. Then the
762 next time this entry is exported, it will be exported with the same UID,
763 superceeding the previous form of it. This is essential for
764 synchronization services.
765 This variable is not turned on by default because we want to avoid creating
766 a property drawer in every entry if people are only playing with this feature,
767 or if they are only using it locally."
768 :group 'org-export-icalendar
769 :type 'boolean)
771 ;;;; Exporting
773 ;;; Variables, constants, and parameter plists
775 (defconst org-level-max 20)
777 (defvar org-export-html-preamble nil
778 "Preamble, to be inserted just before <body>. Set by publishing functions.")
779 (defvar org-export-html-postamble nil
780 "Preamble, to be inserted just after </body>. Set by publishing functions.")
781 (defvar org-export-html-auto-preamble t
782 "Should default preamble be inserted? Set by publishing functions.")
783 (defvar org-export-html-auto-postamble t
784 "Should default postamble be inserted? Set by publishing functions.")
785 (defvar org-current-export-file nil) ; dynamically scoped parameter
786 (defvar org-current-export-dir nil) ; dynamically scoped parameter
788 (defconst org-export-plist-vars
789 '((:link-up . org-export-html-link-up)
790 (:link-home . org-export-html-link-home)
791 (:language . org-export-default-language)
792 (:customtime . org-display-custom-times)
793 (:headline-levels . org-export-headline-levels)
794 (:section-numbers . org-export-with-section-numbers)
795 (:section-number-format . org-export-section-number-format)
796 (:table-of-contents . org-export-with-toc)
797 (:preserve-breaks . org-export-preserve-breaks)
798 (:archived-trees . org-export-with-archived-trees)
799 (:emphasize . org-export-with-emphasize)
800 (:sub-superscript . org-export-with-sub-superscripts)
801 (:special-strings . org-export-with-special-strings)
802 (:footnotes . org-export-with-footnotes)
803 (:drawers . org-export-with-drawers)
804 (:tags . org-export-with-tags)
805 (:TeX-macros . org-export-with-TeX-macros)
806 (:LaTeX-fragments . org-export-with-LaTeX-fragments)
807 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
808 (:fixed-width . org-export-with-fixed-width)
809 (:timestamps . org-export-with-timestamps)
810 (:author-info . org-export-author-info)
811 (:creator-info . org-export-creator-info)
812 (:time-stamp-file . org-export-time-stamp-file)
813 (:tables . org-export-with-tables)
814 (:table-auto-headline . org-export-highlight-first-table-line)
815 (:style . org-export-html-style)
816 (:style-extra . org-export-html-style-extra)
817 (:agenda-style . org-agenda-export-html-style)
818 (:convert-org-links . org-export-html-link-org-files-as-html)
819 (:inline-images . org-export-html-inline-images)
820 (:html-extension . org-export-html-extension)
821 (:html-table-tag . org-export-html-table-tag)
822 (:expand-quoted-html . org-export-html-expand)
823 (:timestamp . org-export-html-with-timestamp)
824 (:publishing-directory . org-export-publishing-directory)
825 (:preamble . org-export-html-preamble)
826 (:postamble . org-export-html-postamble)
827 (:auto-preamble . org-export-html-auto-preamble)
828 (:auto-postamble . org-export-html-auto-postamble)
829 (:author . user-full-name)
830 (:email . user-mail-address)
831 (:select-tags . org-export-select-tags)
832 (:exclude-tags . org-export-exclude-tags)))
834 (defun org-default-export-plist ()
835 "Return the property list with default settings for the export variables."
836 (let ((l org-export-plist-vars) rtn e)
837 (while (setq e (pop l))
838 (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
839 rtn))
841 (defvar org-export-inbuffer-options-extra nil
842 "List of additional in-buffer options that should be detected.
843 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
844 etc. Extensions can add to this list to get their options detected, and they
845 can then add a function to `org-export-options-filters' to process these
846 options.
847 Each element in this list must be a list, with the in-buffer keyword as car,
848 and a property (a symbol) as the next element. All occurences of the
849 keyword will be found, the values concatenated with a space character
850 in between, and the result stored in the export options property list.")
852 (defvar org-export-options-filters nil
853 "Functions to be called to finalize the export/publishing options.
854 All these options are stored in a property list, and each of the functions
855 in this hook gets a chance to modify this property list. Each function
856 must accept the property list as an argument, and must return the (possibly
857 modified) list.")
859 (defun org-infile-export-plist ()
860 "Return the property list with file-local settings for export."
861 (save-excursion
862 (save-restriction
863 (widen)
864 (goto-char (point-min))
865 (let ((re (org-make-options-regexp
866 (append
867 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
868 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
869 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
870 (mapcar 'car org-export-inbuffer-options-extra))))
871 p key val text options js-up js-main js-css js-opt a pr
872 ext-setup-or-nil setup-contents (start 0))
873 (while (or (and ext-setup-or-nil
874 (string-match re ext-setup-or-nil start)
875 (setq start (match-end 0)))
876 (and (setq ext-setup-or-nil nil start 0)
877 (re-search-forward re nil t)))
878 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
879 val (org-match-string-no-properties 2 ext-setup-or-nil))
880 (cond
881 ((setq a (assoc key org-export-inbuffer-options-extra))
882 (setq pr (nth 1 a))
883 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
884 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
885 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
886 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
887 ((string-equal key "DATE") (setq p (plist-put p :date val)))
888 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
889 ((string-equal key "STYLE") (setq p (plist-put p :style-extra val)))
890 ((string-equal key "TEXT")
891 (setq text (if text (concat text "\n" val) val)))
892 ((string-equal key "OPTIONS")
893 (setq options (concat val " " options)))
894 ((string-equal key "LINK_UP")
895 (setq p (plist-put p :link-up val)))
896 ((string-equal key "LINK_HOME")
897 (setq p (plist-put p :link-home val)))
898 ((string-equal key "EXPORT_SELECT_TAGS")
899 (setq p (plist-put p :select-tags (org-split-string val))))
900 ((string-equal key "EXPORT_EXCLUDE_TAGS")
901 (setq p (plist-put p :exclude-tags (org-split-string val))))
902 ((equal key "SETUPFILE")
903 (setq setup-contents (org-file-contents
904 (expand-file-name
905 (org-remove-double-quotes
906 (org-trim val)))
907 'noerror))
908 (if (not ext-setup-or-nil)
909 (setq ext-setup-or-nil setup-contents start 0)
910 (setq ext-setup-or-nil
911 (concat (substring ext-setup-or-nil 0 start)
912 "\n" setup-contents "\n"
913 (substring ext-setup-or-nil start)))))))
914 (setq p (plist-put p :text text))
915 (when options
916 (setq p (org-export-add-options-to-plist p options)))
917 p))))
919 (defun org-export-add-options-to-plist (p options)
920 "Parse an OPTONS line and set values in the property list P."
921 (let (o)
922 (when options
923 (let ((op '(("H" . :headline-levels)
924 ("num" . :section-numbers)
925 ("toc" . :table-of-contents)
926 ("\\n" . :preserve-breaks)
927 ("@" . :expand-quoted-html)
928 (":" . :fixed-width)
929 ("|" . :tables)
930 ("^" . :sub-superscript)
931 ("-" . :special-strings)
932 ("f" . :footnotes)
933 ("d" . :drawers)
934 ("tags" . :tags)
935 ("*" . :emphasize)
936 ("TeX" . :TeX-macros)
937 ("LaTeX" . :LaTeX-fragments)
938 ("skip" . :skip-before-1st-heading)
939 ("author" . :author-info)
940 ("creator" . :creator-info)
941 ("timestamp" . :time-stamp-file)))
943 (while (setq o (pop op))
944 (if (string-match (concat (regexp-quote (car o))
945 ":\\([^ \t\n\r;,.]*\\)")
946 options)
947 (setq p (plist-put p (cdr o)
948 (car (read-from-string
949 (match-string 1 options))))))))))
952 (defun org-export-add-subtree-options (p pos)
953 "Add options in subtree at position POS to property list P."
954 (save-excursion
955 (goto-char pos)
956 (when (org-at-heading-p)
957 (let (a)
958 ;; This is actually read in `org-export-get-title-from-subtree'
959 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
960 ;; (setq p (plist-put p :title a)))
961 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
962 (setq p (plist-put p :text a)))
963 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
964 (setq p (org-export-add-options-to-plist p a)))))
967 (defun org-export-directory (type plist)
968 (let* ((val (plist-get plist :publishing-directory))
969 (dir (if (listp val)
970 (or (cdr (assoc type val)) ".")
971 val)))
972 dir))
974 (defun org-export-process-option-filters (plist)
975 (let ((functions org-export-options-filters) f)
976 (while (setq f (pop functions))
977 (setq plist (funcall f plist))))
978 plist)
980 ;;;###autoload
981 (defun org-export (&optional arg)
982 "Export dispatcher for Org-mode.
983 When `org-export-run-in-background' is non-nil, try to run the command
984 in the background. This will be done only for commands that write
985 to a file. For details see the docstring of `org-export-run-in-background'.
987 The prefix argument ARG will be passed to the exporter. However, if
988 ARG is a double universal prefix `C-u C-u', that means to inverse the
989 value of `org-export-run-in-background'."
990 (interactive "P")
991 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
992 (help "[t] insert the export option template
993 \[v] limit export to visible part of outline tree
995 \[a] export as ASCII
997 \[h] export as HTML
998 \[H] export as HTML to temporary buffer
999 \[R] export region as HTML
1000 \[b] export as HTML and browse immediately
1001 \[x] export as XOXO
1003 \[l] export as LaTeX
1004 \[L] export as LaTeX to temporary buffer
1006 \[i] export current file as iCalendar file
1007 \[I] export all agenda files as iCalendar files
1008 \[c] export agenda files into combined iCalendar file
1010 \[F] publish current file
1011 \[P] publish current project
1012 \[X] publish... (project will be prompted for)
1013 \[A] publish all projects")
1014 (cmds
1015 '((?t org-insert-export-options-template nil)
1016 (?v org-export-visible nil)
1017 (?a org-export-as-ascii t)
1018 (?h org-export-as-html t)
1019 (?b org-export-as-html-and-open t)
1020 (?H org-export-as-html-to-buffer nil)
1021 (?R org-export-region-as-html nil)
1022 (?x org-export-as-xoxo t)
1023 (?l org-export-as-latex t)
1024 (?L org-export-as-latex-to-buffer nil)
1025 (?i org-export-icalendar-this-file t)
1026 (?I org-export-icalendar-all-agenda-files t)
1027 (?c org-export-icalendar-combine-agenda-files t)
1028 (?F org-publish-current-file t)
1029 (?P org-publish-current-project t)
1030 (?X org-publish t)
1031 (?A org-publish-all t)))
1032 r1 r2 ass)
1033 (save-window-excursion
1034 (delete-other-windows)
1035 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1036 (princ help))
1037 (message "Select command: ")
1038 (setq r1 (read-char-exclusive)))
1039 (setq r2 (if (< r1 27) (+ r1 96) r1))
1040 (unless (setq ass (assq r2 cmds))
1041 (error "No command associated with key %c" r1))
1042 (if (and bg (nth 2 ass))
1043 ;; execute in background
1044 (let ((p (start-process
1045 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1046 "*Org Processes*"
1047 (expand-file-name invocation-name invocation-directory)
1048 "-batch"
1049 "-l" user-init-file
1050 "--eval" "(require 'org-exp)"
1051 "--eval" "(setq org-wait .2)"
1052 (buffer-file-name)
1053 "-f" (symbol-name (nth 1 ass)))))
1054 (set-process-sentinel p 'org-export-process-sentinel)
1055 (message "Background process \"%s\": started" p))
1056 ;; background processing not requested, or not possible
1057 (call-interactively (nth 1 ass)))))
1059 (defun org-export-process-sentinel (process status)
1060 (if (string-match "\n+\\'" status)
1061 (setq status (substring status 0 -1)))
1062 (message "Background process \"%s\": %s" process status))
1064 (defconst org-html-entities
1065 '(("nbsp")
1066 ("iexcl")
1067 ("cent")
1068 ("pound")
1069 ("curren")
1070 ("yen")
1071 ("brvbar")
1072 ("vert" . "&#124;")
1073 ("sect")
1074 ("uml")
1075 ("copy")
1076 ("ordf")
1077 ("laquo")
1078 ("not")
1079 ("shy")
1080 ("reg")
1081 ("macr")
1082 ("deg")
1083 ("plusmn")
1084 ("sup2")
1085 ("sup3")
1086 ("acute")
1087 ("micro")
1088 ("para")
1089 ("middot")
1090 ("odot"."o")
1091 ("star"."*")
1092 ("cedil")
1093 ("sup1")
1094 ("ordm")
1095 ("raquo")
1096 ("frac14")
1097 ("frac12")
1098 ("frac34")
1099 ("iquest")
1100 ("Agrave")
1101 ("Aacute")
1102 ("Acirc")
1103 ("Atilde")
1104 ("Auml")
1105 ("Aring") ("AA"."&Aring;")
1106 ("AElig")
1107 ("Ccedil")
1108 ("Egrave")
1109 ("Eacute")
1110 ("Ecirc")
1111 ("Euml")
1112 ("Igrave")
1113 ("Iacute")
1114 ("Icirc")
1115 ("Iuml")
1116 ("ETH")
1117 ("Ntilde")
1118 ("Ograve")
1119 ("Oacute")
1120 ("Ocirc")
1121 ("Otilde")
1122 ("Ouml")
1123 ("times")
1124 ("Oslash")
1125 ("Ugrave")
1126 ("Uacute")
1127 ("Ucirc")
1128 ("Uuml")
1129 ("Yacute")
1130 ("THORN")
1131 ("szlig")
1132 ("agrave")
1133 ("aacute")
1134 ("acirc")
1135 ("atilde")
1136 ("auml")
1137 ("aring")
1138 ("aelig")
1139 ("ccedil")
1140 ("egrave")
1141 ("eacute")
1142 ("ecirc")
1143 ("euml")
1144 ("igrave")
1145 ("iacute")
1146 ("icirc")
1147 ("iuml")
1148 ("eth")
1149 ("ntilde")
1150 ("ograve")
1151 ("oacute")
1152 ("ocirc")
1153 ("otilde")
1154 ("ouml")
1155 ("divide")
1156 ("oslash")
1157 ("ugrave")
1158 ("uacute")
1159 ("ucirc")
1160 ("uuml")
1161 ("yacute")
1162 ("thorn")
1163 ("yuml")
1164 ("fnof")
1165 ("Alpha")
1166 ("Beta")
1167 ("Gamma")
1168 ("Delta")
1169 ("Epsilon")
1170 ("Zeta")
1171 ("Eta")
1172 ("Theta")
1173 ("Iota")
1174 ("Kappa")
1175 ("Lambda")
1176 ("Mu")
1177 ("Nu")
1178 ("Xi")
1179 ("Omicron")
1180 ("Pi")
1181 ("Rho")
1182 ("Sigma")
1183 ("Tau")
1184 ("Upsilon")
1185 ("Phi")
1186 ("Chi")
1187 ("Psi")
1188 ("Omega")
1189 ("alpha")
1190 ("beta")
1191 ("gamma")
1192 ("delta")
1193 ("epsilon")
1194 ("varepsilon"."&epsilon;")
1195 ("zeta")
1196 ("eta")
1197 ("theta")
1198 ("iota")
1199 ("kappa")
1200 ("lambda")
1201 ("mu")
1202 ("nu")
1203 ("xi")
1204 ("omicron")
1205 ("pi")
1206 ("rho")
1207 ("sigmaf") ("varsigma"."&sigmaf;")
1208 ("sigma")
1209 ("tau")
1210 ("upsilon")
1211 ("phi")
1212 ("chi")
1213 ("psi")
1214 ("omega")
1215 ("thetasym") ("vartheta"."&thetasym;")
1216 ("upsih")
1217 ("piv")
1218 ("bull") ("bullet"."&bull;")
1219 ("hellip") ("dots"."&hellip;")
1220 ("prime")
1221 ("Prime")
1222 ("oline")
1223 ("frasl")
1224 ("weierp")
1225 ("image")
1226 ("real")
1227 ("trade")
1228 ("alefsym")
1229 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1230 ("uarr") ("uparrow"."&uarr;")
1231 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1232 ("darr")("downarrow"."&darr;")
1233 ("harr") ("leftrightarrow"."&harr;")
1234 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1235 ("lArr") ("Leftarrow"."&lArr;")
1236 ("uArr") ("Uparrow"."&uArr;")
1237 ("rArr") ("Rightarrow"."&rArr;")
1238 ("dArr") ("Downarrow"."&dArr;")
1239 ("hArr") ("Leftrightarrow"."&hArr;")
1240 ("forall")
1241 ("part") ("partial"."&part;")
1242 ("exist") ("exists"."&exist;")
1243 ("empty") ("emptyset"."&empty;")
1244 ("nabla")
1245 ("isin") ("in"."&isin;")
1246 ("notin")
1247 ("ni")
1248 ("prod")
1249 ("sum")
1250 ("minus")
1251 ("lowast") ("ast"."&lowast;")
1252 ("radic")
1253 ("prop") ("proptp"."&prop;")
1254 ("infin") ("infty"."&infin;")
1255 ("ang") ("angle"."&ang;")
1256 ("and") ("wedge"."&and;")
1257 ("or") ("vee"."&or;")
1258 ("cap")
1259 ("cup")
1260 ("int")
1261 ("there4")
1262 ("sim")
1263 ("cong") ("simeq"."&cong;")
1264 ("asymp")("approx"."&asymp;")
1265 ("ne") ("neq"."&ne;")
1266 ("equiv")
1267 ("le")
1268 ("ge")
1269 ("sub") ("subset"."&sub;")
1270 ("sup") ("supset"."&sup;")
1271 ("nsub")
1272 ("sube")
1273 ("supe")
1274 ("oplus")
1275 ("otimes")
1276 ("perp")
1277 ("sdot") ("cdot"."&sdot;")
1278 ("lceil")
1279 ("rceil")
1280 ("lfloor")
1281 ("rfloor")
1282 ("lang")
1283 ("rang")
1284 ("loz") ("Diamond"."&loz;")
1285 ("spades") ("spadesuit"."&spades;")
1286 ("clubs") ("clubsuit"."&clubs;")
1287 ("hearts") ("diamondsuit"."&hearts;")
1288 ("diams") ("diamondsuit"."&diams;")
1289 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1290 ("quot")
1291 ("amp")
1292 ("lt")
1293 ("gt")
1294 ("OElig")
1295 ("oelig")
1296 ("Scaron")
1297 ("scaron")
1298 ("Yuml")
1299 ("circ")
1300 ("tilde")
1301 ("ensp")
1302 ("emsp")
1303 ("thinsp")
1304 ("zwnj")
1305 ("zwj")
1306 ("lrm")
1307 ("rlm")
1308 ("ndash")
1309 ("mdash")
1310 ("lsquo")
1311 ("rsquo")
1312 ("sbquo")
1313 ("ldquo")
1314 ("rdquo")
1315 ("bdquo")
1316 ("dagger")
1317 ("Dagger")
1318 ("permil")
1319 ("lsaquo")
1320 ("rsaquo")
1321 ("euro")
1323 ("arccos"."arccos")
1324 ("arcsin"."arcsin")
1325 ("arctan"."arctan")
1326 ("arg"."arg")
1327 ("cos"."cos")
1328 ("cosh"."cosh")
1329 ("cot"."cot")
1330 ("coth"."coth")
1331 ("csc"."csc")
1332 ("deg"."deg")
1333 ("det"."det")
1334 ("dim"."dim")
1335 ("exp"."exp")
1336 ("gcd"."gcd")
1337 ("hom"."hom")
1338 ("inf"."inf")
1339 ("ker"."ker")
1340 ("lg"."lg")
1341 ("lim"."lim")
1342 ("liminf"."liminf")
1343 ("limsup"."limsup")
1344 ("ln"."ln")
1345 ("log"."log")
1346 ("max"."max")
1347 ("min"."min")
1348 ("Pr"."Pr")
1349 ("sec"."sec")
1350 ("sin"."sin")
1351 ("sinh"."sinh")
1352 ("sup"."sup")
1353 ("tan"."tan")
1354 ("tanh"."tanh")
1356 "Entities for TeX->HTML translation.
1357 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1358 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1359 In that case, \"\\ent\" will be translated to \"&other;\".
1360 The list contains HTML entities for Latin-1, Greek and other symbols.
1361 It is supplemented by a number of commonly used TeX macros with appropriate
1362 translations. There is currently no way for users to extend this.")
1364 ;;; General functions for all backends
1366 (defun org-export-preprocess-string (string &rest parameters)
1367 "Cleanup STRING so that that the true exported has a more consistent source.
1368 This function takes STRING, which should be a buffer-string of an org-file
1369 to export. It then creates a temporary buffer where it does its job.
1370 The result is then again returned as a string, and the exporter works
1371 on this string to produce the exported version."
1372 (interactive)
1373 (let* ((htmlp (plist-get parameters :for-html))
1374 (asciip (plist-get parameters :for-ascii))
1375 (latexp (plist-get parameters :for-LaTeX))
1376 (archived-trees (plist-get parameters :archived-trees))
1377 (inhibit-read-only t)
1378 (drawers org-drawers)
1379 (outline-regexp "\\*+ ")
1380 target-alist rtn)
1382 (with-current-buffer (get-buffer-create " org-mode-tmp")
1383 (erase-buffer)
1384 (insert string)
1385 (setq case-fold-search t)
1386 ;; Call the hook
1387 (run-hooks 'org-export-preprocess-hook)
1389 ;; Remove license-to-kill stuff
1390 ;; The caller markes some stuff fo killing, stuff that has been
1391 ;; used to create the page title, for example.
1392 (org-export-kill-licensed-text)
1394 (let ((org-inhibit-startup t)) (org-mode))
1395 (setq case-fold-search t)
1396 (untabify (point-min) (point-max))
1398 ;; Handle include files
1399 (org-export-handle-include-files)
1401 ;; Get rid of excluded trees
1402 (org-export-handle-export-tags (plist-get parameters :select-tags)
1403 (plist-get parameters :exclude-tags))
1405 ;; Handle source code snippets
1406 (org-export-replace-src-segments)
1408 ;; Get rid of drawers
1409 (org-export-remove-or-extract-drawers drawers
1410 (plist-get parameters :drawers))
1412 ;; Get the correct stuff before the first headline
1413 (when (plist-get parameters :skip-before-1st-heading)
1414 (goto-char (point-min))
1415 (when (re-search-forward "^\\*+[ \t]" nil t)
1416 (delete-region (point-min) (match-beginning 0))
1417 (goto-char (point-min))
1418 (insert "\n")))
1419 (when (plist-get parameters :add-text)
1420 (goto-char (point-min))
1421 (insert (plist-get parameters :add-text) "\n"))
1423 ;; Get rid of archived trees
1424 (org-export-remove-archived-trees archived-trees)
1426 ;; Find all headings and compute the targets for them
1427 (setq target-alist (org-export-define-heading-targets target-alist))
1429 ;; Find targets in comments and move them out of comments,
1430 ;; but mark them as targets that should be invisible
1431 (setq target-alist (org-export-handle-invisible-targets target-alist))
1433 ;; Protect examples
1434 (org-export-protect-examples (if asciip 'indent nil))
1436 ;; Protect backend specific stuff, throw away the others.
1437 (org-export-select-backend-specific-text
1438 (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1440 ;; Protect quoted subtrees
1441 (org-export-protect-quoted-subtrees)
1443 ;; Protect verbatim elements
1444 (org-export-protect-verbatim)
1446 ;; Blockquotes and verse
1447 (org-export-mark-blockquote-and-verse)
1449 ;; Remove comment environment and comment subtrees
1450 (org-export-remove-comment-blocks-and-subtrees)
1452 ;; Remove special table lines
1453 (when org-export-table-remove-special-lines
1454 (org-export-remove-special-table-lines))
1456 ;; Specific LaTeX stuff
1457 (when latexp
1458 (require 'org-export-latex nil)
1459 (org-export-latex-preprocess))
1461 ;; Specific ASCII stuff
1462 (when asciip
1463 (org-export-ascii-preprocess))
1465 ;; Specific HTML stuff
1466 (when htmlp
1467 (org-export-html-preprocess parameters))
1469 ;; Remove or replace comments
1470 (org-export-handle-comments (plist-get parameters :comments))
1472 ;; Find matches for radio targets and turn them into internal links
1473 (org-export-mark-radio-links)
1475 ;; Find all links that contain a newline and put them into a single line
1476 (org-export-concatenate-multiline-links)
1478 ;; Normalize links: Convert angle and plain links into bracket links
1479 ;; and expand link abbreviations
1480 (org-export-normalize-links)
1482 ;; Find all internal links. If they have a fuzzy match (i.e. not
1483 ;; a *dedicated* target match, let the link point to the
1484 ;; corresponding section.
1485 (org-export-target-internal-links target-alist)
1487 ;; Find multiline emphasis and put them into single line
1488 (when (plist-get parameters :emph-multiline)
1489 (org-export-concatenate-multiline-emphasis))
1491 (setq rtn (buffer-string)))
1492 (kill-buffer " org-mode-tmp")
1493 rtn))
1495 (defun org-export-kill-licensed-text ()
1496 "Remove all text that is marked with a :org-license-to-kill property."
1497 (let (p q)
1498 (while (setq p (text-property-any (point-min) (point-max)
1499 :org-license-to-kill t))
1500 (delete-region
1501 p (or (next-single-property-change p :org-license-to-kill)
1502 (point-max))))))
1504 (defun org-export-define-heading-targets (target-alist)
1505 "Find all headings and define the targets for them.
1506 The new targets are added to TARGET-ALIST, which is also returned."
1507 (goto-char (point-min))
1508 (org-init-section-numbers)
1509 (let ((re (concat "^" org-outline-regexp))
1510 level target)
1511 (while (re-search-forward re nil t)
1512 (setq level (org-reduced-level
1513 (save-excursion (goto-char (point-at-bol))
1514 (org-outline-level))))
1515 (setq target (org-solidify-link-text
1516 (format "sec-%s" (org-section-number level))))
1517 (push (cons target target) target-alist)
1518 (add-text-properties
1519 (point-at-bol) (point-at-eol)
1520 (list 'target target))))
1521 target-alist)
1523 (defun org-export-handle-invisible-targets (target-alist)
1524 "Find targets in comments and move them out of comments.
1525 Mark them as invisible targets."
1526 (let (target tmp)
1527 (goto-char (point-min))
1528 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1529 ;; Check if the line before or after is a headline with a target
1530 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1531 (get-text-property (point-at-bol 2) 'target)))
1532 (progn
1533 ;; use the existing target in a neighboring line
1534 (setq tmp (match-string 2))
1535 (replace-match "")
1536 (and (looking-at "\n") (delete-char 1))
1537 (push (cons (org-solidify-link-text tmp) target)
1538 target-alist))
1539 ;; Make an invisible target
1540 (replace-match "\\1(INVISIBLE)"))))
1541 target-alist)
1543 (defun org-export-target-internal-links (target-alist)
1544 "Find all internal links and assign target to them.
1545 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1546 let the link point to the corresponding section."
1547 (goto-char (point-min))
1548 (while (re-search-forward org-bracket-link-regexp nil t)
1549 (org-if-unprotected
1550 (let* ((md (match-data))
1551 (desc (match-end 2))
1552 (link (org-link-unescape (match-string 1)))
1553 (slink (org-solidify-link-text link))
1554 found props pos
1555 (target
1556 (cond
1557 ((cdr (assoc slink target-alist)))
1558 ((string-match org-link-types-re link) nil)
1559 ((or (file-name-absolute-p link)
1560 (string-match "^\\." link))
1561 nil)
1563 (save-excursion
1564 (setq found (condition-case nil (org-link-search link)
1565 (error nil)))
1566 (when (and found
1567 (or (org-on-heading-p)
1568 (not (eq found 'dedicated))))
1569 (or (get-text-property (point) 'target)
1570 (get-text-property
1571 (max (point-min)
1572 (1- (previous-single-property-change
1573 (point) 'target)))
1574 'target))))))))
1575 (when target
1576 (set-match-data md)
1577 (goto-char (match-beginning 1))
1578 (setq props (text-properties-at (point)))
1579 (delete-region (match-beginning 1) (match-end 1))
1580 (setq pos (point))
1581 (insert target)
1582 (unless desc (insert "][" link))
1583 (add-text-properties pos (point) props))))))
1585 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1586 "Remove drawers, or extract the content.
1587 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1588 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1589 whose content to keep."
1590 (unless (eq t exp-drawers)
1591 (goto-char (point-min))
1592 (let ((re (concat "^[ \t]*:\\("
1593 (mapconcat
1594 'identity
1595 (org-delete-all exp-drawers
1596 (copy-sequence all-drawers))
1597 "\\|")
1598 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1599 (while (re-search-forward re nil t)
1600 (replace-match "")))))
1602 (defun org-export-handle-export-tags (select-tags exclude-tags)
1603 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1604 Both arguments are lists of tags.
1605 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1606 will be removed.
1607 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1608 removed as well."
1609 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1610 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1611 select-tags "\\|")
1612 "\\):"))
1613 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1614 exclude-tags "\\|")
1615 "\\):"))
1616 beg end cont)
1617 (goto-char (point-min))
1618 (when (and select-tags
1619 (re-search-forward
1620 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1621 ;; At least one tree is marked for export, this means
1622 ;; all the unmarked stuff needs to go.
1623 ;; Dig out the trees that should be exported
1624 (goto-char (point-min))
1625 (outline-next-heading)
1626 (setq beg (point))
1627 (put-text-property beg (point-max) :org-delete t)
1628 (while (re-search-forward re-sel nil t)
1629 (when (org-on-heading-p)
1630 (org-back-to-heading)
1631 (remove-text-properties
1632 (max (1- (point)) (point-min))
1633 (setq cont (save-excursion (org-end-of-subtree t t)))
1634 '(:org-delete t))
1635 (while (and (org-up-heading-safe)
1636 (get-text-property (point) :org-delete))
1637 (remove-text-properties (max (1- (point)) (point-min))
1638 (point-at-eol) '(:org-delete t)))
1639 (goto-char cont))))
1640 ;; Remove the trees explicitly marked for noexport
1641 (when exclude-tags
1642 (goto-char (point-min))
1643 (while (re-search-forward re-excl nil t)
1644 (when (org-at-heading-p)
1645 (org-back-to-heading t)
1646 (setq beg (point))
1647 (org-end-of-subtree t)
1648 (delete-region beg (point)))))
1649 ;; Remove everything that is now still marked for deletion
1650 (goto-char (point-min))
1651 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1652 (setq end (or (next-single-property-change beg :org-delete)
1653 (point-max)))
1654 (delete-region beg end))))
1656 (defun org-export-remove-archived-trees (export-archived-trees)
1657 "Remove archived trees.
1658 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1659 When it is t, the entire archived tree will be exported.
1660 When it is nil the entire tree including the headline will be removed
1661 from the buffer."
1662 (let ((re-archive (concat ":" org-archive-tag ":"))
1663 a b)
1664 (when (not (eq export-archived-trees t))
1665 (goto-char (point-min))
1666 (while (re-search-forward re-archive nil t)
1667 (if (not (org-on-heading-p t))
1668 (org-end-of-subtree t)
1669 (beginning-of-line 1)
1670 (setq a (if export-archived-trees
1671 (1+ (point-at-eol)) (point))
1672 b (org-end-of-subtree t))
1673 (if (> b a) (delete-region a b)))))))
1675 (defun org-export-protect-quoted-subtrees ()
1676 "Mark quoted subtrees with the protection property."
1677 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1678 (goto-char (point-min))
1679 (while (re-search-forward re-quote nil t)
1680 (goto-char (match-beginning 0))
1681 (end-of-line 1)
1682 (add-text-properties (point) (org-end-of-subtree t)
1683 '(org-protected t)))))
1685 (defun org-export-protect-verbatim ()
1686 "Mark verbatim snippets with the protection property."
1687 (goto-char (point-min))
1688 (while (re-search-forward org-verbatim-re nil t)
1689 (add-text-properties (match-beginning 4) (match-end 4)
1690 '(org-protected t))
1691 (goto-char (1+ (match-end 4)))))
1693 (defun org-export-protect-examples (&optional indent)
1694 "Protect code that should be exported as monospaced examples."
1695 (goto-char (point-min))
1696 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1697 (goto-char (match-end 0))
1698 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1699 (insert (if indent ": " ":"))
1700 (beginning-of-line 2)))
1701 (goto-char (point-min))
1702 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1703 (add-text-properties (match-beginning 0) (match-end 0)
1704 '(org-protected t))))
1706 (defun org-export-select-backend-specific-text (backend)
1707 (let ((formatters
1708 '((html "HTML" "BEGIN_HTML" "END_HTML")
1709 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1710 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1711 fmt)
1713 (while formatters
1714 (setq fmt (pop formatters))
1715 (when (eq (car fmt) backend)
1716 ;; This is selected code, put it into the file for real
1717 (goto-char (point-min))
1718 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1719 ":[ \t]*\\(.*\\)") nil t)
1720 (replace-match "\\1" t)
1721 (add-text-properties
1722 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1723 '(org-protected t))))
1724 (goto-char (point-min))
1725 (while (re-search-forward
1726 (concat "^#\\+"
1727 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1728 (cadddr fmt) "\\>.*\n?") nil t)
1729 (if (eq (car fmt) backend)
1730 ;; yes, keep this
1731 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1732 '(org-protected t))
1733 ;; No, this is for a different backend, kill it
1734 (delete-region (match-beginning 0) (match-end 0)))))))
1736 (defun org-export-mark-blockquote-and-verse ()
1737 "Mark block quote and verse environments with special cookies.
1738 These special cookies will later be interpreted by the backend."
1739 ;; Blockquotes
1740 (goto-char (point-min))
1741 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1742 nil t)
1743 (replace-match (if (equal (downcase (match-string 1)) "end")
1744 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1745 t t))
1746 ;; Verse
1747 (goto-char (point-min))
1748 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1749 (replace-match (if (equal (downcase (match-string 1)) "end")
1750 "ORG-VERSE-END" "ORG-VERSE-START")
1751 t t)))
1753 (defun org-export-remove-comment-blocks-and-subtrees ()
1754 "Remove the comment environment, and also commented subtrees."
1755 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1756 (case-fold-search nil))
1757 ;; Remove comment environment
1758 (goto-char (point-min))
1759 (while (re-search-forward
1760 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1761 (replace-match "" t t))
1762 ;; Remove subtrees that are commented
1763 (goto-char (point-min))
1764 (while (re-search-forward re-commented nil t)
1765 (goto-char (match-beginning 0))
1766 (delete-region (point) (org-end-of-subtree t)))))
1768 (defun org-export-handle-comments (commentsp)
1769 "Remove comments, or convert to backend-specific format.
1770 COMMENTSP can be a format string for publishing comments.
1771 When it is nil, all comments will be removed."
1772 (let ((re "^#\\(.*\n?\\)")
1773 pos)
1774 (goto-char (point-min))
1775 (while (or (looking-at re)
1776 (re-search-forward re nil t))
1777 (setq pos (match-beginning 0))
1778 (if commentsp
1779 (progn (add-text-properties
1780 (match-beginning 0) (match-end 0) '(org-protected t))
1781 (replace-match (format commentsp (match-string 1)) t t))
1782 (goto-char (1+ pos))
1783 (org-if-unprotected
1784 (replace-match "")
1785 (goto-char (max (point-min) (1- pos))))))))
1787 (defun org-export-mark-radio-links ()
1788 "Find all matches for radio targets and turn them into internal links."
1789 (let ((re-radio (and org-target-link-regexp
1790 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1791 (goto-char (point-min))
1792 (when re-radio
1793 (while (re-search-forward re-radio nil t)
1794 (org-if-unprotected
1795 (replace-match "\\1[[\\2]]"))))))
1797 (defun org-export-remove-special-table-lines ()
1798 "Remove tables lines that are used for internal purposes."
1799 (goto-char (point-min))
1800 (while (re-search-forward "^[ \t]*|" nil t)
1801 (beginning-of-line 1)
1802 (if (or (looking-at "[ \t]*| *[!_^] *|")
1803 (and (looking-at ".*?| *<[0-9]+> *|")
1804 (not (looking-at ".*?| *[^ <|]"))))
1805 (delete-region (max (point-min) (1- (point-at-bol)))
1806 (point-at-eol))
1807 (end-of-line 1))))
1809 (defun org-export-normalize-links ()
1810 "Convert all links to bracket links, and expand link abbreviations."
1811 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1812 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1813 (goto-char (point-min))
1814 (while (re-search-forward re-plain-link nil t)
1815 (goto-char (1- (match-end 0)))
1816 (org-if-unprotected
1817 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1818 ":" (match-string 3) "]]")))
1819 ;; added 'org-link face to links
1820 (put-text-property 0 (length s) 'face 'org-link s)
1821 (replace-match s t t))))
1822 (goto-char (point-min))
1823 (while (re-search-forward re-angle-link nil t)
1824 (goto-char (1- (match-end 0)))
1825 (org-if-unprotected
1826 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1827 ":" (match-string 3) "]]")))
1828 (put-text-property 0 (length s) 'face 'org-link s)
1829 (replace-match s t t))))
1830 (goto-char (point-min))
1831 (while (re-search-forward org-bracket-link-regexp nil t)
1832 (goto-char (1- (match-end 0)))
1833 (org-if-unprotected
1834 (let* ((xx (save-match-data
1835 (org-link-expand-abbrev (match-string 1))))
1836 (s (concat
1837 "[[" xx "]"
1838 (if (match-end 3)
1839 (match-string 2)
1840 (concat "[" xx "]"))
1841 "]")))
1842 (put-text-property 0 (length s) 'face 'org-link s)
1843 (replace-match s t t))))))
1845 (defun org-export-concatenate-multiline-links ()
1846 "Find multi-line links and put it all into a single line.
1847 This is to make sure that the line-processing export backends
1848 can work correctly."
1849 (goto-char (point-min))
1850 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1851 (org-if-unprotected
1852 (replace-match "\\1 \\3")
1853 (goto-char (match-beginning 0)))))
1855 (defun org-export-concatenate-multiline-emphasis ()
1856 "Find multi-line emphasis and put it all into a single line.
1857 This is to make sure that the line-processing export backends
1858 can work correctly."
1859 (goto-char (point-min))
1860 (while (re-search-forward org-emph-re nil t)
1861 (if (not (= (char-after (match-beginning 3))
1862 (char-after (match-beginning 4))))
1863 (org-if-unprotected
1864 (subst-char-in-region (match-beginning 0) (match-end 0)
1865 ?\n ?\ t)
1866 (goto-char (1- (match-end 0))))
1867 (goto-char (1+ (match-beginning 0))))))
1869 (defun org-export-grab-title-from-buffer ()
1870 "Get a title for the current document, from looking at the buffer."
1871 (let ((inhibit-read-only t))
1872 (save-excursion
1873 (goto-char (point-min))
1874 (let ((end (save-excursion (outline-next-heading) (point))))
1875 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1876 ;; Mark the line so that it will not be exported as normal text.
1877 (org-unmodified
1878 (add-text-properties (match-beginning 0) (match-end 0)
1879 (list :org-license-to-kill t)))
1880 ;; Return the title string
1881 (org-trim (match-string 0)))))))
1883 (defun org-export-get-title-from-subtree ()
1884 "Return subtree title and exclude it from export."
1885 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1886 (save-excursion
1887 (goto-char rbeg)
1888 (when (and (org-at-heading-p)
1889 (>= (org-end-of-subtree t t) rend))
1890 ;; This is a subtree, we take the title from the first heading
1891 (goto-char rbeg)
1892 (looking-at org-todo-line-regexp)
1893 (setq title (match-string 3))
1894 (org-unmodified
1895 (add-text-properties (point) (1+ (point-at-eol))
1896 (list :org-license-to-kill t)))
1897 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1898 title))
1900 (defun org-solidify-link-text (s &optional alist)
1901 "Take link text and make a safe target out of it."
1902 (save-match-data
1903 (let* ((rtn
1904 (mapconcat
1905 'identity
1906 (org-split-string s "[ \t\r\n]+") "=="))
1907 (a (assoc rtn alist)))
1908 (or (cdr a) rtn))))
1910 (defun org-get-min-level (lines)
1911 "Get the minimum level in LINES."
1912 (let ((re "^\\(\\*+\\) ") l min)
1913 (catch 'exit
1914 (while (setq l (pop lines))
1915 (if (string-match re l)
1916 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1917 1)))
1919 ;; Variable holding the vector with section numbers
1920 (defvar org-section-numbers (make-vector org-level-max 0))
1922 (defun org-init-section-numbers ()
1923 "Initialize the vector for the section numbers."
1924 (let* ((level -1)
1925 (numbers (nreverse (org-split-string "" "\\.")))
1926 (depth (1- (length org-section-numbers)))
1927 (i depth) number-string)
1928 (while (>= i 0)
1929 (if (> i level)
1930 (aset org-section-numbers i 0)
1931 (setq number-string (or (car numbers) "0"))
1932 (if (string-match "\\`[A-Z]\\'" number-string)
1933 (aset org-section-numbers i
1934 (- (string-to-char number-string) ?A -1))
1935 (aset org-section-numbers i (string-to-number number-string)))
1936 (pop numbers))
1937 (setq i (1- i)))))
1939 (defun org-section-number (&optional level)
1940 "Return a string with the current section number.
1941 When LEVEL is non-nil, increase section numbers on that level."
1942 (let* ((depth (1- (length org-section-numbers)))
1943 (string "")
1944 (fmts (car org-export-section-number-format))
1945 (term (cdr org-export-section-number-format))
1946 (sep "")
1947 ctype fmt idx n)
1948 (when level
1949 (when (> level -1)
1950 (aset org-section-numbers
1951 level (1+ (aref org-section-numbers level))))
1952 (setq idx (1+ level))
1953 (while (<= idx depth)
1954 (if (not (= idx 1))
1955 (aset org-section-numbers idx 0))
1956 (setq idx (1+ idx))))
1957 (setq idx 0)
1958 (while (<= idx depth)
1959 (when (> (aref org-section-numbers idx) 0)
1960 (setq fmt (or (pop fmts) fmt)
1961 ctype (car fmt)
1962 n (aref org-section-numbers idx)
1963 string (if (> n 0)
1964 (concat string sep (org-number-to-counter n ctype))
1965 (concat string ".0"))
1966 sep (nth 1 fmt)))
1967 (setq idx (1+ idx)))
1968 (save-match-data
1969 (if (string-match "\\`\\([@0]\\.\\)+" string)
1970 (setq string (replace-match "" t nil string)))
1971 (if (string-match "\\(\\.0\\)+\\'" string)
1972 (setq string (replace-match "" t nil string))))
1973 (concat string term)))
1975 (defun org-number-to-counter (n type)
1976 "Concert number N to a string counter, according to TYPE.
1977 TYPE must be a string, any of:
1978 1 number
1979 A A,B,....
1980 a a,b,....
1981 I uppper case roman numeral
1982 i lower case roman numeral"
1983 (cond
1984 ((equal type "1") (number-to-string n))
1985 ((equal type "A") (char-to-string (+ ?A n -1)))
1986 ((equal type "a") (char-to-string (+ ?a n -1)))
1987 ((equal type "I") (org-number-to-roman n))
1988 ((equal type "i") (downcase (org-number-to-roman n)))
1989 (t (error "Invalid counter type `%s'" type))))
1991 (defun org-number-to-roman (n)
1992 "Convert integer N into a roman numeral."
1993 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1994 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1995 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1996 ( 1 . "I")))
1997 (res ""))
1998 (if (<= n 0)
1999 (number-to-string n)
2000 (while roman
2001 (if (>= n (caar roman))
2002 (setq n (- n (caar roman))
2003 res (concat res (cdar roman)))
2004 (pop roman)))
2005 res)))
2007 (org-number-to-roman 1961)
2010 ;;; Include files
2012 (defun org-export-handle-include-files ()
2013 "Include the contents of include files, with proper formatting."
2014 (let ((case-fold-search t)
2015 params file markup lang start end prefix prefix1)
2016 (goto-char (point-min))
2017 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2018 (setq params (read (concat "(" (match-string 1) ")"))
2019 prefix (org-get-and-remove-property 'params :prefix)
2020 prefix1 (org-get-and-remove-property 'params :prefix1)
2021 file (org-symname-or-string (pop params))
2022 markup (org-symname-or-string (pop params))
2023 lang (org-symname-or-string (pop params)))
2024 (delete-region (match-beginning 0) (match-end 0))
2025 (if (or (not file)
2026 (not (file-exists-p file))
2027 (not (file-readable-p file)))
2028 (insert (format "CANNOT INCLUDE FILE %s" file))
2029 (when markup
2030 (if (equal (downcase markup) "src")
2031 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2032 end "#+end_src")
2033 (setq start (format "#+begin_%s\n" markup)
2034 end (format "#+end_%s" markup))))
2035 (insert (or start ""))
2036 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2037 (or (bolp) (newline))
2038 (insert (or end ""))))))
2040 (defun org-get-file-contents (file &optional prefix prefix1)
2041 "Get the contents of FILE and return them as a string.
2042 If PREFIX is a string, prepend it to each line. If PREFIX1
2043 is a string, prepend it to the first line instead of PREFIX."
2044 (with-temp-buffer
2045 (insert-file-contents file)
2046 (when (or prefix prefix1)
2047 (goto-char (point-min))
2048 (while (not (eobp))
2049 (insert (or prefix1 prefix))
2050 (setq prefix1 nil)
2051 (beginning-of-line 2)))
2052 (buffer-string)))
2054 (defun org-get-and-remove-property (listvar prop)
2055 "Check if the value of LISTVAR contains PROP as a property.
2056 If yes, return the value of that property (i.e. the element following
2057 in the list) and remove property and value from the list in LISTVAR."
2058 (let ((list (symbol-value listvar)) m v)
2059 (when (setq m (member prop list))
2060 (setq v (nth 1 m))
2061 (if (equal (car list) prop)
2062 (set listvar (cddr list))
2063 (setcdr (nthcdr (- (length list) (length m) 1) list)
2064 (cddr m))
2065 (set listvar list)))
2068 (defun org-symname-or-string (s)
2069 (if (symbolp s)
2070 (if s (symbol-name s) s)
2073 ;;; Fontification of code
2074 ;; Currently only for the HTML backend, but who knows....
2075 (defun org-export-replace-src-segments ()
2076 "Replace source code segments with special code for export."
2077 (let ((case-fold-search t)
2078 lang code trans)
2079 (goto-char (point-min))
2080 (while (re-search-forward
2081 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2082 nil t)
2083 (setq lang (match-string 1) code (match-string 2)
2084 trans (org-export-format-source-code lang code))
2085 (replace-match trans t t))))
2087 (defvar htmlp) ;; dynamically scoped from org-exp.el
2089 (defun org-export-format-source-code (lang code)
2090 "Format CODE from language LANG and return it formatted for export.
2091 Currently, this only does something for HTML export, for all other
2092 backends, it converts the segment into an EXAMPLE segment."
2093 (save-match-data
2094 (cond
2095 (htmlp
2096 ;; We are exporting to HTML
2097 (condition-case nil (require 'htmlize) (nil t))
2098 (if (not (fboundp 'htmlize-region-for-paste))
2099 (progn
2100 ;; we do not have htmlize.el, or an old version of it
2101 (message
2102 "htmlize.el 1.34 or later is needed for source code formatting")
2103 (concat "#+BEGIN_EXAMPLE\n" code
2104 (if (string-match "\n\\'" code) "" "\n")
2105 "#+END_EXAMPLE\n"))
2106 ;; ok, we are good to go
2107 (let* ((mode (and lang (intern (concat lang "-mode"))))
2108 (org-inhibit-startup t)
2109 (org-startup-folded nil)
2110 (htmltext
2111 (with-temp-buffer
2112 (insert code)
2113 ;; Free up the protected stuff
2114 (goto-char (point-min))
2115 (while (re-search-forward "^," nil t)
2116 (replace-match "")
2117 (end-of-line 1))
2118 (if (functionp mode)
2119 (funcall mode)
2120 (fundamental-mode))
2121 (font-lock-fontify-buffer)
2122 (org-export-htmlize-region-for-paste
2123 (point-min) (point-max)))))
2124 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2125 (setq htmltext (replace-match
2126 (format "<pre class=\"src src-%s\">" lang)
2127 t t htmltext)))
2128 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2130 ;; This is not HTML, so just make it an example.
2131 (when (equal lang "org")
2132 (while (string-match "^," code)
2133 (setq code (replace-match "" t t code))))
2134 (concat "#+BEGIN_EXAMPLE\n" code
2135 (if (string-match "\n\\'" code) "" "\n")
2136 "#+END_EXAMPLE\n")))))
2138 ;;; ASCII export
2140 (defvar org-last-level nil) ; dynamically scoped variable
2141 (defvar org-min-level nil) ; dynamically scoped variable
2142 (defvar org-levels-open nil) ; dynamically scoped parameter
2143 (defvar org-ascii-current-indentation nil) ; For communication
2145 ;;;###autoload
2146 (defun org-export-as-ascii (arg)
2147 "Export the outline as a pretty ASCII file.
2148 If there is an active region, export only the region.
2149 The prefix ARG specifies how many levels of the outline should become
2150 underlined headlines. The default is 3."
2151 (interactive "P")
2152 (setq-default org-todo-line-regexp org-todo-line-regexp)
2153 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2154 (org-infile-export-plist)))
2155 (region-p (org-region-active-p))
2156 (rbeg (and region-p (region-beginning)))
2157 (rend (and region-p (region-end)))
2158 (subtree-p
2159 (when region-p
2160 (save-excursion
2161 (goto-char rbeg)
2162 (and (org-at-heading-p)
2163 (>= (org-end-of-subtree t t) rend)))))
2164 (opt-plist (if subtree-p
2165 (org-export-add-subtree-options opt-plist rbeg)
2166 opt-plist))
2167 (custom-times org-display-custom-times)
2168 (org-ascii-current-indentation '(0 . 0))
2169 (level 0) line txt
2170 (umax nil)
2171 (umax-toc nil)
2172 (case-fold-search nil)
2173 (filename (concat (file-name-as-directory
2174 (org-export-directory :ascii opt-plist))
2175 (file-name-sans-extension
2176 (or (and subtree-p
2177 (org-entry-get (region-beginning)
2178 "EXPORT_FILE_NAME" t))
2179 (file-name-nondirectory buffer-file-name)))
2180 ".txt"))
2181 (filename (if (equal (file-truename filename)
2182 (file-truename buffer-file-name))
2183 (concat filename ".txt")
2184 filename))
2185 (buffer (find-file-noselect filename))
2186 (org-levels-open (make-vector org-level-max nil))
2187 (odd org-odd-levels-only)
2188 (date (plist-get opt-plist :date))
2189 (author (plist-get opt-plist :author))
2190 (title (or (and subtree-p (org-export-get-title-from-subtree))
2191 (plist-get opt-plist :title)
2192 (and (not
2193 (plist-get opt-plist :skip-before-1st-heading))
2194 (org-export-grab-title-from-buffer))
2195 (file-name-sans-extension
2196 (file-name-nondirectory buffer-file-name))))
2197 (email (plist-get opt-plist :email))
2198 (language (plist-get opt-plist :language))
2199 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2200 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2201 (todo nil)
2202 (lang-words nil)
2203 (region
2204 (buffer-substring
2205 (if (org-region-active-p) (region-beginning) (point-min))
2206 (if (org-region-active-p) (region-end) (point-max))))
2207 (lines (org-split-string
2208 (org-export-preprocess-string
2209 region
2210 :for-ascii t
2211 :skip-before-1st-heading
2212 (plist-get opt-plist :skip-before-1st-heading)
2213 :drawers (plist-get opt-plist :drawers)
2214 :verbatim-multiline t
2215 :select-tags (plist-get opt-plist :select-tags)
2216 :exclude-tags (plist-get opt-plist :exclude-tags)
2217 :archived-trees
2218 (plist-get opt-plist :archived-trees)
2219 :add-text (plist-get opt-plist :text))
2220 "\n"))
2221 thetoc have-headings first-heading-pos
2222 table-open table-buffer)
2224 (let ((inhibit-read-only t))
2225 (org-unmodified
2226 (remove-text-properties (point-min) (point-max)
2227 '(:org-license-to-kill t))))
2229 (setq org-min-level (org-get-min-level lines))
2230 (setq org-last-level org-min-level)
2231 (org-init-section-numbers)
2233 (find-file-noselect filename)
2235 (setq lang-words (or (assoc language org-export-language-setup)
2236 (assoc "en" org-export-language-setup)))
2237 (switch-to-buffer-other-window buffer)
2238 (erase-buffer)
2239 (fundamental-mode)
2240 ;; create local variables for all options, to make sure all called
2241 ;; functions get the correct information
2242 (mapc (lambda (x)
2243 (set (make-local-variable (cdr x))
2244 (plist-get opt-plist (car x))))
2245 org-export-plist-vars)
2246 (org-set-local 'org-odd-levels-only odd)
2247 (setq umax (if arg (prefix-numeric-value arg)
2248 org-export-headline-levels))
2249 (setq umax-toc (if (integerp org-export-with-toc)
2250 (min org-export-with-toc umax)
2251 umax))
2253 ;; File header
2254 (if title (org-insert-centered title ?=))
2255 (insert "\n")
2256 (if (and (or author email)
2257 org-export-author-info)
2258 (insert (concat (nth 1 lang-words) ": " (or author "")
2259 (if email (concat " <" email ">") "")
2260 "\n")))
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 %T %Z"))))
2268 (if (and date org-export-time-stamp-file)
2269 (insert (concat (nth 2 lang-words) ": " date"\n")))
2271 (insert "\n\n")
2273 (if org-export-with-toc
2274 (progn
2275 (push (concat (nth 3 lang-words) "\n") thetoc)
2276 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2277 "\n") thetoc)
2278 (mapc '(lambda (line)
2279 (if (string-match org-todo-line-regexp
2280 line)
2281 ;; This is a headline
2282 (progn
2283 (setq have-headings t)
2284 (setq level (- (match-end 1) (match-beginning 1))
2285 level (org-tr-level level)
2286 txt (match-string 3 line)
2287 todo
2288 (or (and org-export-mark-todo-in-toc
2289 (match-beginning 2)
2290 (not (member (match-string 2 line)
2291 org-done-keywords)))
2292 ; TODO, not DONE
2293 (and org-export-mark-todo-in-toc
2294 (= level umax-toc)
2295 (org-search-todo-below
2296 line lines level))))
2297 (setq txt (org-html-expand-for-ascii txt))
2299 (while (string-match org-bracket-link-regexp txt)
2300 (setq txt
2301 (replace-match
2302 (match-string (if (match-end 2) 3 1) txt)
2303 t t txt)))
2305 (if (and (memq org-export-with-tags '(not-in-toc nil))
2306 (string-match
2307 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2308 txt))
2309 (setq txt (replace-match "" t t txt)))
2310 (if (string-match quote-re0 txt)
2311 (setq txt (replace-match "" t t txt)))
2313 (if org-export-with-section-numbers
2314 (setq txt (concat (org-section-number level)
2315 " " txt)))
2316 (if (<= level umax-toc)
2317 (progn
2318 (push
2319 (concat
2320 (make-string
2321 (* (max 0 (- level org-min-level)) 4) ?\ )
2322 (format (if todo "%s (*)\n" "%s\n") txt))
2323 thetoc)
2324 (setq org-last-level level))
2325 ))))
2326 lines)
2327 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2329 (org-init-section-numbers)
2330 (while (setq line (pop lines))
2331 ;; Remove the quoted HTML tags.
2332 (setq line (org-html-expand-for-ascii line))
2333 ;; Remove targets
2334 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2335 (setq line (replace-match "" t t line)))
2336 ;; Replace internal links
2337 (while (string-match org-bracket-link-regexp line)
2338 (setq line (replace-match
2339 (if (match-end 3) "[\\3]" "[\\1]")
2340 t nil line)))
2341 (when custom-times
2342 (setq line (org-translate-time line)))
2343 (cond
2344 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2345 ;; a Headline
2346 (setq first-heading-pos (or first-heading-pos (point)))
2347 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2348 txt (match-string 2 line))
2349 (org-ascii-level-start level txt umax lines))
2351 ((and org-export-with-tables
2352 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2353 (if (not table-open)
2354 ;; New table starts
2355 (setq table-open t table-buffer nil))
2356 ;; Accumulate lines
2357 (setq table-buffer (cons line table-buffer))
2358 (when (or (not lines)
2359 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2360 (car lines))))
2361 (setq table-open nil
2362 table-buffer (nreverse table-buffer))
2363 (insert (mapconcat
2364 (lambda (x)
2365 (org-fix-indentation x org-ascii-current-indentation))
2366 (org-format-table-ascii table-buffer)
2367 "\n") "\n")))
2369 (setq line (org-fix-indentation line org-ascii-current-indentation))
2370 (if (and org-export-with-fixed-width
2371 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2372 (setq line (replace-match "\\1" nil nil line)))
2373 (insert line "\n"))))
2375 (normal-mode)
2377 ;; insert the table of contents
2378 (when thetoc
2379 (goto-char (point-min))
2380 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2381 (progn
2382 (goto-char (match-beginning 0))
2383 (replace-match ""))
2384 (goto-char first-heading-pos))
2385 (mapc 'insert thetoc)
2386 (or (looking-at "[ \t]*\n[ \t]*\n")
2387 (insert "\n\n")))
2389 ;; Convert whitespace place holders
2390 (goto-char (point-min))
2391 (let (beg end)
2392 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2393 (setq end (next-single-property-change beg 'org-whitespace))
2394 (goto-char beg)
2395 (delete-region beg end)
2396 (insert (make-string (- end beg) ?\ ))))
2398 (save-buffer)
2399 ;; remove display and invisible chars
2400 (let (beg end)
2401 (goto-char (point-min))
2402 (while (setq beg (next-single-property-change (point) 'display))
2403 (setq end (next-single-property-change beg 'display))
2404 (delete-region beg end)
2405 (goto-char beg)
2406 (insert "=>"))
2407 (goto-char (point-min))
2408 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2409 (setq end (next-single-property-change beg 'org-cwidth))
2410 (delete-region beg end)
2411 (goto-char beg)))
2412 (goto-char (point-min))))
2414 (defun org-export-ascii-preprocess ()
2415 "Do extra work for ASCII export"
2416 (goto-char (point-min))
2417 (while (re-search-forward org-verbatim-re nil t)
2418 (goto-char (match-end 2))
2419 (backward-delete-char 1) (insert "'")
2420 (goto-char (match-beginning 2))
2421 (delete-char 1) (insert "`")
2422 (goto-char (match-end 2))))
2424 (defun org-search-todo-below (line lines level)
2425 "Search the subtree below LINE for any TODO entries."
2426 (let ((rest (cdr (memq line lines)))
2427 (re org-todo-line-regexp)
2428 line lv todo)
2429 (catch 'exit
2430 (while (setq line (pop rest))
2431 (if (string-match re line)
2432 (progn
2433 (setq lv (- (match-end 1) (match-beginning 1))
2434 todo (and (match-beginning 2)
2435 (not (member (match-string 2 line)
2436 org-done-keywords))))
2437 ; TODO, not DONE
2438 (if (<= lv level) (throw 'exit nil))
2439 (if todo (throw 'exit t))))))))
2441 (defun org-html-expand-for-ascii (line)
2442 "Handle quoted HTML for ASCII export."
2443 (if org-export-html-expand
2444 (while (string-match "@<[^<>\n]*>" line)
2445 ;; We just remove the tags for now.
2446 (setq line (replace-match "" nil nil line))))
2447 line)
2449 (defun org-insert-centered (s &optional underline)
2450 "Insert the string S centered and underline it with character UNDERLINE."
2451 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2452 (insert (make-string ind ?\ ) s "\n")
2453 (if underline
2454 (insert (make-string ind ?\ )
2455 (make-string (string-width s) underline)
2456 "\n"))))
2458 (defun org-ascii-level-start (level title umax &optional lines)
2459 "Insert a new level in ASCII export."
2460 (let (char (n (- level umax 1)) (ind 0))
2461 (if (> level umax)
2462 (progn
2463 (insert (make-string (* 2 n) ?\ )
2464 (char-to-string (nth (% n (length org-export-ascii-bullets))
2465 org-export-ascii-bullets))
2466 " " title "\n")
2467 ;; find the indentation of the next non-empty line
2468 (catch 'stop
2469 (while lines
2470 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2471 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2472 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2473 (pop lines)))
2474 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2475 (if (or (not (equal (char-before) ?\n))
2476 (not (equal (char-before (1- (point))) ?\n)))
2477 (insert "\n"))
2478 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2479 (unless org-export-with-tags
2480 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2481 (setq title (replace-match "" t t title))))
2482 (if org-export-with-section-numbers
2483 (setq title (concat (org-section-number level) " " title)))
2484 (insert title "\n" (make-string (string-width title) char) "\n")
2485 (setq org-ascii-current-indentation '(0 . 0)))))
2487 ;;;###autoload
2488 (defun org-export-visible (type arg)
2489 "Create a copy of the visible part of the current buffer, and export it.
2490 The copy is created in a temporary buffer and removed after use.
2491 TYPE is the final key (as a string) that also select the export command in
2492 the `C-c C-e' export dispatcher.
2493 As a special case, if the you type SPC at the prompt, the temporary
2494 org-mode file will not be removed but presented to you so that you can
2495 continue to use it. The prefix arg ARG is passed through to the exporting
2496 command."
2497 (interactive
2498 (list (progn
2499 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2500 (read-char-exclusive))
2501 current-prefix-arg))
2502 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2503 (error "Invalid export key"))
2504 (let* ((binding (cdr (assoc type
2505 '((?a . org-export-as-ascii)
2506 (?\C-a . org-export-as-ascii)
2507 (?b . org-export-as-html-and-open)
2508 (?\C-b . org-export-as-html-and-open)
2509 (?h . org-export-as-html)
2510 (?H . org-export-as-html-to-buffer)
2511 (?R . org-export-region-as-html)
2512 (?x . org-export-as-xoxo)))))
2513 (keepp (equal type ?\ ))
2514 (file buffer-file-name)
2515 (buffer (get-buffer-create "*Org Export Visible*"))
2516 s e)
2517 ;; Need to hack the drawers here.
2518 (save-excursion
2519 (goto-char (point-min))
2520 (while (re-search-forward org-drawer-regexp nil t)
2521 (goto-char (match-beginning 1))
2522 (or (org-invisible-p) (org-flag-drawer nil))))
2523 (with-current-buffer buffer (erase-buffer))
2524 (save-excursion
2525 (setq s (goto-char (point-min)))
2526 (while (not (= (point) (point-max)))
2527 (goto-char (org-find-invisible))
2528 (append-to-buffer buffer s (point))
2529 (setq s (goto-char (org-find-visible))))
2530 (org-cycle-hide-drawers 'all)
2531 (goto-char (point-min))
2532 (unless keepp
2533 ;; Copy all comment lines to the end, to make sure #+ settings are
2534 ;; still available for the second export step. Kind of a hack, but
2535 ;; does do the trick.
2536 (if (looking-at "#[^\r\n]*")
2537 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2538 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2539 (append-to-buffer buffer (1+ (match-beginning 0))
2540 (min (point-max) (1+ (match-end 0))))))
2541 (set-buffer buffer)
2542 (let ((buffer-file-name file)
2543 (org-inhibit-startup t))
2544 (org-mode)
2545 (show-all)
2546 (unless keepp (funcall binding arg))))
2547 (if (not keepp)
2548 (kill-buffer buffer)
2549 (switch-to-buffer-other-window buffer)
2550 (goto-char (point-min)))))
2552 (defun org-find-visible ()
2553 (let ((s (point)))
2554 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2555 (get-char-property s 'invisible)))
2557 (defun org-find-invisible ()
2558 (let ((s (point)))
2559 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2560 (not (get-char-property s 'invisible))))
2563 ;;; HTML export
2565 (defvar org-archive-location) ;; gets loades with the org-archive require.
2566 (defun org-get-current-options ()
2567 "Return a string with current options as keyword options.
2568 Does include HTML export options as well as TODO and CATEGORY stuff."
2569 (require 'org-archive)
2570 (format
2571 "#+TITLE: %s
2572 #+AUTHOR: %s
2573 #+EMAIL: %s
2574 #+DATE: %s
2575 #+LANGUAGE: %s
2576 #+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
2578 #+EXPORT_SELECT_TAGS: %s
2579 #+EXPORT_EXCUDE_TAGS: %s
2580 #+LINK_UP: %s
2581 #+LINK_HOME: %s
2582 #+CATEGORY: %s
2583 #+SEQ_TODO: %s
2584 #+TYP_TODO: %s
2585 #+PRIORITIES: %c %c %c
2586 #+DRAWERS: %s
2587 #+STARTUP: %s %s %s %s %s
2588 #+TAGS: %s
2589 #+FILETAGS: %s
2590 #+ARCHIVE: %s
2591 #+LINK: %s
2593 (buffer-name) (user-full-name) user-mail-address
2594 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2595 org-export-default-language
2596 org-export-headline-levels
2597 org-export-with-section-numbers
2598 org-export-with-toc
2599 org-export-preserve-breaks
2600 org-export-html-expand
2601 org-export-with-fixed-width
2602 org-export-with-tables
2603 org-export-with-sub-superscripts
2604 org-export-with-special-strings
2605 org-export-with-footnotes
2606 org-export-with-emphasize
2607 org-export-with-TeX-macros
2608 org-export-with-LaTeX-fragments
2609 org-export-skip-text-before-1st-heading
2610 org-export-with-drawers
2611 org-export-with-tags
2612 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2613 (mapconcat 'identity org-export-select-tags " ")
2614 (mapconcat 'identity org-export-exclude-tags " ")
2615 org-export-html-link-up
2616 org-export-html-link-home
2617 (file-name-nondirectory buffer-file-name)
2618 "TODO FEEDBACK VERIFY DONE"
2619 "Me Jason Marie DONE"
2620 org-highest-priority org-lowest-priority org-default-priority
2621 (mapconcat 'identity org-drawers " ")
2622 (cdr (assoc org-startup-folded
2623 '((nil . "showall") (t . "overview") (content . "content"))))
2624 (if org-odd-levels-only "odd" "oddeven")
2625 (if org-hide-leading-stars "hidestars" "showstars")
2626 (if org-startup-align-all-tables "align" "noalign")
2627 (cond ((eq org-log-done t) "logdone")
2628 ((equal org-log-done 'note) "lognotedone")
2629 ((not org-log-done) "nologdone"))
2630 (or (mapconcat (lambda (x)
2631 (cond
2632 ((equal '(:startgroup) x) "{")
2633 ((equal '(:endgroup) x) "}")
2634 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2635 (t (car x))))
2636 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2637 (mapconcat 'identity org-file-tags " ")
2638 org-archive-location
2639 "org file:~/org/%s.org"
2642 (defun org-export-html-preprocess (parameters)
2643 ;; Convert LaTeX fragments to images
2644 (when (plist-get parameters :LaTeX-fragments)
2645 (org-format-latex
2646 (concat "ltxpng/" (file-name-sans-extension
2647 (file-name-nondirectory
2648 org-current-export-file)))
2649 org-current-export-dir nil "Creating LaTeX image %s"))
2650 (message "Exporting..."))
2652 ;;;###autoload
2653 (defun org-insert-export-options-template ()
2654 "Insert into the buffer a template with information for exporting."
2655 (interactive)
2656 (if (not (bolp)) (newline))
2657 (let ((s (org-get-current-options)))
2658 (and (string-match "#\\+CATEGORY" s)
2659 (setq s (substring s 0 (match-beginning 0))))
2660 (insert s)))
2662 ;;;###autoload
2663 (defun org-export-as-html-and-open (arg)
2664 "Export the outline as HTML and immediately open it with a browser.
2665 If there is an active region, export only the region.
2666 The prefix ARG specifies how many levels of the outline should become
2667 headlines. The default is 3. Lower levels will become bulleted lists."
2668 (interactive "P")
2669 (org-export-as-html arg 'hidden)
2670 (org-open-file buffer-file-name))
2672 ;;;###autoload
2673 (defun org-export-as-html-batch ()
2674 "Call `org-export-as-html', may be used in batch processing as
2675 emacs --batch
2676 --load=$HOME/lib/emacs/org.el
2677 --eval \"(setq org-export-headline-levels 2)\"
2678 --visit=MyFile --funcall org-export-as-html-batch"
2679 (org-export-as-html org-export-headline-levels 'hidden))
2681 ;;;###autoload
2682 (defun org-export-as-html-to-buffer (arg)
2683 "Call `org-exort-as-html` with output to a temporary buffer.
2684 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2685 (interactive "P")
2686 (org-export-as-html arg nil nil "*Org HTML Export*")
2687 (switch-to-buffer-other-window "*Org HTML Export*"))
2689 ;;;###autoload
2690 (defun org-replace-region-by-html (beg end)
2691 "Assume the current region has org-mode syntax, and convert it to HTML.
2692 This can be used in any buffer. For example, you could write an
2693 itemized list in org-mode syntax in an HTML buffer and then use this
2694 command to convert it."
2695 (interactive "r")
2696 (let (reg html buf pop-up-frames)
2697 (save-window-excursion
2698 (if (org-mode-p)
2699 (setq html (org-export-region-as-html
2700 beg end t 'string))
2701 (setq reg (buffer-substring beg end)
2702 buf (get-buffer-create "*Org tmp*"))
2703 (with-current-buffer buf
2704 (erase-buffer)
2705 (insert reg)
2706 (org-mode)
2707 (setq html (org-export-region-as-html
2708 (point-min) (point-max) t 'string)))
2709 (kill-buffer buf)))
2710 (delete-region beg end)
2711 (insert html)))
2713 ;;;###autoload
2714 (defun org-export-region-as-html (beg end &optional body-only buffer)
2715 "Convert region from BEG to END in org-mode buffer to HTML.
2716 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2717 contents, and only produce the region of converted text, useful for
2718 cut-and-paste operations.
2719 If BUFFER is a buffer or a string, use/create that buffer as a target
2720 of the converted HTML. If BUFFER is the symbol `string', return the
2721 produced HTML as a string and leave not buffer behind. For example,
2722 a Lisp program could call this function in the following way:
2724 (setq html (org-export-region-as-html beg end t 'string))
2726 When called interactively, the output buffer is selected, and shown
2727 in a window. A non-interactive call will only return the buffer."
2728 (interactive "r\nP")
2729 (when (interactive-p)
2730 (setq buffer "*Org HTML Export*"))
2731 (let ((transient-mark-mode t) (zmacs-regions t)
2732 ext-plist rtn)
2733 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2734 (goto-char end)
2735 (set-mark (point)) ;; to activate the region
2736 (goto-char beg)
2737 (setq rtn (org-export-as-html
2738 nil nil ext-plist
2739 buffer body-only))
2740 (if (fboundp 'deactivate-mark) (deactivate-mark))
2741 (if (and (interactive-p) (bufferp rtn))
2742 (switch-to-buffer-other-window rtn)
2743 rtn)))
2745 (defvar html-table-tag nil) ; dynamically scoped into this.
2746 ;;;###autoload
2747 (defun org-export-as-html (arg &optional hidden ext-plist
2748 to-buffer body-only pub-dir)
2749 "Export the outline as a pretty HTML file.
2750 If there is an active region, export only the region. The prefix
2751 ARG specifies how many levels of the outline should become
2752 headlines. The default is 3. Lower levels will become bulleted
2753 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2754 EXT-PLIST is a property list with external parameters overriding
2755 org-mode's default settings, but still inferior to file-local
2756 settings. When TO-BUFFER is non-nil, create a buffer with that
2757 name and export to that buffer. If TO-BUFFER is the symbol
2758 `string', don't leave any buffer behind but just return the
2759 resulting HTML as a string. When BODY-ONLY is set, don't produce
2760 the file header and footer, simply return the content of
2761 <body>...</body>, without even the body tags themselves. When
2762 PUB-DIR is set, use this as the publishing directory."
2763 (interactive "P")
2765 ;; Make sure we have a file name when we need it.
2766 (when (and (not (or to-buffer body-only))
2767 (not buffer-file-name))
2768 (if (buffer-base-buffer)
2769 (org-set-local 'buffer-file-name
2770 (with-current-buffer (buffer-base-buffer)
2771 buffer-file-name))
2772 (error "Need a file name to be able to export.")))
2774 (message "Exporting...")
2775 (setq-default org-todo-line-regexp org-todo-line-regexp)
2776 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2777 (setq-default org-done-keywords org-done-keywords)
2778 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2779 (let* ((opt-plist
2780 (org-export-process-option-filters
2781 (org-combine-plists (org-default-export-plist)
2782 ext-plist
2783 (org-infile-export-plist))))
2785 (style (concat org-export-html-style-default
2786 (plist-get opt-plist :style)
2787 (plist-get opt-plist :style-extra)))
2788 (html-extension (plist-get opt-plist :html-extension))
2789 (link-validate (plist-get opt-plist :link-validation-function))
2790 valid thetoc have-headings first-heading-pos
2791 (odd org-odd-levels-only)
2792 (region-p (org-region-active-p))
2793 (rbeg (and region-p (region-beginning)))
2794 (rend (and region-p (region-end)))
2795 (subtree-p
2796 (if (plist-get opt-plist :ignore-subree-p)
2798 (when region-p
2799 (save-excursion
2800 (goto-char rbeg)
2801 (and (org-at-heading-p)
2802 (>= (org-end-of-subtree t t) rend))))))
2803 (opt-plist (if subtree-p
2804 (org-export-add-subtree-options opt-plist rbeg)
2805 opt-plist))
2806 ;; The following two are dynamically scoped into other
2807 ;; routines below.
2808 (org-current-export-dir
2809 (or pub-dir (org-export-directory :html opt-plist)))
2810 (org-current-export-file buffer-file-name)
2811 (level 0) (line "") (origline "") txt todo
2812 (umax nil)
2813 (umax-toc nil)
2814 (filename (if to-buffer nil
2815 (expand-file-name
2816 (concat
2817 (file-name-sans-extension
2818 (or (and subtree-p
2819 (org-entry-get (region-beginning)
2820 "EXPORT_FILE_NAME" t))
2821 (file-name-nondirectory buffer-file-name)))
2822 "." html-extension)
2823 (file-name-as-directory
2824 (or pub-dir (org-export-directory :html opt-plist))))))
2825 (current-dir (if buffer-file-name
2826 (file-name-directory buffer-file-name)
2827 default-directory))
2828 (buffer (if to-buffer
2829 (cond
2830 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2831 (t (get-buffer-create to-buffer)))
2832 (find-file-noselect filename)))
2833 (org-levels-open (make-vector org-level-max nil))
2834 (date (plist-get opt-plist :date))
2835 (author (plist-get opt-plist :author))
2836 (title (or (and subtree-p (org-export-get-title-from-subtree))
2837 (plist-get opt-plist :title)
2838 (and (not
2839 (plist-get opt-plist :skip-before-1st-heading))
2840 (org-export-grab-title-from-buffer))
2841 (and buffer-file-name
2842 (file-name-sans-extension
2843 (file-name-nondirectory buffer-file-name)))
2844 "UNTITLED"))
2845 (html-table-tag (plist-get opt-plist :html-table-tag))
2846 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2847 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2848 (inquote nil)
2849 (infixed nil)
2850 (inverse nil)
2851 (in-local-list nil)
2852 (local-list-type nil)
2853 (local-list-indent nil)
2854 (llt org-plain-list-ordered-item-terminator)
2855 (email (plist-get opt-plist :email))
2856 (language (plist-get opt-plist :language))
2857 (lang-words nil)
2858 (head-count 0) cnt
2859 (start 0)
2860 (coding-system (and (boundp 'buffer-file-coding-system)
2861 buffer-file-coding-system))
2862 (coding-system-for-write (or org-export-html-coding-system
2863 coding-system))
2864 (save-buffer-coding-system (or org-export-html-coding-system
2865 coding-system))
2866 (charset (and coding-system-for-write
2867 (fboundp 'coding-system-get)
2868 (coding-system-get coding-system-for-write
2869 'mime-charset)))
2870 (region
2871 (buffer-substring
2872 (if region-p (region-beginning) (point-min))
2873 (if region-p (region-end) (point-max))))
2874 (lines
2875 (org-split-string
2876 (org-export-preprocess-string
2877 region
2878 :emph-multiline t
2879 :for-html t
2880 :skip-before-1st-heading
2881 (plist-get opt-plist :skip-before-1st-heading)
2882 :drawers (plist-get opt-plist :drawers)
2883 :archived-trees
2884 (plist-get opt-plist :archived-trees)
2885 :select-tags (plist-get opt-plist :select-tags)
2886 :exclude-tags (plist-get opt-plist :exclude-tags)
2887 :add-text
2888 (plist-get opt-plist :text)
2889 :LaTeX-fragments
2890 (plist-get opt-plist :LaTeX-fragments))
2891 "[\r\n]"))
2892 table-open type
2893 table-buffer table-orig-buffer
2894 ind item-type starter didclose
2895 rpl path attr desc descp desc1 desc2 link
2896 snumber fnc item-tag
2899 (let ((inhibit-read-only t))
2900 (org-unmodified
2901 (remove-text-properties (point-min) (point-max)
2902 '(:org-license-to-kill t))))
2904 (message "Exporting...")
2906 (setq org-min-level (org-get-min-level lines))
2907 (setq org-last-level org-min-level)
2908 (org-init-section-numbers)
2910 (cond
2911 ((and date (string-match "%" date))
2912 (setq date (format-time-string date)))
2913 (date)
2914 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2916 ;; Get the language-dependent settings
2917 (setq lang-words (or (assoc language org-export-language-setup)
2918 (assoc "en" org-export-language-setup)))
2920 ;; Switch to the output buffer
2921 (set-buffer buffer)
2922 (let ((inhibit-read-only t)) (erase-buffer))
2923 (fundamental-mode)
2925 (and (fboundp 'set-buffer-file-coding-system)
2926 (set-buffer-file-coding-system coding-system-for-write))
2928 (let ((case-fold-search nil)
2929 (org-odd-levels-only odd))
2930 ;; create local variables for all options, to make sure all called
2931 ;; functions get the correct information
2932 (mapc (lambda (x)
2933 (set (make-local-variable (cdr x))
2934 (plist-get opt-plist (car x))))
2935 org-export-plist-vars)
2936 (setq umax (if arg (prefix-numeric-value arg)
2937 org-export-headline-levels))
2938 (setq umax-toc (if (integerp org-export-with-toc)
2939 (min org-export-with-toc umax)
2940 umax))
2941 (unless body-only
2942 ;; File header
2943 (insert (format
2944 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2945 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2946 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2947 lang=\"%s\" xml:lang=\"%s\">
2948 <head>
2949 <title>%s</title>
2950 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2951 <meta name=\"generator\" content=\"Org-mode\"/>
2952 <meta name=\"generated\" content=\"%s\"/>
2953 <meta name=\"author\" content=\"%s\"/>
2955 </head><body>
2957 language language (org-html-expand title)
2958 (or charset "iso-8859-1") date author style))
2960 (insert (or (plist-get opt-plist :preamble) ""))
2962 (when (plist-get opt-plist :auto-preamble)
2963 (if title (insert (format org-export-html-title-format
2964 (org-html-expand title))))))
2966 (if (and org-export-with-toc (not body-only))
2967 (progn
2968 (push (format "<h%d>%s</h%d>\n"
2969 org-export-html-toplevel-hlevel
2970 (nth 3 lang-words)
2971 org-export-html-toplevel-hlevel)
2972 thetoc)
2973 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2974 (push "<ul>\n<li>" thetoc)
2975 (setq lines
2976 (mapcar '(lambda (line)
2977 (if (string-match org-todo-line-regexp line)
2978 ;; This is a headline
2979 (progn
2980 (setq have-headings t)
2981 (setq level (- (match-end 1) (match-beginning 1))
2982 level (org-tr-level level)
2983 txt (save-match-data
2984 (org-html-expand
2985 (org-export-cleanup-toc-line
2986 (match-string 3 line))))
2987 todo
2988 (or (and org-export-mark-todo-in-toc
2989 (match-beginning 2)
2990 (not (member (match-string 2 line)
2991 org-done-keywords)))
2992 ; TODO, not DONE
2993 (and org-export-mark-todo-in-toc
2994 (= level umax-toc)
2995 (org-search-todo-below
2996 line lines level))))
2997 (if (string-match
2998 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2999 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3000 (if (string-match quote-re0 txt)
3001 (setq txt (replace-match "" t t txt)))
3002 (setq snumber (org-section-number level))
3003 (if org-export-with-section-numbers
3004 (setq txt (concat snumber " " txt)))
3005 (if (<= level (max umax umax-toc))
3006 (setq head-count (+ head-count 1)))
3007 (if (<= level umax-toc)
3008 (progn
3009 (if (> level org-last-level)
3010 (progn
3011 (setq cnt (- level org-last-level))
3012 (while (>= (setq cnt (1- cnt)) 0)
3013 (push "\n<ul>\n<li>" thetoc))
3014 (push "\n" thetoc)))
3015 (if (< level org-last-level)
3016 (progn
3017 (setq cnt (- org-last-level level))
3018 (while (>= (setq cnt (1- cnt)) 0)
3019 (push "</li>\n</ul>" thetoc))
3020 (push "\n" thetoc)))
3021 ;; Check for targets
3022 (while (string-match org-any-target-regexp line)
3023 (setq line (replace-match
3024 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3025 t t line)))
3026 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3027 (setq txt (replace-match "" t t txt)))
3028 (push
3029 (format
3030 (if todo
3031 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3032 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3033 snumber txt) thetoc)
3035 (setq org-last-level level))
3037 line)
3038 lines))
3039 (while (> org-last-level (1- org-min-level))
3040 (setq org-last-level (1- org-last-level))
3041 (push "</li>\n</ul>\n" thetoc))
3042 (push "</div>\n" thetoc)
3043 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3045 (setq head-count 0)
3046 (org-init-section-numbers)
3048 (org-open-par)
3050 (while (setq line (pop lines) origline line)
3051 (catch 'nextline
3053 ;; end of quote section?
3054 (when (and inquote (string-match "^\\*+ " line))
3055 (insert "</pre>\n")
3056 (setq inquote nil))
3057 ;; inside a quote section?
3058 (when inquote
3059 (insert (org-html-protect line) "\n")
3060 (throw 'nextline nil))
3062 ;; Fixed-width, verbatim lines (examples)
3063 (when (and org-export-with-fixed-width
3064 (string-match "^[ \t]*:\\(.*\\)" line))
3065 (when (not infixed)
3066 (setq infixed t)
3067 (insert "<pre class=\"example\">\n"))
3068 (insert (org-html-protect (match-string 1 line)) "\n")
3069 (when (or (not lines)
3070 (not (string-match "^[ \t]*\\(:.*\\)"
3071 (car lines))))
3072 (setq infixed nil)
3073 (insert "</pre>\n"))
3074 (throw 'nextline nil))
3076 ;; Protected HTML
3077 (when (get-text-property 0 'org-protected line)
3078 (let (par)
3079 (when (re-search-backward
3080 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3081 (setq par (match-string 1))
3082 (replace-match "\\2\n"))
3083 (insert line "\n")
3084 (while (and lines
3085 (not (string-match "^[ \t]*:" (car lines)))
3086 (or (= (length (car lines)) 0)
3087 (get-text-property 0 'org-protected (car lines))))
3088 (insert (pop lines) "\n"))
3089 (and par (insert "<p>\n")))
3090 (throw 'nextline nil))
3092 ;; Horizontal line
3093 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3094 (insert "\n<hr/>\n")
3095 (throw 'nextline nil))
3097 ;; Blockquotes and verse
3098 (when (equal "ORG-BLOCKQUOTE-START" line)
3099 (insert "<blockquote>\n<p>\n")
3100 (throw 'nextline nil))
3101 (when (equal "ORG-BLOCKQUOTE-END" line)
3102 (insert "</p>\n</blockquote>\n")
3103 (throw 'nextline nil))
3104 (when (equal "ORG-VERSE-START" line)
3105 (insert "\n<p class=\"verse\">\n")
3106 (setq inverse t)
3107 (throw 'nextline nil))
3108 (when (equal "ORG-VERSE-END" line)
3109 (insert "</p>\n")
3110 (setq inverse nil)
3111 (throw 'nextline nil))
3112 (when inverse
3113 (let ((i (org-get-string-indentation line)))
3114 (if (> i 0)
3115 (setq line (concat (mapconcat 'identity
3116 (make-list (* 2 i) "\\nbsp") "")
3117 " " (org-trim line))))
3118 (setq line (concat line " \\\\"))))
3120 ;; make targets to anchors
3121 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3122 (cond
3123 ((match-end 2)
3124 (setq line (replace-match
3125 (concat "@<a name=\""
3126 (org-solidify-link-text (match-string 1 line))
3127 "\">\\nbsp@</a>")
3128 t t line)))
3129 ((and org-export-with-toc (equal (string-to-char line) ?*))
3130 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3131 (setq line (replace-match
3132 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3133 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3134 t t line)))
3136 (setq line (replace-match
3137 (concat "@<a name=\""
3138 (org-solidify-link-text (match-string 1 line))
3139 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3140 t t line)))))
3142 (setq line (org-html-handle-time-stamps line))
3144 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3145 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3146 ;; Also handle sub_superscripts and checkboxes
3147 (or (string-match org-table-hline-regexp line)
3148 (setq line (org-html-expand line)))
3150 ;; Format the links
3151 (setq start 0)
3152 (while (string-match org-bracket-link-analytic-regexp line start)
3153 (setq start (match-beginning 0))
3154 (setq path (save-match-data (org-link-unescape
3155 (match-string 3 line))))
3156 (setq type (cond
3157 ((match-end 2) (match-string 2 line))
3158 ((save-match-data
3159 (or (file-name-absolute-p path)
3160 (string-match "^\\.\\.?/" path)))
3161 "file")
3162 (t "internal")))
3163 (setq path (org-extract-attributes path))
3164 (setq attr (org-attributes-to-string
3165 (get-text-property 0 'org-attributes path)))
3166 (setq desc1 (if (match-end 5) (match-string 5 line))
3167 desc2 (if (match-end 2) (concat type ":" path) path)
3168 descp (and desc1 (not (equal desc1 desc2)))
3169 desc (or desc1 desc2))
3170 ;; Make an image out of the description if that is so wanted
3171 (when (and descp (org-file-image-p desc))
3172 (save-match-data
3173 (if (string-match "^file:" desc)
3174 (setq desc (substring desc (match-end 0)))))
3175 (setq desc (concat "<img src=\"" desc "\"/>")))
3176 ;; FIXME: do we need to unescape here somewhere?
3177 (cond
3178 ((equal type "internal")
3179 (setq rpl
3180 (concat
3181 "<a href=\"#"
3182 (org-solidify-link-text
3183 (save-match-data (org-link-unescape path)) nil)
3184 "\"" attr ">" desc "</a>")))
3185 ((member type '("http" "https"))
3186 ;; standard URL, just check if we need to inline an image
3187 (if (and (or (eq t org-export-html-inline-images)
3188 (and org-export-html-inline-images (not descp)))
3189 (org-file-image-p path))
3190 (setq rpl (concat "<img src=\"" type ":" path "\"" attr "/>"))
3191 (setq link (concat type ":" path))
3192 (setq rpl (concat "<a href=\"" link "\"" attr ">"
3193 desc "</a>"))))
3194 ((member type '("ftp" "mailto" "news"))
3195 ;; standard URL
3196 (setq link (concat type ":" path))
3197 (setq rpl (concat "<a href=\"" link "\"" attr ">" desc "</a>")))
3199 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3200 ;; The link protocol has a function for format the link
3201 (setq rpl
3202 (save-match-data
3203 (funcall fnc (org-link-unescape path) desc1 'html))))
3205 ((string= type "file")
3206 ;; FILE link
3207 (let* ((filename path)
3208 (abs-p (file-name-absolute-p filename))
3209 thefile file-is-image-p search)
3210 (save-match-data
3211 (if (string-match "::\\(.*\\)" filename)
3212 (setq search (match-string 1 filename)
3213 filename (replace-match "" t nil filename)))
3214 (setq valid
3215 (if (functionp link-validate)
3216 (funcall link-validate filename current-dir)
3218 (setq file-is-image-p (org-file-image-p filename))
3219 (setq thefile (if abs-p (expand-file-name filename) filename))
3220 (when (and org-export-html-link-org-files-as-html
3221 (string-match "\\.org$" thefile))
3222 (setq thefile (concat (substring thefile 0
3223 (match-beginning 0))
3224 "." html-extension))
3225 (if (and search
3226 ;; make sure this is can be used as target search
3227 (not (string-match "^[0-9]*$" search))
3228 (not (string-match "^\\*" search))
3229 (not (string-match "^/.*/$" search)))
3230 (setq thefile (concat thefile "#"
3231 (org-solidify-link-text
3232 (org-link-unescape search)))))
3233 (when (string-match "^file:" desc)
3234 (setq desc (replace-match "" t t desc))
3235 (if (string-match "\\.org$" desc)
3236 (setq desc (replace-match "" t t desc))))))
3237 (setq rpl (if (and file-is-image-p
3238 (or (eq t org-export-html-inline-images)
3239 (and org-export-html-inline-images
3240 (not descp))))
3241 (concat "<img src=\"" thefile "\"" attr "/>")
3242 (concat "<a href=\"" thefile "\"" attr ">"
3243 desc "</a>")))
3244 (if (not valid) (setq rpl desc))))
3247 ;; just publish the path, as default
3248 (setq rpl (concat "<i>&lt;" type ":"
3249 (save-match-data (org-link-unescape path))
3250 "&gt;</i>"))))
3251 (setq line (replace-match rpl t t line)
3252 start (+ start (length rpl))))
3254 ;; TODO items
3255 (if (and (string-match org-todo-line-regexp line)
3256 (match-beginning 2))
3258 (setq line
3259 (concat (substring line 0 (match-beginning 2))
3260 "<span class=\""
3261 (if (member (match-string 2 line)
3262 org-done-keywords)
3263 "done" "todo")
3264 "\">" (match-string 2 line)
3265 "</span>" (substring line (match-end 2)))))
3267 ;; Does this contain a reference to a footnote?
3268 (when org-export-with-footnotes
3269 (setq start 0)
3270 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3271 (if (get-text-property (match-beginning 2) 'org-protected line)
3272 (setq start (match-end 2))
3273 (let ((n (match-string 2 line)))
3274 (setq line
3275 (replace-match
3276 (format
3277 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3278 (match-string 1 line) n n n)
3279 t t line))))))
3281 (cond
3282 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3283 ;; This is a headline
3284 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3285 txt (match-string 2 line))
3286 (if (string-match quote-re0 txt)
3287 (setq txt (replace-match "" t t txt)))
3288 (if (<= level (max umax umax-toc))
3289 (setq head-count (+ head-count 1)))
3290 (when in-local-list
3291 ;; Close any local lists before inserting a new header line
3292 (while local-list-type
3293 (org-close-li (car local-list-type))
3294 (insert (format "</%sl>\n" (car local-list-type)))
3295 (pop local-list-type))
3296 (setq local-list-indent nil
3297 in-local-list nil))
3298 (setq first-heading-pos (or first-heading-pos (point)))
3299 (org-html-level-start level txt umax
3300 (and org-export-with-toc (<= level umax))
3301 head-count)
3302 ;; QUOTES
3303 (when (string-match quote-re line)
3304 (insert "<pre>")
3305 (setq inquote t)))
3307 ((and org-export-with-tables
3308 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3309 (if (not table-open)
3310 ;; New table starts
3311 (setq table-open t table-buffer nil table-orig-buffer nil))
3312 ;; Accumulate lines
3313 (setq table-buffer (cons line table-buffer)
3314 table-orig-buffer (cons origline table-orig-buffer))
3315 (when (or (not lines)
3316 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3317 (car lines))))
3318 (setq table-open nil
3319 table-buffer (nreverse table-buffer)
3320 table-orig-buffer (nreverse table-orig-buffer))
3321 (org-close-par-maybe)
3322 (insert (org-format-table-html table-buffer table-orig-buffer))))
3324 ;; Normal lines
3325 (when (string-match
3326 (cond
3327 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3328 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3329 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3330 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3331 line)
3332 (setq ind (org-get-string-indentation line)
3333 item-type (if (match-beginning 4) "o" "u")
3334 starter (if (match-beginning 2)
3335 (substring (match-string 2 line) 0 -1))
3336 line (substring line (match-beginning 5))
3337 item-tag nil)
3338 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3339 (setq item-type "d"
3340 item-tag (match-string 1 line)
3341 line (substring line (match-end 0))))
3342 (when (and (not (equal item-type "d"))
3343 (not (string-match "[^ \t]" line)))
3344 ;; empty line. Pretend indentation is large.
3345 (setq ind (if org-empty-line-terminates-plain-lists
3347 (1+ (or (car local-list-indent) 1)))))
3348 (setq didclose nil)
3349 (while (and in-local-list
3350 (or (and (= ind (car local-list-indent))
3351 (not starter))
3352 (< ind (car local-list-indent))))
3353 (setq didclose t)
3354 (org-close-li (car local-list-type))
3355 (insert (format "</%sl>\n" (car local-list-type)))
3356 (pop local-list-type) (pop local-list-indent)
3357 (setq in-local-list local-list-indent))
3358 (cond
3359 ((and starter
3360 (or (not in-local-list)
3361 (> ind (car local-list-indent))))
3362 ;; Start new (level of) list
3363 (org-close-par-maybe)
3364 (insert (cond
3365 ((equal item-type "u") "<ul>\n<li>\n")
3366 ((equal item-type "o") "<ol>\n<li>\n")
3367 ((equal item-type "d")
3368 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3369 (push item-type local-list-type)
3370 (push ind local-list-indent)
3371 (setq in-local-list t))
3372 (starter
3373 ;; continue current list
3374 (org-close-li (car local-list-type))
3375 (insert (cond
3376 ((equal (car local-list-type) "d")
3377 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3378 (t "<li>\n"))))
3379 (didclose
3380 ;; we did close a list, normal text follows: need <p>
3381 (org-open-par)))
3382 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3383 (setq line
3384 (replace-match
3385 (if (equal (match-string 1 line) "X")
3386 "<b>[X]</b>"
3387 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3388 t t line))))
3390 ;; Empty lines start a new paragraph. If hand-formatted lists
3391 ;; are not fully interpreted, lines starting with "-", "+", "*"
3392 ;; also start a new paragraph.
3393 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3395 ;; Is this the start of a footnote?
3396 (when org-export-with-footnotes
3397 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3398 (org-close-par-maybe)
3399 (let ((n (match-string 1 line)))
3400 (setq line (replace-match
3401 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3402 (setq line (concat line "</p>")))))
3404 ;; Check if the line break needs to be conserved
3405 (cond
3406 ((string-match "\\\\\\\\[ \t]*$" line)
3407 (setq line (replace-match "<br/>" t t line)))
3408 (org-export-preserve-breaks
3409 (setq line (concat line "<br/>"))))
3411 (insert line "\n")))))
3413 ;; Properly close all local lists and other lists
3414 (when inquote (insert "</pre>\n"))
3415 (when in-local-list
3416 ;; Close any local lists before inserting a new header line
3417 (while local-list-type
3418 (org-close-li (car local-list-type))
3419 (insert (format "</%sl>\n" (car local-list-type)))
3420 (pop local-list-type))
3421 (setq local-list-indent nil
3422 in-local-list nil))
3423 (org-html-level-start 1 nil umax
3424 (and org-export-with-toc (<= level umax))
3425 head-count)
3426 ;; the </div> to close the last text-... div.
3427 (insert "</div>\n")
3429 (unless body-only
3430 (when (plist-get opt-plist :auto-postamble)
3431 (insert "<div id=\"postamble\">")
3432 (when (and org-export-author-info author)
3433 (insert "<p class=\"author\"> "
3434 (nth 1 lang-words) ": " author "\n")
3435 (when email
3436 (if (listp (split-string email ",+ *"))
3437 (mapc (lambda(e)
3438 (insert "<a href=\"mailto:" e "\">&lt;"
3439 e "&gt;</a>\n"))
3440 (split-string email ",+ *"))
3441 (insert "<a href=\"mailto:" email "\">&lt;"
3442 email "&gt;</a>\n")))
3443 (insert "</p>\n"))
3444 (when (and date org-export-time-stamp-file)
3445 (insert "<p class=\"date\"> "
3446 (nth 2 lang-words) ": "
3447 date "</p>\n"))
3448 (when org-export-creator-info
3449 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3450 org-version emacs-major-version)))
3451 (insert "</div>"))
3453 (if org-export-html-with-timestamp
3454 (insert org-export-html-html-helper-timestamp))
3455 (insert (or (plist-get opt-plist :postamble) ""))
3456 (insert "</body>\n</html>\n"))
3458 (unless (plist-get opt-plist :buffer-will-be-killed)
3459 (normal-mode)
3460 (if (eq major-mode default-major-mode) (html-mode)))
3462 ;; insert the table of contents
3463 (goto-char (point-min))
3464 (when thetoc
3465 (if (or (re-search-forward
3466 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3467 (re-search-forward
3468 "\\[TABLE-OF-CONTENTS\\]" nil t))
3469 (progn
3470 (goto-char (match-beginning 0))
3471 (replace-match ""))
3472 (goto-char first-heading-pos)
3473 (when (looking-at "\\s-*</p>")
3474 (goto-char (match-end 0))
3475 (insert "\n")))
3476 (insert "<div id=\"table-of-contents\">\n")
3477 (mapc 'insert thetoc)
3478 (insert "</div>\n"))
3479 ;; remove empty paragraphs and lists
3480 (goto-char (point-min))
3481 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3482 (replace-match ""))
3483 (goto-char (point-min))
3484 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3485 (replace-match ""))
3486 (goto-char (point-min))
3487 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3488 (replace-match ""))
3489 ;; Convert whitespace place holders
3490 (goto-char (point-min))
3491 (let (beg end n)
3492 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3493 (setq n (get-text-property beg 'org-whitespace)
3494 end (next-single-property-change beg 'org-whitespace))
3495 (goto-char beg)
3496 (delete-region beg end)
3497 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3498 (make-string n ?x)))))
3499 (or to-buffer (save-buffer))
3500 (goto-char (point-min))
3501 (message "Exporting... done")
3502 (if (eq to-buffer 'string)
3503 (prog1 (buffer-substring (point-min) (point-max))
3504 (kill-buffer (current-buffer)))
3505 (current-buffer)))))
3508 (defvar org-table-colgroup-info nil)
3509 (defun org-format-table-ascii (lines)
3510 "Format a table for ascii export."
3511 (if (stringp lines)
3512 (setq lines (org-split-string lines "\n")))
3513 (if (not (string-match "^[ \t]*|" (car lines)))
3514 ;; Table made by table.el - test for spanning
3515 lines
3517 ;; A normal org table
3518 ;; Get rid of hlines at beginning and end
3519 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3520 (setq lines (nreverse lines))
3521 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3522 (setq lines (nreverse lines))
3523 (when org-export-table-remove-special-lines
3524 ;; Check if the table has a marking column. If yes remove the
3525 ;; column and the special lines
3526 (setq lines (org-table-clean-before-export lines)))
3527 ;; Get rid of the vertical lines except for grouping
3528 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3529 rtn line vl1 start)
3530 (while (setq line (pop lines))
3531 (if (string-match org-table-hline-regexp line)
3532 (and (string-match "|\\(.*\\)|" line)
3533 (setq line (replace-match " \\1" t nil line)))
3534 (setq start 0 vl1 vl)
3535 (while (string-match "|" line start)
3536 (setq start (match-end 0))
3537 (or (pop vl1) (setq line (replace-match " " t t line)))))
3538 (push line rtn))
3539 (nreverse rtn))))
3541 (defun org-colgroup-info-to-vline-list (info)
3542 (let (vl new last)
3543 (while info
3544 (setq last new new (pop info))
3545 (if (or (memq last '(:end :startend))
3546 (memq new '(:start :startend)))
3547 (push t vl)
3548 (push nil vl)))
3549 (setq vl (nreverse vl))
3550 (and vl (setcar vl nil))
3551 vl))
3553 (defvar org-table-number-regexp) ; defined in org-table.el
3554 (defun org-format-table-html (lines olines)
3555 "Find out which HTML converter to use and return the HTML code."
3556 (if (stringp lines)
3557 (setq lines (org-split-string lines "\n")))
3558 (if (string-match "^[ \t]*|" (car lines))
3559 ;; A normal org table
3560 (org-format-org-table-html lines)
3561 ;; Table made by table.el - test for spanning
3562 (let* ((hlines (delq nil (mapcar
3563 (lambda (x)
3564 (if (string-match "^[ \t]*\\+-" x) x
3565 nil))
3566 lines)))
3567 (first (car hlines))
3568 (ll (and (string-match "\\S-+" first)
3569 (match-string 0 first)))
3570 (re (concat "^[ \t]*" (regexp-quote ll)))
3571 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3572 hlines))))
3573 (if (and (not spanning)
3574 (not org-export-prefer-native-exporter-for-tables))
3575 ;; We can use my own converter with HTML conversions
3576 (org-format-table-table-html lines)
3577 ;; Need to use the code generator in table.el, with the original text.
3578 (org-format-table-table-html-using-table-generate-source olines)))))
3580 (defvar org-table-number-fraction) ; defined in org-table.el
3581 (defun org-format-org-table-html (lines &optional splice)
3582 "Format a table into HTML."
3583 (require 'org-table)
3584 ;; Get rid of hlines at beginning and end
3585 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3586 (setq lines (nreverse lines))
3587 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3588 (setq lines (nreverse lines))
3589 (when org-export-table-remove-special-lines
3590 ;; Check if the table has a marking column. If yes remove the
3591 ;; column and the special lines
3592 (setq lines (org-table-clean-before-export lines)))
3594 (let ((head (and org-export-highlight-first-table-line
3595 (delq nil (mapcar
3596 (lambda (x) (string-match "^[ \t]*|-" x))
3597 (cdr lines)))))
3598 (nlines 0) fnum i
3599 tbopen line fields html gr colgropen)
3600 (if splice (setq head nil))
3601 (unless splice (push (if head "<thead>" "<tbody>") html))
3602 (setq tbopen t)
3603 (while (setq line (pop lines))
3604 (catch 'next-line
3605 (if (string-match "^[ \t]*|-" line)
3606 (progn
3607 (unless splice
3608 (push (if head "</thead>" "</tbody>") html)
3609 (if lines (push "<tbody>" html) (setq tbopen nil)))
3610 (setq head nil) ;; head ends here, first time around
3611 ;; ignore this line
3612 (throw 'next-line t)))
3613 ;; Break the line into fields
3614 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3615 (unless fnum (setq fnum (make-vector (length fields) 0)))
3616 (setq nlines (1+ nlines) i -1)
3617 (push (concat "<tr>"
3618 (mapconcat
3619 (lambda (x)
3620 (setq i (1+ i))
3621 (if (and (< i nlines)
3622 (string-match org-table-number-regexp x))
3623 (incf (aref fnum i)))
3624 (if head
3625 (concat (car org-export-table-header-tags) x
3626 (cdr org-export-table-header-tags))
3627 (concat (car org-export-table-data-tags) x
3628 (cdr org-export-table-data-tags))))
3629 fields "")
3630 "</tr>")
3631 html)))
3632 (unless splice (if tbopen (push "</tbody>" html)))
3633 (unless splice (push "</table>\n" html))
3634 (setq html (nreverse html))
3635 (unless splice
3636 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3637 (push (mapconcat
3638 (lambda (x)
3639 (setq gr (pop org-table-colgroup-info))
3640 (format "%s<col align=\"%s\"></col>%s"
3641 (if (memq gr '(:start :startend))
3642 (prog1
3643 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3644 (setq colgropen t))
3646 (if (> (/ (float x) nlines) org-table-number-fraction)
3647 "right" "left")
3648 (if (memq gr '(:end :startend))
3649 (progn (setq colgropen nil) "</colgroup>")
3650 "")))
3651 fnum "")
3652 html)
3653 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3654 (push html-table-tag html))
3655 (concat (mapconcat 'identity html "\n") "\n")))
3657 (defun org-table-clean-before-export (lines)
3658 "Check if the table has a marking column.
3659 If yes remove the column and the special lines."
3660 (setq org-table-colgroup-info nil)
3661 (if (memq nil
3662 (mapcar
3663 (lambda (x) (or (string-match "^[ \t]*|-" x)
3664 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3665 lines))
3666 (progn
3667 (setq org-table-clean-did-remove-column nil)
3668 (delq nil
3669 (mapcar
3670 (lambda (x)
3671 (cond
3672 ((string-match "^[ \t]*| */ *|" x)
3673 (setq org-table-colgroup-info
3674 (mapcar (lambda (x)
3675 (cond ((member x '("<" "&lt;")) :start)
3676 ((member x '(">" "&gt;")) :end)
3677 ((member x '("<>" "&lt;&gt;")) :startend)
3678 (t nil)))
3679 (org-split-string x "[ \t]*|[ \t]*")))
3680 nil)
3681 (t x)))
3682 lines)))
3683 (setq org-table-clean-did-remove-column t)
3684 (delq nil
3685 (mapcar
3686 (lambda (x)
3687 (cond
3688 ((string-match "^[ \t]*| */ *|" x)
3689 (setq org-table-colgroup-info
3690 (mapcar (lambda (x)
3691 (cond ((member x '("<" "&lt;")) :start)
3692 ((member x '(">" "&gt;")) :end)
3693 ((member x '("<>" "&lt;&gt;")) :startend)
3694 (t nil)))
3695 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3696 nil)
3697 ((string-match "^[ \t]*| *[!_^/] *|" x)
3698 nil) ; ignore this line
3699 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3700 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3701 ;; remove the first column
3702 (replace-match "\\1|" t nil x))))
3703 lines))))
3705 (defun org-format-table-table-html (lines)
3706 "Format a table generated by table.el into HTML.
3707 This conversion does *not* use `table-generate-source' from table.el.
3708 This has the advantage that Org-mode's HTML conversions can be used.
3709 But it has the disadvantage, that no cell- or row-spanning is allowed."
3710 (let (line field-buffer
3711 (head org-export-highlight-first-table-line)
3712 fields html empty)
3713 (setq html (concat html-table-tag "\n"))
3714 (while (setq line (pop lines))
3715 (setq empty "&nbsp;")
3716 (catch 'next-line
3717 (if (string-match "^[ \t]*\\+-" line)
3718 (progn
3719 (if field-buffer
3720 (progn
3721 (setq
3722 html
3723 (concat
3724 html
3725 "<tr>"
3726 (mapconcat
3727 (lambda (x)
3728 (if (equal x "") (setq x empty))
3729 (if head
3730 (concat (car org-export-table-header-tags) x
3731 (cdr org-export-table-header-tags))
3732 (concat (car org-export-table-data-tags) x
3733 (cdr org-export-table-data-tags))))
3734 field-buffer "\n")
3735 "</tr>\n"))
3736 (setq head nil)
3737 (setq field-buffer nil)))
3738 ;; Ignore this line
3739 (throw 'next-line t)))
3740 ;; Break the line into fields and store the fields
3741 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3742 (if field-buffer
3743 (setq field-buffer (mapcar
3744 (lambda (x)
3745 (concat x "<br/>" (pop fields)))
3746 field-buffer))
3747 (setq field-buffer fields))))
3748 (setq html (concat html "</table>\n"))
3749 html))
3751 (defun org-format-table-table-html-using-table-generate-source (lines)
3752 "Format a table into html, using `table-generate-source' from table.el.
3753 This has the advantage that cell- or row-spanning is allowed.
3754 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3755 (require 'table)
3756 (with-current-buffer (get-buffer-create " org-tmp1 ")
3757 (erase-buffer)
3758 (insert (mapconcat 'identity lines "\n"))
3759 (goto-char (point-min))
3760 (if (not (re-search-forward "|[^+]" nil t))
3761 (error "Error processing table"))
3762 (table-recognize-table)
3763 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3764 (table-generate-source 'html " org-tmp2 ")
3765 (set-buffer " org-tmp2 ")
3766 (buffer-substring (point-min) (point-max))))
3768 (defun org-export-splice-style (style extra)
3769 "Splice EXTRA into STYLE, just before \"</style>\"."
3770 (if (and (stringp extra)
3771 (string-match "\\S-" extra)
3772 (string-match "</style>" style))
3773 (concat (substring style 0 (match-beginning 0))
3774 "\n" extra "\n"
3775 (substring style (match-beginning 0)))
3776 style))
3778 (defun org-html-handle-time-stamps (s)
3779 "Format time stamps in string S, or remove them."
3780 (catch 'exit
3781 (let (r b)
3782 (while (string-match org-maybe-keyword-time-regexp s)
3783 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3784 ;; never export CLOCK
3785 (throw 'exit ""))
3786 (or b (setq b (substring s 0 (match-beginning 0))))
3787 (if (not org-export-with-timestamps)
3788 (setq r (concat r (substring s 0 (match-beginning 0)))
3789 s (substring s (match-end 0)))
3790 (setq r (concat
3791 r (substring s 0 (match-beginning 0))
3792 (if (match-end 1)
3793 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3794 (match-string 1 s)))
3795 (format " @<span class=\"timestamp\">%s@</span>"
3796 (substring
3797 (org-translate-time (match-string 3 s)) 1 -1)))
3798 s (substring s (match-end 0)))))
3799 ;; Line break if line started and ended with time stamp stuff
3800 (if (not r)
3802 (setq r (concat r s))
3803 (unless (string-match "\\S-" (concat b s))
3804 (setq r (concat r "@<br/>")))
3805 r))))
3807 (defun org-export-htmlize-region-for-paste (beg end)
3808 "Convert the region to HTML, using htmlize.el.
3809 This is much like `htmlize-region-for-paste', only that it uses
3810 the settings define in the org-... variables."
3811 (let* ((htmlize-output-type org-export-htmlize-output-type)
3812 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3813 (htmlbuf (htmlize-region beg end)))
3814 (unwind-protect
3815 (with-current-buffer htmlbuf
3816 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3817 (plist-get htmlize-buffer-places 'content-end)))
3818 (kill-buffer htmlbuf))))
3820 ;;;###autoload
3821 (defun org-export-htmlize-generate-css ()
3822 "Create the CSS for all font definitions in the current Emacs session.
3823 Use this to create face definitions in your CSS style file that can then
3824 be used by code snippets transformed by htmlize.
3825 This command just produces a buffer that contains class definitions for all
3826 faces used in the current Emacs session. You can copy and paste the ones you
3827 need into your CSS file.
3829 If you then set `org-export-htmlize-output-type' to `css', calls to
3830 the function `org-export-htmlize-region-for-paste' will produce code
3831 that uses these same face definitions."
3832 (interactive)
3833 (require 'htmlize)
3834 (and (get-buffer "*html*") (kill-buffer "*html*"))
3835 (with-temp-buffer
3836 (let ((fl (face-list))
3837 (htmlize-css-name-prefix "org-")
3838 (htmlize-output-type 'css)
3839 f i)
3840 (while (setq f (pop fl)
3841 i (and f (face-attribute f :inherit)))
3842 (when (and (symbolp f) (or (not i) (not (listp i))))
3843 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3844 (htmlize-region (point-min) (point-max))))
3845 (switch-to-buffer "*html*")
3846 (goto-char (point-min))
3847 (if (re-search-forward "<style" nil t)
3848 (delete-region (point-min) (match-beginning 0)))
3849 (if (re-search-forward "</style>" nil t)
3850 (delete-region (1+ (match-end 0)) (point-max)))
3851 (beginning-of-line 1)
3852 (if (looking-at " +") (replace-match ""))
3853 (goto-char (point-min)))
3855 (defun org-html-protect (s)
3856 ;; convert & to &amp;, < to &lt; and > to &gt;
3857 (let ((start 0))
3858 (while (string-match "&" s start)
3859 (setq s (replace-match "&amp;" t t s)
3860 start (1+ (match-beginning 0))))
3861 (while (string-match "<" s)
3862 (setq s (replace-match "&lt;" t t s)))
3863 (while (string-match ">" s)
3864 (setq s (replace-match "&gt;" t t s))))
3867 (defun org-export-cleanup-toc-line (s)
3868 "Remove tags and time staps from lines going into the toc."
3869 (when (memq org-export-with-tags '(not-in-toc nil))
3870 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3871 (setq s (replace-match "" t t s))))
3872 (when org-export-remove-timestamps-from-toc
3873 (while (string-match org-maybe-keyword-time-regexp s)
3874 (setq s (replace-match "" t t s))))
3875 (while (string-match org-bracket-link-regexp s)
3876 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3877 t t s)))
3880 (defun org-html-expand (string)
3881 "Prepare STRING for HTML export. Applies all active conversions.
3882 If there are links in the string, don't modify these."
3883 (let* ((re (concat org-bracket-link-regexp "\\|"
3884 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3885 m s l res)
3886 (while (setq m (string-match re string))
3887 (setq s (substring string 0 m)
3888 l (match-string 0 string)
3889 string (substring string (match-end 0)))
3890 (push (org-html-do-expand s) res)
3891 (push l res))
3892 (push (org-html-do-expand string) res)
3893 (apply 'concat (nreverse res))))
3895 (defun org-html-do-expand (s)
3896 "Apply all active conversions to translate special ASCII to HTML."
3897 (setq s (org-html-protect s))
3898 (if org-export-html-expand
3899 (let ((start 0))
3900 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3901 (setq s (replace-match "<\\1>" t nil s)))))
3902 (if org-export-with-emphasize
3903 (setq s (org-export-html-convert-emphasize s)))
3904 (if org-export-with-special-strings
3905 (setq s (org-export-html-convert-special-strings s)))
3906 (if org-export-with-sub-superscripts
3907 (setq s (org-export-html-convert-sub-super s)))
3908 (if org-export-with-TeX-macros
3909 (let ((start 0) wd ass)
3910 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
3911 s start))
3912 (if (get-text-property (match-beginning 0) 'org-protected s)
3913 (setq start (match-end 0))
3914 (setq wd (match-string 1 s))
3915 (if (setq ass (assoc wd org-html-entities))
3916 (setq s (replace-match (or (cdr ass)
3917 (concat "&" (car ass) ";"))
3918 t t s))
3919 (setq start (+ start (length wd))))))))
3922 (defun org-create-multibrace-regexp (left right n)
3923 "Create a regular expression which will match a balanced sexp.
3924 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3925 as single character strings.
3926 The regexp returned will match the entire expression including the
3927 delimiters. It will also define a single group which contains the
3928 match except for the outermost delimiters. The maximum depth of
3929 stacked delimiters is N. Escaping delimiters is not possible."
3930 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3931 (or "\\|")
3932 (re nothing)
3933 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3934 (while (> n 1)
3935 (setq n (1- n)
3936 re (concat re or next)
3937 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3938 (concat left "\\(" re "\\)" right)))
3940 (defvar org-match-substring-regexp
3941 (concat
3942 "\\([^\\]\\)\\([_^]\\)\\("
3943 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3944 "\\|"
3945 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3946 "\\|"
3947 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3948 "The regular expression matching a sub- or superscript.")
3950 (defvar org-match-substring-with-braces-regexp
3951 (concat
3952 "\\([^\\]\\)\\([_^]\\)\\("
3953 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3954 "\\)")
3955 "The regular expression matching a sub- or superscript, forcing braces.")
3957 (defconst org-export-html-special-string-regexps
3958 '(("\\\\-" . "&shy;")
3959 ("---\\([^-]\\)" . "&mdash;\\1")
3960 ("--\\([^-]\\)" . "&ndash;\\1")
3961 ("\\.\\.\\." . "&hellip;"))
3962 "Regular expressions for special string conversion.")
3964 (defun org-export-html-convert-special-strings (string)
3965 "Convert special characters in STRING to HTML."
3966 (let ((all org-export-html-special-string-regexps)
3967 e a re rpl start)
3968 (while (setq a (pop all))
3969 (setq re (car a) rpl (cdr a) start 0)
3970 (while (string-match re string start)
3971 (if (get-text-property (match-beginning 0) 'org-protected string)
3972 (setq start (match-end 0))
3973 (setq string (replace-match rpl t nil string)))))
3974 string))
3976 (defun org-export-html-convert-sub-super (string)
3977 "Convert sub- and superscripts in STRING to HTML."
3978 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3979 (while (string-match org-match-substring-regexp string s)
3980 (cond
3981 ((and requireb (match-end 8)) (setq s (match-end 2)))
3982 ((get-text-property (match-beginning 2) 'org-protected string)
3983 (setq s (match-end 2)))
3985 (setq s (match-end 1)
3986 key (if (string= (match-string 2 string) "_") "sub" "sup")
3987 c (or (match-string 8 string)
3988 (match-string 6 string)
3989 (match-string 5 string))
3990 string (replace-match
3991 (concat (match-string 1 string)
3992 "<" key ">" c "</" key ">")
3993 t t string)))))
3994 (while (string-match "\\\\\\([_^]\\)" string)
3995 (setq string (replace-match (match-string 1 string) t t string)))
3996 string))
3998 (defun org-export-html-convert-emphasize (string)
3999 "Apply emphasis."
4000 (let ((s 0) rpl)
4001 (while (string-match org-emph-re string s)
4002 (if (not (equal
4003 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4004 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4005 (setq s (match-beginning 0)
4007 (concat
4008 (match-string 1 string)
4009 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4010 (match-string 4 string)
4011 (nth 3 (assoc (match-string 3 string)
4012 org-emphasis-alist))
4013 (match-string 5 string))
4014 string (replace-match rpl t t string)
4015 s (+ s (- (length rpl) 2)))
4016 (setq s (1+ s))))
4017 string))
4019 (defvar org-par-open nil)
4020 (defun org-open-par ()
4021 "Insert <p>, but first close previous paragraph if any."
4022 (org-close-par-maybe)
4023 (insert "\n<p>")
4024 (setq org-par-open t))
4025 (defun org-close-par-maybe ()
4026 "Close paragraph if there is one open."
4027 (when org-par-open
4028 (insert "</p>")
4029 (setq org-par-open nil)))
4030 (defun org-close-li (&optional type)
4031 "Close <li> if necessary."
4032 (org-close-par-maybe)
4033 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4035 (defvar body-only) ; dynamically scoped into this.
4036 (defun org-html-level-start (level title umax with-toc head-count)
4037 "Insert a new level in HTML export.
4038 When TITLE is nil, just close all open levels."
4039 (org-close-par-maybe)
4040 (let ((target (and title (org-get-text-property-any 0 'target title)))
4041 (l org-level-max)
4042 snumber)
4043 (while (>= l level)
4044 (if (aref org-levels-open (1- l))
4045 (progn
4046 (org-html-level-close l umax)
4047 (aset org-levels-open (1- l) nil)))
4048 (setq l (1- l)))
4049 (when title
4050 ;; If title is nil, this means this function is called to close
4051 ;; all levels, so the rest is done only if title is given
4052 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4053 (setq title (replace-match
4054 (if org-export-with-tags
4055 (save-match-data
4056 (concat
4057 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4058 (mapconcat 'identity (org-split-string
4059 (match-string 1 title) ":")
4060 "&nbsp;")
4061 "</span>"))
4063 t t title)))
4064 (if (> level umax)
4065 (progn
4066 (if (aref org-levels-open (1- level))
4067 (progn
4068 (org-close-li)
4069 (if target
4070 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
4071 (insert "<li>" title "<br/>\n")))
4072 (aset org-levels-open (1- level) t)
4073 (org-close-par-maybe)
4074 (if target
4075 (insert (format "<ul>\n<li id=\"%s\">" target)
4076 title "<br/>\n")
4077 (insert "<ul>\n<li>" title "<br/>\n"))))
4078 (aset org-levels-open (1- level) t)
4079 (setq snumber (org-section-number level))
4080 (if (and org-export-with-section-numbers (not body-only))
4081 (setq title (concat snumber " " title)))
4082 (setq level (+ level org-export-html-toplevel-hlevel -1))
4083 (unless (= head-count 1) (insert "\n</div>\n"))
4084 (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"
4085 snumber level level snumber title level snumber))
4086 (org-open-par)))))
4088 (defun org-get-text-property-any (pos prop &optional object)
4089 (or (get-text-property pos prop object)
4090 (and (setq pos (next-single-property-change pos prop object))
4091 (get-text-property pos prop object))))
4093 (defun org-html-level-close (level max-outline-level)
4094 "Terminate one level in HTML export."
4095 (if (<= level max-outline-level)
4096 (insert "</div>\n")
4097 (org-close-li)
4098 (insert "</ul>\n")))
4100 ;;; iCalendar export
4102 ;;;###autoload
4103 (defun org-export-icalendar-this-file ()
4104 "Export current file as an iCalendar file.
4105 The iCalendar file will be located in the same directory as the Org-mode
4106 file, but with extension `.ics'."
4107 (interactive)
4108 (org-export-icalendar nil buffer-file-name))
4110 ;;;###autoload
4111 (defun org-export-icalendar-all-agenda-files ()
4112 "Export all files in `org-agenda-files' to iCalendar .ics files.
4113 Each iCalendar file will be located in the same directory as the Org-mode
4114 file, but with extension `.ics'."
4115 (interactive)
4116 (apply 'org-export-icalendar nil (org-agenda-files t)))
4118 ;;;###autoload
4119 (defun org-export-icalendar-combine-agenda-files ()
4120 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4121 The file is stored under the name `org-combined-agenda-icalendar-file'."
4122 (interactive)
4123 (apply 'org-export-icalendar t (org-agenda-files t)))
4125 (defun org-export-icalendar (combine &rest files)
4126 "Create iCalendar files for all elements of FILES.
4127 If COMBINE is non-nil, combine all calendar entries into a single large
4128 file and store it under the name `org-combined-agenda-icalendar-file'."
4129 (save-excursion
4130 (org-prepare-agenda-buffers files)
4131 (let* ((dir (org-export-directory
4132 :ical (list :publishing-directory
4133 org-export-publishing-directory)))
4134 file ical-file ical-buffer category started org-agenda-new-buffers)
4135 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4136 (when combine
4137 (setq ical-file
4138 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4139 org-combined-agenda-icalendar-file
4140 (expand-file-name org-combined-agenda-icalendar-file dir))
4141 ical-buffer (org-get-agenda-file-buffer ical-file))
4142 (set-buffer ical-buffer) (erase-buffer))
4143 (while (setq file (pop files))
4144 (catch 'nextfile
4145 (org-check-agenda-file file)
4146 (set-buffer (org-get-agenda-file-buffer file))
4147 (unless combine
4148 (setq ical-file (concat (file-name-as-directory dir)
4149 (file-name-sans-extension
4150 (file-name-nondirectory buffer-file-name))
4151 ".ics"))
4152 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4153 (with-current-buffer ical-buffer (erase-buffer)))
4154 (setq category (or org-category
4155 (file-name-sans-extension
4156 (file-name-nondirectory buffer-file-name))))
4157 (if (symbolp category) (setq category (symbol-name category)))
4158 (let ((standard-output ical-buffer))
4159 (if combine
4160 (and (not started) (setq started t)
4161 (org-start-icalendar-file org-icalendar-combined-name))
4162 (org-start-icalendar-file category))
4163 (org-print-icalendar-entries combine)
4164 (when (or (and combine (not files)) (not combine))
4165 (org-finish-icalendar-file)
4166 (set-buffer ical-buffer)
4167 (run-hooks 'org-before-save-iCalendar-file-hook)
4168 (save-buffer)
4169 (run-hooks 'org-after-save-iCalendar-file-hook)
4170 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4171 ))))
4172 (org-release-buffers org-agenda-new-buffers))))
4174 (defvar org-before-save-iCalendar-file-hook nil
4175 "Hook run before an iCalendar file has been saved.
4176 This can be used to modify the result of the export.")
4178 (defvar org-after-save-iCalendar-file-hook nil
4179 "Hook run after an iCalendar file has been saved.
4180 The iCalendar buffer is still current when this hook is run.
4181 A good way to use this is to tell a desktop calenndar application to re-read
4182 the iCalendar file.")
4184 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4185 (defun org-print-icalendar-entries (&optional combine)
4186 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4187 When COMBINE is non nil, add the category to each line."
4188 (require 'org-agenda)
4189 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4190 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4191 (dts (org-ical-ts-to-string
4192 (format-time-string (cdr org-time-stamp-formats) (current-time))
4193 "DTSTART"))
4194 hd ts ts2 state status (inc t) pos b sexp rrule
4195 scheduledp deadlinep todo prefix due start
4196 tmp pri categories entry location summary desc uid
4197 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4198 (org-refresh-category-properties)
4199 (save-excursion
4200 (goto-char (point-min))
4201 (while (re-search-forward re1 nil t)
4202 (catch :skip
4203 (org-agenda-skip)
4204 (when (boundp 'org-icalendar-verify-function)
4205 (unless (funcall org-icalendar-verify-function)
4206 (outline-next-heading)
4207 (backward-char 1)
4208 (throw :skip nil)))
4209 (setq pos (match-beginning 0)
4210 ts (match-string 0)
4211 inc t
4212 hd (condition-case nil
4213 (org-icalendar-cleanup-string
4214 (org-get-heading))
4215 (error (throw :skip nil)))
4216 summary (org-icalendar-cleanup-string
4217 (org-entry-get nil "SUMMARY"))
4218 desc (org-icalendar-cleanup-string
4219 (or (org-entry-get nil "DESCRIPTION")
4220 (and org-icalendar-include-body (org-get-entry)))
4221 t org-icalendar-include-body)
4222 location (org-icalendar-cleanup-string
4223 (org-entry-get nil "LOCATION"))
4224 uid (if org-icalendar-store-UID
4225 (org-id-get-create)
4226 (or (org-id-get) (org-id-new)))
4227 categories (org-export-get-categories)
4228 deadlinep nil scheduledp nil)
4229 (if (looking-at re2)
4230 (progn
4231 (goto-char (match-end 0))
4232 (setq ts2 (match-string 1)
4233 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4234 (setq tmp (buffer-substring (max (point-min)
4235 (- pos org-ds-keyword-length))
4236 pos)
4237 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4238 (progn
4239 (setq inc nil)
4240 (replace-match "\\1" t nil ts))
4242 deadlinep (string-match org-deadline-regexp tmp)
4243 scheduledp (string-match org-scheduled-regexp tmp)
4244 todo (org-get-todo-state)
4245 ;; donep (org-entry-is-done-p)
4247 (when (and
4248 deadlinep
4249 (if todo
4250 (not (memq 'event-if-todo org-icalendar-use-deadline))
4251 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4252 (throw :skip t))
4253 (when (and
4254 scheduledp
4255 (if todo
4256 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4257 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4258 (throw :skip t))
4259 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4260 (if (or (string-match org-tr-regexp hd)
4261 (string-match org-ts-regexp hd))
4262 (setq hd (replace-match "" t t hd)))
4263 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4264 (setq rrule
4265 (concat "\nRRULE:FREQ="
4266 (cdr (assoc
4267 (match-string 2 ts)
4268 '(("d" . "DAILY")("w" . "WEEKLY")
4269 ("m" . "MONTHLY")("y" . "YEARLY"))))
4270 ";INTERVAL=" (match-string 1 ts)))
4271 (setq rrule ""))
4272 (setq summary (or summary hd))
4273 (if (string-match org-bracket-link-regexp summary)
4274 (setq summary
4275 (replace-match (if (match-end 3)
4276 (match-string 3 summary)
4277 (match-string 1 summary))
4278 t t summary)))
4279 (if deadlinep (setq summary (concat "DL: " summary)))
4280 (if scheduledp (setq summary (concat "S: " summary)))
4281 (if (string-match "\\`<%%" ts)
4282 (with-current-buffer sexp-buffer
4283 (insert (substring ts 1 -1) " " summary "\n"))
4284 (princ (format "BEGIN:VEVENT
4285 UID: %s
4287 %s%s
4288 SUMMARY:%s%s%s
4289 CATEGORIES:%s
4290 END:VEVENT\n"
4291 (concat prefix uid)
4292 (org-ical-ts-to-string ts "DTSTART")
4293 (org-ical-ts-to-string ts2 "DTEND" inc)
4294 rrule summary
4295 (if (and desc (string-match "\\S-" desc))
4296 (concat "\nDESCRIPTION: " desc) "")
4297 (if (and location (string-match "\\S-" location))
4298 (concat "\nLOCATION: " location) "")
4299 categories)))))
4300 (when (and org-icalendar-include-sexps
4301 (condition-case nil (require 'icalendar) (error nil))
4302 (fboundp 'icalendar-export-region))
4303 ;; Get all the literal sexps
4304 (goto-char (point-min))
4305 (while (re-search-forward "^&?%%(" nil t)
4306 (catch :skip
4307 (org-agenda-skip)
4308 (setq b (match-beginning 0))
4309 (goto-char (1- (match-end 0)))
4310 (forward-sexp 1)
4311 (end-of-line 1)
4312 (setq sexp (buffer-substring b (point)))
4313 (with-current-buffer sexp-buffer
4314 (insert sexp "\n"))))
4315 (princ (org-diary-to-ical-string sexp-buffer))
4316 (kill-buffer sexp-buffer))
4318 (when org-icalendar-include-todo
4319 (setq prefix "TODO-")
4320 (goto-char (point-min))
4321 (while (re-search-forward org-todo-line-regexp nil t)
4322 (catch :skip
4323 (org-agenda-skip)
4324 (when (boundp 'org-icalendar-verify-function)
4325 (unless (funcall org-icalendar-verify-function)
4326 (outline-next-heading)
4327 (backward-char 1)
4328 (throw :skip nil)))
4329 (setq state (match-string 2))
4330 (setq status (if (member state org-done-keywords)
4331 "COMPLETED" "NEEDS-ACTION"))
4332 (when (and state
4333 (or (not (member state org-done-keywords))
4334 (eq org-icalendar-include-todo 'all))
4335 (not (member org-archive-tag (org-get-tags-at)))
4337 (setq hd (match-string 3)
4338 summary (org-icalendar-cleanup-string
4339 (org-entry-get nil "SUMMARY"))
4340 desc (org-icalendar-cleanup-string
4341 (or (org-entry-get nil "DESCRIPTION")
4342 (and org-icalendar-include-body (org-get-entry)))
4343 t org-icalendar-include-body)
4344 location (org-icalendar-cleanup-string
4345 (org-entry-get nil "LOCATION"))
4346 due (and (member 'todo-due org-icalendar-use-deadline)
4347 (org-entry-get nil "DEADLINE"))
4348 start (and (member 'todo-start org-icalendar-use-scheduled)
4349 (org-entry-get nil "SCHEDULED"))
4350 categories (org-export-get-categories)
4351 uid (if org-icalendar-store-UID
4352 (org-id-get-create)
4353 (or (org-id-get) (org-id-new))))
4354 (and due (setq due (org-ical-ts-to-string due "DUE")))
4355 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4357 (if (string-match org-bracket-link-regexp hd)
4358 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4359 (match-string 1 hd))
4360 t t hd)))
4361 (if (string-match org-priority-regexp hd)
4362 (setq pri (string-to-char (match-string 2 hd))
4363 hd (concat (substring hd 0 (match-beginning 1))
4364 (substring hd (match-end 1))))
4365 (setq pri org-default-priority))
4366 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4367 (- org-lowest-priority org-highest-priority))))))
4369 (princ (format "BEGIN:VTODO
4370 UID: %s
4372 SUMMARY:%s%s%s%s
4373 CATEGORIES:%s
4374 SEQUENCE:1
4375 PRIORITY:%d
4376 STATUS:%s
4377 END:VTODO\n"
4378 (concat prefix uid)
4379 (or start dts)
4380 (or summary hd)
4381 (if (and location (string-match "\\S-" location))
4382 (concat "\nLOCATION: " location) "")
4383 (if (and desc (string-match "\\S-" desc))
4384 (concat "\nDESCRIPTION: " desc) "")
4385 (if due (concat "\n" due) "")
4386 categories
4387 pri status)))))))))
4389 (defun org-export-get-categories ()
4390 "Get categories according to `org-icalendar-categories'."
4391 (let ((cs org-icalendar-categories) c rtn tmp)
4392 (while (setq c (pop cs))
4393 (cond
4394 ((eq c 'category) (push (org-get-category) rtn))
4395 ((eq c 'todo-state)
4396 (setq tmp (org-get-todo-state))
4397 (and tmp (push tmp rtn)))
4398 ((eq c 'local-tags)
4399 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4400 ((eq c 'all-tags)
4401 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4402 (mapconcat 'identity (nreverse rtn) ",")))
4404 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4405 "Take out stuff and quote what needs to be quoted.
4406 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4407 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4408 characters."
4409 (if (not s)
4411 (when is-body
4412 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4413 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4414 (while (string-match re s) (setq s (replace-match "" t t s)))
4415 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4416 (let ((start 0))
4417 (while (string-match "\\([,;]\\)" s start)
4418 (setq start (+ (match-beginning 0) 2)
4419 s (replace-match "\\\\\\1" nil nil s))))
4420 (when is-body
4421 (while (string-match "[ \t]*\n[ \t]*" s)
4422 (setq s (replace-match "\\n" t t s))))
4423 (setq s (org-trim s))
4424 (if is-body
4425 (if maxlength
4426 (if (and (numberp maxlength)
4427 (> (length s) maxlength))
4428 (setq s (substring s 0 maxlength)))))
4431 (defun org-get-entry ()
4432 "Clean-up description string."
4433 (save-excursion
4434 (org-back-to-heading t)
4435 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4437 (defun org-start-icalendar-file (name)
4438 "Start an iCalendar file by inserting the header."
4439 (let ((user user-full-name)
4440 (name (or name "unknown"))
4441 (timezone (cadr (current-time-zone))))
4442 (princ
4443 (format "BEGIN:VCALENDAR
4444 VERSION:2.0
4445 X-WR-CALNAME:%s
4446 PRODID:-//%s//Emacs with Org-mode//EN
4447 X-WR-TIMEZONE:%s
4448 CALSCALE:GREGORIAN\n" name user timezone))))
4450 (defun org-finish-icalendar-file ()
4451 "Finish an iCalendar file by inserting the END statement."
4452 (princ "END:VCALENDAR\n"))
4454 (defun org-ical-ts-to-string (s keyword &optional inc)
4455 "Take a time string S and convert it to iCalendar format.
4456 KEYWORD is added in front, to make a complete line like DTSTART....
4457 When INC is non-nil, increase the hour by two (if time string contains
4458 a time), or the day by one (if it does not contain a time)."
4459 (let ((t1 (org-parse-time-string s 'nodefault))
4460 t2 fmt have-time time)
4461 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4462 (setq t2 t1 have-time t)
4463 (setq t2 (org-parse-time-string s)))
4464 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4465 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4466 (when inc
4467 (if have-time
4468 (if org-agenda-default-appointment-duration
4469 (setq mi (+ org-agenda-default-appointment-duration mi))
4470 (setq h (+ 2 h)))
4471 (setq d (1+ d))))
4472 (setq time (encode-time s mi h d m y)))
4473 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4474 (concat keyword (format-time-string fmt time))))
4476 ;;; XOXO export
4478 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4479 (with-current-buffer buffer
4480 (apply 'insert output)))
4481 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4483 ;;;###autoload
4484 (defun org-export-as-xoxo (&optional buffer)
4485 "Export the org buffer as XOXO.
4486 The XOXO buffer is named *xoxo-<source buffer name>*"
4487 (interactive (list (current-buffer)))
4488 ;; A quickie abstraction
4490 ;; Output everything as XOXO
4491 (with-current-buffer (get-buffer buffer)
4492 (let* ((pos (point))
4493 (opt-plist (org-combine-plists (org-default-export-plist)
4494 (org-infile-export-plist)))
4495 (filename (concat (file-name-as-directory
4496 (org-export-directory :xoxo opt-plist))
4497 (file-name-sans-extension
4498 (file-name-nondirectory buffer-file-name))
4499 ".html"))
4500 (out (find-file-noselect filename))
4501 (last-level 1)
4502 (hanging-li nil))
4503 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4504 ;; Check the output buffer is empty.
4505 (with-current-buffer out (erase-buffer))
4506 ;; Kick off the output
4507 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4508 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4509 (let* ((hd (match-string-no-properties 1))
4510 (level (length hd))
4511 (text (concat
4512 (match-string-no-properties 2)
4513 (save-excursion
4514 (goto-char (match-end 0))
4515 (let ((str ""))
4516 (catch 'loop
4517 (while 't
4518 (forward-line)
4519 (if (looking-at "^[ \t]\\(.*\\)")
4520 (setq str (concat str (match-string-no-properties 1)))
4521 (throw 'loop str)))))))))
4523 ;; Handle level rendering
4524 (cond
4525 ((> level last-level)
4526 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4528 ((< level last-level)
4529 (dotimes (- (- last-level level) 1)
4530 (if hanging-li
4531 (org-export-as-xoxo-insert-into out "</li>\n"))
4532 (org-export-as-xoxo-insert-into out "</ol>\n"))
4533 (when hanging-li
4534 (org-export-as-xoxo-insert-into out "</li>\n")
4535 (setq hanging-li nil)))
4537 ((equal level last-level)
4538 (if hanging-li
4539 (org-export-as-xoxo-insert-into out "</li>\n")))
4542 (setq last-level level)
4544 ;; And output the new li
4545 (setq hanging-li 't)
4546 (if (equal ?+ (elt text 0))
4547 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4548 (org-export-as-xoxo-insert-into out "<li>" text))))
4550 ;; Finally finish off the ol
4551 (dotimes (- last-level 1)
4552 (if hanging-li
4553 (org-export-as-xoxo-insert-into out "</li>\n"))
4554 (org-export-as-xoxo-insert-into out "</ol>\n"))
4556 (goto-char pos)
4557 ;; Finish the buffer off and clean it up.
4558 (switch-to-buffer-other-window out)
4559 (indent-region (point-min) (point-max) nil)
4560 (save-buffer)
4561 (goto-char (point-min))
4564 (provide 'org-exp)
4566 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4568 ;;; org-exp.el ends here