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