Version number bump to 6.00pre-3
[org-mode.git] / lisp / org-exp.el
blob034b0266ac5b3c411d5bffa045bd470e9feb3f1c
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.00pre-3
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; 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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 (require 'org)
31 (require 'org-agenda)
32 (eval-and-compile
33 (require 'cl))
35 (declare-function org-export-latex-cleaned-string "org-export-latex" ())
36 (declare-function org-agenda-skip "org-agenda" ())
38 (defgroup org-export nil
39 "Options for exporting org-listings."
40 :tag "Org Export"
41 :group 'org)
43 (defgroup org-export-general nil
44 "General options for exporting Org-mode files."
45 :tag "Org Export General"
46 :group 'org-export)
48 ;; FIXME
49 (defvar org-export-publishing-directory nil)
51 (defcustom org-export-with-special-strings t
52 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
53 When this option is turned on, these strings will be exported as:
55 Org HTML LaTeX
56 -----+----------+--------
57 \\- &shy; \\-
58 -- &ndash; --
59 --- &mdash; ---
60 ... &hellip; \ldots
62 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
63 :group 'org-export-translation
64 :type 'boolean)
66 (defcustom org-export-language-setup
67 '(("en" "Author" "Date" "Table of Contents")
68 ("cs" "Autor" "Datum" "Obsah")
69 ("da" "Ophavsmand" "Dato" "Indhold")
70 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
71 ("es" "Autor" "Fecha" "\xcdndice")
72 ("fr" "Auteur" "Date" "Table des mati\xe8res")
73 ("it" "Autore" "Data" "Indice")
74 ("nl" "Auteur" "Datum" "Inhoudsopgave")
75 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
76 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
77 "Terms used in export text, translated to different languages.
78 Use the variable `org-export-default-language' to set the language,
79 or use the +OPTION lines for a per-file setting."
80 :group 'org-export-general
81 :type '(repeat
82 (list
83 (string :tag "HTML language tag")
84 (string :tag "Author")
85 (string :tag "Date")
86 (string :tag "Table of Contents"))))
88 (defcustom org-export-default-language "en"
89 "The default language of HTML export, as a string.
90 This should have an association in `org-export-language-setup'."
91 :group 'org-export-general
92 :type 'string)
94 (defcustom org-export-skip-text-before-1st-heading t
95 "Non-nil means, skip all text before the first headline when exporting.
96 When nil, that text is exported as well."
97 :group 'org-export-general
98 :type 'boolean)
100 (defcustom org-export-headline-levels 3
101 "The last level which is still exported as a headline.
102 Inferior levels will produce itemize lists when exported.
103 Note that a numeric prefix argument to an exporter function overrides
104 this setting.
106 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
107 :group 'org-export-general
108 :type 'number)
110 (defcustom org-export-with-section-numbers t
111 "Non-nil means, add section numbers to headlines when exporting.
113 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
114 :group 'org-export-general
115 :type 'boolean)
117 (defcustom org-export-with-toc t
118 "Non-nil means, create a table of contents in exported files.
119 The TOC contains headlines with levels up to`org-export-headline-levels'.
120 When an integer, include levels up to N in the toc, this may then be
121 different from `org-export-headline-levels', but it will not be allowed
122 to be larger than the number of headline levels.
123 When nil, no table of contents is made.
125 Headlines which contain any TODO items will be marked with \"(*)\" in
126 ASCII export, and with red color in HTML output, if the option
127 `org-export-mark-todo-in-toc' is set.
129 In HTML output, the TOC will be clickable.
131 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
132 or \"toc:3\"."
133 :group 'org-export-general
134 :type '(choice
135 (const :tag "No Table of Contents" nil)
136 (const :tag "Full Table of Contents" t)
137 (integer :tag "TOC to level")))
139 (defcustom org-export-mark-todo-in-toc nil
140 "Non-nil means, mark TOC lines that contain any open TODO items."
141 :group 'org-export-general
142 :type 'boolean)
144 (defcustom org-export-preserve-breaks nil
145 "Non-nil means, preserve all line breaks when exporting.
146 Normally, in HTML output paragraphs will be reformatted. In ASCII
147 export, line breaks will always be preserved, regardless of this variable.
149 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
150 :group 'org-export-general
151 :type 'boolean)
153 (defcustom org-export-with-archived-trees 'headline
154 "Whether subtrees with the ARCHIVE tag should be exported.
155 This can have three different values
156 nil Do not export, pretend this tree is not present
157 t Do export the entire tree
158 headline Only export the headline, but skip the tree below it."
159 :group 'org-export-general
160 :group 'org-archive
161 :type '(choice
162 (const :tag "not at all" nil)
163 (const :tag "headline only" 'headline)
164 (const :tag "entirely" t)))
166 (defcustom org-export-author-info t
167 "Non-nil means, insert author name and email into the exported file.
169 This option can also be set with the +OPTIONS line,
170 e.g. \"author-info:nil\"."
171 :group 'org-export-general
172 :type 'boolean)
174 (defcustom org-export-time-stamp-file t
175 "Non-nil means, insert a time stamp into the exported file.
176 The time stamp shows when the file was created.
178 This option can also be set with the +OPTIONS line,
179 e.g. \"timestamp:nil\"."
180 :group 'org-export-general
181 :type 'boolean)
183 (defcustom org-export-with-timestamps t
184 "If nil, do not export time stamps and associated keywords."
185 :group 'org-export-general
186 :type 'boolean)
188 (defcustom org-export-remove-timestamps-from-toc t
189 "If nil, remove timestamps from the table of contents entries."
190 :group 'org-export-general
191 :type 'boolean)
193 (defcustom org-export-with-tags 'not-in-toc
194 "If nil, do not export tags, just remove them from headlines.
195 If this is the symbol `not-in-toc', tags will be removed from table of
196 contents entries, but still be shown in the headlines of the document.
198 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
199 :group 'org-export-general
200 :type '(choice
201 (const :tag "Off" nil)
202 (const :tag "Not in TOC" not-in-toc)
203 (const :tag "On" t)))
205 (defcustom org-export-with-drawers nil
206 "Non-nil means, export with drawers like the property drawer.
207 When t, all drawers are exported. This may also be a list of
208 drawer names to export."
209 :group 'org-export-general
210 :type '(choice
211 (const :tag "All drawers" t)
212 (const :tag "None" nil)
213 (repeat :tag "Selected drawers"
214 (string :tag "Drawer name"))))
216 (defgroup org-export-translation nil
217 "Options for translating special ascii sequences for the export backends."
218 :tag "Org Export Translation"
219 :group 'org-export)
221 (defcustom org-export-with-emphasize t
222 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
223 If the export target supports emphasizing text, the word will be
224 typeset in bold, italic, or underlined, respectively. Works only for
225 single words, but you can say: I *really* *mean* *this*.
226 Not all export backends support this.
228 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
229 :group 'org-export-translation
230 :type 'boolean)
232 (defcustom org-export-with-footnotes t
233 "If nil, export [1] as a footnote marker.
234 Lines starting with [1] will be formatted as footnotes.
236 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
237 :group 'org-export-translation
238 :type 'boolean)
240 (defcustom org-export-with-sub-superscripts t
241 "Non-nil means, interpret \"_\" and \"^\" for export.
242 When this option is turned on, you can use TeX-like syntax for sub- and
243 superscripts. Several characters after \"_\" or \"^\" will be
244 considered as a single item - so grouping with {} is normally not
245 needed. For example, the following things will be parsed as single
246 sub- or superscripts.
248 10^24 or 10^tau several digits will be considered 1 item.
249 10^-12 or 10^-tau a leading sign with digits or a word
250 x^2-y^3 will be read as x^2 - y^3, because items are
251 terminated by almost any nonword/nondigit char.
252 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
254 Still, ambiguity is possible - so when in doubt use {} to enclose the
255 sub/superscript. If you set this variable to the symbol `{}',
256 the braces are *required* in order to trigger interpretations as
257 sub/superscript. This can be helpful in documents that need \"_\"
258 frequently in plain text.
260 Not all export backends support this, but HTML does.
262 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
263 :group 'org-export-translation
264 :type '(choice
265 (const :tag "Always interpret" t)
266 (const :tag "Only with braces" {})
267 (const :tag "Never interpret" nil)))
269 (defcustom org-export-with-special-strings t
270 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
271 When this option is turned on, these strings will be exported as:
273 \\- : &shy;
274 -- : &ndash;
275 --- : &mdash;
277 Not all export backends support this, but HTML does.
279 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
280 :group 'org-export-translation
281 :type 'boolean)
283 (defcustom org-export-with-TeX-macros t
284 "Non-nil means, interpret simple TeX-like macros when exporting.
285 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
286 No only real TeX macros will work here, but the standard HTML entities
287 for math can be used as macro names as well. For a list of supported
288 names in HTML export, see the constant `org-html-entities'.
289 Not all export backends support this.
291 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
292 :group 'org-export-translation
293 :group 'org-export-latex
294 :type 'boolean)
296 (defcustom org-export-with-LaTeX-fragments nil
297 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
298 When set, the exporter will find LaTeX environments if the \\begin line is
299 the first non-white thing on a line. It will also find the math delimiters
300 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
301 display math.
303 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
304 :group 'org-export-translation
305 :group 'org-export-latex
306 :type 'boolean)
308 (defcustom org-export-with-fixed-width t
309 "Non-nil means, lines starting with \":\" will be in fixed width font.
310 This can be used to have pre-formatted text, fragments of code etc. For
311 example:
312 : ;; Some Lisp examples
313 : (while (defc cnt)
314 : (ding))
315 will be looking just like this in also HTML. See also the QUOTE keyword.
316 Not all export backends support this.
318 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
319 :group 'org-export-translation
320 :type 'boolean)
322 (defcustom org-match-sexp-depth 3
323 "Number of stacked braces for sub/superscript matching.
324 This has to be set before loading org.el to be effective."
325 :group 'org-export-translation
326 :type 'integer)
328 (defgroup org-export-tables nil
329 "Options for exporting tables in Org-mode."
330 :tag "Org Export Tables"
331 :group 'org-export)
333 (defcustom org-export-with-tables t
334 "If non-nil, lines starting with \"|\" define a table.
335 For example:
337 | Name | Address | Birthday |
338 |-------------+----------+-----------|
339 | Arthur Dent | England | 29.2.2100 |
341 Not all export backends support this.
343 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
344 :group 'org-export-tables
345 :type 'boolean)
347 (defcustom org-export-highlight-first-table-line t
348 "Non-nil means, highlight the first table line.
349 In HTML export, this means use <th> instead of <td>.
350 In tables created with table.el, this applies to the first table line.
351 In Org-mode tables, all lines before the first horizontal separator
352 line will be formatted with <th> tags."
353 :group 'org-export-tables
354 :type 'boolean)
356 (defcustom org-export-table-remove-special-lines t
357 "Remove special lines and marking characters in calculating tables.
358 This removes the special marking character column from tables that are set
359 up for spreadsheet calculations. It also removes the entire lines
360 marked with `!', `_', or `^'. The lines with `$' are kept, because
361 the values of constants may be useful to have."
362 :group 'org-export-tables
363 :type 'boolean)
365 (defcustom org-export-prefer-native-exporter-for-tables nil
366 "Non-nil means, always export tables created with table.el natively.
367 Natively means, use the HTML code generator in table.el.
368 When nil, Org-mode's own HTML generator is used when possible (i.e. if
369 the table does not use row- or column-spanning). This has the
370 advantage, that the automatic HTML conversions for math symbols and
371 sub/superscripts can be applied. Org-mode's HTML generator is also
372 much faster."
373 :group 'org-export-tables
374 :type 'boolean)
376 (defgroup org-export-ascii nil
377 "Options specific for ASCII export of Org-mode files."
378 :tag "Org Export ASCII"
379 :group 'org-export)
381 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
382 "Characters for underlining headings in ASCII export.
383 In the given sequence, these characters will be used for level 1, 2, ..."
384 :group 'org-export-ascii
385 :type '(repeat character))
387 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
388 "Bullet characters for headlines converted to lists in ASCII export.
389 The first character is used for the first lest level generated in this
390 way, and so on. If there are more levels than characters given here,
391 the list will be repeated.
392 Note that plain lists will keep the same bullets as the have in the
393 Org-mode file."
394 :group 'org-export-ascii
395 :type '(repeat character))
397 (defgroup org-export-xml nil
398 "Options specific for XML export of Org-mode files."
399 :tag "Org Export XML"
400 :group 'org-export)
402 (defgroup org-export-html nil
403 "Options specific for HTML export of Org-mode files."
404 :tag "Org Export HTML"
405 :group 'org-export)
407 (defcustom org-export-html-coding-system nil
408 "Coding system for HTML export, defaults to buffer-file-coding-system."
409 :group 'org-export-html
410 :type 'coding-system)
412 (defcustom org-export-html-extension "html"
413 "The extension for exported HTML files."
414 :group 'org-export-html
415 :type 'string)
417 (defcustom org-export-html-link-up ""
418 "Where should the \"UP\" link of exported HTML pages lead?"
419 :group 'org-export-html
420 :type '(string :tag "File or URL"))
422 (defcustom org-export-html-link-home ""
423 "Where should the \"HOME\" link of exported HTML pages lead?"
424 :group 'org-export-html
425 :type '(string :tag "File or URL"))
427 (defcustom org-export-html-style
428 "<style type=\"text/css\">
429 html {
430 font-family: Times, serif;
431 font-size: 12pt;
433 .title { text-align: center; }
434 .todo { color: red; }
435 .done { color: green; }
436 .timestamp { color: grey }
437 .timestamp-kwd { color: CadetBlue }
438 .tag { background-color:lightblue; font-weight:normal }
439 .target { background-color: lavender; }
440 pre {
441 border: 1pt solid #AEBDCC;
442 background-color: #F3F5F7;
443 padding: 5pt;
444 font-family: courier, monospace;
446 table { border-collapse: collapse; }
447 td, th {
448 vertical-align: top;
449 <!--border: 1pt solid #ADB9CC;-->
451 </style>"
452 "The default style specification for exported HTML files.
453 Since there are different ways of setting style information, this variable
454 needs to contain the full HTML structure to provide a style, including the
455 surrounding HTML tags. The style specifications should include definitions
456 for new classes todo, done, title, and deadline. For example, valid values
457 would be:
459 <style type=\"text/css\">
460 p { font-weight: normal; color: gray; }
461 h1 { color: black; }
462 .title { text-align: center; }
463 .todo, .deadline { color: red; }
464 .done { color: green; }
465 </style>
467 or, if you want to keep the style in a file,
469 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
471 As the value of this option simply gets inserted into the HTML <head> header,
472 you can \"misuse\" it to add arbitrary text to the header."
473 :group 'org-export-html
474 :type 'string)
477 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
478 "Format for typesetting the document title in HTML export."
479 :group 'org-export-html
480 :type 'string)
482 (defcustom org-export-html-toplevel-hlevel 2
483 "The <H> level for level 1 headings in HTML export."
484 :group 'org-export-html
485 :type 'string)
487 (defcustom org-export-html-link-org-files-as-html t
488 "Non-nil means, make file links to `file.org' point to `file.html'.
489 When org-mode is exporting an org-mode file to HTML, links to
490 non-html files are directly put into a href tag in HTML.
491 However, links to other Org-mode files (recognized by the
492 extension `.org.) should become links to the corresponding html
493 file, assuming that the linked org-mode file will also be
494 converted to HTML.
495 When nil, the links still point to the plain `.org' file."
496 :group 'org-export-html
497 :type 'boolean)
499 (defcustom org-export-html-inline-images 'maybe
500 "Non-nil means, inline images into exported HTML pages.
501 This is done using an <img> tag. When nil, an anchor with href is used to
502 link to the image. If this option is `maybe', then images in links with
503 an empty description will be inlined, while images with a description will
504 be linked only."
505 :group 'org-export-html
506 :type '(choice (const :tag "Never" nil)
507 (const :tag "Always" t)
508 (const :tag "When there is no description" maybe)))
510 ;; FIXME: rename
511 (defcustom org-export-html-expand t
512 "Non-nil means, for HTML export, treat @<...> as HTML tag.
513 When nil, these tags will be exported as plain text and therefore
514 not be interpreted by a browser.
516 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
517 :group 'org-export-html
518 :type 'boolean)
520 (defcustom org-export-html-table-tag
521 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
522 "The HTML tag that is used to start a table.
523 This must be a <table> tag, but you may change the options like
524 borders and spacing."
525 :group 'org-export-html
526 :type 'string)
528 (defcustom org-export-table-header-tags '("<th>" . "</th>")
529 "The opening tag for table header fields.
530 This is customizable so that alignment options can be specified."
531 :group 'org-export-tables
532 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
534 (defcustom org-export-table-data-tags '("<td>" . "</td>")
535 "The opening tag for table data fields.
536 This is customizable so that alignment options can be specified."
537 :group 'org-export-tables
538 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
540 (defcustom org-export-html-with-timestamp nil
541 "If non-nil, write `org-export-html-html-helper-timestamp'
542 into the exported HTML text. Otherwise, the buffer will just be saved
543 to a file."
544 :group 'org-export-html
545 :type 'boolean)
547 (defcustom org-export-html-html-helper-timestamp
548 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
549 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
550 :group 'org-export-html
551 :type 'string)
553 (defgroup org-export-icalendar nil
554 "Options specific for iCalendar export of Org-mode files."
555 :tag "Org Export iCalendar"
556 :group 'org-export)
558 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
559 "The file name for the iCalendar file covering all agenda files.
560 This file is created with the command \\[org-export-icalendar-all-agenda-files].
561 The file name should be absolute, the file will be overwritten without warning."
562 :group 'org-export-icalendar
563 :type 'file)
565 (defcustom org-icalendar-include-todo nil
566 "Non-nil means, export to iCalendar files should also cover TODO items."
567 :group 'org-export-icalendar
568 :type '(choice
569 (const :tag "None" nil)
570 (const :tag "Unfinished" t)
571 (const :tag "All" all)))
573 (defcustom org-icalendar-include-sexps t
574 "Non-nil means, export to iCalendar files should also cover sexp entries.
575 These are entries like in the diary, but directly in an Org-mode file."
576 :group 'org-export-icalendar
577 :type 'boolean)
579 (defcustom org-icalendar-include-body 100
580 "Amount of text below headline to be included in iCalendar export.
581 This is a number of characters that should maximally be included.
582 Properties, scheduling and clocking lines will always be removed.
583 The text will be inserted into the DESCRIPTION field."
584 :group 'org-export-icalendar
585 :type '(choice
586 (const :tag "Nothing" nil)
587 (const :tag "Everything" t)
588 (integer :tag "Max characters")))
590 (defcustom org-icalendar-combined-name "OrgMode"
591 "Calendar name for the combined iCalendar representing all agenda files."
592 :group 'org-export-icalendar
593 :type 'string)
595 ;;;; Exporting
597 ;;; Variables, constants, and parameter plists
599 (defconst org-level-max 20)
601 (defvar org-export-html-preamble nil
602 "Preamble, to be inserted just after <body>. Set by publishing functions.")
603 (defvar org-export-html-postamble nil
604 "Preamble, to be inserted just before </body>. Set by publishing functions.")
605 (defvar org-export-html-auto-preamble t
606 "Should default preamble be inserted? Set by publishing functions.")
607 (defvar org-export-html-auto-postamble t
608 "Should default postamble be inserted? Set by publishing functions.")
609 (defvar org-current-export-file nil) ; dynamically scoped parameter
610 (defvar org-current-export-dir nil) ; dynamically scoped parameter
612 (defconst org-export-plist-vars
613 '((:link-up . org-export-html-link-up)
614 (:link-home . org-export-html-link-home)
615 (:language . org-export-default-language)
616 (:customtime . org-display-custom-times)
617 (:headline-levels . org-export-headline-levels)
618 (:section-numbers . org-export-with-section-numbers)
619 (:table-of-contents . org-export-with-toc)
620 (:preserve-breaks . org-export-preserve-breaks)
621 (:archived-trees . org-export-with-archived-trees)
622 (:emphasize . org-export-with-emphasize)
623 (:sub-superscript . org-export-with-sub-superscripts)
624 (:special-strings . org-export-with-special-strings)
625 (:footnotes . org-export-with-footnotes)
626 (:drawers . org-export-with-drawers)
627 (:tags . org-export-with-tags)
628 (:TeX-macros . org-export-with-TeX-macros)
629 (:LaTeX-fragments . org-export-with-LaTeX-fragments)
630 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
631 (:fixed-width . org-export-with-fixed-width)
632 (:timestamps . org-export-with-timestamps)
633 (:author-info . org-export-author-info)
634 (:time-stamp-file . org-export-time-stamp-file)
635 (:tables . org-export-with-tables)
636 (:table-auto-headline . org-export-highlight-first-table-line)
637 (:style . org-export-html-style)
638 (:agenda-style . org-agenda-export-html-style)
639 (:convert-org-links . org-export-html-link-org-files-as-html)
640 (:inline-images . org-export-html-inline-images)
641 (:html-extension . org-export-html-extension)
642 (:html-table-tag . org-export-html-table-tag)
643 (:expand-quoted-html . org-export-html-expand)
644 (:timestamp . org-export-html-with-timestamp)
645 (:publishing-directory . org-export-publishing-directory)
646 (:preamble . org-export-html-preamble)
647 (:postamble . org-export-html-postamble)
648 (:auto-preamble . org-export-html-auto-preamble)
649 (:auto-postamble . org-export-html-auto-postamble)
650 (:author . user-full-name)
651 (:email . user-mail-address)))
653 (defun org-default-export-plist ()
654 "Return the property list with default settings for the export variables."
655 (let ((l org-export-plist-vars) rtn e)
656 (while (setq e (pop l))
657 (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
658 rtn))
660 (defvar org-export-inbuffer-options-extra nil
661 "List of additional in-buffer options that should be detected.
662 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
663 etc. Extensions can add to this list to get their options detected, and they
664 can then add a function to `org-export-options-filters' to process these
665 options.
666 Each element in this list must be a list, with the in-buffer keyword as car,
667 and a property (a symbol) as the next element. All occurences of the
668 keyword will be found, the values concatenated with a space character
669 in between, and the result stored in the export options property list.")
671 (defvar org-export-options-filters nil
672 "Functions to be called to finalize the export/publishing options.
673 All these options are stored in a property list, and each of the functions
674 in this hook gets a chance to modify this property list. Each function
675 must accept the property list as an argument, and must return the (possibly
676 modified) list.")
678 (defun org-infile-export-plist ()
679 "Return the property list with file-local settings for export."
680 (save-excursion
681 (save-restriction
682 (widen)
683 (goto-char 0)
684 (let ((re (org-make-options-regexp
685 (append
686 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
687 "LINK_UP" "LINK_HOME")
688 (mapcar 'car org-export-inbuffer-options-extra))))
689 p key val text options js-up js-main js-css js-opt a pr)
690 (while (re-search-forward re nil t)
691 (setq key (org-match-string-no-properties 1)
692 val (org-match-string-no-properties 2))
693 (cond
694 ((setq a (assoc key org-export-inbuffer-options-extra))
695 (setq pr (nth 1 a))
696 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
697 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
698 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
699 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
700 ((string-equal key "DATE") (setq p (plist-put p :date val)))
701 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
702 ((string-equal key "TEXT")
703 (setq text (if text (concat text "\n" val) val)))
704 ((string-equal key "OPTIONS")
705 (setq options (concat options " " val)))
706 ((string-equal key "LINK_UP")
707 (setq p (plist-put p :link-up val)))
708 ((string-equal key "LINK_HOME")
709 (setq p (plist-put p :link-home val)))))
710 (setq p (plist-put p :text text))
711 (when options
712 (let ((op '(("H" . :headline-levels)
713 ("num" . :section-numbers)
714 ("toc" . :table-of-contents)
715 ("\\n" . :preserve-breaks)
716 ("@" . :expand-quoted-html)
717 (":" . :fixed-width)
718 ("|" . :tables)
719 ("^" . :sub-superscript)
720 ("-" . :special-strings)
721 ("f" . :footnotes)
722 ("d" . :drawers)
723 ("tags" . :tags)
724 ("*" . :emphasize)
725 ("TeX" . :TeX-macros)
726 ("LaTeX" . :LaTeX-fragments)
727 ("skip" . :skip-before-1st-heading)
728 ("author" . :author-info)
729 ("timestamp" . :time-stamp-file)))
731 (while (setq o (pop op))
732 (if (string-match (concat (regexp-quote (car o))
733 ":\\([^ \t\n\r;,.]*\\)")
734 options)
735 (setq p (plist-put p (cdr o)
736 (car (read-from-string
737 (match-string 1 options)))))))))
738 p))))
740 (defun org-export-directory (type plist)
741 (let* ((val (plist-get plist :publishing-directory))
742 (dir (if (listp val)
743 (or (cdr (assoc type val)) ".")
744 val)))
745 dir))
747 ;;;###autoload
748 (defun org-export (&optional arg)
749 "Export dispatcher for Org-mode."
750 (interactive)
751 (let ((help "[t] insert the export option template
752 \[v] limit export to visible part of outline tree
754 \[a] export as ASCII
756 \[h] export as HTML
757 \[H] export as HTML to temporary buffer
758 \[R] export region as HTML
759 \[b] export as HTML and browse immediately
760 \[x] export as XOXO
762 \[l] export as LaTeX
763 \[L] export as LaTeX to temporary buffer
765 \[i] export current file as iCalendar file
766 \[I] export all agenda files as iCalendar files
767 \[c] export agenda files into combined iCalendar file
769 \[F] publish current file
770 \[P] publish current project
771 \[X] publish... (project will be prompted for)
772 \[A] publish all projects")
773 (cmds
774 '((?t . org-insert-export-options-template)
775 (?v . org-export-visible)
776 (?a . org-export-as-ascii)
777 (?h . org-export-as-html)
778 (?b . org-export-as-html-and-open)
779 (?H . org-export-as-html-to-buffer)
780 (?R . org-export-region-as-html)
781 (?x . org-export-as-xoxo)
782 (?l . org-export-as-latex)
783 (?L . org-export-as-latex-to-buffer)
784 (?i . org-export-icalendar-this-file)
785 (?I . org-export-icalendar-all-agenda-files)
786 (?c . org-export-icalendar-combine-agenda-files)
787 (?F . org-publish-current-file)
788 (?P . org-publish-current-project)
789 (?X . org-publish)
790 (?A . org-publish-all)))
791 r1 r2 ass)
792 (save-window-excursion
793 (delete-other-windows)
794 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
795 (princ help))
796 (message "Select command: ")
797 (setq r1 (read-char-exclusive)))
798 (setq r2 (if (< r1 27) (+ r1 96) r1))
799 (if (setq ass (assq r2 cmds))
800 (call-interactively (cdr ass))
801 (error "No command associated with key %c" r1))))
803 (defconst org-html-entities
804 '(("nbsp")
805 ("iexcl")
806 ("cent")
807 ("pound")
808 ("curren")
809 ("yen")
810 ("brvbar")
811 ("vert" . "&#124;")
812 ("sect")
813 ("uml")
814 ("copy")
815 ("ordf")
816 ("laquo")
817 ("not")
818 ("shy")
819 ("reg")
820 ("macr")
821 ("deg")
822 ("plusmn")
823 ("sup2")
824 ("sup3")
825 ("acute")
826 ("micro")
827 ("para")
828 ("middot")
829 ("odot"."o")
830 ("star"."*")
831 ("cedil")
832 ("sup1")
833 ("ordm")
834 ("raquo")
835 ("frac14")
836 ("frac12")
837 ("frac34")
838 ("iquest")
839 ("Agrave")
840 ("Aacute")
841 ("Acirc")
842 ("Atilde")
843 ("Auml")
844 ("Aring") ("AA"."&Aring;")
845 ("AElig")
846 ("Ccedil")
847 ("Egrave")
848 ("Eacute")
849 ("Ecirc")
850 ("Euml")
851 ("Igrave")
852 ("Iacute")
853 ("Icirc")
854 ("Iuml")
855 ("ETH")
856 ("Ntilde")
857 ("Ograve")
858 ("Oacute")
859 ("Ocirc")
860 ("Otilde")
861 ("Ouml")
862 ("times")
863 ("Oslash")
864 ("Ugrave")
865 ("Uacute")
866 ("Ucirc")
867 ("Uuml")
868 ("Yacute")
869 ("THORN")
870 ("szlig")
871 ("agrave")
872 ("aacute")
873 ("acirc")
874 ("atilde")
875 ("auml")
876 ("aring")
877 ("aelig")
878 ("ccedil")
879 ("egrave")
880 ("eacute")
881 ("ecirc")
882 ("euml")
883 ("igrave")
884 ("iacute")
885 ("icirc")
886 ("iuml")
887 ("eth")
888 ("ntilde")
889 ("ograve")
890 ("oacute")
891 ("ocirc")
892 ("otilde")
893 ("ouml")
894 ("divide")
895 ("oslash")
896 ("ugrave")
897 ("uacute")
898 ("ucirc")
899 ("uuml")
900 ("yacute")
901 ("thorn")
902 ("yuml")
903 ("fnof")
904 ("Alpha")
905 ("Beta")
906 ("Gamma")
907 ("Delta")
908 ("Epsilon")
909 ("Zeta")
910 ("Eta")
911 ("Theta")
912 ("Iota")
913 ("Kappa")
914 ("Lambda")
915 ("Mu")
916 ("Nu")
917 ("Xi")
918 ("Omicron")
919 ("Pi")
920 ("Rho")
921 ("Sigma")
922 ("Tau")
923 ("Upsilon")
924 ("Phi")
925 ("Chi")
926 ("Psi")
927 ("Omega")
928 ("alpha")
929 ("beta")
930 ("gamma")
931 ("delta")
932 ("epsilon")
933 ("varepsilon"."&epsilon;")
934 ("zeta")
935 ("eta")
936 ("theta")
937 ("iota")
938 ("kappa")
939 ("lambda")
940 ("mu")
941 ("nu")
942 ("xi")
943 ("omicron")
944 ("pi")
945 ("rho")
946 ("sigmaf") ("varsigma"."&sigmaf;")
947 ("sigma")
948 ("tau")
949 ("upsilon")
950 ("phi")
951 ("chi")
952 ("psi")
953 ("omega")
954 ("thetasym") ("vartheta"."&thetasym;")
955 ("upsih")
956 ("piv")
957 ("bull") ("bullet"."&bull;")
958 ("hellip") ("dots"."&hellip;")
959 ("prime")
960 ("Prime")
961 ("oline")
962 ("frasl")
963 ("weierp")
964 ("image")
965 ("real")
966 ("trade")
967 ("alefsym")
968 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
969 ("uarr") ("uparrow"."&uarr;")
970 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
971 ("darr")("downarrow"."&darr;")
972 ("harr") ("leftrightarrow"."&harr;")
973 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
974 ("lArr") ("Leftarrow"."&lArr;")
975 ("uArr") ("Uparrow"."&uArr;")
976 ("rArr") ("Rightarrow"."&rArr;")
977 ("dArr") ("Downarrow"."&dArr;")
978 ("hArr") ("Leftrightarrow"."&hArr;")
979 ("forall")
980 ("part") ("partial"."&part;")
981 ("exist") ("exists"."&exist;")
982 ("empty") ("emptyset"."&empty;")
983 ("nabla")
984 ("isin") ("in"."&isin;")
985 ("notin")
986 ("ni")
987 ("prod")
988 ("sum")
989 ("minus")
990 ("lowast") ("ast"."&lowast;")
991 ("radic")
992 ("prop") ("proptp"."&prop;")
993 ("infin") ("infty"."&infin;")
994 ("ang") ("angle"."&ang;")
995 ("and") ("wedge"."&and;")
996 ("or") ("vee"."&or;")
997 ("cap")
998 ("cup")
999 ("int")
1000 ("there4")
1001 ("sim")
1002 ("cong") ("simeq"."&cong;")
1003 ("asymp")("approx"."&asymp;")
1004 ("ne") ("neq"."&ne;")
1005 ("equiv")
1006 ("le")
1007 ("ge")
1008 ("sub") ("subset"."&sub;")
1009 ("sup") ("supset"."&sup;")
1010 ("nsub")
1011 ("sube")
1012 ("supe")
1013 ("oplus")
1014 ("otimes")
1015 ("perp")
1016 ("sdot") ("cdot"."&sdot;")
1017 ("lceil")
1018 ("rceil")
1019 ("lfloor")
1020 ("rfloor")
1021 ("lang")
1022 ("rang")
1023 ("loz") ("Diamond"."&loz;")
1024 ("spades") ("spadesuit"."&spades;")
1025 ("clubs") ("clubsuit"."&clubs;")
1026 ("hearts") ("diamondsuit"."&hearts;")
1027 ("diams") ("diamondsuit"."&diams;")
1028 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1029 ("quot")
1030 ("amp")
1031 ("lt")
1032 ("gt")
1033 ("OElig")
1034 ("oelig")
1035 ("Scaron")
1036 ("scaron")
1037 ("Yuml")
1038 ("circ")
1039 ("tilde")
1040 ("ensp")
1041 ("emsp")
1042 ("thinsp")
1043 ("zwnj")
1044 ("zwj")
1045 ("lrm")
1046 ("rlm")
1047 ("ndash")
1048 ("mdash")
1049 ("lsquo")
1050 ("rsquo")
1051 ("sbquo")
1052 ("ldquo")
1053 ("rdquo")
1054 ("bdquo")
1055 ("dagger")
1056 ("Dagger")
1057 ("permil")
1058 ("lsaquo")
1059 ("rsaquo")
1060 ("euro")
1062 ("arccos"."arccos")
1063 ("arcsin"."arcsin")
1064 ("arctan"."arctan")
1065 ("arg"."arg")
1066 ("cos"."cos")
1067 ("cosh"."cosh")
1068 ("cot"."cot")
1069 ("coth"."coth")
1070 ("csc"."csc")
1071 ("deg"."deg")
1072 ("det"."det")
1073 ("dim"."dim")
1074 ("exp"."exp")
1075 ("gcd"."gcd")
1076 ("hom"."hom")
1077 ("inf"."inf")
1078 ("ker"."ker")
1079 ("lg"."lg")
1080 ("lim"."lim")
1081 ("liminf"."liminf")
1082 ("limsup"."limsup")
1083 ("ln"."ln")
1084 ("log"."log")
1085 ("max"."max")
1086 ("min"."min")
1087 ("Pr"."Pr")
1088 ("sec"."sec")
1089 ("sin"."sin")
1090 ("sinh"."sinh")
1091 ("sup"."sup")
1092 ("tan"."tan")
1093 ("tanh"."tanh")
1095 "Entities for TeX->HTML translation.
1096 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1097 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1098 In that case, \"\\ent\" will be translated to \"&other;\".
1099 The list contains HTML entities for Latin-1, Greek and other symbols.
1100 It is supplemented by a number of commonly used TeX macros with appropriate
1101 translations. There is currently no way for users to extend this.")
1103 ;;; General functions for all backends
1105 (defun org-cleaned-string-for-export (string &rest parameters)
1106 "Cleanup a buffer STRING so that links can be created safely."
1107 (interactive)
1108 (let* ((re-radio (and org-target-link-regexp
1109 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
1110 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1111 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1112 (re-archive (concat ":" org-archive-tag ":"))
1113 (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
1114 (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1115 (htmlp (plist-get parameters :for-html))
1116 (asciip (plist-get parameters :for-ascii))
1117 (latexp (plist-get parameters :for-LaTeX))
1118 (commentsp (plist-get parameters :comments))
1119 (archived-trees (plist-get parameters :archived-trees))
1120 (inhibit-read-only t)
1121 (drawers org-drawers)
1122 (exp-drawers (plist-get parameters :drawers))
1123 (outline-regexp "\\*+ ")
1124 a b xx
1125 rtn p)
1126 (with-current-buffer (get-buffer-create " org-mode-tmp")
1127 (erase-buffer)
1128 (insert string)
1129 ;; Remove license-to-kill stuff
1130 (while (setq p (text-property-any (point-min) (point-max)
1131 :org-license-to-kill t))
1132 (delete-region p (next-single-property-change p :org-license-to-kill)))
1134 (let ((org-inhibit-startup t)) (org-mode))
1135 (untabify (point-min) (point-max))
1137 ;; Get rid of drawers
1138 (unless (eq t exp-drawers)
1139 (goto-char (point-min))
1140 (let ((re (concat "^[ \t]*:\\("
1141 (mapconcat
1142 'identity
1143 (org-delete-all exp-drawers
1144 (copy-sequence drawers))
1145 "\\|")
1146 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1147 (while (re-search-forward re nil t)
1148 (replace-match ""))))
1150 ;; Get the correct stuff before the first headline
1151 (when (plist-get parameters :skip-before-1st-heading)
1152 (goto-char (point-min))
1153 (when (re-search-forward "^\\*+[ \t]" nil t)
1154 (delete-region (point-min) (match-beginning 0))
1155 (goto-char (point-min))
1156 (insert "\n")))
1157 (when (plist-get parameters :add-text)
1158 (goto-char (point-min))
1159 (insert (plist-get parameters :add-text) "\n"))
1161 ;; Get rid of archived trees
1162 (when (not (eq archived-trees t))
1163 (goto-char (point-min))
1164 (while (re-search-forward re-archive nil t)
1165 (if (not (org-on-heading-p t))
1166 (org-end-of-subtree t)
1167 (beginning-of-line 1)
1168 (setq a (if archived-trees
1169 (1+ (point-at-eol)) (point))
1170 b (org-end-of-subtree t))
1171 (if (> b a) (delete-region a b)))))
1173 ;; Find targets in comments and move them out of comments,
1174 ;; but mark them as targets that should be invisible
1175 (goto-char (point-min))
1176 (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t)
1177 (replace-match "\\1(INVISIBLE)"))
1179 ;; Protect backend specific stuff, throw away the others.
1180 (let ((formatters
1181 `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
1182 (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
1183 (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1184 fmt)
1185 (goto-char (point-min))
1186 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1187 (goto-char (match-end 0))
1188 (while (not (looking-at "#\\+END_EXAMPLE"))
1189 (insert ": ")
1190 (beginning-of-line 2)))
1191 (goto-char (point-min))
1192 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1193 (add-text-properties (match-beginning 0) (match-end 0)
1194 '(org-protected t)))
1195 (while formatters
1196 (setq fmt (pop formatters))
1197 (when (car fmt)
1198 (goto-char (point-min))
1199 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1200 ":[ \t]*\\(.*\\)") nil t)
1201 (replace-match "\\1" t)
1202 (add-text-properties
1203 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1204 '(org-protected t))))
1205 (goto-char (point-min))
1206 (while (re-search-forward
1207 (concat "^#\\+"
1208 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1209 (cadddr fmt) "\\>.*\n?") nil t)
1210 (if (car fmt)
1211 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1212 '(org-protected t))
1213 (delete-region (match-beginning 0) (match-end 0))))))
1215 ;; Protect quoted subtrees
1216 (goto-char (point-min))
1217 (while (re-search-forward re-quote nil t)
1218 (goto-char (match-beginning 0))
1219 (end-of-line 1)
1220 (add-text-properties (point) (org-end-of-subtree t)
1221 '(org-protected t)))
1223 ;; Protect verbatim elements
1224 (goto-char (point-min))
1225 (while (re-search-forward org-verbatim-re nil t)
1226 (add-text-properties (match-beginning 4) (match-end 4)
1227 '(org-protected t))
1228 (goto-char (1+ (match-end 4))))
1230 ;; Remove subtrees that are commented
1231 (goto-char (point-min))
1232 (while (re-search-forward re-commented nil t)
1233 (goto-char (match-beginning 0))
1234 (delete-region (point) (org-end-of-subtree t)))
1236 ;; Remove special table lines
1237 (when org-export-table-remove-special-lines
1238 (goto-char (point-min))
1239 (while (re-search-forward "^[ \t]*|" nil t)
1240 (beginning-of-line 1)
1241 (if (or (looking-at "[ \t]*| *[!_^] *|")
1242 (and (looking-at ".*?| *<[0-9]+> *|")
1243 (not (looking-at ".*?| *[^ <|]"))))
1244 (delete-region (max (point-min) (1- (point-at-bol)))
1245 (point-at-eol))
1246 (end-of-line 1))))
1248 ;; Specific LaTeX stuff
1249 (when latexp
1250 (require 'org-export-latex nil)
1251 (org-export-latex-cleaned-string))
1253 (when asciip
1254 (org-export-ascii-clean-string))
1256 ;; Specific HTML stuff
1257 (when htmlp
1258 ;; Convert LaTeX fragments to images
1259 (when (plist-get parameters :LaTeX-fragments)
1260 (org-format-latex
1261 (concat "ltxpng/" (file-name-sans-extension
1262 (file-name-nondirectory
1263 org-current-export-file)))
1264 org-current-export-dir nil "Creating LaTeX image %s"))
1265 (message "Exporting..."))
1267 ;; Remove or replace comments
1268 (goto-char (point-min))
1269 (while (re-search-forward "^#\\(.*\n?\\)" nil t)
1270 (if commentsp
1271 (progn (add-text-properties
1272 (match-beginning 0) (match-end 0) '(org-protected t))
1273 (replace-match (format commentsp (match-string 1)) t t))
1274 (replace-match "")))
1276 ;; Find matches for radio targets and turn them into internal links
1277 (goto-char (point-min))
1278 (when re-radio
1279 (while (re-search-forward re-radio nil t)
1280 (org-if-unprotected
1281 (replace-match "\\1[[\\2]]"))))
1283 ;; Find all links that contain a newline and put them into a single line
1284 (goto-char (point-min))
1285 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1286 (org-if-unprotected
1287 (replace-match "\\1 \\3")
1288 (goto-char (match-beginning 0))))
1291 ;; Normalize links: Convert angle and plain links into bracket links
1292 ;; Expand link abbreviations
1293 (goto-char (point-min))
1294 (while (re-search-forward re-plain-link nil t)
1295 (goto-char (1- (match-end 0)))
1296 (org-if-unprotected
1297 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1298 ":" (match-string 3) "]]")))
1299 ;; added 'org-link face to links
1300 (put-text-property 0 (length s) 'face 'org-link s)
1301 (replace-match s t t))))
1302 (goto-char (point-min))
1303 (while (re-search-forward re-angle-link nil t)
1304 (goto-char (1- (match-end 0)))
1305 (org-if-unprotected
1306 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1307 ":" (match-string 3) "]]")))
1308 (put-text-property 0 (length s) 'face 'org-link s)
1309 (replace-match s t t))))
1310 (goto-char (point-min))
1311 (while (re-search-forward org-bracket-link-regexp nil t)
1312 (org-if-unprotected
1313 (let* ((s (concat "[[" (setq xx (save-match-data
1314 (org-link-expand-abbrev (match-string 1))))
1316 (if (match-end 3)
1317 (match-string 2)
1318 (concat "[" xx "]"))
1319 "]")))
1320 (put-text-property 0 (length s) 'face 'org-link s)
1321 (replace-match s t t))))
1323 ;; Find multiline emphasis and put them into single line
1324 (when (plist-get parameters :emph-multiline)
1325 (goto-char (point-min))
1326 (while (re-search-forward org-emph-re nil t)
1327 (if (not (= (char-after (match-beginning 3))
1328 (char-after (match-beginning 4))))
1329 (org-if-unprotected
1330 (subst-char-in-region (match-beginning 0) (match-end 0)
1331 ?\n ?\ t)
1332 (goto-char (1- (match-end 0))))
1333 (goto-char (1+ (match-beginning 0))))))
1335 (setq rtn (buffer-string)))
1336 (kill-buffer " org-mode-tmp")
1337 rtn))
1339 (defun org-export-grab-title-from-buffer ()
1340 "Get a title for the current document, from looking at the buffer."
1341 (let ((inhibit-read-only t))
1342 (save-excursion
1343 (goto-char (point-min))
1344 (let ((end (save-excursion (outline-next-heading) (point))))
1345 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1346 ;; Mark the line so that it will not be exported as normal text.
1347 (org-unmodified
1348 (add-text-properties (match-beginning 0) (match-end 0)
1349 (list :org-license-to-kill t)))
1350 ;; Return the title string
1351 (org-trim (match-string 0)))))))
1353 (defun org-export-get-title-from-subtree ()
1354 "Return subtree title and exclude it from export."
1355 (let (title (m (mark)))
1356 (save-excursion
1357 (goto-char (region-beginning))
1358 (when (and (org-at-heading-p)
1359 (>= (org-end-of-subtree t t) (region-end)))
1360 ;; This is a subtree, we take the title from the first heading
1361 (goto-char (region-beginning))
1362 (looking-at org-todo-line-regexp)
1363 (setq title (match-string 3))
1364 (org-unmodified
1365 (add-text-properties (point) (1+ (point-at-eol))
1366 (list :org-license-to-kill t)))))
1367 title))
1369 (defun org-solidify-link-text (s &optional alist)
1370 "Take link text and make a safe target out of it."
1371 (save-match-data
1372 (let* ((rtn
1373 (mapconcat
1374 'identity
1375 (org-split-string s "[ \t\r\n]+") "--"))
1376 (a (assoc rtn alist)))
1377 (or (cdr a) rtn))))
1379 (defun org-get-min-level (lines)
1380 "Get the minimum level in LINES."
1381 (let ((re "^\\(\\*+\\) ") l min)
1382 (catch 'exit
1383 (while (setq l (pop lines))
1384 (if (string-match re l)
1385 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1386 1)))
1388 ;; Variable holding the vector with section numbers
1389 (defvar org-section-numbers (make-vector org-level-max 0))
1391 (defun org-init-section-numbers ()
1392 "Initialize the vector for the section numbers."
1393 (let* ((level -1)
1394 (numbers (nreverse (org-split-string "" "\\.")))
1395 (depth (1- (length org-section-numbers)))
1396 (i depth) number-string)
1397 (while (>= i 0)
1398 (if (> i level)
1399 (aset org-section-numbers i 0)
1400 (setq number-string (or (car numbers) "0"))
1401 (if (string-match "\\`[A-Z]\\'" number-string)
1402 (aset org-section-numbers i
1403 (- (string-to-char number-string) ?A -1))
1404 (aset org-section-numbers i (string-to-number number-string)))
1405 (pop numbers))
1406 (setq i (1- i)))))
1408 (defun org-section-number (&optional level)
1409 "Return a string with the current section number.
1410 When LEVEL is non-nil, increase section numbers on that level."
1411 (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
1412 (when level
1413 (when (> level -1)
1414 (aset org-section-numbers
1415 level (1+ (aref org-section-numbers level))))
1416 (setq idx (1+ level))
1417 (while (<= idx depth)
1418 (if (not (= idx 1))
1419 (aset org-section-numbers idx 0))
1420 (setq idx (1+ idx))))
1421 (setq idx 0)
1422 (while (<= idx depth)
1423 (setq n (aref org-section-numbers idx))
1424 (setq string (concat string (if (not (string= string "")) "." "")
1425 (int-to-string n)))
1426 (setq idx (1+ idx)))
1427 (save-match-data
1428 (if (string-match "\\`\\([@0]\\.\\)+" string)
1429 (setq string (replace-match "" t nil string)))
1430 (if (string-match "\\(\\.0\\)+\\'" string)
1431 (setq string (replace-match "" t nil string))))
1432 string))
1434 ;;; ASCII export
1436 (defvar org-last-level nil) ; dynamically scoped variable
1437 (defvar org-min-level nil) ; dynamically scoped variable
1438 (defvar org-levels-open nil) ; dynamically scoped parameter
1439 (defvar org-ascii-current-indentation nil) ; For communication
1441 ;;;###autoload
1442 (defun org-export-as-ascii (arg)
1443 "Export the outline as a pretty ASCII file.
1444 If there is an active region, export only the region.
1445 The prefix ARG specifies how many levels of the outline should become
1446 underlined headlines. The default is 3."
1447 (interactive "P")
1448 (setq-default org-todo-line-regexp org-todo-line-regexp)
1449 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1450 (org-infile-export-plist)))
1451 (region-p (org-region-active-p))
1452 (subtree-p
1453 (when region-p
1454 (save-excursion
1455 (goto-char (region-beginning))
1456 (and (org-at-heading-p)
1457 (>= (org-end-of-subtree t t) (region-end))))))
1458 (custom-times org-display-custom-times)
1459 (org-ascii-current-indentation '(0 . 0))
1460 (level 0) line txt
1461 (umax nil)
1462 (umax-toc nil)
1463 (case-fold-search nil)
1464 (filename (concat (file-name-as-directory
1465 (org-export-directory :ascii opt-plist))
1466 (file-name-sans-extension
1467 (or (and subtree-p
1468 (org-entry-get (region-beginning)
1469 "EXPORT_FILE_NAME" t))
1470 (file-name-nondirectory buffer-file-name)))
1471 ".txt"))
1472 (filename (if (equal (file-truename filename)
1473 (file-truename buffer-file-name))
1474 (concat filename ".txt")
1475 filename))
1476 (buffer (find-file-noselect filename))
1477 (org-levels-open (make-vector org-level-max nil))
1478 (odd org-odd-levels-only)
1479 (date (plist-get opt-plist :date))
1480 (author (plist-get opt-plist :author))
1481 (title (or (and subtree-p (org-export-get-title-from-subtree))
1482 (plist-get opt-plist :title)
1483 (and (not
1484 (plist-get opt-plist :skip-before-1st-heading))
1485 (org-export-grab-title-from-buffer))
1486 (file-name-sans-extension
1487 (file-name-nondirectory buffer-file-name))))
1488 (email (plist-get opt-plist :email))
1489 (language (plist-get opt-plist :language))
1490 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1491 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1492 (todo nil)
1493 (lang-words nil)
1494 (region
1495 (buffer-substring
1496 (if (org-region-active-p) (region-beginning) (point-min))
1497 (if (org-region-active-p) (region-end) (point-max))))
1498 (lines (org-split-string
1499 (org-cleaned-string-for-export
1500 region
1501 :for-ascii t
1502 :skip-before-1st-heading
1503 (plist-get opt-plist :skip-before-1st-heading)
1504 :drawers (plist-get opt-plist :drawers)
1505 :verbatim-multiline t
1506 :archived-trees
1507 (plist-get opt-plist :archived-trees)
1508 :add-text (plist-get opt-plist :text))
1509 "\n"))
1510 thetoc have-headings first-heading-pos
1511 table-open table-buffer)
1513 (let ((inhibit-read-only t))
1514 (org-unmodified
1515 (remove-text-properties (point-min) (point-max)
1516 '(:org-license-to-kill t))))
1518 (setq org-min-level (org-get-min-level lines))
1519 (setq org-last-level org-min-level)
1520 (org-init-section-numbers)
1522 (find-file-noselect filename)
1524 (setq lang-words (or (assoc language org-export-language-setup)
1525 (assoc "en" org-export-language-setup)))
1526 (switch-to-buffer-other-window buffer)
1527 (erase-buffer)
1528 (fundamental-mode)
1529 ;; create local variables for all options, to make sure all called
1530 ;; functions get the correct information
1531 (mapc (lambda (x)
1532 (set (make-local-variable (cdr x))
1533 (plist-get opt-plist (car x))))
1534 org-export-plist-vars)
1535 (org-set-local 'org-odd-levels-only odd)
1536 (setq umax (if arg (prefix-numeric-value arg)
1537 org-export-headline-levels))
1538 (setq umax-toc (if (integerp org-export-with-toc)
1539 (min org-export-with-toc umax)
1540 umax))
1542 ;; File header
1543 (if title (org-insert-centered title ?=))
1544 (insert "\n")
1545 (if (and (or author email)
1546 org-export-author-info)
1547 (insert (concat (nth 1 lang-words) ": " (or author "")
1548 (if email (concat " <" email ">") "")
1549 "\n")))
1551 (cond
1552 ((and date (string-match "%" date))
1553 (setq date (format-time-string date)))
1554 (date)
1555 (t (setq date (format-time-string "%Y/%m/%d %X"))))
1557 (if (and date org-export-time-stamp-file)
1558 (insert (concat (nth 2 lang-words) ": " date"\n")))
1560 (insert "\n\n")
1562 (if org-export-with-toc
1563 (progn
1564 (push (concat (nth 3 lang-words) "\n") thetoc)
1565 (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
1566 (mapc '(lambda (line)
1567 (if (string-match org-todo-line-regexp
1568 line)
1569 ;; This is a headline
1570 (progn
1571 (setq have-headings t)
1572 (setq level (- (match-end 1) (match-beginning 1))
1573 level (org-tr-level level)
1574 txt (match-string 3 line)
1575 todo
1576 (or (and org-export-mark-todo-in-toc
1577 (match-beginning 2)
1578 (not (member (match-string 2 line)
1579 org-done-keywords)))
1580 ; TODO, not DONE
1581 (and org-export-mark-todo-in-toc
1582 (= level umax-toc)
1583 (org-search-todo-below
1584 line lines level))))
1585 (setq txt (org-html-expand-for-ascii txt))
1587 (while (string-match org-bracket-link-regexp txt)
1588 (setq txt
1589 (replace-match
1590 (match-string (if (match-end 2) 3 1) txt)
1591 t t txt)))
1593 (if (and (memq org-export-with-tags '(not-in-toc nil))
1594 (string-match
1595 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1596 txt))
1597 (setq txt (replace-match "" t t txt)))
1598 (if (string-match quote-re0 txt)
1599 (setq txt (replace-match "" t t txt)))
1601 (if org-export-with-section-numbers
1602 (setq txt (concat (org-section-number level)
1603 " " txt)))
1604 (if (<= level umax-toc)
1605 (progn
1606 (push
1607 (concat
1608 (make-string
1609 (* (max 0 (- level org-min-level)) 4) ?\ )
1610 (format (if todo "%s (*)\n" "%s\n") txt))
1611 thetoc)
1612 (setq org-last-level level))
1613 ))))
1614 lines)
1615 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1617 (org-init-section-numbers)
1618 (while (setq line (pop lines))
1619 ;; Remove the quoted HTML tags.
1620 (setq line (org-html-expand-for-ascii line))
1621 ;; Remove targets
1622 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
1623 (setq line (replace-match "" t t line)))
1624 ;; Replace internal links
1625 (while (string-match org-bracket-link-regexp line)
1626 (setq line (replace-match
1627 (if (match-end 3) "[\\3]" "[\\1]")
1628 t nil line)))
1629 (when custom-times
1630 (setq line (org-translate-time line)))
1631 (cond
1632 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1633 ;; a Headline
1634 (setq first-heading-pos (or first-heading-pos (point)))
1635 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
1636 txt (match-string 2 line))
1637 (org-ascii-level-start level txt umax lines))
1639 ((and org-export-with-tables
1640 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1641 (if (not table-open)
1642 ;; New table starts
1643 (setq table-open t table-buffer nil))
1644 ;; Accumulate lines
1645 (setq table-buffer (cons line table-buffer))
1646 (when (or (not lines)
1647 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1648 (car lines))))
1649 (setq table-open nil
1650 table-buffer (nreverse table-buffer))
1651 (insert (mapconcat
1652 (lambda (x)
1653 (org-fix-indentation x org-ascii-current-indentation))
1654 (org-format-table-ascii table-buffer)
1655 "\n") "\n")))
1657 (setq line (org-fix-indentation line org-ascii-current-indentation))
1658 (if (and org-export-with-fixed-width
1659 (string-match "^\\([ \t]*\\)\\(:\\)" line))
1660 (setq line (replace-match "\\1" nil nil line)))
1661 (insert line "\n"))))
1663 (normal-mode)
1665 ;; insert the table of contents
1666 (when thetoc
1667 (goto-char (point-min))
1668 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
1669 (progn
1670 (goto-char (match-beginning 0))
1671 (replace-match ""))
1672 (goto-char first-heading-pos))
1673 (mapc 'insert thetoc)
1674 (or (looking-at "[ \t]*\n[ \t]*\n")
1675 (insert "\n\n")))
1677 ;; Convert whitespace place holders
1678 (goto-char (point-min))
1679 (let (beg end)
1680 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1681 (setq end (next-single-property-change beg 'org-whitespace))
1682 (goto-char beg)
1683 (delete-region beg end)
1684 (insert (make-string (- end beg) ?\ ))))
1686 (save-buffer)
1687 ;; remove display and invisible chars
1688 (let (beg end)
1689 (goto-char (point-min))
1690 (while (setq beg (next-single-property-change (point) 'display))
1691 (setq end (next-single-property-change beg 'display))
1692 (delete-region beg end)
1693 (goto-char beg)
1694 (insert "=>"))
1695 (goto-char (point-min))
1696 (while (setq beg (next-single-property-change (point) 'org-cwidth))
1697 (setq end (next-single-property-change beg 'org-cwidth))
1698 (delete-region beg end)
1699 (goto-char beg)))
1700 (goto-char (point-min))))
1702 (defun org-export-ascii-clean-string ()
1703 "Do extra work for ASCII export"
1704 (goto-char (point-min))
1705 (while (re-search-forward org-verbatim-re nil t)
1706 (goto-char (match-end 2))
1707 (backward-delete-char 1) (insert "'")
1708 (goto-char (match-beginning 2))
1709 (delete-char 1) (insert "`")
1710 (goto-char (match-end 2))))
1712 (defun org-search-todo-below (line lines level)
1713 "Search the subtree below LINE for any TODO entries."
1714 (let ((rest (cdr (memq line lines)))
1715 (re org-todo-line-regexp)
1716 line lv todo)
1717 (catch 'exit
1718 (while (setq line (pop rest))
1719 (if (string-match re line)
1720 (progn
1721 (setq lv (- (match-end 1) (match-beginning 1))
1722 todo (and (match-beginning 2)
1723 (not (member (match-string 2 line)
1724 org-done-keywords))))
1725 ; TODO, not DONE
1726 (if (<= lv level) (throw 'exit nil))
1727 (if todo (throw 'exit t))))))))
1729 (defun org-html-expand-for-ascii (line)
1730 "Handle quoted HTML for ASCII export."
1731 (if org-export-html-expand
1732 (while (string-match "@<[^<>\n]*>" line)
1733 ;; We just remove the tags for now.
1734 (setq line (replace-match "" nil nil line))))
1735 line)
1737 (defun org-insert-centered (s &optional underline)
1738 "Insert the string S centered and underline it with character UNDERLINE."
1739 (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
1740 (insert (make-string ind ?\ ) s "\n")
1741 (if underline
1742 (insert (make-string ind ?\ )
1743 (make-string (string-width s) underline)
1744 "\n"))))
1746 (defun org-ascii-level-start (level title umax &optional lines)
1747 "Insert a new level in ASCII export."
1748 (let (char (n (- level umax 1)) (ind 0))
1749 (if (> level umax)
1750 (progn
1751 (insert (make-string (* 2 n) ?\ )
1752 (char-to-string (nth (% n (length org-export-ascii-bullets))
1753 org-export-ascii-bullets))
1754 " " title "\n")
1755 ;; find the indentation of the next non-empty line
1756 (catch 'stop
1757 (while lines
1758 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
1759 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
1760 (throw 'stop (setq ind (org-get-indentation (car lines)))))
1761 (pop lines)))
1762 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
1763 (if (or (not (equal (char-before) ?\n))
1764 (not (equal (char-before (1- (point))) ?\n)))
1765 (insert "\n"))
1766 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
1767 (unless org-export-with-tags
1768 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
1769 (setq title (replace-match "" t t title))))
1770 (if org-export-with-section-numbers
1771 (setq title (concat (org-section-number level) " " title)))
1772 (insert title "\n" (make-string (string-width title) char) "\n")
1773 (setq org-ascii-current-indentation '(0 . 0)))))
1775 ;;;###autoload
1776 (defun org-export-visible (type arg)
1777 "Create a copy of the visible part of the current buffer, and export it.
1778 The copy is created in a temporary buffer and removed after use.
1779 TYPE is the final key (as a string) that also select the export command in
1780 the `C-c C-e' export dispatcher.
1781 As a special case, if the you type SPC at the prompt, the temporary
1782 org-mode file will not be removed but presented to you so that you can
1783 continue to use it. The prefix arg ARG is passed through to the exporting
1784 command."
1785 (interactive
1786 (list (progn
1787 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
1788 (read-char-exclusive))
1789 current-prefix-arg))
1790 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
1791 (error "Invalid export key"))
1792 (let* ((binding (cdr (assoc type
1793 '((?a . org-export-as-ascii)
1794 (?\C-a . org-export-as-ascii)
1795 (?b . org-export-as-html-and-open)
1796 (?\C-b . org-export-as-html-and-open)
1797 (?h . org-export-as-html)
1798 (?H . org-export-as-html-to-buffer)
1799 (?R . org-export-region-as-html)
1800 (?x . org-export-as-xoxo)))))
1801 (keepp (equal type ?\ ))
1802 (file buffer-file-name)
1803 (buffer (get-buffer-create "*Org Export Visible*"))
1804 s e)
1805 ;; Need to hack the drawers here.
1806 (save-excursion
1807 (goto-char (point-min))
1808 (while (re-search-forward org-drawer-regexp nil t)
1809 (goto-char (match-beginning 1))
1810 (or (org-invisible-p) (org-flag-drawer nil))))
1811 (with-current-buffer buffer (erase-buffer))
1812 (save-excursion
1813 (setq s (goto-char (point-min)))
1814 (while (not (= (point) (point-max)))
1815 (goto-char (org-find-invisible))
1816 (append-to-buffer buffer s (point))
1817 (setq s (goto-char (org-find-visible))))
1818 (org-cycle-hide-drawers 'all)
1819 (goto-char (point-min))
1820 (unless keepp
1821 ;; Copy all comment lines to the end, to make sure #+ settings are
1822 ;; still available for the second export step. Kind of a hack, but
1823 ;; does do the trick.
1824 (if (looking-at "#[^\r\n]*")
1825 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
1826 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
1827 (append-to-buffer buffer (1+ (match-beginning 0))
1828 (min (point-max) (1+ (match-end 0))))))
1829 (set-buffer buffer)
1830 (let ((buffer-file-name file)
1831 (org-inhibit-startup t))
1832 (org-mode)
1833 (show-all)
1834 (unless keepp (funcall binding arg))))
1835 (if (not keepp)
1836 (kill-buffer buffer)
1837 (switch-to-buffer-other-window buffer)
1838 (goto-char (point-min)))))
1840 (defun org-find-visible ()
1841 (let ((s (point)))
1842 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
1843 (get-char-property s 'invisible)))
1845 (defun org-find-invisible ()
1846 (let ((s (point)))
1847 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
1848 (not (get-char-property s 'invisible))))
1851 ;;; HTML export
1853 (defun org-get-current-options ()
1854 "Return a string with current options as keyword options.
1855 Does include HTML export options as well as TODO and CATEGORY stuff."
1856 (format
1857 "#+TITLE: %s
1858 #+AUTHOR: %s
1859 #+EMAIL: %s
1860 #+DATE: %s
1861 #+LANGUAGE: %s
1862 #+TEXT: Some descriptive text to be emitted. Several lines OK.
1863 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s tags:%s
1864 #+CATEGORY: %s
1865 #+SEQ_TODO: %s
1866 #+TYP_TODO: %s
1867 #+PRIORITIES: %c %c %c
1868 #+DRAWERS: %s
1869 #+STARTUP: %s %s %s %s %s
1870 #+TAGS: %s
1871 #+ARCHIVE: %s
1872 #+LINK: %s
1874 (buffer-name) (user-full-name) user-mail-address
1875 (format-time-string (car org-time-stamp-formats))
1876 org-export-default-language
1877 org-export-headline-levels
1878 org-export-with-section-numbers
1879 org-export-with-toc
1880 org-export-preserve-breaks
1881 org-export-html-expand
1882 org-export-with-fixed-width
1883 org-export-with-tables
1884 org-export-with-sub-superscripts
1885 org-export-with-special-strings
1886 org-export-with-footnotes
1887 org-export-with-emphasize
1888 org-export-with-TeX-macros
1889 org-export-with-LaTeX-fragments
1890 org-export-skip-text-before-1st-heading
1891 org-export-with-drawers
1892 org-export-with-tags
1893 (file-name-nondirectory buffer-file-name)
1894 "TODO FEEDBACK VERIFY DONE"
1895 "Me Jason Marie DONE"
1896 org-highest-priority org-lowest-priority org-default-priority
1897 (mapconcat 'identity org-drawers " ")
1898 (cdr (assoc org-startup-folded
1899 '((nil . "showall") (t . "overview") (content . "content"))))
1900 (if org-odd-levels-only "odd" "oddeven")
1901 (if org-hide-leading-stars "hidestars" "showstars")
1902 (if org-startup-align-all-tables "align" "noalign")
1903 (cond ((eq org-log-done t) "logdone")
1904 ((equal org-log-done 'note) "lognotedone")
1905 ((not org-log-done) "nologdone"))
1906 (or (mapconcat (lambda (x)
1907 (cond
1908 ((equal '(:startgroup) x) "{")
1909 ((equal '(:endgroup) x) "}")
1910 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
1911 (t (car x))))
1912 (or org-tag-alist (org-get-buffer-tags)) " ") "")
1913 org-archive-location
1914 "org file:~/org/%s.org"
1917 ;;;###autoload
1918 (defun org-insert-export-options-template ()
1919 "Insert into the buffer a template with information for exporting."
1920 (interactive)
1921 (if (not (bolp)) (newline))
1922 (let ((s (org-get-current-options)))
1923 (and (string-match "#\\+CATEGORY" s)
1924 (setq s (substring s 0 (match-beginning 0))))
1925 (insert s)))
1927 ;;;###autoload
1928 (defun org-export-as-html-and-open (arg)
1929 "Export the outline as HTML and immediately open it with a browser.
1930 If there is an active region, export only the region.
1931 The prefix ARG specifies how many levels of the outline should become
1932 headlines. The default is 3. Lower levels will become bulleted lists."
1933 (interactive "P")
1934 (org-export-as-html arg 'hidden)
1935 (org-open-file buffer-file-name))
1937 ;;;###autoload
1938 (defun org-export-as-html-batch ()
1939 "Call `org-export-as-html', may be used in batch processing as
1940 emacs --batch
1941 --load=$HOME/lib/emacs/org.el
1942 --eval \"(setq org-export-headline-levels 2)\"
1943 --visit=MyFile --funcall org-export-as-html-batch"
1944 (org-export-as-html org-export-headline-levels 'hidden))
1946 ;;;###autoload
1947 (defun org-export-as-html-to-buffer (arg)
1948 "Call `org-exort-as-html` with output to a temporary buffer.
1949 No file is created. The prefix ARG is passed through to `org-export-as-html'."
1950 (interactive "P")
1951 (org-export-as-html arg nil nil "*Org HTML Export*")
1952 (switch-to-buffer-other-window "*Org HTML Export*"))
1954 ;;;###autoload
1955 (defun org-replace-region-by-html (beg end)
1956 "Assume the current region has org-mode syntax, and convert it to HTML.
1957 This can be used in any buffer. For example, you could write an
1958 itemized list in org-mode syntax in an HTML buffer and then use this
1959 command to convert it."
1960 (interactive "r")
1961 (let (reg html buf pop-up-frames)
1962 (save-window-excursion
1963 (if (org-mode-p)
1964 (setq html (org-export-region-as-html
1965 beg end t 'string))
1966 (setq reg (buffer-substring beg end)
1967 buf (get-buffer-create "*Org tmp*"))
1968 (with-current-buffer buf
1969 (erase-buffer)
1970 (insert reg)
1971 (org-mode)
1972 (setq html (org-export-region-as-html
1973 (point-min) (point-max) t 'string)))
1974 (kill-buffer buf)))
1975 (delete-region beg end)
1976 (insert html)))
1978 ;;;###autoload
1979 (defun org-export-region-as-html (beg end &optional body-only buffer)
1980 "Convert region from BEG to END in org-mode buffer to HTML.
1981 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
1982 contents, and only produce the region of converted text, useful for
1983 cut-and-paste operations.
1984 If BUFFER is a buffer or a string, use/create that buffer as a target
1985 of the converted HTML. If BUFFER is the symbol `string', return the
1986 produced HTML as a string and leave not buffer behind. For example,
1987 a Lisp program could call this function in the following way:
1989 (setq html (org-export-region-as-html beg end t 'string))
1991 When called interactively, the output buffer is selected, and shown
1992 in a window. A non-interactive call will only retunr the buffer."
1993 (interactive "r\nP")
1994 (when (interactive-p)
1995 (setq buffer "*Org HTML Export*"))
1996 (let ((transient-mark-mode t) (zmacs-regions t)
1997 rtn)
1998 (goto-char end)
1999 (set-mark (point)) ;; to activate the region
2000 (goto-char beg)
2001 (setq rtn (org-export-as-html
2002 nil nil nil
2003 buffer body-only))
2004 (if (fboundp 'deactivate-mark) (deactivate-mark))
2005 (if (and (interactive-p) (bufferp rtn))
2006 (switch-to-buffer-other-window rtn)
2007 rtn)))
2009 (defvar html-table-tag nil) ; dynamically scoped into this.
2010 ;;;###autoload
2011 (defun org-export-as-html (arg &optional hidden ext-plist
2012 to-buffer body-only pub-dir)
2013 "Export the outline as a pretty HTML file.
2014 If there is an active region, export only the region. The prefix
2015 ARG specifies how many levels of the outline should become
2016 headlines. The default is 3. Lower levels will become bulleted
2017 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2018 EXT-PLIST is a property list with external parameters overriding
2019 org-mode's default settings, but still inferior to file-local
2020 settings. When TO-BUFFER is non-nil, create a buffer with that
2021 name and export to that buffer. If TO-BUFFER is the symbol
2022 `string', don't leave any buffer behind but just return the
2023 resulting HTML as a string. When BODY-ONLY is set, don't produce
2024 the file header and footer, simply return the content of
2025 <body>...</body>, without even the body tags themselves. When
2026 PUB-DIR is set, use this as the publishing directory."
2027 (interactive "P")
2029 ;; Make sure we have a file name when we need it.
2030 (when (and (not (or to-buffer body-only))
2031 (not buffer-file-name))
2032 (if (buffer-base-buffer)
2033 (org-set-local 'buffer-file-name
2034 (with-current-buffer (buffer-base-buffer)
2035 buffer-file-name))
2036 (error "Need a file name to be able to export.")))
2038 (message "Exporting...")
2039 (setq-default org-todo-line-regexp org-todo-line-regexp)
2040 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2041 (setq-default org-done-keywords org-done-keywords)
2042 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2043 (let* ((opt-plist
2044 (org-export-process-option-filters
2045 (org-combine-plists (org-default-export-plist)
2046 ext-plist
2047 (org-infile-export-plist))))
2049 (style (plist-get opt-plist :style))
2050 (html-extension (plist-get opt-plist :html-extension))
2051 (link-validate (plist-get opt-plist :link-validation-function))
2052 valid thetoc have-headings first-heading-pos
2053 (odd org-odd-levels-only)
2054 (region-p (org-region-active-p))
2055 (subtree-p
2056 (when region-p
2057 (save-excursion
2058 (goto-char (region-beginning))
2059 (and (org-at-heading-p)
2060 (>= (org-end-of-subtree t t) (region-end))))))
2061 ;; The following two are dynamically scoped into other
2062 ;; routines below.
2063 (org-current-export-dir
2064 (or pub-dir (org-export-directory :html opt-plist)))
2065 (org-current-export-file buffer-file-name)
2066 (level 0) (line "") (origline "") txt todo
2067 (umax nil)
2068 (umax-toc nil)
2069 (filename (if to-buffer nil
2070 (expand-file-name
2071 (concat
2072 (file-name-sans-extension
2073 (or (and subtree-p
2074 (org-entry-get (region-beginning)
2075 "EXPORT_FILE_NAME" t))
2076 (file-name-nondirectory buffer-file-name)))
2077 "." html-extension)
2078 (file-name-as-directory
2079 (or pub-dir (org-export-directory :html opt-plist))))))
2080 (current-dir (if buffer-file-name
2081 (file-name-directory buffer-file-name)
2082 default-directory))
2083 (buffer (if to-buffer
2084 (cond
2085 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2086 (t (get-buffer-create to-buffer)))
2087 (find-file-noselect filename)))
2088 (org-levels-open (make-vector org-level-max nil))
2089 (date (plist-get opt-plist :date))
2090 (author (plist-get opt-plist :author))
2091 (title (or (and subtree-p (org-export-get-title-from-subtree))
2092 (plist-get opt-plist :title)
2093 (and (not
2094 (plist-get opt-plist :skip-before-1st-heading))
2095 (org-export-grab-title-from-buffer))
2096 (and buffer-file-name
2097 (file-name-sans-extension
2098 (file-name-nondirectory buffer-file-name)))
2099 "UNTITLED"))
2100 (html-table-tag (plist-get opt-plist :html-table-tag))
2101 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2102 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2103 (inquote nil)
2104 (infixed nil)
2105 (in-local-list nil)
2106 (local-list-num nil)
2107 (local-list-indent nil)
2108 (llt org-plain-list-ordered-item-terminator)
2109 (email (plist-get opt-plist :email))
2110 (language (plist-get opt-plist :language))
2111 (lang-words nil)
2112 (target-alist nil) tg
2113 (head-count 0) cnt
2114 (start 0)
2115 (coding-system (and (boundp 'buffer-file-coding-system)
2116 buffer-file-coding-system))
2117 (coding-system-for-write (or org-export-html-coding-system
2118 coding-system))
2119 (save-buffer-coding-system (or org-export-html-coding-system
2120 coding-system))
2121 (charset (and coding-system-for-write
2122 (fboundp 'coding-system-get)
2123 (coding-system-get coding-system-for-write
2124 'mime-charset)))
2125 (region
2126 (buffer-substring
2127 (if region-p (region-beginning) (point-min))
2128 (if region-p (region-end) (point-max))))
2129 (lines
2130 (org-split-string
2131 (org-cleaned-string-for-export
2132 region
2133 :emph-multiline t
2134 :for-html t
2135 :skip-before-1st-heading
2136 (plist-get opt-plist :skip-before-1st-heading)
2137 :drawers (plist-get opt-plist :drawers)
2138 :archived-trees
2139 (plist-get opt-plist :archived-trees)
2140 :add-text
2141 (plist-get opt-plist :text)
2142 :LaTeX-fragments
2143 (plist-get opt-plist :LaTeX-fragments))
2144 "[\r\n]"))
2145 table-open type
2146 table-buffer table-orig-buffer
2147 ind start-is-num starter didclose
2148 rpl path desc descp desc1 desc2 link
2149 snumber fnc
2152 (let ((inhibit-read-only t))
2153 (org-unmodified
2154 (remove-text-properties (point-min) (point-max)
2155 '(:org-license-to-kill t))))
2157 (message "Exporting...")
2159 (setq org-min-level (org-get-min-level lines))
2160 (setq org-last-level org-min-level)
2161 (org-init-section-numbers)
2163 (cond
2164 ((and date (string-match "%" date))
2165 (setq date (format-time-string date)))
2166 (date)
2167 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2169 ;; Get the language-dependent settings
2170 (setq lang-words (or (assoc language org-export-language-setup)
2171 (assoc "en" org-export-language-setup)))
2173 ;; Switch to the output buffer
2174 (set-buffer buffer)
2175 (let ((inhibit-read-only t)) (erase-buffer))
2176 (fundamental-mode)
2178 (and (fboundp 'set-buffer-file-coding-system)
2179 (set-buffer-file-coding-system coding-system-for-write))
2181 (let ((case-fold-search nil)
2182 (org-odd-levels-only odd))
2183 ;; create local variables for all options, to make sure all called
2184 ;; functions get the correct information
2185 (mapc (lambda (x)
2186 (set (make-local-variable (cdr x))
2187 (plist-get opt-plist (car x))))
2188 org-export-plist-vars)
2189 (setq umax (if arg (prefix-numeric-value arg)
2190 org-export-headline-levels))
2191 (setq umax-toc (if (integerp org-export-with-toc)
2192 (min org-export-with-toc umax)
2193 umax))
2194 (unless body-only
2195 ;; File header
2196 (insert (format
2197 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2198 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2199 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2200 lang=\"%s\" xml:lang=\"%s\">
2201 <head>
2202 <title>%s</title>
2203 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2204 <meta name=\"generator\" content=\"Org-mode\"/>
2205 <meta name=\"generated\" content=\"%s\"/>
2206 <meta name=\"author\" content=\"%s\"/>
2208 </head><body>
2210 language language (org-html-expand title)
2211 (or charset "iso-8859-1") date author style))
2213 (insert (or (plist-get opt-plist :preamble) ""))
2215 (when (plist-get opt-plist :auto-preamble)
2216 (if title (insert (format org-export-html-title-format
2217 (org-html-expand title))))))
2219 (if (and org-export-with-toc (not body-only))
2220 (progn
2221 (push (format "<h%d>%s</h%d>\n"
2222 org-export-html-toplevel-hlevel
2223 (nth 3 lang-words)
2224 org-export-html-toplevel-hlevel)
2225 thetoc)
2226 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2227 (push "<ul>\n<li>" thetoc)
2228 (setq lines
2229 (mapcar '(lambda (line)
2230 (if (string-match org-todo-line-regexp line)
2231 ;; This is a headline
2232 (progn
2233 (setq have-headings t)
2234 (setq level (- (match-end 1) (match-beginning 1))
2235 level (org-tr-level level)
2236 txt (save-match-data
2237 (org-html-expand
2238 (org-export-cleanup-toc-line
2239 (match-string 3 line))))
2240 todo
2241 (or (and org-export-mark-todo-in-toc
2242 (match-beginning 2)
2243 (not (member (match-string 2 line)
2244 org-done-keywords)))
2245 ; TODO, not DONE
2246 (and org-export-mark-todo-in-toc
2247 (= level umax-toc)
2248 (org-search-todo-below
2249 line lines level))))
2250 (if (string-match
2251 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2252 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2253 (if (string-match quote-re0 txt)
2254 (setq txt (replace-match "" t t txt)))
2255 (setq snumber (org-section-number level))
2256 (if org-export-with-section-numbers
2257 (setq txt (concat snumber " " txt)))
2258 (if (<= level (max umax umax-toc))
2259 (setq head-count (+ head-count 1)))
2260 (if (<= level umax-toc)
2261 (progn
2262 (if (> level org-last-level)
2263 (progn
2264 (setq cnt (- level org-last-level))
2265 (while (>= (setq cnt (1- cnt)) 0)
2266 (push "\n<ul>\n<li>" thetoc))
2267 (push "\n" thetoc)))
2268 (if (< level org-last-level)
2269 (progn
2270 (setq cnt (- org-last-level level))
2271 (while (>= (setq cnt (1- cnt)) 0)
2272 (push "</li>\n</ul>" thetoc))
2273 (push "\n" thetoc)))
2274 ;; Check for targets
2275 (while (string-match org-target-regexp line)
2276 (setq tg (match-string 1 line)
2277 line (replace-match
2278 (concat "@<span class=\"target\">" tg "@</span> ")
2279 t t line))
2280 (push (cons (org-solidify-link-text tg)
2281 (format "sec-%s" snumber))
2282 target-alist))
2283 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2284 (setq txt (replace-match "" t t txt)))
2285 (push
2286 (format
2287 (if todo
2288 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2289 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2290 snumber txt) thetoc)
2292 (setq org-last-level level))
2294 line)
2295 lines))
2296 (while (> org-last-level (1- org-min-level))
2297 (setq org-last-level (1- org-last-level))
2298 (push "</li>\n</ul>\n" thetoc))
2299 (push "</div>\n" thetoc)
2300 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2302 (setq head-count 0)
2303 (org-init-section-numbers)
2305 (while (setq line (pop lines) origline line)
2306 (catch 'nextline
2308 ;; end of quote section?
2309 (when (and inquote (string-match "^\\*+ " line))
2310 (insert "</pre>\n")
2311 (setq inquote nil))
2312 ;; inside a quote section?
2313 (when inquote
2314 (insert (org-html-protect line) "\n")
2315 (throw 'nextline nil))
2317 ;; verbatim lines
2318 (when (and org-export-with-fixed-width
2319 (string-match "^[ \t]*:\\(.*\\)" line))
2320 (when (not infixed)
2321 (setq infixed t)
2322 (insert "<pre>\n"))
2323 (insert (org-html-protect (match-string 1 line)) "\n")
2324 (when (and lines
2325 (not (string-match "^[ \t]*\\(:.*\\)"
2326 (car lines))))
2327 (setq infixed nil)
2328 (insert "</pre>\n"))
2329 (throw 'nextline nil))
2331 ;; Protected HTML
2332 (when (get-text-property 0 'org-protected line)
2333 (let (par)
2334 (when (re-search-backward
2335 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2336 (setq par (match-string 1))
2337 (replace-match "\\2\n"))
2338 (insert line "\n")
2339 (while (and lines
2340 (or (= (length (car lines)) 0)
2341 (get-text-property 0 'org-protected (car lines))))
2342 (insert (pop lines) "\n"))
2343 (and par (insert "<p>\n")))
2344 (throw 'nextline nil))
2346 ;; Horizontal line
2347 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2348 (insert "\n<hr/>\n")
2349 (throw 'nextline nil))
2351 ;; make targets to anchors
2352 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2353 (cond
2354 ((match-end 2)
2355 (setq line (replace-match
2356 (concat "@<a name=\""
2357 (org-solidify-link-text (match-string 1 line))
2358 "\">\\nbsp@</a>")
2359 t t line)))
2360 ((and org-export-with-toc (equal (string-to-char line) ?*))
2361 (setq line (replace-match
2362 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2363 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2364 t t line)))
2366 (setq line (replace-match
2367 (concat "@<a name=\""
2368 (org-solidify-link-text (match-string 1 line))
2369 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2370 t t line)))))
2372 (setq line (org-html-handle-time-stamps line))
2374 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2375 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2376 ;; Also handle sub_superscripts and checkboxes
2377 (or (string-match org-table-hline-regexp line)
2378 (setq line (org-html-expand line)))
2380 ;; Format the links
2381 (setq start 0)
2382 (while (string-match org-bracket-link-analytic-regexp line start)
2383 (setq start (match-beginning 0))
2384 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2385 (setq path (match-string 3 line))
2386 (setq desc1 (if (match-end 5) (match-string 5 line))
2387 desc2 (if (match-end 2) (concat type ":" path) path)
2388 descp (and desc1 (not (equal desc1 desc2)))
2389 desc (or desc1 desc2))
2390 ;; Make an image out of the description if that is so wanted
2391 (when (and descp (org-file-image-p desc))
2392 (save-match-data
2393 (if (string-match "^file:" desc)
2394 (setq desc (substring desc (match-end 0)))))
2395 (setq desc (concat "<img src=\"" desc "\"/>")))
2396 ;; FIXME: do we need to unescape here somewhere?
2397 (cond
2398 ((equal type "internal")
2399 (setq rpl
2400 (concat
2401 "<a href=\"#"
2402 (org-solidify-link-text
2403 (save-match-data (org-link-unescape path)) target-alist)
2404 "\">" desc "</a>")))
2405 ((member type '("http" "https"))
2406 ;; standard URL, just check if we need to inline an image
2407 (if (and (or (eq t org-export-html-inline-images)
2408 (and org-export-html-inline-images (not descp)))
2409 (org-file-image-p path))
2410 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2411 (setq link (concat type ":" path))
2412 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2413 ((member type '("ftp" "mailto" "news"))
2414 ;; standard URL
2415 (setq link (concat type ":" path))
2416 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2417 ((string= type "file")
2418 ;; FILE link
2419 (let* ((filename path)
2420 (abs-p (file-name-absolute-p filename))
2421 thefile file-is-image-p search)
2422 (save-match-data
2423 (if (string-match "::\\(.*\\)" filename)
2424 (setq search (match-string 1 filename)
2425 filename (replace-match "" t nil filename)))
2426 (setq valid
2427 (if (functionp link-validate)
2428 (funcall link-validate filename current-dir)
2430 (setq file-is-image-p (org-file-image-p filename))
2431 (setq thefile (if abs-p (expand-file-name filename) filename))
2432 (when (and org-export-html-link-org-files-as-html
2433 (string-match "\\.org$" thefile))
2434 (setq thefile (concat (substring thefile 0
2435 (match-beginning 0))
2436 "." html-extension))
2437 (if (and search
2438 ;; make sure this is can be used as target search
2439 (not (string-match "^[0-9]*$" search))
2440 (not (string-match "^\\*" search))
2441 (not (string-match "^/.*/$" search)))
2442 (setq thefile (concat thefile "#"
2443 (org-solidify-link-text
2444 (org-link-unescape search)))))
2445 (when (string-match "^file:" desc)
2446 (setq desc (replace-match "" t t desc))
2447 (if (string-match "\\.org$" desc)
2448 (setq desc (replace-match "" t t desc))))))
2449 (setq rpl (if (and file-is-image-p
2450 (or (eq t org-export-html-inline-images)
2451 (and org-export-html-inline-images
2452 (not descp))))
2453 (concat "<img src=\"" thefile "\"/>")
2454 (concat "<a href=\"" thefile "\">" desc "</a>")))
2455 (if (not valid) (setq rpl desc))))
2457 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2458 (setq rpl
2459 (save-match-data
2460 (funcall fnc (org-link-unescape path) desc1 'html))))
2463 ;; just publish the path, as default
2464 (setq rpl (concat "<i>&lt;" type ":"
2465 (save-match-data (org-link-unescape path))
2466 "&gt;</i>"))))
2467 (setq line (replace-match rpl t t line)
2468 start (+ start (length rpl))))
2470 ;; TODO items
2471 (if (and (string-match org-todo-line-regexp line)
2472 (match-beginning 2))
2474 (setq line
2475 (concat (substring line 0 (match-beginning 2))
2476 "<span class=\""
2477 (if (member (match-string 2 line)
2478 org-done-keywords)
2479 "done" "todo")
2480 "\">" (match-string 2 line)
2481 "</span>" (substring line (match-end 2)))))
2483 ;; Does this contain a reference to a footnote?
2484 (when org-export-with-footnotes
2485 (setq start 0)
2486 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
2487 (if (get-text-property (match-beginning 2) 'org-protected line)
2488 (setq start (match-end 2))
2489 (let ((n (match-string 2 line)))
2490 (setq line
2491 (replace-match
2492 (format
2493 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2494 (match-string 1 line) n n n)
2495 t t line))))))
2497 (cond
2498 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2499 ;; This is a headline
2500 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2501 txt (match-string 2 line))
2502 (if (string-match quote-re0 txt)
2503 (setq txt (replace-match "" t t txt)))
2504 (if (<= level (max umax umax-toc))
2505 (setq head-count (+ head-count 1)))
2506 (when in-local-list
2507 ;; Close any local lists before inserting a new header line
2508 (while local-list-num
2509 (org-close-li)
2510 (insert (if (car local-list-num) "</ol>\n" "</ul>"))
2511 (pop local-list-num))
2512 (setq local-list-indent nil
2513 in-local-list nil))
2514 (setq first-heading-pos (or first-heading-pos (point)))
2515 (org-html-level-start level txt umax
2516 (and org-export-with-toc (<= level umax))
2517 head-count)
2518 ;; QUOTES
2519 (when (string-match quote-re line)
2520 (insert "<pre>")
2521 (setq inquote t)))
2523 ((and org-export-with-tables
2524 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2525 (if (not table-open)
2526 ;; New table starts
2527 (setq table-open t table-buffer nil table-orig-buffer nil))
2528 ;; Accumulate lines
2529 (setq table-buffer (cons line table-buffer)
2530 table-orig-buffer (cons origline table-orig-buffer))
2531 (when (or (not lines)
2532 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2533 (car lines))))
2534 (setq table-open nil
2535 table-buffer (nreverse table-buffer)
2536 table-orig-buffer (nreverse table-orig-buffer))
2537 (org-close-par-maybe)
2538 (insert (org-format-table-html table-buffer table-orig-buffer))))
2540 ;; Normal lines
2541 (when (string-match
2542 (cond
2543 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2544 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2545 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2546 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2547 line)
2548 (setq ind (org-get-string-indentation line)
2549 start-is-num (match-beginning 4)
2550 starter (if (match-beginning 2)
2551 (substring (match-string 2 line) 0 -1))
2552 line (substring line (match-beginning 5)))
2553 (unless (string-match "[^ \t]" line)
2554 ;; empty line. Pretend indentation is large.
2555 (setq ind (if org-empty-line-terminates-plain-lists
2557 (1+ (or (car local-list-indent) 1)))))
2558 (setq didclose nil)
2559 (while (and in-local-list
2560 (or (and (= ind (car local-list-indent))
2561 (not starter))
2562 (< ind (car local-list-indent))))
2563 (setq didclose t)
2564 (org-close-li)
2565 (insert (if (car local-list-num) "</ol>\n" "</ul>"))
2566 (pop local-list-num) (pop local-list-indent)
2567 (setq in-local-list local-list-indent))
2568 (cond
2569 ((and starter
2570 (or (not in-local-list)
2571 (> ind (car local-list-indent))))
2572 ;; Start new (level of) list
2573 (org-close-par-maybe)
2574 (insert (if start-is-num "<ol>\n<li>\n" "<ul>\n<li>\n"))
2575 (push start-is-num local-list-num)
2576 (push ind local-list-indent)
2577 (setq in-local-list t))
2578 (starter
2579 ;; continue current list
2580 (org-close-li)
2581 (insert "<li>\n"))
2582 (didclose
2583 ;; we did close a list, normal text follows: need <p>
2584 (org-open-par)))
2585 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
2586 (setq line
2587 (replace-match
2588 (if (equal (match-string 1 line) "X")
2589 "<b>[X]</b>"
2590 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2591 t t line))))
2593 ;; Empty lines start a new paragraph. If hand-formatted lists
2594 ;; are not fully interpreted, lines starting with "-", "+", "*"
2595 ;; also start a new paragraph.
2596 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
2598 ;; Is this the start of a footnote?
2599 (when org-export-with-footnotes
2600 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
2601 (org-close-par-maybe)
2602 (let ((n (match-string 1 line)))
2603 (setq line (replace-match
2604 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
2606 ;; Check if the line break needs to be conserved
2607 (cond
2608 ((string-match "\\\\\\\\[ \t]*$" line)
2609 (setq line (replace-match "<br/>" t t line)))
2610 (org-export-preserve-breaks
2611 (setq line (concat line "<br/>"))))
2613 (insert line "\n")))))
2615 ;; Properly close all local lists and other lists
2616 (when inquote (insert "</pre>\n"))
2617 (when in-local-list
2618 ;; Close any local lists before inserting a new header line
2619 (while local-list-num
2620 (org-close-li)
2621 (insert (if (car local-list-num) "</ol>\n" "</ul>\n"))
2622 (pop local-list-num))
2623 (setq local-list-indent nil
2624 in-local-list nil))
2625 (org-html-level-start 1 nil umax
2626 (and org-export-with-toc (<= level umax))
2627 head-count)
2628 ;; the </div> to lose the last text-... div.
2629 (insert "</div>\n")
2631 (unless body-only
2632 (when (plist-get opt-plist :auto-postamble)
2633 (insert "<div id=\"postamble\">")
2634 (when (and org-export-author-info author)
2635 (insert "<p class=\"author\"> "
2636 (nth 1 lang-words) ": " author "\n")
2637 (when email
2638 (if (listp (split-string email ",+ *"))
2639 (mapc (lambda(e)
2640 (insert "<a href=\"mailto:" e "\">&lt;"
2641 e "&gt;</a>\n"))
2642 (split-string email ",+ *"))
2643 (insert "<a href=\"mailto:" email "\">&lt;"
2644 email "&gt;</a>\n")))
2645 (insert "</p>\n"))
2646 (when (and date org-export-time-stamp-file)
2647 (insert "<p class=\"date\"> "
2648 (nth 2 lang-words) ": "
2649 date "</p>\n"))
2650 (insert "</div>"))
2652 (if org-export-html-with-timestamp
2653 (insert org-export-html-html-helper-timestamp))
2654 (insert (or (plist-get opt-plist :postamble) ""))
2655 (insert "</body>\n</html>\n"))
2657 (normal-mode)
2658 (if (eq major-mode default-major-mode) (html-mode))
2660 ;; insert the table of contents
2661 (goto-char (point-min))
2662 (when thetoc
2663 (if (or (re-search-forward
2664 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
2665 (re-search-forward
2666 "\\[TABLE-OF-CONTENTS\\]" nil t))
2667 (progn
2668 (goto-char (match-beginning 0))
2669 (replace-match ""))
2670 (goto-char first-heading-pos)
2671 (when (looking-at "\\s-*</p>")
2672 (goto-char (match-end 0))
2673 (insert "\n")))
2674 (insert "<div id=\"table-of-contents\">\n")
2675 (mapc 'insert thetoc)
2676 (insert "</div>\n"))
2677 ;; remove empty paragraphs and lists
2678 (goto-char (point-min))
2679 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2680 (replace-match ""))
2681 (goto-char (point-min))
2682 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
2683 (replace-match ""))
2684 (goto-char (point-min))
2685 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
2686 (replace-match ""))
2687 ;; Convert whitespace place holders
2688 (goto-char (point-min))
2689 (let (beg end n)
2690 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2691 (setq n (get-text-property beg 'org-whitespace)
2692 end (next-single-property-change beg 'org-whitespace))
2693 (goto-char beg)
2694 (delete-region beg end)
2695 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2696 (make-string n ?x)))))
2697 (or to-buffer (save-buffer))
2698 (goto-char (point-min))
2699 (message "Exporting... done")
2700 (if (eq to-buffer 'string)
2701 (prog1 (buffer-substring (point-min) (point-max))
2702 (kill-buffer (current-buffer)))
2703 (current-buffer)))))
2705 (defvar org-table-colgroup-info nil)
2706 (defun org-format-table-ascii (lines)
2707 "Format a table for ascii export."
2708 (if (stringp lines)
2709 (setq lines (org-split-string lines "\n")))
2710 (if (not (string-match "^[ \t]*|" (car lines)))
2711 ;; Table made by table.el - test for spanning
2712 lines
2714 ;; A normal org table
2715 ;; Get rid of hlines at beginning and end
2716 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2717 (setq lines (nreverse lines))
2718 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2719 (setq lines (nreverse lines))
2720 (when org-export-table-remove-special-lines
2721 ;; Check if the table has a marking column. If yes remove the
2722 ;; column and the special lines
2723 (setq lines (org-table-clean-before-export lines)))
2724 ;; Get rid of the vertical lines except for grouping
2725 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
2726 rtn line vl1 start)
2727 (while (setq line (pop lines))
2728 (if (string-match org-table-hline-regexp line)
2729 (and (string-match "|\\(.*\\)|" line)
2730 (setq line (replace-match " \\1" t nil line)))
2731 (setq start 0 vl1 vl)
2732 (while (string-match "|" line start)
2733 (setq start (match-end 0))
2734 (or (pop vl1) (setq line (replace-match " " t t line)))))
2735 (push line rtn))
2736 (nreverse rtn))))
2738 (defun org-colgroup-info-to-vline-list (info)
2739 (let (vl new last)
2740 (while info
2741 (setq last new new (pop info))
2742 (if (or (memq last '(:end :startend))
2743 (memq new '(:start :startend)))
2744 (push t vl)
2745 (push nil vl)))
2746 (setq vl (nreverse vl))
2747 (and vl (setcar vl nil))
2748 vl))
2750 (defvar org-table-number-regexp) ; defined in org-table.el
2751 (defun org-format-table-html (lines olines)
2752 "Find out which HTML converter to use and return the HTML code."
2753 (if (stringp lines)
2754 (setq lines (org-split-string lines "\n")))
2755 (if (string-match "^[ \t]*|" (car lines))
2756 ;; A normal org table
2757 (org-format-org-table-html lines)
2758 ;; Table made by table.el - test for spanning
2759 (let* ((hlines (delq nil (mapcar
2760 (lambda (x)
2761 (if (string-match "^[ \t]*\\+-" x) x
2762 nil))
2763 lines)))
2764 (first (car hlines))
2765 (ll (and (string-match "\\S-+" first)
2766 (match-string 0 first)))
2767 (re (concat "^[ \t]*" (regexp-quote ll)))
2768 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
2769 hlines))))
2770 (if (and (not spanning)
2771 (not org-export-prefer-native-exporter-for-tables))
2772 ;; We can use my own converter with HTML conversions
2773 (org-format-table-table-html lines)
2774 ;; Need to use the code generator in table.el, with the original text.
2775 (org-format-table-table-html-using-table-generate-source olines)))))
2777 (defvar org-table-number-fraction) ; defined in org-table.el
2778 (defun org-format-org-table-html (lines &optional splice)
2779 "Format a table into HTML."
2780 (require 'org-table)
2781 ;; Get rid of hlines at beginning and end
2782 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2783 (setq lines (nreverse lines))
2784 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2785 (setq lines (nreverse lines))
2786 (when org-export-table-remove-special-lines
2787 ;; Check if the table has a marking column. If yes remove the
2788 ;; column and the special lines
2789 (setq lines (org-table-clean-before-export lines)))
2791 (let ((head (and org-export-highlight-first-table-line
2792 (delq nil (mapcar
2793 (lambda (x) (string-match "^[ \t]*|-" x))
2794 (cdr lines)))))
2795 (nlines 0) fnum i
2796 tbopen line fields html gr colgropen)
2797 (if splice (setq head nil))
2798 (unless splice (push (if head "<thead>" "<tbody>") html))
2799 (setq tbopen t)
2800 (while (setq line (pop lines))
2801 (catch 'next-line
2802 (if (string-match "^[ \t]*|-" line)
2803 (progn
2804 (unless splice
2805 (push (if head "</thead>" "</tbody>") html)
2806 (if lines (push "<tbody>" html) (setq tbopen nil)))
2807 (setq head nil) ;; head ends here, first time around
2808 ;; ignore this line
2809 (throw 'next-line t)))
2810 ;; Break the line into fields
2811 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2812 (unless fnum (setq fnum (make-vector (length fields) 0)))
2813 (setq nlines (1+ nlines) i -1)
2814 (push (concat "<tr>"
2815 (mapconcat
2816 (lambda (x)
2817 (setq i (1+ i))
2818 (if (and (< i nlines)
2819 (string-match org-table-number-regexp x))
2820 (incf (aref fnum i)))
2821 (if head
2822 (concat (car org-export-table-header-tags) x
2823 (cdr org-export-table-header-tags))
2824 (concat (car org-export-table-data-tags) x
2825 (cdr org-export-table-data-tags))))
2826 fields "")
2827 "</tr>")
2828 html)))
2829 (unless splice (if tbopen (push "</tbody>" html)))
2830 (unless splice (push "</table>\n" html))
2831 (setq html (nreverse html))
2832 (unless splice
2833 ;; Put in col tags with the alignment (unfortuntely often ignored...)
2834 (push (mapconcat
2835 (lambda (x)
2836 (setq gr (pop org-table-colgroup-info))
2837 (format "%s<col align=\"%s\"></col>%s"
2838 (if (memq gr '(:start :startend))
2839 (prog1
2840 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
2841 (setq colgropen t))
2843 (if (> (/ (float x) nlines) org-table-number-fraction)
2844 "right" "left")
2845 (if (memq gr '(:end :startend))
2846 (progn (setq colgropen nil) "</colgroup>")
2847 "")))
2848 fnum "")
2849 html)
2850 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
2851 (push html-table-tag html))
2852 (concat (mapconcat 'identity html "\n") "\n")))
2854 (defun org-table-clean-before-export (lines)
2855 "Check if the table has a marking column.
2856 If yes remove the column and the special lines."
2857 (setq org-table-colgroup-info nil)
2858 (if (memq nil
2859 (mapcar
2860 (lambda (x) (or (string-match "^[ \t]*|-" x)
2861 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
2862 lines))
2863 (progn
2864 (setq org-table-clean-did-remove-column nil)
2865 (delq nil
2866 (mapcar
2867 (lambda (x)
2868 (cond
2869 ((string-match "^[ \t]*| */ *|" x)
2870 (setq org-table-colgroup-info
2871 (mapcar (lambda (x)
2872 (cond ((member x '("<" "&lt;")) :start)
2873 ((member x '(">" "&gt;")) :end)
2874 ((member x '("<>" "&lt;&gt;")) :startend)
2875 (t nil)))
2876 (org-split-string x "[ \t]*|[ \t]*")))
2877 nil)
2878 (t x)))
2879 lines)))
2880 (setq org-table-clean-did-remove-column t)
2881 (delq nil
2882 (mapcar
2883 (lambda (x)
2884 (cond
2885 ((string-match "^[ \t]*| */ *|" x)
2886 (setq org-table-colgroup-info
2887 (mapcar (lambda (x)
2888 (cond ((member x '("<" "&lt;")) :start)
2889 ((member x '(">" "&gt;")) :end)
2890 ((member x '("<>" "&lt;&gt;")) :startend)
2891 (t nil)))
2892 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2893 nil)
2894 ((string-match "^[ \t]*| *[!_^/] *|" x)
2895 nil) ; ignore this line
2896 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2897 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2898 ;; remove the first column
2899 (replace-match "\\1|" t nil x))))
2900 lines))))
2902 (defun org-format-table-table-html (lines)
2903 "Format a table generated by table.el into HTML.
2904 This conversion does *not* use `table-generate-source' from table.el.
2905 This has the advantage that Org-mode's HTML conversions can be used.
2906 But it has the disadvantage, that no cell- or row-spanning is allowed."
2907 (let (line field-buffer
2908 (head org-export-highlight-first-table-line)
2909 fields html empty)
2910 (setq html (concat html-table-tag "\n"))
2911 (while (setq line (pop lines))
2912 (setq empty "&nbsp;")
2913 (catch 'next-line
2914 (if (string-match "^[ \t]*\\+-" line)
2915 (progn
2916 (if field-buffer
2917 (progn
2918 (setq
2919 html
2920 (concat
2921 html
2922 "<tr>"
2923 (mapconcat
2924 (lambda (x)
2925 (if (equal x "") (setq x empty))
2926 (if head
2927 (concat (car org-export-table-header-tags) x
2928 (cdr org-export-table-header-tags))
2929 (concat (car org-export-table-data-tags) x
2930 (cdr org-export-table-data-tags))))
2931 field-buffer "\n")
2932 "</tr>\n"))
2933 (setq head nil)
2934 (setq field-buffer nil)))
2935 ;; Ignore this line
2936 (throw 'next-line t)))
2937 ;; Break the line into fields and store the fields
2938 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2939 (if field-buffer
2940 (setq field-buffer (mapcar
2941 (lambda (x)
2942 (concat x "<br/>" (pop fields)))
2943 field-buffer))
2944 (setq field-buffer fields))))
2945 (setq html (concat html "</table>\n"))
2946 html))
2948 (defun org-format-table-table-html-using-table-generate-source (lines)
2949 "Format a table into html, using `table-generate-source' from table.el.
2950 This has the advantage that cell- or row-spanning is allowed.
2951 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
2952 (require 'table)
2953 (with-current-buffer (get-buffer-create " org-tmp1 ")
2954 (erase-buffer)
2955 (insert (mapconcat 'identity lines "\n"))
2956 (goto-char (point-min))
2957 (if (not (re-search-forward "|[^+]" nil t))
2958 (error "Error processing table"))
2959 (table-recognize-table)
2960 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2961 (table-generate-source 'html " org-tmp2 ")
2962 (set-buffer " org-tmp2 ")
2963 (buffer-substring (point-min) (point-max))))
2965 (defun org-html-handle-time-stamps (s)
2966 "Format time stamps in string S, or remove them."
2967 (catch 'exit
2968 (let (r b)
2969 (while (string-match org-maybe-keyword-time-regexp s)
2970 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
2971 ;; never export CLOCK
2972 (throw 'exit ""))
2973 (or b (setq b (substring s 0 (match-beginning 0))))
2974 (if (not org-export-with-timestamps)
2975 (setq r (concat r (substring s 0 (match-beginning 0)))
2976 s (substring s (match-end 0)))
2977 (setq r (concat
2978 r (substring s 0 (match-beginning 0))
2979 (if (match-end 1)
2980 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2981 (match-string 1 s)))
2982 (format " @<span class=\"timestamp\">%s@</span>"
2983 (substring
2984 (org-translate-time (match-string 3 s)) 1 -1)))
2985 s (substring s (match-end 0)))))
2986 ;; Line break if line started and ended with time stamp stuff
2987 (if (not r)
2989 (setq r (concat r s))
2990 (unless (string-match "\\S-" (concat b s))
2991 (setq r (concat r "@<br/>")))
2992 r))))
2994 (defun org-html-protect (s)
2995 ;; convert & to &amp;, < to &lt; and > to &gt;
2996 (let ((start 0))
2997 (while (string-match "&" s start)
2998 (setq s (replace-match "&amp;" t t s)
2999 start (1+ (match-beginning 0))))
3000 (while (string-match "<" s)
3001 (setq s (replace-match "&lt;" t t s)))
3002 (while (string-match ">" s)
3003 (setq s (replace-match "&gt;" t t s))))
3006 (defun org-export-cleanup-toc-line (s)
3007 "Remove tags and time staps from lines going into the toc."
3008 (when (memq org-export-with-tags '(not-in-toc nil))
3009 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3010 (setq s (replace-match "" t t s))))
3011 (when org-export-remove-timestamps-from-toc
3012 (while (string-match org-maybe-keyword-time-regexp s)
3013 (setq s (replace-match "" t t s))))
3014 (while (string-match org-bracket-link-regexp s)
3015 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3016 t t s)))
3019 (defun org-html-expand (string)
3020 "Prepare STRING for HTML export. Applies all active conversions.
3021 If there are links in the string, don't modify these."
3022 (let* ((re (concat org-bracket-link-regexp "\\|"
3023 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3024 m s l res)
3025 (while (setq m (string-match re string))
3026 (setq s (substring string 0 m)
3027 l (match-string 0 string)
3028 string (substring string (match-end 0)))
3029 (push (org-html-do-expand s) res)
3030 (push l res))
3031 (push (org-html-do-expand string) res)
3032 (apply 'concat (nreverse res))))
3034 (defun org-html-do-expand (s)
3035 "Apply all active conversions to translate special ASCII to HTML."
3036 (setq s (org-html-protect s))
3037 (if org-export-html-expand
3038 (let ((start 0))
3039 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3040 (setq s (replace-match "<\\1>" t nil s)))))
3041 (if org-export-with-emphasize
3042 (setq s (org-export-html-convert-emphasize s)))
3043 (if org-export-with-special-strings
3044 (setq s (org-export-html-convert-special-strings s)))
3045 (if org-export-with-sub-superscripts
3046 (setq s (org-export-html-convert-sub-super s)))
3047 (if org-export-with-TeX-macros
3048 (let ((start 0) wd ass)
3049 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3050 (if (get-text-property (match-beginning 0) 'org-protected s)
3051 (setq start (match-end 0))
3052 (setq wd (match-string 1 s))
3053 (if (setq ass (assoc wd org-html-entities))
3054 (setq s (replace-match (or (cdr ass)
3055 (concat "&" (car ass) ";"))
3056 t t s))
3057 (setq start (+ start (length wd))))))))
3060 (defun org-create-multibrace-regexp (left right n)
3061 "Create a regular expression which will match a balanced sexp.
3062 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3063 as single character strings.
3064 The regexp returned will match the entire expression including the
3065 delimiters. It will also define a single group which contains the
3066 match except for the outermost delimiters. The maximum depth of
3067 stacked delimiters is N. Escaping delimiters is not possible."
3068 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3069 (or "\\|")
3070 (re nothing)
3071 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3072 (while (> n 1)
3073 (setq n (1- n)
3074 re (concat re or next)
3075 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3076 (concat left "\\(" re "\\)" right)))
3078 (defvar org-match-substring-regexp
3079 (concat
3080 "\\([^\\]\\)\\([_^]\\)\\("
3081 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3082 "\\|"
3083 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3084 "\\|"
3085 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3086 "The regular expression matching a sub- or superscript.")
3088 (defvar org-match-substring-with-braces-regexp
3089 (concat
3090 "\\([^\\]\\)\\([_^]\\)\\("
3091 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3092 "\\)")
3093 "The regular expression matching a sub- or superscript, forcing braces.")
3095 (defconst org-export-html-special-string-regexps
3096 '(("\\\\-" . "&shy;")
3097 ("---\\([^-]\\)" . "&mdash;\\1")
3098 ("--\\([^-]\\)" . "&ndash;\\1")
3099 ("\\.\\.\\." . "&hellip;"))
3100 "Regular expressions for special string conversion.")
3102 (defun org-export-html-convert-special-strings (string)
3103 "Convert special characters in STRING to HTML."
3104 (let ((all org-export-html-special-string-regexps)
3105 e a re rpl start)
3106 (while (setq a (pop all))
3107 (setq re (car a) rpl (cdr a) start 0)
3108 (while (string-match re string start)
3109 (if (get-text-property (match-beginning 0) 'org-protected string)
3110 (setq start (match-end 0))
3111 (setq string (replace-match rpl t nil string)))))
3112 string))
3114 (defun org-export-html-convert-sub-super (string)
3115 "Convert sub- and superscripts in STRING to HTML."
3116 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3117 (while (string-match org-match-substring-regexp string s)
3118 (cond
3119 ((and requireb (match-end 8)) (setq s (match-end 2)))
3120 ((get-text-property (match-beginning 2) 'org-protected string)
3121 (setq s (match-end 2)))
3123 (setq s (match-end 1)
3124 key (if (string= (match-string 2 string) "_") "sub" "sup")
3125 c (or (match-string 8 string)
3126 (match-string 6 string)
3127 (match-string 5 string))
3128 string (replace-match
3129 (concat (match-string 1 string)
3130 "<" key ">" c "</" key ">")
3131 t t string)))))
3132 (while (string-match "\\\\\\([_^]\\)" string)
3133 (setq string (replace-match (match-string 1 string) t t string)))
3134 string))
3136 (defun org-export-html-convert-emphasize (string)
3137 "Apply emphasis."
3138 (let ((s 0) rpl)
3139 (while (string-match org-emph-re string s)
3140 (if (not (equal
3141 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3142 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3143 (setq s (match-beginning 0)
3145 (concat
3146 (match-string 1 string)
3147 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3148 (match-string 4 string)
3149 (nth 3 (assoc (match-string 3 string)
3150 org-emphasis-alist))
3151 (match-string 5 string))
3152 string (replace-match rpl t t string)
3153 s (+ s (- (length rpl) 2)))
3154 (setq s (1+ s))))
3155 string))
3157 (defvar org-par-open nil)
3158 (defun org-open-par ()
3159 "Insert <p>, but first close previous paragraph if any."
3160 (org-close-par-maybe)
3161 (insert "\n<p>")
3162 (setq org-par-open t))
3163 (defun org-close-par-maybe ()
3164 "Close paragraph if there is one open."
3165 (when org-par-open
3166 (insert "</p>")
3167 (setq org-par-open nil)))
3168 (defun org-close-li ()
3169 "Close <li> if necessary."
3170 (org-close-par-maybe)
3171 (insert "</li>\n"))
3173 (defvar body-only) ; dynamically scoped into this.
3174 (defun org-html-level-start (level title umax with-toc head-count)
3175 "Insert a new level in HTML export.
3176 When TITLE is nil, just close all open levels."
3177 (org-close-par-maybe)
3178 (let ((l org-level-max) snumber)
3179 (while (>= l level)
3180 (if (aref org-levels-open (1- l))
3181 (progn
3182 (org-html-level-close l umax)
3183 (aset org-levels-open (1- l) nil)))
3184 (setq l (1- l)))
3185 (when title
3186 ;; If title is nil, this means this function is called to close
3187 ;; all levels, so the rest is done only if title is given
3188 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3189 (setq title (replace-match
3190 (if org-export-with-tags
3191 (save-match-data
3192 (concat
3193 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3194 (mapconcat 'identity (org-split-string
3195 (match-string 1 title) ":")
3196 "&nbsp;")
3197 "</span>"))
3199 t t title)))
3200 (if (> level umax)
3201 (progn
3202 (if (aref org-levels-open (1- level))
3203 (progn
3204 (org-close-li)
3205 (insert "<li>" title "<br/>\n"))
3206 (aset org-levels-open (1- level) t)
3207 (org-close-par-maybe)
3208 (insert "<ul>\n<li>" title "<br/>\n")))
3209 (aset org-levels-open (1- level) t)
3210 (setq snumber (org-section-number level))
3211 (if (and org-export-with-section-numbers (not body-only))
3212 (setq title (concat snumber " " title)))
3213 (setq level (+ level org-export-html-toplevel-hlevel -1))
3214 (unless (= head-count 1) (insert "\n</div>\n"))
3215 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s</h%d>\n<div id=\"text-%s\">\n"
3216 snumber level level snumber title level snumber))
3217 (org-open-par)))))
3219 (defun org-html-level-close (level max-outline-level)
3220 "Terminate one level in HTML export."
3221 (if (<= level max-outline-level)
3222 (insert "</div>\n")
3223 (org-close-li)
3224 (insert "</ul>\n")))
3226 ;;; iCalendar export
3228 ;;;###autoload
3229 (defun org-export-icalendar-this-file ()
3230 "Export current file as an iCalendar file.
3231 The iCalendar file will be located in the same directory as the Org-mode
3232 file, but with extension `.ics'."
3233 (interactive)
3234 (org-export-icalendar nil buffer-file-name))
3236 ;;;###autoload
3237 (defun org-export-icalendar-all-agenda-files ()
3238 "Export all files in `org-agenda-files' to iCalendar .ics files.
3239 Each iCalendar file will be located in the same directory as the Org-mode
3240 file, but with extension `.ics'."
3241 (interactive)
3242 (apply 'org-export-icalendar nil (org-agenda-files t)))
3244 ;;;###autoload
3245 (defun org-export-icalendar-combine-agenda-files ()
3246 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3247 The file is stored under the name `org-combined-agenda-icalendar-file'."
3248 (interactive)
3249 (apply 'org-export-icalendar t (org-agenda-files t)))
3251 (defun org-export-icalendar (combine &rest files)
3252 "Create iCalendar files for all elements of FILES.
3253 If COMBINE is non-nil, combine all calendar entries into a single large
3254 file and store it under the name `org-combined-agenda-icalendar-file'."
3255 (save-excursion
3256 (org-prepare-agenda-buffers files)
3257 (let* ((dir (org-export-directory
3258 :ical (list :publishing-directory
3259 org-export-publishing-directory)))
3260 file ical-file ical-buffer category started org-agenda-new-buffers)
3261 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3262 (when combine
3263 (setq ical-file
3264 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3265 org-combined-agenda-icalendar-file
3266 (expand-file-name org-combined-agenda-icalendar-file dir))
3267 ical-buffer (org-get-agenda-file-buffer ical-file))
3268 (set-buffer ical-buffer) (erase-buffer))
3269 (while (setq file (pop files))
3270 (catch 'nextfile
3271 (org-check-agenda-file file)
3272 (set-buffer (org-get-agenda-file-buffer file))
3273 (unless combine
3274 (setq ical-file (concat (file-name-as-directory dir)
3275 (file-name-sans-extension
3276 (file-name-nondirectory buffer-file-name))
3277 ".ics"))
3278 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3279 (with-current-buffer ical-buffer (erase-buffer)))
3280 (setq category (or org-category
3281 (file-name-sans-extension
3282 (file-name-nondirectory buffer-file-name))))
3283 (if (symbolp category) (setq category (symbol-name category)))
3284 (let ((standard-output ical-buffer))
3285 (if combine
3286 (and (not started) (setq started t)
3287 (org-start-icalendar-file org-icalendar-combined-name))
3288 (org-start-icalendar-file category))
3289 (org-print-icalendar-entries combine)
3290 (when (or (and combine (not files)) (not combine))
3291 (org-finish-icalendar-file)
3292 (set-buffer ical-buffer)
3293 (save-buffer)
3294 (run-hooks 'org-after-save-iCalendar-file-hook)))))
3295 (org-release-buffers org-agenda-new-buffers))))
3297 (defvar org-after-save-iCalendar-file-hook nil
3298 "Hook run after an iCalendar file has been saved.
3299 The iCalendar buffer is still current when this hook is run.
3300 A good way to use this is to tell a desktop calenndar application to re-read
3301 the iCalendar file.")
3303 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3304 (defun org-print-icalendar-entries (&optional combine)
3305 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3306 When COMBINE is non nil, add the category to each line."
3307 (require 'org-agenda)
3308 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3309 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3310 (dts (org-ical-ts-to-string
3311 (format-time-string (cdr org-time-stamp-formats) (current-time))
3312 "DTSTART"))
3313 hd ts ts2 state status (inc t) pos b sexp rrule
3314 scheduledp deadlinep tmp pri category entry location summary desc
3315 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3316 (org-refresh-category-properties)
3317 (save-excursion
3318 (goto-char (point-min))
3319 (while (re-search-forward re1 nil t)
3320 (catch :skip
3321 (org-agenda-skip)
3322 (when (boundp 'org-icalendar-verify-function)
3323 (unless (funcall org-icalendar-verify-function)
3324 (outline-next-heading)
3325 (backward-char 1)
3326 (throw :skip nil)))
3327 (setq pos (match-beginning 0)
3328 ts (match-string 0)
3329 inc t
3330 hd (condition-case nil (org-get-heading)
3331 (error (throw :skip nil)))
3332 summary (org-icalendar-cleanup-string
3333 (org-entry-get nil "SUMMARY"))
3334 desc (org-icalendar-cleanup-string
3335 (or (org-entry-get nil "DESCRIPTION")
3336 (and org-icalendar-include-body (org-get-entry)))
3337 t org-icalendar-include-body)
3338 location (org-icalendar-cleanup-string
3339 (org-entry-get nil "LOCATION"))
3340 category (org-get-category))
3341 (if (looking-at re2)
3342 (progn
3343 (goto-char (match-end 0))
3344 (setq ts2 (match-string 1) inc nil))
3345 (setq tmp (buffer-substring (max (point-min)
3346 (- pos org-ds-keyword-length))
3347 pos)
3348 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3349 (progn
3350 (setq inc nil)
3351 (replace-match "\\1" t nil ts))
3353 deadlinep (string-match org-deadline-regexp tmp)
3354 scheduledp (string-match org-scheduled-regexp tmp)
3355 ;; donep (org-entry-is-done-p)
3357 (if (or (string-match org-tr-regexp hd)
3358 (string-match org-ts-regexp hd))
3359 (setq hd (replace-match "" t t hd)))
3360 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3361 (setq rrule
3362 (concat "\nRRULE:FREQ="
3363 (cdr (assoc
3364 (match-string 2 ts)
3365 '(("d" . "DAILY")("w" . "WEEKLY")
3366 ("m" . "MONTHLY")("y" . "YEARLY"))))
3367 ";INTERVAL=" (match-string 1 ts)))
3368 (setq rrule ""))
3369 (setq summary (or summary hd))
3370 (if (string-match org-bracket-link-regexp summary)
3371 (setq summary
3372 (replace-match (if (match-end 3)
3373 (match-string 3 summary)
3374 (match-string 1 summary))
3375 t t summary)))
3376 (if deadlinep (setq summary (concat "DL: " summary)))
3377 (if scheduledp (setq summary (concat "S: " summary)))
3378 (if (string-match "\\`<%%" ts)
3379 (with-current-buffer sexp-buffer
3380 (insert (substring ts 1 -1) " " summary "\n"))
3381 (princ (format "BEGIN:VEVENT
3383 %s%s
3384 SUMMARY:%s%s%s
3385 CATEGORIES:%s
3386 END:VEVENT\n"
3387 (org-ical-ts-to-string ts "DTSTART")
3388 (org-ical-ts-to-string ts2 "DTEND" inc)
3389 rrule summary
3390 (if (and desc (string-match "\\S-" desc))
3391 (concat "\nDESCRIPTION: " desc) "")
3392 (if (and location (string-match "\\S-" location))
3393 (concat "\nLOCATION: " location) "")
3394 category)))))
3396 (when (and org-icalendar-include-sexps
3397 (condition-case nil (require 'icalendar) (error nil))
3398 (fboundp 'icalendar-export-region))
3399 ;; Get all the literal sexps
3400 (goto-char (point-min))
3401 (while (re-search-forward "^&?%%(" nil t)
3402 (catch :skip
3403 (org-agenda-skip)
3404 (setq b (match-beginning 0))
3405 (goto-char (1- (match-end 0)))
3406 (forward-sexp 1)
3407 (end-of-line 1)
3408 (setq sexp (buffer-substring b (point)))
3409 (with-current-buffer sexp-buffer
3410 (insert sexp "\n"))
3411 (princ (org-diary-to-ical-string sexp-buffer)))))
3413 (when org-icalendar-include-todo
3414 (goto-char (point-min))
3415 (while (re-search-forward org-todo-line-regexp nil t)
3416 (catch :skip
3417 (org-agenda-skip)
3418 (when (boundp 'org-icalendar-verify-function)
3419 (unless (funcall org-icalendar-verify-function)
3420 (outline-next-heading)
3421 (backward-char 1)
3422 (throw :skip nil)))
3423 (setq state (match-string 2))
3424 (setq status (if (member state org-done-keywords)
3425 "COMPLETED" "NEEDS-ACTION"))
3426 (when (and state
3427 (or (not (member state org-done-keywords))
3428 (eq org-icalendar-include-todo 'all))
3429 (not (member org-archive-tag (org-get-tags-at)))
3431 (setq hd (match-string 3)
3432 summary (org-icalendar-cleanup-string
3433 (org-entry-get nil "SUMMARY"))
3434 desc (org-icalendar-cleanup-string
3435 (or (org-entry-get nil "DESCRIPTION")
3436 (and org-icalendar-include-body (org-get-entry)))
3437 t org-icalendar-include-body)
3438 location (org-icalendar-cleanup-string
3439 (org-entry-get nil "LOCATION")))
3440 (if (string-match org-bracket-link-regexp hd)
3441 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
3442 (match-string 1 hd))
3443 t t hd)))
3444 (if (string-match org-priority-regexp hd)
3445 (setq pri (string-to-char (match-string 2 hd))
3446 hd (concat (substring hd 0 (match-beginning 1))
3447 (substring hd (match-end 1))))
3448 (setq pri org-default-priority))
3449 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
3450 (- org-lowest-priority org-highest-priority))))))
3452 (princ (format "BEGIN:VTODO
3454 SUMMARY:%s%s%s
3455 CATEGORIES:%s
3456 SEQUENCE:1
3457 PRIORITY:%d
3458 STATUS:%s
3459 END:VTODO\n"
3461 (or summary hd)
3462 (if (and location (string-match "\\S-" location))
3463 (concat "\nLOCATION: " location) "")
3464 (if (and desc (string-match "\\S-" desc))
3465 (concat "\nDESCRIPTION: " desc) "")
3466 category pri status)))))))))
3468 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
3469 "Take out stuff and quote what needs to be quoted.
3470 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3471 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3472 characters."
3473 (if (not s)
3475 (when is-body
3476 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
3477 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
3478 (while (string-match re s) (setq s (replace-match "" t t s)))
3479 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
3480 (let ((start 0))
3481 (while (string-match "\\([,;\\]\\)" s start)
3482 (setq start (+ (match-beginning 0) 2)
3483 s (replace-match "\\\\\\1" nil nil s))))
3484 (when is-body
3485 (while (string-match "[ \t]*\n[ \t]*" s)
3486 (setq s (replace-match "\\n" t t s))))
3487 (setq s (org-trim s))
3488 (if is-body
3489 (if maxlength
3490 (if (and (numberp maxlength)
3491 (> (length s) maxlength))
3492 (setq s (substring s 0 maxlength)))))
3495 (defun org-get-entry ()
3496 "Clean-up description string."
3497 (save-excursion
3498 (org-back-to-heading t)
3499 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
3501 (defun org-start-icalendar-file (name)
3502 "Start an iCalendar file by inserting the header."
3503 (let ((user user-full-name)
3504 (name (or name "unknown"))
3505 (timezone (cadr (current-time-zone))))
3506 (princ
3507 (format "BEGIN:VCALENDAR
3508 VERSION:2.0
3509 X-WR-CALNAME:%s
3510 PRODID:-//%s//Emacs with Org-mode//EN
3511 X-WR-TIMEZONE:%s
3512 CALSCALE:GREGORIAN\n" name user timezone))))
3514 (defun org-finish-icalendar-file ()
3515 "Finish an iCalendar file by inserting the END statement."
3516 (princ "END:VCALENDAR\n"))
3518 (defun org-ical-ts-to-string (s keyword &optional inc)
3519 "Take a time string S and convert it to iCalendar format.
3520 KEYWORD is added in front, to make a complete line like DTSTART....
3521 When INC is non-nil, increase the hour by two (if time string contains
3522 a time), or the day by one (if it does not contain a time)."
3523 (let ((t1 (org-parse-time-string s 'nodefault))
3524 t2 fmt have-time time)
3525 (if (and (car t1) (nth 1 t1) (nth 2 t1))
3526 (setq t2 t1 have-time t)
3527 (setq t2 (org-parse-time-string s)))
3528 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
3529 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
3530 (when inc
3531 (if have-time
3532 (if org-agenda-default-appointment-duration
3533 (setq mi (+ org-agenda-default-appointment-duration mi))
3534 (setq h (+ 2 h)))
3535 (setq d (1+ d))))
3536 (setq time (encode-time s mi h d m y)))
3537 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3538 (concat keyword (format-time-string fmt time))))
3540 ;;; XOXO export
3542 (defun org-export-as-xoxo-insert-into (buffer &rest output)
3543 (with-current-buffer buffer
3544 (apply 'insert output)))
3545 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
3547 ;;;###autoload
3548 (defun org-export-as-xoxo (&optional buffer)
3549 "Export the org buffer as XOXO.
3550 The XOXO buffer is named *xoxo-<source buffer name>*"
3551 (interactive (list (current-buffer)))
3552 ;; A quickie abstraction
3554 ;; Output everything as XOXO
3555 (with-current-buffer (get-buffer buffer)
3556 (let* ((pos (point))
3557 (opt-plist (org-combine-plists (org-default-export-plist)
3558 (org-infile-export-plist)))
3559 (filename (concat (file-name-as-directory
3560 (org-export-directory :xoxo opt-plist))
3561 (file-name-sans-extension
3562 (file-name-nondirectory buffer-file-name))
3563 ".html"))
3564 (out (find-file-noselect filename))
3565 (last-level 1)
3566 (hanging-li nil))
3567 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3568 ;; Check the output buffer is empty.
3569 (with-current-buffer out (erase-buffer))
3570 ;; Kick off the output
3571 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
3572 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
3573 (let* ((hd (match-string-no-properties 1))
3574 (level (length hd))
3575 (text (concat
3576 (match-string-no-properties 2)
3577 (save-excursion
3578 (goto-char (match-end 0))
3579 (let ((str ""))
3580 (catch 'loop
3581 (while 't
3582 (forward-line)
3583 (if (looking-at "^[ \t]\\(.*\\)")
3584 (setq str (concat str (match-string-no-properties 1)))
3585 (throw 'loop str)))))))))
3587 ;; Handle level rendering
3588 (cond
3589 ((> level last-level)
3590 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
3592 ((< level last-level)
3593 (dotimes (- (- last-level level) 1)
3594 (if hanging-li
3595 (org-export-as-xoxo-insert-into out "</li>\n"))
3596 (org-export-as-xoxo-insert-into out "</ol>\n"))
3597 (when hanging-li
3598 (org-export-as-xoxo-insert-into out "</li>\n")
3599 (setq hanging-li nil)))
3601 ((equal level last-level)
3602 (if hanging-li
3603 (org-export-as-xoxo-insert-into out "</li>\n")))
3606 (setq last-level level)
3608 ;; And output the new li
3609 (setq hanging-li 't)
3610 (if (equal ?+ (elt text 0))
3611 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
3612 (org-export-as-xoxo-insert-into out "<li>" text))))
3614 ;; Finally finish off the ol
3615 (dotimes (- last-level 1)
3616 (if hanging-li
3617 (org-export-as-xoxo-insert-into out "</li>\n"))
3618 (org-export-as-xoxo-insert-into out "</ol>\n"))
3620 (goto-char pos)
3621 ;; Finish the buffer off and clean it up.
3622 (switch-to-buffer-other-window out)
3623 (indent-region (point-min) (point-max) nil)
3624 (save-buffer)
3625 (goto-char (point-min))
3628 (provide 'org-exp)
3630 ;;; org-exp.el ends here
3633 (defun org-export-process-option-filters (plist)
3634 (let ((functions org-export-options-filters) f)
3635 (while (setq f (pop functions))
3636 (setq plist (funcall f plist))))
3637 plist)