Implement #+LATEX_HEADER special.
[org-mode.git] / lisp / org-exp.el
blob5ed9831eca0beee9b0342bf1f4bb88566252807d
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 (save-excursion (outline-next-heading) (point))))
1882 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1883 ;; Mark the line so that it will not be exported as normal text.
1884 (org-unmodified
1885 (add-text-properties (match-beginning 0) (match-end 0)
1886 (list :org-license-to-kill t)))
1887 ;; Return the title string
1888 (org-trim (match-string 0)))))))
1890 (defun org-export-get-title-from-subtree ()
1891 "Return subtree title and exclude it from export."
1892 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1893 (save-excursion
1894 (goto-char rbeg)
1895 (when (and (org-at-heading-p)
1896 (>= (org-end-of-subtree t t) rend))
1897 ;; This is a subtree, we take the title from the first heading
1898 (goto-char rbeg)
1899 (looking-at org-todo-line-regexp)
1900 (setq title (match-string 3))
1901 (org-unmodified
1902 (add-text-properties (point) (1+ (point-at-eol))
1903 (list :org-license-to-kill t)))
1904 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1905 title))
1907 (defun org-solidify-link-text (s &optional alist)
1908 "Take link text and make a safe target out of it."
1909 (save-match-data
1910 (let* ((rtn
1911 (mapconcat
1912 'identity
1913 (org-split-string s "[ \t\r\n]+") "=="))
1914 (a (assoc rtn alist)))
1915 (or (cdr a) rtn))))
1917 (defun org-get-min-level (lines)
1918 "Get the minimum level in LINES."
1919 (let ((re "^\\(\\*+\\) ") l min)
1920 (catch 'exit
1921 (while (setq l (pop lines))
1922 (if (string-match re l)
1923 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1924 1)))
1926 ;; Variable holding the vector with section numbers
1927 (defvar org-section-numbers (make-vector org-level-max 0))
1929 (defun org-init-section-numbers ()
1930 "Initialize the vector for the section numbers."
1931 (let* ((level -1)
1932 (numbers (nreverse (org-split-string "" "\\.")))
1933 (depth (1- (length org-section-numbers)))
1934 (i depth) number-string)
1935 (while (>= i 0)
1936 (if (> i level)
1937 (aset org-section-numbers i 0)
1938 (setq number-string (or (car numbers) "0"))
1939 (if (string-match "\\`[A-Z]\\'" number-string)
1940 (aset org-section-numbers i
1941 (- (string-to-char number-string) ?A -1))
1942 (aset org-section-numbers i (string-to-number number-string)))
1943 (pop numbers))
1944 (setq i (1- i)))))
1946 (defun org-section-number (&optional level)
1947 "Return a string with the current section number.
1948 When LEVEL is non-nil, increase section numbers on that level."
1949 (let* ((depth (1- (length org-section-numbers)))
1950 (string "")
1951 (fmts (car org-export-section-number-format))
1952 (term (cdr org-export-section-number-format))
1953 (sep "")
1954 ctype fmt idx n)
1955 (when level
1956 (when (> level -1)
1957 (aset org-section-numbers
1958 level (1+ (aref org-section-numbers level))))
1959 (setq idx (1+ level))
1960 (while (<= idx depth)
1961 (if (not (= idx 1))
1962 (aset org-section-numbers idx 0))
1963 (setq idx (1+ idx))))
1964 (setq idx 0)
1965 (while (<= idx depth)
1966 (when (> (aref org-section-numbers idx) 0)
1967 (setq fmt (or (pop fmts) fmt)
1968 ctype (car fmt)
1969 n (aref org-section-numbers idx)
1970 string (if (> n 0)
1971 (concat string sep (org-number-to-counter n ctype))
1972 (concat string ".0"))
1973 sep (nth 1 fmt)))
1974 (setq idx (1+ idx)))
1975 (save-match-data
1976 (if (string-match "\\`\\([@0]\\.\\)+" string)
1977 (setq string (replace-match "" t nil string)))
1978 (if (string-match "\\(\\.0\\)+\\'" string)
1979 (setq string (replace-match "" t nil string))))
1980 (concat string term)))
1982 (defun org-number-to-counter (n type)
1983 "Concert number N to a string counter, according to TYPE.
1984 TYPE must be a string, any of:
1985 1 number
1986 A A,B,....
1987 a a,b,....
1988 I uppper case roman numeral
1989 i lower case roman numeral"
1990 (cond
1991 ((equal type "1") (number-to-string n))
1992 ((equal type "A") (char-to-string (+ ?A n -1)))
1993 ((equal type "a") (char-to-string (+ ?a n -1)))
1994 ((equal type "I") (org-number-to-roman n))
1995 ((equal type "i") (downcase (org-number-to-roman n)))
1996 (t (error "Invalid counter type `%s'" type))))
1998 (defun org-number-to-roman (n)
1999 "Convert integer N into a roman numeral."
2000 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2001 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2002 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2003 ( 1 . "I")))
2004 (res ""))
2005 (if (<= n 0)
2006 (number-to-string n)
2007 (while roman
2008 (if (>= n (caar roman))
2009 (setq n (- n (caar roman))
2010 res (concat res (cdar roman)))
2011 (pop roman)))
2012 res)))
2014 (org-number-to-roman 1961)
2017 ;;; Include files
2019 (defun org-export-handle-include-files ()
2020 "Include the contents of include files, with proper formatting."
2021 (let ((case-fold-search t)
2022 params file markup lang start end prefix prefix1)
2023 (goto-char (point-min))
2024 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2025 (setq params (read (concat "(" (match-string 1) ")"))
2026 prefix (org-get-and-remove-property 'params :prefix)
2027 prefix1 (org-get-and-remove-property 'params :prefix1)
2028 file (org-symname-or-string (pop params))
2029 markup (org-symname-or-string (pop params))
2030 lang (org-symname-or-string (pop params)))
2031 (delete-region (match-beginning 0) (match-end 0))
2032 (if (or (not file)
2033 (not (file-exists-p file))
2034 (not (file-readable-p file)))
2035 (insert (format "CANNOT INCLUDE FILE %s" file))
2036 (when markup
2037 (if (equal (downcase markup) "src")
2038 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2039 end "#+end_src")
2040 (setq start (format "#+begin_%s\n" markup)
2041 end (format "#+end_%s" markup))))
2042 (insert (or start ""))
2043 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2044 (or (bolp) (newline))
2045 (insert (or end ""))))))
2047 (defun org-get-file-contents (file &optional prefix prefix1)
2048 "Get the contents of FILE and return them as a string.
2049 If PREFIX is a string, prepend it to each line. If PREFIX1
2050 is a string, prepend it to the first line instead of PREFIX."
2051 (with-temp-buffer
2052 (insert-file-contents file)
2053 (when (or prefix prefix1)
2054 (goto-char (point-min))
2055 (while (not (eobp))
2056 (insert (or prefix1 prefix))
2057 (setq prefix1 nil)
2058 (beginning-of-line 2)))
2059 (buffer-string)))
2061 (defun org-get-and-remove-property (listvar prop)
2062 "Check if the value of LISTVAR contains PROP as a property.
2063 If yes, return the value of that property (i.e. the element following
2064 in the list) and remove property and value from the list in LISTVAR."
2065 (let ((list (symbol-value listvar)) m v)
2066 (when (setq m (member prop list))
2067 (setq v (nth 1 m))
2068 (if (equal (car list) prop)
2069 (set listvar (cddr list))
2070 (setcdr (nthcdr (- (length list) (length m) 1) list)
2071 (cddr m))
2072 (set listvar list)))
2075 (defun org-symname-or-string (s)
2076 (if (symbolp s)
2077 (if s (symbol-name s) s)
2080 ;;; Fontification of code
2081 ;; Currently only for the HTML backend, but who knows....
2082 (defun org-export-replace-src-segments ()
2083 "Replace source code segments with special code for export."
2084 (let ((case-fold-search t)
2085 lang code trans)
2086 (goto-char (point-min))
2087 (while (re-search-forward
2088 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2089 nil t)
2090 (setq lang (match-string 1) code (match-string 2)
2091 trans (org-export-format-source-code lang code))
2092 (replace-match trans t t))))
2094 (defvar htmlp) ;; dynamically scoped from org-exp.el
2096 (defun org-export-format-source-code (lang code)
2097 "Format CODE from language LANG and return it formatted for export.
2098 Currently, this only does something for HTML export, for all other
2099 backends, it converts the segment into an EXAMPLE segment."
2100 (save-match-data
2101 (cond
2102 (htmlp
2103 ;; We are exporting to HTML
2104 (condition-case nil (require 'htmlize) (nil t))
2105 (if (not (fboundp 'htmlize-region-for-paste))
2106 (progn
2107 ;; we do not have htmlize.el, or an old version of it
2108 (message
2109 "htmlize.el 1.34 or later is needed for source code formatting")
2110 (concat "#+BEGIN_EXAMPLE\n" code
2111 (if (string-match "\n\\'" code) "" "\n")
2112 "#+END_EXAMPLE\n"))
2113 ;; ok, we are good to go
2114 (let* ((mode (and lang (intern (concat lang "-mode"))))
2115 (org-inhibit-startup t)
2116 (org-startup-folded nil)
2117 (htmltext
2118 (with-temp-buffer
2119 (insert code)
2120 ;; Free up the protected stuff
2121 (goto-char (point-min))
2122 (while (re-search-forward "^," nil t)
2123 (replace-match "")
2124 (end-of-line 1))
2125 (if (functionp mode)
2126 (funcall mode)
2127 (fundamental-mode))
2128 (font-lock-fontify-buffer)
2129 (org-export-htmlize-region-for-paste
2130 (point-min) (point-max)))))
2131 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2132 (setq htmltext (replace-match
2133 (format "<pre class=\"src src-%s\">" lang)
2134 t t htmltext)))
2135 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2137 ;; This is not HTML, so just make it an example.
2138 (when (equal lang "org")
2139 (while (string-match "^," code)
2140 (setq code (replace-match "" t t code))))
2141 (concat "#+BEGIN_EXAMPLE\n" code
2142 (if (string-match "\n\\'" code) "" "\n")
2143 "#+END_EXAMPLE\n")))))
2145 ;;; ASCII export
2147 (defvar org-last-level nil) ; dynamically scoped variable
2148 (defvar org-min-level nil) ; dynamically scoped variable
2149 (defvar org-levels-open nil) ; dynamically scoped parameter
2150 (defvar org-ascii-current-indentation nil) ; For communication
2152 ;;;###autoload
2153 (defun org-export-as-ascii (arg)
2154 "Export the outline as a pretty ASCII file.
2155 If there is an active region, export only the region.
2156 The prefix ARG specifies how many levels of the outline should become
2157 underlined headlines. The default is 3."
2158 (interactive "P")
2159 (setq-default org-todo-line-regexp org-todo-line-regexp)
2160 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2161 (org-infile-export-plist)))
2162 (region-p (org-region-active-p))
2163 (rbeg (and region-p (region-beginning)))
2164 (rend (and region-p (region-end)))
2165 (subtree-p
2166 (when region-p
2167 (save-excursion
2168 (goto-char rbeg)
2169 (and (org-at-heading-p)
2170 (>= (org-end-of-subtree t t) rend)))))
2171 (opt-plist (if subtree-p
2172 (org-export-add-subtree-options opt-plist rbeg)
2173 opt-plist))
2174 (custom-times org-display-custom-times)
2175 (org-ascii-current-indentation '(0 . 0))
2176 (level 0) line txt
2177 (umax nil)
2178 (umax-toc nil)
2179 (case-fold-search nil)
2180 (filename (concat (file-name-as-directory
2181 (org-export-directory :ascii opt-plist))
2182 (file-name-sans-extension
2183 (or (and subtree-p
2184 (org-entry-get (region-beginning)
2185 "EXPORT_FILE_NAME" t))
2186 (file-name-nondirectory buffer-file-name)))
2187 ".txt"))
2188 (filename (if (equal (file-truename filename)
2189 (file-truename buffer-file-name))
2190 (concat filename ".txt")
2191 filename))
2192 (buffer (find-file-noselect filename))
2193 (org-levels-open (make-vector org-level-max nil))
2194 (odd org-odd-levels-only)
2195 (date (plist-get opt-plist :date))
2196 (author (plist-get opt-plist :author))
2197 (title (or (and subtree-p (org-export-get-title-from-subtree))
2198 (plist-get opt-plist :title)
2199 (and (not
2200 (plist-get opt-plist :skip-before-1st-heading))
2201 (org-export-grab-title-from-buffer))
2202 (file-name-sans-extension
2203 (file-name-nondirectory buffer-file-name))))
2204 (email (plist-get opt-plist :email))
2205 (language (plist-get opt-plist :language))
2206 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2207 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2208 (todo nil)
2209 (lang-words nil)
2210 (region
2211 (buffer-substring
2212 (if (org-region-active-p) (region-beginning) (point-min))
2213 (if (org-region-active-p) (region-end) (point-max))))
2214 (lines (org-split-string
2215 (org-export-preprocess-string
2216 region
2217 :for-ascii t
2218 :skip-before-1st-heading
2219 (plist-get opt-plist :skip-before-1st-heading)
2220 :drawers (plist-get opt-plist :drawers)
2221 :verbatim-multiline t
2222 :select-tags (plist-get opt-plist :select-tags)
2223 :exclude-tags (plist-get opt-plist :exclude-tags)
2224 :archived-trees
2225 (plist-get opt-plist :archived-trees)
2226 :add-text (plist-get opt-plist :text))
2227 "\n"))
2228 thetoc have-headings first-heading-pos
2229 table-open table-buffer)
2231 (let ((inhibit-read-only t))
2232 (org-unmodified
2233 (remove-text-properties (point-min) (point-max)
2234 '(:org-license-to-kill t))))
2236 (setq org-min-level (org-get-min-level lines))
2237 (setq org-last-level org-min-level)
2238 (org-init-section-numbers)
2240 (find-file-noselect filename)
2242 (setq lang-words (or (assoc language org-export-language-setup)
2243 (assoc "en" org-export-language-setup)))
2244 (switch-to-buffer-other-window buffer)
2245 (erase-buffer)
2246 (fundamental-mode)
2247 ;; create local variables for all options, to make sure all called
2248 ;; functions get the correct information
2249 (mapc (lambda (x)
2250 (set (make-local-variable (cdr x))
2251 (plist-get opt-plist (car x))))
2252 org-export-plist-vars)
2253 (org-set-local 'org-odd-levels-only odd)
2254 (setq umax (if arg (prefix-numeric-value arg)
2255 org-export-headline-levels))
2256 (setq umax-toc (if (integerp org-export-with-toc)
2257 (min org-export-with-toc umax)
2258 umax))
2260 ;; File header
2261 (if title (org-insert-centered title ?=))
2262 (insert "\n")
2263 (if (and (or author email)
2264 org-export-author-info)
2265 (insert (concat (nth 1 lang-words) ": " (or author "")
2266 (if email (concat " <" email ">") "")
2267 "\n")))
2269 (cond
2270 ((and date (string-match "%" date))
2271 (setq date (format-time-string date)))
2272 (date)
2273 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2275 (if (and date org-export-time-stamp-file)
2276 (insert (concat (nth 2 lang-words) ": " date"\n")))
2278 (insert "\n\n")
2280 (if org-export-with-toc
2281 (progn
2282 (push (concat (nth 3 lang-words) "\n") thetoc)
2283 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2284 "\n") thetoc)
2285 (mapc '(lambda (line)
2286 (if (string-match org-todo-line-regexp
2287 line)
2288 ;; This is a headline
2289 (progn
2290 (setq have-headings t)
2291 (setq level (- (match-end 1) (match-beginning 1))
2292 level (org-tr-level level)
2293 txt (match-string 3 line)
2294 todo
2295 (or (and org-export-mark-todo-in-toc
2296 (match-beginning 2)
2297 (not (member (match-string 2 line)
2298 org-done-keywords)))
2299 ; TODO, not DONE
2300 (and org-export-mark-todo-in-toc
2301 (= level umax-toc)
2302 (org-search-todo-below
2303 line lines level))))
2304 (setq txt (org-html-expand-for-ascii txt))
2306 (while (string-match org-bracket-link-regexp txt)
2307 (setq txt
2308 (replace-match
2309 (match-string (if (match-end 2) 3 1) txt)
2310 t t txt)))
2312 (if (and (memq org-export-with-tags '(not-in-toc nil))
2313 (string-match
2314 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2315 txt))
2316 (setq txt (replace-match "" t t txt)))
2317 (if (string-match quote-re0 txt)
2318 (setq txt (replace-match "" t t txt)))
2320 (if org-export-with-section-numbers
2321 (setq txt (concat (org-section-number level)
2322 " " txt)))
2323 (if (<= level umax-toc)
2324 (progn
2325 (push
2326 (concat
2327 (make-string
2328 (* (max 0 (- level org-min-level)) 4) ?\ )
2329 (format (if todo "%s (*)\n" "%s\n") txt))
2330 thetoc)
2331 (setq org-last-level level))
2332 ))))
2333 lines)
2334 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2336 (org-init-section-numbers)
2337 (while (setq line (pop lines))
2338 ;; Remove the quoted HTML tags.
2339 (setq line (org-html-expand-for-ascii line))
2340 ;; Remove targets
2341 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2342 (setq line (replace-match "" t t line)))
2343 ;; Replace internal links
2344 (while (string-match org-bracket-link-regexp line)
2345 (setq line (replace-match
2346 (if (match-end 3) "[\\3]" "[\\1]")
2347 t nil line)))
2348 (when custom-times
2349 (setq line (org-translate-time line)))
2350 (cond
2351 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2352 ;; a Headline
2353 (setq first-heading-pos (or first-heading-pos (point)))
2354 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2355 txt (match-string 2 line))
2356 (org-ascii-level-start level txt umax lines))
2358 ((and org-export-with-tables
2359 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2360 (if (not table-open)
2361 ;; New table starts
2362 (setq table-open t table-buffer nil))
2363 ;; Accumulate lines
2364 (setq table-buffer (cons line table-buffer))
2365 (when (or (not lines)
2366 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2367 (car lines))))
2368 (setq table-open nil
2369 table-buffer (nreverse table-buffer))
2370 (insert (mapconcat
2371 (lambda (x)
2372 (org-fix-indentation x org-ascii-current-indentation))
2373 (org-format-table-ascii table-buffer)
2374 "\n") "\n")))
2376 (setq line (org-fix-indentation line org-ascii-current-indentation))
2377 (if (and org-export-with-fixed-width
2378 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2379 (setq line (replace-match "\\1" nil nil line)))
2380 (insert line "\n"))))
2382 (normal-mode)
2384 ;; insert the table of contents
2385 (when thetoc
2386 (goto-char (point-min))
2387 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2388 (progn
2389 (goto-char (match-beginning 0))
2390 (replace-match ""))
2391 (goto-char first-heading-pos))
2392 (mapc 'insert thetoc)
2393 (or (looking-at "[ \t]*\n[ \t]*\n")
2394 (insert "\n\n")))
2396 ;; Convert whitespace place holders
2397 (goto-char (point-min))
2398 (let (beg end)
2399 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2400 (setq end (next-single-property-change beg 'org-whitespace))
2401 (goto-char beg)
2402 (delete-region beg end)
2403 (insert (make-string (- end beg) ?\ ))))
2405 (save-buffer)
2406 ;; remove display and invisible chars
2407 (let (beg end)
2408 (goto-char (point-min))
2409 (while (setq beg (next-single-property-change (point) 'display))
2410 (setq end (next-single-property-change beg 'display))
2411 (delete-region beg end)
2412 (goto-char beg)
2413 (insert "=>"))
2414 (goto-char (point-min))
2415 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2416 (setq end (next-single-property-change beg 'org-cwidth))
2417 (delete-region beg end)
2418 (goto-char beg)))
2419 (goto-char (point-min))))
2421 (defun org-export-ascii-preprocess ()
2422 "Do extra work for ASCII export"
2423 (goto-char (point-min))
2424 (while (re-search-forward org-verbatim-re nil t)
2425 (goto-char (match-end 2))
2426 (backward-delete-char 1) (insert "'")
2427 (goto-char (match-beginning 2))
2428 (delete-char 1) (insert "`")
2429 (goto-char (match-end 2))))
2431 (defun org-search-todo-below (line lines level)
2432 "Search the subtree below LINE for any TODO entries."
2433 (let ((rest (cdr (memq line lines)))
2434 (re org-todo-line-regexp)
2435 line lv todo)
2436 (catch 'exit
2437 (while (setq line (pop rest))
2438 (if (string-match re line)
2439 (progn
2440 (setq lv (- (match-end 1) (match-beginning 1))
2441 todo (and (match-beginning 2)
2442 (not (member (match-string 2 line)
2443 org-done-keywords))))
2444 ; TODO, not DONE
2445 (if (<= lv level) (throw 'exit nil))
2446 (if todo (throw 'exit t))))))))
2448 (defun org-html-expand-for-ascii (line)
2449 "Handle quoted HTML for ASCII export."
2450 (if org-export-html-expand
2451 (while (string-match "@<[^<>\n]*>" line)
2452 ;; We just remove the tags for now.
2453 (setq line (replace-match "" nil nil line))))
2454 line)
2456 (defun org-insert-centered (s &optional underline)
2457 "Insert the string S centered and underline it with character UNDERLINE."
2458 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2459 (insert (make-string ind ?\ ) s "\n")
2460 (if underline
2461 (insert (make-string ind ?\ )
2462 (make-string (string-width s) underline)
2463 "\n"))))
2465 (defun org-ascii-level-start (level title umax &optional lines)
2466 "Insert a new level in ASCII export."
2467 (let (char (n (- level umax 1)) (ind 0))
2468 (if (> level umax)
2469 (progn
2470 (insert (make-string (* 2 n) ?\ )
2471 (char-to-string (nth (% n (length org-export-ascii-bullets))
2472 org-export-ascii-bullets))
2473 " " title "\n")
2474 ;; find the indentation of the next non-empty line
2475 (catch 'stop
2476 (while lines
2477 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2478 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2479 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2480 (pop lines)))
2481 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2482 (if (or (not (equal (char-before) ?\n))
2483 (not (equal (char-before (1- (point))) ?\n)))
2484 (insert "\n"))
2485 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2486 (unless org-export-with-tags
2487 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2488 (setq title (replace-match "" t t title))))
2489 (if org-export-with-section-numbers
2490 (setq title (concat (org-section-number level) " " title)))
2491 (insert title "\n" (make-string (string-width title) char) "\n")
2492 (setq org-ascii-current-indentation '(0 . 0)))))
2494 ;;;###autoload
2495 (defun org-export-visible (type arg)
2496 "Create a copy of the visible part of the current buffer, and export it.
2497 The copy is created in a temporary buffer and removed after use.
2498 TYPE is the final key (as a string) that also select the export command in
2499 the `C-c C-e' export dispatcher.
2500 As a special case, if the you type SPC at the prompt, the temporary
2501 org-mode file will not be removed but presented to you so that you can
2502 continue to use it. The prefix arg ARG is passed through to the exporting
2503 command."
2504 (interactive
2505 (list (progn
2506 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2507 (read-char-exclusive))
2508 current-prefix-arg))
2509 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2510 (error "Invalid export key"))
2511 (let* ((binding (cdr (assoc type
2512 '((?a . org-export-as-ascii)
2513 (?\C-a . org-export-as-ascii)
2514 (?b . org-export-as-html-and-open)
2515 (?\C-b . org-export-as-html-and-open)
2516 (?h . org-export-as-html)
2517 (?H . org-export-as-html-to-buffer)
2518 (?R . org-export-region-as-html)
2519 (?x . org-export-as-xoxo)))))
2520 (keepp (equal type ?\ ))
2521 (file buffer-file-name)
2522 (buffer (get-buffer-create "*Org Export Visible*"))
2523 s e)
2524 ;; Need to hack the drawers here.
2525 (save-excursion
2526 (goto-char (point-min))
2527 (while (re-search-forward org-drawer-regexp nil t)
2528 (goto-char (match-beginning 1))
2529 (or (org-invisible-p) (org-flag-drawer nil))))
2530 (with-current-buffer buffer (erase-buffer))
2531 (save-excursion
2532 (setq s (goto-char (point-min)))
2533 (while (not (= (point) (point-max)))
2534 (goto-char (org-find-invisible))
2535 (append-to-buffer buffer s (point))
2536 (setq s (goto-char (org-find-visible))))
2537 (org-cycle-hide-drawers 'all)
2538 (goto-char (point-min))
2539 (unless keepp
2540 ;; Copy all comment lines to the end, to make sure #+ settings are
2541 ;; still available for the second export step. Kind of a hack, but
2542 ;; does do the trick.
2543 (if (looking-at "#[^\r\n]*")
2544 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2545 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2546 (append-to-buffer buffer (1+ (match-beginning 0))
2547 (min (point-max) (1+ (match-end 0))))))
2548 (set-buffer buffer)
2549 (let ((buffer-file-name file)
2550 (org-inhibit-startup t))
2551 (org-mode)
2552 (show-all)
2553 (unless keepp (funcall binding arg))))
2554 (if (not keepp)
2555 (kill-buffer buffer)
2556 (switch-to-buffer-other-window buffer)
2557 (goto-char (point-min)))))
2559 (defun org-find-visible ()
2560 (let ((s (point)))
2561 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2562 (get-char-property s 'invisible)))
2564 (defun org-find-invisible ()
2565 (let ((s (point)))
2566 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2567 (not (get-char-property s 'invisible))))
2570 ;;; HTML export
2572 (defvar org-archive-location) ;; gets loades with the org-archive require.
2573 (defun org-get-current-options ()
2574 "Return a string with current options as keyword options.
2575 Does include HTML export options as well as TODO and CATEGORY stuff."
2576 (require 'org-archive)
2577 (format
2578 "#+TITLE: %s
2579 #+AUTHOR: %s
2580 #+EMAIL: %s
2581 #+DATE: %s
2582 #+LANGUAGE: %s
2583 #+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
2585 #+EXPORT_SELECT_TAGS: %s
2586 #+EXPORT_EXCUDE_TAGS: %s
2587 #+LINK_UP: %s
2588 #+LINK_HOME: %s
2589 #+CATEGORY: %s
2590 #+SEQ_TODO: %s
2591 #+TYP_TODO: %s
2592 #+PRIORITIES: %c %c %c
2593 #+DRAWERS: %s
2594 #+STARTUP: %s %s %s %s %s
2595 #+TAGS: %s
2596 #+FILETAGS: %s
2597 #+ARCHIVE: %s
2598 #+LINK: %s
2600 (buffer-name) (user-full-name) user-mail-address
2601 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2602 org-export-default-language
2603 org-export-headline-levels
2604 org-export-with-section-numbers
2605 org-export-with-toc
2606 org-export-preserve-breaks
2607 org-export-html-expand
2608 org-export-with-fixed-width
2609 org-export-with-tables
2610 org-export-with-sub-superscripts
2611 org-export-with-special-strings
2612 org-export-with-footnotes
2613 org-export-with-emphasize
2614 org-export-with-TeX-macros
2615 org-export-with-LaTeX-fragments
2616 org-export-skip-text-before-1st-heading
2617 org-export-with-drawers
2618 org-export-with-tags
2619 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2620 (mapconcat 'identity org-export-select-tags " ")
2621 (mapconcat 'identity org-export-exclude-tags " ")
2622 org-export-html-link-up
2623 org-export-html-link-home
2624 (file-name-nondirectory buffer-file-name)
2625 "TODO FEEDBACK VERIFY DONE"
2626 "Me Jason Marie DONE"
2627 org-highest-priority org-lowest-priority org-default-priority
2628 (mapconcat 'identity org-drawers " ")
2629 (cdr (assoc org-startup-folded
2630 '((nil . "showall") (t . "overview") (content . "content"))))
2631 (if org-odd-levels-only "odd" "oddeven")
2632 (if org-hide-leading-stars "hidestars" "showstars")
2633 (if org-startup-align-all-tables "align" "noalign")
2634 (cond ((eq org-log-done t) "logdone")
2635 ((equal org-log-done 'note) "lognotedone")
2636 ((not org-log-done) "nologdone"))
2637 (or (mapconcat (lambda (x)
2638 (cond
2639 ((equal '(:startgroup) x) "{")
2640 ((equal '(:endgroup) x) "}")
2641 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2642 (t (car x))))
2643 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2644 (mapconcat 'identity org-file-tags " ")
2645 org-archive-location
2646 "org file:~/org/%s.org"
2649 (defun org-export-html-preprocess (parameters)
2650 ;; Convert LaTeX fragments to images
2651 (when (plist-get parameters :LaTeX-fragments)
2652 (org-format-latex
2653 (concat "ltxpng/" (file-name-sans-extension
2654 (file-name-nondirectory
2655 org-current-export-file)))
2656 org-current-export-dir nil "Creating LaTeX image %s"))
2657 (message "Exporting..."))
2659 ;;;###autoload
2660 (defun org-insert-export-options-template ()
2661 "Insert into the buffer a template with information for exporting."
2662 (interactive)
2663 (if (not (bolp)) (newline))
2664 (let ((s (org-get-current-options)))
2665 (and (string-match "#\\+CATEGORY" s)
2666 (setq s (substring s 0 (match-beginning 0))))
2667 (insert s)))
2669 ;;;###autoload
2670 (defun org-export-as-html-and-open (arg)
2671 "Export the outline as HTML and immediately open it with a browser.
2672 If there is an active region, export only the region.
2673 The prefix ARG specifies how many levels of the outline should become
2674 headlines. The default is 3. Lower levels will become bulleted lists."
2675 (interactive "P")
2676 (org-export-as-html arg 'hidden)
2677 (org-open-file buffer-file-name))
2679 ;;;###autoload
2680 (defun org-export-as-html-batch ()
2681 "Call `org-export-as-html', may be used in batch processing as
2682 emacs --batch
2683 --load=$HOME/lib/emacs/org.el
2684 --eval \"(setq org-export-headline-levels 2)\"
2685 --visit=MyFile --funcall org-export-as-html-batch"
2686 (org-export-as-html org-export-headline-levels 'hidden))
2688 ;;;###autoload
2689 (defun org-export-as-html-to-buffer (arg)
2690 "Call `org-exort-as-html` with output to a temporary buffer.
2691 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2692 (interactive "P")
2693 (org-export-as-html arg nil nil "*Org HTML Export*")
2694 (switch-to-buffer-other-window "*Org HTML Export*"))
2696 ;;;###autoload
2697 (defun org-replace-region-by-html (beg end)
2698 "Assume the current region has org-mode syntax, and convert it to HTML.
2699 This can be used in any buffer. For example, you could write an
2700 itemized list in org-mode syntax in an HTML buffer and then use this
2701 command to convert it."
2702 (interactive "r")
2703 (let (reg html buf pop-up-frames)
2704 (save-window-excursion
2705 (if (org-mode-p)
2706 (setq html (org-export-region-as-html
2707 beg end t 'string))
2708 (setq reg (buffer-substring beg end)
2709 buf (get-buffer-create "*Org tmp*"))
2710 (with-current-buffer buf
2711 (erase-buffer)
2712 (insert reg)
2713 (org-mode)
2714 (setq html (org-export-region-as-html
2715 (point-min) (point-max) t 'string)))
2716 (kill-buffer buf)))
2717 (delete-region beg end)
2718 (insert html)))
2720 ;;;###autoload
2721 (defun org-export-region-as-html (beg end &optional body-only buffer)
2722 "Convert region from BEG to END in org-mode buffer to HTML.
2723 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2724 contents, and only produce the region of converted text, useful for
2725 cut-and-paste operations.
2726 If BUFFER is a buffer or a string, use/create that buffer as a target
2727 of the converted HTML. If BUFFER is the symbol `string', return the
2728 produced HTML as a string and leave not buffer behind. For example,
2729 a Lisp program could call this function in the following way:
2731 (setq html (org-export-region-as-html beg end t 'string))
2733 When called interactively, the output buffer is selected, and shown
2734 in a window. A non-interactive call will only return the buffer."
2735 (interactive "r\nP")
2736 (when (interactive-p)
2737 (setq buffer "*Org HTML Export*"))
2738 (let ((transient-mark-mode t) (zmacs-regions t)
2739 ext-plist rtn)
2740 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2741 (goto-char end)
2742 (set-mark (point)) ;; to activate the region
2743 (goto-char beg)
2744 (setq rtn (org-export-as-html
2745 nil nil ext-plist
2746 buffer body-only))
2747 (if (fboundp 'deactivate-mark) (deactivate-mark))
2748 (if (and (interactive-p) (bufferp rtn))
2749 (switch-to-buffer-other-window rtn)
2750 rtn)))
2752 (defvar html-table-tag nil) ; dynamically scoped into this.
2753 ;;;###autoload
2754 (defun org-export-as-html (arg &optional hidden ext-plist
2755 to-buffer body-only pub-dir)
2756 "Export the outline as a pretty HTML file.
2757 If there is an active region, export only the region. The prefix
2758 ARG specifies how many levels of the outline should become
2759 headlines. The default is 3. Lower levels will become bulleted
2760 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2761 EXT-PLIST is a property list with external parameters overriding
2762 org-mode's default settings, but still inferior to file-local
2763 settings. When TO-BUFFER is non-nil, create a buffer with that
2764 name and export to that buffer. If TO-BUFFER is the symbol
2765 `string', don't leave any buffer behind but just return the
2766 resulting HTML as a string. When BODY-ONLY is set, don't produce
2767 the file header and footer, simply return the content of
2768 <body>...</body>, without even the body tags themselves. When
2769 PUB-DIR is set, use this as the publishing directory."
2770 (interactive "P")
2772 ;; Make sure we have a file name when we need it.
2773 (when (and (not (or to-buffer body-only))
2774 (not buffer-file-name))
2775 (if (buffer-base-buffer)
2776 (org-set-local 'buffer-file-name
2777 (with-current-buffer (buffer-base-buffer)
2778 buffer-file-name))
2779 (error "Need a file name to be able to export.")))
2781 (message "Exporting...")
2782 (setq-default org-todo-line-regexp org-todo-line-regexp)
2783 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2784 (setq-default org-done-keywords org-done-keywords)
2785 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2786 (let* ((opt-plist
2787 (org-export-process-option-filters
2788 (org-combine-plists (org-default-export-plist)
2789 ext-plist
2790 (org-infile-export-plist))))
2792 (style (concat org-export-html-style-default
2793 (plist-get opt-plist :style)
2794 (plist-get opt-plist :style-extra)))
2795 (html-extension (plist-get opt-plist :html-extension))
2796 (link-validate (plist-get opt-plist :link-validation-function))
2797 valid thetoc have-headings first-heading-pos
2798 (odd org-odd-levels-only)
2799 (region-p (org-region-active-p))
2800 (rbeg (and region-p (region-beginning)))
2801 (rend (and region-p (region-end)))
2802 (subtree-p
2803 (if (plist-get opt-plist :ignore-subree-p)
2805 (when region-p
2806 (save-excursion
2807 (goto-char rbeg)
2808 (and (org-at-heading-p)
2809 (>= (org-end-of-subtree t t) rend))))))
2810 (opt-plist (if subtree-p
2811 (org-export-add-subtree-options opt-plist rbeg)
2812 opt-plist))
2813 ;; The following two are dynamically scoped into other
2814 ;; routines below.
2815 (org-current-export-dir
2816 (or pub-dir (org-export-directory :html opt-plist)))
2817 (org-current-export-file buffer-file-name)
2818 (level 0) (line "") (origline "") txt todo
2819 (umax nil)
2820 (umax-toc nil)
2821 (filename (if to-buffer nil
2822 (expand-file-name
2823 (concat
2824 (file-name-sans-extension
2825 (or (and subtree-p
2826 (org-entry-get (region-beginning)
2827 "EXPORT_FILE_NAME" t))
2828 (file-name-nondirectory buffer-file-name)))
2829 "." html-extension)
2830 (file-name-as-directory
2831 (or pub-dir (org-export-directory :html opt-plist))))))
2832 (current-dir (if buffer-file-name
2833 (file-name-directory buffer-file-name)
2834 default-directory))
2835 (buffer (if to-buffer
2836 (cond
2837 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2838 (t (get-buffer-create to-buffer)))
2839 (find-file-noselect filename)))
2840 (org-levels-open (make-vector org-level-max nil))
2841 (date (plist-get opt-plist :date))
2842 (author (plist-get opt-plist :author))
2843 (title (or (and subtree-p (org-export-get-title-from-subtree))
2844 (plist-get opt-plist :title)
2845 (and (not
2846 (plist-get opt-plist :skip-before-1st-heading))
2847 (org-export-grab-title-from-buffer))
2848 (and buffer-file-name
2849 (file-name-sans-extension
2850 (file-name-nondirectory buffer-file-name)))
2851 "UNTITLED"))
2852 (html-table-tag (plist-get opt-plist :html-table-tag))
2853 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2854 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2855 (inquote nil)
2856 (infixed nil)
2857 (inverse nil)
2858 (in-local-list nil)
2859 (local-list-type nil)
2860 (local-list-indent nil)
2861 (llt org-plain-list-ordered-item-terminator)
2862 (email (plist-get opt-plist :email))
2863 (language (plist-get opt-plist :language))
2864 (lang-words nil)
2865 (head-count 0) cnt
2866 (start 0)
2867 (coding-system (and (boundp 'buffer-file-coding-system)
2868 buffer-file-coding-system))
2869 (coding-system-for-write (or org-export-html-coding-system
2870 coding-system))
2871 (save-buffer-coding-system (or org-export-html-coding-system
2872 coding-system))
2873 (charset (and coding-system-for-write
2874 (fboundp 'coding-system-get)
2875 (coding-system-get coding-system-for-write
2876 'mime-charset)))
2877 (region
2878 (buffer-substring
2879 (if region-p (region-beginning) (point-min))
2880 (if region-p (region-end) (point-max))))
2881 (lines
2882 (org-split-string
2883 (org-export-preprocess-string
2884 region
2885 :emph-multiline t
2886 :for-html t
2887 :skip-before-1st-heading
2888 (plist-get opt-plist :skip-before-1st-heading)
2889 :drawers (plist-get opt-plist :drawers)
2890 :archived-trees
2891 (plist-get opt-plist :archived-trees)
2892 :select-tags (plist-get opt-plist :select-tags)
2893 :exclude-tags (plist-get opt-plist :exclude-tags)
2894 :add-text
2895 (plist-get opt-plist :text)
2896 :LaTeX-fragments
2897 (plist-get opt-plist :LaTeX-fragments))
2898 "[\r\n]"))
2899 table-open type
2900 table-buffer table-orig-buffer
2901 ind item-type starter didclose
2902 rpl path attr desc descp desc1 desc2 link
2903 snumber fnc item-tag
2906 (let ((inhibit-read-only t))
2907 (org-unmodified
2908 (remove-text-properties (point-min) (point-max)
2909 '(:org-license-to-kill t))))
2911 (message "Exporting...")
2913 (setq org-min-level (org-get-min-level lines))
2914 (setq org-last-level org-min-level)
2915 (org-init-section-numbers)
2917 (cond
2918 ((and date (string-match "%" date))
2919 (setq date (format-time-string date)))
2920 (date)
2921 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2923 ;; Get the language-dependent settings
2924 (setq lang-words (or (assoc language org-export-language-setup)
2925 (assoc "en" org-export-language-setup)))
2927 ;; Switch to the output buffer
2928 (set-buffer buffer)
2929 (let ((inhibit-read-only t)) (erase-buffer))
2930 (fundamental-mode)
2932 (and (fboundp 'set-buffer-file-coding-system)
2933 (set-buffer-file-coding-system coding-system-for-write))
2935 (let ((case-fold-search nil)
2936 (org-odd-levels-only odd))
2937 ;; create local variables for all options, to make sure all called
2938 ;; functions get the correct information
2939 (mapc (lambda (x)
2940 (set (make-local-variable (cdr x))
2941 (plist-get opt-plist (car x))))
2942 org-export-plist-vars)
2943 (setq umax (if arg (prefix-numeric-value arg)
2944 org-export-headline-levels))
2945 (setq umax-toc (if (integerp org-export-with-toc)
2946 (min org-export-with-toc umax)
2947 umax))
2948 (unless body-only
2949 ;; File header
2950 (insert (format
2951 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2952 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2953 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2954 lang=\"%s\" xml:lang=\"%s\">
2955 <head>
2956 <title>%s</title>
2957 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2958 <meta name=\"generator\" content=\"Org-mode\"/>
2959 <meta name=\"generated\" content=\"%s\"/>
2960 <meta name=\"author\" content=\"%s\"/>
2962 </head><body>
2964 language language (org-html-expand title)
2965 (or charset "iso-8859-1") date author style))
2967 (insert (or (plist-get opt-plist :preamble) ""))
2969 (when (plist-get opt-plist :auto-preamble)
2970 (if title (insert (format org-export-html-title-format
2971 (org-html-expand title))))))
2973 (if (and org-export-with-toc (not body-only))
2974 (progn
2975 (push (format "<h%d>%s</h%d>\n"
2976 org-export-html-toplevel-hlevel
2977 (nth 3 lang-words)
2978 org-export-html-toplevel-hlevel)
2979 thetoc)
2980 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2981 (push "<ul>\n<li>" thetoc)
2982 (setq lines
2983 (mapcar '(lambda (line)
2984 (if (string-match org-todo-line-regexp line)
2985 ;; This is a headline
2986 (progn
2987 (setq have-headings t)
2988 (setq level (- (match-end 1) (match-beginning 1))
2989 level (org-tr-level level)
2990 txt (save-match-data
2991 (org-html-expand
2992 (org-export-cleanup-toc-line
2993 (match-string 3 line))))
2994 todo
2995 (or (and org-export-mark-todo-in-toc
2996 (match-beginning 2)
2997 (not (member (match-string 2 line)
2998 org-done-keywords)))
2999 ; TODO, not DONE
3000 (and org-export-mark-todo-in-toc
3001 (= level umax-toc)
3002 (org-search-todo-below
3003 line lines level))))
3004 (if (string-match
3005 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3006 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3007 (if (string-match quote-re0 txt)
3008 (setq txt (replace-match "" t t txt)))
3009 (setq snumber (org-section-number level))
3010 (if org-export-with-section-numbers
3011 (setq txt (concat snumber " " txt)))
3012 (if (<= level (max umax umax-toc))
3013 (setq head-count (+ head-count 1)))
3014 (if (<= level umax-toc)
3015 (progn
3016 (if (> level org-last-level)
3017 (progn
3018 (setq cnt (- level org-last-level))
3019 (while (>= (setq cnt (1- cnt)) 0)
3020 (push "\n<ul>\n<li>" thetoc))
3021 (push "\n" thetoc)))
3022 (if (< level org-last-level)
3023 (progn
3024 (setq cnt (- org-last-level level))
3025 (while (>= (setq cnt (1- cnt)) 0)
3026 (push "</li>\n</ul>" thetoc))
3027 (push "\n" thetoc)))
3028 ;; Check for targets
3029 (while (string-match org-any-target-regexp line)
3030 (setq line (replace-match
3031 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3032 t t line)))
3033 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3034 (setq txt (replace-match "" t t txt)))
3035 (push
3036 (format
3037 (if todo
3038 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3039 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3040 snumber txt) thetoc)
3042 (setq org-last-level level))
3044 line)
3045 lines))
3046 (while (> org-last-level (1- org-min-level))
3047 (setq org-last-level (1- org-last-level))
3048 (push "</li>\n</ul>\n" thetoc))
3049 (push "</div>\n" thetoc)
3050 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3052 (setq head-count 0)
3053 (org-init-section-numbers)
3055 (org-open-par)
3057 (while (setq line (pop lines) origline line)
3058 (catch 'nextline
3060 ;; end of quote section?
3061 (when (and inquote (string-match "^\\*+ " line))
3062 (insert "</pre>\n")
3063 (setq inquote nil))
3064 ;; inside a quote section?
3065 (when inquote
3066 (insert (org-html-protect line) "\n")
3067 (throw 'nextline nil))
3069 ;; Fixed-width, verbatim lines (examples)
3070 (when (and org-export-with-fixed-width
3071 (string-match "^[ \t]*:\\(.*\\)" line))
3072 (when (not infixed)
3073 (setq infixed t)
3074 (insert "<pre class=\"example\">\n"))
3075 (insert (org-html-protect (match-string 1 line)) "\n")
3076 (when (or (not lines)
3077 (not (string-match "^[ \t]*\\(:.*\\)"
3078 (car lines))))
3079 (setq infixed nil)
3080 (insert "</pre>\n"))
3081 (throw 'nextline nil))
3083 ;; Protected HTML
3084 (when (get-text-property 0 'org-protected line)
3085 (let (par)
3086 (when (re-search-backward
3087 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3088 (setq par (match-string 1))
3089 (replace-match "\\2\n"))
3090 (insert line "\n")
3091 (while (and lines
3092 (not (string-match "^[ \t]*:" (car lines)))
3093 (or (= (length (car lines)) 0)
3094 (get-text-property 0 'org-protected (car lines))))
3095 (insert (pop lines) "\n"))
3096 (and par (insert "<p>\n")))
3097 (throw 'nextline nil))
3099 ;; Horizontal line
3100 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3101 (insert "\n<hr/>\n")
3102 (throw 'nextline nil))
3104 ;; Blockquotes and verse
3105 (when (equal "ORG-BLOCKQUOTE-START" line)
3106 (insert "<blockquote>\n<p>\n")
3107 (throw 'nextline nil))
3108 (when (equal "ORG-BLOCKQUOTE-END" line)
3109 (insert "</p>\n</blockquote>\n")
3110 (throw 'nextline nil))
3111 (when (equal "ORG-VERSE-START" line)
3112 (insert "\n<p class=\"verse\">\n")
3113 (setq inverse t)
3114 (throw 'nextline nil))
3115 (when (equal "ORG-VERSE-END" line)
3116 (insert "</p>\n")
3117 (setq inverse nil)
3118 (throw 'nextline nil))
3119 (when inverse
3120 (let ((i (org-get-string-indentation line)))
3121 (if (> i 0)
3122 (setq line (concat (mapconcat 'identity
3123 (make-list (* 2 i) "\\nbsp") "")
3124 " " (org-trim line))))
3125 (setq line (concat line " \\\\"))))
3127 ;; make targets to anchors
3128 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3129 (cond
3130 ((match-end 2)
3131 (setq line (replace-match
3132 (concat "@<a name=\""
3133 (org-solidify-link-text (match-string 1 line))
3134 "\">\\nbsp@</a>")
3135 t t line)))
3136 ((and org-export-with-toc (equal (string-to-char line) ?*))
3137 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3138 (setq line (replace-match
3139 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3140 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3141 t t line)))
3143 (setq line (replace-match
3144 (concat "@<a name=\""
3145 (org-solidify-link-text (match-string 1 line))
3146 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3147 t t line)))))
3149 (setq line (org-html-handle-time-stamps line))
3151 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3152 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3153 ;; Also handle sub_superscripts and checkboxes
3154 (or (string-match org-table-hline-regexp line)
3155 (setq line (org-html-expand line)))
3157 ;; Format the links
3158 (setq start 0)
3159 (while (string-match org-bracket-link-analytic-regexp line start)
3160 (setq start (match-beginning 0))
3161 (setq path (save-match-data (org-link-unescape
3162 (match-string 3 line))))
3163 (setq type (cond
3164 ((match-end 2) (match-string 2 line))
3165 ((save-match-data
3166 (or (file-name-absolute-p path)
3167 (string-match "^\\.\\.?/" path)))
3168 "file")
3169 (t "internal")))
3170 (setq path (org-extract-attributes path))
3171 (setq attr (org-attributes-to-string
3172 (get-text-property 0 'org-attributes path)))
3173 (setq desc1 (if (match-end 5) (match-string 5 line))
3174 desc2 (if (match-end 2) (concat type ":" path) path)
3175 descp (and desc1 (not (equal desc1 desc2)))
3176 desc (or desc1 desc2))
3177 ;; Make an image out of the description if that is so wanted
3178 (when (and descp (org-file-image-p desc))
3179 (save-match-data
3180 (if (string-match "^file:" desc)
3181 (setq desc (substring desc (match-end 0)))))
3182 (setq desc (concat "<img src=\"" desc "\"/>")))
3183 ;; FIXME: do we need to unescape here somewhere?
3184 (cond
3185 ((equal type "internal")
3186 (setq rpl
3187 (concat
3188 "<a href=\"#"
3189 (org-solidify-link-text
3190 (save-match-data (org-link-unescape path)) nil)
3191 "\"" attr ">" desc "</a>")))
3192 ((member type '("http" "https"))
3193 ;; standard URL, just check if we need to inline an image
3194 (if (and (or (eq t org-export-html-inline-images)
3195 (and org-export-html-inline-images (not descp)))
3196 (org-file-image-p path))
3197 (setq rpl (concat "<img src=\"" type ":" path "\"" attr "/>"))
3198 (setq link (concat type ":" path))
3199 (setq rpl (concat "<a href=\"" link "\"" attr ">"
3200 desc "</a>"))))
3201 ((member type '("ftp" "mailto" "news"))
3202 ;; standard URL
3203 (setq link (concat type ":" path))
3204 (setq rpl (concat "<a href=\"" link "\"" attr ">" desc "</a>")))
3206 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3207 ;; The link protocol has a function for format the link
3208 (setq rpl
3209 (save-match-data
3210 (funcall fnc (org-link-unescape path) desc1 'html))))
3212 ((string= type "file")
3213 ;; FILE link
3214 (let* ((filename path)
3215 (abs-p (file-name-absolute-p filename))
3216 thefile file-is-image-p search)
3217 (save-match-data
3218 (if (string-match "::\\(.*\\)" filename)
3219 (setq search (match-string 1 filename)
3220 filename (replace-match "" t nil filename)))
3221 (setq valid
3222 (if (functionp link-validate)
3223 (funcall link-validate filename current-dir)
3225 (setq file-is-image-p (org-file-image-p filename))
3226 (setq thefile (if abs-p (expand-file-name filename) filename))
3227 (when (and org-export-html-link-org-files-as-html
3228 (string-match "\\.org$" thefile))
3229 (setq thefile (concat (substring thefile 0
3230 (match-beginning 0))
3231 "." html-extension))
3232 (if (and search
3233 ;; make sure this is can be used as target search
3234 (not (string-match "^[0-9]*$" search))
3235 (not (string-match "^\\*" search))
3236 (not (string-match "^/.*/$" search)))
3237 (setq thefile (concat thefile "#"
3238 (org-solidify-link-text
3239 (org-link-unescape search)))))
3240 (when (string-match "^file:" desc)
3241 (setq desc (replace-match "" t t desc))
3242 (if (string-match "\\.org$" desc)
3243 (setq desc (replace-match "" t t desc))))))
3244 (setq rpl (if (and file-is-image-p
3245 (or (eq t org-export-html-inline-images)
3246 (and org-export-html-inline-images
3247 (not descp))))
3248 (concat "<img src=\"" thefile "\"" attr "/>")
3249 (concat "<a href=\"" thefile "\"" attr ">"
3250 desc "</a>")))
3251 (if (not valid) (setq rpl desc))))
3254 ;; just publish the path, as default
3255 (setq rpl (concat "<i>&lt;" type ":"
3256 (save-match-data (org-link-unescape path))
3257 "&gt;</i>"))))
3258 (setq line (replace-match rpl t t line)
3259 start (+ start (length rpl))))
3261 ;; TODO items
3262 (if (and (string-match org-todo-line-regexp line)
3263 (match-beginning 2))
3265 (setq line
3266 (concat (substring line 0 (match-beginning 2))
3267 "<span class=\""
3268 (if (member (match-string 2 line)
3269 org-done-keywords)
3270 "done" "todo")
3271 "\">" (match-string 2 line)
3272 "</span>" (substring line (match-end 2)))))
3274 ;; Does this contain a reference to a footnote?
3275 (when org-export-with-footnotes
3276 (setq start 0)
3277 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3278 (if (get-text-property (match-beginning 2) 'org-protected line)
3279 (setq start (match-end 2))
3280 (let ((n (match-string 2 line)))
3281 (setq line
3282 (replace-match
3283 (format
3284 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3285 (match-string 1 line) n n n)
3286 t t line))))))
3288 (cond
3289 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3290 ;; This is a headline
3291 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3292 txt (match-string 2 line))
3293 (if (string-match quote-re0 txt)
3294 (setq txt (replace-match "" t t txt)))
3295 (if (<= level (max umax umax-toc))
3296 (setq head-count (+ head-count 1)))
3297 (when in-local-list
3298 ;; Close any local lists before inserting a new header line
3299 (while local-list-type
3300 (org-close-li (car local-list-type))
3301 (insert (format "</%sl>\n" (car local-list-type)))
3302 (pop local-list-type))
3303 (setq local-list-indent nil
3304 in-local-list nil))
3305 (setq first-heading-pos (or first-heading-pos (point)))
3306 (org-html-level-start level txt umax
3307 (and org-export-with-toc (<= level umax))
3308 head-count)
3309 ;; QUOTES
3310 (when (string-match quote-re line)
3311 (insert "<pre>")
3312 (setq inquote t)))
3314 ((and org-export-with-tables
3315 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3316 (if (not table-open)
3317 ;; New table starts
3318 (setq table-open t table-buffer nil table-orig-buffer nil))
3319 ;; Accumulate lines
3320 (setq table-buffer (cons line table-buffer)
3321 table-orig-buffer (cons origline table-orig-buffer))
3322 (when (or (not lines)
3323 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3324 (car lines))))
3325 (setq table-open nil
3326 table-buffer (nreverse table-buffer)
3327 table-orig-buffer (nreverse table-orig-buffer))
3328 (org-close-par-maybe)
3329 (insert (org-format-table-html table-buffer table-orig-buffer))))
3331 ;; Normal lines
3332 (when (string-match
3333 (cond
3334 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3335 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3336 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3337 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3338 line)
3339 (setq ind (org-get-string-indentation line)
3340 item-type (if (match-beginning 4) "o" "u")
3341 starter (if (match-beginning 2)
3342 (substring (match-string 2 line) 0 -1))
3343 line (substring line (match-beginning 5))
3344 item-tag nil)
3345 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3346 (setq item-type "d"
3347 item-tag (match-string 1 line)
3348 line (substring line (match-end 0))))
3349 (when (and (not (equal item-type "d"))
3350 (not (string-match "[^ \t]" line)))
3351 ;; empty line. Pretend indentation is large.
3352 (setq ind (if org-empty-line-terminates-plain-lists
3354 (1+ (or (car local-list-indent) 1)))))
3355 (setq didclose nil)
3356 (while (and in-local-list
3357 (or (and (= ind (car local-list-indent))
3358 (not starter))
3359 (< ind (car local-list-indent))))
3360 (setq didclose t)
3361 (org-close-li (car local-list-type))
3362 (insert (format "</%sl>\n" (car local-list-type)))
3363 (pop local-list-type) (pop local-list-indent)
3364 (setq in-local-list local-list-indent))
3365 (cond
3366 ((and starter
3367 (or (not in-local-list)
3368 (> ind (car local-list-indent))))
3369 ;; Start new (level of) list
3370 (org-close-par-maybe)
3371 (insert (cond
3372 ((equal item-type "u") "<ul>\n<li>\n")
3373 ((equal item-type "o") "<ol>\n<li>\n")
3374 ((equal item-type "d")
3375 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3376 (push item-type local-list-type)
3377 (push ind local-list-indent)
3378 (setq in-local-list t))
3379 (starter
3380 ;; continue current list
3381 (org-close-li (car local-list-type))
3382 (insert (cond
3383 ((equal (car local-list-type) "d")
3384 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3385 (t "<li>\n"))))
3386 (didclose
3387 ;; we did close a list, normal text follows: need <p>
3388 (org-open-par)))
3389 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3390 (setq line
3391 (replace-match
3392 (if (equal (match-string 1 line) "X")
3393 "<b>[X]</b>"
3394 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3395 t t line))))
3397 ;; Empty lines start a new paragraph. If hand-formatted lists
3398 ;; are not fully interpreted, lines starting with "-", "+", "*"
3399 ;; also start a new paragraph.
3400 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3402 ;; Is this the start of a footnote?
3403 (when org-export-with-footnotes
3404 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3405 (org-close-par-maybe)
3406 (let ((n (match-string 1 line)))
3407 (setq line (replace-match
3408 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3409 (setq line (concat line "</p>")))))
3411 ;; Check if the line break needs to be conserved
3412 (cond
3413 ((string-match "\\\\\\\\[ \t]*$" line)
3414 (setq line (replace-match "<br/>" t t line)))
3415 (org-export-preserve-breaks
3416 (setq line (concat line "<br/>"))))
3418 (insert line "\n")))))
3420 ;; Properly close all local lists and other lists
3421 (when inquote (insert "</pre>\n"))
3422 (when in-local-list
3423 ;; Close any local lists before inserting a new header line
3424 (while local-list-type
3425 (org-close-li (car local-list-type))
3426 (insert (format "</%sl>\n" (car local-list-type)))
3427 (pop local-list-type))
3428 (setq local-list-indent nil
3429 in-local-list nil))
3430 (org-html-level-start 1 nil umax
3431 (and org-export-with-toc (<= level umax))
3432 head-count)
3433 ;; the </div> to close the last text-... div.
3434 (insert "</div>\n")
3436 (unless body-only
3437 (when (plist-get opt-plist :auto-postamble)
3438 (insert "<div id=\"postamble\">")
3439 (when (and org-export-author-info author)
3440 (insert "<p class=\"author\"> "
3441 (nth 1 lang-words) ": " author "\n")
3442 (when email
3443 (if (listp (split-string email ",+ *"))
3444 (mapc (lambda(e)
3445 (insert "<a href=\"mailto:" e "\">&lt;"
3446 e "&gt;</a>\n"))
3447 (split-string email ",+ *"))
3448 (insert "<a href=\"mailto:" email "\">&lt;"
3449 email "&gt;</a>\n")))
3450 (insert "</p>\n"))
3451 (when (and date org-export-time-stamp-file)
3452 (insert "<p class=\"date\"> "
3453 (nth 2 lang-words) ": "
3454 date "</p>\n"))
3455 (when org-export-creator-info
3456 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3457 org-version emacs-major-version)))
3458 (insert "</div>"))
3460 (if org-export-html-with-timestamp
3461 (insert org-export-html-html-helper-timestamp))
3462 (insert (or (plist-get opt-plist :postamble) ""))
3463 (insert "</body>\n</html>\n"))
3465 (unless (plist-get opt-plist :buffer-will-be-killed)
3466 (normal-mode)
3467 (if (eq major-mode default-major-mode) (html-mode)))
3469 ;; insert the table of contents
3470 (goto-char (point-min))
3471 (when thetoc
3472 (if (or (re-search-forward
3473 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3474 (re-search-forward
3475 "\\[TABLE-OF-CONTENTS\\]" nil t))
3476 (progn
3477 (goto-char (match-beginning 0))
3478 (replace-match ""))
3479 (goto-char first-heading-pos)
3480 (when (looking-at "\\s-*</p>")
3481 (goto-char (match-end 0))
3482 (insert "\n")))
3483 (insert "<div id=\"table-of-contents\">\n")
3484 (mapc 'insert thetoc)
3485 (insert "</div>\n"))
3486 ;; remove empty paragraphs and lists
3487 (goto-char (point-min))
3488 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3489 (replace-match ""))
3490 (goto-char (point-min))
3491 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3492 (replace-match ""))
3493 (goto-char (point-min))
3494 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3495 (replace-match ""))
3496 ;; Convert whitespace place holders
3497 (goto-char (point-min))
3498 (let (beg end n)
3499 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3500 (setq n (get-text-property beg 'org-whitespace)
3501 end (next-single-property-change beg 'org-whitespace))
3502 (goto-char beg)
3503 (delete-region beg end)
3504 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3505 (make-string n ?x)))))
3506 (or to-buffer (save-buffer))
3507 (goto-char (point-min))
3508 (message "Exporting... done")
3509 (if (eq to-buffer 'string)
3510 (prog1 (buffer-substring (point-min) (point-max))
3511 (kill-buffer (current-buffer)))
3512 (current-buffer)))))
3515 (defvar org-table-colgroup-info nil)
3516 (defun org-format-table-ascii (lines)
3517 "Format a table for ascii export."
3518 (if (stringp lines)
3519 (setq lines (org-split-string lines "\n")))
3520 (if (not (string-match "^[ \t]*|" (car lines)))
3521 ;; Table made by table.el - test for spanning
3522 lines
3524 ;; A normal org table
3525 ;; Get rid of hlines at beginning and end
3526 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3527 (setq lines (nreverse lines))
3528 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3529 (setq lines (nreverse lines))
3530 (when org-export-table-remove-special-lines
3531 ;; Check if the table has a marking column. If yes remove the
3532 ;; column and the special lines
3533 (setq lines (org-table-clean-before-export lines)))
3534 ;; Get rid of the vertical lines except for grouping
3535 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3536 rtn line vl1 start)
3537 (while (setq line (pop lines))
3538 (if (string-match org-table-hline-regexp line)
3539 (and (string-match "|\\(.*\\)|" line)
3540 (setq line (replace-match " \\1" t nil line)))
3541 (setq start 0 vl1 vl)
3542 (while (string-match "|" line start)
3543 (setq start (match-end 0))
3544 (or (pop vl1) (setq line (replace-match " " t t line)))))
3545 (push line rtn))
3546 (nreverse rtn))))
3548 (defun org-colgroup-info-to-vline-list (info)
3549 (let (vl new last)
3550 (while info
3551 (setq last new new (pop info))
3552 (if (or (memq last '(:end :startend))
3553 (memq new '(:start :startend)))
3554 (push t vl)
3555 (push nil vl)))
3556 (setq vl (nreverse vl))
3557 (and vl (setcar vl nil))
3558 vl))
3560 (defvar org-table-number-regexp) ; defined in org-table.el
3561 (defun org-format-table-html (lines olines)
3562 "Find out which HTML converter to use and return the HTML code."
3563 (if (stringp lines)
3564 (setq lines (org-split-string lines "\n")))
3565 (if (string-match "^[ \t]*|" (car lines))
3566 ;; A normal org table
3567 (org-format-org-table-html lines)
3568 ;; Table made by table.el - test for spanning
3569 (let* ((hlines (delq nil (mapcar
3570 (lambda (x)
3571 (if (string-match "^[ \t]*\\+-" x) x
3572 nil))
3573 lines)))
3574 (first (car hlines))
3575 (ll (and (string-match "\\S-+" first)
3576 (match-string 0 first)))
3577 (re (concat "^[ \t]*" (regexp-quote ll)))
3578 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3579 hlines))))
3580 (if (and (not spanning)
3581 (not org-export-prefer-native-exporter-for-tables))
3582 ;; We can use my own converter with HTML conversions
3583 (org-format-table-table-html lines)
3584 ;; Need to use the code generator in table.el, with the original text.
3585 (org-format-table-table-html-using-table-generate-source olines)))))
3587 (defvar org-table-number-fraction) ; defined in org-table.el
3588 (defun org-format-org-table-html (lines &optional splice)
3589 "Format a table into HTML."
3590 (require 'org-table)
3591 ;; Get rid of hlines at beginning and end
3592 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3593 (setq lines (nreverse lines))
3594 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3595 (setq lines (nreverse lines))
3596 (when org-export-table-remove-special-lines
3597 ;; Check if the table has a marking column. If yes remove the
3598 ;; column and the special lines
3599 (setq lines (org-table-clean-before-export lines)))
3601 (let ((head (and org-export-highlight-first-table-line
3602 (delq nil (mapcar
3603 (lambda (x) (string-match "^[ \t]*|-" x))
3604 (cdr lines)))))
3605 (nlines 0) fnum i
3606 tbopen line fields html gr colgropen)
3607 (if splice (setq head nil))
3608 (unless splice (push (if head "<thead>" "<tbody>") html))
3609 (setq tbopen t)
3610 (while (setq line (pop lines))
3611 (catch 'next-line
3612 (if (string-match "^[ \t]*|-" line)
3613 (progn
3614 (unless splice
3615 (push (if head "</thead>" "</tbody>") html)
3616 (if lines (push "<tbody>" html) (setq tbopen nil)))
3617 (setq head nil) ;; head ends here, first time around
3618 ;; ignore this line
3619 (throw 'next-line t)))
3620 ;; Break the line into fields
3621 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3622 (unless fnum (setq fnum (make-vector (length fields) 0)))
3623 (setq nlines (1+ nlines) i -1)
3624 (push (concat "<tr>"
3625 (mapconcat
3626 (lambda (x)
3627 (setq i (1+ i))
3628 (if (and (< i nlines)
3629 (string-match org-table-number-regexp x))
3630 (incf (aref fnum i)))
3631 (if head
3632 (concat (car org-export-table-header-tags) x
3633 (cdr org-export-table-header-tags))
3634 (concat (car org-export-table-data-tags) x
3635 (cdr org-export-table-data-tags))))
3636 fields "")
3637 "</tr>")
3638 html)))
3639 (unless splice (if tbopen (push "</tbody>" html)))
3640 (unless splice (push "</table>\n" html))
3641 (setq html (nreverse html))
3642 (unless splice
3643 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3644 (push (mapconcat
3645 (lambda (x)
3646 (setq gr (pop org-table-colgroup-info))
3647 (format "%s<col align=\"%s\"></col>%s"
3648 (if (memq gr '(:start :startend))
3649 (prog1
3650 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3651 (setq colgropen t))
3653 (if (> (/ (float x) nlines) org-table-number-fraction)
3654 "right" "left")
3655 (if (memq gr '(:end :startend))
3656 (progn (setq colgropen nil) "</colgroup>")
3657 "")))
3658 fnum "")
3659 html)
3660 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3661 (push html-table-tag html))
3662 (concat (mapconcat 'identity html "\n") "\n")))
3664 (defun org-table-clean-before-export (lines)
3665 "Check if the table has a marking column.
3666 If yes remove the column and the special lines."
3667 (setq org-table-colgroup-info nil)
3668 (if (memq nil
3669 (mapcar
3670 (lambda (x) (or (string-match "^[ \t]*|-" x)
3671 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3672 lines))
3673 (progn
3674 (setq org-table-clean-did-remove-column nil)
3675 (delq nil
3676 (mapcar
3677 (lambda (x)
3678 (cond
3679 ((string-match "^[ \t]*| */ *|" x)
3680 (setq org-table-colgroup-info
3681 (mapcar (lambda (x)
3682 (cond ((member x '("<" "&lt;")) :start)
3683 ((member x '(">" "&gt;")) :end)
3684 ((member x '("<>" "&lt;&gt;")) :startend)
3685 (t nil)))
3686 (org-split-string x "[ \t]*|[ \t]*")))
3687 nil)
3688 (t x)))
3689 lines)))
3690 (setq org-table-clean-did-remove-column t)
3691 (delq nil
3692 (mapcar
3693 (lambda (x)
3694 (cond
3695 ((string-match "^[ \t]*| */ *|" x)
3696 (setq org-table-colgroup-info
3697 (mapcar (lambda (x)
3698 (cond ((member x '("<" "&lt;")) :start)
3699 ((member x '(">" "&gt;")) :end)
3700 ((member x '("<>" "&lt;&gt;")) :startend)
3701 (t nil)))
3702 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3703 nil)
3704 ((string-match "^[ \t]*| *[!_^/] *|" x)
3705 nil) ; ignore this line
3706 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3707 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3708 ;; remove the first column
3709 (replace-match "\\1|" t nil x))))
3710 lines))))
3712 (defun org-format-table-table-html (lines)
3713 "Format a table generated by table.el into HTML.
3714 This conversion does *not* use `table-generate-source' from table.el.
3715 This has the advantage that Org-mode's HTML conversions can be used.
3716 But it has the disadvantage, that no cell- or row-spanning is allowed."
3717 (let (line field-buffer
3718 (head org-export-highlight-first-table-line)
3719 fields html empty)
3720 (setq html (concat html-table-tag "\n"))
3721 (while (setq line (pop lines))
3722 (setq empty "&nbsp;")
3723 (catch 'next-line
3724 (if (string-match "^[ \t]*\\+-" line)
3725 (progn
3726 (if field-buffer
3727 (progn
3728 (setq
3729 html
3730 (concat
3731 html
3732 "<tr>"
3733 (mapconcat
3734 (lambda (x)
3735 (if (equal x "") (setq x empty))
3736 (if head
3737 (concat (car org-export-table-header-tags) x
3738 (cdr org-export-table-header-tags))
3739 (concat (car org-export-table-data-tags) x
3740 (cdr org-export-table-data-tags))))
3741 field-buffer "\n")
3742 "</tr>\n"))
3743 (setq head nil)
3744 (setq field-buffer nil)))
3745 ;; Ignore this line
3746 (throw 'next-line t)))
3747 ;; Break the line into fields and store the fields
3748 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3749 (if field-buffer
3750 (setq field-buffer (mapcar
3751 (lambda (x)
3752 (concat x "<br/>" (pop fields)))
3753 field-buffer))
3754 (setq field-buffer fields))))
3755 (setq html (concat html "</table>\n"))
3756 html))
3758 (defun org-format-table-table-html-using-table-generate-source (lines)
3759 "Format a table into html, using `table-generate-source' from table.el.
3760 This has the advantage that cell- or row-spanning is allowed.
3761 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3762 (require 'table)
3763 (with-current-buffer (get-buffer-create " org-tmp1 ")
3764 (erase-buffer)
3765 (insert (mapconcat 'identity lines "\n"))
3766 (goto-char (point-min))
3767 (if (not (re-search-forward "|[^+]" nil t))
3768 (error "Error processing table"))
3769 (table-recognize-table)
3770 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3771 (table-generate-source 'html " org-tmp2 ")
3772 (set-buffer " org-tmp2 ")
3773 (buffer-substring (point-min) (point-max))))
3775 (defun org-export-splice-style (style extra)
3776 "Splice EXTRA into STYLE, just before \"</style>\"."
3777 (if (and (stringp extra)
3778 (string-match "\\S-" extra)
3779 (string-match "</style>" style))
3780 (concat (substring style 0 (match-beginning 0))
3781 "\n" extra "\n"
3782 (substring style (match-beginning 0)))
3783 style))
3785 (defun org-html-handle-time-stamps (s)
3786 "Format time stamps in string S, or remove them."
3787 (catch 'exit
3788 (let (r b)
3789 (while (string-match org-maybe-keyword-time-regexp s)
3790 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3791 ;; never export CLOCK
3792 (throw 'exit ""))
3793 (or b (setq b (substring s 0 (match-beginning 0))))
3794 (if (not org-export-with-timestamps)
3795 (setq r (concat r (substring s 0 (match-beginning 0)))
3796 s (substring s (match-end 0)))
3797 (setq r (concat
3798 r (substring s 0 (match-beginning 0))
3799 (if (match-end 1)
3800 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3801 (match-string 1 s)))
3802 (format " @<span class=\"timestamp\">%s@</span>"
3803 (substring
3804 (org-translate-time (match-string 3 s)) 1 -1)))
3805 s (substring s (match-end 0)))))
3806 ;; Line break if line started and ended with time stamp stuff
3807 (if (not r)
3809 (setq r (concat r s))
3810 (unless (string-match "\\S-" (concat b s))
3811 (setq r (concat r "@<br/>")))
3812 r))))
3814 (defun org-export-htmlize-region-for-paste (beg end)
3815 "Convert the region to HTML, using htmlize.el.
3816 This is much like `htmlize-region-for-paste', only that it uses
3817 the settings define in the org-... variables."
3818 (let* ((htmlize-output-type org-export-htmlize-output-type)
3819 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3820 (htmlbuf (htmlize-region beg end)))
3821 (unwind-protect
3822 (with-current-buffer htmlbuf
3823 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3824 (plist-get htmlize-buffer-places 'content-end)))
3825 (kill-buffer htmlbuf))))
3827 ;;;###autoload
3828 (defun org-export-htmlize-generate-css ()
3829 "Create the CSS for all font definitions in the current Emacs session.
3830 Use this to create face definitions in your CSS style file that can then
3831 be used by code snippets transformed by htmlize.
3832 This command just produces a buffer that contains class definitions for all
3833 faces used in the current Emacs session. You can copy and paste the ones you
3834 need into your CSS file.
3836 If you then set `org-export-htmlize-output-type' to `css', calls to
3837 the function `org-export-htmlize-region-for-paste' will produce code
3838 that uses these same face definitions."
3839 (interactive)
3840 (require 'htmlize)
3841 (and (get-buffer "*html*") (kill-buffer "*html*"))
3842 (with-temp-buffer
3843 (let ((fl (face-list))
3844 (htmlize-css-name-prefix "org-")
3845 (htmlize-output-type 'css)
3846 f i)
3847 (while (setq f (pop fl)
3848 i (and f (face-attribute f :inherit)))
3849 (when (and (symbolp f) (or (not i) (not (listp i))))
3850 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3851 (htmlize-region (point-min) (point-max))))
3852 (switch-to-buffer "*html*")
3853 (goto-char (point-min))
3854 (if (re-search-forward "<style" nil t)
3855 (delete-region (point-min) (match-beginning 0)))
3856 (if (re-search-forward "</style>" nil t)
3857 (delete-region (1+ (match-end 0)) (point-max)))
3858 (beginning-of-line 1)
3859 (if (looking-at " +") (replace-match ""))
3860 (goto-char (point-min)))
3862 (defun org-html-protect (s)
3863 ;; convert & to &amp;, < to &lt; and > to &gt;
3864 (let ((start 0))
3865 (while (string-match "&" s start)
3866 (setq s (replace-match "&amp;" t t s)
3867 start (1+ (match-beginning 0))))
3868 (while (string-match "<" s)
3869 (setq s (replace-match "&lt;" t t s)))
3870 (while (string-match ">" s)
3871 (setq s (replace-match "&gt;" t t s))))
3874 (defun org-export-cleanup-toc-line (s)
3875 "Remove tags and time staps from lines going into the toc."
3876 (when (memq org-export-with-tags '(not-in-toc nil))
3877 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3878 (setq s (replace-match "" t t s))))
3879 (when org-export-remove-timestamps-from-toc
3880 (while (string-match org-maybe-keyword-time-regexp s)
3881 (setq s (replace-match "" t t s))))
3882 (while (string-match org-bracket-link-regexp s)
3883 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3884 t t s)))
3887 (defun org-html-expand (string)
3888 "Prepare STRING for HTML export. Applies all active conversions.
3889 If there are links in the string, don't modify these."
3890 (let* ((re (concat org-bracket-link-regexp "\\|"
3891 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3892 m s l res)
3893 (while (setq m (string-match re string))
3894 (setq s (substring string 0 m)
3895 l (match-string 0 string)
3896 string (substring string (match-end 0)))
3897 (push (org-html-do-expand s) res)
3898 (push l res))
3899 (push (org-html-do-expand string) res)
3900 (apply 'concat (nreverse res))))
3902 (defun org-html-do-expand (s)
3903 "Apply all active conversions to translate special ASCII to HTML."
3904 (setq s (org-html-protect s))
3905 (if org-export-html-expand
3906 (let ((start 0))
3907 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3908 (setq s (replace-match "<\\1>" t nil s)))))
3909 (if org-export-with-emphasize
3910 (setq s (org-export-html-convert-emphasize s)))
3911 (if org-export-with-special-strings
3912 (setq s (org-export-html-convert-special-strings s)))
3913 (if org-export-with-sub-superscripts
3914 (setq s (org-export-html-convert-sub-super s)))
3915 (if org-export-with-TeX-macros
3916 (let ((start 0) wd ass)
3917 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
3918 s start))
3919 (if (get-text-property (match-beginning 0) 'org-protected s)
3920 (setq start (match-end 0))
3921 (setq wd (match-string 1 s))
3922 (if (setq ass (assoc wd org-html-entities))
3923 (setq s (replace-match (or (cdr ass)
3924 (concat "&" (car ass) ";"))
3925 t t s))
3926 (setq start (+ start (length wd))))))))
3929 (defun org-create-multibrace-regexp (left right n)
3930 "Create a regular expression which will match a balanced sexp.
3931 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3932 as single character strings.
3933 The regexp returned will match the entire expression including the
3934 delimiters. It will also define a single group which contains the
3935 match except for the outermost delimiters. The maximum depth of
3936 stacked delimiters is N. Escaping delimiters is not possible."
3937 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3938 (or "\\|")
3939 (re nothing)
3940 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3941 (while (> n 1)
3942 (setq n (1- n)
3943 re (concat re or next)
3944 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3945 (concat left "\\(" re "\\)" right)))
3947 (defvar org-match-substring-regexp
3948 (concat
3949 "\\([^\\]\\)\\([_^]\\)\\("
3950 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3951 "\\|"
3952 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3953 "\\|"
3954 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3955 "The regular expression matching a sub- or superscript.")
3957 (defvar org-match-substring-with-braces-regexp
3958 (concat
3959 "\\([^\\]\\)\\([_^]\\)\\("
3960 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3961 "\\)")
3962 "The regular expression matching a sub- or superscript, forcing braces.")
3964 (defconst org-export-html-special-string-regexps
3965 '(("\\\\-" . "&shy;")
3966 ("---\\([^-]\\)" . "&mdash;\\1")
3967 ("--\\([^-]\\)" . "&ndash;\\1")
3968 ("\\.\\.\\." . "&hellip;"))
3969 "Regular expressions for special string conversion.")
3971 (defun org-export-html-convert-special-strings (string)
3972 "Convert special characters in STRING to HTML."
3973 (let ((all org-export-html-special-string-regexps)
3974 e a re rpl start)
3975 (while (setq a (pop all))
3976 (setq re (car a) rpl (cdr a) start 0)
3977 (while (string-match re string start)
3978 (if (get-text-property (match-beginning 0) 'org-protected string)
3979 (setq start (match-end 0))
3980 (setq string (replace-match rpl t nil string)))))
3981 string))
3983 (defun org-export-html-convert-sub-super (string)
3984 "Convert sub- and superscripts in STRING to HTML."
3985 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3986 (while (string-match org-match-substring-regexp string s)
3987 (cond
3988 ((and requireb (match-end 8)) (setq s (match-end 2)))
3989 ((get-text-property (match-beginning 2) 'org-protected string)
3990 (setq s (match-end 2)))
3992 (setq s (match-end 1)
3993 key (if (string= (match-string 2 string) "_") "sub" "sup")
3994 c (or (match-string 8 string)
3995 (match-string 6 string)
3996 (match-string 5 string))
3997 string (replace-match
3998 (concat (match-string 1 string)
3999 "<" key ">" c "</" key ">")
4000 t t string)))))
4001 (while (string-match "\\\\\\([_^]\\)" string)
4002 (setq string (replace-match (match-string 1 string) t t string)))
4003 string))
4005 (defun org-export-html-convert-emphasize (string)
4006 "Apply emphasis."
4007 (let ((s 0) rpl)
4008 (while (string-match org-emph-re string s)
4009 (if (not (equal
4010 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4011 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4012 (setq s (match-beginning 0)
4014 (concat
4015 (match-string 1 string)
4016 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4017 (match-string 4 string)
4018 (nth 3 (assoc (match-string 3 string)
4019 org-emphasis-alist))
4020 (match-string 5 string))
4021 string (replace-match rpl t t string)
4022 s (+ s (- (length rpl) 2)))
4023 (setq s (1+ s))))
4024 string))
4026 (defvar org-par-open nil)
4027 (defun org-open-par ()
4028 "Insert <p>, but first close previous paragraph if any."
4029 (org-close-par-maybe)
4030 (insert "\n<p>")
4031 (setq org-par-open t))
4032 (defun org-close-par-maybe ()
4033 "Close paragraph if there is one open."
4034 (when org-par-open
4035 (insert "</p>")
4036 (setq org-par-open nil)))
4037 (defun org-close-li (&optional type)
4038 "Close <li> if necessary."
4039 (org-close-par-maybe)
4040 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4042 (defvar body-only) ; dynamically scoped into this.
4043 (defun org-html-level-start (level title umax with-toc head-count)
4044 "Insert a new level in HTML export.
4045 When TITLE is nil, just close all open levels."
4046 (org-close-par-maybe)
4047 (let ((target (and title (org-get-text-property-any 0 'target title)))
4048 (l org-level-max)
4049 snumber)
4050 (while (>= l level)
4051 (if (aref org-levels-open (1- l))
4052 (progn
4053 (org-html-level-close l umax)
4054 (aset org-levels-open (1- l) nil)))
4055 (setq l (1- l)))
4056 (when title
4057 ;; If title is nil, this means this function is called to close
4058 ;; all levels, so the rest is done only if title is given
4059 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4060 (setq title (replace-match
4061 (if org-export-with-tags
4062 (save-match-data
4063 (concat
4064 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4065 (mapconcat 'identity (org-split-string
4066 (match-string 1 title) ":")
4067 "&nbsp;")
4068 "</span>"))
4070 t t title)))
4071 (if (> level umax)
4072 (progn
4073 (if (aref org-levels-open (1- level))
4074 (progn
4075 (org-close-li)
4076 (if target
4077 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
4078 (insert "<li>" title "<br/>\n")))
4079 (aset org-levels-open (1- level) t)
4080 (org-close-par-maybe)
4081 (if target
4082 (insert (format "<ul>\n<li id=\"%s\">" target)
4083 title "<br/>\n")
4084 (insert "<ul>\n<li>" title "<br/>\n"))))
4085 (aset org-levels-open (1- level) t)
4086 (setq snumber (org-section-number level))
4087 (if (and org-export-with-section-numbers (not body-only))
4088 (setq title (concat snumber " " title)))
4089 (setq level (+ level org-export-html-toplevel-hlevel -1))
4090 (unless (= head-count 1) (insert "\n</div>\n"))
4091 (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"
4092 snumber level level snumber title level snumber))
4093 (org-open-par)))))
4095 (defun org-get-text-property-any (pos prop &optional object)
4096 (or (get-text-property pos prop object)
4097 (and (setq pos (next-single-property-change pos prop object))
4098 (get-text-property pos prop object))))
4100 (defun org-html-level-close (level max-outline-level)
4101 "Terminate one level in HTML export."
4102 (if (<= level max-outline-level)
4103 (insert "</div>\n")
4104 (org-close-li)
4105 (insert "</ul>\n")))
4107 ;;; iCalendar export
4109 ;;;###autoload
4110 (defun org-export-icalendar-this-file ()
4111 "Export current file as an iCalendar file.
4112 The iCalendar file will be located in the same directory as the Org-mode
4113 file, but with extension `.ics'."
4114 (interactive)
4115 (org-export-icalendar nil buffer-file-name))
4117 ;;;###autoload
4118 (defun org-export-icalendar-all-agenda-files ()
4119 "Export all files in `org-agenda-files' to iCalendar .ics files.
4120 Each iCalendar file will be located in the same directory as the Org-mode
4121 file, but with extension `.ics'."
4122 (interactive)
4123 (apply 'org-export-icalendar nil (org-agenda-files t)))
4125 ;;;###autoload
4126 (defun org-export-icalendar-combine-agenda-files ()
4127 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4128 The file is stored under the name `org-combined-agenda-icalendar-file'."
4129 (interactive)
4130 (apply 'org-export-icalendar t (org-agenda-files t)))
4132 (defun org-export-icalendar (combine &rest files)
4133 "Create iCalendar files for all elements of FILES.
4134 If COMBINE is non-nil, combine all calendar entries into a single large
4135 file and store it under the name `org-combined-agenda-icalendar-file'."
4136 (save-excursion
4137 (org-prepare-agenda-buffers files)
4138 (let* ((dir (org-export-directory
4139 :ical (list :publishing-directory
4140 org-export-publishing-directory)))
4141 file ical-file ical-buffer category started org-agenda-new-buffers)
4142 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4143 (when combine
4144 (setq ical-file
4145 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4146 org-combined-agenda-icalendar-file
4147 (expand-file-name org-combined-agenda-icalendar-file dir))
4148 ical-buffer (org-get-agenda-file-buffer ical-file))
4149 (set-buffer ical-buffer) (erase-buffer))
4150 (while (setq file (pop files))
4151 (catch 'nextfile
4152 (org-check-agenda-file file)
4153 (set-buffer (org-get-agenda-file-buffer file))
4154 (unless combine
4155 (setq ical-file (concat (file-name-as-directory dir)
4156 (file-name-sans-extension
4157 (file-name-nondirectory buffer-file-name))
4158 ".ics"))
4159 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4160 (with-current-buffer ical-buffer (erase-buffer)))
4161 (setq category (or org-category
4162 (file-name-sans-extension
4163 (file-name-nondirectory buffer-file-name))))
4164 (if (symbolp category) (setq category (symbol-name category)))
4165 (let ((standard-output ical-buffer))
4166 (if combine
4167 (and (not started) (setq started t)
4168 (org-start-icalendar-file org-icalendar-combined-name))
4169 (org-start-icalendar-file category))
4170 (org-print-icalendar-entries combine)
4171 (when (or (and combine (not files)) (not combine))
4172 (org-finish-icalendar-file)
4173 (set-buffer ical-buffer)
4174 (run-hooks 'org-before-save-iCalendar-file-hook)
4175 (save-buffer)
4176 (run-hooks 'org-after-save-iCalendar-file-hook)
4177 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4178 ))))
4179 (org-release-buffers org-agenda-new-buffers))))
4181 (defvar org-before-save-iCalendar-file-hook nil
4182 "Hook run before an iCalendar file has been saved.
4183 This can be used to modify the result of the export.")
4185 (defvar org-after-save-iCalendar-file-hook nil
4186 "Hook run after an iCalendar file has been saved.
4187 The iCalendar buffer is still current when this hook is run.
4188 A good way to use this is to tell a desktop calenndar application to re-read
4189 the iCalendar file.")
4191 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4192 (defun org-print-icalendar-entries (&optional combine)
4193 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4194 When COMBINE is non nil, add the category to each line."
4195 (require 'org-agenda)
4196 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4197 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4198 (dts (org-ical-ts-to-string
4199 (format-time-string (cdr org-time-stamp-formats) (current-time))
4200 "DTSTART"))
4201 hd ts ts2 state status (inc t) pos b sexp rrule
4202 scheduledp deadlinep todo prefix due start
4203 tmp pri categories entry location summary desc uid
4204 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4205 (org-refresh-category-properties)
4206 (save-excursion
4207 (goto-char (point-min))
4208 (while (re-search-forward re1 nil t)
4209 (catch :skip
4210 (org-agenda-skip)
4211 (when (boundp 'org-icalendar-verify-function)
4212 (unless (funcall org-icalendar-verify-function)
4213 (outline-next-heading)
4214 (backward-char 1)
4215 (throw :skip nil)))
4216 (setq pos (match-beginning 0)
4217 ts (match-string 0)
4218 inc t
4219 hd (condition-case nil
4220 (org-icalendar-cleanup-string
4221 (org-get-heading))
4222 (error (throw :skip nil)))
4223 summary (org-icalendar-cleanup-string
4224 (org-entry-get nil "SUMMARY"))
4225 desc (org-icalendar-cleanup-string
4226 (or (org-entry-get nil "DESCRIPTION")
4227 (and org-icalendar-include-body (org-get-entry)))
4228 t org-icalendar-include-body)
4229 location (org-icalendar-cleanup-string
4230 (org-entry-get nil "LOCATION"))
4231 uid (if org-icalendar-store-UID
4232 (org-id-get-create)
4233 (or (org-id-get) (org-id-new)))
4234 categories (org-export-get-categories)
4235 deadlinep nil scheduledp nil)
4236 (if (looking-at re2)
4237 (progn
4238 (goto-char (match-end 0))
4239 (setq ts2 (match-string 1)
4240 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4241 (setq tmp (buffer-substring (max (point-min)
4242 (- pos org-ds-keyword-length))
4243 pos)
4244 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4245 (progn
4246 (setq inc nil)
4247 (replace-match "\\1" t nil ts))
4249 deadlinep (string-match org-deadline-regexp tmp)
4250 scheduledp (string-match org-scheduled-regexp tmp)
4251 todo (org-get-todo-state)
4252 ;; donep (org-entry-is-done-p)
4254 (when (and
4255 deadlinep
4256 (if todo
4257 (not (memq 'event-if-todo org-icalendar-use-deadline))
4258 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4259 (throw :skip t))
4260 (when (and
4261 scheduledp
4262 (if todo
4263 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4264 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4265 (throw :skip t))
4266 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4267 (if (or (string-match org-tr-regexp hd)
4268 (string-match org-ts-regexp hd))
4269 (setq hd (replace-match "" t t hd)))
4270 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4271 (setq rrule
4272 (concat "\nRRULE:FREQ="
4273 (cdr (assoc
4274 (match-string 2 ts)
4275 '(("d" . "DAILY")("w" . "WEEKLY")
4276 ("m" . "MONTHLY")("y" . "YEARLY"))))
4277 ";INTERVAL=" (match-string 1 ts)))
4278 (setq rrule ""))
4279 (setq summary (or summary hd))
4280 (if (string-match org-bracket-link-regexp summary)
4281 (setq summary
4282 (replace-match (if (match-end 3)
4283 (match-string 3 summary)
4284 (match-string 1 summary))
4285 t t summary)))
4286 (if deadlinep (setq summary (concat "DL: " summary)))
4287 (if scheduledp (setq summary (concat "S: " summary)))
4288 (if (string-match "\\`<%%" ts)
4289 (with-current-buffer sexp-buffer
4290 (insert (substring ts 1 -1) " " summary "\n"))
4291 (princ (format "BEGIN:VEVENT
4292 UID: %s
4294 %s%s
4295 SUMMARY:%s%s%s
4296 CATEGORIES:%s
4297 END:VEVENT\n"
4298 (concat prefix uid)
4299 (org-ical-ts-to-string ts "DTSTART")
4300 (org-ical-ts-to-string ts2 "DTEND" inc)
4301 rrule summary
4302 (if (and desc (string-match "\\S-" desc))
4303 (concat "\nDESCRIPTION: " desc) "")
4304 (if (and location (string-match "\\S-" location))
4305 (concat "\nLOCATION: " location) "")
4306 categories)))))
4307 (when (and org-icalendar-include-sexps
4308 (condition-case nil (require 'icalendar) (error nil))
4309 (fboundp 'icalendar-export-region))
4310 ;; Get all the literal sexps
4311 (goto-char (point-min))
4312 (while (re-search-forward "^&?%%(" nil t)
4313 (catch :skip
4314 (org-agenda-skip)
4315 (setq b (match-beginning 0))
4316 (goto-char (1- (match-end 0)))
4317 (forward-sexp 1)
4318 (end-of-line 1)
4319 (setq sexp (buffer-substring b (point)))
4320 (with-current-buffer sexp-buffer
4321 (insert sexp "\n"))))
4322 (princ (org-diary-to-ical-string sexp-buffer))
4323 (kill-buffer sexp-buffer))
4325 (when org-icalendar-include-todo
4326 (setq prefix "TODO-")
4327 (goto-char (point-min))
4328 (while (re-search-forward org-todo-line-regexp nil t)
4329 (catch :skip
4330 (org-agenda-skip)
4331 (when (boundp 'org-icalendar-verify-function)
4332 (unless (funcall org-icalendar-verify-function)
4333 (outline-next-heading)
4334 (backward-char 1)
4335 (throw :skip nil)))
4336 (setq state (match-string 2))
4337 (setq status (if (member state org-done-keywords)
4338 "COMPLETED" "NEEDS-ACTION"))
4339 (when (and state
4340 (or (not (member state org-done-keywords))
4341 (eq org-icalendar-include-todo 'all))
4342 (not (member org-archive-tag (org-get-tags-at)))
4344 (setq hd (match-string 3)
4345 summary (org-icalendar-cleanup-string
4346 (org-entry-get nil "SUMMARY"))
4347 desc (org-icalendar-cleanup-string
4348 (or (org-entry-get nil "DESCRIPTION")
4349 (and org-icalendar-include-body (org-get-entry)))
4350 t org-icalendar-include-body)
4351 location (org-icalendar-cleanup-string
4352 (org-entry-get nil "LOCATION"))
4353 due (and (member 'todo-due org-icalendar-use-deadline)
4354 (org-entry-get nil "DEADLINE"))
4355 start (and (member 'todo-start org-icalendar-use-scheduled)
4356 (org-entry-get nil "SCHEDULED"))
4357 categories (org-export-get-categories)
4358 uid (if org-icalendar-store-UID
4359 (org-id-get-create)
4360 (or (org-id-get) (org-id-new))))
4361 (and due (setq due (org-ical-ts-to-string due "DUE")))
4362 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4364 (if (string-match org-bracket-link-regexp hd)
4365 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4366 (match-string 1 hd))
4367 t t hd)))
4368 (if (string-match org-priority-regexp hd)
4369 (setq pri (string-to-char (match-string 2 hd))
4370 hd (concat (substring hd 0 (match-beginning 1))
4371 (substring hd (match-end 1))))
4372 (setq pri org-default-priority))
4373 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4374 (- org-lowest-priority org-highest-priority))))))
4376 (princ (format "BEGIN:VTODO
4377 UID: %s
4379 SUMMARY:%s%s%s%s
4380 CATEGORIES:%s
4381 SEQUENCE:1
4382 PRIORITY:%d
4383 STATUS:%s
4384 END:VTODO\n"
4385 (concat prefix uid)
4386 (or start dts)
4387 (or summary hd)
4388 (if (and location (string-match "\\S-" location))
4389 (concat "\nLOCATION: " location) "")
4390 (if (and desc (string-match "\\S-" desc))
4391 (concat "\nDESCRIPTION: " desc) "")
4392 (if due (concat "\n" due) "")
4393 categories
4394 pri status)))))))))
4396 (defun org-export-get-categories ()
4397 "Get categories according to `org-icalendar-categories'."
4398 (let ((cs org-icalendar-categories) c rtn tmp)
4399 (while (setq c (pop cs))
4400 (cond
4401 ((eq c 'category) (push (org-get-category) rtn))
4402 ((eq c 'todo-state)
4403 (setq tmp (org-get-todo-state))
4404 (and tmp (push tmp rtn)))
4405 ((eq c 'local-tags)
4406 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4407 ((eq c 'all-tags)
4408 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4409 (mapconcat 'identity (nreverse rtn) ",")))
4411 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4412 "Take out stuff and quote what needs to be quoted.
4413 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4414 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4415 characters."
4416 (if (not s)
4418 (when is-body
4419 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4420 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4421 (while (string-match re s) (setq s (replace-match "" t t s)))
4422 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4423 (let ((start 0))
4424 (while (string-match "\\([,;]\\)" s start)
4425 (setq start (+ (match-beginning 0) 2)
4426 s (replace-match "\\\\\\1" nil nil s))))
4427 (when is-body
4428 (while (string-match "[ \t]*\n[ \t]*" s)
4429 (setq s (replace-match "\\n" t t s))))
4430 (setq s (org-trim s))
4431 (if is-body
4432 (if maxlength
4433 (if (and (numberp maxlength)
4434 (> (length s) maxlength))
4435 (setq s (substring s 0 maxlength)))))
4438 (defun org-get-entry ()
4439 "Clean-up description string."
4440 (save-excursion
4441 (org-back-to-heading t)
4442 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4444 (defun org-start-icalendar-file (name)
4445 "Start an iCalendar file by inserting the header."
4446 (let ((user user-full-name)
4447 (name (or name "unknown"))
4448 (timezone (cadr (current-time-zone))))
4449 (princ
4450 (format "BEGIN:VCALENDAR
4451 VERSION:2.0
4452 X-WR-CALNAME:%s
4453 PRODID:-//%s//Emacs with Org-mode//EN
4454 X-WR-TIMEZONE:%s
4455 CALSCALE:GREGORIAN\n" name user timezone))))
4457 (defun org-finish-icalendar-file ()
4458 "Finish an iCalendar file by inserting the END statement."
4459 (princ "END:VCALENDAR\n"))
4461 (defun org-ical-ts-to-string (s keyword &optional inc)
4462 "Take a time string S and convert it to iCalendar format.
4463 KEYWORD is added in front, to make a complete line like DTSTART....
4464 When INC is non-nil, increase the hour by two (if time string contains
4465 a time), or the day by one (if it does not contain a time)."
4466 (let ((t1 (org-parse-time-string s 'nodefault))
4467 t2 fmt have-time time)
4468 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4469 (setq t2 t1 have-time t)
4470 (setq t2 (org-parse-time-string s)))
4471 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4472 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4473 (when inc
4474 (if have-time
4475 (if org-agenda-default-appointment-duration
4476 (setq mi (+ org-agenda-default-appointment-duration mi))
4477 (setq h (+ 2 h)))
4478 (setq d (1+ d))))
4479 (setq time (encode-time s mi h d m y)))
4480 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4481 (concat keyword (format-time-string fmt time))))
4483 ;;; XOXO export
4485 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4486 (with-current-buffer buffer
4487 (apply 'insert output)))
4488 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4490 ;;;###autoload
4491 (defun org-export-as-xoxo (&optional buffer)
4492 "Export the org buffer as XOXO.
4493 The XOXO buffer is named *xoxo-<source buffer name>*"
4494 (interactive (list (current-buffer)))
4495 ;; A quickie abstraction
4497 ;; Output everything as XOXO
4498 (with-current-buffer (get-buffer buffer)
4499 (let* ((pos (point))
4500 (opt-plist (org-combine-plists (org-default-export-plist)
4501 (org-infile-export-plist)))
4502 (filename (concat (file-name-as-directory
4503 (org-export-directory :xoxo opt-plist))
4504 (file-name-sans-extension
4505 (file-name-nondirectory buffer-file-name))
4506 ".html"))
4507 (out (find-file-noselect filename))
4508 (last-level 1)
4509 (hanging-li nil))
4510 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4511 ;; Check the output buffer is empty.
4512 (with-current-buffer out (erase-buffer))
4513 ;; Kick off the output
4514 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4515 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4516 (let* ((hd (match-string-no-properties 1))
4517 (level (length hd))
4518 (text (concat
4519 (match-string-no-properties 2)
4520 (save-excursion
4521 (goto-char (match-end 0))
4522 (let ((str ""))
4523 (catch 'loop
4524 (while 't
4525 (forward-line)
4526 (if (looking-at "^[ \t]\\(.*\\)")
4527 (setq str (concat str (match-string-no-properties 1)))
4528 (throw 'loop str)))))))))
4530 ;; Handle level rendering
4531 (cond
4532 ((> level last-level)
4533 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4535 ((< level last-level)
4536 (dotimes (- (- last-level level) 1)
4537 (if hanging-li
4538 (org-export-as-xoxo-insert-into out "</li>\n"))
4539 (org-export-as-xoxo-insert-into out "</ol>\n"))
4540 (when hanging-li
4541 (org-export-as-xoxo-insert-into out "</li>\n")
4542 (setq hanging-li nil)))
4544 ((equal level last-level)
4545 (if hanging-li
4546 (org-export-as-xoxo-insert-into out "</li>\n")))
4549 (setq last-level level)
4551 ;; And output the new li
4552 (setq hanging-li 't)
4553 (if (equal ?+ (elt text 0))
4554 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4555 (org-export-as-xoxo-insert-into out "<li>" text))))
4557 ;; Finally finish off the ol
4558 (dotimes (- last-level 1)
4559 (if hanging-li
4560 (org-export-as-xoxo-insert-into out "</li>\n"))
4561 (org-export-as-xoxo-insert-into out "</ol>\n"))
4563 (goto-char pos)
4564 ;; Finish the buffer off and clean it up.
4565 (switch-to-buffer-other-window out)
4566 (indent-region (point-min) (point-max) nil)
4567 (save-buffer)
4568 (goto-char (point-min))
4571 (provide 'org-exp)
4573 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4575 ;;; org-exp.el ends here