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