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