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