Allow multiple #+STYLE lines in the buffer.
[org-mode/org-tableheadings.git] / lisp / org-exp.el
blob361a49e61e6b7d5e8b98af5ce6cdf50889a85183
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.08-pre01
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 style
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")
890 (setq style (concat style "\n" val)))
891 ((string-equal key "TEXT")
892 (setq text (if text (concat text "\n" val) val)))
893 ((string-equal key "OPTIONS")
894 (setq options (concat val " " options)))
895 ((string-equal key "LINK_UP")
896 (setq p (plist-put p :link-up val)))
897 ((string-equal key "LINK_HOME")
898 (setq p (plist-put p :link-home val)))
899 ((string-equal key "EXPORT_SELECT_TAGS")
900 (setq p (plist-put p :select-tags (org-split-string val))))
901 ((string-equal key "EXPORT_EXCLUDE_TAGS")
902 (setq p (plist-put p :exclude-tags (org-split-string val))))
903 ((equal key "SETUPFILE")
904 (setq setup-contents (org-file-contents
905 (expand-file-name
906 (org-remove-double-quotes
907 (org-trim val)))
908 'noerror))
909 (if (not ext-setup-or-nil)
910 (setq ext-setup-or-nil setup-contents start 0)
911 (setq ext-setup-or-nil
912 (concat (substring ext-setup-or-nil 0 start)
913 "\n" setup-contents "\n"
914 (substring ext-setup-or-nil start)))))))
915 (setq p (plist-put p :text text))
916 (if style (setq p (plist-put p :style-extra style)))
917 (when options
918 (setq p (org-export-add-options-to-plist p options)))
919 p))))
921 (defun org-export-add-options-to-plist (p options)
922 "Parse an OPTONS line and set values in the property list P."
923 (let (o)
924 (when options
925 (let ((op '(("H" . :headline-levels)
926 ("num" . :section-numbers)
927 ("toc" . :table-of-contents)
928 ("\\n" . :preserve-breaks)
929 ("@" . :expand-quoted-html)
930 (":" . :fixed-width)
931 ("|" . :tables)
932 ("^" . :sub-superscript)
933 ("-" . :special-strings)
934 ("f" . :footnotes)
935 ("d" . :drawers)
936 ("tags" . :tags)
937 ("*" . :emphasize)
938 ("TeX" . :TeX-macros)
939 ("LaTeX" . :LaTeX-fragments)
940 ("skip" . :skip-before-1st-heading)
941 ("author" . :author-info)
942 ("creator" . :creator-info)
943 ("timestamp" . :time-stamp-file)))
945 (while (setq o (pop op))
946 (if (string-match (concat (regexp-quote (car o))
947 ":\\([^ \t\n\r;,.]*\\)")
948 options)
949 (setq p (plist-put p (cdr o)
950 (car (read-from-string
951 (match-string 1 options))))))))))
954 (defun org-export-add-subtree-options (p pos)
955 "Add options in subtree at position POS to property list P."
956 (save-excursion
957 (goto-char pos)
958 (when (org-at-heading-p)
959 (let (a)
960 ;; This is actually read in `org-export-get-title-from-subtree'
961 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
962 ;; (setq p (plist-put p :title a)))
963 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
964 (setq p (plist-put p :text a)))
965 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
966 (setq p (org-export-add-options-to-plist p a)))))
969 (defun org-export-directory (type plist)
970 (let* ((val (plist-get plist :publishing-directory))
971 (dir (if (listp val)
972 (or (cdr (assoc type val)) ".")
973 val)))
974 dir))
976 (defun org-export-process-option-filters (plist)
977 (let ((functions org-export-options-filters) f)
978 (while (setq f (pop functions))
979 (setq plist (funcall f plist))))
980 plist)
982 ;;;###autoload
983 (defun org-export (&optional arg)
984 "Export dispatcher for Org-mode.
985 When `org-export-run-in-background' is non-nil, try to run the command
986 in the background. This will be done only for commands that write
987 to a file. For details see the docstring of `org-export-run-in-background'.
989 The prefix argument ARG will be passed to the exporter. However, if
990 ARG is a double universal prefix `C-u C-u', that means to inverse the
991 value of `org-export-run-in-background'."
992 (interactive "P")
993 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
994 (help "[t] insert the export option template
995 \[v] limit export to visible part of outline tree
997 \[a] export as ASCII
999 \[h] export as HTML
1000 \[H] export as HTML to temporary buffer
1001 \[R] export region as HTML
1002 \[b] export as HTML and browse immediately
1003 \[x] export as XOXO
1005 \[l] export as LaTeX
1006 \[L] export as LaTeX to temporary buffer
1008 \[i] export current file as iCalendar file
1009 \[I] export all agenda files as iCalendar files
1010 \[c] export agenda files into combined iCalendar file
1012 \[F] publish current file
1013 \[P] publish current project
1014 \[X] publish... (project will be prompted for)
1015 \[A] publish all projects")
1016 (cmds
1017 '((?t org-insert-export-options-template nil)
1018 (?v org-export-visible nil)
1019 (?a org-export-as-ascii t)
1020 (?h org-export-as-html t)
1021 (?b org-export-as-html-and-open t)
1022 (?H org-export-as-html-to-buffer nil)
1023 (?R org-export-region-as-html nil)
1024 (?x org-export-as-xoxo t)
1025 (?l org-export-as-latex t)
1026 (?L org-export-as-latex-to-buffer nil)
1027 (?i org-export-icalendar-this-file t)
1028 (?I org-export-icalendar-all-agenda-files t)
1029 (?c org-export-icalendar-combine-agenda-files t)
1030 (?F org-publish-current-file t)
1031 (?P org-publish-current-project t)
1032 (?X org-publish t)
1033 (?A org-publish-all t)))
1034 r1 r2 ass)
1035 (save-window-excursion
1036 (delete-other-windows)
1037 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1038 (princ help))
1039 (message "Select command: ")
1040 (setq r1 (read-char-exclusive)))
1041 (setq r2 (if (< r1 27) (+ r1 96) r1))
1042 (unless (setq ass (assq r2 cmds))
1043 (error "No command associated with key %c" r1))
1044 (if (and bg (nth 2 ass))
1045 ;; execute in background
1046 (let ((p (start-process
1047 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1048 "*Org Processes*"
1049 (expand-file-name invocation-name invocation-directory)
1050 "-batch"
1051 "-l" user-init-file
1052 "--eval" "(require 'org-exp)"
1053 "--eval" "(setq org-wait .2)"
1054 (buffer-file-name)
1055 "-f" (symbol-name (nth 1 ass)))))
1056 (set-process-sentinel p 'org-export-process-sentinel)
1057 (message "Background process \"%s\": started" p))
1058 ;; background processing not requested, or not possible
1059 (call-interactively (nth 1 ass)))))
1061 (defun org-export-process-sentinel (process status)
1062 (if (string-match "\n+\\'" status)
1063 (setq status (substring status 0 -1)))
1064 (message "Background process \"%s\": %s" process status))
1066 (defconst org-html-entities
1067 '(("nbsp")
1068 ("iexcl")
1069 ("cent")
1070 ("pound")
1071 ("curren")
1072 ("yen")
1073 ("brvbar")
1074 ("vert" . "&#124;")
1075 ("sect")
1076 ("uml")
1077 ("copy")
1078 ("ordf")
1079 ("laquo")
1080 ("not")
1081 ("shy")
1082 ("reg")
1083 ("macr")
1084 ("deg")
1085 ("plusmn")
1086 ("sup2")
1087 ("sup3")
1088 ("acute")
1089 ("micro")
1090 ("para")
1091 ("middot")
1092 ("odot"."o")
1093 ("star"."*")
1094 ("cedil")
1095 ("sup1")
1096 ("ordm")
1097 ("raquo")
1098 ("frac14")
1099 ("frac12")
1100 ("frac34")
1101 ("iquest")
1102 ("Agrave")
1103 ("Aacute")
1104 ("Acirc")
1105 ("Atilde")
1106 ("Auml")
1107 ("Aring") ("AA"."&Aring;")
1108 ("AElig")
1109 ("Ccedil")
1110 ("Egrave")
1111 ("Eacute")
1112 ("Ecirc")
1113 ("Euml")
1114 ("Igrave")
1115 ("Iacute")
1116 ("Icirc")
1117 ("Iuml")
1118 ("ETH")
1119 ("Ntilde")
1120 ("Ograve")
1121 ("Oacute")
1122 ("Ocirc")
1123 ("Otilde")
1124 ("Ouml")
1125 ("times")
1126 ("Oslash")
1127 ("Ugrave")
1128 ("Uacute")
1129 ("Ucirc")
1130 ("Uuml")
1131 ("Yacute")
1132 ("THORN")
1133 ("szlig")
1134 ("agrave")
1135 ("aacute")
1136 ("acirc")
1137 ("atilde")
1138 ("auml")
1139 ("aring")
1140 ("aelig")
1141 ("ccedil")
1142 ("egrave")
1143 ("eacute")
1144 ("ecirc")
1145 ("euml")
1146 ("igrave")
1147 ("iacute")
1148 ("icirc")
1149 ("iuml")
1150 ("eth")
1151 ("ntilde")
1152 ("ograve")
1153 ("oacute")
1154 ("ocirc")
1155 ("otilde")
1156 ("ouml")
1157 ("divide")
1158 ("oslash")
1159 ("ugrave")
1160 ("uacute")
1161 ("ucirc")
1162 ("uuml")
1163 ("yacute")
1164 ("thorn")
1165 ("yuml")
1166 ("fnof")
1167 ("Alpha")
1168 ("Beta")
1169 ("Gamma")
1170 ("Delta")
1171 ("Epsilon")
1172 ("Zeta")
1173 ("Eta")
1174 ("Theta")
1175 ("Iota")
1176 ("Kappa")
1177 ("Lambda")
1178 ("Mu")
1179 ("Nu")
1180 ("Xi")
1181 ("Omicron")
1182 ("Pi")
1183 ("Rho")
1184 ("Sigma")
1185 ("Tau")
1186 ("Upsilon")
1187 ("Phi")
1188 ("Chi")
1189 ("Psi")
1190 ("Omega")
1191 ("alpha")
1192 ("beta")
1193 ("gamma")
1194 ("delta")
1195 ("epsilon")
1196 ("varepsilon"."&epsilon;")
1197 ("zeta")
1198 ("eta")
1199 ("theta")
1200 ("iota")
1201 ("kappa")
1202 ("lambda")
1203 ("mu")
1204 ("nu")
1205 ("xi")
1206 ("omicron")
1207 ("pi")
1208 ("rho")
1209 ("sigmaf") ("varsigma"."&sigmaf;")
1210 ("sigma")
1211 ("tau")
1212 ("upsilon")
1213 ("phi")
1214 ("chi")
1215 ("psi")
1216 ("omega")
1217 ("thetasym") ("vartheta"."&thetasym;")
1218 ("upsih")
1219 ("piv")
1220 ("bull") ("bullet"."&bull;")
1221 ("hellip") ("dots"."&hellip;")
1222 ("prime")
1223 ("Prime")
1224 ("oline")
1225 ("frasl")
1226 ("weierp")
1227 ("image")
1228 ("real")
1229 ("trade")
1230 ("alefsym")
1231 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1232 ("uarr") ("uparrow"."&uarr;")
1233 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1234 ("darr")("downarrow"."&darr;")
1235 ("harr") ("leftrightarrow"."&harr;")
1236 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1237 ("lArr") ("Leftarrow"."&lArr;")
1238 ("uArr") ("Uparrow"."&uArr;")
1239 ("rArr") ("Rightarrow"."&rArr;")
1240 ("dArr") ("Downarrow"."&dArr;")
1241 ("hArr") ("Leftrightarrow"."&hArr;")
1242 ("forall")
1243 ("part") ("partial"."&part;")
1244 ("exist") ("exists"."&exist;")
1245 ("empty") ("emptyset"."&empty;")
1246 ("nabla")
1247 ("isin") ("in"."&isin;")
1248 ("notin")
1249 ("ni")
1250 ("prod")
1251 ("sum")
1252 ("minus")
1253 ("lowast") ("ast"."&lowast;")
1254 ("radic")
1255 ("prop") ("proptp"."&prop;")
1256 ("infin") ("infty"."&infin;")
1257 ("ang") ("angle"."&ang;")
1258 ("and") ("wedge"."&and;")
1259 ("or") ("vee"."&or;")
1260 ("cap")
1261 ("cup")
1262 ("int")
1263 ("there4")
1264 ("sim")
1265 ("cong") ("simeq"."&cong;")
1266 ("asymp")("approx"."&asymp;")
1267 ("ne") ("neq"."&ne;")
1268 ("equiv")
1269 ("le")
1270 ("ge")
1271 ("sub") ("subset"."&sub;")
1272 ("sup") ("supset"."&sup;")
1273 ("nsub")
1274 ("sube")
1275 ("supe")
1276 ("oplus")
1277 ("otimes")
1278 ("perp")
1279 ("sdot") ("cdot"."&sdot;")
1280 ("lceil")
1281 ("rceil")
1282 ("lfloor")
1283 ("rfloor")
1284 ("lang")
1285 ("rang")
1286 ("loz") ("Diamond"."&loz;")
1287 ("spades") ("spadesuit"."&spades;")
1288 ("clubs") ("clubsuit"."&clubs;")
1289 ("hearts") ("diamondsuit"."&hearts;")
1290 ("diams") ("diamondsuit"."&diams;")
1291 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1292 ("quot")
1293 ("amp")
1294 ("lt")
1295 ("gt")
1296 ("OElig")
1297 ("oelig")
1298 ("Scaron")
1299 ("scaron")
1300 ("Yuml")
1301 ("circ")
1302 ("tilde")
1303 ("ensp")
1304 ("emsp")
1305 ("thinsp")
1306 ("zwnj")
1307 ("zwj")
1308 ("lrm")
1309 ("rlm")
1310 ("ndash")
1311 ("mdash")
1312 ("lsquo")
1313 ("rsquo")
1314 ("sbquo")
1315 ("ldquo")
1316 ("rdquo")
1317 ("bdquo")
1318 ("dagger")
1319 ("Dagger")
1320 ("permil")
1321 ("lsaquo")
1322 ("rsaquo")
1323 ("euro")
1325 ("arccos"."arccos")
1326 ("arcsin"."arcsin")
1327 ("arctan"."arctan")
1328 ("arg"."arg")
1329 ("cos"."cos")
1330 ("cosh"."cosh")
1331 ("cot"."cot")
1332 ("coth"."coth")
1333 ("csc"."csc")
1334 ("deg"."deg")
1335 ("det"."det")
1336 ("dim"."dim")
1337 ("exp"."exp")
1338 ("gcd"."gcd")
1339 ("hom"."hom")
1340 ("inf"."inf")
1341 ("ker"."ker")
1342 ("lg"."lg")
1343 ("lim"."lim")
1344 ("liminf"."liminf")
1345 ("limsup"."limsup")
1346 ("ln"."ln")
1347 ("log"."log")
1348 ("max"."max")
1349 ("min"."min")
1350 ("Pr"."Pr")
1351 ("sec"."sec")
1352 ("sin"."sin")
1353 ("sinh"."sinh")
1354 ("sup"."sup")
1355 ("tan"."tan")
1356 ("tanh"."tanh")
1358 "Entities for TeX->HTML translation.
1359 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1360 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1361 In that case, \"\\ent\" will be translated to \"&other;\".
1362 The list contains HTML entities for Latin-1, Greek and other symbols.
1363 It is supplemented by a number of commonly used TeX macros with appropriate
1364 translations. There is currently no way for users to extend this.")
1366 ;;; General functions for all backends
1368 (defun org-export-preprocess-string (string &rest parameters)
1369 "Cleanup STRING so that that the true exported has a more consistent source.
1370 This function takes STRING, which should be a buffer-string of an org-file
1371 to export. It then creates a temporary buffer where it does its job.
1372 The result is then again returned as a string, and the exporter works
1373 on this string to produce the exported version."
1374 (interactive)
1375 (let* ((htmlp (plist-get parameters :for-html))
1376 (asciip (plist-get parameters :for-ascii))
1377 (latexp (plist-get parameters :for-LaTeX))
1378 (archived-trees (plist-get parameters :archived-trees))
1379 (inhibit-read-only t)
1380 (drawers org-drawers)
1381 (outline-regexp "\\*+ ")
1382 target-alist rtn)
1384 (with-current-buffer (get-buffer-create " org-mode-tmp")
1385 (erase-buffer)
1386 (insert string)
1387 (setq case-fold-search t)
1388 ;; Call the hook
1389 (run-hooks 'org-export-preprocess-hook)
1391 ;; Remove license-to-kill stuff
1392 ;; The caller markes some stuff fo killing, stuff that has been
1393 ;; used to create the page title, for example.
1394 (org-export-kill-licensed-text)
1396 (let ((org-inhibit-startup t)) (org-mode))
1397 (setq case-fold-search t)
1398 (untabify (point-min) (point-max))
1400 ;; Handle include files
1401 (org-export-handle-include-files)
1403 ;; Get rid of excluded trees
1404 (org-export-handle-export-tags (plist-get parameters :select-tags)
1405 (plist-get parameters :exclude-tags))
1407 ;; Handle source code snippets
1408 (org-export-replace-src-segments)
1410 ;; Get rid of drawers
1411 (org-export-remove-or-extract-drawers drawers
1412 (plist-get parameters :drawers))
1414 ;; Get the correct stuff before the first headline
1415 (when (plist-get parameters :skip-before-1st-heading)
1416 (goto-char (point-min))
1417 (when (re-search-forward "^\\*+[ \t]" nil t)
1418 (delete-region (point-min) (match-beginning 0))
1419 (goto-char (point-min))
1420 (insert "\n")))
1421 (when (plist-get parameters :add-text)
1422 (goto-char (point-min))
1423 (insert (plist-get parameters :add-text) "\n"))
1425 ;; Get rid of archived trees
1426 (org-export-remove-archived-trees archived-trees)
1428 ;; Find all headings and compute the targets for them
1429 (setq target-alist (org-export-define-heading-targets target-alist))
1431 ;; Find targets in comments and move them out of comments,
1432 ;; but mark them as targets that should be invisible
1433 (setq target-alist (org-export-handle-invisible-targets target-alist))
1435 ;; Protect examples
1436 (org-export-protect-examples (if asciip 'indent nil))
1438 ;; Protect backend specific stuff, throw away the others.
1439 (org-export-select-backend-specific-text
1440 (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1442 ;; Protect quoted subtrees
1443 (org-export-protect-quoted-subtrees)
1445 ;; Protect verbatim elements
1446 (org-export-protect-verbatim)
1448 ;; Blockquotes and verse
1449 (org-export-mark-blockquote-and-verse)
1451 ;; Remove comment environment and comment subtrees
1452 (org-export-remove-comment-blocks-and-subtrees)
1454 ;; Remove special table lines
1455 (when org-export-table-remove-special-lines
1456 (org-export-remove-special-table-lines))
1458 ;; Specific LaTeX stuff
1459 (when latexp
1460 (require 'org-export-latex nil)
1461 (org-export-latex-preprocess))
1463 ;; Specific ASCII stuff
1464 (when asciip
1465 (org-export-ascii-preprocess))
1467 ;; Specific HTML stuff
1468 (when htmlp
1469 (org-export-html-preprocess parameters))
1471 ;; Remove or replace comments
1472 (org-export-handle-comments (plist-get parameters :comments))
1474 ;; Find matches for radio targets and turn them into internal links
1475 (org-export-mark-radio-links)
1477 ;; Find all links that contain a newline and put them into a single line
1478 (org-export-concatenate-multiline-links)
1480 ;; Normalize links: Convert angle and plain links into bracket links
1481 ;; and expand link abbreviations
1482 (org-export-normalize-links)
1484 ;; Find all internal links. If they have a fuzzy match (i.e. not
1485 ;; a *dedicated* target match, let the link point to the
1486 ;; corresponding section.
1487 (org-export-target-internal-links target-alist)
1489 ;; Find multiline emphasis and put them into single line
1490 (when (plist-get parameters :emph-multiline)
1491 (org-export-concatenate-multiline-emphasis))
1493 (setq rtn (buffer-string)))
1494 (kill-buffer " org-mode-tmp")
1495 rtn))
1497 (defun org-export-kill-licensed-text ()
1498 "Remove all text that is marked with a :org-license-to-kill property."
1499 (let (p q)
1500 (while (setq p (text-property-any (point-min) (point-max)
1501 :org-license-to-kill t))
1502 (delete-region
1503 p (or (next-single-property-change p :org-license-to-kill)
1504 (point-max))))))
1506 (defun org-export-define-heading-targets (target-alist)
1507 "Find all headings and define the targets for them.
1508 The new targets are added to TARGET-ALIST, which is also returned."
1509 (goto-char (point-min))
1510 (org-init-section-numbers)
1511 (let ((re (concat "^" org-outline-regexp))
1512 level target)
1513 (while (re-search-forward re nil t)
1514 (setq level (org-reduced-level
1515 (save-excursion (goto-char (point-at-bol))
1516 (org-outline-level))))
1517 (setq target (org-solidify-link-text
1518 (format "sec-%s" (org-section-number level))))
1519 (push (cons target target) target-alist)
1520 (add-text-properties
1521 (point-at-bol) (point-at-eol)
1522 (list 'target target))))
1523 target-alist)
1525 (defun org-export-handle-invisible-targets (target-alist)
1526 "Find targets in comments and move them out of comments.
1527 Mark them as invisible targets."
1528 (let (target tmp)
1529 (goto-char (point-min))
1530 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1531 ;; Check if the line before or after is a headline with a target
1532 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1533 (get-text-property (point-at-bol 2) 'target)))
1534 (progn
1535 ;; use the existing target in a neighboring line
1536 (setq tmp (match-string 2))
1537 (replace-match "")
1538 (and (looking-at "\n") (delete-char 1))
1539 (push (cons (org-solidify-link-text tmp) target)
1540 target-alist))
1541 ;; Make an invisible target
1542 (replace-match "\\1(INVISIBLE)"))))
1543 target-alist)
1545 (defun org-export-target-internal-links (target-alist)
1546 "Find all internal links and assign target to them.
1547 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1548 let the link point to the corresponding section."
1549 (goto-char (point-min))
1550 (while (re-search-forward org-bracket-link-regexp nil t)
1551 (org-if-unprotected
1552 (let* ((md (match-data))
1553 (desc (match-end 2))
1554 (link (org-link-unescape (match-string 1)))
1555 (slink (org-solidify-link-text link))
1556 found props pos
1557 (target
1558 (cond
1559 ((cdr (assoc slink target-alist)))
1560 ((string-match org-link-types-re link) nil)
1561 ((or (file-name-absolute-p link)
1562 (string-match "^\\." link))
1563 nil)
1565 (save-excursion
1566 (setq found (condition-case nil (org-link-search link)
1567 (error nil)))
1568 (when (and found
1569 (or (org-on-heading-p)
1570 (not (eq found 'dedicated))))
1571 (or (get-text-property (point) 'target)
1572 (get-text-property
1573 (max (point-min)
1574 (1- (previous-single-property-change
1575 (point) 'target)))
1576 'target))))))))
1577 (when target
1578 (set-match-data md)
1579 (goto-char (match-beginning 1))
1580 (setq props (text-properties-at (point)))
1581 (delete-region (match-beginning 1) (match-end 1))
1582 (setq pos (point))
1583 (insert target)
1584 (unless desc (insert "][" link))
1585 (add-text-properties pos (point) props))))))
1587 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1588 "Remove drawers, or extract the content.
1589 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1590 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1591 whose content to keep."
1592 (unless (eq t exp-drawers)
1593 (goto-char (point-min))
1594 (let ((re (concat "^[ \t]*:\\("
1595 (mapconcat
1596 'identity
1597 (org-delete-all exp-drawers
1598 (copy-sequence all-drawers))
1599 "\\|")
1600 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1601 (while (re-search-forward re nil t)
1602 (replace-match "")))))
1604 (defun org-export-handle-export-tags (select-tags exclude-tags)
1605 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1606 Both arguments are lists of tags.
1607 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1608 will be removed.
1609 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1610 removed as well."
1611 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1612 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1613 select-tags "\\|")
1614 "\\):"))
1615 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1616 exclude-tags "\\|")
1617 "\\):"))
1618 beg end cont)
1619 (goto-char (point-min))
1620 (when (and select-tags
1621 (re-search-forward
1622 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1623 ;; At least one tree is marked for export, this means
1624 ;; all the unmarked stuff needs to go.
1625 ;; Dig out the trees that should be exported
1626 (goto-char (point-min))
1627 (outline-next-heading)
1628 (setq beg (point))
1629 (put-text-property beg (point-max) :org-delete t)
1630 (while (re-search-forward re-sel nil t)
1631 (when (org-on-heading-p)
1632 (org-back-to-heading)
1633 (remove-text-properties
1634 (max (1- (point)) (point-min))
1635 (setq cont (save-excursion (org-end-of-subtree t t)))
1636 '(:org-delete t))
1637 (while (and (org-up-heading-safe)
1638 (get-text-property (point) :org-delete))
1639 (remove-text-properties (max (1- (point)) (point-min))
1640 (point-at-eol) '(:org-delete t)))
1641 (goto-char cont))))
1642 ;; Remove the trees explicitly marked for noexport
1643 (when exclude-tags
1644 (goto-char (point-min))
1645 (while (re-search-forward re-excl nil t)
1646 (when (org-at-heading-p)
1647 (org-back-to-heading t)
1648 (setq beg (point))
1649 (org-end-of-subtree t)
1650 (delete-region beg (point)))))
1651 ;; Remove everything that is now still marked for deletion
1652 (goto-char (point-min))
1653 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1654 (setq end (or (next-single-property-change beg :org-delete)
1655 (point-max)))
1656 (delete-region beg end))))
1658 (defun org-export-remove-archived-trees (export-archived-trees)
1659 "Remove archived trees.
1660 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1661 When it is t, the entire archived tree will be exported.
1662 When it is nil the entire tree including the headline will be removed
1663 from the buffer."
1664 (let ((re-archive (concat ":" org-archive-tag ":"))
1665 a b)
1666 (when (not (eq export-archived-trees t))
1667 (goto-char (point-min))
1668 (while (re-search-forward re-archive nil t)
1669 (if (not (org-on-heading-p t))
1670 (org-end-of-subtree t)
1671 (beginning-of-line 1)
1672 (setq a (if export-archived-trees
1673 (1+ (point-at-eol)) (point))
1674 b (org-end-of-subtree t))
1675 (if (> b a) (delete-region a b)))))))
1677 (defun org-export-protect-quoted-subtrees ()
1678 "Mark quoted subtrees with the protection property."
1679 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1680 (goto-char (point-min))
1681 (while (re-search-forward re-quote nil t)
1682 (goto-char (match-beginning 0))
1683 (end-of-line 1)
1684 (add-text-properties (point) (org-end-of-subtree t)
1685 '(org-protected t)))))
1687 (defun org-export-protect-verbatim ()
1688 "Mark verbatim snippets with the protection property."
1689 (goto-char (point-min))
1690 (while (re-search-forward org-verbatim-re nil t)
1691 (add-text-properties (match-beginning 4) (match-end 4)
1692 '(org-protected t))
1693 (goto-char (1+ (match-end 4)))))
1695 (defun org-export-protect-examples (&optional indent)
1696 "Protect code that should be exported as monospaced examples."
1697 (goto-char (point-min))
1698 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1699 (goto-char (match-end 0))
1700 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1701 (insert (if indent ": " ":"))
1702 (beginning-of-line 2)))
1703 (goto-char (point-min))
1704 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1705 (add-text-properties (match-beginning 0) (match-end 0)
1706 '(org-protected t))))
1708 (defun org-export-select-backend-specific-text (backend)
1709 (let ((formatters
1710 '((html "HTML" "BEGIN_HTML" "END_HTML")
1711 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1712 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1713 fmt)
1715 (while formatters
1716 (setq fmt (pop formatters))
1717 (when (eq (car fmt) backend)
1718 ;; This is selected code, put it into the file for real
1719 (goto-char (point-min))
1720 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1721 ":[ \t]*\\(.*\\)") nil t)
1722 (replace-match "\\1" t)
1723 (add-text-properties
1724 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1725 '(org-protected t))))
1726 (goto-char (point-min))
1727 (while (re-search-forward
1728 (concat "^#\\+"
1729 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1730 (cadddr fmt) "\\>.*\n?") nil t)
1731 (if (eq (car fmt) backend)
1732 ;; yes, keep this
1733 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1734 '(org-protected t))
1735 ;; No, this is for a different backend, kill it
1736 (delete-region (match-beginning 0) (match-end 0)))))))
1738 (defun org-export-mark-blockquote-and-verse ()
1739 "Mark block quote and verse environments with special cookies.
1740 These special cookies will later be interpreted by the backend."
1741 ;; Blockquotes
1742 (goto-char (point-min))
1743 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1744 nil t)
1745 (replace-match (if (equal (downcase (match-string 1)) "end")
1746 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1747 t t))
1748 ;; Verse
1749 (goto-char (point-min))
1750 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1751 (replace-match (if (equal (downcase (match-string 1)) "end")
1752 "ORG-VERSE-END" "ORG-VERSE-START")
1753 t t)))
1755 (defun org-export-remove-comment-blocks-and-subtrees ()
1756 "Remove the comment environment, and also commented subtrees."
1757 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1758 (case-fold-search nil))
1759 ;; Remove comment environment
1760 (goto-char (point-min))
1761 (while (re-search-forward
1762 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1763 (replace-match "" t t))
1764 ;; Remove subtrees that are commented
1765 (goto-char (point-min))
1766 (while (re-search-forward re-commented nil t)
1767 (goto-char (match-beginning 0))
1768 (delete-region (point) (org-end-of-subtree t)))))
1770 (defun org-export-handle-comments (commentsp)
1771 "Remove comments, or convert to backend-specific format.
1772 COMMENTSP can be a format string for publishing comments.
1773 When it is nil, all comments will be removed."
1774 (let ((re "^#\\(.*\n?\\)")
1775 pos)
1776 (goto-char (point-min))
1777 (while (or (looking-at re)
1778 (re-search-forward re nil t))
1779 (setq pos (match-beginning 0))
1780 (if commentsp
1781 (progn (add-text-properties
1782 (match-beginning 0) (match-end 0) '(org-protected t))
1783 (replace-match (format commentsp (match-string 1)) t t))
1784 (goto-char (1+ pos))
1785 (org-if-unprotected
1786 (replace-match "")
1787 (goto-char (max (point-min) (1- pos))))))))
1789 (defun org-export-mark-radio-links ()
1790 "Find all matches for radio targets and turn them into internal links."
1791 (let ((re-radio (and org-target-link-regexp
1792 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1793 (goto-char (point-min))
1794 (when re-radio
1795 (while (re-search-forward re-radio nil t)
1796 (org-if-unprotected
1797 (replace-match "\\1[[\\2]]"))))))
1799 (defun org-export-remove-special-table-lines ()
1800 "Remove tables lines that are used for internal purposes."
1801 (goto-char (point-min))
1802 (while (re-search-forward "^[ \t]*|" nil t)
1803 (beginning-of-line 1)
1804 (if (or (looking-at "[ \t]*| *[!_^] *|")
1805 (and (looking-at ".*?| *<[0-9]+> *|")
1806 (not (looking-at ".*?| *[^ <|]"))))
1807 (delete-region (max (point-min) (1- (point-at-bol)))
1808 (point-at-eol))
1809 (end-of-line 1))))
1811 (defun org-export-normalize-links ()
1812 "Convert all links to bracket links, and expand link abbreviations."
1813 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1814 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1815 (goto-char (point-min))
1816 (while (re-search-forward re-plain-link nil t)
1817 (goto-char (1- (match-end 0)))
1818 (org-if-unprotected
1819 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1820 ":" (match-string 3) "]]")))
1821 ;; added 'org-link face to links
1822 (put-text-property 0 (length s) 'face 'org-link s)
1823 (replace-match s t t))))
1824 (goto-char (point-min))
1825 (while (re-search-forward re-angle-link nil t)
1826 (goto-char (1- (match-end 0)))
1827 (org-if-unprotected
1828 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1829 ":" (match-string 3) "]]")))
1830 (put-text-property 0 (length s) 'face 'org-link s)
1831 (replace-match s t t))))
1832 (goto-char (point-min))
1833 (while (re-search-forward org-bracket-link-regexp nil t)
1834 (goto-char (1- (match-end 0)))
1835 (org-if-unprotected
1836 (let* ((xx (save-match-data
1837 (org-link-expand-abbrev (match-string 1))))
1838 (s (concat
1839 "[[" xx "]"
1840 (if (match-end 3)
1841 (match-string 2)
1842 (concat "[" xx "]"))
1843 "]")))
1844 (put-text-property 0 (length s) 'face 'org-link s)
1845 (replace-match s t t))))))
1847 (defun org-export-concatenate-multiline-links ()
1848 "Find multi-line links and put it all into a single line.
1849 This is to make sure that the line-processing export backends
1850 can work correctly."
1851 (goto-char (point-min))
1852 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1853 (org-if-unprotected
1854 (replace-match "\\1 \\3")
1855 (goto-char (match-beginning 0)))))
1857 (defun org-export-concatenate-multiline-emphasis ()
1858 "Find multi-line emphasis and put it all into a single line.
1859 This is to make sure that the line-processing export backends
1860 can work correctly."
1861 (goto-char (point-min))
1862 (while (re-search-forward org-emph-re nil t)
1863 (if (not (= (char-after (match-beginning 3))
1864 (char-after (match-beginning 4))))
1865 (org-if-unprotected
1866 (subst-char-in-region (match-beginning 0) (match-end 0)
1867 ?\n ?\ t)
1868 (goto-char (1- (match-end 0))))
1869 (goto-char (1+ (match-beginning 0))))))
1871 (defun org-export-grab-title-from-buffer ()
1872 "Get a title for the current document, from looking at the buffer."
1873 (let ((inhibit-read-only t))
1874 (save-excursion
1875 (goto-char (point-min))
1876 (let ((end (save-excursion (outline-next-heading) (point))))
1877 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1878 ;; Mark the line so that it will not be exported as normal text.
1879 (org-unmodified
1880 (add-text-properties (match-beginning 0) (match-end 0)
1881 (list :org-license-to-kill t)))
1882 ;; Return the title string
1883 (org-trim (match-string 0)))))))
1885 (defun org-export-get-title-from-subtree ()
1886 "Return subtree title and exclude it from export."
1887 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1888 (save-excursion
1889 (goto-char rbeg)
1890 (when (and (org-at-heading-p)
1891 (>= (org-end-of-subtree t t) rend))
1892 ;; This is a subtree, we take the title from the first heading
1893 (goto-char rbeg)
1894 (looking-at org-todo-line-regexp)
1895 (setq title (match-string 3))
1896 (org-unmodified
1897 (add-text-properties (point) (1+ (point-at-eol))
1898 (list :org-license-to-kill t)))
1899 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1900 title))
1902 (defun org-solidify-link-text (s &optional alist)
1903 "Take link text and make a safe target out of it."
1904 (save-match-data
1905 (let* ((rtn
1906 (mapconcat
1907 'identity
1908 (org-split-string s "[ \t\r\n]+") "=="))
1909 (a (assoc rtn alist)))
1910 (or (cdr a) rtn))))
1912 (defun org-get-min-level (lines)
1913 "Get the minimum level in LINES."
1914 (let ((re "^\\(\\*+\\) ") l min)
1915 (catch 'exit
1916 (while (setq l (pop lines))
1917 (if (string-match re l)
1918 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1919 1)))
1921 ;; Variable holding the vector with section numbers
1922 (defvar org-section-numbers (make-vector org-level-max 0))
1924 (defun org-init-section-numbers ()
1925 "Initialize the vector for the section numbers."
1926 (let* ((level -1)
1927 (numbers (nreverse (org-split-string "" "\\.")))
1928 (depth (1- (length org-section-numbers)))
1929 (i depth) number-string)
1930 (while (>= i 0)
1931 (if (> i level)
1932 (aset org-section-numbers i 0)
1933 (setq number-string (or (car numbers) "0"))
1934 (if (string-match "\\`[A-Z]\\'" number-string)
1935 (aset org-section-numbers i
1936 (- (string-to-char number-string) ?A -1))
1937 (aset org-section-numbers i (string-to-number number-string)))
1938 (pop numbers))
1939 (setq i (1- i)))))
1941 (defun org-section-number (&optional level)
1942 "Return a string with the current section number.
1943 When LEVEL is non-nil, increase section numbers on that level."
1944 (let* ((depth (1- (length org-section-numbers)))
1945 (string "")
1946 (fmts (car org-export-section-number-format))
1947 (term (cdr org-export-section-number-format))
1948 (sep "")
1949 ctype fmt idx n)
1950 (when level
1951 (when (> level -1)
1952 (aset org-section-numbers
1953 level (1+ (aref org-section-numbers level))))
1954 (setq idx (1+ level))
1955 (while (<= idx depth)
1956 (if (not (= idx 1))
1957 (aset org-section-numbers idx 0))
1958 (setq idx (1+ idx))))
1959 (setq idx 0)
1960 (while (<= idx depth)
1961 (when (> (aref org-section-numbers idx) 0)
1962 (setq fmt (or (pop fmts) fmt)
1963 ctype (car fmt)
1964 n (aref org-section-numbers idx)
1965 string (if (> n 0)
1966 (concat string sep (org-number-to-counter n ctype))
1967 (concat string ".0"))
1968 sep (nth 1 fmt)))
1969 (setq idx (1+ idx)))
1970 (save-match-data
1971 (if (string-match "\\`\\([@0]\\.\\)+" string)
1972 (setq string (replace-match "" t nil string)))
1973 (if (string-match "\\(\\.0\\)+\\'" string)
1974 (setq string (replace-match "" t nil string))))
1975 (concat string term)))
1977 (defun org-number-to-counter (n type)
1978 "Concert number N to a string counter, according to TYPE.
1979 TYPE must be a string, any of:
1980 1 number
1981 A A,B,....
1982 a a,b,....
1983 I uppper case roman numeral
1984 i lower case roman numeral"
1985 (cond
1986 ((equal type "1") (number-to-string n))
1987 ((equal type "A") (char-to-string (+ ?A n -1)))
1988 ((equal type "a") (char-to-string (+ ?a n -1)))
1989 ((equal type "I") (org-number-to-roman n))
1990 ((equal type "i") (downcase (org-number-to-roman n)))
1991 (t (error "Invalid counter type `%s'" type))))
1993 (defun org-number-to-roman (n)
1994 "Convert integer N into a roman numeral."
1995 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1996 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1997 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1998 ( 1 . "I")))
1999 (res ""))
2000 (if (<= n 0)
2001 (number-to-string n)
2002 (while roman
2003 (if (>= n (caar roman))
2004 (setq n (- n (caar roman))
2005 res (concat res (cdar roman)))
2006 (pop roman)))
2007 res)))
2009 (org-number-to-roman 1961)
2012 ;;; Include files
2014 (defun org-export-handle-include-files ()
2015 "Include the contents of include files, with proper formatting."
2016 (let ((case-fold-search t)
2017 params file markup lang start end prefix prefix1)
2018 (goto-char (point-min))
2019 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2020 (setq params (read (concat "(" (match-string 1) ")"))
2021 prefix (org-get-and-remove-property 'params :prefix)
2022 prefix1 (org-get-and-remove-property 'params :prefix1)
2023 file (org-symname-or-string (pop params))
2024 markup (org-symname-or-string (pop params))
2025 lang (org-symname-or-string (pop params)))
2026 (delete-region (match-beginning 0) (match-end 0))
2027 (if (or (not file)
2028 (not (file-exists-p file))
2029 (not (file-readable-p file)))
2030 (insert (format "CANNOT INCLUDE FILE %s" file))
2031 (when markup
2032 (if (equal (downcase markup) "src")
2033 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2034 end "#+end_src")
2035 (setq start (format "#+begin_%s\n" markup)
2036 end (format "#+end_%s" markup))))
2037 (insert (or start ""))
2038 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2039 (or (bolp) (newline))
2040 (insert (or end ""))))))
2042 (defun org-get-file-contents (file &optional prefix prefix1)
2043 "Get the contents of FILE and return them as a string.
2044 If PREFIX is a string, prepend it to each line. If PREFIX1
2045 is a string, prepend it to the first line instead of PREFIX."
2046 (with-temp-buffer
2047 (insert-file-contents file)
2048 (when (or prefix prefix1)
2049 (goto-char (point-min))
2050 (while (not (eobp))
2051 (insert (or prefix1 prefix))
2052 (setq prefix1 nil)
2053 (beginning-of-line 2)))
2054 (buffer-string)))
2056 (defun org-get-and-remove-property (listvar prop)
2057 "Check if the value of LISTVAR contains PROP as a property.
2058 If yes, return the value of that property (i.e. the element following
2059 in the list) and remove property and value from the list in LISTVAR."
2060 (let ((list (symbol-value listvar)) m v)
2061 (when (setq m (member prop list))
2062 (setq v (nth 1 m))
2063 (if (equal (car list) prop)
2064 (set listvar (cddr list))
2065 (setcdr (nthcdr (- (length list) (length m) 1) list)
2066 (cddr m))
2067 (set listvar list)))
2070 (defun org-symname-or-string (s)
2071 (if (symbolp s)
2072 (if s (symbol-name s) s)
2075 ;;; Fontification of code
2076 ;; Currently only for the HTML backend, but who knows....
2077 (defun org-export-replace-src-segments ()
2078 "Replace source code segments with special code for export."
2079 (let ((case-fold-search t)
2080 lang code trans)
2081 (goto-char (point-min))
2082 (while (re-search-forward
2083 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2084 nil t)
2085 (setq lang (match-string 1) code (match-string 2)
2086 trans (org-export-format-source-code lang code))
2087 (replace-match trans t t))))
2089 (defvar htmlp) ;; dynamically scoped from org-exp.el
2091 (defun org-export-format-source-code (lang code)
2092 "Format CODE from language LANG and return it formatted for export.
2093 Currently, this only does something for HTML export, for all other
2094 backends, it converts the segment into an EXAMPLE segment."
2095 (save-match-data
2096 (cond
2097 (htmlp
2098 ;; We are exporting to HTML
2099 (condition-case nil (require 'htmlize) (nil t))
2100 (if (not (fboundp 'htmlize-region-for-paste))
2101 (progn
2102 ;; we do not have htmlize.el, or an old version of it
2103 (message
2104 "htmlize.el 1.34 or later is needed for source code formatting")
2105 (concat "#+BEGIN_EXAMPLE\n" code
2106 (if (string-match "\n\\'" code) "" "\n")
2107 "#+END_EXAMPLE\n"))
2108 ;; ok, we are good to go
2109 (let* ((mode (and lang (intern (concat lang "-mode"))))
2110 (org-inhibit-startup t)
2111 (org-startup-folded nil)
2112 (htmltext
2113 (with-temp-buffer
2114 (insert code)
2115 ;; Free up the protected stuff
2116 (goto-char (point-min))
2117 (while (re-search-forward "^," nil t)
2118 (replace-match "")
2119 (end-of-line 1))
2120 (if (functionp mode)
2121 (funcall mode)
2122 (fundamental-mode))
2123 (font-lock-fontify-buffer)
2124 (org-export-htmlize-region-for-paste
2125 (point-min) (point-max)))))
2126 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2127 (setq htmltext (replace-match
2128 (format "<pre class=\"src src-%s\">" lang)
2129 t t htmltext)))
2130 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2132 ;; This is not HTML, so just make it an example.
2133 (when (equal lang "org")
2134 (while (string-match "^," code)
2135 (setq code (replace-match "" t t code))))
2136 (concat "#+BEGIN_EXAMPLE\n" code
2137 (if (string-match "\n\\'" code) "" "\n")
2138 "#+END_EXAMPLE\n")))))
2140 ;;; ASCII export
2142 (defvar org-last-level nil) ; dynamically scoped variable
2143 (defvar org-min-level nil) ; dynamically scoped variable
2144 (defvar org-levels-open nil) ; dynamically scoped parameter
2145 (defvar org-ascii-current-indentation nil) ; For communication
2147 ;;;###autoload
2148 (defun org-export-as-ascii (arg)
2149 "Export the outline as a pretty ASCII file.
2150 If there is an active region, export only the region.
2151 The prefix ARG specifies how many levels of the outline should become
2152 underlined headlines. The default is 3."
2153 (interactive "P")
2154 (setq-default org-todo-line-regexp org-todo-line-regexp)
2155 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2156 (org-infile-export-plist)))
2157 (region-p (org-region-active-p))
2158 (rbeg (and region-p (region-beginning)))
2159 (rend (and region-p (region-end)))
2160 (subtree-p
2161 (when region-p
2162 (save-excursion
2163 (goto-char rbeg)
2164 (and (org-at-heading-p)
2165 (>= (org-end-of-subtree t t) rend)))))
2166 (opt-plist (if subtree-p
2167 (org-export-add-subtree-options opt-plist rbeg)
2168 opt-plist))
2169 (custom-times org-display-custom-times)
2170 (org-ascii-current-indentation '(0 . 0))
2171 (level 0) line txt
2172 (umax nil)
2173 (umax-toc nil)
2174 (case-fold-search nil)
2175 (filename (concat (file-name-as-directory
2176 (org-export-directory :ascii opt-plist))
2177 (file-name-sans-extension
2178 (or (and subtree-p
2179 (org-entry-get (region-beginning)
2180 "EXPORT_FILE_NAME" t))
2181 (file-name-nondirectory buffer-file-name)))
2182 ".txt"))
2183 (filename (if (equal (file-truename filename)
2184 (file-truename buffer-file-name))
2185 (concat filename ".txt")
2186 filename))
2187 (buffer (find-file-noselect filename))
2188 (org-levels-open (make-vector org-level-max nil))
2189 (odd org-odd-levels-only)
2190 (date (plist-get opt-plist :date))
2191 (author (plist-get opt-plist :author))
2192 (title (or (and subtree-p (org-export-get-title-from-subtree))
2193 (plist-get opt-plist :title)
2194 (and (not
2195 (plist-get opt-plist :skip-before-1st-heading))
2196 (org-export-grab-title-from-buffer))
2197 (file-name-sans-extension
2198 (file-name-nondirectory buffer-file-name))))
2199 (email (plist-get opt-plist :email))
2200 (language (plist-get opt-plist :language))
2201 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2202 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2203 (todo nil)
2204 (lang-words nil)
2205 (region
2206 (buffer-substring
2207 (if (org-region-active-p) (region-beginning) (point-min))
2208 (if (org-region-active-p) (region-end) (point-max))))
2209 (lines (org-split-string
2210 (org-export-preprocess-string
2211 region
2212 :for-ascii t
2213 :skip-before-1st-heading
2214 (plist-get opt-plist :skip-before-1st-heading)
2215 :drawers (plist-get opt-plist :drawers)
2216 :verbatim-multiline t
2217 :select-tags (plist-get opt-plist :select-tags)
2218 :exclude-tags (plist-get opt-plist :exclude-tags)
2219 :archived-trees
2220 (plist-get opt-plist :archived-trees)
2221 :add-text (plist-get opt-plist :text))
2222 "\n"))
2223 thetoc have-headings first-heading-pos
2224 table-open table-buffer)
2226 (let ((inhibit-read-only t))
2227 (org-unmodified
2228 (remove-text-properties (point-min) (point-max)
2229 '(:org-license-to-kill t))))
2231 (setq org-min-level (org-get-min-level lines))
2232 (setq org-last-level org-min-level)
2233 (org-init-section-numbers)
2235 (find-file-noselect filename)
2237 (setq lang-words (or (assoc language org-export-language-setup)
2238 (assoc "en" org-export-language-setup)))
2239 (switch-to-buffer-other-window buffer)
2240 (erase-buffer)
2241 (fundamental-mode)
2242 ;; create local variables for all options, to make sure all called
2243 ;; functions get the correct information
2244 (mapc (lambda (x)
2245 (set (make-local-variable (cdr x))
2246 (plist-get opt-plist (car x))))
2247 org-export-plist-vars)
2248 (org-set-local 'org-odd-levels-only odd)
2249 (setq umax (if arg (prefix-numeric-value arg)
2250 org-export-headline-levels))
2251 (setq umax-toc (if (integerp org-export-with-toc)
2252 (min org-export-with-toc umax)
2253 umax))
2255 ;; File header
2256 (if title (org-insert-centered title ?=))
2257 (insert "\n")
2258 (if (and (or author email)
2259 org-export-author-info)
2260 (insert (concat (nth 1 lang-words) ": " (or author "")
2261 (if email (concat " <" email ">") "")
2262 "\n")))
2264 (cond
2265 ((and date (string-match "%" date))
2266 (setq date (format-time-string date)))
2267 (date)
2268 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2270 (if (and date org-export-time-stamp-file)
2271 (insert (concat (nth 2 lang-words) ": " date"\n")))
2273 (insert "\n\n")
2275 (if org-export-with-toc
2276 (progn
2277 (push (concat (nth 3 lang-words) "\n") thetoc)
2278 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2279 "\n") thetoc)
2280 (mapc '(lambda (line)
2281 (if (string-match org-todo-line-regexp
2282 line)
2283 ;; This is a headline
2284 (progn
2285 (setq have-headings t)
2286 (setq level (- (match-end 1) (match-beginning 1))
2287 level (org-tr-level level)
2288 txt (match-string 3 line)
2289 todo
2290 (or (and org-export-mark-todo-in-toc
2291 (match-beginning 2)
2292 (not (member (match-string 2 line)
2293 org-done-keywords)))
2294 ; TODO, not DONE
2295 (and org-export-mark-todo-in-toc
2296 (= level umax-toc)
2297 (org-search-todo-below
2298 line lines level))))
2299 (setq txt (org-html-expand-for-ascii txt))
2301 (while (string-match org-bracket-link-regexp txt)
2302 (setq txt
2303 (replace-match
2304 (match-string (if (match-end 2) 3 1) txt)
2305 t t txt)))
2307 (if (and (memq org-export-with-tags '(not-in-toc nil))
2308 (string-match
2309 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2310 txt))
2311 (setq txt (replace-match "" t t txt)))
2312 (if (string-match quote-re0 txt)
2313 (setq txt (replace-match "" t t txt)))
2315 (if org-export-with-section-numbers
2316 (setq txt (concat (org-section-number level)
2317 " " txt)))
2318 (if (<= level umax-toc)
2319 (progn
2320 (push
2321 (concat
2322 (make-string
2323 (* (max 0 (- level org-min-level)) 4) ?\ )
2324 (format (if todo "%s (*)\n" "%s\n") txt))
2325 thetoc)
2326 (setq org-last-level level))
2327 ))))
2328 lines)
2329 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2331 (org-init-section-numbers)
2332 (while (setq line (pop lines))
2333 ;; Remove the quoted HTML tags.
2334 (setq line (org-html-expand-for-ascii line))
2335 ;; Remove targets
2336 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2337 (setq line (replace-match "" t t line)))
2338 ;; Replace internal links
2339 (while (string-match org-bracket-link-regexp line)
2340 (setq line (replace-match
2341 (if (match-end 3) "[\\3]" "[\\1]")
2342 t nil line)))
2343 (when custom-times
2344 (setq line (org-translate-time line)))
2345 (cond
2346 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2347 ;; a Headline
2348 (setq first-heading-pos (or first-heading-pos (point)))
2349 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2350 txt (match-string 2 line))
2351 (org-ascii-level-start level txt umax lines))
2353 ((and org-export-with-tables
2354 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2355 (if (not table-open)
2356 ;; New table starts
2357 (setq table-open t table-buffer nil))
2358 ;; Accumulate lines
2359 (setq table-buffer (cons line table-buffer))
2360 (when (or (not lines)
2361 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2362 (car lines))))
2363 (setq table-open nil
2364 table-buffer (nreverse table-buffer))
2365 (insert (mapconcat
2366 (lambda (x)
2367 (org-fix-indentation x org-ascii-current-indentation))
2368 (org-format-table-ascii table-buffer)
2369 "\n") "\n")))
2371 (setq line (org-fix-indentation line org-ascii-current-indentation))
2372 (if (and org-export-with-fixed-width
2373 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2374 (setq line (replace-match "\\1" nil nil line)))
2375 (insert line "\n"))))
2377 (normal-mode)
2379 ;; insert the table of contents
2380 (when thetoc
2381 (goto-char (point-min))
2382 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2383 (progn
2384 (goto-char (match-beginning 0))
2385 (replace-match ""))
2386 (goto-char first-heading-pos))
2387 (mapc 'insert thetoc)
2388 (or (looking-at "[ \t]*\n[ \t]*\n")
2389 (insert "\n\n")))
2391 ;; Convert whitespace place holders
2392 (goto-char (point-min))
2393 (let (beg end)
2394 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2395 (setq end (next-single-property-change beg 'org-whitespace))
2396 (goto-char beg)
2397 (delete-region beg end)
2398 (insert (make-string (- end beg) ?\ ))))
2400 (save-buffer)
2401 ;; remove display and invisible chars
2402 (let (beg end)
2403 (goto-char (point-min))
2404 (while (setq beg (next-single-property-change (point) 'display))
2405 (setq end (next-single-property-change beg 'display))
2406 (delete-region beg end)
2407 (goto-char beg)
2408 (insert "=>"))
2409 (goto-char (point-min))
2410 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2411 (setq end (next-single-property-change beg 'org-cwidth))
2412 (delete-region beg end)
2413 (goto-char beg)))
2414 (goto-char (point-min))))
2416 (defun org-export-ascii-preprocess ()
2417 "Do extra work for ASCII export"
2418 (goto-char (point-min))
2419 (while (re-search-forward org-verbatim-re nil t)
2420 (goto-char (match-end 2))
2421 (backward-delete-char 1) (insert "'")
2422 (goto-char (match-beginning 2))
2423 (delete-char 1) (insert "`")
2424 (goto-char (match-end 2))))
2426 (defun org-search-todo-below (line lines level)
2427 "Search the subtree below LINE for any TODO entries."
2428 (let ((rest (cdr (memq line lines)))
2429 (re org-todo-line-regexp)
2430 line lv todo)
2431 (catch 'exit
2432 (while (setq line (pop rest))
2433 (if (string-match re line)
2434 (progn
2435 (setq lv (- (match-end 1) (match-beginning 1))
2436 todo (and (match-beginning 2)
2437 (not (member (match-string 2 line)
2438 org-done-keywords))))
2439 ; TODO, not DONE
2440 (if (<= lv level) (throw 'exit nil))
2441 (if todo (throw 'exit t))))))))
2443 (defun org-html-expand-for-ascii (line)
2444 "Handle quoted HTML for ASCII export."
2445 (if org-export-html-expand
2446 (while (string-match "@<[^<>\n]*>" line)
2447 ;; We just remove the tags for now.
2448 (setq line (replace-match "" nil nil line))))
2449 line)
2451 (defun org-insert-centered (s &optional underline)
2452 "Insert the string S centered and underline it with character UNDERLINE."
2453 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2454 (insert (make-string ind ?\ ) s "\n")
2455 (if underline
2456 (insert (make-string ind ?\ )
2457 (make-string (string-width s) underline)
2458 "\n"))))
2460 (defun org-ascii-level-start (level title umax &optional lines)
2461 "Insert a new level in ASCII export."
2462 (let (char (n (- level umax 1)) (ind 0))
2463 (if (> level umax)
2464 (progn
2465 (insert (make-string (* 2 n) ?\ )
2466 (char-to-string (nth (% n (length org-export-ascii-bullets))
2467 org-export-ascii-bullets))
2468 " " title "\n")
2469 ;; find the indentation of the next non-empty line
2470 (catch 'stop
2471 (while lines
2472 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2473 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2474 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2475 (pop lines)))
2476 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2477 (if (or (not (equal (char-before) ?\n))
2478 (not (equal (char-before (1- (point))) ?\n)))
2479 (insert "\n"))
2480 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2481 (unless org-export-with-tags
2482 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2483 (setq title (replace-match "" t t title))))
2484 (if org-export-with-section-numbers
2485 (setq title (concat (org-section-number level) " " title)))
2486 (insert title "\n" (make-string (string-width title) char) "\n")
2487 (setq org-ascii-current-indentation '(0 . 0)))))
2489 ;;;###autoload
2490 (defun org-export-visible (type arg)
2491 "Create a copy of the visible part of the current buffer, and export it.
2492 The copy is created in a temporary buffer and removed after use.
2493 TYPE is the final key (as a string) that also select the export command in
2494 the `C-c C-e' export dispatcher.
2495 As a special case, if the you type SPC at the prompt, the temporary
2496 org-mode file will not be removed but presented to you so that you can
2497 continue to use it. The prefix arg ARG is passed through to the exporting
2498 command."
2499 (interactive
2500 (list (progn
2501 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2502 (read-char-exclusive))
2503 current-prefix-arg))
2504 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2505 (error "Invalid export key"))
2506 (let* ((binding (cdr (assoc type
2507 '((?a . org-export-as-ascii)
2508 (?\C-a . org-export-as-ascii)
2509 (?b . org-export-as-html-and-open)
2510 (?\C-b . org-export-as-html-and-open)
2511 (?h . org-export-as-html)
2512 (?H . org-export-as-html-to-buffer)
2513 (?R . org-export-region-as-html)
2514 (?x . org-export-as-xoxo)))))
2515 (keepp (equal type ?\ ))
2516 (file buffer-file-name)
2517 (buffer (get-buffer-create "*Org Export Visible*"))
2518 s e)
2519 ;; Need to hack the drawers here.
2520 (save-excursion
2521 (goto-char (point-min))
2522 (while (re-search-forward org-drawer-regexp nil t)
2523 (goto-char (match-beginning 1))
2524 (or (org-invisible-p) (org-flag-drawer nil))))
2525 (with-current-buffer buffer (erase-buffer))
2526 (save-excursion
2527 (setq s (goto-char (point-min)))
2528 (while (not (= (point) (point-max)))
2529 (goto-char (org-find-invisible))
2530 (append-to-buffer buffer s (point))
2531 (setq s (goto-char (org-find-visible))))
2532 (org-cycle-hide-drawers 'all)
2533 (goto-char (point-min))
2534 (unless keepp
2535 ;; Copy all comment lines to the end, to make sure #+ settings are
2536 ;; still available for the second export step. Kind of a hack, but
2537 ;; does do the trick.
2538 (if (looking-at "#[^\r\n]*")
2539 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2540 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2541 (append-to-buffer buffer (1+ (match-beginning 0))
2542 (min (point-max) (1+ (match-end 0))))))
2543 (set-buffer buffer)
2544 (let ((buffer-file-name file)
2545 (org-inhibit-startup t))
2546 (org-mode)
2547 (show-all)
2548 (unless keepp (funcall binding arg))))
2549 (if (not keepp)
2550 (kill-buffer buffer)
2551 (switch-to-buffer-other-window buffer)
2552 (goto-char (point-min)))))
2554 (defun org-find-visible ()
2555 (let ((s (point)))
2556 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2557 (get-char-property s 'invisible)))
2559 (defun org-find-invisible ()
2560 (let ((s (point)))
2561 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2562 (not (get-char-property s 'invisible))))
2565 ;;; HTML export
2567 (defvar org-archive-location) ;; gets loades with the org-archive require.
2568 (defun org-get-current-options ()
2569 "Return a string with current options as keyword options.
2570 Does include HTML export options as well as TODO and CATEGORY stuff."
2571 (require 'org-archive)
2572 (format
2573 "#+TITLE: %s
2574 #+AUTHOR: %s
2575 #+EMAIL: %s
2576 #+DATE: %s
2577 #+LANGUAGE: %s
2578 #+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
2580 #+EXPORT_SELECT_TAGS: %s
2581 #+EXPORT_EXCUDE_TAGS: %s
2582 #+LINK_UP: %s
2583 #+LINK_HOME: %s
2584 #+CATEGORY: %s
2585 #+SEQ_TODO: %s
2586 #+TYP_TODO: %s
2587 #+PRIORITIES: %c %c %c
2588 #+DRAWERS: %s
2589 #+STARTUP: %s %s %s %s %s
2590 #+TAGS: %s
2591 #+FILETAGS: %s
2592 #+ARCHIVE: %s
2593 #+LINK: %s
2595 (buffer-name) (user-full-name) user-mail-address
2596 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2597 org-export-default-language
2598 org-export-headline-levels
2599 org-export-with-section-numbers
2600 org-export-with-toc
2601 org-export-preserve-breaks
2602 org-export-html-expand
2603 org-export-with-fixed-width
2604 org-export-with-tables
2605 org-export-with-sub-superscripts
2606 org-export-with-special-strings
2607 org-export-with-footnotes
2608 org-export-with-emphasize
2609 org-export-with-TeX-macros
2610 org-export-with-LaTeX-fragments
2611 org-export-skip-text-before-1st-heading
2612 org-export-with-drawers
2613 org-export-with-tags
2614 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2615 (mapconcat 'identity org-export-select-tags " ")
2616 (mapconcat 'identity org-export-exclude-tags " ")
2617 org-export-html-link-up
2618 org-export-html-link-home
2619 (file-name-nondirectory buffer-file-name)
2620 "TODO FEEDBACK VERIFY DONE"
2621 "Me Jason Marie DONE"
2622 org-highest-priority org-lowest-priority org-default-priority
2623 (mapconcat 'identity org-drawers " ")
2624 (cdr (assoc org-startup-folded
2625 '((nil . "showall") (t . "overview") (content . "content"))))
2626 (if org-odd-levels-only "odd" "oddeven")
2627 (if org-hide-leading-stars "hidestars" "showstars")
2628 (if org-startup-align-all-tables "align" "noalign")
2629 (cond ((eq org-log-done t) "logdone")
2630 ((equal org-log-done 'note) "lognotedone")
2631 ((not org-log-done) "nologdone"))
2632 (or (mapconcat (lambda (x)
2633 (cond
2634 ((equal '(:startgroup) x) "{")
2635 ((equal '(:endgroup) x) "}")
2636 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2637 (t (car x))))
2638 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2639 (mapconcat 'identity org-file-tags " ")
2640 org-archive-location
2641 "org file:~/org/%s.org"
2644 (defun org-export-html-preprocess (parameters)
2645 ;; Convert LaTeX fragments to images
2646 (when (plist-get parameters :LaTeX-fragments)
2647 (org-format-latex
2648 (concat "ltxpng/" (file-name-sans-extension
2649 (file-name-nondirectory
2650 org-current-export-file)))
2651 org-current-export-dir nil "Creating LaTeX image %s"))
2652 (message "Exporting..."))
2654 ;;;###autoload
2655 (defun org-insert-export-options-template ()
2656 "Insert into the buffer a template with information for exporting."
2657 (interactive)
2658 (if (not (bolp)) (newline))
2659 (let ((s (org-get-current-options)))
2660 (and (string-match "#\\+CATEGORY" s)
2661 (setq s (substring s 0 (match-beginning 0))))
2662 (insert s)))
2664 ;;;###autoload
2665 (defun org-export-as-html-and-open (arg)
2666 "Export the outline as HTML and immediately open it with a browser.
2667 If there is an active region, export only the region.
2668 The prefix ARG specifies how many levels of the outline should become
2669 headlines. The default is 3. Lower levels will become bulleted lists."
2670 (interactive "P")
2671 (org-export-as-html arg 'hidden)
2672 (org-open-file buffer-file-name))
2674 ;;;###autoload
2675 (defun org-export-as-html-batch ()
2676 "Call `org-export-as-html', may be used in batch processing as
2677 emacs --batch
2678 --load=$HOME/lib/emacs/org.el
2679 --eval \"(setq org-export-headline-levels 2)\"
2680 --visit=MyFile --funcall org-export-as-html-batch"
2681 (org-export-as-html org-export-headline-levels 'hidden))
2683 ;;;###autoload
2684 (defun org-export-as-html-to-buffer (arg)
2685 "Call `org-exort-as-html` with output to a temporary buffer.
2686 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2687 (interactive "P")
2688 (org-export-as-html arg nil nil "*Org HTML Export*")
2689 (switch-to-buffer-other-window "*Org HTML Export*"))
2691 ;;;###autoload
2692 (defun org-replace-region-by-html (beg end)
2693 "Assume the current region has org-mode syntax, and convert it to HTML.
2694 This can be used in any buffer. For example, you could write an
2695 itemized list in org-mode syntax in an HTML buffer and then use this
2696 command to convert it."
2697 (interactive "r")
2698 (let (reg html buf pop-up-frames)
2699 (save-window-excursion
2700 (if (org-mode-p)
2701 (setq html (org-export-region-as-html
2702 beg end t 'string))
2703 (setq reg (buffer-substring beg end)
2704 buf (get-buffer-create "*Org tmp*"))
2705 (with-current-buffer buf
2706 (erase-buffer)
2707 (insert reg)
2708 (org-mode)
2709 (setq html (org-export-region-as-html
2710 (point-min) (point-max) t 'string)))
2711 (kill-buffer buf)))
2712 (delete-region beg end)
2713 (insert html)))
2715 ;;;###autoload
2716 (defun org-export-region-as-html (beg end &optional body-only buffer)
2717 "Convert region from BEG to END in org-mode buffer to HTML.
2718 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2719 contents, and only produce the region of converted text, useful for
2720 cut-and-paste operations.
2721 If BUFFER is a buffer or a string, use/create that buffer as a target
2722 of the converted HTML. If BUFFER is the symbol `string', return the
2723 produced HTML as a string and leave not buffer behind. For example,
2724 a Lisp program could call this function in the following way:
2726 (setq html (org-export-region-as-html beg end t 'string))
2728 When called interactively, the output buffer is selected, and shown
2729 in a window. A non-interactive call will only return the buffer."
2730 (interactive "r\nP")
2731 (when (interactive-p)
2732 (setq buffer "*Org HTML Export*"))
2733 (let ((transient-mark-mode t) (zmacs-regions t)
2734 ext-plist rtn)
2735 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2736 (goto-char end)
2737 (set-mark (point)) ;; to activate the region
2738 (goto-char beg)
2739 (setq rtn (org-export-as-html
2740 nil nil ext-plist
2741 buffer body-only))
2742 (if (fboundp 'deactivate-mark) (deactivate-mark))
2743 (if (and (interactive-p) (bufferp rtn))
2744 (switch-to-buffer-other-window rtn)
2745 rtn)))
2747 (defvar html-table-tag nil) ; dynamically scoped into this.
2748 ;;;###autoload
2749 (defun org-export-as-html (arg &optional hidden ext-plist
2750 to-buffer body-only pub-dir)
2751 "Export the outline as a pretty HTML file.
2752 If there is an active region, export only the region. The prefix
2753 ARG specifies how many levels of the outline should become
2754 headlines. The default is 3. Lower levels will become bulleted
2755 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2756 EXT-PLIST is a property list with external parameters overriding
2757 org-mode's default settings, but still inferior to file-local
2758 settings. When TO-BUFFER is non-nil, create a buffer with that
2759 name and export to that buffer. If TO-BUFFER is the symbol
2760 `string', don't leave any buffer behind but just return the
2761 resulting HTML as a string. When BODY-ONLY is set, don't produce
2762 the file header and footer, simply return the content of
2763 <body>...</body>, without even the body tags themselves. When
2764 PUB-DIR is set, use this as the publishing directory."
2765 (interactive "P")
2767 ;; Make sure we have a file name when we need it.
2768 (when (and (not (or to-buffer body-only))
2769 (not buffer-file-name))
2770 (if (buffer-base-buffer)
2771 (org-set-local 'buffer-file-name
2772 (with-current-buffer (buffer-base-buffer)
2773 buffer-file-name))
2774 (error "Need a file name to be able to export.")))
2776 (message "Exporting...")
2777 (setq-default org-todo-line-regexp org-todo-line-regexp)
2778 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2779 (setq-default org-done-keywords org-done-keywords)
2780 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2781 (let* ((opt-plist
2782 (org-export-process-option-filters
2783 (org-combine-plists (org-default-export-plist)
2784 ext-plist
2785 (org-infile-export-plist))))
2787 (style (concat org-export-html-style-default
2788 (plist-get opt-plist :style)
2789 (plist-get opt-plist :style-extra)))
2790 (html-extension (plist-get opt-plist :html-extension))
2791 (link-validate (plist-get opt-plist :link-validation-function))
2792 valid thetoc have-headings first-heading-pos
2793 (odd org-odd-levels-only)
2794 (region-p (org-region-active-p))
2795 (rbeg (and region-p (region-beginning)))
2796 (rend (and region-p (region-end)))
2797 (subtree-p
2798 (if (plist-get opt-plist :ignore-subree-p)
2800 (when region-p
2801 (save-excursion
2802 (goto-char rbeg)
2803 (and (org-at-heading-p)
2804 (>= (org-end-of-subtree t t) rend))))))
2805 (opt-plist (if subtree-p
2806 (org-export-add-subtree-options opt-plist rbeg)
2807 opt-plist))
2808 ;; The following two are dynamically scoped into other
2809 ;; routines below.
2810 (org-current-export-dir
2811 (or pub-dir (org-export-directory :html opt-plist)))
2812 (org-current-export-file buffer-file-name)
2813 (level 0) (line "") (origline "") txt todo
2814 (umax nil)
2815 (umax-toc nil)
2816 (filename (if to-buffer nil
2817 (expand-file-name
2818 (concat
2819 (file-name-sans-extension
2820 (or (and subtree-p
2821 (org-entry-get (region-beginning)
2822 "EXPORT_FILE_NAME" t))
2823 (file-name-nondirectory buffer-file-name)))
2824 "." html-extension)
2825 (file-name-as-directory
2826 (or pub-dir (org-export-directory :html opt-plist))))))
2827 (current-dir (if buffer-file-name
2828 (file-name-directory buffer-file-name)
2829 default-directory))
2830 (buffer (if to-buffer
2831 (cond
2832 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2833 (t (get-buffer-create to-buffer)))
2834 (find-file-noselect filename)))
2835 (org-levels-open (make-vector org-level-max nil))
2836 (date (plist-get opt-plist :date))
2837 (author (plist-get opt-plist :author))
2838 (title (or (and subtree-p (org-export-get-title-from-subtree))
2839 (plist-get opt-plist :title)
2840 (and (not
2841 (plist-get opt-plist :skip-before-1st-heading))
2842 (org-export-grab-title-from-buffer))
2843 (and buffer-file-name
2844 (file-name-sans-extension
2845 (file-name-nondirectory buffer-file-name)))
2846 "UNTITLED"))
2847 (html-table-tag (plist-get opt-plist :html-table-tag))
2848 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2849 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2850 (inquote nil)
2851 (infixed nil)
2852 (inverse nil)
2853 (in-local-list nil)
2854 (local-list-type nil)
2855 (local-list-indent nil)
2856 (llt org-plain-list-ordered-item-terminator)
2857 (email (plist-get opt-plist :email))
2858 (language (plist-get opt-plist :language))
2859 (lang-words nil)
2860 (head-count 0) cnt
2861 (start 0)
2862 (coding-system (and (boundp 'buffer-file-coding-system)
2863 buffer-file-coding-system))
2864 (coding-system-for-write (or org-export-html-coding-system
2865 coding-system))
2866 (save-buffer-coding-system (or org-export-html-coding-system
2867 coding-system))
2868 (charset (and coding-system-for-write
2869 (fboundp 'coding-system-get)
2870 (coding-system-get coding-system-for-write
2871 'mime-charset)))
2872 (region
2873 (buffer-substring
2874 (if region-p (region-beginning) (point-min))
2875 (if region-p (region-end) (point-max))))
2876 (lines
2877 (org-split-string
2878 (org-export-preprocess-string
2879 region
2880 :emph-multiline t
2881 :for-html t
2882 :skip-before-1st-heading
2883 (plist-get opt-plist :skip-before-1st-heading)
2884 :drawers (plist-get opt-plist :drawers)
2885 :archived-trees
2886 (plist-get opt-plist :archived-trees)
2887 :select-tags (plist-get opt-plist :select-tags)
2888 :exclude-tags (plist-get opt-plist :exclude-tags)
2889 :add-text
2890 (plist-get opt-plist :text)
2891 :LaTeX-fragments
2892 (plist-get opt-plist :LaTeX-fragments))
2893 "[\r\n]"))
2894 table-open type
2895 table-buffer table-orig-buffer
2896 ind item-type starter didclose
2897 rpl path attr desc descp desc1 desc2 link
2898 snumber fnc item-tag
2901 (let ((inhibit-read-only t))
2902 (org-unmodified
2903 (remove-text-properties (point-min) (point-max)
2904 '(:org-license-to-kill t))))
2906 (message "Exporting...")
2908 (setq org-min-level (org-get-min-level lines))
2909 (setq org-last-level org-min-level)
2910 (org-init-section-numbers)
2912 (cond
2913 ((and date (string-match "%" date))
2914 (setq date (format-time-string date)))
2915 (date)
2916 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2918 ;; Get the language-dependent settings
2919 (setq lang-words (or (assoc language org-export-language-setup)
2920 (assoc "en" org-export-language-setup)))
2922 ;; Switch to the output buffer
2923 (set-buffer buffer)
2924 (let ((inhibit-read-only t)) (erase-buffer))
2925 (fundamental-mode)
2927 (and (fboundp 'set-buffer-file-coding-system)
2928 (set-buffer-file-coding-system coding-system-for-write))
2930 (let ((case-fold-search nil)
2931 (org-odd-levels-only odd))
2932 ;; create local variables for all options, to make sure all called
2933 ;; functions get the correct information
2934 (mapc (lambda (x)
2935 (set (make-local-variable (cdr x))
2936 (plist-get opt-plist (car x))))
2937 org-export-plist-vars)
2938 (setq umax (if arg (prefix-numeric-value arg)
2939 org-export-headline-levels))
2940 (setq umax-toc (if (integerp org-export-with-toc)
2941 (min org-export-with-toc umax)
2942 umax))
2943 (unless body-only
2944 ;; File header
2945 (insert (format
2946 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2947 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2948 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2949 lang=\"%s\" xml:lang=\"%s\">
2950 <head>
2951 <title>%s</title>
2952 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2953 <meta name=\"generator\" content=\"Org-mode\"/>
2954 <meta name=\"generated\" content=\"%s\"/>
2955 <meta name=\"author\" content=\"%s\"/>
2957 </head><body>
2959 language language (org-html-expand title)
2960 (or charset "iso-8859-1") date author style))
2962 (insert (or (plist-get opt-plist :preamble) ""))
2964 (when (plist-get opt-plist :auto-preamble)
2965 (if title (insert (format org-export-html-title-format
2966 (org-html-expand title))))))
2968 (if (and org-export-with-toc (not body-only))
2969 (progn
2970 (push (format "<h%d>%s</h%d>\n"
2971 org-export-html-toplevel-hlevel
2972 (nth 3 lang-words)
2973 org-export-html-toplevel-hlevel)
2974 thetoc)
2975 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2976 (push "<ul>\n<li>" thetoc)
2977 (setq lines
2978 (mapcar '(lambda (line)
2979 (if (string-match org-todo-line-regexp line)
2980 ;; This is a headline
2981 (progn
2982 (setq have-headings t)
2983 (setq level (- (match-end 1) (match-beginning 1))
2984 level (org-tr-level level)
2985 txt (save-match-data
2986 (org-html-expand
2987 (org-export-cleanup-toc-line
2988 (match-string 3 line))))
2989 todo
2990 (or (and org-export-mark-todo-in-toc
2991 (match-beginning 2)
2992 (not (member (match-string 2 line)
2993 org-done-keywords)))
2994 ; TODO, not DONE
2995 (and org-export-mark-todo-in-toc
2996 (= level umax-toc)
2997 (org-search-todo-below
2998 line lines level))))
2999 (if (string-match
3000 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3001 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3002 (if (string-match quote-re0 txt)
3003 (setq txt (replace-match "" t t txt)))
3004 (setq snumber (org-section-number level))
3005 (if org-export-with-section-numbers
3006 (setq txt (concat snumber " " txt)))
3007 (if (<= level (max umax umax-toc))
3008 (setq head-count (+ head-count 1)))
3009 (if (<= level umax-toc)
3010 (progn
3011 (if (> level org-last-level)
3012 (progn
3013 (setq cnt (- level org-last-level))
3014 (while (>= (setq cnt (1- cnt)) 0)
3015 (push "\n<ul>\n<li>" thetoc))
3016 (push "\n" thetoc)))
3017 (if (< level org-last-level)
3018 (progn
3019 (setq cnt (- org-last-level level))
3020 (while (>= (setq cnt (1- cnt)) 0)
3021 (push "</li>\n</ul>" thetoc))
3022 (push "\n" thetoc)))
3023 ;; Check for targets
3024 (while (string-match org-any-target-regexp line)
3025 (setq line (replace-match
3026 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3027 t t line)))
3028 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3029 (setq txt (replace-match "" t t txt)))
3030 (push
3031 (format
3032 (if todo
3033 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3034 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3035 snumber txt) thetoc)
3037 (setq org-last-level level))
3039 line)
3040 lines))
3041 (while (> org-last-level (1- org-min-level))
3042 (setq org-last-level (1- org-last-level))
3043 (push "</li>\n</ul>\n" thetoc))
3044 (push "</div>\n" thetoc)
3045 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3047 (setq head-count 0)
3048 (org-init-section-numbers)
3050 (org-open-par)
3052 (while (setq line (pop lines) origline line)
3053 (catch 'nextline
3055 ;; end of quote section?
3056 (when (and inquote (string-match "^\\*+ " line))
3057 (insert "</pre>\n")
3058 (setq inquote nil))
3059 ;; inside a quote section?
3060 (when inquote
3061 (insert (org-html-protect line) "\n")
3062 (throw 'nextline nil))
3064 ;; Fixed-width, verbatim lines (examples)
3065 (when (and org-export-with-fixed-width
3066 (string-match "^[ \t]*:\\(.*\\)" line))
3067 (when (not infixed)
3068 (setq infixed t)
3069 (insert "<pre class=\"example\">\n"))
3070 (insert (org-html-protect (match-string 1 line)) "\n")
3071 (when (or (not lines)
3072 (not (string-match "^[ \t]*\\(:.*\\)"
3073 (car lines))))
3074 (setq infixed nil)
3075 (insert "</pre>\n"))
3076 (throw 'nextline nil))
3078 ;; Protected HTML
3079 (when (get-text-property 0 'org-protected line)
3080 (let (par)
3081 (when (re-search-backward
3082 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3083 (setq par (match-string 1))
3084 (replace-match "\\2\n"))
3085 (insert line "\n")
3086 (while (and lines
3087 (not (string-match "^[ \t]*:" (car lines)))
3088 (or (= (length (car lines)) 0)
3089 (get-text-property 0 'org-protected (car lines))))
3090 (insert (pop lines) "\n"))
3091 (and par (insert "<p>\n")))
3092 (throw 'nextline nil))
3094 ;; Horizontal line
3095 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3096 (insert "\n<hr/>\n")
3097 (throw 'nextline nil))
3099 ;; Blockquotes and verse
3100 (when (equal "ORG-BLOCKQUOTE-START" line)
3101 (insert "<blockquote>\n<p>\n")
3102 (throw 'nextline nil))
3103 (when (equal "ORG-BLOCKQUOTE-END" line)
3104 (insert "</p>\n</blockquote>\n")
3105 (throw 'nextline nil))
3106 (when (equal "ORG-VERSE-START" line)
3107 (insert "\n<p class=\"verse\">\n")
3108 (setq inverse t)
3109 (throw 'nextline nil))
3110 (when (equal "ORG-VERSE-END" line)
3111 (insert "</p>\n")
3112 (setq inverse nil)
3113 (throw 'nextline nil))
3114 (when inverse
3115 (let ((i (org-get-string-indentation line)))
3116 (if (> i 0)
3117 (setq line (concat (mapconcat 'identity
3118 (make-list (* 2 i) "\\nbsp") "")
3119 " " (org-trim line))))
3120 (setq line (concat line " \\\\"))))
3122 ;; make targets to anchors
3123 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3124 (cond
3125 ((match-end 2)
3126 (setq line (replace-match
3127 (concat "@<a name=\""
3128 (org-solidify-link-text (match-string 1 line))
3129 "\">\\nbsp@</a>")
3130 t t line)))
3131 ((and org-export-with-toc (equal (string-to-char line) ?*))
3132 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3133 (setq line (replace-match
3134 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3135 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3136 t t line)))
3138 (setq line (replace-match
3139 (concat "@<a name=\""
3140 (org-solidify-link-text (match-string 1 line))
3141 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3142 t t line)))))
3144 (setq line (org-html-handle-time-stamps line))
3146 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3147 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3148 ;; Also handle sub_superscripts and checkboxes
3149 (or (string-match org-table-hline-regexp line)
3150 (setq line (org-html-expand line)))
3152 ;; Format the links
3153 (setq start 0)
3154 (while (string-match org-bracket-link-analytic-regexp line start)
3155 (setq start (match-beginning 0))
3156 (setq path (save-match-data (org-link-unescape
3157 (match-string 3 line))))
3158 (setq type (cond
3159 ((match-end 2) (match-string 2 line))
3160 ((save-match-data
3161 (or (file-name-absolute-p path)
3162 (string-match "^\\.\\.?/" path)))
3163 "file")
3164 (t "internal")))
3165 (setq path (org-extract-attributes path))
3166 (setq attr (org-attributes-to-string
3167 (get-text-property 0 'org-attributes path)))
3168 (setq desc1 (if (match-end 5) (match-string 5 line))
3169 desc2 (if (match-end 2) (concat type ":" path) path)
3170 descp (and desc1 (not (equal desc1 desc2)))
3171 desc (or desc1 desc2))
3172 ;; Make an image out of the description if that is so wanted
3173 (when (and descp (org-file-image-p desc))
3174 (save-match-data
3175 (if (string-match "^file:" desc)
3176 (setq desc (substring desc (match-end 0)))))
3177 (setq desc (concat "<img src=\"" desc "\"/>")))
3178 ;; FIXME: do we need to unescape here somewhere?
3179 (cond
3180 ((equal type "internal")
3181 (setq rpl
3182 (concat
3183 "<a href=\"#"
3184 (org-solidify-link-text
3185 (save-match-data (org-link-unescape path)) nil)
3186 "\"" attr ">" desc "</a>")))
3187 ((member type '("http" "https"))
3188 ;; standard URL, just check if we need to inline an image
3189 (if (and (or (eq t org-export-html-inline-images)
3190 (and org-export-html-inline-images (not descp)))
3191 (org-file-image-p path))
3192 (setq rpl (concat "<img src=\"" type ":" path "\"" attr "/>"))
3193 (setq link (concat type ":" path))
3194 (setq rpl (concat "<a href=\"" link "\"" attr ">"
3195 desc "</a>"))))
3196 ((member type '("ftp" "mailto" "news"))
3197 ;; standard URL
3198 (setq link (concat type ":" path))
3199 (setq rpl (concat "<a href=\"" link "\"" attr ">" desc "</a>")))
3201 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3202 ;; The link protocol has a function for format the link
3203 (setq rpl
3204 (save-match-data
3205 (funcall fnc (org-link-unescape path) desc1 'html))))
3207 ((string= type "file")
3208 ;; FILE link
3209 (let* ((filename path)
3210 (abs-p (file-name-absolute-p filename))
3211 thefile file-is-image-p search)
3212 (save-match-data
3213 (if (string-match "::\\(.*\\)" filename)
3214 (setq search (match-string 1 filename)
3215 filename (replace-match "" t nil filename)))
3216 (setq valid
3217 (if (functionp link-validate)
3218 (funcall link-validate filename current-dir)
3220 (setq file-is-image-p (org-file-image-p filename))
3221 (setq thefile (if abs-p (expand-file-name filename) filename))
3222 (when (and org-export-html-link-org-files-as-html
3223 (string-match "\\.org$" thefile))
3224 (setq thefile (concat (substring thefile 0
3225 (match-beginning 0))
3226 "." html-extension))
3227 (if (and search
3228 ;; make sure this is can be used as target search
3229 (not (string-match "^[0-9]*$" search))
3230 (not (string-match "^\\*" search))
3231 (not (string-match "^/.*/$" search)))
3232 (setq thefile (concat thefile "#"
3233 (org-solidify-link-text
3234 (org-link-unescape search)))))
3235 (when (string-match "^file:" desc)
3236 (setq desc (replace-match "" t t desc))
3237 (if (string-match "\\.org$" desc)
3238 (setq desc (replace-match "" t t desc))))))
3239 (setq rpl (if (and file-is-image-p
3240 (or (eq t org-export-html-inline-images)
3241 (and org-export-html-inline-images
3242 (not descp))))
3243 (concat "<img src=\"" thefile "\"" attr "/>")
3244 (concat "<a href=\"" thefile "\"" attr ">"
3245 desc "</a>")))
3246 (if (not valid) (setq rpl desc))))
3249 ;; just publish the path, as default
3250 (setq rpl (concat "<i>&lt;" type ":"
3251 (save-match-data (org-link-unescape path))
3252 "&gt;</i>"))))
3253 (setq line (replace-match rpl t t line)
3254 start (+ start (length rpl))))
3256 ;; TODO items
3257 (if (and (string-match org-todo-line-regexp line)
3258 (match-beginning 2))
3260 (setq line
3261 (concat (substring line 0 (match-beginning 2))
3262 "<span class=\""
3263 (if (member (match-string 2 line)
3264 org-done-keywords)
3265 "done" "todo")
3266 "\">" (match-string 2 line)
3267 "</span>" (substring line (match-end 2)))))
3269 ;; Does this contain a reference to a footnote?
3270 (when org-export-with-footnotes
3271 (setq start 0)
3272 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3273 (if (get-text-property (match-beginning 2) 'org-protected line)
3274 (setq start (match-end 2))
3275 (let ((n (match-string 2 line)))
3276 (setq line
3277 (replace-match
3278 (format
3279 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3280 (match-string 1 line) n n n)
3281 t t line))))))
3283 (cond
3284 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3285 ;; This is a headline
3286 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3287 txt (match-string 2 line))
3288 (if (string-match quote-re0 txt)
3289 (setq txt (replace-match "" t t txt)))
3290 (if (<= level (max umax umax-toc))
3291 (setq head-count (+ head-count 1)))
3292 (when in-local-list
3293 ;; Close any local lists before inserting a new header line
3294 (while local-list-type
3295 (org-close-li (car local-list-type))
3296 (insert (format "</%sl>\n" (car local-list-type)))
3297 (pop local-list-type))
3298 (setq local-list-indent nil
3299 in-local-list nil))
3300 (setq first-heading-pos (or first-heading-pos (point)))
3301 (org-html-level-start level txt umax
3302 (and org-export-with-toc (<= level umax))
3303 head-count)
3304 ;; QUOTES
3305 (when (string-match quote-re line)
3306 (insert "<pre>")
3307 (setq inquote t)))
3309 ((and org-export-with-tables
3310 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3311 (if (not table-open)
3312 ;; New table starts
3313 (setq table-open t table-buffer nil table-orig-buffer nil))
3314 ;; Accumulate lines
3315 (setq table-buffer (cons line table-buffer)
3316 table-orig-buffer (cons origline table-orig-buffer))
3317 (when (or (not lines)
3318 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3319 (car lines))))
3320 (setq table-open nil
3321 table-buffer (nreverse table-buffer)
3322 table-orig-buffer (nreverse table-orig-buffer))
3323 (org-close-par-maybe)
3324 (insert (org-format-table-html table-buffer table-orig-buffer))))
3326 ;; Normal lines
3327 (when (string-match
3328 (cond
3329 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3330 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3331 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3332 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3333 line)
3334 (setq ind (org-get-string-indentation line)
3335 item-type (if (match-beginning 4) "o" "u")
3336 starter (if (match-beginning 2)
3337 (substring (match-string 2 line) 0 -1))
3338 line (substring line (match-beginning 5))
3339 item-tag nil)
3340 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3341 (setq item-type "d"
3342 item-tag (match-string 1 line)
3343 line (substring line (match-end 0))))
3344 (when (and (not (equal item-type "d"))
3345 (not (string-match "[^ \t]" line)))
3346 ;; empty line. Pretend indentation is large.
3347 (setq ind (if org-empty-line-terminates-plain-lists
3349 (1+ (or (car local-list-indent) 1)))))
3350 (setq didclose nil)
3351 (while (and in-local-list
3352 (or (and (= ind (car local-list-indent))
3353 (not starter))
3354 (< ind (car local-list-indent))))
3355 (setq didclose t)
3356 (org-close-li (car local-list-type))
3357 (insert (format "</%sl>\n" (car local-list-type)))
3358 (pop local-list-type) (pop local-list-indent)
3359 (setq in-local-list local-list-indent))
3360 (cond
3361 ((and starter
3362 (or (not in-local-list)
3363 (> ind (car local-list-indent))))
3364 ;; Start new (level of) list
3365 (org-close-par-maybe)
3366 (insert (cond
3367 ((equal item-type "u") "<ul>\n<li>\n")
3368 ((equal item-type "o") "<ol>\n<li>\n")
3369 ((equal item-type "d")
3370 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3371 (push item-type local-list-type)
3372 (push ind local-list-indent)
3373 (setq in-local-list t))
3374 (starter
3375 ;; continue current list
3376 (org-close-li (car local-list-type))
3377 (insert (cond
3378 ((equal (car local-list-type) "d")
3379 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3380 (t "<li>\n"))))
3381 (didclose
3382 ;; we did close a list, normal text follows: need <p>
3383 (org-open-par)))
3384 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3385 (setq line
3386 (replace-match
3387 (if (equal (match-string 1 line) "X")
3388 "<b>[X]</b>"
3389 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3390 t t line))))
3392 ;; Empty lines start a new paragraph. If hand-formatted lists
3393 ;; are not fully interpreted, lines starting with "-", "+", "*"
3394 ;; also start a new paragraph.
3395 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3397 ;; Is this the start of a footnote?
3398 (when org-export-with-footnotes
3399 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3400 (org-close-par-maybe)
3401 (let ((n (match-string 1 line)))
3402 (setq line (replace-match
3403 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3404 (setq line (concat line "</p>")))))
3406 ;; Check if the line break needs to be conserved
3407 (cond
3408 ((string-match "\\\\\\\\[ \t]*$" line)
3409 (setq line (replace-match "<br/>" t t line)))
3410 (org-export-preserve-breaks
3411 (setq line (concat line "<br/>"))))
3413 (insert line "\n")))))
3415 ;; Properly close all local lists and other lists
3416 (when inquote (insert "</pre>\n"))
3417 (when in-local-list
3418 ;; Close any local lists before inserting a new header line
3419 (while local-list-type
3420 (org-close-li (car local-list-type))
3421 (insert (format "</%sl>\n" (car local-list-type)))
3422 (pop local-list-type))
3423 (setq local-list-indent nil
3424 in-local-list nil))
3425 (org-html-level-start 1 nil umax
3426 (and org-export-with-toc (<= level umax))
3427 head-count)
3428 ;; the </div> to close the last text-... div.
3429 (insert "</div>\n")
3431 (unless body-only
3432 (when (plist-get opt-plist :auto-postamble)
3433 (insert "<div id=\"postamble\">")
3434 (when (and org-export-author-info author)
3435 (insert "<p class=\"author\"> "
3436 (nth 1 lang-words) ": " author "\n")
3437 (when email
3438 (if (listp (split-string email ",+ *"))
3439 (mapc (lambda(e)
3440 (insert "<a href=\"mailto:" e "\">&lt;"
3441 e "&gt;</a>\n"))
3442 (split-string email ",+ *"))
3443 (insert "<a href=\"mailto:" email "\">&lt;"
3444 email "&gt;</a>\n")))
3445 (insert "</p>\n"))
3446 (when (and date org-export-time-stamp-file)
3447 (insert "<p class=\"date\"> "
3448 (nth 2 lang-words) ": "
3449 date "</p>\n"))
3450 (when org-export-creator-info
3451 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3452 org-version emacs-major-version)))
3453 (insert "</div>"))
3455 (if org-export-html-with-timestamp
3456 (insert org-export-html-html-helper-timestamp))
3457 (insert (or (plist-get opt-plist :postamble) ""))
3458 (insert "</body>\n</html>\n"))
3460 (unless (plist-get opt-plist :buffer-will-be-killed)
3461 (normal-mode)
3462 (if (eq major-mode default-major-mode) (html-mode)))
3464 ;; insert the table of contents
3465 (goto-char (point-min))
3466 (when thetoc
3467 (if (or (re-search-forward
3468 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3469 (re-search-forward
3470 "\\[TABLE-OF-CONTENTS\\]" nil t))
3471 (progn
3472 (goto-char (match-beginning 0))
3473 (replace-match ""))
3474 (goto-char first-heading-pos)
3475 (when (looking-at "\\s-*</p>")
3476 (goto-char (match-end 0))
3477 (insert "\n")))
3478 (insert "<div id=\"table-of-contents\">\n")
3479 (mapc 'insert thetoc)
3480 (insert "</div>\n"))
3481 ;; remove empty paragraphs and lists
3482 (goto-char (point-min))
3483 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3484 (replace-match ""))
3485 (goto-char (point-min))
3486 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3487 (replace-match ""))
3488 (goto-char (point-min))
3489 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3490 (replace-match ""))
3491 ;; Convert whitespace place holders
3492 (goto-char (point-min))
3493 (let (beg end n)
3494 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3495 (setq n (get-text-property beg 'org-whitespace)
3496 end (next-single-property-change beg 'org-whitespace))
3497 (goto-char beg)
3498 (delete-region beg end)
3499 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3500 (make-string n ?x)))))
3501 (or to-buffer (save-buffer))
3502 (goto-char (point-min))
3503 (message "Exporting... done")
3504 (if (eq to-buffer 'string)
3505 (prog1 (buffer-substring (point-min) (point-max))
3506 (kill-buffer (current-buffer)))
3507 (current-buffer)))))
3510 (defvar org-table-colgroup-info nil)
3511 (defun org-format-table-ascii (lines)
3512 "Format a table for ascii export."
3513 (if (stringp lines)
3514 (setq lines (org-split-string lines "\n")))
3515 (if (not (string-match "^[ \t]*|" (car lines)))
3516 ;; Table made by table.el - test for spanning
3517 lines
3519 ;; A normal org table
3520 ;; Get rid of hlines at beginning and end
3521 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3522 (setq lines (nreverse lines))
3523 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3524 (setq lines (nreverse lines))
3525 (when org-export-table-remove-special-lines
3526 ;; Check if the table has a marking column. If yes remove the
3527 ;; column and the special lines
3528 (setq lines (org-table-clean-before-export lines)))
3529 ;; Get rid of the vertical lines except for grouping
3530 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3531 rtn line vl1 start)
3532 (while (setq line (pop lines))
3533 (if (string-match org-table-hline-regexp line)
3534 (and (string-match "|\\(.*\\)|" line)
3535 (setq line (replace-match " \\1" t nil line)))
3536 (setq start 0 vl1 vl)
3537 (while (string-match "|" line start)
3538 (setq start (match-end 0))
3539 (or (pop vl1) (setq line (replace-match " " t t line)))))
3540 (push line rtn))
3541 (nreverse rtn))))
3543 (defun org-colgroup-info-to-vline-list (info)
3544 (let (vl new last)
3545 (while info
3546 (setq last new new (pop info))
3547 (if (or (memq last '(:end :startend))
3548 (memq new '(:start :startend)))
3549 (push t vl)
3550 (push nil vl)))
3551 (setq vl (nreverse vl))
3552 (and vl (setcar vl nil))
3553 vl))
3555 (defvar org-table-number-regexp) ; defined in org-table.el
3556 (defun org-format-table-html (lines olines)
3557 "Find out which HTML converter to use and return the HTML code."
3558 (if (stringp lines)
3559 (setq lines (org-split-string lines "\n")))
3560 (if (string-match "^[ \t]*|" (car lines))
3561 ;; A normal org table
3562 (org-format-org-table-html lines)
3563 ;; Table made by table.el - test for spanning
3564 (let* ((hlines (delq nil (mapcar
3565 (lambda (x)
3566 (if (string-match "^[ \t]*\\+-" x) x
3567 nil))
3568 lines)))
3569 (first (car hlines))
3570 (ll (and (string-match "\\S-+" first)
3571 (match-string 0 first)))
3572 (re (concat "^[ \t]*" (regexp-quote ll)))
3573 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3574 hlines))))
3575 (if (and (not spanning)
3576 (not org-export-prefer-native-exporter-for-tables))
3577 ;; We can use my own converter with HTML conversions
3578 (org-format-table-table-html lines)
3579 ;; Need to use the code generator in table.el, with the original text.
3580 (org-format-table-table-html-using-table-generate-source olines)))))
3582 (defvar org-table-number-fraction) ; defined in org-table.el
3583 (defun org-format-org-table-html (lines &optional splice)
3584 "Format a table into HTML."
3585 (require 'org-table)
3586 ;; Get rid of hlines at beginning and end
3587 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3588 (setq lines (nreverse lines))
3589 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3590 (setq lines (nreverse lines))
3591 (when org-export-table-remove-special-lines
3592 ;; Check if the table has a marking column. If yes remove the
3593 ;; column and the special lines
3594 (setq lines (org-table-clean-before-export lines)))
3596 (let ((head (and org-export-highlight-first-table-line
3597 (delq nil (mapcar
3598 (lambda (x) (string-match "^[ \t]*|-" x))
3599 (cdr lines)))))
3600 (nlines 0) fnum i
3601 tbopen line fields html gr colgropen)
3602 (if splice (setq head nil))
3603 (unless splice (push (if head "<thead>" "<tbody>") html))
3604 (setq tbopen t)
3605 (while (setq line (pop lines))
3606 (catch 'next-line
3607 (if (string-match "^[ \t]*|-" line)
3608 (progn
3609 (unless splice
3610 (push (if head "</thead>" "</tbody>") html)
3611 (if lines (push "<tbody>" html) (setq tbopen nil)))
3612 (setq head nil) ;; head ends here, first time around
3613 ;; ignore this line
3614 (throw 'next-line t)))
3615 ;; Break the line into fields
3616 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3617 (unless fnum (setq fnum (make-vector (length fields) 0)))
3618 (setq nlines (1+ nlines) i -1)
3619 (push (concat "<tr>"
3620 (mapconcat
3621 (lambda (x)
3622 (setq i (1+ i))
3623 (if (and (< i nlines)
3624 (string-match org-table-number-regexp x))
3625 (incf (aref fnum i)))
3626 (if head
3627 (concat (car org-export-table-header-tags) x
3628 (cdr org-export-table-header-tags))
3629 (concat (car org-export-table-data-tags) x
3630 (cdr org-export-table-data-tags))))
3631 fields "")
3632 "</tr>")
3633 html)))
3634 (unless splice (if tbopen (push "</tbody>" html)))
3635 (unless splice (push "</table>\n" html))
3636 (setq html (nreverse html))
3637 (unless splice
3638 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3639 (push (mapconcat
3640 (lambda (x)
3641 (setq gr (pop org-table-colgroup-info))
3642 (format "%s<col align=\"%s\"></col>%s"
3643 (if (memq gr '(:start :startend))
3644 (prog1
3645 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3646 (setq colgropen t))
3648 (if (> (/ (float x) nlines) org-table-number-fraction)
3649 "right" "left")
3650 (if (memq gr '(:end :startend))
3651 (progn (setq colgropen nil) "</colgroup>")
3652 "")))
3653 fnum "")
3654 html)
3655 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3656 (push html-table-tag html))
3657 (concat (mapconcat 'identity html "\n") "\n")))
3659 (defun org-table-clean-before-export (lines)
3660 "Check if the table has a marking column.
3661 If yes remove the column and the special lines."
3662 (setq org-table-colgroup-info nil)
3663 (if (memq nil
3664 (mapcar
3665 (lambda (x) (or (string-match "^[ \t]*|-" x)
3666 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3667 lines))
3668 (progn
3669 (setq org-table-clean-did-remove-column nil)
3670 (delq nil
3671 (mapcar
3672 (lambda (x)
3673 (cond
3674 ((string-match "^[ \t]*| */ *|" x)
3675 (setq org-table-colgroup-info
3676 (mapcar (lambda (x)
3677 (cond ((member x '("<" "&lt;")) :start)
3678 ((member x '(">" "&gt;")) :end)
3679 ((member x '("<>" "&lt;&gt;")) :startend)
3680 (t nil)))
3681 (org-split-string x "[ \t]*|[ \t]*")))
3682 nil)
3683 (t x)))
3684 lines)))
3685 (setq org-table-clean-did-remove-column t)
3686 (delq nil
3687 (mapcar
3688 (lambda (x)
3689 (cond
3690 ((string-match "^[ \t]*| */ *|" x)
3691 (setq org-table-colgroup-info
3692 (mapcar (lambda (x)
3693 (cond ((member x '("<" "&lt;")) :start)
3694 ((member x '(">" "&gt;")) :end)
3695 ((member x '("<>" "&lt;&gt;")) :startend)
3696 (t nil)))
3697 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3698 nil)
3699 ((string-match "^[ \t]*| *[!_^/] *|" x)
3700 nil) ; ignore this line
3701 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3702 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3703 ;; remove the first column
3704 (replace-match "\\1|" t nil x))))
3705 lines))))
3707 (defun org-format-table-table-html (lines)
3708 "Format a table generated by table.el into HTML.
3709 This conversion does *not* use `table-generate-source' from table.el.
3710 This has the advantage that Org-mode's HTML conversions can be used.
3711 But it has the disadvantage, that no cell- or row-spanning is allowed."
3712 (let (line field-buffer
3713 (head org-export-highlight-first-table-line)
3714 fields html empty)
3715 (setq html (concat html-table-tag "\n"))
3716 (while (setq line (pop lines))
3717 (setq empty "&nbsp;")
3718 (catch 'next-line
3719 (if (string-match "^[ \t]*\\+-" line)
3720 (progn
3721 (if field-buffer
3722 (progn
3723 (setq
3724 html
3725 (concat
3726 html
3727 "<tr>"
3728 (mapconcat
3729 (lambda (x)
3730 (if (equal x "") (setq x empty))
3731 (if head
3732 (concat (car org-export-table-header-tags) x
3733 (cdr org-export-table-header-tags))
3734 (concat (car org-export-table-data-tags) x
3735 (cdr org-export-table-data-tags))))
3736 field-buffer "\n")
3737 "</tr>\n"))
3738 (setq head nil)
3739 (setq field-buffer nil)))
3740 ;; Ignore this line
3741 (throw 'next-line t)))
3742 ;; Break the line into fields and store the fields
3743 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3744 (if field-buffer
3745 (setq field-buffer (mapcar
3746 (lambda (x)
3747 (concat x "<br/>" (pop fields)))
3748 field-buffer))
3749 (setq field-buffer fields))))
3750 (setq html (concat html "</table>\n"))
3751 html))
3753 (defun org-format-table-table-html-using-table-generate-source (lines)
3754 "Format a table into html, using `table-generate-source' from table.el.
3755 This has the advantage that cell- or row-spanning is allowed.
3756 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3757 (require 'table)
3758 (with-current-buffer (get-buffer-create " org-tmp1 ")
3759 (erase-buffer)
3760 (insert (mapconcat 'identity lines "\n"))
3761 (goto-char (point-min))
3762 (if (not (re-search-forward "|[^+]" nil t))
3763 (error "Error processing table"))
3764 (table-recognize-table)
3765 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3766 (table-generate-source 'html " org-tmp2 ")
3767 (set-buffer " org-tmp2 ")
3768 (buffer-substring (point-min) (point-max))))
3770 (defun org-export-splice-style (style extra)
3771 "Splice EXTRA into STYLE, just before \"</style>\"."
3772 (if (and (stringp extra)
3773 (string-match "\\S-" extra)
3774 (string-match "</style>" style))
3775 (concat (substring style 0 (match-beginning 0))
3776 "\n" extra "\n"
3777 (substring style (match-beginning 0)))
3778 style))
3780 (defun org-html-handle-time-stamps (s)
3781 "Format time stamps in string S, or remove them."
3782 (catch 'exit
3783 (let (r b)
3784 (while (string-match org-maybe-keyword-time-regexp s)
3785 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3786 ;; never export CLOCK
3787 (throw 'exit ""))
3788 (or b (setq b (substring s 0 (match-beginning 0))))
3789 (if (not org-export-with-timestamps)
3790 (setq r (concat r (substring s 0 (match-beginning 0)))
3791 s (substring s (match-end 0)))
3792 (setq r (concat
3793 r (substring s 0 (match-beginning 0))
3794 (if (match-end 1)
3795 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3796 (match-string 1 s)))
3797 (format " @<span class=\"timestamp\">%s@</span>"
3798 (substring
3799 (org-translate-time (match-string 3 s)) 1 -1)))
3800 s (substring s (match-end 0)))))
3801 ;; Line break if line started and ended with time stamp stuff
3802 (if (not r)
3804 (setq r (concat r s))
3805 (unless (string-match "\\S-" (concat b s))
3806 (setq r (concat r "@<br/>")))
3807 r))))
3809 (defun org-export-htmlize-region-for-paste (beg end)
3810 "Convert the region to HTML, using htmlize.el.
3811 This is much like `htmlize-region-for-paste', only that it uses
3812 the settings define in the org-... variables."
3813 (let* ((htmlize-output-type org-export-htmlize-output-type)
3814 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3815 (htmlbuf (htmlize-region beg end)))
3816 (unwind-protect
3817 (with-current-buffer htmlbuf
3818 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3819 (plist-get htmlize-buffer-places 'content-end)))
3820 (kill-buffer htmlbuf))))
3822 ;;;###autoload
3823 (defun org-export-htmlize-generate-css ()
3824 "Create the CSS for all font definitions in the current Emacs session.
3825 Use this to create face definitions in your CSS style file that can then
3826 be used by code snippets transformed by htmlize.
3827 This command just produces a buffer that contains class definitions for all
3828 faces used in the current Emacs session. You can copy and paste the ones you
3829 need into your CSS file.
3831 If you then set `org-export-htmlize-output-type' to `css', calls to
3832 the function `org-export-htmlize-region-for-paste' will produce code
3833 that uses these same face definitions."
3834 (interactive)
3835 (require 'htmlize)
3836 (and (get-buffer "*html*") (kill-buffer "*html*"))
3837 (with-temp-buffer
3838 (let ((fl (face-list))
3839 (htmlize-css-name-prefix "org-")
3840 (htmlize-output-type 'css)
3841 f i)
3842 (while (setq f (pop fl)
3843 i (and f (face-attribute f :inherit)))
3844 (when (and (symbolp f) (or (not i) (not (listp i))))
3845 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3846 (htmlize-region (point-min) (point-max))))
3847 (switch-to-buffer "*html*")
3848 (goto-char (point-min))
3849 (if (re-search-forward "<style" nil t)
3850 (delete-region (point-min) (match-beginning 0)))
3851 (if (re-search-forward "</style>" nil t)
3852 (delete-region (1+ (match-end 0)) (point-max)))
3853 (beginning-of-line 1)
3854 (if (looking-at " +") (replace-match ""))
3855 (goto-char (point-min)))
3857 (defun org-html-protect (s)
3858 ;; convert & to &amp;, < to &lt; and > to &gt;
3859 (let ((start 0))
3860 (while (string-match "&" s start)
3861 (setq s (replace-match "&amp;" t t s)
3862 start (1+ (match-beginning 0))))
3863 (while (string-match "<" s)
3864 (setq s (replace-match "&lt;" t t s)))
3865 (while (string-match ">" s)
3866 (setq s (replace-match "&gt;" t t s))))
3869 (defun org-export-cleanup-toc-line (s)
3870 "Remove tags and time staps from lines going into the toc."
3871 (when (memq org-export-with-tags '(not-in-toc nil))
3872 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3873 (setq s (replace-match "" t t s))))
3874 (when org-export-remove-timestamps-from-toc
3875 (while (string-match org-maybe-keyword-time-regexp s)
3876 (setq s (replace-match "" t t s))))
3877 (while (string-match org-bracket-link-regexp s)
3878 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3879 t t s)))
3882 (defun org-html-expand (string)
3883 "Prepare STRING for HTML export. Applies all active conversions.
3884 If there are links in the string, don't modify these."
3885 (let* ((re (concat org-bracket-link-regexp "\\|"
3886 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3887 m s l res)
3888 (while (setq m (string-match re string))
3889 (setq s (substring string 0 m)
3890 l (match-string 0 string)
3891 string (substring string (match-end 0)))
3892 (push (org-html-do-expand s) res)
3893 (push l res))
3894 (push (org-html-do-expand string) res)
3895 (apply 'concat (nreverse res))))
3897 (defun org-html-do-expand (s)
3898 "Apply all active conversions to translate special ASCII to HTML."
3899 (setq s (org-html-protect s))
3900 (if org-export-html-expand
3901 (let ((start 0))
3902 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3903 (setq s (replace-match "<\\1>" t nil s)))))
3904 (if org-export-with-emphasize
3905 (setq s (org-export-html-convert-emphasize s)))
3906 (if org-export-with-special-strings
3907 (setq s (org-export-html-convert-special-strings s)))
3908 (if org-export-with-sub-superscripts
3909 (setq s (org-export-html-convert-sub-super s)))
3910 (if org-export-with-TeX-macros
3911 (let ((start 0) wd ass)
3912 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
3913 s start))
3914 (if (get-text-property (match-beginning 0) 'org-protected s)
3915 (setq start (match-end 0))
3916 (setq wd (match-string 1 s))
3917 (if (setq ass (assoc wd org-html-entities))
3918 (setq s (replace-match (or (cdr ass)
3919 (concat "&" (car ass) ";"))
3920 t t s))
3921 (setq start (+ start (length wd))))))))
3924 (defun org-create-multibrace-regexp (left right n)
3925 "Create a regular expression which will match a balanced sexp.
3926 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3927 as single character strings.
3928 The regexp returned will match the entire expression including the
3929 delimiters. It will also define a single group which contains the
3930 match except for the outermost delimiters. The maximum depth of
3931 stacked delimiters is N. Escaping delimiters is not possible."
3932 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3933 (or "\\|")
3934 (re nothing)
3935 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3936 (while (> n 1)
3937 (setq n (1- n)
3938 re (concat re or next)
3939 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3940 (concat left "\\(" re "\\)" right)))
3942 (defvar org-match-substring-regexp
3943 (concat
3944 "\\([^\\]\\)\\([_^]\\)\\("
3945 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3946 "\\|"
3947 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3948 "\\|"
3949 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3950 "The regular expression matching a sub- or superscript.")
3952 (defvar org-match-substring-with-braces-regexp
3953 (concat
3954 "\\([^\\]\\)\\([_^]\\)\\("
3955 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3956 "\\)")
3957 "The regular expression matching a sub- or superscript, forcing braces.")
3959 (defconst org-export-html-special-string-regexps
3960 '(("\\\\-" . "&shy;")
3961 ("---\\([^-]\\)" . "&mdash;\\1")
3962 ("--\\([^-]\\)" . "&ndash;\\1")
3963 ("\\.\\.\\." . "&hellip;"))
3964 "Regular expressions for special string conversion.")
3966 (defun org-export-html-convert-special-strings (string)
3967 "Convert special characters in STRING to HTML."
3968 (let ((all org-export-html-special-string-regexps)
3969 e a re rpl start)
3970 (while (setq a (pop all))
3971 (setq re (car a) rpl (cdr a) start 0)
3972 (while (string-match re string start)
3973 (if (get-text-property (match-beginning 0) 'org-protected string)
3974 (setq start (match-end 0))
3975 (setq string (replace-match rpl t nil string)))))
3976 string))
3978 (defun org-export-html-convert-sub-super (string)
3979 "Convert sub- and superscripts in STRING to HTML."
3980 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3981 (while (string-match org-match-substring-regexp string s)
3982 (cond
3983 ((and requireb (match-end 8)) (setq s (match-end 2)))
3984 ((get-text-property (match-beginning 2) 'org-protected string)
3985 (setq s (match-end 2)))
3987 (setq s (match-end 1)
3988 key (if (string= (match-string 2 string) "_") "sub" "sup")
3989 c (or (match-string 8 string)
3990 (match-string 6 string)
3991 (match-string 5 string))
3992 string (replace-match
3993 (concat (match-string 1 string)
3994 "<" key ">" c "</" key ">")
3995 t t string)))))
3996 (while (string-match "\\\\\\([_^]\\)" string)
3997 (setq string (replace-match (match-string 1 string) t t string)))
3998 string))
4000 (defun org-export-html-convert-emphasize (string)
4001 "Apply emphasis."
4002 (let ((s 0) rpl)
4003 (while (string-match org-emph-re string s)
4004 (if (not (equal
4005 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4006 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4007 (setq s (match-beginning 0)
4009 (concat
4010 (match-string 1 string)
4011 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4012 (match-string 4 string)
4013 (nth 3 (assoc (match-string 3 string)
4014 org-emphasis-alist))
4015 (match-string 5 string))
4016 string (replace-match rpl t t string)
4017 s (+ s (- (length rpl) 2)))
4018 (setq s (1+ s))))
4019 string))
4021 (defvar org-par-open nil)
4022 (defun org-open-par ()
4023 "Insert <p>, but first close previous paragraph if any."
4024 (org-close-par-maybe)
4025 (insert "\n<p>")
4026 (setq org-par-open t))
4027 (defun org-close-par-maybe ()
4028 "Close paragraph if there is one open."
4029 (when org-par-open
4030 (insert "</p>")
4031 (setq org-par-open nil)))
4032 (defun org-close-li (&optional type)
4033 "Close <li> if necessary."
4034 (org-close-par-maybe)
4035 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4037 (defvar body-only) ; dynamically scoped into this.
4038 (defun org-html-level-start (level title umax with-toc head-count)
4039 "Insert a new level in HTML export.
4040 When TITLE is nil, just close all open levels."
4041 (org-close-par-maybe)
4042 (let ((target (and title (org-get-text-property-any 0 'target title)))
4043 (l org-level-max)
4044 snumber)
4045 (while (>= l level)
4046 (if (aref org-levels-open (1- l))
4047 (progn
4048 (org-html-level-close l umax)
4049 (aset org-levels-open (1- l) nil)))
4050 (setq l (1- l)))
4051 (when title
4052 ;; If title is nil, this means this function is called to close
4053 ;; all levels, so the rest is done only if title is given
4054 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4055 (setq title (replace-match
4056 (if org-export-with-tags
4057 (save-match-data
4058 (concat
4059 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4060 (mapconcat 'identity (org-split-string
4061 (match-string 1 title) ":")
4062 "&nbsp;")
4063 "</span>"))
4065 t t title)))
4066 (if (> level umax)
4067 (progn
4068 (if (aref org-levels-open (1- level))
4069 (progn
4070 (org-close-li)
4071 (if target
4072 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
4073 (insert "<li>" title "<br/>\n")))
4074 (aset org-levels-open (1- level) t)
4075 (org-close-par-maybe)
4076 (if target
4077 (insert (format "<ul>\n<li id=\"%s\">" target)
4078 title "<br/>\n")
4079 (insert "<ul>\n<li>" title "<br/>\n"))))
4080 (aset org-levels-open (1- level) t)
4081 (setq snumber (org-section-number level))
4082 (if (and org-export-with-section-numbers (not body-only))
4083 (setq title (concat snumber " " title)))
4084 (setq level (+ level org-export-html-toplevel-hlevel -1))
4085 (unless (= head-count 1) (insert "\n</div>\n"))
4086 (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"
4087 snumber level level snumber title level snumber))
4088 (org-open-par)))))
4090 (defun org-get-text-property-any (pos prop &optional object)
4091 (or (get-text-property pos prop object)
4092 (and (setq pos (next-single-property-change pos prop object))
4093 (get-text-property pos prop object))))
4095 (defun org-html-level-close (level max-outline-level)
4096 "Terminate one level in HTML export."
4097 (if (<= level max-outline-level)
4098 (insert "</div>\n")
4099 (org-close-li)
4100 (insert "</ul>\n")))
4102 ;;; iCalendar export
4104 ;;;###autoload
4105 (defun org-export-icalendar-this-file ()
4106 "Export current file as an iCalendar file.
4107 The iCalendar file will be located in the same directory as the Org-mode
4108 file, but with extension `.ics'."
4109 (interactive)
4110 (org-export-icalendar nil buffer-file-name))
4112 ;;;###autoload
4113 (defun org-export-icalendar-all-agenda-files ()
4114 "Export all files in `org-agenda-files' to iCalendar .ics files.
4115 Each iCalendar file will be located in the same directory as the Org-mode
4116 file, but with extension `.ics'."
4117 (interactive)
4118 (apply 'org-export-icalendar nil (org-agenda-files t)))
4120 ;;;###autoload
4121 (defun org-export-icalendar-combine-agenda-files ()
4122 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4123 The file is stored under the name `org-combined-agenda-icalendar-file'."
4124 (interactive)
4125 (apply 'org-export-icalendar t (org-agenda-files t)))
4127 (defun org-export-icalendar (combine &rest files)
4128 "Create iCalendar files for all elements of FILES.
4129 If COMBINE is non-nil, combine all calendar entries into a single large
4130 file and store it under the name `org-combined-agenda-icalendar-file'."
4131 (save-excursion
4132 (org-prepare-agenda-buffers files)
4133 (let* ((dir (org-export-directory
4134 :ical (list :publishing-directory
4135 org-export-publishing-directory)))
4136 file ical-file ical-buffer category started org-agenda-new-buffers)
4137 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4138 (when combine
4139 (setq ical-file
4140 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4141 org-combined-agenda-icalendar-file
4142 (expand-file-name org-combined-agenda-icalendar-file dir))
4143 ical-buffer (org-get-agenda-file-buffer ical-file))
4144 (set-buffer ical-buffer) (erase-buffer))
4145 (while (setq file (pop files))
4146 (catch 'nextfile
4147 (org-check-agenda-file file)
4148 (set-buffer (org-get-agenda-file-buffer file))
4149 (unless combine
4150 (setq ical-file (concat (file-name-as-directory dir)
4151 (file-name-sans-extension
4152 (file-name-nondirectory buffer-file-name))
4153 ".ics"))
4154 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4155 (with-current-buffer ical-buffer (erase-buffer)))
4156 (setq category (or org-category
4157 (file-name-sans-extension
4158 (file-name-nondirectory buffer-file-name))))
4159 (if (symbolp category) (setq category (symbol-name category)))
4160 (let ((standard-output ical-buffer))
4161 (if combine
4162 (and (not started) (setq started t)
4163 (org-start-icalendar-file org-icalendar-combined-name))
4164 (org-start-icalendar-file category))
4165 (org-print-icalendar-entries combine)
4166 (when (or (and combine (not files)) (not combine))
4167 (org-finish-icalendar-file)
4168 (set-buffer ical-buffer)
4169 (run-hooks 'org-before-save-iCalendar-file-hook)
4170 (save-buffer)
4171 (run-hooks 'org-after-save-iCalendar-file-hook)
4172 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4173 ))))
4174 (org-release-buffers org-agenda-new-buffers))))
4176 (defvar org-before-save-iCalendar-file-hook nil
4177 "Hook run before an iCalendar file has been saved.
4178 This can be used to modify the result of the export.")
4180 (defvar org-after-save-iCalendar-file-hook nil
4181 "Hook run after an iCalendar file has been saved.
4182 The iCalendar buffer is still current when this hook is run.
4183 A good way to use this is to tell a desktop calenndar application to re-read
4184 the iCalendar file.")
4186 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4187 (defun org-print-icalendar-entries (&optional combine)
4188 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4189 When COMBINE is non nil, add the category to each line."
4190 (require 'org-agenda)
4191 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4192 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4193 (dts (org-ical-ts-to-string
4194 (format-time-string (cdr org-time-stamp-formats) (current-time))
4195 "DTSTART"))
4196 hd ts ts2 state status (inc t) pos b sexp rrule
4197 scheduledp deadlinep todo prefix due start
4198 tmp pri categories entry location summary desc uid
4199 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4200 (org-refresh-category-properties)
4201 (save-excursion
4202 (goto-char (point-min))
4203 (while (re-search-forward re1 nil t)
4204 (catch :skip
4205 (org-agenda-skip)
4206 (when (boundp 'org-icalendar-verify-function)
4207 (unless (funcall org-icalendar-verify-function)
4208 (outline-next-heading)
4209 (backward-char 1)
4210 (throw :skip nil)))
4211 (setq pos (match-beginning 0)
4212 ts (match-string 0)
4213 inc t
4214 hd (condition-case nil
4215 (org-icalendar-cleanup-string
4216 (org-get-heading))
4217 (error (throw :skip nil)))
4218 summary (org-icalendar-cleanup-string
4219 (org-entry-get nil "SUMMARY"))
4220 desc (org-icalendar-cleanup-string
4221 (or (org-entry-get nil "DESCRIPTION")
4222 (and org-icalendar-include-body (org-get-entry)))
4223 t org-icalendar-include-body)
4224 location (org-icalendar-cleanup-string
4225 (org-entry-get nil "LOCATION"))
4226 uid (if org-icalendar-store-UID
4227 (org-id-get-create)
4228 (or (org-id-get) (org-id-new)))
4229 categories (org-export-get-categories)
4230 deadlinep nil scheduledp nil)
4231 (if (looking-at re2)
4232 (progn
4233 (goto-char (match-end 0))
4234 (setq ts2 (match-string 1)
4235 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4236 (setq tmp (buffer-substring (max (point-min)
4237 (- pos org-ds-keyword-length))
4238 pos)
4239 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4240 (progn
4241 (setq inc nil)
4242 (replace-match "\\1" t nil ts))
4244 deadlinep (string-match org-deadline-regexp tmp)
4245 scheduledp (string-match org-scheduled-regexp tmp)
4246 todo (org-get-todo-state)
4247 ;; donep (org-entry-is-done-p)
4249 (when (and
4250 deadlinep
4251 (if todo
4252 (not (memq 'event-if-todo org-icalendar-use-deadline))
4253 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4254 (throw :skip t))
4255 (when (and
4256 scheduledp
4257 (if todo
4258 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4259 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4260 (throw :skip t))
4261 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4262 (if (or (string-match org-tr-regexp hd)
4263 (string-match org-ts-regexp hd))
4264 (setq hd (replace-match "" t t hd)))
4265 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4266 (setq rrule
4267 (concat "\nRRULE:FREQ="
4268 (cdr (assoc
4269 (match-string 2 ts)
4270 '(("d" . "DAILY")("w" . "WEEKLY")
4271 ("m" . "MONTHLY")("y" . "YEARLY"))))
4272 ";INTERVAL=" (match-string 1 ts)))
4273 (setq rrule ""))
4274 (setq summary (or summary hd))
4275 (if (string-match org-bracket-link-regexp summary)
4276 (setq summary
4277 (replace-match (if (match-end 3)
4278 (match-string 3 summary)
4279 (match-string 1 summary))
4280 t t summary)))
4281 (if deadlinep (setq summary (concat "DL: " summary)))
4282 (if scheduledp (setq summary (concat "S: " summary)))
4283 (if (string-match "\\`<%%" ts)
4284 (with-current-buffer sexp-buffer
4285 (insert (substring ts 1 -1) " " summary "\n"))
4286 (princ (format "BEGIN:VEVENT
4287 UID: %s
4289 %s%s
4290 SUMMARY:%s%s%s
4291 CATEGORIES:%s
4292 END:VEVENT\n"
4293 (concat prefix uid)
4294 (org-ical-ts-to-string ts "DTSTART")
4295 (org-ical-ts-to-string ts2 "DTEND" inc)
4296 rrule summary
4297 (if (and desc (string-match "\\S-" desc))
4298 (concat "\nDESCRIPTION: " desc) "")
4299 (if (and location (string-match "\\S-" location))
4300 (concat "\nLOCATION: " location) "")
4301 categories)))))
4302 (when (and org-icalendar-include-sexps
4303 (condition-case nil (require 'icalendar) (error nil))
4304 (fboundp 'icalendar-export-region))
4305 ;; Get all the literal sexps
4306 (goto-char (point-min))
4307 (while (re-search-forward "^&?%%(" nil t)
4308 (catch :skip
4309 (org-agenda-skip)
4310 (setq b (match-beginning 0))
4311 (goto-char (1- (match-end 0)))
4312 (forward-sexp 1)
4313 (end-of-line 1)
4314 (setq sexp (buffer-substring b (point)))
4315 (with-current-buffer sexp-buffer
4316 (insert sexp "\n"))))
4317 (princ (org-diary-to-ical-string sexp-buffer))
4318 (kill-buffer sexp-buffer))
4320 (when org-icalendar-include-todo
4321 (setq prefix "TODO-")
4322 (goto-char (point-min))
4323 (while (re-search-forward org-todo-line-regexp nil t)
4324 (catch :skip
4325 (org-agenda-skip)
4326 (when (boundp 'org-icalendar-verify-function)
4327 (unless (funcall org-icalendar-verify-function)
4328 (outline-next-heading)
4329 (backward-char 1)
4330 (throw :skip nil)))
4331 (setq state (match-string 2))
4332 (setq status (if (member state org-done-keywords)
4333 "COMPLETED" "NEEDS-ACTION"))
4334 (when (and state
4335 (or (not (member state org-done-keywords))
4336 (eq org-icalendar-include-todo 'all))
4337 (not (member org-archive-tag (org-get-tags-at)))
4339 (setq hd (match-string 3)
4340 summary (org-icalendar-cleanup-string
4341 (org-entry-get nil "SUMMARY"))
4342 desc (org-icalendar-cleanup-string
4343 (or (org-entry-get nil "DESCRIPTION")
4344 (and org-icalendar-include-body (org-get-entry)))
4345 t org-icalendar-include-body)
4346 location (org-icalendar-cleanup-string
4347 (org-entry-get nil "LOCATION"))
4348 due (and (member 'todo-due org-icalendar-use-deadline)
4349 (org-entry-get nil "DEADLINE"))
4350 start (and (member 'todo-start org-icalendar-use-scheduled)
4351 (org-entry-get nil "SCHEDULED"))
4352 categories (org-export-get-categories)
4353 uid (if org-icalendar-store-UID
4354 (org-id-get-create)
4355 (or (org-id-get) (org-id-new))))
4356 (and due (setq due (org-ical-ts-to-string due "DUE")))
4357 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4359 (if (string-match org-bracket-link-regexp hd)
4360 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4361 (match-string 1 hd))
4362 t t hd)))
4363 (if (string-match org-priority-regexp hd)
4364 (setq pri (string-to-char (match-string 2 hd))
4365 hd (concat (substring hd 0 (match-beginning 1))
4366 (substring hd (match-end 1))))
4367 (setq pri org-default-priority))
4368 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4369 (- org-lowest-priority org-highest-priority))))))
4371 (princ (format "BEGIN:VTODO
4372 UID: %s
4374 SUMMARY:%s%s%s%s
4375 CATEGORIES:%s
4376 SEQUENCE:1
4377 PRIORITY:%d
4378 STATUS:%s
4379 END:VTODO\n"
4380 (concat prefix uid)
4381 (or start dts)
4382 (or summary hd)
4383 (if (and location (string-match "\\S-" location))
4384 (concat "\nLOCATION: " location) "")
4385 (if (and desc (string-match "\\S-" desc))
4386 (concat "\nDESCRIPTION: " desc) "")
4387 (if due (concat "\n" due) "")
4388 categories
4389 pri status)))))))))
4391 (defun org-export-get-categories ()
4392 "Get categories according to `org-icalendar-categories'."
4393 (let ((cs org-icalendar-categories) c rtn tmp)
4394 (while (setq c (pop cs))
4395 (cond
4396 ((eq c 'category) (push (org-get-category) rtn))
4397 ((eq c 'todo-state)
4398 (setq tmp (org-get-todo-state))
4399 (and tmp (push tmp rtn)))
4400 ((eq c 'local-tags)
4401 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4402 ((eq c 'all-tags)
4403 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4404 (mapconcat 'identity (nreverse rtn) ",")))
4406 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4407 "Take out stuff and quote what needs to be quoted.
4408 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4409 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4410 characters."
4411 (if (not s)
4413 (when is-body
4414 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4415 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4416 (while (string-match re s) (setq s (replace-match "" t t s)))
4417 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4418 (let ((start 0))
4419 (while (string-match "\\([,;]\\)" s start)
4420 (setq start (+ (match-beginning 0) 2)
4421 s (replace-match "\\\\\\1" nil nil s))))
4422 (when is-body
4423 (while (string-match "[ \t]*\n[ \t]*" s)
4424 (setq s (replace-match "\\n" t t s))))
4425 (setq s (org-trim s))
4426 (if is-body
4427 (if maxlength
4428 (if (and (numberp maxlength)
4429 (> (length s) maxlength))
4430 (setq s (substring s 0 maxlength)))))
4433 (defun org-get-entry ()
4434 "Clean-up description string."
4435 (save-excursion
4436 (org-back-to-heading t)
4437 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4439 (defun org-start-icalendar-file (name)
4440 "Start an iCalendar file by inserting the header."
4441 (let ((user user-full-name)
4442 (name (or name "unknown"))
4443 (timezone (cadr (current-time-zone))))
4444 (princ
4445 (format "BEGIN:VCALENDAR
4446 VERSION:2.0
4447 X-WR-CALNAME:%s
4448 PRODID:-//%s//Emacs with Org-mode//EN
4449 X-WR-TIMEZONE:%s
4450 CALSCALE:GREGORIAN\n" name user timezone))))
4452 (defun org-finish-icalendar-file ()
4453 "Finish an iCalendar file by inserting the END statement."
4454 (princ "END:VCALENDAR\n"))
4456 (defun org-ical-ts-to-string (s keyword &optional inc)
4457 "Take a time string S and convert it to iCalendar format.
4458 KEYWORD is added in front, to make a complete line like DTSTART....
4459 When INC is non-nil, increase the hour by two (if time string contains
4460 a time), or the day by one (if it does not contain a time)."
4461 (let ((t1 (org-parse-time-string s 'nodefault))
4462 t2 fmt have-time time)
4463 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4464 (setq t2 t1 have-time t)
4465 (setq t2 (org-parse-time-string s)))
4466 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4467 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4468 (when inc
4469 (if have-time
4470 (if org-agenda-default-appointment-duration
4471 (setq mi (+ org-agenda-default-appointment-duration mi))
4472 (setq h (+ 2 h)))
4473 (setq d (1+ d))))
4474 (setq time (encode-time s mi h d m y)))
4475 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4476 (concat keyword (format-time-string fmt time))))
4478 ;;; XOXO export
4480 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4481 (with-current-buffer buffer
4482 (apply 'insert output)))
4483 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4485 ;;;###autoload
4486 (defun org-export-as-xoxo (&optional buffer)
4487 "Export the org buffer as XOXO.
4488 The XOXO buffer is named *xoxo-<source buffer name>*"
4489 (interactive (list (current-buffer)))
4490 ;; A quickie abstraction
4492 ;; Output everything as XOXO
4493 (with-current-buffer (get-buffer buffer)
4494 (let* ((pos (point))
4495 (opt-plist (org-combine-plists (org-default-export-plist)
4496 (org-infile-export-plist)))
4497 (filename (concat (file-name-as-directory
4498 (org-export-directory :xoxo opt-plist))
4499 (file-name-sans-extension
4500 (file-name-nondirectory buffer-file-name))
4501 ".html"))
4502 (out (find-file-noselect filename))
4503 (last-level 1)
4504 (hanging-li nil))
4505 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4506 ;; Check the output buffer is empty.
4507 (with-current-buffer out (erase-buffer))
4508 ;; Kick off the output
4509 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4510 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4511 (let* ((hd (match-string-no-properties 1))
4512 (level (length hd))
4513 (text (concat
4514 (match-string-no-properties 2)
4515 (save-excursion
4516 (goto-char (match-end 0))
4517 (let ((str ""))
4518 (catch 'loop
4519 (while 't
4520 (forward-line)
4521 (if (looking-at "^[ \t]\\(.*\\)")
4522 (setq str (concat str (match-string-no-properties 1)))
4523 (throw 'loop str)))))))))
4525 ;; Handle level rendering
4526 (cond
4527 ((> level last-level)
4528 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4530 ((< level last-level)
4531 (dotimes (- (- last-level level) 1)
4532 (if hanging-li
4533 (org-export-as-xoxo-insert-into out "</li>\n"))
4534 (org-export-as-xoxo-insert-into out "</ol>\n"))
4535 (when hanging-li
4536 (org-export-as-xoxo-insert-into out "</li>\n")
4537 (setq hanging-li nil)))
4539 ((equal level last-level)
4540 (if hanging-li
4541 (org-export-as-xoxo-insert-into out "</li>\n")))
4544 (setq last-level level)
4546 ;; And output the new li
4547 (setq hanging-li 't)
4548 (if (equal ?+ (elt text 0))
4549 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4550 (org-export-as-xoxo-insert-into out "<li>" text))))
4552 ;; Finally finish off the ol
4553 (dotimes (- last-level 1)
4554 (if hanging-li
4555 (org-export-as-xoxo-insert-into out "</li>\n"))
4556 (org-export-as-xoxo-insert-into out "</ol>\n"))
4558 (goto-char pos)
4559 ;; Finish the buffer off and clean it up.
4560 (switch-to-buffer-other-window out)
4561 (indent-region (point-min) (point-max) nil)
4562 (save-buffer)
4563 (goto-char (point-min))
4566 (provide 'org-exp)
4568 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4570 ;;; org-exp.el ends here