1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess "org-export-latex" ())
34 (declare-function org-agenda-skip "org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
36 (declare-function htmlize-region "ext:htmlize" (beg end))
37 (defvar htmlize-buffer-places) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag "Org Export General"
50 (defvar org-export-publishing-directory nil)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group 'org-export-general
68 (defcustom org-export-select-tags '("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-exclude-tags'."
74 :group 'org-export-general
75 :type '(repeat (string :tag "Tag")))
77 (defcustom org-export-exclude-tags '("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without contition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group 'org-export-general
83 :type '(repeat (string :tag "Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
90 -----+----------+--------
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group 'org-export-translation
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
102 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
103 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
104 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
105 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
106 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
107 ("es" "Autor" "Fecha" "Índice" "Pies de página")
108 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
109 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
110 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
111 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
112 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
113 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
114 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
115 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
116 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
117 ("pl" "Autor" "Data" "Spis treści" "Przypis")
118 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
119 "Terms used in export text, translated to different languages.
120 Use the variable `org-export-default-language' to set the language,
121 or use the +OPTION lines for a per-file setting."
122 :group 'org-export-general
125 (string :tag "HTML language tag")
126 (string :tag "Author")
128 (string :tag "Table of Contents")
129 (string :tag "Footnotes"))))
131 (defcustom org-export-default-language "en"
132 "The default language of HTML export, as a string.
133 This should have an association in `org-export-language-setup'."
134 :group 'org-export-general
137 (defcustom org-export-skip-text-before-1st-heading nil
138 "Non-nil means, skip all text before the first headline when exporting.
139 When nil, that text is exported as well."
140 :group 'org-export-general
143 (defcustom org-export-headline-levels 3
144 "The last level which is still exported as a headline.
145 Inferior levels will produce itemize lists when exported.
146 Note that a numeric prefix argument to an exporter function overrides
149 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
150 :group 'org-export-general
153 (defcustom org-export-with-section-numbers t
154 "Non-nil means, add section numbers to headlines when exporting.
156 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
157 :group 'org-export-general
160 (defcustom org-export-section-number-format '((("1" ".")) . "")
161 "Format of section numbers for export.
162 The variable has two components.
163 1. A list of lists, each indicating a counter type and a separator.
164 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
165 It causes causes numeric, alphabetic, or roman counters, respectively.
166 The separator is only used if another counter for a subsection is being
168 If there are more numbered section levels than entries in this lists,
169 then the last entry will be reused.
170 2. A terminator string that will be added after the entire
172 :group 'org-export-general
176 (string :tag "Counter Type")
177 (string :tag "Separator ")))
178 (string :tag "Terminator")))
180 (defcustom org-export-with-toc t
181 "Non-nil means, create a table of contents in exported files.
182 The TOC contains headlines with levels up to`org-export-headline-levels'.
183 When an integer, include levels up to N in the toc, this may then be
184 different from `org-export-headline-levels', but it will not be allowed
185 to be larger than the number of headline levels.
186 When nil, no table of contents is made.
188 Headlines which contain any TODO items will be marked with \"(*)\" in
189 ASCII export, and with red color in HTML output, if the option
190 `org-export-mark-todo-in-toc' is set.
192 In HTML output, the TOC will be clickable.
194 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
196 :group 'org-export-general
198 (const :tag "No Table of Contents" nil)
199 (const :tag "Full Table of Contents" t)
200 (integer :tag "TOC to level")))
202 (defcustom org-export-mark-todo-in-toc nil
203 "Non-nil means, mark TOC lines that contain any open TODO items."
204 :group 'org-export-general
207 (defcustom org-export-with-todo-keywords t
208 "Non-nil means, include TODO keywords in export.
209 When nil, remove all these keywords from the export."
210 :group 'org-export-general
213 (defcustom org-export-with-priority nil
214 "Non-nil means, include priority cookies in export.
215 When nil, remove priority cookies for export."
216 :group 'org-export-general
219 (defcustom org-export-preserve-breaks nil
220 "Non-nil means, preserve all line breaks when exporting.
221 Normally, in HTML output paragraphs will be reformatted. In ASCII
222 export, line breaks will always be preserved, regardless of this variable.
224 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
225 :group 'org-export-general
228 (defcustom org-export-with-archived-trees 'headline
229 "Whether subtrees with the ARCHIVE tag should be exported.
230 This can have three different values
231 nil Do not export, pretend this tree is not present
232 t Do export the entire tree
233 headline Only export the headline, but skip the tree below it."
234 :group 'org-export-general
237 (const :tag "not at all" nil)
238 (const :tag "headline only" 'headline)
239 (const :tag "entirely" t)))
241 (defcustom org-export-author-info t
242 "Non-nil means, insert author name and email into the exported file.
244 This option can also be set with the +OPTIONS line,
245 e.g. \"author-info:nil\"."
246 :group 'org-export-general
249 (defcustom org-export-creator-info t
250 "Non-nil means, the postamle should contain a creator sentence.
251 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
252 :group 'org-export-general
255 (defcustom org-export-time-stamp-file t
256 "Non-nil means, insert a time stamp into the exported file.
257 The time stamp shows when the file was created.
259 This option can also be set with the +OPTIONS line,
260 e.g. \"timestamp:nil\"."
261 :group 'org-export-general
264 (defcustom org-export-with-timestamps t
265 "If nil, do not export time stamps and associated keywords."
266 :group 'org-export-general
269 (defcustom org-export-remove-timestamps-from-toc t
270 "If nil, remove timestamps from the table of contents entries."
271 :group 'org-export-general
274 (defcustom org-export-with-tags 'not-in-toc
275 "If nil, do not export tags, just remove them from headlines.
276 If this is the symbol `not-in-toc', tags will be removed from table of
277 contents entries, but still be shown in the headlines of the document.
279 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
280 :group 'org-export-general
282 (const :tag "Off" nil)
283 (const :tag "Not in TOC" not-in-toc)
284 (const :tag "On" t)))
286 (defcustom org-export-with-drawers nil
287 "Non-nil means, export with drawers like the property drawer.
288 When t, all drawers are exported. This may also be a list of
289 drawer names to export."
290 :group 'org-export-general
292 (const :tag "All drawers" t)
293 (const :tag "None" nil)
294 (repeat :tag "Selected drawers"
295 (string :tag "Drawer name"))))
297 (defvar org-export-preprocess-hook nil
298 "Hook for preprocessing an export buffer.
299 Pretty much the first thing when exporting is running this hook.")
301 (defgroup org-export-translation nil
302 "Options for translating special ascii sequences for the export backends."
303 :tag "Org Export Translation"
306 (defcustom org-export-with-emphasize t
307 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
308 If the export target supports emphasizing text, the word will be
309 typeset in bold, italic, or underlined, respectively. Works only for
310 single words, but you can say: I *really* *mean* *this*.
311 Not all export backends support this.
313 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
314 :group 'org-export-translation
317 (defcustom org-export-with-footnotes t
318 "If nil, export [1] as a footnote marker.
319 Lines starting with [1] will be formatted as footnotes.
321 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
322 :group 'org-export-translation
325 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
326 <h2 class=\"footnotes\">%s: </h2>
327 <div id=\"footnotes-text\">
331 "Format for the footnotes section.
332 Should contain a two instances of %s. The first will be replaced with the
333 language-specific word for \"Footnotes\", the second one will be replaced
334 by the footnotes themselves."
335 :group 'org-export-html
338 (defcustom org-export-with-sub-superscripts t
339 "Non-nil means, interpret \"_\" and \"^\" for export.
340 When this option is turned on, you can use TeX-like syntax for sub- and
341 superscripts. Several characters after \"_\" or \"^\" will be
342 considered as a single item - so grouping with {} is normally not
343 needed. For example, the following things will be parsed as single
344 sub- or superscripts.
346 10^24 or 10^tau several digits will be considered 1 item.
347 10^-12 or 10^-tau a leading sign with digits or a word
348 x^2-y^3 will be read as x^2 - y^3, because items are
349 terminated by almost any nonword/nondigit char.
350 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
352 Still, ambiguity is possible - so when in doubt use {} to enclose the
353 sub/superscript. If you set this variable to the symbol `{}',
354 the braces are *required* in order to trigger interpretations as
355 sub/superscript. This can be helpful in documents that need \"_\"
356 frequently in plain text.
358 Not all export backends support this, but HTML does.
360 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
361 :group 'org-export-translation
363 (const :tag "Always interpret" t)
364 (const :tag "Only with braces" {})
365 (const :tag "Never interpret" nil)))
367 (defcustom org-export-with-special-strings t
368 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
369 When this option is turned on, these strings will be exported as:
375 Not all export backends support this, but HTML does.
377 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
378 :group 'org-export-translation
381 (defcustom org-export-with-TeX-macros t
382 "Non-nil means, interpret simple TeX-like macros when exporting.
383 For example, HTML export converts \\alpha to α and \\AA to Å.
384 No only real TeX macros will work here, but the standard HTML entities
385 for math can be used as macro names as well. For a list of supported
386 names in HTML export, see the constant `org-html-entities'.
387 Not all export backends support this.
389 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
390 :group 'org-export-translation
391 :group 'org-export-latex
394 (defcustom org-export-with-LaTeX-fragments nil
395 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
396 When set, the exporter will find LaTeX environments if the \\begin line is
397 the first non-white thing on a line. It will also find the math delimiters
398 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
401 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
402 :group 'org-export-translation
403 :group 'org-export-latex
406 (defcustom org-export-with-fixed-width t
407 "Non-nil means, lines starting with \":\" will be in fixed width font.
408 This can be used to have pre-formatted text, fragments of code etc. For
410 : ;; Some Lisp examples
413 will be looking just like this in also HTML. See also the QUOTE keyword.
414 Not all export backends support this.
416 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
417 :group 'org-export-translation
420 (defcustom org-match-sexp-depth 3
421 "Number of stacked braces for sub/superscript matching.
422 This has to be set before loading org.el to be effective."
423 :group 'org-export-translation
426 (defgroup org-export-tables nil
427 "Options for exporting tables in Org-mode."
428 :tag "Org Export Tables"
431 (defcustom org-export-with-tables t
432 "If non-nil, lines starting with \"|\" define a table.
435 | Name | Address | Birthday |
436 |-------------+----------+-----------|
437 | Arthur Dent | England | 29.2.2100 |
439 Not all export backends support this.
441 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
442 :group 'org-export-tables
445 (defcustom org-export-highlight-first-table-line t
446 "Non-nil means, highlight the first table line.
447 In HTML export, this means use <th> instead of <td>.
448 In tables created with table.el, this applies to the first table line.
449 In Org-mode tables, all lines before the first horizontal separator
450 line will be formatted with <th> tags."
451 :group 'org-export-tables
454 (defcustom org-export-table-remove-special-lines t
455 "Remove special lines and marking characters in calculating tables.
456 This removes the special marking character column from tables that are set
457 up for spreadsheet calculations. It also removes the entire lines
458 marked with `!', `_', or `^'. The lines with `$' are kept, because
459 the values of constants may be useful to have."
460 :group 'org-export-tables
463 (defcustom org-export-prefer-native-exporter-for-tables nil
464 "Non-nil means, always export tables created with table.el natively.
465 Natively means, use the HTML code generator in table.el.
466 When nil, Org-mode's own HTML generator is used when possible (i.e. if
467 the table does not use row- or column-spanning). This has the
468 advantage, that the automatic HTML conversions for math symbols and
469 sub/superscripts can be applied. Org-mode's HTML generator is also
471 :group 'org-export-tables
474 (defgroup org-export-ascii nil
475 "Options specific for ASCII export of Org-mode files."
476 :tag "Org Export ASCII"
479 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
480 "Characters for underlining headings in ASCII export.
481 In the given sequence, these characters will be used for level 1, 2, ..."
482 :group 'org-export-ascii
483 :type '(repeat character))
485 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
486 "Bullet characters for headlines converted to lists in ASCII export.
487 The first character is used for the first lest level generated in this
488 way, and so on. If there are more levels than characters given here,
489 the list will be repeated.
490 Note that plain lists will keep the same bullets as the have in the
492 :group 'org-export-ascii
493 :type '(repeat character))
495 (defgroup org-export-xml nil
496 "Options specific for XML export of Org-mode files."
497 :tag "Org Export XML"
500 (defgroup org-export-html nil
501 "Options specific for HTML export of Org-mode files."
502 :tag "Org Export HTML"
505 (defcustom org-export-html-coding-system nil
506 "Coding system for HTML export, defaults to buffer-file-coding-system."
507 :group 'org-export-html
508 :type 'coding-system)
510 (defcustom org-export-html-extension "html"
511 "The extension for exported HTML files."
512 :group 'org-export-html
515 (defcustom org-export-html-link-up ""
516 "Where should the \"UP\" link of exported HTML pages lead?"
517 :group 'org-export-html
518 :type '(string :tag "File or URL"))
520 (defcustom org-export-html-link-home ""
521 "Where should the \"HOME\" link of exported HTML pages lead?"
522 :group 'org-export-html
523 :type '(string :tag "File or URL"))
525 (defconst org-export-html-style-default
526 "<style type=\"text/css\">
527 <!--/*--><![CDATA[/*><!--*/
528 html { font-family: Times, serif; font-size: 12pt; }
529 .title { text-align: center; }
530 .todo { color: red; }
531 .done { color: green; }
532 .tag { background-color:lightblue; font-weight:normal }
534 .timestamp { color: grey }
535 .timestamp-kwd { color: CadetBlue }
536 p.verse { margin-left: 3% }
538 border: 1pt solid #AEBDCC;
539 background-color: #F3F5F7;
541 font-family: courier, monospace;
545 table { border-collapse: collapse; }
546 td, th { vertical-align: top; }
547 dt { font-weight: bold; }
549 .org-info-js_info-navigation { border-style:none; }
550 #org-info-js_console-label { font-size:10px; font-weight:bold;
551 white-space:nowrap; }
552 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
556 "The default style specification for exported HTML files.
557 Please use the variables `org-export-html-style' and
558 `org-export-html-style-extra' to add to this style. If you wish to not
559 have the default style included, customize the variable
560 `org-export-html-style-include-default'.")
562 (defcustom org-export-html-style-include-default t
563 "Non-nil means, include the default style in exported HTML files.
564 The actualy style is defined in `org-export-html-style-default' and should
565 not be modified. Use the variables `org-export-html-style' to add
566 your own style information."
567 :group 'org-export-html
570 (put 'org-export-html-style 'safe-local-variable 'booleanp)
572 (defcustom org-export-html-style ""
573 "Org-wide style definitions for exported HTML files.
575 This variable needs to contain the full HTML structure to provide a style,
576 including the surrounding HTML tags. If you set the value of this variable,
577 you should consider to include definitions for the following classes:
578 title, todo, done, timestamp, timestamp-kwd, tag, target.
580 For example, a valid value would be:
582 <style type=\"text/css\">
584 p { font-weight: normal; color: gray; }
586 .title { text-align: center; }
587 .todo, .timestamp-kwd { color: red; }
588 .done { color: green; }
592 If you'd like to refer to en external style file, use something like
594 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
596 As the value of this option simply gets inserted into the HTML <head> header,
597 you can \"misuse\" it to add arbitrary text to the header.
598 See also the variable `org-export-html-style-extra'."
599 :group 'org-export-html
602 (put 'org-export-html-style 'safe-local-variable 'stringp)
604 (defcustom org-export-html-style-extra ""
605 "Additional style information for HTML export.
606 The value of this variable is inserted into the HTML buffer right after
607 the value of `org-export-html-style'. Use this variable for per-file
608 settings of style information, and do not forget to surround the style
609 settings with <style>...</style> tags."
610 :group 'org-export-html
613 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
616 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
617 "Format for typesetting the document title in HTML export."
618 :group 'org-export-html
621 (defcustom org-export-html-toplevel-hlevel 2
622 "The <H> level for level 1 headings in HTML export."
623 :group 'org-export-html
626 (defcustom org-export-html-link-org-files-as-html t
627 "Non-nil means, make file links to `file.org' point to `file.html'.
628 When org-mode is exporting an org-mode file to HTML, links to
629 non-html files are directly put into a href tag in HTML.
630 However, links to other Org-mode files (recognized by the
631 extension `.org.) should become links to the corresponding html
632 file, assuming that the linked org-mode file will also be
634 When nil, the links still point to the plain `.org' file."
635 :group 'org-export-html
638 (defcustom org-export-html-inline-images 'maybe
639 "Non-nil means, inline images into exported HTML pages.
640 This is done using an <img> tag. When nil, an anchor with href is used to
641 link to the image. If this option is `maybe', then images in links with
642 an empty description will be inlined, while images with a description will
644 :group 'org-export-html
645 :type '(choice (const :tag "Never" nil)
646 (const :tag "Always" t)
647 (const :tag "When there is no description" maybe)))
650 (defcustom org-export-html-expand t
651 "Non-nil means, for HTML export, treat @<...> as HTML tag.
652 When nil, these tags will be exported as plain text and therefore
653 not be interpreted by a browser.
655 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
656 :group 'org-export-html
659 (defcustom org-export-html-table-tag
660 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
661 "The HTML tag that is used to start a table.
662 This must be a <table> tag, but you may change the options like
663 borders and spacing."
664 :group 'org-export-html
667 (defcustom org-export-table-header-tags '("<th>" . "</th>")
668 "The opening tag for table header fields.
669 This is customizable so that alignment options can be specified."
670 :group 'org-export-tables
671 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
673 (defcustom org-export-table-data-tags '("<td>" . "</td>")
674 "The opening tag for table data fields.
675 This is customizable so that alignment options can be specified."
676 :group 'org-export-tables
677 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
679 (defcustom org-export-html-with-timestamp nil
680 "If non-nil, write `org-export-html-html-helper-timestamp'
681 into the exported HTML text. Otherwise, the buffer will just be saved
683 :group 'org-export-html
686 (defcustom org-export-html-html-helper-timestamp
687 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
688 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
689 :group 'org-export-html
692 (defgroup org-export-htmlize nil
693 "Options for processing examples with htmlize.el."
694 :tag "Org Export Htmlize"
695 :group 'org-export-html)
697 (defcustom org-export-htmlize-output-type 'inline-css
698 "Output type to be used by htmlize when formatting code snippets.
699 Normally this is `inline-css', but if you have defined to appropriate
700 classes in your css style file, setting this to `css' means that the
701 fontification will use the class names.
702 See also the function `org-export-htmlize-generate-css'."
703 :group 'org-export-htmlize
704 :type '(choice (const css) (const inline-css)))
706 (defcustom org-export-htmlize-css-font-prefix "org-"
707 "The prefix for CSS class names for htmlize font specifications."
708 :group 'org-export-htmlize
711 (defgroup org-export-icalendar nil
712 "Options specific for iCalendar export of Org-mode files."
713 :tag "Org Export iCalendar"
716 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
717 "The file name for the iCalendar file covering all agenda files.
718 This file is created with the command \\[org-export-icalendar-all-agenda-files].
719 The file name should be absolute, the file will be overwritten without warning."
720 :group 'org-export-icalendar
723 (defcustom org-icalendar-combined-name "OrgMode"
724 "Calendar name for the combined iCalendar representing all agenda files."
725 :group 'org-export-icalendar
728 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
729 "Contexts where iCalendar export should use a deadline time stamp.
730 This is a list with several symbols in it. Valid symbol are:
732 event-if-todo Deadlines in TODO entries become calendar events.
733 event-if-not-todo Deadlines in non-TODO entries become calendar events.
734 todo-due Use deadlines in TODO entries as due-dates"
735 :group 'org-export-icalendar
736 :type '(set :greedy t
737 (const :tag "Deadlines in non-TODO entries become events"
739 (const :tag "Deadline in TODO entries become events"
741 (const :tag "Deadlines in TODO entries become due-dates"
744 (defcustom org-icalendar-use-scheduled '(todo-start)
745 "Contexts where iCalendar export should use a scheduling time stamp.
746 This is a list with several symbols in it. Valid symbol are:
748 event-if-todo Scheduling time stamps in TODO entries become an event.
749 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
750 todo-start Scheduling time stamps in TODO entries become start date.
751 Some calendar applications show TODO entries only after
753 :group 'org-export-icalendar
754 :type '(set :greedy t
756 "SCHEDULED timestamps in non-TODO entries become events"
758 (const :tag "SCHEDULED timestamps in TODO entries become events"
760 (const :tag "SCHEDULED in TODO entries become start date"
763 (defcustom org-icalendar-categories '(local-tags category)
764 "Items that should be entered into the categories field.
765 This is a list of symbols, the following are valid:
767 category The Org-mode category of the current file or tree
768 todo-state The todo state, if any
769 local-tags The tags, defined in the current line
770 all-tags All tags, including inherited ones."
771 :group 'org-export-icalendar
774 (const :tag "The file or tree category" category)
775 (const :tag "The TODO state" todo-state)
776 (const :tag "Tags defined in current line" local-tags)
777 (const :tag "All tags, including inherited ones" all-tags))))
779 (defcustom org-icalendar-include-todo nil
780 "Non-nil means, export to iCalendar files should also cover TODO items."
781 :group 'org-export-icalendar
783 (const :tag "None" nil)
784 (const :tag "Unfinished" t)
785 (const :tag "All" all)))
787 (defcustom org-icalendar-include-sexps t
788 "Non-nil means, export to iCalendar files should also cover sexp entries.
789 These are entries like in the diary, but directly in an Org-mode file."
790 :group 'org-export-icalendar
793 (defcustom org-icalendar-include-body 100
794 "Amount of text below headline to be included in iCalendar export.
795 This is a number of characters that should maximally be included.
796 Properties, scheduling and clocking lines will always be removed.
797 The text will be inserted into the DESCRIPTION field."
798 :group 'org-export-icalendar
800 (const :tag "Nothing" nil)
801 (const :tag "Everything" t)
802 (integer :tag "Max characters")))
804 (defcustom org-icalendar-store-UID nil
805 "Non-nil means, store any created UIDs in properties.
806 The iCalendar standard requires that all entries have a unique identifyer.
807 Org will create these identifiers as needed. When this variable is non-nil,
808 the created UIDs will be stored in the ID property of the entry. Then the
809 next time this entry is exported, it will be exported with the same UID,
810 superceeding the previous form of it. This is essential for
811 synchronization services.
812 This variable is not turned on by default because we want to avoid creating
813 a property drawer in every entry if people are only playing with this feature,
814 or if they are only using it locally."
815 :group 'org-export-icalendar
820 ;;; Variables, constants, and parameter plists
822 (defconst org-level-max 20)
824 (defvar org-export-html-preamble nil
825 "Preamble, to be inserted just before <body>. Set by publishing functions.")
826 (defvar org-export-html-postamble nil
827 "Preamble, to be inserted just after </body>. Set by publishing functions.")
828 (defvar org-export-html-auto-preamble t
829 "Should default preamble be inserted? Set by publishing functions.")
830 (defvar org-export-html-auto-postamble t
831 "Should default postamble be inserted? Set by publishing functions.")
832 (defvar org-current-export-file nil) ; dynamically scoped parameter
833 (defvar org-current-export-dir nil) ; dynamically scoped parameter
835 (defconst org-export-plist-vars
836 '((:link-up nil org-export-html-link-up)
837 (:link-home nil org-export-html-link-home)
838 (:language nil org-export-default-language)
839 (:customtime nil org-display-custom-times)
840 (:headline-levels "H" org-export-headline-levels)
841 (:section-numbers "num" org-export-with-section-numbers)
842 (:section-number-format nil org-export-section-number-format)
843 (:table-of-contents "toc" org-export-with-toc)
844 (:preserve-breaks "\\n" org-export-preserve-breaks)
845 (:archived-trees nil org-export-with-archived-trees)
846 (:emphasize "*" org-export-with-emphasize)
847 (:sub-superscript "^" org-export-with-sub-superscripts)
848 (:special-strings "-" org-export-with-special-strings)
849 (:footnotes "f" org-export-with-footnotes)
850 (:drawers "d" org-export-with-drawers)
851 (:tags "tags" org-export-with-tags)
852 (:todo-keywords "todo" org-export-with-todo-keywords)
853 (:priority "pri" org-export-with-priority)
854 (:TeX-macros "TeX" org-export-with-TeX-macros)
855 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
856 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
857 (:fixed-width ":" org-export-with-fixed-width)
858 (:timestamps "<" org-export-with-timestamps)
859 (:author-info "author" org-export-author-info)
860 (:creator-info "creator" org-export-creator-info)
861 (:time-stamp-file "timestamp" org-export-time-stamp-file)
862 (:tables "|" org-export-with-tables)
863 (:table-auto-headline nil org-export-highlight-first-table-line)
864 (:style-include-default nil org-export-html-style-include-default)
865 (:style nil org-export-html-style)
866 (:style-extra nil org-export-html-style-extra)
867 (:agenda-style nil org-agenda-export-html-style)
868 (:convert-org-links nil org-export-html-link-org-files-as-html)
869 (:inline-images nil org-export-html-inline-images)
870 (:html-extension nil org-export-html-extension)
871 (:html-table-tag nil org-export-html-table-tag)
872 (:expand-quoted-html "@" org-export-html-expand)
873 (:timestamp nil org-export-html-with-timestamp)
874 (:publishing-directory nil org-export-publishing-directory)
875 (:preamble nil org-export-html-preamble)
876 (:postamble nil org-export-html-postamble)
877 (:auto-preamble nil org-export-html-auto-preamble)
878 (:auto-postamble nil org-export-html-auto-postamble)
879 (:author nil user-full-name)
880 (:email nil user-mail-address)
881 (:select-tags nil org-export-select-tags)
882 (:exclude-tags nil org-export-exclude-tags))
883 "List of properties that represent export/publishing variables.
884 Each element is a list of 3 items:
885 1. The property that is used internally, and also for org-publish-project-alist
886 2. The string that can be used in the OPTION lines to set this option,
887 or nil if this option cannot be changed in this way
888 3. The customization variable that sets the default for this option."
892 (defun org-default-export-plist ()
893 "Return the property list with default settings for the export variables."
894 (let ((l org-export-plist-vars) rtn e)
895 (while (setq e (pop l))
896 (setq rtn (cons (car e) (cons (symbol-value (nth 2 e)) rtn))))
899 (defvar org-export-inbuffer-options-extra nil
900 "List of additional in-buffer options that should be detected.
901 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
902 etc. Extensions can add to this list to get their options detected, and they
903 can then add a function to `org-export-options-filters' to process these
905 Each element in this list must be a list, with the in-buffer keyword as car,
906 and a property (a symbol) as the next element. All occurences of the
907 keyword will be found, the values concatenated with a space character
908 in between, and the result stored in the export options property list.")
910 (defvar org-export-options-filters nil
911 "Functions to be called to finalize the export/publishing options.
912 All these options are stored in a property list, and each of the functions
913 in this hook gets a chance to modify this property list. Each function
914 must accept the property list as an argument, and must return the (possibly
917 ;; FIXME: should we fold case here?
918 (defun org-infile-export-plist ()
919 "Return the property list with file-local settings for export."
923 (goto-char (point-min))
924 (let ((re (org-make-options-regexp
926 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
927 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
928 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
929 (mapcar 'car org-export-inbuffer-options-extra))))
930 p key val text options js-up js-main js-css js-opt a pr style
932 ext-setup-or-nil setup-contents (start 0))
933 (while (or (and ext-setup-or-nil
934 (string-match re ext-setup-or-nil start)
935 (setq start (match-end 0)))
936 (and (setq ext-setup-or-nil nil start 0)
937 (re-search-forward re nil t)))
938 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
939 val (org-match-string-no-properties 2 ext-setup-or-nil))
941 ((setq a (assoc key org-export-inbuffer-options-extra))
943 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
944 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
945 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
946 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
947 ((string-equal key "DATE") (setq p (plist-put p :date val)))
948 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
949 ((string-equal key "STYLE")
950 (setq style (concat style "\n" val)))
951 ((string-equal key "LATEX_HEADER")
952 (setq latex-header (concat latex-header "\n" val)))
953 ((string-equal key "TEXT")
954 (setq text (if text (concat text "\n" val) val)))
955 ((string-equal key "OPTIONS")
956 (setq options (concat val " " options)))
957 ((string-equal key "LINK_UP")
958 (setq p (plist-put p :link-up val)))
959 ((string-equal key "LINK_HOME")
960 (setq p (plist-put p :link-home val)))
961 ((string-equal key "EXPORT_SELECT_TAGS")
962 (setq p (plist-put p :select-tags (org-split-string val))))
963 ((string-equal key "EXPORT_EXCLUDE_TAGS")
964 (setq p (plist-put p :exclude-tags (org-split-string val))))
965 ((equal key "SETUPFILE")
966 (setq setup-contents (org-file-contents
968 (org-remove-double-quotes
971 (if (not ext-setup-or-nil)
972 (setq ext-setup-or-nil setup-contents start 0)
973 (setq ext-setup-or-nil
974 (concat (substring ext-setup-or-nil 0 start)
975 "\n" setup-contents "\n"
976 (substring ext-setup-or-nil start)))))))
977 (setq p (plist-put p :text text))
978 (when style (setq p (plist-put p :style-extra style)))
980 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
982 (setq p (org-export-add-options-to-plist p options)))
985 (defun org-export-add-options-to-plist (p options)
986 "Parse an OPTONS line and set values in the property list P."
989 (let ((op org-export-plist-vars) a)
990 (while (setq o (pop op))
992 (string-match (concat (regexp-quote (nth 1 o))
993 ":\\([^ \t\n\r;,.]*\\)")
995 (setq p (plist-put p (car o)
996 (car (read-from-string
997 (match-string 1 options))))))))))
1000 (defun org-export-add-subtree-options (p pos)
1001 "Add options in subtree at position POS to property list P."
1004 (when (org-at-heading-p)
1006 ;; This is actually read in `org-export-get-title-from-subtree'
1007 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1008 ;; (setq p (plist-put p :title a)))
1009 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
1010 (setq p (plist-put p :text a)))
1011 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
1012 (setq p (org-export-add-options-to-plist p a)))))
1015 (defun org-export-directory (type plist)
1016 (let* ((val (plist-get plist :publishing-directory))
1017 (dir (if (listp val)
1018 (or (cdr (assoc type val)) ".")
1022 (defun org-export-process-option-filters (plist)
1023 (let ((functions org-export-options-filters) f)
1024 (while (setq f (pop functions))
1025 (setq plist (funcall f plist))))
1029 (defun org-export (&optional arg)
1030 "Export dispatcher for Org-mode.
1031 When `org-export-run-in-background' is non-nil, try to run the command
1032 in the background. This will be done only for commands that write
1033 to a file. For details see the docstring of `org-export-run-in-background'.
1035 The prefix argument ARG will be passed to the exporter. However, if
1036 ARG is a double universal prefix `C-u C-u', that means to inverse the
1037 value of `org-export-run-in-background'."
1039 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
1040 (help "[t] insert the export option template
1041 \[v] limit export to visible part of outline tree
1043 \[a] export as ASCII
1046 \[H] export as HTML to temporary buffer
1047 \[R] export region as HTML
1048 \[b] export as HTML and browse immediately
1051 \[l] export as LaTeX
1052 \[p] export as LaTeX and process to PDF
1053 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1054 \[L] export as LaTeX to temporary buffer
1056 \[i] export current file as iCalendar file
1057 \[I] export all agenda files as iCalendar files
1058 \[c] export agenda files into combined iCalendar file
1060 \[F] publish current file
1061 \[P] publish current project
1062 \[X] publish... (project will be prompted for)
1063 \[A] publish all projects")
1065 '((?t org-insert-export-options-template nil)
1066 (?v org-export-visible nil)
1067 (?a org-export-as-ascii t)
1068 (?h org-export-as-html t)
1069 (?b org-export-as-html-and-open t)
1070 (?H org-export-as-html-to-buffer nil)
1071 (?R org-export-region-as-html nil)
1072 (?x org-export-as-xoxo t)
1073 (?l org-export-as-latex t)
1074 (?p org-export-as-pdf t)
1075 (?d org-export-as-pdf-and-open t)
1076 (?L org-export-as-latex-to-buffer nil)
1077 (?i org-export-icalendar-this-file t)
1078 (?I org-export-icalendar-all-agenda-files t)
1079 (?c org-export-icalendar-combine-agenda-files t)
1080 (?F org-publish-current-file t)
1081 (?P org-publish-current-project t)
1083 (?A org-publish-all t)))
1085 (save-window-excursion
1086 (delete-other-windows)
1087 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1089 (org-fit-window-to-buffer (get-buffer-window
1090 "*Org Export/Publishing Help*"))
1091 (message "Select command: ")
1092 (setq r1 (read-char-exclusive)))
1093 (setq r2 (if (< r1 27) (+ r1 96) r1))
1094 (unless (setq ass (assq r2 cmds))
1095 (error "No command associated with key %c" r1))
1096 (if (and bg (nth 2 ass)
1097 (not (buffer-base-buffer))
1098 (not (org-region-active-p)))
1099 ;; execute in background
1100 (let ((p (start-process
1101 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1103 (expand-file-name invocation-name invocation-directory)
1106 "--eval" "(require 'org-exp)"
1107 "--eval" "(setq org-wait .2)"
1109 "-f" (symbol-name (nth 1 ass)))))
1110 (set-process-sentinel p 'org-export-process-sentinel)
1111 (message "Background process \"%s\": started" p))
1112 ;; background processing not requested, or not possible
1113 (call-interactively (nth 1 ass)))))
1115 (defun org-export-process-sentinel (process status)
1116 (if (string-match "\n+\\'" status)
1117 (setq status (substring status 0 -1)))
1118 (message "Background process \"%s\": %s" process status))
1120 (defconst org-html-entities
1161 ("Aring") ("AA"."Å")
1250 ("varepsilon"."ε")
1263 ("sigmaf") ("varsigma"."ς")
1271 ("thetasym") ("vartheta"."ϑ")
1274 ("bull") ("bullet"."•")
1275 ("hellip") ("dots"."…")
1285 ("larr") ("leftarrow"."←") ("gets"."←")
1286 ("uarr") ("uparrow"."↑")
1287 ("rarr") ("to"."→") ("rightarrow"."→")
1288 ("darr")("downarrow"."↓")
1289 ("harr") ("leftrightarrow"."↔")
1290 ("crarr") ("hookleftarrow"."↵") ; has round hook, not quite CR
1291 ("lArr") ("Leftarrow"."⇐")
1292 ("uArr") ("Uparrow"."⇑")
1293 ("rArr") ("Rightarrow"."⇒")
1294 ("dArr") ("Downarrow"."⇓")
1295 ("hArr") ("Leftrightarrow"."⇔")
1297 ("part") ("partial"."∂")
1298 ("exist") ("exists"."∃")
1299 ("empty") ("emptyset"."∅")
1301 ("isin") ("in"."∈")
1307 ("lowast") ("ast"."∗")
1309 ("prop") ("proptp"."∝")
1310 ("infin") ("infty"."∞")
1311 ("ang") ("angle"."∠")
1312 ("and") ("wedge"."∧")
1313 ("or") ("vee"."∨")
1319 ("cong") ("simeq"."≅")
1320 ("asymp")("approx"."≈")
1321 ("ne") ("neq"."≠")
1325 ("sub") ("subset"."⊂")
1326 ("sup") ("supset"."⊃")
1333 ("sdot") ("cdot"."⋅")
1340 ("loz") ("Diamond"."◊")
1341 ("spades") ("spadesuit"."♠")
1342 ("clubs") ("clubsuit"."♣")
1343 ("hearts") ("diamondsuit"."♥")
1344 ("diams") ("diamondsuit"."♦")
1345 ("smile"."☺") ("blacksmile"."☻") ("sad"."☹")
1412 "Entities for TeX->HTML translation.
1413 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1414 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1415 In that case, \"\\ent\" will be translated to \"&other;\".
1416 The list contains HTML entities for Latin-1, Greek and other symbols.
1417 It is supplemented by a number of commonly used TeX macros with appropriate
1418 translations. There is currently no way for users to extend this.")
1420 ;;; General functions for all backends
1422 (defvar org-export-target-aliases nil
1423 "Alist of targets with invisible aliases.")
1425 (defun org-export-preprocess-string (string &rest parameters)
1426 "Cleanup STRING so that that the true exported has a more consistent source.
1427 This function takes STRING, which should be a buffer-string of an org-file
1428 to export. It then creates a temporary buffer where it does its job.
1429 The result is then again returned as a string, and the exporter works
1430 on this string to produce the exported version."
1432 (let* ((htmlp (plist-get parameters :for-html))
1433 (asciip (plist-get parameters :for-ascii))
1434 (latexp (plist-get parameters :for-LaTeX))
1435 (archived-trees (plist-get parameters :archived-trees))
1436 (inhibit-read-only t)
1437 (drawers org-drawers)
1438 (outline-regexp "\\*+ ")
1441 (setq org-export-target-aliases nil)
1443 (with-current-buffer (get-buffer-create " org-mode-tmp")
1446 (setq case-fold-search t)
1448 (run-hooks 'org-export-preprocess-hook)
1450 ;; Remove license-to-kill stuff
1451 ;; The caller markes some stuff fo killing, stuff that has been
1452 ;; used to create the page title, for example.
1453 (org-export-kill-licensed-text)
1455 (let ((org-inhibit-startup t)) (org-mode))
1456 (setq case-fold-search t)
1457 (untabify (point-min) (point-max))
1459 ;; Handle include files
1460 (org-export-handle-include-files)
1462 ;; Get rid of excluded trees
1463 (org-export-handle-export-tags (plist-get parameters :select-tags)
1464 (plist-get parameters :exclude-tags))
1466 ;; Handle source code snippets
1467 (org-export-replace-src-segments)
1469 ;; Find all headings and compute the targets for them
1470 (setq target-alist (org-export-define-heading-targets target-alist))
1472 ;; Get rid of drawers
1473 (org-export-remove-or-extract-drawers drawers
1474 (plist-get parameters :drawers))
1476 ;; Get the correct stuff before the first headline
1477 (when (plist-get parameters :skip-before-1st-heading)
1478 (goto-char (point-min))
1479 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t)
1480 (delete-region (point-min) (match-beginning 0))
1481 (goto-char (point-min))
1483 (when (plist-get parameters :add-text)
1484 (goto-char (point-min))
1485 (insert (plist-get parameters :add-text) "\n"))
1487 ;; Get rid of archived trees
1488 (org-export-remove-archived-trees archived-trees)
1490 ;; Remove todo-keywords before exporting, if the user has requested so
1491 (org-export-remove-headline-metadata parameters)
1493 ;; Find targets in comments and move them out of comments,
1494 ;; but mark them as targets that should be invisible
1495 (setq target-alist (org-export-handle-invisible-targets target-alist))
1498 (org-export-protect-examples (if asciip 'indent nil))
1500 ;; Protect backend specific stuff, throw away the others.
1501 (org-export-select-backend-specific-text
1502 (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1504 ;; Protect quoted subtrees
1505 (org-export-protect-quoted-subtrees)
1507 ;; Protect verbatim elements
1508 (org-export-protect-verbatim)
1510 ;; Blockquotes and verse
1511 (org-export-mark-blockquote-and-verse)
1513 ;; Remove comment environment and comment subtrees
1514 (org-export-remove-comment-blocks-and-subtrees)
1516 ;; Find matches for radio targets and turn them into internal links
1517 (org-export-mark-radio-links)
1519 ;; Find all links that contain a newline and put them into a single line
1520 (org-export-concatenate-multiline-links)
1522 ;; Normalize links: Convert angle and plain links into bracket links
1523 ;; and expand link abbreviations
1524 (org-export-normalize-links)
1526 ;; Find all internal links. If they have a fuzzy match (i.e. not
1527 ;; a *dedicated* target match, let the link point to the
1528 ;; corresponding section.
1529 (org-export-target-internal-links target-alist)
1531 ;; Find multiline emphasis and put them into single line
1532 (when (plist-get parameters :emph-multiline)
1533 (org-export-concatenate-multiline-emphasis))
1535 ;; Remove special table lines
1536 (when org-export-table-remove-special-lines
1537 (org-export-remove-special-table-lines))
1539 ;; Specific LaTeX stuff
1541 (require 'org-export-latex nil)
1542 (org-export-latex-preprocess))
1544 ;; Specific ASCII stuff
1546 (org-export-ascii-preprocess))
1548 ;; Specific HTML stuff
1550 (org-export-html-preprocess parameters))
1552 ;; Remove or replace comments
1553 (org-export-handle-comments (plist-get parameters :comments))
1555 (setq rtn (buffer-string)))
1556 (kill-buffer " org-mode-tmp")
1559 (defun org-export-kill-licensed-text ()
1560 "Remove all text that is marked with a :org-license-to-kill property."
1562 (while (setq p (text-property-any (point-min) (point-max)
1563 :org-license-to-kill t))
1565 p (or (next-single-property-change p :org-license-to-kill)
1568 (defun org-export-define-heading-targets (target-alist)
1569 "Find all headings and define the targets for them.
1570 The new targets are added to TARGET-ALIST, which is also returned."
1571 (goto-char (point-min))
1572 (org-init-section-numbers)
1573 (let ((re (concat "^" org-outline-regexp
1574 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1576 (while (re-search-forward re nil t)
1578 (push (cons (org-match-string-no-properties 1)
1579 target) target-alist)
1580 (setq level (org-reduced-level
1581 (save-excursion (goto-char (point-at-bol))
1582 (org-outline-level))))
1583 (setq target (org-solidify-link-text
1584 (format "sec-%s" (org-section-number level))))
1585 (push (cons target target) target-alist)
1586 (add-text-properties
1587 (point-at-bol) (point-at-eol)
1588 (list 'target target)))))
1591 (defun org-export-handle-invisible-targets (target-alist)
1592 "Find targets in comments and move them out of comments.
1593 Mark them as invisible targets."
1595 (goto-char (point-min))
1596 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1597 ;; Check if the line before or after is a headline with a target
1598 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1599 (get-text-property (point-at-bol 2) 'target)))
1601 ;; use the existing target in a neighboring line
1602 (setq tmp (match-string 2))
1604 (and (looking-at "\n") (delete-char 1))
1605 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1607 (setq a (or (assoc target org-export-target-aliases)
1609 (push (list target) org-export-target-aliases)
1610 (car org-export-target-aliases))))
1612 ;; Make an invisible target
1613 (replace-match "\\1(INVISIBLE)"))))
1616 (defun org-export-target-internal-links (target-alist)
1617 "Find all internal links and assign targets to them.
1618 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1619 let the link point to the corresponding section.
1620 This function also handles the id links, if they have a match in
1622 (goto-char (point-min))
1623 (while (re-search-forward org-bracket-link-regexp nil t)
1625 (let* ((md (match-data))
1626 (desc (match-end 2))
1627 (link (org-link-unescape (match-string 1)))
1628 (slink (org-solidify-link-text link))
1632 ((cdr (assoc slink target-alist)))
1633 ((and (string-match "^id:" link)
1634 (cdr (assoc (substring link 3) target-alist))))
1635 ((string-match org-link-types-re link) nil)
1636 ((or (file-name-absolute-p link)
1637 (string-match "^\\." link))
1641 (setq found (condition-case nil (org-link-search link)
1644 (or (org-on-heading-p)
1645 (not (eq found 'dedicated))))
1646 (or (get-text-property (point) 'target)
1649 (1- (or (previous-single-property-change
1650 (point) 'target) 0)))
1654 (goto-char (match-beginning 1))
1655 (setq props (text-properties-at (point)))
1656 (delete-region (match-beginning 1) (match-end 1))
1659 (unless desc (insert "][" link))
1660 (add-text-properties pos (point) props))))))
1662 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1663 "Remove drawers, or extract the content.
1664 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1665 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1666 whose content to keep."
1667 (unless (eq t exp-drawers)
1668 (goto-char (point-min))
1669 (let ((re (concat "^[ \t]*:\\("
1672 (org-delete-all exp-drawers
1673 (copy-sequence all-drawers))
1675 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1676 (while (re-search-forward re nil t)
1677 (replace-match "")))))
1679 (defun org-export-handle-export-tags (select-tags exclude-tags)
1680 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1681 Both arguments are lists of tags.
1682 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1684 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1686 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1687 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1690 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1694 (goto-char (point-min))
1695 (when (and select-tags
1697 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1698 ;; At least one tree is marked for export, this means
1699 ;; all the unmarked stuff needs to go.
1700 ;; Dig out the trees that should be exported
1701 (goto-char (point-min))
1702 (outline-next-heading)
1704 (put-text-property beg (point-max) :org-delete t)
1705 (while (re-search-forward re-sel nil t)
1706 (when (org-on-heading-p)
1707 (org-back-to-heading)
1708 (remove-text-properties
1709 (max (1- (point)) (point-min))
1710 (setq cont (save-excursion (org-end-of-subtree t t)))
1712 (while (and (org-up-heading-safe)
1713 (get-text-property (point) :org-delete))
1714 (remove-text-properties (max (1- (point)) (point-min))
1715 (point-at-eol) '(:org-delete t)))
1717 ;; Remove the trees explicitly marked for noexport
1719 (goto-char (point-min))
1720 (while (re-search-forward re-excl nil t)
1721 (when (org-at-heading-p)
1722 (org-back-to-heading t)
1724 (org-end-of-subtree t)
1725 (delete-region beg (point)))))
1726 ;; Remove everything that is now still marked for deletion
1727 (goto-char (point-min))
1728 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1729 (setq end (or (next-single-property-change beg :org-delete)
1731 (delete-region beg end))))
1733 (defun org-export-remove-archived-trees (export-archived-trees)
1734 "Remove archived trees.
1735 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1736 When it is t, the entire archived tree will be exported.
1737 When it is nil the entire tree including the headline will be removed
1739 (let ((re-archive (concat ":" org-archive-tag ":"))
1741 (when (not (eq export-archived-trees t))
1742 (goto-char (point-min))
1743 (while (re-search-forward re-archive nil t)
1744 (if (not (org-on-heading-p t))
1745 (org-end-of-subtree t)
1746 (beginning-of-line 1)
1747 (setq a (if export-archived-trees
1748 (1+ (point-at-eol)) (point))
1749 b (org-end-of-subtree t))
1750 (if (> b a) (delete-region a b)))))))
1752 (defun org-export-remove-headline-metadata (opts)
1753 "Remove meta data from the headline, according to user options."
1754 (let ((re org-complex-heading-regexp)
1755 (todo (plist-get opts :todo-keywords))
1756 (tags (plist-get opts :tags))
1757 (pri (plist-get opts :priority))
1759 (when (or (not todo) (not tags) (not pri))
1760 ;; OK, something needs to be removed
1761 (setq rpl (concat "\\1"
1765 (if tags " \\5" "")))
1766 (goto-char (point-min))
1767 (while (re-search-forward re nil t)
1768 (replace-match rpl t nil)))))
1770 (defun org-export-protect-quoted-subtrees ()
1771 "Mark quoted subtrees with the protection property."
1772 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1773 (goto-char (point-min))
1774 (while (re-search-forward re-quote nil t)
1775 (goto-char (match-beginning 0))
1777 (add-text-properties (point) (org-end-of-subtree t)
1778 '(org-protected t)))))
1780 (defun org-export-protect-verbatim ()
1781 "Mark verbatim snippets with the protection property."
1782 (goto-char (point-min))
1783 (while (re-search-forward org-verbatim-re nil t)
1784 (add-text-properties (match-beginning 4) (match-end 4)
1786 (goto-char (1+ (match-end 4)))))
1788 (defun org-export-protect-examples (&optional indent)
1789 "Protect code that should be exported as monospaced examples."
1790 (goto-char (point-min))
1791 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1792 (goto-char (match-end 0))
1793 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1794 (insert (if indent ": " ":"))
1795 (beginning-of-line 2)))
1796 (goto-char (point-min))
1797 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1798 (add-text-properties (match-beginning 0) (match-end 0)
1799 '(org-protected t))))
1801 (defun org-export-select-backend-specific-text (backend)
1803 '((html "HTML" "BEGIN_HTML" "END_HTML")
1804 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1805 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1809 (setq fmt (pop formatters))
1810 (when (eq (car fmt) backend)
1811 ;; This is selected code, put it into the file for real
1812 (goto-char (point-min))
1813 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1814 ":[ \t]*\\(.*\\)") nil t)
1815 (replace-match "\\1" t)
1816 (add-text-properties
1817 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1818 '(org-protected t))))
1819 (goto-char (point-min))
1820 (while (re-search-forward
1822 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1823 (cadddr fmt) "\\>.*\n?") nil t)
1824 (if (eq (car fmt) backend)
1826 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1828 ;; No, this is for a different backend, kill it
1829 (delete-region (match-beginning 0) (match-end 0)))))))
1831 (defun org-export-mark-blockquote-and-verse ()
1832 "Mark block quote and verse environments with special cookies.
1833 These special cookies will later be interpreted by the backend."
1835 (goto-char (point-min))
1836 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1838 (replace-match (if (equal (downcase (match-string 1)) "end")
1839 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1842 (goto-char (point-min))
1843 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1844 (replace-match (if (equal (downcase (match-string 1)) "end")
1845 "ORG-VERSE-END" "ORG-VERSE-START")
1848 (defun org-export-remove-comment-blocks-and-subtrees ()
1849 "Remove the comment environment, and also commented subtrees."
1850 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1851 (case-fold-search nil))
1852 ;; Remove comment environment
1853 (goto-char (point-min))
1854 (while (re-search-forward
1855 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1856 (replace-match "" t t))
1857 ;; Remove subtrees that are commented
1858 (goto-char (point-min))
1859 (while (re-search-forward re-commented nil t)
1860 (goto-char (match-beginning 0))
1861 (delete-region (point) (org-end-of-subtree t)))))
1863 (defun org-export-handle-comments (commentsp)
1864 "Remove comments, or convert to backend-specific format.
1865 COMMENTSP can be a format string for publishing comments.
1866 When it is nil, all comments will be removed."
1867 (let ((re "^#\\(.*\n?\\)")
1869 (goto-char (point-min))
1870 (while (or (looking-at re)
1871 (re-search-forward re nil t))
1872 (setq pos (match-beginning 0))
1874 (progn (add-text-properties
1875 (match-beginning 0) (match-end 0) '(org-protected t))
1876 (replace-match (format commentsp (match-string 1)) t t))
1877 (goto-char (1+ pos))
1880 (goto-char (max (point-min) (1- pos))))))))
1882 (defun org-export-mark-radio-links ()
1883 "Find all matches for radio targets and turn them into internal links."
1884 (let ((re-radio (and org-target-link-regexp
1885 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1886 (goto-char (point-min))
1888 (while (re-search-forward re-radio nil t)
1890 (replace-match "\\1[[\\2]]"))))))
1892 (defun org-export-remove-special-table-lines ()
1893 "Remove tables lines that are used for internal purposes."
1894 (goto-char (point-min))
1895 (while (re-search-forward "^[ \t]*|" nil t)
1896 (beginning-of-line 1)
1897 (if (or (looking-at "[ \t]*| *[!_^] *|")
1898 (and (looking-at ".*?| *<[0-9]+> *|")
1899 (not (looking-at ".*?| *[^ <|]"))))
1900 (delete-region (max (point-min) (1- (point-at-bol)))
1904 (defun org-export-normalize-links ()
1905 "Convert all links to bracket links, and expand link abbreviations."
1906 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1907 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1908 (goto-char (point-min))
1909 (while (re-search-forward re-plain-link nil t)
1910 (goto-char (1- (match-end 0)))
1912 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1913 ":" (match-string 3) "]]")))
1914 ;; added 'org-link face to links
1915 (put-text-property 0 (length s) 'face 'org-link s)
1916 (replace-match s t t))))
1917 (goto-char (point-min))
1918 (while (re-search-forward re-angle-link nil t)
1919 (goto-char (1- (match-end 0)))
1921 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1922 ":" (match-string 3) "]]")))
1923 (put-text-property 0 (length s) 'face 'org-link s)
1924 (replace-match s t t))))
1925 (goto-char (point-min))
1926 (while (re-search-forward org-bracket-link-regexp nil t)
1927 (goto-char (1- (match-end 0)))
1929 (let* ((xx (save-match-data
1931 (org-link-expand-abbrev (match-string 1)))))
1936 (concat "[" xx "]"))
1938 (put-text-property 0 (length s) 'face 'org-link s)
1939 (replace-match s t t))))))
1941 (defun org-export-concatenate-multiline-links ()
1942 "Find multi-line links and put it all into a single line.
1943 This is to make sure that the line-processing export backends
1944 can work correctly."
1945 (goto-char (point-min))
1946 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1948 (replace-match "\\1 \\3")
1949 (goto-char (match-beginning 0)))))
1951 (defun org-export-concatenate-multiline-emphasis ()
1952 "Find multi-line emphasis and put it all into a single line.
1953 This is to make sure that the line-processing export backends
1954 can work correctly."
1955 (goto-char (point-min))
1956 (while (re-search-forward org-emph-re nil t)
1957 (if (not (= (char-after (match-beginning 3))
1958 (char-after (match-beginning 4))))
1960 (subst-char-in-region (match-beginning 0) (match-end 0)
1962 (goto-char (1- (match-end 0))))
1963 (goto-char (1+ (match-beginning 0))))))
1965 (defun org-export-grab-title-from-buffer ()
1966 "Get a title for the current document, from looking at the buffer."
1967 (let ((inhibit-read-only t))
1969 (goto-char (point-min))
1970 (let ((end (if (looking-at org-outline-regexp)
1972 (save-excursion (outline-next-heading) (point)))))
1973 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1974 ;; Mark the line so that it will not be exported as normal text.
1976 (add-text-properties (match-beginning 0) (match-end 0)
1977 (list :org-license-to-kill t)))
1978 ;; Return the title string
1979 (org-trim (match-string 0)))))))
1981 (defun org-export-get-title-from-subtree ()
1982 "Return subtree title and exclude it from export."
1983 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1986 (when (and (org-at-heading-p)
1987 (>= (org-end-of-subtree t t) rend))
1988 ;; This is a subtree, we take the title from the first heading
1990 (looking-at org-todo-line-regexp)
1991 (setq title (match-string 3))
1993 (add-text-properties (point) (1+ (point-at-eol))
1994 (list :org-license-to-kill t)))
1995 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1998 (defun org-solidify-link-text (s &optional alist)
1999 "Take link text and make a safe target out of it."
2004 (org-split-string s "[ \t\r\n]+") "=="))
2005 (a (assoc rtn alist)))
2008 (defun org-get-min-level (lines)
2009 "Get the minimum level in LINES."
2010 (let ((re "^\\(\\*+\\) ") l min)
2012 (while (setq l (pop lines))
2013 (if (string-match re l)
2014 (throw 'exit (org-tr-level (length (match-string 1 l))))))
2017 ;; Variable holding the vector with section numbers
2018 (defvar org-section-numbers (make-vector org-level-max 0))
2020 (defun org-init-section-numbers ()
2021 "Initialize the vector for the section numbers."
2023 (numbers (nreverse (org-split-string "" "\\.")))
2024 (depth (1- (length org-section-numbers)))
2025 (i depth) number-string)
2028 (aset org-section-numbers i 0)
2029 (setq number-string (or (car numbers) "0"))
2030 (if (string-match "\\`[A-Z]\\'" number-string)
2031 (aset org-section-numbers i
2032 (- (string-to-char number-string) ?A -1))
2033 (aset org-section-numbers i (string-to-number number-string)))
2037 (defun org-section-number (&optional level)
2038 "Return a string with the current section number.
2039 When LEVEL is non-nil, increase section numbers on that level."
2040 (let* ((depth (1- (length org-section-numbers)))
2042 (fmts (car org-export-section-number-format))
2043 (term (cdr org-export-section-number-format))
2048 (aset org-section-numbers
2049 level (1+ (aref org-section-numbers level))))
2050 (setq idx (1+ level))
2051 (while (<= idx depth)
2053 (aset org-section-numbers idx 0))
2054 (setq idx (1+ idx))))
2056 (while (<= idx depth)
2057 (when (> (aref org-section-numbers idx) 0)
2058 (setq fmt (or (pop fmts) fmt)
2060 n (aref org-section-numbers idx)
2062 (concat string sep (org-number-to-counter n ctype))
2063 (concat string ".0"))
2065 (setq idx (1+ idx)))
2067 (if (string-match "\\`\\([@0]\\.\\)+" string)
2068 (setq string (replace-match "" t nil string)))
2069 (if (string-match "\\(\\.0\\)+\\'" string)
2070 (setq string (replace-match "" t nil string))))
2071 (concat string term)))
2073 (defun org-number-to-counter (n type)
2074 "Concert number N to a string counter, according to TYPE.
2075 TYPE must be a string, any of:
2079 I uppper case roman numeral
2080 i lower case roman numeral"
2082 ((equal type "1") (number-to-string n))
2083 ((equal type "A") (char-to-string (+ ?A n -1)))
2084 ((equal type "a") (char-to-string (+ ?a n -1)))
2085 ((equal type "I") (org-number-to-roman n))
2086 ((equal type "i") (downcase (org-number-to-roman n)))
2087 (t (error "Invalid counter type `%s'" type))))
2089 (defun org-number-to-roman (n)
2090 "Convert integer N into a roman numeral."
2091 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2092 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2093 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2097 (number-to-string n)
2099 (if (>= n (caar roman))
2100 (setq n (- n (caar roman))
2101 res (concat res (cdar roman)))
2105 (org-number-to-roman 1961)
2110 (defun org-export-handle-include-files ()
2111 "Include the contents of include files, with proper formatting."
2112 (let ((case-fold-search t)
2113 params file markup lang start end prefix prefix1)
2114 (goto-char (point-min))
2115 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2116 (setq params (read (concat "(" (match-string 1) ")"))
2117 prefix (org-get-and-remove-property 'params :prefix)
2118 prefix1 (org-get-and-remove-property 'params :prefix1)
2119 file (org-symname-or-string (pop params))
2120 markup (org-symname-or-string (pop params))
2121 lang (org-symname-or-string (pop params)))
2122 (delete-region (match-beginning 0) (match-end 0))
2124 (not (file-exists-p file))
2125 (not (file-readable-p file)))
2126 (insert (format "CANNOT INCLUDE FILE %s" file))
2128 (if (equal (downcase markup) "src")
2129 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2131 (setq start (format "#+begin_%s\n" markup)
2132 end (format "#+end_%s" markup))))
2133 (insert (or start ""))
2134 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2135 (or (bolp) (newline))
2136 (insert (or end ""))))))
2138 (defun org-get-file-contents (file &optional prefix prefix1)
2139 "Get the contents of FILE and return them as a string.
2140 If PREFIX is a string, prepend it to each line. If PREFIX1
2141 is a string, prepend it to the first line instead of PREFIX."
2143 (insert-file-contents file)
2144 (when (or prefix prefix1)
2145 (goto-char (point-min))
2147 (insert (or prefix1 prefix))
2149 (beginning-of-line 2)))
2152 (defun org-get-and-remove-property (listvar prop)
2153 "Check if the value of LISTVAR contains PROP as a property.
2154 If yes, return the value of that property (i.e. the element following
2155 in the list) and remove property and value from the list in LISTVAR."
2156 (let ((list (symbol-value listvar)) m v)
2157 (when (setq m (member prop list))
2159 (if (equal (car list) prop)
2160 (set listvar (cddr list))
2161 (setcdr (nthcdr (- (length list) (length m) 1) list)
2163 (set listvar list)))
2166 (defun org-symname-or-string (s)
2168 (if s (symbol-name s) s)
2171 ;;; Fontification of code
2172 ;; Currently only for the HTML backend, but who knows....
2173 (defun org-export-replace-src-segments ()
2174 "Replace source code segments with special code for export."
2175 (let ((case-fold-search t)
2177 (goto-char (point-min))
2178 (while (re-search-forward
2179 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2181 (setq lang (match-string 1) code (match-string 2)
2182 trans (org-export-format-source-code lang code))
2183 (replace-match trans t t))))
2185 (defvar htmlp) ;; dynamically scoped from org-exp.el
2187 (defun org-export-format-source-code (lang code)
2188 "Format CODE from language LANG and return it formatted for export.
2189 Currently, this only does something for HTML export, for all other
2190 backends, it converts the segment into an EXAMPLE segment."
2194 ;; We are exporting to HTML
2195 (require 'htmlize nil t)
2196 (if (not (fboundp 'htmlize-region-for-paste))
2198 ;; we do not have htmlize.el, or an old version of it
2200 "htmlize.el 1.34 or later is needed for source code formatting")
2201 (concat "#+BEGIN_EXAMPLE\n" code
2202 (if (string-match "\n\\'" code) "" "\n")
2204 ;; ok, we are good to go
2205 (let* ((mode (and lang (intern (concat lang "-mode"))))
2206 (org-inhibit-startup t)
2207 (org-startup-folded nil)
2211 ;; Free up the protected stuff
2212 (goto-char (point-min))
2213 (while (re-search-forward "^," nil t)
2216 (if (functionp mode)
2219 (font-lock-fontify-buffer)
2220 (org-export-htmlize-region-for-paste
2221 (point-min) (point-max)))))
2222 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2223 (setq htmltext (replace-match
2224 (format "<pre class=\"src src-%s\">" lang)
2226 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2228 ;; This is not HTML, so just make it an example.
2229 (when (equal lang "org")
2230 (while (string-match "^," code)
2231 (setq code (replace-match "" t t code))))
2232 (concat "#+BEGIN_EXAMPLE\n" code
2233 (if (string-match "\n\\'" code) "" "\n")
2234 "#+END_EXAMPLE\n")))))
2238 (defvar org-last-level nil) ; dynamically scoped variable
2239 (defvar org-min-level nil) ; dynamically scoped variable
2240 (defvar org-levels-open nil) ; dynamically scoped parameter
2241 (defvar org-ascii-current-indentation nil) ; For communication
2244 (defun org-export-as-ascii (arg)
2245 "Export the outline as a pretty ASCII file.
2246 If there is an active region, export only the region.
2247 The prefix ARG specifies how many levels of the outline should become
2248 underlined headlines. The default is 3."
2250 (setq-default org-todo-line-regexp org-todo-line-regexp)
2251 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2252 (org-infile-export-plist)))
2253 (region-p (org-region-active-p))
2254 (rbeg (and region-p (region-beginning)))
2255 (rend (and region-p (region-end)))
2260 (and (org-at-heading-p)
2261 (>= (org-end-of-subtree t t) rend)))))
2262 (opt-plist (if subtree-p
2263 (org-export-add-subtree-options opt-plist rbeg)
2265 (custom-times org-display-custom-times)
2266 (org-ascii-current-indentation '(0 . 0))
2270 (case-fold-search nil)
2271 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2272 (filename (concat (file-name-as-directory
2273 (org-export-directory :ascii opt-plist))
2274 (file-name-sans-extension
2276 (org-entry-get (region-beginning)
2277 "EXPORT_FILE_NAME" t))
2278 (file-name-nondirectory bfname)))
2280 (filename (if (equal (file-truename filename)
2281 (file-truename bfname))
2282 (concat filename ".txt")
2284 (buffer (find-file-noselect filename))
2285 (org-levels-open (make-vector org-level-max nil))
2286 (odd org-odd-levels-only)
2287 (date (plist-get opt-plist :date))
2288 (author (plist-get opt-plist :author))
2289 (title (or (and subtree-p (org-export-get-title-from-subtree))
2290 (plist-get opt-plist :title)
2292 (plist-get opt-plist :skip-before-1st-heading))
2293 (org-export-grab-title-from-buffer))
2294 (file-name-sans-extension
2295 (file-name-nondirectory bfname))))
2296 (email (plist-get opt-plist :email))
2297 (language (plist-get opt-plist :language))
2298 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2299 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2304 (if (org-region-active-p) (region-beginning) (point-min))
2305 (if (org-region-active-p) (region-end) (point-max))))
2306 (lines (org-split-string
2307 (org-export-preprocess-string
2310 :skip-before-1st-heading
2311 (plist-get opt-plist :skip-before-1st-heading)
2312 :drawers (plist-get opt-plist :drawers)
2313 :tags (plist-get opt-plist :tags)
2314 :priority (plist-get opt-plist :priority)
2315 :todo-keywords (plist-get opt-plist :todo-keywords)
2316 :verbatim-multiline t
2317 :select-tags (plist-get opt-plist :select-tags)
2318 :exclude-tags (plist-get opt-plist :exclude-tags)
2320 (plist-get opt-plist :archived-trees)
2321 :add-text (plist-get opt-plist :text))
2323 thetoc have-headings first-heading-pos
2324 table-open table-buffer)
2326 (let ((inhibit-read-only t))
2328 (remove-text-properties (point-min) (point-max)
2329 '(:org-license-to-kill t))))
2331 (setq org-min-level (org-get-min-level lines))
2332 (setq org-last-level org-min-level)
2333 (org-init-section-numbers)
2335 (find-file-noselect filename)
2337 (setq lang-words (or (assoc language org-export-language-setup)
2338 (assoc "en" org-export-language-setup)))
2339 (switch-to-buffer-other-window buffer)
2342 ;; create local variables for all options, to make sure all called
2343 ;; functions get the correct information
2345 (set (make-local-variable (nth 2 x))
2346 (plist-get opt-plist (car x))))
2347 org-export-plist-vars)
2348 (org-set-local 'org-odd-levels-only odd)
2349 (setq umax (if arg (prefix-numeric-value arg)
2350 org-export-headline-levels))
2351 (setq umax-toc (if (integerp org-export-with-toc)
2352 (min org-export-with-toc umax)
2356 (if title (org-insert-centered title ?=))
2358 (if (and (or author email)
2359 org-export-author-info)
2360 (insert (concat (nth 1 lang-words) ": " (or author "")
2361 (if email (concat " <" email ">") "")
2365 ((and date (string-match "%" date))
2366 (setq date (format-time-string date)))
2368 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2370 (if (and date org-export-time-stamp-file)
2371 (insert (concat (nth 2 lang-words) ": " date"\n")))
2375 (if org-export-with-toc
2377 (push (concat (nth 3 lang-words) "\n") thetoc)
2378 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2380 (mapc '(lambda (line)
2381 (if (string-match org-todo-line-regexp
2383 ;; This is a headline
2385 (setq have-headings t)
2386 (setq level (- (match-end 1) (match-beginning 1))
2387 level (org-tr-level level)
2388 txt (match-string 3 line)
2390 (or (and org-export-mark-todo-in-toc
2392 (not (member (match-string 2 line)
2393 org-done-keywords)))
2395 (and org-export-mark-todo-in-toc
2397 (org-search-todo-below
2398 line lines level))))
2399 (setq txt (org-html-expand-for-ascii txt))
2401 (while (string-match org-bracket-link-regexp txt)
2404 (match-string (if (match-end 2) 3 1) txt)
2407 (if (and (memq org-export-with-tags '(not-in-toc nil))
2409 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2411 (setq txt (replace-match "" t t txt)))
2412 (if (string-match quote-re0 txt)
2413 (setq txt (replace-match "" t t txt)))
2415 (if org-export-with-section-numbers
2416 (setq txt (concat (org-section-number level)
2418 (if (<= level umax-toc)
2423 (* (max 0 (- level org-min-level)) 4) ?\ )
2424 (format (if todo "%s (*)\n" "%s\n") txt))
2426 (setq org-last-level level))
2429 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2431 (org-init-section-numbers)
2432 (while (setq line (pop lines))
2433 ;; Remove the quoted HTML tags.
2434 (setq line (org-html-expand-for-ascii line))
2435 ;; Replace links with the description when possible
2436 (while (string-match org-bracket-link-regexp line)
2437 (setq line (replace-match
2438 (if (match-end 3) "[\\3]" "[\\1]")
2441 (setq line (org-translate-time line)))
2443 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2445 (setq first-heading-pos (or first-heading-pos (point)))
2446 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2447 txt (match-string 2 line))
2448 (org-ascii-level-start level txt umax lines))
2450 ((and org-export-with-tables
2451 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2452 (if (not table-open)
2454 (setq table-open t table-buffer nil))
2456 (setq table-buffer (cons line table-buffer))
2457 (when (or (not lines)
2458 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2460 (setq table-open nil
2461 table-buffer (nreverse table-buffer))
2464 (org-fix-indentation x org-ascii-current-indentation))
2465 (org-format-table-ascii table-buffer)
2468 (setq line (org-fix-indentation line org-ascii-current-indentation))
2469 ;; Remove forced line breaks
2470 (if (string-match "\\\\\\\\[ \t]*$" line)
2471 (setq line (replace-match "" t t line)))
2472 (if (and org-export-with-fixed-width
2473 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2474 (setq line (replace-match "\\1" nil nil line)))
2475 (insert line "\n"))))
2479 ;; insert the table of contents
2481 (goto-char (point-min))
2482 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2484 (goto-char (match-beginning 0))
2486 (goto-char first-heading-pos))
2487 (mapc 'insert thetoc)
2488 (or (looking-at "[ \t]*\n[ \t]*\n")
2491 ;; Convert whitespace place holders
2492 (goto-char (point-min))
2494 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2495 (setq end (next-single-property-change beg 'org-whitespace))
2497 (delete-region beg end)
2498 (insert (make-string (- end beg) ?\ ))))
2501 ;; remove display and invisible chars
2503 (goto-char (point-min))
2504 (while (setq beg (next-single-property-change (point) 'display))
2505 (setq end (next-single-property-change beg 'display))
2506 (delete-region beg end)
2509 (goto-char (point-min))
2510 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2511 (setq end (next-single-property-change beg 'org-cwidth))
2512 (delete-region beg end)
2514 (goto-char (point-min))))
2516 (defun org-export-ascii-preprocess ()
2517 "Do extra work for ASCII export"
2518 ;; Put quotes around verbatim text
2519 (goto-char (point-min))
2520 (while (re-search-forward org-verbatim-re nil t)
2521 (goto-char (match-end 2))
2522 (backward-delete-char 1) (insert "'")
2523 (goto-char (match-beginning 2))
2524 (delete-char 1) (insert "`")
2525 (goto-char (match-end 2)))
2526 (goto-char (point-min))
2527 ;; Remove target markers
2528 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
2529 (replace-match "\\1\\2")))
2531 (defun org-search-todo-below (line lines level)
2532 "Search the subtree below LINE for any TODO entries."
2533 (let ((rest (cdr (memq line lines)))
2534 (re org-todo-line-regexp)
2537 (while (setq line (pop rest))
2538 (if (string-match re line)
2540 (setq lv (- (match-end 1) (match-beginning 1))
2541 todo (and (match-beginning 2)
2542 (not (member (match-string 2 line)
2543 org-done-keywords))))
2545 (if (<= lv level) (throw 'exit nil))
2546 (if todo (throw 'exit t))))))))
2548 (defun org-html-expand-for-ascii (line)
2549 "Handle quoted HTML for ASCII export."
2550 (if org-export-html-expand
2551 (while (string-match "@<[^<>\n]*>" line)
2552 ;; We just remove the tags for now.
2553 (setq line (replace-match "" nil nil line))))
2556 (defun org-insert-centered (s &optional underline)
2557 "Insert the string S centered and underline it with character UNDERLINE."
2558 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2559 (insert (make-string ind ?\ ) s "\n")
2561 (insert (make-string ind ?\ )
2562 (make-string (string-width s) underline)
2565 (defun org-ascii-level-start (level title umax &optional lines)
2566 "Insert a new level in ASCII export."
2567 (let (char (n (- level umax 1)) (ind 0))
2570 (insert (make-string (* 2 n) ?\ )
2571 (char-to-string (nth (% n (length org-export-ascii-bullets))
2572 org-export-ascii-bullets))
2574 ;; find the indentation of the next non-empty line
2577 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2578 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2579 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2581 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2582 (if (or (not (equal (char-before) ?\n))
2583 (not (equal (char-before (1- (point))) ?\n)))
2585 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2586 (unless org-export-with-tags
2587 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2588 (setq title (replace-match "" t t title))))
2589 (if org-export-with-section-numbers
2590 (setq title (concat (org-section-number level) " " title)))
2591 (insert title "\n" (make-string (string-width title) char) "\n")
2592 (setq org-ascii-current-indentation '(0 . 0)))))
2595 (defun org-export-visible (type arg)
2596 "Create a copy of the visible part of the current buffer, and export it.
2597 The copy is created in a temporary buffer and removed after use.
2598 TYPE is the final key (as a string) that also select the export command in
2599 the `C-c C-e' export dispatcher.
2600 As a special case, if the you type SPC at the prompt, the temporary
2601 org-mode file will not be removed but presented to you so that you can
2602 continue to use it. The prefix arg ARG is passed through to the exporting
2606 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2607 (read-char-exclusive))
2608 current-prefix-arg))
2609 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2610 (error "Invalid export key"))
2611 (let* ((binding (cdr (assoc type
2612 '((?a . org-export-as-ascii)
2613 (?\C-a . org-export-as-ascii)
2614 (?b . org-export-as-html-and-open)
2615 (?\C-b . org-export-as-html-and-open)
2616 (?h . org-export-as-html)
2617 (?H . org-export-as-html-to-buffer)
2618 (?R . org-export-region-as-html)
2619 (?x . org-export-as-xoxo)))))
2620 (keepp (equal type ?\ ))
2621 (file buffer-file-name)
2622 (buffer (get-buffer-create "*Org Export Visible*"))
2624 ;; Need to hack the drawers here.
2626 (goto-char (point-min))
2627 (while (re-search-forward org-drawer-regexp nil t)
2628 (goto-char (match-beginning 1))
2629 (or (org-invisible-p) (org-flag-drawer nil))))
2630 (with-current-buffer buffer (erase-buffer))
2632 (setq s (goto-char (point-min)))
2633 (while (not (= (point) (point-max)))
2634 (goto-char (org-find-invisible))
2635 (append-to-buffer buffer s (point))
2636 (setq s (goto-char (org-find-visible))))
2637 (org-cycle-hide-drawers 'all)
2638 (goto-char (point-min))
2640 ;; Copy all comment lines to the end, to make sure #+ settings are
2641 ;; still available for the second export step. Kind of a hack, but
2642 ;; does do the trick.
2643 (if (looking-at "#[^\r\n]*")
2644 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2645 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2646 (append-to-buffer buffer (1+ (match-beginning 0))
2647 (min (point-max) (1+ (match-end 0))))))
2649 (let ((buffer-file-name file)
2650 (org-inhibit-startup t))
2653 (unless keepp (funcall binding arg))))
2655 (kill-buffer buffer)
2656 (switch-to-buffer-other-window buffer)
2657 (goto-char (point-min)))))
2659 (defun org-find-visible ()
2661 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2662 (get-char-property s 'invisible)))
2664 (defun org-find-invisible ()
2666 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2667 (not (get-char-property s 'invisible))))
2672 (defvar org-archive-location) ;; gets loades with the org-archive require.
2673 (defun org-get-current-options ()
2674 "Return a string with current options as keyword options.
2675 Does include HTML export options as well as TODO and CATEGORY stuff."
2676 (require 'org-archive)
2683 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2685 #+EXPORT_SELECT_TAGS: %s
2686 #+EXPORT_EXCLUDE_TAGS: %s
2692 #+PRIORITIES: %c %c %c
2694 #+STARTUP: %s %s %s %s %s
2700 (buffer-name) (user-full-name) user-mail-address
2701 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2702 org-export-default-language
2703 org-export-headline-levels
2704 org-export-with-section-numbers
2706 org-export-preserve-breaks
2707 org-export-html-expand
2708 org-export-with-fixed-width
2709 org-export-with-tables
2710 org-export-with-sub-superscripts
2711 org-export-with-special-strings
2712 org-export-with-footnotes
2713 org-export-with-emphasize
2714 org-export-with-TeX-macros
2715 org-export-with-LaTeX-fragments
2716 org-export-skip-text-before-1st-heading
2717 org-export-with-drawers
2718 org-export-with-todo-keywords
2719 org-export-with-priority
2720 org-export-with-tags
2721 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2722 (mapconcat 'identity org-export-select-tags " ")
2723 (mapconcat 'identity org-export-exclude-tags " ")
2724 org-export-html-link-up
2725 org-export-html-link-home
2726 (file-name-nondirectory buffer-file-name)
2727 "TODO FEEDBACK VERIFY DONE"
2728 "Me Jason Marie DONE"
2729 org-highest-priority org-lowest-priority org-default-priority
2730 (mapconcat 'identity org-drawers " ")
2731 (cdr (assoc org-startup-folded
2732 '((nil . "showall") (t . "overview") (content . "content"))))
2733 (if org-odd-levels-only "odd" "oddeven")
2734 (if org-hide-leading-stars "hidestars" "showstars")
2735 (if org-startup-align-all-tables "align" "noalign")
2736 (cond ((eq org-log-done t) "logdone")
2737 ((equal org-log-done 'note) "lognotedone")
2738 ((not org-log-done) "nologdone"))
2739 (or (mapconcat (lambda (x)
2741 ((equal '(:startgroup) x) "{")
2742 ((equal '(:endgroup) x) "}")
2743 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2745 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2746 (mapconcat 'identity org-file-tags " ")
2747 org-archive-location
2748 "org file:~/org/%s.org"
2751 (defun org-export-html-preprocess (parameters)
2752 ;; Convert LaTeX fragments to images
2753 (when (plist-get parameters :LaTeX-fragments)
2755 (concat "ltxpng/" (file-name-sans-extension
2756 (file-name-nondirectory
2757 org-current-export-file)))
2758 org-current-export-dir nil "Creating LaTeX image %s"))
2759 (message "Exporting..."))
2762 (defun org-insert-export-options-template ()
2763 "Insert into the buffer a template with information for exporting."
2765 (if (not (bolp)) (newline))
2766 (let ((s (org-get-current-options)))
2767 (and (string-match "#\\+CATEGORY" s)
2768 (setq s (substring s 0 (match-beginning 0))))
2772 (defun org-export-as-html-and-open (arg)
2773 "Export the outline as HTML and immediately open it with a browser.
2774 If there is an active region, export only the region.
2775 The prefix ARG specifies how many levels of the outline should become
2776 headlines. The default is 3. Lower levels will become bulleted lists."
2778 (org-export-as-html arg 'hidden)
2779 (org-open-file buffer-file-name))
2782 (defun org-export-as-html-batch ()
2783 "Call `org-export-as-html', may be used in batch processing as
2785 --load=$HOME/lib/emacs/org.el
2786 --eval \"(setq org-export-headline-levels 2)\"
2787 --visit=MyFile --funcall org-export-as-html-batch"
2788 (org-export-as-html org-export-headline-levels 'hidden))
2791 (defun org-export-as-html-to-buffer (arg)
2792 "Call `org-exort-as-html` with output to a temporary buffer.
2793 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2795 (org-export-as-html arg nil nil "*Org HTML Export*")
2796 (switch-to-buffer-other-window "*Org HTML Export*"))
2799 (defun org-replace-region-by-html (beg end)
2800 "Assume the current region has org-mode syntax, and convert it to HTML.
2801 This can be used in any buffer. For example, you could write an
2802 itemized list in org-mode syntax in an HTML buffer and then use this
2803 command to convert it."
2805 (let (reg html buf pop-up-frames)
2806 (save-window-excursion
2808 (setq html (org-export-region-as-html
2810 (setq reg (buffer-substring beg end)
2811 buf (get-buffer-create "*Org tmp*"))
2812 (with-current-buffer buf
2816 (setq html (org-export-region-as-html
2817 (point-min) (point-max) t 'string)))
2819 (delete-region beg end)
2823 (defun org-export-region-as-html (beg end &optional body-only buffer)
2824 "Convert region from BEG to END in org-mode buffer to HTML.
2825 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2826 contents, and only produce the region of converted text, useful for
2827 cut-and-paste operations.
2828 If BUFFER is a buffer or a string, use/create that buffer as a target
2829 of the converted HTML. If BUFFER is the symbol `string', return the
2830 produced HTML as a string and leave not buffer behind. For example,
2831 a Lisp program could call this function in the following way:
2833 (setq html (org-export-region-as-html beg end t 'string))
2835 When called interactively, the output buffer is selected, and shown
2836 in a window. A non-interactive call will only return the buffer."
2837 (interactive "r\nP")
2838 (when (interactive-p)
2839 (setq buffer "*Org HTML Export*"))
2840 (let ((transient-mark-mode t) (zmacs-regions t)
2842 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2844 (set-mark (point)) ;; to activate the region
2846 (setq rtn (org-export-as-html
2849 (if (fboundp 'deactivate-mark) (deactivate-mark))
2850 (if (and (interactive-p) (bufferp rtn))
2851 (switch-to-buffer-other-window rtn)
2854 (defvar html-table-tag nil) ; dynamically scoped into this.
2855 (defvar org-par-open nil)
2857 (defun org-export-as-html (arg &optional hidden ext-plist
2858 to-buffer body-only pub-dir)
2859 "Export the outline as a pretty HTML file.
2860 If there is an active region, export only the region. The prefix
2861 ARG specifies how many levels of the outline should become
2862 headlines. The default is 3. Lower levels will become bulleted
2863 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2864 EXT-PLIST is a property list with external parameters overriding
2865 org-mode's default settings, but still inferior to file-local
2866 settings. When TO-BUFFER is non-nil, create a buffer with that
2867 name and export to that buffer. If TO-BUFFER is the symbol
2868 `string', don't leave any buffer behind but just return the
2869 resulting HTML as a string. When BODY-ONLY is set, don't produce
2870 the file header and footer, simply return the content of
2871 <body>...</body>, without even the body tags themselves. When
2872 PUB-DIR is set, use this as the publishing directory."
2875 ;; Make sure we have a file name when we need it.
2876 (when (and (not (or to-buffer body-only))
2877 (not buffer-file-name))
2878 (if (buffer-base-buffer)
2879 (org-set-local 'buffer-file-name
2880 (with-current-buffer (buffer-base-buffer)
2882 (error "Need a file name to be able to export.")))
2884 (message "Exporting...")
2885 (setq-default org-todo-line-regexp org-todo-line-regexp)
2886 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2887 (setq-default org-done-keywords org-done-keywords)
2888 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2890 (org-export-process-option-filters
2891 (org-combine-plists (org-default-export-plist)
2893 (org-infile-export-plist))))
2894 (style (concat (if (plist-get opt-plist :style-include-default)
2895 org-export-html-style-default)
2896 (plist-get opt-plist :style)
2897 (plist-get opt-plist :style-extra)))
2898 (html-extension (plist-get opt-plist :html-extension))
2899 (link-validate (plist-get opt-plist :link-validation-function))
2900 valid thetoc have-headings first-heading-pos
2901 (odd org-odd-levels-only)
2902 (region-p (org-region-active-p))
2903 (rbeg (and region-p (region-beginning)))
2904 (rend (and region-p (region-end)))
2906 (if (plist-get opt-plist :ignore-subree-p)
2911 (and (org-at-heading-p)
2912 (>= (org-end-of-subtree t t) rend))))))
2913 (opt-plist (if subtree-p
2914 (org-export-add-subtree-options opt-plist rbeg)
2916 ;; The following two are dynamically scoped into other
2918 (org-current-export-dir
2919 (or pub-dir (org-export-directory :html opt-plist)))
2920 (org-current-export-file buffer-file-name)
2921 (level 0) (line "") (origline "") txt todo
2924 (filename (if to-buffer nil
2927 (file-name-sans-extension
2929 (org-entry-get (region-beginning)
2930 "EXPORT_FILE_NAME" t))
2931 (file-name-nondirectory buffer-file-name)))
2933 (file-name-as-directory
2934 (or pub-dir (org-export-directory :html opt-plist))))))
2935 (current-dir (if buffer-file-name
2936 (file-name-directory buffer-file-name)
2938 (buffer (if to-buffer
2940 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2941 (t (get-buffer-create to-buffer)))
2942 (find-file-noselect filename)))
2943 (org-levels-open (make-vector org-level-max nil))
2944 (date (plist-get opt-plist :date))
2945 (author (plist-get opt-plist :author))
2946 (title (or (and subtree-p (org-export-get-title-from-subtree))
2947 (plist-get opt-plist :title)
2949 (plist-get opt-plist :skip-before-1st-heading))
2950 (org-export-grab-title-from-buffer))
2951 (and buffer-file-name
2952 (file-name-sans-extension
2953 (file-name-nondirectory buffer-file-name)))
2955 (html-table-tag (plist-get opt-plist :html-table-tag))
2956 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2957 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2962 (local-list-type nil)
2963 (local-list-indent nil)
2964 (llt org-plain-list-ordered-item-terminator)
2965 (email (plist-get opt-plist :email))
2966 (language (plist-get opt-plist :language))
2970 (coding-system (and (boundp 'buffer-file-coding-system)
2971 buffer-file-coding-system))
2972 (coding-system-for-write (or org-export-html-coding-system
2974 (save-buffer-coding-system (or org-export-html-coding-system
2976 (charset (and coding-system-for-write
2977 (fboundp 'coding-system-get)
2978 (coding-system-get coding-system-for-write
2982 (if region-p (region-beginning) (point-min))
2983 (if region-p (region-end) (point-max))))
2986 (org-export-preprocess-string
2990 :skip-before-1st-heading
2991 (plist-get opt-plist :skip-before-1st-heading)
2992 :drawers (plist-get opt-plist :drawers)
2993 :todo-keywords (plist-get opt-plist :todo-keywords)
2994 :tags (plist-get opt-plist :tags)
2995 :priority (plist-get opt-plist :priority)
2997 (plist-get opt-plist :archived-trees)
2998 :select-tags (plist-get opt-plist :select-tags)
2999 :exclude-tags (plist-get opt-plist :exclude-tags)
3001 (plist-get opt-plist :text)
3003 (plist-get opt-plist :LaTeX-fragments))
3006 table-buffer table-orig-buffer
3007 ind item-type starter didclose
3008 rpl path attr desc descp desc1 desc2 link
3009 snumber fnc item-tag
3013 (let ((inhibit-read-only t))
3015 (remove-text-properties (point-min) (point-max)
3016 '(:org-license-to-kill t))))
3018 (message "Exporting...")
3020 (setq org-min-level (org-get-min-level lines))
3021 (setq org-last-level org-min-level)
3022 (org-init-section-numbers)
3025 ((and date (string-match "%" date))
3026 (setq date (format-time-string date)))
3028 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3030 ;; Get the language-dependent settings
3031 (setq lang-words (or (assoc language org-export-language-setup)
3032 (assoc "en" org-export-language-setup)))
3034 ;; Switch to the output buffer
3036 (let ((inhibit-read-only t)) (erase-buffer))
3039 (and (fboundp 'set-buffer-file-coding-system)
3040 (set-buffer-file-coding-system coding-system-for-write))
3042 (let ((case-fold-search nil)
3043 (org-odd-levels-only odd))
3044 ;; create local variables for all options, to make sure all called
3045 ;; functions get the correct information
3047 (set (make-local-variable (nth 2 x))
3048 (plist-get opt-plist (car x))))
3049 org-export-plist-vars)
3050 (setq umax (if arg (prefix-numeric-value arg)
3051 org-export-headline-levels))
3052 (setq umax-toc (if (integerp org-export-with-toc)
3053 (min org-export-with-toc umax)
3058 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3059 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3060 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3061 lang=\"%s\" xml:lang=\"%s\">
3064 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3065 <meta name=\"generator\" content=\"Org-mode\"/>
3066 <meta name=\"generated\" content=\"%s\"/>
3067 <meta name=\"author\" content=\"%s\"/>
3071 language language (org-html-expand title)
3072 (or charset "iso-8859-1") date author style))
3074 (insert (or (plist-get opt-plist :preamble) ""))
3076 (when (plist-get opt-plist :auto-preamble)
3077 (if title (insert (format org-export-html-title-format
3078 (org-html-expand title))))))
3080 (if (and org-export-with-toc (not body-only))
3082 (push (format "<h%d>%s</h%d>\n"
3083 org-export-html-toplevel-hlevel
3085 org-export-html-toplevel-hlevel)
3087 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3088 (push "<ul>\n<li>" thetoc)
3090 (mapcar '(lambda (line)
3091 (if (string-match org-todo-line-regexp line)
3092 ;; This is a headline
3094 (setq have-headings t)
3095 (setq level (- (match-end 1) (match-beginning 1))
3096 level (org-tr-level level)
3097 txt (save-match-data
3099 (org-export-cleanup-toc-line
3100 (match-string 3 line))))
3102 (or (and org-export-mark-todo-in-toc
3104 (not (member (match-string 2 line)
3105 org-done-keywords)))
3107 (and org-export-mark-todo-in-toc
3109 (org-search-todo-below
3110 line lines level))))
3112 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3113 (setq txt (replace-match " <span class=\"tag\"> \\1</span>" t nil txt)))
3114 (if (string-match quote-re0 txt)
3115 (setq txt (replace-match "" t t txt)))
3116 (setq snumber (org-section-number level))
3117 (if org-export-with-section-numbers
3118 (setq txt (concat snumber " " txt)))
3119 (if (<= level (max umax umax-toc))
3120 (setq head-count (+ head-count 1)))
3121 (if (<= level umax-toc)
3123 (if (> level org-last-level)
3125 (setq cnt (- level org-last-level))
3126 (while (>= (setq cnt (1- cnt)) 0)
3127 (push "\n<ul>\n<li>" thetoc))
3128 (push "\n" thetoc)))
3129 (if (< level org-last-level)
3131 (setq cnt (- org-last-level level))
3132 (while (>= (setq cnt (1- cnt)) 0)
3133 (push "</li>\n</ul>" thetoc))
3134 (push "\n" thetoc)))
3135 ;; Check for targets
3136 (while (string-match org-any-target-regexp line)
3137 (setq line (replace-match
3138 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3140 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt)
3141 (setq txt (replace-match "" t t txt)))
3145 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3146 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3147 snumber txt) thetoc)
3149 (setq org-last-level level))
3153 (while (> org-last-level (1- org-min-level))
3154 (setq org-last-level (1- org-last-level))
3155 (push "</li>\n</ul>\n" thetoc))
3156 (push "</div>\n" thetoc)
3157 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3160 (org-init-section-numbers)
3164 (while (setq line (pop lines) origline line)
3167 ;; end of quote section?
3168 (when (and inquote (string-match "^\\*+ " line))
3171 ;; inside a quote section?
3173 (insert (org-html-protect line) "\n")
3174 (throw 'nextline nil))
3176 ;; Fixed-width, verbatim lines (examples)
3177 (when (and org-export-with-fixed-width
3178 (string-match "^[ \t]*:\\(.*\\)" line))
3181 (org-close-par-maybe)
3182 (insert "<pre class=\"example\">\n"))
3183 (insert (org-html-protect (match-string 1 line)) "\n")
3184 (when (or (not lines)
3185 (not (string-match "^[ \t]*\\(:.*\\)"
3188 (insert "</pre>\n"))
3189 (throw 'nextline nil))
3192 (when (get-text-property 0 'org-protected line)
3194 (when (re-search-backward
3195 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3196 (setq par (match-string 1))
3197 (replace-match "\\2\n"))
3200 (not (string-match "^[ \t]*:" (car lines)))
3201 (or (= (length (car lines)) 0)
3202 (get-text-property 0 'org-protected (car lines))))
3203 (insert (pop lines) "\n"))
3204 (and par (insert "<p>\n")))
3205 (throw 'nextline nil))
3208 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3210 (insert "\n</p>\n<hr/>\n<p>\n")
3211 (insert "\n<hr/>\n"))
3212 (throw 'nextline nil))
3214 ;; Blockquotes and verse
3215 (when (equal "ORG-BLOCKQUOTE-START" line)
3216 (insert "<blockquote>\n<p>\n")
3217 (throw 'nextline nil))
3218 (when (equal "ORG-BLOCKQUOTE-END" line)
3219 (insert "</p>\n</blockquote>\n")
3220 (throw 'nextline nil))
3221 (when (equal "ORG-VERSE-START" line)
3222 (insert "\n<p class=\"verse\">\n")
3224 (throw 'nextline nil))
3225 (when (equal "ORG-VERSE-END" line)
3228 (throw 'nextline nil))
3230 (let ((i (org-get-string-indentation line)))
3232 (setq line (concat (mapconcat 'identity
3233 (make-list (* 2 i) "\\nbsp") "")
3234 " " (org-trim line))))
3235 (setq line (concat line " \\\\"))))
3237 ;; make targets to anchors
3238 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3241 (setq line (replace-match
3243 "@<a name=\"%s\" id=\"%s\">@</a>"
3244 (org-solidify-link-text (match-string 1 line))
3245 (org-solidify-link-text (match-string 1 line)))
3247 ((and org-export-with-toc (equal (string-to-char line) ?*))
3248 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3249 (setq line (replace-match
3250 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3251 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3254 (setq line (replace-match
3255 (concat "@<a name=\""
3256 (org-solidify-link-text (match-string 1 line))
3257 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3260 (setq line (org-html-handle-time-stamps line))
3262 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3263 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3264 ;; Also handle sub_superscripts and checkboxes
3265 (or (string-match org-table-hline-regexp line)
3266 (setq line (org-html-expand line)))
3270 (while (string-match org-bracket-link-analytic-regexp line start)
3271 (setq start (match-beginning 0))
3272 (setq path (save-match-data (org-link-unescape
3273 (match-string 3 line))))
3275 ((match-end 2) (match-string 2 line))
3277 (or (file-name-absolute-p path)
3278 (string-match "^\\.\\.?/" path)))
3281 (setq path (org-extract-attributes path))
3282 (setq attr (org-attributes-to-string
3283 (get-text-property 0 'org-attributes path)))
3284 (setq desc1 (if (match-end 5) (match-string 5 line))
3285 desc2 (if (match-end 2) (concat type ":" path) path)
3286 descp (and desc1 (not (equal desc1 desc2)))
3287 desc (or desc1 desc2))
3288 ;; Make an image out of the description if that is so wanted
3289 (when (and descp (org-file-image-p desc))
3291 (if (string-match "^file:" desc)
3292 (setq desc (substring desc (match-end 0)))))
3293 (setq desc (org-add-props
3294 (concat "<img src=\"" desc "\"/>")
3295 '(org-protected t))))
3296 ;; FIXME: do we need to unescape here somewhere?
3298 ((equal type "internal")
3302 (org-solidify-link-text
3303 (save-match-data (org-link-unescape path)) nil)
3305 (org-export-html-format-desc desc)
3307 ((member type '("http" "https"))
3308 ;; standard URL, just check if we need to inline an image
3309 (if (and (or (eq t org-export-html-inline-images)
3310 (and org-export-html-inline-images (not descp)))
3311 (org-file-image-p path))
3312 (setq rpl (concat "<img src=\"" type ":" path "\""
3313 (if (string-match "\\<alt=" attr)
3314 attr (concat attr " alt=\"" path "\""))
3316 (setq link (concat type ":" path))
3317 (setq rpl (concat "<a href=\""
3318 (org-export-html-format-href link)
3320 (org-export-html-format-desc desc)
3322 ((member type '("ftp" "mailto" "news"))
3324 (setq link (concat type ":" path))
3325 (setq rpl (concat "<a href=\""
3326 (org-export-html-format-href link)
3328 (org-export-html-format-desc desc)
3331 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3332 ;; The link protocol has a function for format the link
3335 (funcall fnc (org-link-unescape path) desc1 'html))))
3337 ((string= type "file")
3339 (let* ((filename path)
3340 (abs-p (file-name-absolute-p filename))
3341 thefile file-is-image-p search)
3343 (if (string-match "::\\(.*\\)" filename)
3344 (setq search (match-string 1 filename)
3345 filename (replace-match "" t nil filename)))
3347 (if (functionp link-validate)
3348 (funcall link-validate filename current-dir)
3350 (setq file-is-image-p (org-file-image-p filename))
3351 (setq thefile (if abs-p (expand-file-name filename) filename))
3352 (when (and org-export-html-link-org-files-as-html
3353 (string-match "\\.org$" thefile))
3354 (setq thefile (concat (substring thefile 0
3355 (match-beginning 0))
3356 "." html-extension))
3358 ;; make sure this is can be used as target search
3359 (not (string-match "^[0-9]*$" search))
3360 (not (string-match "^\\*" search))
3361 (not (string-match "^/.*/$" search)))
3362 (setq thefile (concat thefile "#"
3363 (org-solidify-link-text
3364 (org-link-unescape search)))))
3365 (when (string-match "^file:" desc)
3366 (setq desc (replace-match "" t t desc))
3367 (if (string-match "\\.org$" desc)
3368 (setq desc (replace-match "" t t desc))))))
3369 (setq rpl (if (and file-is-image-p
3370 (or (eq t org-export-html-inline-images)
3371 (and org-export-html-inline-images
3373 (concat "<img src=\"" thefile "\""
3374 (if (string-match "alt=" attr)
3376 (concat attr " alt=\""
3377 thefile "\"")) "/>")
3378 (concat "<a href=\"" thefile "\"" attr ">"
3379 (org-export-html-format-desc desc)
3381 (if (not valid) (setq rpl desc))))
3384 ;; just publish the path, as default
3385 (setq rpl (concat "<i><" type ":"
3386 (save-match-data (org-link-unescape path))
3388 (setq line (replace-match rpl t t line)
3389 start (+ start (length rpl))))
3392 (if (and (string-match org-todo-line-regexp line)
3393 (match-beginning 2))
3396 (concat (substring line 0 (match-beginning 2))
3398 (if (member (match-string 2 line)
3401 "\">" (match-string 2 line)
3402 "</span>" (substring line (match-end 2)))))
3404 ;; Does this contain a reference to a footnote?
3405 (when org-export-with-footnotes
3407 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3408 (if (get-text-property (match-beginning 2) 'org-protected line)
3409 (setq start (match-end 2))
3410 (let ((n (match-string 2 line)))
3414 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3415 (match-string 1 line) n n n)
3419 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3420 ;; This is a headline
3421 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3422 txt (match-string 2 line))
3423 (if (string-match quote-re0 txt)
3424 (setq txt (replace-match "" t t txt)))
3425 (if (<= level (max umax umax-toc))
3426 (setq head-count (+ head-count 1)))
3428 ;; Close any local lists before inserting a new header line
3429 (while local-list-type
3430 (org-close-li (car local-list-type))
3431 (insert (format "</%sl>\n" (car local-list-type)))
3432 (pop local-list-type))
3433 (setq local-list-indent nil
3435 (setq first-heading-pos (or first-heading-pos (point)))
3436 (org-html-level-start level txt umax
3437 (and org-export-with-toc (<= level umax))
3440 (when (string-match quote-re line)
3441 (org-close-par-maybe)
3445 ((and org-export-with-tables
3446 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3447 (if (not table-open)
3449 (setq table-open t table-buffer nil table-orig-buffer nil))
3451 (setq table-buffer (cons line table-buffer)
3452 table-orig-buffer (cons origline table-orig-buffer))
3453 (when (or (not lines)
3454 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3456 (setq table-open nil
3457 table-buffer (nreverse table-buffer)
3458 table-orig-buffer (nreverse table-orig-buffer))
3459 (org-close-par-maybe)
3460 (insert (org-format-table-html table-buffer table-orig-buffer))))
3465 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3466 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3467 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3468 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3470 (setq ind (org-get-string-indentation line)
3471 item-type (if (match-beginning 4) "o" "u")
3472 starter (if (match-beginning 2)
3473 (substring (match-string 2 line) 0 -1))
3474 line (substring line (match-beginning 5))
3476 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3478 item-tag (match-string 1 line)
3479 line (substring line (match-end 0))))
3480 (when (and (not (equal item-type "d"))
3481 (not (string-match "[^ \t]" line)))
3482 ;; empty line. Pretend indentation is large.
3483 (setq ind (if org-empty-line-terminates-plain-lists
3485 (1+ (or (car local-list-indent) 1)))))
3487 (while (and in-local-list
3488 (or (and (= ind (car local-list-indent))
3490 (< ind (car local-list-indent))))
3492 (org-close-li (car local-list-type))
3493 (insert (format "</%sl>\n" (car local-list-type)))
3494 (pop local-list-type) (pop local-list-indent)
3495 (setq in-local-list local-list-indent))
3498 (or (not in-local-list)
3499 (> ind (car local-list-indent))))
3500 ;; Start new (level of) list
3501 (org-close-par-maybe)
3503 ((equal item-type "u") "<ul>\n<li>\n")
3504 ((equal item-type "o") "<ol>\n<li>\n")
3505 ((equal item-type "d")
3506 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3507 (push item-type local-list-type)
3508 (push ind local-list-indent)
3509 (setq in-local-list t))
3511 ;; continue current list
3512 (org-close-li (car local-list-type))
3514 ((equal (car local-list-type) "d")
3515 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3518 ;; we did close a list, normal text follows: need <p>
3520 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3523 (if (equal (match-string 1 line) "X")
3525 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3528 ;; Empty lines start a new paragraph. If hand-formatted lists
3529 ;; are not fully interpreted, lines starting with "-", "+", "*"
3530 ;; also start a new paragraph.
3531 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3533 ;; Is this the start of a footnote?
3534 (when org-export-with-footnotes
3535 (when (and (boundp 'footnote-section-tag-regexp)
3536 (string-match (concat "^" footnote-section-tag-regexp)
3539 (throw 'nextline nil))
3540 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3541 (org-close-par-maybe)
3542 (let ((n (match-string 1 line)))
3543 (setq org-par-open t
3545 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
3547 ;; Check if the line break needs to be conserved
3549 ((string-match "\\\\\\\\[ \t]*$" line)
3550 (setq line (replace-match "<br/>" t t line)))
3551 (org-export-preserve-breaks
3552 (setq line (concat line "<br/>"))))
3554 (insert line "\n")))))
3556 ;; Properly close all local lists and other lists
3561 ;; Close any local lists before inserting a new header line
3562 (while local-list-type
3563 (org-close-li (car local-list-type))
3564 (insert (format "</%sl>\n" (car local-list-type)))
3565 (pop local-list-type))
3566 (setq local-list-indent nil
3568 (org-html-level-start 1 nil umax
3569 (and org-export-with-toc (<= level umax))
3571 ;; the </div> to close the last text-... div.
3572 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
3575 (goto-char (point-min))
3576 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
3577 (push (match-string 0) footnotes)
3578 (replace-match "" t t)))
3580 (insert (format org-export-html-footnotes-section
3581 (or (nth 4 lang-words) "Footnotes")
3582 (mapconcat 'identity (nreverse footnotes) "\n"))
3585 (when (plist-get opt-plist :auto-postamble)
3586 (insert "<div id=\"postamble\">")
3587 (when (and org-export-author-info author)
3588 (insert "<p class=\"author\"> "
3589 (nth 1 lang-words) ": " author "\n")
3591 (if (listp (split-string email ",+ *"))
3593 (insert "<a href=\"mailto:" e "\"><"
3595 (split-string email ",+ *"))
3596 (insert "<a href=\"mailto:" email "\"><"
3597 email "></a>\n")))
3599 (when (and date org-export-time-stamp-file)
3600 (insert "<p class=\"date\"> "
3601 (nth 2 lang-words) ": "
3603 (when org-export-creator-info
3604 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3605 org-version emacs-major-version)))
3608 (if org-export-html-with-timestamp
3609 (insert org-export-html-html-helper-timestamp))
3610 (insert (or (plist-get opt-plist :postamble) ""))
3611 (insert "</body>\n</html>\n"))
3613 (unless (plist-get opt-plist :buffer-will-be-killed)
3615 (if (eq major-mode default-major-mode) (html-mode)))
3617 ;; insert the table of contents
3618 (goto-char (point-min))
3620 (if (or (re-search-forward
3621 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3623 "\\[TABLE-OF-CONTENTS\\]" nil t))
3625 (goto-char (match-beginning 0))
3627 (goto-char first-heading-pos)
3628 (when (looking-at "\\s-*</p>")
3629 (goto-char (match-end 0))
3631 (insert "<div id=\"table-of-contents\">\n")
3632 (mapc 'insert thetoc)
3633 (insert "</div>\n"))
3634 ;; remove empty paragraphs and lists
3635 (goto-char (point-min))
3636 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3638 (goto-char (point-min))
3639 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3641 (goto-char (point-min))
3642 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3644 ;; Convert whitespace place holders
3645 (goto-char (point-min))
3647 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3648 (setq n (get-text-property beg 'org-whitespace)
3649 end (next-single-property-change beg 'org-whitespace))
3651 (delete-region beg end)
3652 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3653 (make-string n ?x)))))
3654 (or to-buffer (save-buffer))
3655 (goto-char (point-min))
3656 (message "Exporting... done")
3657 (if (eq to-buffer 'string)
3658 (prog1 (buffer-substring (point-min) (point-max))
3659 (kill-buffer (current-buffer)))
3660 (current-buffer)))))
3662 (defun org-export-html-format-href (s)
3663 "Make sure the S is valid as a href reference in an XHTML document."
3666 (while (string-match "&" s start)
3667 (setq start (+ (match-beginning 0) 3)
3668 s (replace-match "&" t t s)))))
3671 (defun org-export-html-format-desc (s)
3672 "Make sure the S is valid as a description in a link."
3673 (if (and s (not (get-text-property 1 'org-protected s)))
3675 (org-html-do-expand s))
3678 (defvar org-table-colgroup-info nil)
3679 (defun org-format-table-ascii (lines)
3680 "Format a table for ascii export."
3682 (setq lines (org-split-string lines "\n")))
3683 (if (not (string-match "^[ \t]*|" (car lines)))
3684 ;; Table made by table.el - test for spanning
3687 ;; A normal org table
3688 ;; Get rid of hlines at beginning and end
3689 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3690 (setq lines (nreverse lines))
3691 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3692 (setq lines (nreverse lines))
3693 (when org-export-table-remove-special-lines
3694 ;; Check if the table has a marking column. If yes remove the
3695 ;; column and the special lines
3696 (setq lines (org-table-clean-before-export lines)))
3697 ;; Get rid of the vertical lines except for grouping
3698 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3700 (while (setq line (pop lines))
3701 (if (string-match org-table-hline-regexp line)
3702 (and (string-match "|\\(.*\\)|" line)
3703 (setq line (replace-match " \\1" t nil line)))
3704 (setq start 0 vl1 vl)
3705 (while (string-match "|" line start)
3706 (setq start (match-end 0))
3707 (or (pop vl1) (setq line (replace-match " " t t line)))))
3711 (defun org-colgroup-info-to-vline-list (info)
3714 (setq last new new (pop info))
3715 (if (or (memq last '(:end :startend))
3716 (memq new '(:start :startend)))
3719 (setq vl (nreverse vl))
3720 (and vl (setcar vl nil))
3723 (defvar org-table-number-regexp) ; defined in org-table.el
3724 (defun org-format-table-html (lines olines)
3725 "Find out which HTML converter to use and return the HTML code."
3727 (setq lines (org-split-string lines "\n")))
3728 (if (string-match "^[ \t]*|" (car lines))
3729 ;; A normal org table
3730 (org-format-org-table-html lines)
3731 ;; Table made by table.el - test for spanning
3732 (let* ((hlines (delq nil (mapcar
3734 (if (string-match "^[ \t]*\\+-" x) x
3737 (first (car hlines))
3738 (ll (and (string-match "\\S-+" first)
3739 (match-string 0 first)))
3740 (re (concat "^[ \t]*" (regexp-quote ll)))
3741 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3743 (if (and (not spanning)
3744 (not org-export-prefer-native-exporter-for-tables))
3745 ;; We can use my own converter with HTML conversions
3746 (org-format-table-table-html lines)
3747 ;; Need to use the code generator in table.el, with the original text.
3748 (org-format-table-table-html-using-table-generate-source olines)))))
3750 (defvar org-table-number-fraction) ; defined in org-table.el
3751 (defun org-format-org-table-html (lines &optional splice)
3752 "Format a table into HTML."
3753 (require 'org-table)
3754 ;; Get rid of hlines at beginning and end
3755 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3756 (setq lines (nreverse lines))
3757 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3758 (setq lines (nreverse lines))
3759 (when org-export-table-remove-special-lines
3760 ;; Check if the table has a marking column. If yes remove the
3761 ;; column and the special lines
3762 (setq lines (org-table-clean-before-export lines)))
3764 (let ((head (and org-export-highlight-first-table-line
3766 (lambda (x) (string-match "^[ \t]*|-" x))
3769 tbopen line fields html gr colgropen)
3770 (if splice (setq head nil))
3771 (unless splice (push (if head "<thead>" "<tbody>") html))
3773 (while (setq line (pop lines))
3775 (if (string-match "^[ \t]*|-" line)
3778 (push (if head "</thead>" "</tbody>") html)
3779 (if lines (push "<tbody>" html) (setq tbopen nil)))
3780 (setq head nil) ;; head ends here, first time around
3782 (throw 'next-line t)))
3783 ;; Break the line into fields
3784 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3785 (unless fnum (setq fnum (make-vector (length fields) 0)))
3786 (setq nlines (1+ nlines) i -1)
3787 (push (concat "<tr>"
3791 (if (and (< i nlines)
3792 (string-match org-table-number-regexp x))
3793 (incf (aref fnum i)))
3795 (concat (car org-export-table-header-tags) x
3796 (cdr org-export-table-header-tags))
3797 (concat (car org-export-table-data-tags) x
3798 (cdr org-export-table-data-tags))))
3802 (unless splice (if tbopen (push "</tbody>" html)))
3803 (unless splice (push "</table>\n" html))
3804 (setq html (nreverse html))
3806 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3809 (setq gr (pop org-table-colgroup-info))
3810 (format "%s<col align=\"%s\"></col>%s"
3811 (if (memq gr '(:start :startend))
3813 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3816 (if (> (/ (float x) nlines) org-table-number-fraction)
3818 (if (memq gr '(:end :startend))
3819 (progn (setq colgropen nil) "</colgroup>")
3823 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3824 (push html-table-tag html))
3825 (concat (mapconcat 'identity html "\n") "\n")))
3827 (defun org-table-clean-before-export (lines)
3828 "Check if the table has a marking column.
3829 If yes remove the column and the special lines."
3830 (setq org-table-colgroup-info nil)
3833 (lambda (x) (or (string-match "^[ \t]*|-" x)
3834 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3837 (setq org-table-clean-did-remove-column nil)
3842 ((string-match "^[ \t]*| */ *|" x)
3843 (setq org-table-colgroup-info
3845 (cond ((member x '("<" "<")) :start)
3846 ((member x '(">" ">")) :end)
3847 ((member x '("<>" "<>")) :startend)
3849 (org-split-string x "[ \t]*|[ \t]*")))
3853 (setq org-table-clean-did-remove-column t)
3858 ((string-match "^[ \t]*| */ *|" x)
3859 (setq org-table-colgroup-info
3861 (cond ((member x '("<" "<")) :start)
3862 ((member x '(">" ">")) :end)
3863 ((member x '("<>" "<>")) :startend)
3865 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3867 ((string-match "^[ \t]*| *[!_^/] *|" x)
3868 nil) ; ignore this line
3869 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3870 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3871 ;; remove the first column
3872 (replace-match "\\1|" t nil x))))
3875 (defun org-format-table-table-html (lines)
3876 "Format a table generated by table.el into HTML.
3877 This conversion does *not* use `table-generate-source' from table.el.
3878 This has the advantage that Org-mode's HTML conversions can be used.
3879 But it has the disadvantage, that no cell- or row-spanning is allowed."
3880 (let (line field-buffer
3881 (head org-export-highlight-first-table-line)
3883 (setq html (concat html-table-tag "\n"))
3884 (while (setq line (pop lines))
3885 (setq empty " ")
3887 (if (string-match "^[ \t]*\\+-" line)
3898 (if (equal x "") (setq x empty))
3900 (concat (car org-export-table-header-tags) x
3901 (cdr org-export-table-header-tags))
3902 (concat (car org-export-table-data-tags) x
3903 (cdr org-export-table-data-tags))))
3907 (setq field-buffer nil)))
3909 (throw 'next-line t)))
3910 ;; Break the line into fields and store the fields
3911 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3913 (setq field-buffer (mapcar
3915 (concat x "<br/>" (pop fields)))
3917 (setq field-buffer fields))))
3918 (setq html (concat html "</table>\n"))
3921 (defun org-format-table-table-html-using-table-generate-source (lines)
3922 "Format a table into html, using `table-generate-source' from table.el.
3923 This has the advantage that cell- or row-spanning is allowed.
3924 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3926 (with-current-buffer (get-buffer-create " org-tmp1 ")
3928 (insert (mapconcat 'identity lines "\n"))
3929 (goto-char (point-min))
3930 (if (not (re-search-forward "|[^+]" nil t))
3931 (error "Error processing table"))
3932 (table-recognize-table)
3933 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3934 (table-generate-source 'html " org-tmp2 ")
3935 (set-buffer " org-tmp2 ")
3936 (buffer-substring (point-min) (point-max))))
3938 (defun org-export-splice-style (style extra)
3939 "Splice EXTRA into STYLE, just before \"</style>\"."
3940 (if (and (stringp extra)
3941 (string-match "\\S-" extra)
3942 (string-match "</style>" style))
3943 (concat (substring style 0 (match-beginning 0))
3945 (substring style (match-beginning 0)))
3948 (defun org-html-handle-time-stamps (s)
3949 "Format time stamps in string S, or remove them."
3952 (while (string-match org-maybe-keyword-time-regexp s)
3953 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3954 ;; never export CLOCK
3956 (or b (setq b (substring s 0 (match-beginning 0))))
3957 (if (not org-export-with-timestamps)
3958 (setq r (concat r (substring s 0 (match-beginning 0)))
3959 s (substring s (match-end 0)))
3961 r (substring s 0 (match-beginning 0))
3963 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3964 (match-string 1 s)))
3965 (format " @<span class=\"timestamp\">%s@</span>"
3967 (org-translate-time (match-string 3 s)) 1 -1)))
3968 s (substring s (match-end 0)))))
3969 ;; Line break if line started and ended with time stamp stuff
3972 (setq r (concat r s))
3973 (unless (string-match "\\S-" (concat b s))
3974 (setq r (concat r "@<br/>")))
3977 (defun org-export-htmlize-region-for-paste (beg end)
3978 "Convert the region to HTML, using htmlize.el.
3979 This is much like `htmlize-region-for-paste', only that it uses
3980 the settings define in the org-... variables."
3981 (let* ((htmlize-output-type org-export-htmlize-output-type)
3982 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3983 (htmlbuf (htmlize-region beg end)))
3985 (with-current-buffer htmlbuf
3986 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3987 (plist-get htmlize-buffer-places 'content-end)))
3988 (kill-buffer htmlbuf))))
3991 (defun org-export-htmlize-generate-css ()
3992 "Create the CSS for all font definitions in the current Emacs session.
3993 Use this to create face definitions in your CSS style file that can then
3994 be used by code snippets transformed by htmlize.
3995 This command just produces a buffer that contains class definitions for all
3996 faces used in the current Emacs session. You can copy and paste the ones you
3997 need into your CSS file.
3999 If you then set `org-export-htmlize-output-type' to `css', calls to
4000 the function `org-export-htmlize-region-for-paste' will produce code
4001 that uses these same face definitions."
4004 (and (get-buffer "*html*") (kill-buffer "*html*"))
4006 (let ((fl (face-list))
4007 (htmlize-css-name-prefix "org-")
4008 (htmlize-output-type 'css)
4010 (while (setq f (pop fl)
4011 i (and f (face-attribute f :inherit)))
4012 (when (and (symbolp f) (or (not i) (not (listp i))))
4013 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4014 (htmlize-region (point-min) (point-max))))
4015 (switch-to-buffer "*html*")
4016 (goto-char (point-min))
4017 (if (re-search-forward "<style" nil t)
4018 (delete-region (point-min) (match-beginning 0)))
4019 (if (re-search-forward "</style>" nil t)
4020 (delete-region (1+ (match-end 0)) (point-max)))
4021 (beginning-of-line 1)
4022 (if (looking-at " +") (replace-match ""))
4023 (goto-char (point-min)))
4025 (defun org-html-protect (s)
4026 ;; convert & to &, < to < and > to >
4028 (while (string-match "&" s start)
4029 (setq s (replace-match "&" t t s)
4030 start (1+ (match-beginning 0))))
4031 (while (string-match "<" s)
4032 (setq s (replace-match "<" t t s)))
4033 (while (string-match ">" s)
4034 (setq s (replace-match ">" t t s)))
4035 ; (while (string-match "\"" s)
4036 ; (setq s (replace-match """ t t s)))
4040 (defun org-export-cleanup-toc-line (s)
4041 "Remove tags and time staps from lines going into the toc."
4042 (when (memq org-export-with-tags '(not-in-toc nil))
4043 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4044 (setq s (replace-match "" t t s))))
4045 (when org-export-remove-timestamps-from-toc
4046 (while (string-match org-maybe-keyword-time-regexp s)
4047 (setq s (replace-match "" t t s))))
4048 (while (string-match org-bracket-link-regexp s)
4049 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4053 (defun org-html-expand (string)
4054 "Prepare STRING for HTML export. Applies all active conversions.
4055 If there are links in the string, don't modify these."
4056 (let* ((re (concat org-bracket-link-regexp "\\|"
4057 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4059 (while (setq m (string-match re string))
4060 (setq s (substring string 0 m)
4061 l (match-string 0 string)
4062 string (substring string (match-end 0)))
4063 (push (org-html-do-expand s) res)
4065 (push (org-html-do-expand string) res)
4066 (apply 'concat (nreverse res))))
4068 (defun org-html-do-expand (s)
4069 "Apply all active conversions to translate special ASCII to HTML."
4070 (setq s (org-html-protect s))
4071 (if org-export-html-expand
4073 (while (string-match "@<\\([^&]*\\)>" s)
4074 (setq s (replace-match "<\\1>" t nil s)))))
4075 (if org-export-with-emphasize
4076 (setq s (org-export-html-convert-emphasize s)))
4077 (if org-export-with-special-strings
4078 (setq s (org-export-html-convert-special-strings s)))
4079 (if org-export-with-sub-superscripts
4080 (setq s (org-export-html-convert-sub-super s)))
4081 (if org-export-with-TeX-macros
4082 (let ((start 0) wd ass)
4083 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4085 (if (get-text-property (match-beginning 0) 'org-protected s)
4086 (setq start (match-end 0))
4087 (setq wd (match-string 1 s))
4088 (if (setq ass (assoc wd org-html-entities))
4089 (setq s (replace-match (or (cdr ass)
4090 (concat "&" (car ass) ";"))
4092 (setq start (+ start (length wd))))))))
4095 (defun org-create-multibrace-regexp (left right n)
4096 "Create a regular expression which will match a balanced sexp.
4097 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4098 as single character strings.
4099 The regexp returned will match the entire expression including the
4100 delimiters. It will also define a single group which contains the
4101 match except for the outermost delimiters. The maximum depth of
4102 stacked delimiters is N. Escaping delimiters is not possible."
4103 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
4106 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4109 re (concat re or next)
4110 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4111 (concat left "\\(" re "\\)" right)))
4113 (defvar org-match-substring-regexp
4115 "\\([^\\]\\)\\([_^]\\)\\("
4116 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4118 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4120 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4121 "The regular expression matching a sub- or superscript.")
4123 (defvar org-match-substring-with-braces-regexp
4125 "\\([^\\]\\)\\([_^]\\)\\("
4126 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4128 "The regular expression matching a sub- or superscript, forcing braces.")
4130 (defconst org-export-html-special-string-regexps
4131 '(("\\\\-" . "­")
4132 ("---\\([^-]\\)" . "—\\1")
4133 ("--\\([^-]\\)" . "–\\1")
4134 ("\\.\\.\\." . "…"))
4135 "Regular expressions for special string conversion.")
4137 (defun org-export-html-convert-special-strings (string)
4138 "Convert special characters in STRING to HTML."
4139 (let ((all org-export-html-special-string-regexps)
4141 (while (setq a (pop all))
4142 (setq re (car a) rpl (cdr a) start 0)
4143 (while (string-match re string start)
4144 (if (get-text-property (match-beginning 0) 'org-protected string)
4145 (setq start (match-end 0))
4146 (setq string (replace-match rpl t nil string)))))
4149 (defun org-export-html-convert-sub-super (string)
4150 "Convert sub- and superscripts in STRING to HTML."
4151 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4152 (while (string-match org-match-substring-regexp string s)
4154 ((and requireb (match-end 8)) (setq s (match-end 2)))
4155 ((get-text-property (match-beginning 2) 'org-protected string)
4156 (setq s (match-end 2)))
4158 (setq s (match-end 1)
4159 key (if (string= (match-string 2 string) "_") "sub" "sup")
4160 c (or (match-string 8 string)
4161 (match-string 6 string)
4162 (match-string 5 string))
4163 string (replace-match
4164 (concat (match-string 1 string)
4165 "<" key ">" c "</" key ">")
4167 (while (string-match "\\\\\\([_^]\\)" string)
4168 (setq string (replace-match (match-string 1 string) t t string)))
4171 (defun org-export-html-convert-emphasize (string)
4174 (while (string-match org-emph-re string s)
4176 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4177 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4178 (setq s (match-beginning 0)
4181 (match-string 1 string)
4182 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4183 (match-string 4 string)
4184 (nth 3 (assoc (match-string 3 string)
4185 org-emphasis-alist))
4186 (match-string 5 string))
4187 string (replace-match rpl t t string)
4188 s (+ s (- (length rpl) 2)))
4192 (defun org-open-par ()
4193 "Insert <p>, but first close previous paragraph if any."
4194 (org-close-par-maybe)
4196 (setq org-par-open t))
4197 (defun org-close-par-maybe ()
4198 "Close paragraph if there is one open."
4201 (setq org-par-open nil)))
4202 (defun org-close-li (&optional type)
4203 "Close <li> if necessary."
4204 (org-close-par-maybe)
4205 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4207 (defvar body-only) ; dynamically scoped into this.
4208 (defun org-html-level-start (level title umax with-toc head-count)
4209 "Insert a new level in HTML export.
4210 When TITLE is nil, just close all open levels."
4211 (org-close-par-maybe)
4212 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4214 (mapconcat (lambda (x)
4215 (format "<a name=\"%s\" id=\"%s\"></a>"
4217 (cdr (assoc target org-export-target-aliases))
4222 (if (aref org-levels-open (1- l))
4224 (org-html-level-close l umax)
4225 (aset org-levels-open (1- l) nil)))
4228 ;; If title is nil, this means this function is called to close
4229 ;; all levels, so the rest is done only if title is given
4230 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4231 (setq title (replace-match
4232 (if org-export-with-tags
4235 " <span class=\"tag\">"
4236 (mapconcat 'identity (org-split-string
4237 (match-string 1 title) ":")
4244 (if (aref org-levels-open (1- level))
4248 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4249 (insert "<li>" title "<br/>\n")))
4250 (aset org-levels-open (1- level) t)
4251 (org-close-par-maybe)
4253 (insert (format "<ul>\n<li id=\"%s\">" target)
4254 extra-targets title "<br/>\n")
4255 (insert "<ul>\n<li>" title "<br/>\n"))))
4256 (aset org-levels-open (1- level) t)
4257 (setq snumber (org-section-number level))
4258 (if (and org-export-with-section-numbers (not body-only))
4259 (setq title (concat snumber " " title)))
4260 (setq level (+ level org-export-html-toplevel-hlevel -1))
4261 (unless (= head-count 1) (insert "\n</div>\n"))
4262 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div id=\"text-%s\">\n"
4263 snumber level level snumber extra-targets title level snumber))
4266 (defun org-get-text-property-any (pos prop &optional object)
4267 (or (get-text-property pos prop object)
4268 (and (setq pos (next-single-property-change pos prop object))
4269 (get-text-property pos prop object))))
4271 (defun org-html-level-close (level max-outline-level)
4272 "Terminate one level in HTML export."
4273 (if (<= level max-outline-level)
4276 (insert "</ul>\n")))
4278 ;;; iCalendar export
4281 (defun org-export-icalendar-this-file ()
4282 "Export current file as an iCalendar file.
4283 The iCalendar file will be located in the same directory as the Org-mode
4284 file, but with extension `.ics'."
4286 (org-export-icalendar nil buffer-file-name))
4289 (defun org-export-icalendar-all-agenda-files ()
4290 "Export all files in `org-agenda-files' to iCalendar .ics files.
4291 Each iCalendar file will be located in the same directory as the Org-mode
4292 file, but with extension `.ics'."
4294 (apply 'org-export-icalendar nil (org-agenda-files t)))
4297 (defun org-export-icalendar-combine-agenda-files ()
4298 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4299 The file is stored under the name `org-combined-agenda-icalendar-file'."
4301 (apply 'org-export-icalendar t (org-agenda-files t)))
4303 (defun org-export-icalendar (combine &rest files)
4304 "Create iCalendar files for all elements of FILES.
4305 If COMBINE is non-nil, combine all calendar entries into a single large
4306 file and store it under the name `org-combined-agenda-icalendar-file'."
4308 (org-prepare-agenda-buffers files)
4309 (let* ((dir (org-export-directory
4310 :ical (list :publishing-directory
4311 org-export-publishing-directory)))
4312 file ical-file ical-buffer category started org-agenda-new-buffers)
4313 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4316 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4317 org-combined-agenda-icalendar-file
4318 (expand-file-name org-combined-agenda-icalendar-file dir))
4319 ical-buffer (org-get-agenda-file-buffer ical-file))
4320 (set-buffer ical-buffer) (erase-buffer))
4321 (while (setq file (pop files))
4323 (org-check-agenda-file file)
4324 (set-buffer (org-get-agenda-file-buffer file))
4326 (setq ical-file (concat (file-name-as-directory dir)
4327 (file-name-sans-extension
4328 (file-name-nondirectory buffer-file-name))
4330 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4331 (with-current-buffer ical-buffer (erase-buffer)))
4332 (setq category (or org-category
4333 (file-name-sans-extension
4334 (file-name-nondirectory buffer-file-name))))
4335 (if (symbolp category) (setq category (symbol-name category)))
4336 (let ((standard-output ical-buffer))
4338 (and (not started) (setq started t)
4339 (org-start-icalendar-file org-icalendar-combined-name))
4340 (org-start-icalendar-file category))
4341 (org-print-icalendar-entries combine)
4342 (when (or (and combine (not files)) (not combine))
4343 (org-finish-icalendar-file)
4344 (set-buffer ical-buffer)
4345 (run-hooks 'org-before-save-iCalendar-file-hook)
4347 (run-hooks 'org-after-save-iCalendar-file-hook)
4348 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4350 (org-release-buffers org-agenda-new-buffers))))
4352 (defvar org-before-save-iCalendar-file-hook nil
4353 "Hook run before an iCalendar file has been saved.
4354 This can be used to modify the result of the export.")
4356 (defvar org-after-save-iCalendar-file-hook nil
4357 "Hook run after an iCalendar file has been saved.
4358 The iCalendar buffer is still current when this hook is run.
4359 A good way to use this is to tell a desktop calenndar application to re-read
4360 the iCalendar file.")
4362 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4363 (defun org-print-icalendar-entries (&optional combine)
4364 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4365 When COMBINE is non nil, add the category to each line."
4366 (require 'org-agenda)
4367 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4368 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4369 (dts (org-ical-ts-to-string
4370 (format-time-string (cdr org-time-stamp-formats) (current-time))
4372 hd ts ts2 state status (inc t) pos b sexp rrule
4373 scheduledp deadlinep todo prefix due start
4374 tmp pri categories entry location summary desc uid
4375 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4376 (org-refresh-category-properties)
4378 (goto-char (point-min))
4379 (while (re-search-forward re1 nil t)
4382 (when (boundp 'org-icalendar-verify-function)
4383 (unless (funcall org-icalendar-verify-function)
4384 (outline-next-heading)
4387 (setq pos (match-beginning 0)
4390 hd (condition-case nil
4391 (org-icalendar-cleanup-string
4393 (error (throw :skip nil)))
4394 summary (org-icalendar-cleanup-string
4395 (org-entry-get nil "SUMMARY"))
4396 desc (org-icalendar-cleanup-string
4397 (or (org-entry-get nil "DESCRIPTION")
4398 (and org-icalendar-include-body (org-get-entry)))
4399 t org-icalendar-include-body)
4400 location (org-icalendar-cleanup-string
4401 (org-entry-get nil "LOCATION" 'selective))
4402 uid (if org-icalendar-store-UID
4404 (or (org-id-get) (org-id-new)))
4405 categories (org-export-get-categories)
4406 deadlinep nil scheduledp nil)
4407 (if (looking-at re2)
4409 (goto-char (match-end 0))
4410 (setq ts2 (match-string 1)
4411 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4412 (setq tmp (buffer-substring (max (point-min)
4413 (- pos org-ds-keyword-length))
4415 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4418 (replace-match "\\1" t nil ts))
4420 deadlinep (string-match org-deadline-regexp tmp)
4421 scheduledp (string-match org-scheduled-regexp tmp)
4422 todo (org-get-todo-state)
4423 ;; donep (org-entry-is-done-p)
4428 (not (memq 'event-if-todo org-icalendar-use-deadline))
4429 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4434 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4435 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4437 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4438 (if (or (string-match org-tr-regexp hd)
4439 (string-match org-ts-regexp hd))
4440 (setq hd (replace-match "" t t hd)))
4441 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4443 (concat "\nRRULE:FREQ="
4446 '(("d" . "DAILY")("w" . "WEEKLY")
4447 ("m" . "MONTHLY")("y" . "YEARLY"))))
4448 ";INTERVAL=" (match-string 1 ts)))
4450 (setq summary (or summary hd))
4451 (if (string-match org-bracket-link-regexp summary)
4453 (replace-match (if (match-end 3)
4454 (match-string 3 summary)
4455 (match-string 1 summary))
4457 (if deadlinep (setq summary (concat "DL: " summary)))
4458 (if scheduledp (setq summary (concat "S: " summary)))
4459 (if (string-match "\\`<%%" ts)
4460 (with-current-buffer sexp-buffer
4461 (insert (substring ts 1 -1) " " summary "\n"))
4462 (princ (format "BEGIN:VEVENT
4470 (org-ical-ts-to-string ts "DTSTART")
4471 (org-ical-ts-to-string ts2 "DTEND" inc)
4473 (if (and desc (string-match "\\S-" desc))
4474 (concat "\nDESCRIPTION: " desc) "")
4475 (if (and location (string-match "\\S-" location))
4476 (concat "\nLOCATION: " location) "")
4478 (when (and org-icalendar-include-sexps
4479 (condition-case nil (require 'icalendar) (error nil))
4480 (fboundp 'icalendar-export-region))
4481 ;; Get all the literal sexps
4482 (goto-char (point-min))
4483 (while (re-search-forward "^&?%%(" nil t)
4486 (setq b (match-beginning 0))
4487 (goto-char (1- (match-end 0)))
4490 (setq sexp (buffer-substring b (point)))
4491 (with-current-buffer sexp-buffer
4492 (insert sexp "\n"))))
4493 (princ (org-diary-to-ical-string sexp-buffer))
4494 (kill-buffer sexp-buffer))
4496 (when org-icalendar-include-todo
4497 (setq prefix "TODO-")
4498 (goto-char (point-min))
4499 (while (re-search-forward org-todo-line-regexp nil t)
4502 (when (boundp 'org-icalendar-verify-function)
4503 (unless (funcall org-icalendar-verify-function)
4504 (outline-next-heading)
4507 (setq state (match-string 2))
4508 (setq status (if (member state org-done-keywords)
4509 "COMPLETED" "NEEDS-ACTION"))
4511 (or (not (member state org-done-keywords))
4512 (eq org-icalendar-include-todo 'all))
4513 (not (member org-archive-tag (org-get-tags-at)))
4515 (setq hd (match-string 3)
4516 summary (org-icalendar-cleanup-string
4517 (org-entry-get nil "SUMMARY"))
4518 desc (org-icalendar-cleanup-string
4519 (or (org-entry-get nil "DESCRIPTION")
4520 (and org-icalendar-include-body (org-get-entry)))
4521 t org-icalendar-include-body)
4522 location (org-icalendar-cleanup-string
4523 (org-entry-get nil "LOCATION" 'selective))
4524 due (and (member 'todo-due org-icalendar-use-deadline)
4525 (org-entry-get nil "DEADLINE"))
4526 start (and (member 'todo-start org-icalendar-use-scheduled)
4527 (org-entry-get nil "SCHEDULED"))
4528 categories (org-export-get-categories)
4529 uid (if org-icalendar-store-UID
4531 (or (org-id-get) (org-id-new))))
4532 (and due (setq due (org-ical-ts-to-string due "DUE")))
4533 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4535 (if (string-match org-bracket-link-regexp hd)
4536 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4537 (match-string 1 hd))
4539 (if (string-match org-priority-regexp hd)
4540 (setq pri (string-to-char (match-string 2 hd))
4541 hd (concat (substring hd 0 (match-beginning 1))
4542 (substring hd (match-end 1))))
4543 (setq pri org-default-priority))
4544 (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
4545 (- org-lowest-priority org-highest-priority))))))
4547 (princ (format "BEGIN:VTODO
4559 (if (and location (string-match "\\S-" location))
4560 (concat "\nLOCATION: " location) "")
4561 (if (and desc (string-match "\\S-" desc))
4562 (concat "\nDESCRIPTION: " desc) "")
4563 (if due (concat "\n" due) "")
4567 (defun org-export-get-categories ()
4568 "Get categories according to `org-icalendar-categories'."
4569 (let ((cs org-icalendar-categories) c rtn tmp)
4570 (while (setq c (pop cs))
4572 ((eq c 'category) (push (org-get-category) rtn))
4574 (setq tmp (org-get-todo-state))
4575 (and tmp (push tmp rtn)))
4577 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4579 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4580 (mapconcat 'identity (nreverse rtn) ",")))
4582 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4583 "Take out stuff and quote what needs to be quoted.
4584 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4585 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4590 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4591 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4592 (while (string-match re s) (setq s (replace-match "" t t s)))
4593 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4595 (while (string-match "\\([,;]\\)" s start)
4596 (setq start (+ (match-beginning 0) 2)
4597 s (replace-match "\\\\\\1" nil nil s))))
4598 (setq s (org-trim s))
4600 (while (string-match "[ \t]*\n[ \t]*" s)
4601 (setq s (replace-match "\\n" t t s))))
4604 (if (and (numberp maxlength)
4605 (> (length s) maxlength))
4606 (setq s (substring s 0 maxlength)))))
4609 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
4610 "Take out stuff and quote what needs to be quoted.
4611 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4612 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4614 This seems to be more like RFC 2455, but it causes problems, so it is
4615 not used right now."
4619 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4620 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4621 (while (string-match re s) (setq s (replace-match "" t t s)))
4622 (while (string-match re2 s) (setq s (replace-match "" t t s)))
4623 (setq s (org-trim s))
4624 (while (string-match "[ \t]*\n[ \t]*" s)
4625 (setq s (replace-match "\\n" t t s)))
4627 (if (and (numberp maxlength)
4628 (> (length s) maxlength))
4629 (setq s (substring s 0 maxlength)))))
4630 (setq s (org-trim s)))
4631 (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
4632 (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
4635 (defun org-get-entry ()
4636 "Clean-up description string."
4638 (org-back-to-heading t)
4639 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4641 (defun org-start-icalendar-file (name)
4642 "Start an iCalendar file by inserting the header."
4643 (let ((user user-full-name)
4644 (name (or name "unknown"))
4645 (timezone (cadr (current-time-zone))))
4647 (format "BEGIN:VCALENDAR
4650 PRODID:-//%s//Emacs with Org-mode//EN
4652 CALSCALE:GREGORIAN\n" name user timezone))))
4654 (defun org-finish-icalendar-file ()
4655 "Finish an iCalendar file by inserting the END statement."
4656 (princ "END:VCALENDAR\n"))
4658 (defun org-ical-ts-to-string (s keyword &optional inc)
4659 "Take a time string S and convert it to iCalendar format.
4660 KEYWORD is added in front, to make a complete line like DTSTART....
4661 When INC is non-nil, increase the hour by two (if time string contains
4662 a time), or the day by one (if it does not contain a time)."
4663 (let ((t1 (org-parse-time-string s 'nodefault))
4664 t2 fmt have-time time)
4665 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4666 (setq t2 t1 have-time t)
4667 (setq t2 (org-parse-time-string s)))
4668 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4669 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4672 (if org-agenda-default-appointment-duration
4673 (setq mi (+ org-agenda-default-appointment-duration mi))
4676 (setq time (encode-time s mi h d m y)))
4677 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4678 (concat keyword (format-time-string fmt time))))
4682 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4683 (with-current-buffer buffer
4684 (apply 'insert output)))
4685 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4688 (defun org-export-as-xoxo (&optional buffer)
4689 "Export the org buffer as XOXO.
4690 The XOXO buffer is named *xoxo-<source buffer name>*"
4691 (interactive (list (current-buffer)))
4692 ;; A quickie abstraction
4694 ;; Output everything as XOXO
4695 (with-current-buffer (get-buffer buffer)
4696 (let* ((pos (point))
4697 (opt-plist (org-combine-plists (org-default-export-plist)
4698 (org-infile-export-plist)))
4699 (filename (concat (file-name-as-directory
4700 (org-export-directory :xoxo opt-plist))
4701 (file-name-sans-extension
4702 (file-name-nondirectory buffer-file-name))
4704 (out (find-file-noselect filename))
4707 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4708 ;; Check the output buffer is empty.
4709 (with-current-buffer out (erase-buffer))
4710 ;; Kick off the output
4711 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4712 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4713 (let* ((hd (match-string-no-properties 1))
4716 (match-string-no-properties 2)
4718 (goto-char (match-end 0))
4723 (if (looking-at "^[ \t]\\(.*\\)")
4724 (setq str (concat str (match-string-no-properties 1)))
4725 (throw 'loop str)))))))))
4727 ;; Handle level rendering
4729 ((> level last-level)
4730 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4732 ((< level last-level)
4733 (dotimes (- (- last-level level) 1)
4735 (org-export-as-xoxo-insert-into out "</li>\n"))
4736 (org-export-as-xoxo-insert-into out "</ol>\n"))
4738 (org-export-as-xoxo-insert-into out "</li>\n")
4739 (setq hanging-li nil)))
4741 ((equal level last-level)
4743 (org-export-as-xoxo-insert-into out "</li>\n")))
4746 (setq last-level level)
4748 ;; And output the new li
4749 (setq hanging-li 't)
4750 (if (equal ?+ (elt text 0))
4751 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4752 (org-export-as-xoxo-insert-into out "<li>" text))))
4754 ;; Finally finish off the ol
4755 (dotimes (- last-level 1)
4757 (org-export-as-xoxo-insert-into out "</li>\n"))
4758 (org-export-as-xoxo-insert-into out "</ol>\n"))
4761 ;; Finish the buffer off and clean it up.
4762 (switch-to-buffer-other-window out)
4763 (indent-region (point-min) (point-max) nil)
4765 (goto-char (point-min))
4770 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4772 ;;; org-exp.el ends here