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