1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
37 (defgroup org-export nil
38 "Options for exporting org-listings."
42 (defgroup org-export-general nil
43 "General options for exporting Org-mode files."
44 :tag
"Org Export General"
48 (defvar org-export-publishing-directory nil
)
50 (defcustom org-export-run-in-background nil
51 "Non-nil means export and publishing commands will run in background.
52 This works by starting up a separate Emacs process visiting the same file
53 and doing the export from there.
54 Not all export commands are affected by this - only the ones which
55 actually write to a file, and that do not depend on the buffer state.
57 If this option is nil, you can still get background export by calling
58 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
60 If this option is t, the double prefix can be used to exceptionally
61 force an export command into the current process."
62 :group
'org-export-general
65 (defcustom org-export-with-special-strings t
66 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
67 When this option is turned on, these strings will be exported as:
70 -----+----------+--------
76 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
77 :group
'org-export-translation
80 (defcustom org-export-language-setup
81 '(("en" "Author" "Date" "Table of Contents")
82 ("cs" "Autor" "Datum" "Obsah")
83 ("da" "Ophavsmand" "Dato" "Indhold")
84 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
85 ("es" "Autor" "Fecha" "\xcdndice")
86 ("fr" "Auteur" "Date" "Table des mati\xe8res")
87 ("it" "Autore" "Data" "Indice")
88 ("nl" "Auteur" "Datum" "Inhoudsopgave")
89 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
90 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
91 "Terms used in export text, translated to different languages.
92 Use the variable `org-export-default-language' to set the language,
93 or use the +OPTION lines for a per-file setting."
94 :group
'org-export-general
97 (string :tag
"HTML language tag")
98 (string :tag
"Author")
100 (string :tag
"Table of Contents"))))
102 (defcustom org-export-default-language
"en"
103 "The default language of HTML export, as a string.
104 This should have an association in `org-export-language-setup'."
105 :group
'org-export-general
108 (defcustom org-export-skip-text-before-1st-heading nil
109 "Non-nil means, skip all text before the first headline when exporting.
110 When nil, that text is exported as well."
111 :group
'org-export-general
114 (defcustom org-export-headline-levels
3
115 "The last level which is still exported as a headline.
116 Inferior levels will produce itemize lists when exported.
117 Note that a numeric prefix argument to an exporter function overrides
120 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
121 :group
'org-export-general
124 (defcustom org-export-with-section-numbers t
125 "Non-nil means, add section numbers to headlines when exporting.
127 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
128 :group
'org-export-general
131 (defcustom org-export-with-toc t
132 "Non-nil means, create a table of contents in exported files.
133 The TOC contains headlines with levels up to`org-export-headline-levels'.
134 When an integer, include levels up to N in the toc, this may then be
135 different from `org-export-headline-levels', but it will not be allowed
136 to be larger than the number of headline levels.
137 When nil, no table of contents is made.
139 Headlines which contain any TODO items will be marked with \"(*)\" in
140 ASCII export, and with red color in HTML output, if the option
141 `org-export-mark-todo-in-toc' is set.
143 In HTML output, the TOC will be clickable.
145 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
147 :group
'org-export-general
149 (const :tag
"No Table of Contents" nil
)
150 (const :tag
"Full Table of Contents" t
)
151 (integer :tag
"TOC to level")))
153 (defcustom org-export-mark-todo-in-toc nil
154 "Non-nil means, mark TOC lines that contain any open TODO items."
155 :group
'org-export-general
158 (defcustom org-export-preserve-breaks nil
159 "Non-nil means, preserve all line breaks when exporting.
160 Normally, in HTML output paragraphs will be reformatted. In ASCII
161 export, line breaks will always be preserved, regardless of this variable.
163 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
164 :group
'org-export-general
167 (defcustom org-export-with-archived-trees
'headline
168 "Whether subtrees with the ARCHIVE tag should be exported.
169 This can have three different values
170 nil Do not export, pretend this tree is not present
171 t Do export the entire tree
172 headline Only export the headline, but skip the tree below it."
173 :group
'org-export-general
176 (const :tag
"not at all" nil
)
177 (const :tag
"headline only" 'headline
)
178 (const :tag
"entirely" t
)))
180 (defcustom org-export-author-info t
181 "Non-nil means, insert author name and email into the exported file.
183 This option can also be set with the +OPTIONS line,
184 e.g. \"author-info:nil\"."
185 :group
'org-export-general
188 (defcustom org-export-time-stamp-file t
189 "Non-nil means, insert a time stamp into the exported file.
190 The time stamp shows when the file was created.
192 This option can also be set with the +OPTIONS line,
193 e.g. \"timestamp:nil\"."
194 :group
'org-export-general
197 (defcustom org-export-with-timestamps t
198 "If nil, do not export time stamps and associated keywords."
199 :group
'org-export-general
202 (defcustom org-export-remove-timestamps-from-toc t
203 "If nil, remove timestamps from the table of contents entries."
204 :group
'org-export-general
207 (defcustom org-export-with-tags
'not-in-toc
208 "If nil, do not export tags, just remove them from headlines.
209 If this is the symbol `not-in-toc', tags will be removed from table of
210 contents entries, but still be shown in the headlines of the document.
212 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
213 :group
'org-export-general
215 (const :tag
"Off" nil
)
216 (const :tag
"Not in TOC" not-in-toc
)
217 (const :tag
"On" t
)))
219 (defcustom org-export-with-drawers nil
220 "Non-nil means, export with drawers like the property drawer.
221 When t, all drawers are exported. This may also be a list of
222 drawer names to export."
223 :group
'org-export-general
225 (const :tag
"All drawers" t
)
226 (const :tag
"None" nil
)
227 (repeat :tag
"Selected drawers"
228 (string :tag
"Drawer name"))))
230 (defvar org-export-preprocess-hook nil
231 "Hook for preprocessing an export buffer.
232 Pretty much the first thing when exporting is running this hook.")
234 (defgroup org-export-translation nil
235 "Options for translating special ascii sequences for the export backends."
236 :tag
"Org Export Translation"
239 (defcustom org-export-with-emphasize t
240 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
241 If the export target supports emphasizing text, the word will be
242 typeset in bold, italic, or underlined, respectively. Works only for
243 single words, but you can say: I *really* *mean* *this*.
244 Not all export backends support this.
246 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
247 :group
'org-export-translation
250 (defcustom org-export-with-footnotes t
251 "If nil, export [1] as a footnote marker.
252 Lines starting with [1] will be formatted as footnotes.
254 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
255 :group
'org-export-translation
258 (defcustom org-export-with-sub-superscripts t
259 "Non-nil means, interpret \"_\" and \"^\" for export.
260 When this option is turned on, you can use TeX-like syntax for sub- and
261 superscripts. Several characters after \"_\" or \"^\" will be
262 considered as a single item - so grouping with {} is normally not
263 needed. For example, the following things will be parsed as single
264 sub- or superscripts.
266 10^24 or 10^tau several digits will be considered 1 item.
267 10^-12 or 10^-tau a leading sign with digits or a word
268 x^2-y^3 will be read as x^2 - y^3, because items are
269 terminated by almost any nonword/nondigit char.
270 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
272 Still, ambiguity is possible - so when in doubt use {} to enclose the
273 sub/superscript. If you set this variable to the symbol `{}',
274 the braces are *required* in order to trigger interpretations as
275 sub/superscript. This can be helpful in documents that need \"_\"
276 frequently in plain text.
278 Not all export backends support this, but HTML does.
280 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
281 :group
'org-export-translation
283 (const :tag
"Always interpret" t
)
284 (const :tag
"Only with braces" {})
285 (const :tag
"Never interpret" nil
)))
287 (defcustom org-export-with-special-strings t
288 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
289 When this option is turned on, these strings will be exported as:
295 Not all export backends support this, but HTML does.
297 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
298 :group
'org-export-translation
301 (defcustom org-export-with-TeX-macros t
302 "Non-nil means, interpret simple TeX-like macros when exporting.
303 For example, HTML export converts \\alpha to α and \\AA to Å.
304 No only real TeX macros will work here, but the standard HTML entities
305 for math can be used as macro names as well. For a list of supported
306 names in HTML export, see the constant `org-html-entities'.
307 Not all export backends support this.
309 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
310 :group
'org-export-translation
311 :group
'org-export-latex
314 (defcustom org-export-with-LaTeX-fragments nil
315 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
316 When set, the exporter will find LaTeX environments if the \\begin line is
317 the first non-white thing on a line. It will also find the math delimiters
318 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
321 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
322 :group
'org-export-translation
323 :group
'org-export-latex
326 (defcustom org-export-with-fixed-width t
327 "Non-nil means, lines starting with \":\" will be in fixed width font.
328 This can be used to have pre-formatted text, fragments of code etc. For
330 : ;; Some Lisp examples
333 will be looking just like this in also HTML. See also the QUOTE keyword.
334 Not all export backends support this.
336 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
337 :group
'org-export-translation
340 (defcustom org-match-sexp-depth
3
341 "Number of stacked braces for sub/superscript matching.
342 This has to be set before loading org.el to be effective."
343 :group
'org-export-translation
346 (defgroup org-export-tables nil
347 "Options for exporting tables in Org-mode."
348 :tag
"Org Export Tables"
351 (defcustom org-export-with-tables t
352 "If non-nil, lines starting with \"|\" define a table.
355 | Name | Address | Birthday |
356 |-------------+----------+-----------|
357 | Arthur Dent | England | 29.2.2100 |
359 Not all export backends support this.
361 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
362 :group
'org-export-tables
365 (defcustom org-export-highlight-first-table-line t
366 "Non-nil means, highlight the first table line.
367 In HTML export, this means use <th> instead of <td>.
368 In tables created with table.el, this applies to the first table line.
369 In Org-mode tables, all lines before the first horizontal separator
370 line will be formatted with <th> tags."
371 :group
'org-export-tables
374 (defcustom org-export-table-remove-special-lines t
375 "Remove special lines and marking characters in calculating tables.
376 This removes the special marking character column from tables that are set
377 up for spreadsheet calculations. It also removes the entire lines
378 marked with `!', `_', or `^'. The lines with `$' are kept, because
379 the values of constants may be useful to have."
380 :group
'org-export-tables
383 (defcustom org-export-prefer-native-exporter-for-tables nil
384 "Non-nil means, always export tables created with table.el natively.
385 Natively means, use the HTML code generator in table.el.
386 When nil, Org-mode's own HTML generator is used when possible (i.e. if
387 the table does not use row- or column-spanning). This has the
388 advantage, that the automatic HTML conversions for math symbols and
389 sub/superscripts can be applied. Org-mode's HTML generator is also
391 :group
'org-export-tables
394 (defgroup org-export-ascii nil
395 "Options specific for ASCII export of Org-mode files."
396 :tag
"Org Export ASCII"
399 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
400 "Characters for underlining headings in ASCII export.
401 In the given sequence, these characters will be used for level 1, 2, ..."
402 :group
'org-export-ascii
403 :type
'(repeat character
))
405 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
406 "Bullet characters for headlines converted to lists in ASCII export.
407 The first character is used for the first lest level generated in this
408 way, and so on. If there are more levels than characters given here,
409 the list will be repeated.
410 Note that plain lists will keep the same bullets as the have in the
412 :group
'org-export-ascii
413 :type
'(repeat character
))
415 (defgroup org-export-xml nil
416 "Options specific for XML export of Org-mode files."
417 :tag
"Org Export XML"
420 (defgroup org-export-html nil
421 "Options specific for HTML export of Org-mode files."
422 :tag
"Org Export HTML"
425 (defcustom org-export-html-coding-system nil
426 "Coding system for HTML export, defaults to buffer-file-coding-system."
427 :group
'org-export-html
428 :type
'coding-system
)
430 (defcustom org-export-html-extension
"html"
431 "The extension for exported HTML files."
432 :group
'org-export-html
435 (defcustom org-export-html-link-up
""
436 "Where should the \"UP\" link of exported HTML pages lead?"
437 :group
'org-export-html
438 :type
'(string :tag
"File or URL"))
440 (defcustom org-export-html-link-home
""
441 "Where should the \"HOME\" link of exported HTML pages lead?"
442 :group
'org-export-html
443 :type
'(string :tag
"File or URL"))
445 (defcustom org-export-html-style
446 "<style type=\"text/css\">
448 font-family: Times, serif;
451 .title { text-align: center; }
452 .todo { color: red; }
453 .done { color: green; }
454 .timestamp { color: grey }
455 .timestamp-kwd { color: CadetBlue }
456 .tag { background-color:lightblue; font-weight:normal }
459 border: 1pt solid #AEBDCC;
460 background-color: #F3F5F7;
462 font-family: courier, monospace;
464 table { border-collapse: collapse; }
467 <!--border: 1pt solid #ADB9CC;-->
469 dt { font-weight: bold; }
471 "The default style specification for exported HTML files.
472 Since there are different ways of setting style information, this variable
473 needs to contain the full HTML structure to provide a style, including the
474 surrounding HTML tags. The style specifications should include definitions
475 for new classes todo, done, title, and deadline. For example, valid values
478 <style type=\"text/css\">
479 p { font-weight: normal; color: gray; }
481 .title { text-align: center; }
482 .todo, .deadline { color: red; }
483 .done { color: green; }
486 or, if you want to keep the style in a file,
488 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
490 As the value of this option simply gets inserted into the HTML <head> header,
491 you can \"misuse\" it to add arbitrary text to the header."
492 :group
'org-export-html
496 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
497 "Format for typesetting the document title in HTML export."
498 :group
'org-export-html
501 (defcustom org-export-html-toplevel-hlevel
2
502 "The <H> level for level 1 headings in HTML export."
503 :group
'org-export-html
506 (defcustom org-export-html-link-org-files-as-html t
507 "Non-nil means, make file links to `file.org' point to `file.html'.
508 When org-mode is exporting an org-mode file to HTML, links to
509 non-html files are directly put into a href tag in HTML.
510 However, links to other Org-mode files (recognized by the
511 extension `.org.) should become links to the corresponding html
512 file, assuming that the linked org-mode file will also be
514 When nil, the links still point to the plain `.org' file."
515 :group
'org-export-html
518 (defcustom org-export-html-inline-images
'maybe
519 "Non-nil means, inline images into exported HTML pages.
520 This is done using an <img> tag. When nil, an anchor with href is used to
521 link to the image. If this option is `maybe', then images in links with
522 an empty description will be inlined, while images with a description will
524 :group
'org-export-html
525 :type
'(choice (const :tag
"Never" nil
)
526 (const :tag
"Always" t
)
527 (const :tag
"When there is no description" maybe
)))
530 (defcustom org-export-html-expand t
531 "Non-nil means, for HTML export, treat @<...> as HTML tag.
532 When nil, these tags will be exported as plain text and therefore
533 not be interpreted by a browser.
535 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
536 :group
'org-export-html
539 (defcustom org-export-html-table-tag
540 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
541 "The HTML tag that is used to start a table.
542 This must be a <table> tag, but you may change the options like
543 borders and spacing."
544 :group
'org-export-html
547 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
548 "The opening tag for table header fields.
549 This is customizable so that alignment options can be specified."
550 :group
'org-export-tables
551 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
553 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
554 "The opening tag for table data fields.
555 This is customizable so that alignment options can be specified."
556 :group
'org-export-tables
557 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
559 (defcustom org-export-html-with-timestamp nil
560 "If non-nil, write `org-export-html-html-helper-timestamp'
561 into the exported HTML text. Otherwise, the buffer will just be saved
563 :group
'org-export-html
566 (defcustom org-export-html-html-helper-timestamp
567 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
568 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
569 :group
'org-export-html
572 (defgroup org-export-icalendar nil
573 "Options specific for iCalendar export of Org-mode files."
574 :tag
"Org Export iCalendar"
577 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
578 "The file name for the iCalendar file covering all agenda files.
579 This file is created with the command \\[org-export-icalendar-all-agenda-files].
580 The file name should be absolute, the file will be overwritten without warning."
581 :group
'org-export-icalendar
584 (defcustom org-icalendar-include-todo nil
585 "Non-nil means, export to iCalendar files should also cover TODO items."
586 :group
'org-export-icalendar
588 (const :tag
"None" nil
)
589 (const :tag
"Unfinished" t
)
590 (const :tag
"All" all
)))
592 (defcustom org-icalendar-include-sexps t
593 "Non-nil means, export to iCalendar files should also cover sexp entries.
594 These are entries like in the diary, but directly in an Org-mode file."
595 :group
'org-export-icalendar
598 (defcustom org-icalendar-include-body
100
599 "Amount of text below headline to be included in iCalendar export.
600 This is a number of characters that should maximally be included.
601 Properties, scheduling and clocking lines will always be removed.
602 The text will be inserted into the DESCRIPTION field."
603 :group
'org-export-icalendar
605 (const :tag
"Nothing" nil
)
606 (const :tag
"Everything" t
)
607 (integer :tag
"Max characters")))
609 (defcustom org-icalendar-combined-name
"OrgMode"
610 "Calendar name for the combined iCalendar representing all agenda files."
611 :group
'org-export-icalendar
616 ;;; Variables, constants, and parameter plists
618 (defconst org-level-max
20)
620 (defvar org-export-html-preamble nil
621 "Preamble, to be inserted just after <body>. Set by publishing functions.")
622 (defvar org-export-html-postamble nil
623 "Preamble, to be inserted just before </body>. Set by publishing functions.")
624 (defvar org-export-html-auto-preamble t
625 "Should default preamble be inserted? Set by publishing functions.")
626 (defvar org-export-html-auto-postamble t
627 "Should default postamble be inserted? Set by publishing functions.")
628 (defvar org-current-export-file nil
) ; dynamically scoped parameter
629 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
631 (defconst org-export-plist-vars
632 '((:link-up . org-export-html-link-up
)
633 (:link-home . org-export-html-link-home
)
634 (:language . org-export-default-language
)
635 (:customtime . org-display-custom-times
)
636 (:headline-levels . org-export-headline-levels
)
637 (:section-numbers . org-export-with-section-numbers
)
638 (:table-of-contents . org-export-with-toc
)
639 (:preserve-breaks . org-export-preserve-breaks
)
640 (:archived-trees . org-export-with-archived-trees
)
641 (:emphasize . org-export-with-emphasize
)
642 (:sub-superscript . org-export-with-sub-superscripts
)
643 (:special-strings . org-export-with-special-strings
)
644 (:footnotes . org-export-with-footnotes
)
645 (:drawers . org-export-with-drawers
)
646 (:tags . org-export-with-tags
)
647 (:TeX-macros . org-export-with-TeX-macros
)
648 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
649 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
650 (:fixed-width . org-export-with-fixed-width
)
651 (:timestamps . org-export-with-timestamps
)
652 (:author-info . org-export-author-info
)
653 (:time-stamp-file . org-export-time-stamp-file
)
654 (:tables . org-export-with-tables
)
655 (:table-auto-headline . org-export-highlight-first-table-line
)
656 (:style . org-export-html-style
)
657 (:agenda-style . org-agenda-export-html-style
)
658 (:convert-org-links . org-export-html-link-org-files-as-html
)
659 (:inline-images . org-export-html-inline-images
)
660 (:html-extension . org-export-html-extension
)
661 (:html-table-tag . org-export-html-table-tag
)
662 (:expand-quoted-html . org-export-html-expand
)
663 (:timestamp . org-export-html-with-timestamp
)
664 (:publishing-directory . org-export-publishing-directory
)
665 (:preamble . org-export-html-preamble
)
666 (:postamble . org-export-html-postamble
)
667 (:auto-preamble . org-export-html-auto-preamble
)
668 (:auto-postamble . org-export-html-auto-postamble
)
669 (:author . user-full-name
)
670 (:email . user-mail-address
)))
672 (defun org-default-export-plist ()
673 "Return the property list with default settings for the export variables."
674 (let ((l org-export-plist-vars
) rtn e
)
675 (while (setq e
(pop l
))
676 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
679 (defvar org-export-inbuffer-options-extra nil
680 "List of additional in-buffer options that should be detected.
681 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
682 etc. Extensions can add to this list to get their options detected, and they
683 can then add a function to `org-export-options-filters' to process these
685 Each element in this list must be a list, with the in-buffer keyword as car,
686 and a property (a symbol) as the next element. All occurences of the
687 keyword will be found, the values concatenated with a space character
688 in between, and the result stored in the export options property list.")
690 (defvar org-export-options-filters nil
691 "Functions to be called to finalize the export/publishing options.
692 All these options are stored in a property list, and each of the functions
693 in this hook gets a chance to modify this property list. Each function
694 must accept the property list as an argument, and must return the (possibly
697 (defun org-infile-export-plist ()
698 "Return the property list with file-local settings for export."
702 (goto-char (point-min))
703 (let ((re (org-make-options-regexp
705 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
706 "LINK_UP" "LINK_HOME" "SETUPFILE")
707 (mapcar 'car org-export-inbuffer-options-extra
))))
708 p key val text options js-up js-main js-css js-opt a pr
709 ext-setup-or-nil setup-contents
(start 0))
710 (while (or (and ext-setup-or-nil
711 (string-match re ext-setup-or-nil start
)
712 (setq start
(match-end 0)))
713 (and (setq ext-setup-or-nil nil start
0)
714 (re-search-forward re nil t
)))
715 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
716 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
718 ((setq a
(assoc key org-export-inbuffer-options-extra
))
720 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
721 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
722 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
723 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
724 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
725 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
726 ((string-equal key
"TEXT")
727 (setq text
(if text
(concat text
"\n" val
) val
)))
728 ((string-equal key
"OPTIONS")
729 (setq options
(concat val
" " options
)))
730 ((string-equal key
"LINK_UP")
731 (setq p
(plist-put p
:link-up val
)))
732 ((string-equal key
"LINK_HOME")
733 (setq p
(plist-put p
:link-home val
)))
734 ((equal key
"SETUPFILE")
735 (setq setup-contents
(org-file-contents
737 (org-remove-double-quotes
740 (if (not ext-setup-or-nil
)
741 (setq ext-setup-or-nil setup-contents start
0)
742 (setq ext-setup-or-nil
743 (concat (substring ext-setup-or-nil
0 start
)
744 "\n" setup-contents
"\n"
745 (substring ext-setup-or-nil start
)))))))
746 (setq p
(plist-put p
:text text
))
748 (let ((op '(("H" .
:headline-levels
)
749 ("num" .
:section-numbers
)
750 ("toc" .
:table-of-contents
)
751 ("\\n" .
:preserve-breaks
)
752 ("@" .
:expand-quoted-html
)
755 ("^" .
:sub-superscript
)
756 ("-" .
:special-strings
)
761 ("TeX" .
:TeX-macros
)
762 ("LaTeX" .
:LaTeX-fragments
)
763 ("skip" .
:skip-before-1st-heading
)
764 ("author" .
:author-info
)
765 ("timestamp" .
:time-stamp-file
)))
767 (while (setq o
(pop op
))
768 (if (string-match (concat (regexp-quote (car o
))
769 ":\\([^ \t\n\r;,.]*\\)")
771 (setq p
(plist-put p
(cdr o
)
772 (car (read-from-string
773 (match-string 1 options
)))))))))
776 (defun org-export-directory (type plist
)
777 (let* ((val (plist-get plist
:publishing-directory
))
779 (or (cdr (assoc type val
)) ".")
783 (defun org-export-process-option-filters (plist)
784 (let ((functions org-export-options-filters
) f
)
785 (while (setq f
(pop functions
))
786 (setq plist
(funcall f plist
))))
790 (defun org-export (&optional arg
)
791 "Export dispatcher for Org-mode.
792 When `org-export-run-in-background' is non-nil, try to run the command
793 in the background. This will be done only for commands that write
794 to a file. For details see the docstring of `org-export-run-in-background'.
796 The prefix argument ARG will be passed to the exporter. However, if
797 ARG is a double universal prefix `C-u C-u', that means to inverse the
798 value of `org-export-run-in-background'."
800 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
801 (help "[t] insert the export option template
802 \[v] limit export to visible part of outline tree
807 \[H] export as HTML to temporary buffer
808 \[R] export region as HTML
809 \[b] export as HTML and browse immediately
813 \[L] export as LaTeX to temporary buffer
815 \[i] export current file as iCalendar file
816 \[I] export all agenda files as iCalendar files
817 \[c] export agenda files into combined iCalendar file
819 \[F] publish current file
820 \[P] publish current project
821 \[X] publish... (project will be prompted for)
822 \[A] publish all projects")
824 '((?t org-insert-export-options-template nil
)
825 (?v org-export-visible nil
)
826 (?a org-export-as-ascii t
)
827 (?h org-export-as-html t
)
828 (?b org-export-as-html-and-open t
)
829 (?H org-export-as-html-to-buffer nil
)
830 (?R org-export-region-as-html nil
)
831 (?x org-export-as-xoxo t
)
832 (?l org-export-as-latex t
)
833 (?L org-export-as-latex-to-buffer nil
)
834 (?i org-export-icalendar-this-file t
)
835 (?I org-export-icalendar-all-agenda-files t
)
836 (?c org-export-icalendar-combine-agenda-files t
)
837 (?F org-publish-current-file t
)
838 (?P org-publish-current-project t
)
840 (?A org-publish-all t
)))
842 (save-window-excursion
843 (delete-other-windows)
844 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
846 (message "Select command: ")
847 (setq r1
(read-char-exclusive)))
848 (setq r2
(if (< r1
27) (+ r1
96) r1
))
849 (unless (setq ass
(assq r2 cmds
))
850 (error "No command associated with key %c" r1
))
851 (if (and bg
(nth 2 ass
))
852 ;; execute in background
853 (let ((p (start-process
854 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
856 (expand-file-name invocation-name invocation-directory
)
859 "--eval" "(require 'org-exp)"
860 "--eval" "(setq org-wait .2)"
862 "-f" (symbol-name (nth 1 ass
)))))
863 (set-process-sentinel p
'org-export-process-sentinel
)
864 (message "Background process \"%s\": started" p
))
865 ;; background processing not requested, or not possible
866 (call-interactively (nth 1 ass
)))))
868 (defun org-export-process-sentinel (process status
)
869 (if (string-match "\n+\\'" status
)
870 (setq status
(substring status
0 -
1)))
871 (message "Background process \"%s\": %s" process status
))
873 (defconst org-html-entities
914 ("Aring") ("AA".
"Å")
1003 ("varepsilon".
"ε")
1016 ("sigmaf") ("varsigma".
"ς")
1024 ("thetasym") ("vartheta".
"ϑ")
1027 ("bull") ("bullet".
"•")
1028 ("hellip") ("dots".
"…")
1038 ("larr") ("leftarrow".
"←") ("gets".
"←")
1039 ("uarr") ("uparrow".
"↑")
1040 ("rarr") ("to".
"→") ("rightarrow".
"→")
1041 ("darr")("downarrow".
"↓")
1042 ("harr") ("leftrightarrow".
"↔")
1043 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1044 ("lArr") ("Leftarrow".
"⇐")
1045 ("uArr") ("Uparrow".
"⇑")
1046 ("rArr") ("Rightarrow".
"⇒")
1047 ("dArr") ("Downarrow".
"⇓")
1048 ("hArr") ("Leftrightarrow".
"⇔")
1050 ("part") ("partial".
"∂")
1051 ("exist") ("exists".
"∃")
1052 ("empty") ("emptyset".
"∅")
1054 ("isin") ("in".
"∈")
1060 ("lowast") ("ast".
"∗")
1062 ("prop") ("proptp".
"∝")
1063 ("infin") ("infty".
"∞")
1064 ("ang") ("angle".
"∠")
1065 ("and") ("wedge".
"∧")
1066 ("or") ("vee".
"∨")
1072 ("cong") ("simeq".
"≅")
1073 ("asymp")("approx".
"≈")
1074 ("ne") ("neq".
"≠")
1078 ("sub") ("subset".
"⊂")
1079 ("sup") ("supset".
"⊃")
1086 ("sdot") ("cdot".
"⋅")
1093 ("loz") ("Diamond".
"◊")
1094 ("spades") ("spadesuit".
"♠")
1095 ("clubs") ("clubsuit".
"♣")
1096 ("hearts") ("diamondsuit".
"♥")
1097 ("diams") ("diamondsuit".
"♦")
1098 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1165 "Entities for TeX->HTML translation.
1166 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1167 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1168 In that case, \"\\ent\" will be translated to \"&other;\".
1169 The list contains HTML entities for Latin-1, Greek and other symbols.
1170 It is supplemented by a number of commonly used TeX macros with appropriate
1171 translations. There is currently no way for users to extend this.")
1173 ;;; General functions for all backends
1175 (defun org-export-preprocess-string (string &rest parameters
)
1176 "Cleanup STRING so that that the true exported has a more consistent source.
1177 This function takes STRING, which should be a buffer-string of an org-file
1178 to export. It then creates a temporary buffer where it does its job.
1179 The result is then again returned as a string, and the exporter works
1180 on this string to produce the exported version."
1182 (let* ((re-radio (and org-target-link-regexp
1183 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1184 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1185 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1186 (re-archive (concat ":" org-archive-tag
":"))
1187 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1188 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1189 (htmlp (plist-get parameters
:for-html
))
1190 (asciip (plist-get parameters
:for-ascii
))
1191 (latexp (plist-get parameters
:for-LaTeX
))
1192 (commentsp (plist-get parameters
:comments
))
1193 (archived-trees (plist-get parameters
:archived-trees
))
1194 (inhibit-read-only t
)
1195 (drawers org-drawers
)
1196 (exp-drawers (plist-get parameters
:drawers
))
1197 (outline-regexp "\\*+ ")
1198 target-alist tmp target level
1201 (with-current-buffer (get-buffer-create " org-mode-tmp")
1205 (run-hooks 'org-export-preprocess-hook
)
1207 ;; Remove license-to-kill stuff
1208 ;; The caller markes some stuff fo killing, stuff that has been
1209 ;; used to create the page title, for example.
1210 (while (setq p
(text-property-any (point-min) (point-max)
1211 :org-license-to-kill t
))
1212 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1214 (let ((org-inhibit-startup t
)) (org-mode))
1215 (untabify (point-min) (point-max))
1217 ;; Handle incude files
1218 (org-export-handle-include-files)
1220 ;; Handle source code snippets
1221 (org-export-replace-src-segments)
1223 ;; Get rid of drawers
1224 (unless (eq t exp-drawers
)
1225 (goto-char (point-min))
1226 (let ((re (concat "^[ \t]*:\\("
1229 (org-delete-all exp-drawers
1230 (copy-sequence drawers
))
1232 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1233 (while (re-search-forward re nil t
)
1234 (replace-match ""))))
1236 ;; Get the correct stuff before the first headline
1237 (when (plist-get parameters
:skip-before-1st-heading
)
1238 (goto-char (point-min))
1239 (when (re-search-forward "^\\*+[ \t]" nil t
)
1240 (delete-region (point-min) (match-beginning 0))
1241 (goto-char (point-min))
1243 (when (plist-get parameters
:add-text
)
1244 (goto-char (point-min))
1245 (insert (plist-get parameters
:add-text
) "\n"))
1247 ;; Get rid of archived trees
1248 (when (not (eq archived-trees t
))
1249 (goto-char (point-min))
1250 (while (re-search-forward re-archive nil t
)
1251 (if (not (org-on-heading-p t
))
1252 (org-end-of-subtree t
)
1253 (beginning-of-line 1)
1254 (setq a
(if archived-trees
1255 (1+ (point-at-eol)) (point))
1256 b
(org-end-of-subtree t
))
1257 (if (> b a
) (delete-region a b
)))))
1259 ;; Find all headings and compute the targets for them
1260 (goto-char (point-min))
1261 (org-init-section-numbers)
1262 (let ((re (concat "^" org-outline-regexp
)))
1263 (while (re-search-forward re nil t
)
1264 (setq level
(org-reduced-level
1265 (save-excursion (goto-char (point-at-bol))
1266 (org-outline-level))))
1267 (setq target
(org-solidify-link-text
1268 (format "sec-%s" (org-section-number level
))))
1269 (push (cons target target
) target-alist
)
1270 (add-text-properties
1271 (point-at-bol) (point-at-eol)
1272 (list 'target target
))))
1274 ;; Find targets in comments and move them out of comments,
1275 ;; but mark them as targets that should be invisible
1276 (goto-char (point-min))
1277 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1278 ;; Check if the line before or after is a headline with a target
1279 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1280 (get-text-property (point-at-bol 2) 'target
)))
1282 ;; use the existing target in a neighboring line
1283 (setq tmp
(match-string 2))
1285 (and (looking-at "\n") (delete-char 1))
1286 (push (cons (org-solidify-link-text tmp
) target
)
1288 ;; Make an invisible target
1289 (replace-match "\\1(INVISIBLE)")))
1291 ;; Protect backend specific stuff, throw away the others.
1293 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1294 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1295 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1297 (goto-char (point-min))
1298 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1299 (goto-char (match-end 0))
1300 (while (not (looking-at "#\\+END_EXAMPLE"))
1302 (beginning-of-line 2)))
1303 (goto-char (point-min))
1304 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1305 (add-text-properties (match-beginning 0) (match-end 0)
1306 '(org-protected t
)))
1308 (setq fmt
(pop formatters
))
1310 (goto-char (point-min))
1311 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1312 ":[ \t]*\\(.*\\)") nil t
)
1313 (replace-match "\\1" t
)
1314 (add-text-properties
1315 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1316 '(org-protected t
))))
1317 (goto-char (point-min))
1318 (while (re-search-forward
1320 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1321 (cadddr fmt
) "\\>.*\n?") nil t
)
1323 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1325 (delete-region (match-beginning 0) (match-end 0))))))
1327 ;; Protect quoted subtrees
1328 (goto-char (point-min))
1329 (while (re-search-forward re-quote nil t
)
1330 (goto-char (match-beginning 0))
1332 (add-text-properties (point) (org-end-of-subtree t
)
1333 '(org-protected t
)))
1335 ;; Protect verbatim elements
1336 (goto-char (point-min))
1337 (while (re-search-forward org-verbatim-re nil t
)
1338 (add-text-properties (match-beginning 4) (match-end 4)
1340 (goto-char (1+ (match-end 4))))
1343 (goto-char (point-min))
1344 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1345 (replace-match (if (equal (downcase (match-string 1)) "end")
1346 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1349 ;; Remove subtrees that are commented
1350 (goto-char (point-min))
1351 (while (re-search-forward re-commented nil t
)
1352 (goto-char (match-beginning 0))
1353 (delete-region (point) (org-end-of-subtree t
)))
1355 ;; Remove special table lines
1356 (when org-export-table-remove-special-lines
1357 (goto-char (point-min))
1358 (while (re-search-forward "^[ \t]*|" nil t
)
1359 (beginning-of-line 1)
1360 (if (or (looking-at "[ \t]*| *[!_^] *|")
1361 (and (looking-at ".*?| *<[0-9]+> *|")
1362 (not (looking-at ".*?| *[^ <|]"))))
1363 (delete-region (max (point-min) (1- (point-at-bol)))
1367 ;; Specific LaTeX stuff
1369 (require 'org-export-latex nil
)
1370 (org-export-latex-preprocess))
1373 (org-export-ascii-clean-string))
1375 ;; Specific HTML stuff
1377 ;; Convert LaTeX fragments to images
1378 (when (plist-get parameters
:LaTeX-fragments
)
1380 (concat "ltxpng/" (file-name-sans-extension
1381 (file-name-nondirectory
1382 org-current-export-file
)))
1383 org-current-export-dir nil
"Creating LaTeX image %s"))
1384 (message "Exporting..."))
1386 ;; Remove or replace comments
1387 (goto-char (point-min))
1388 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1390 (progn (add-text-properties
1391 (match-beginning 0) (match-end 0) '(org-protected t
))
1392 (replace-match (format commentsp
(match-string 1)) t t
))
1393 (replace-match "")))
1395 ;; Find matches for radio targets and turn them into internal links
1396 (goto-char (point-min))
1398 (while (re-search-forward re-radio nil t
)
1400 (replace-match "\\1[[\\2]]"))))
1402 ;; Find all links that contain a newline and put them into a single line
1403 (goto-char (point-min))
1404 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1406 (replace-match "\\1 \\3")
1407 (goto-char (match-beginning 0))))
1409 ;; Find all internal links. If they have a fuzzy match (i.e. not
1410 ;; a *dedicated* target match, let the link point to the
1411 ;; correspinding section.
1413 (goto-char (point-min))
1414 (while (re-search-forward org-bracket-link-regexp nil t
)
1416 (let* ((md (match-data))
1417 (desc (match-end 2))
1418 (link (org-link-unescape (match-string 1)))
1419 (slink (org-solidify-link-text link
))
1422 (or (cdr (assoc slink target-alist
))
1424 (unless (string-match org-link-types-re link
)
1425 (setq found
(condition-case nil
(org-link-search link
)
1428 (or (org-on-heading-p)
1429 (not (eq found
'dedicated
))))
1430 (or (get-text-property (point) 'target
)
1433 (1- (previous-single-property-change
1438 (goto-char (match-beginning 1))
1439 (setq props
(text-properties-at (point)))
1440 (delete-region (match-beginning 1) (match-end 1))
1443 (unless desc
(insert "][" link
))
1444 (add-text-properties pos
(point) props
)))))
1446 ;; Normalize links: Convert angle and plain links into bracket links
1447 ;; Expand link abbreviations
1448 (goto-char (point-min))
1449 (while (re-search-forward re-plain-link nil t
)
1450 (goto-char (1- (match-end 0)))
1452 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1453 ":" (match-string 3) "]]")))
1454 ;; added 'org-link face to links
1455 (put-text-property 0 (length s
) 'face
'org-link s
)
1456 (replace-match s t t
))))
1457 (goto-char (point-min))
1458 (while (re-search-forward re-angle-link nil t
)
1459 (goto-char (1- (match-end 0)))
1461 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1462 ":" (match-string 3) "]]")))
1463 (put-text-property 0 (length s
) 'face
'org-link s
)
1464 (replace-match s t t
))))
1465 (goto-char (point-min))
1466 (while (re-search-forward org-bracket-link-regexp nil t
)
1468 (let* ((s (concat "[[" (setq xx
(save-match-data
1469 (org-link-expand-abbrev (match-string 1))))
1473 (concat "[" xx
"]"))
1475 (put-text-property 0 (length s
) 'face
'org-link s
)
1476 (replace-match s t t
))))
1478 ;; Find multiline emphasis and put them into single line
1479 (when (plist-get parameters
:emph-multiline
)
1480 (goto-char (point-min))
1481 (while (re-search-forward org-emph-re nil t
)
1482 (if (not (= (char-after (match-beginning 3))
1483 (char-after (match-beginning 4))))
1485 (subst-char-in-region (match-beginning 0) (match-end 0)
1487 (goto-char (1- (match-end 0))))
1488 (goto-char (1+ (match-beginning 0))))))
1490 (setq rtn
(buffer-string)))
1491 (kill-buffer " org-mode-tmp")
1494 (defun org-export-grab-title-from-buffer ()
1495 "Get a title for the current document, from looking at the buffer."
1496 (let ((inhibit-read-only t
))
1498 (goto-char (point-min))
1499 (let ((end (save-excursion (outline-next-heading) (point))))
1500 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1501 ;; Mark the line so that it will not be exported as normal text.
1503 (add-text-properties (match-beginning 0) (match-end 0)
1504 (list :org-license-to-kill t
)))
1505 ;; Return the title string
1506 (org-trim (match-string 0)))))))
1508 (defun org-export-get-title-from-subtree ()
1509 "Return subtree title and exclude it from export."
1510 (let (title (m (mark)))
1512 (goto-char (region-beginning))
1513 (when (and (org-at-heading-p)
1514 (>= (org-end-of-subtree t t
) (region-end)))
1515 ;; This is a subtree, we take the title from the first heading
1516 (goto-char (region-beginning))
1517 (looking-at org-todo-line-regexp
)
1518 (setq title
(match-string 3))
1520 (add-text-properties (point) (1+ (point-at-eol))
1521 (list :org-license-to-kill t
)))))
1524 (defun org-solidify-link-text (s &optional alist
)
1525 "Take link text and make a safe target out of it."
1530 (org-split-string s
"[ \t\r\n]+") "=="))
1531 (a (assoc rtn alist
)))
1534 (defun org-get-min-level (lines)
1535 "Get the minimum level in LINES."
1536 (let ((re "^\\(\\*+\\) ") l min
)
1538 (while (setq l
(pop lines
))
1539 (if (string-match re l
)
1540 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1543 ;; Variable holding the vector with section numbers
1544 (defvar org-section-numbers
(make-vector org-level-max
0))
1546 (defun org-init-section-numbers ()
1547 "Initialize the vector for the section numbers."
1549 (numbers (nreverse (org-split-string "" "\\.")))
1550 (depth (1- (length org-section-numbers
)))
1551 (i depth
) number-string
)
1554 (aset org-section-numbers i
0)
1555 (setq number-string
(or (car numbers
) "0"))
1556 (if (string-match "\\`[A-Z]\\'" number-string
)
1557 (aset org-section-numbers i
1558 (- (string-to-char number-string
) ?A -
1))
1559 (aset org-section-numbers i
(string-to-number number-string
)))
1563 (defun org-section-number (&optional level
)
1564 "Return a string with the current section number.
1565 When LEVEL is non-nil, increase section numbers on that level."
1566 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1569 (aset org-section-numbers
1570 level
(1+ (aref org-section-numbers level
))))
1571 (setq idx
(1+ level
))
1572 (while (<= idx depth
)
1574 (aset org-section-numbers idx
0))
1575 (setq idx
(1+ idx
))))
1577 (while (<= idx depth
)
1578 (setq n
(aref org-section-numbers idx
))
1579 (setq string
(concat string
(if (not (string= string
"")) "." "")
1581 (setq idx
(1+ idx
)))
1583 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1584 (setq string
(replace-match "" t nil string
)))
1585 (if (string-match "\\(\\.0\\)+\\'" string
)
1586 (setq string
(replace-match "" t nil string
))))
1591 (defun org-export-handle-include-files ()
1592 "Include the contents of include files, with proper formatting."
1593 (let (params file markup lang start end
)
1594 (goto-char (point-min))
1595 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1596 (setq params
(read (concat "(" (match-string 1) ")"))
1597 file
(org-symname-or-string (pop params
))
1598 markup
(org-symname-or-string (pop params
))
1599 lang
(org-symname-or-string (pop params
)))
1600 (delete-region (match-beginning 0) (match-end 0))
1602 (not (file-exists-p file
))
1603 (not (file-readable-p file
)))
1604 (insert (format "CANNOT INCLUDE FILE %s" file
))
1606 (if (equal (downcase markup
) "src")
1607 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1609 (setq start
(format "#+begin_%s\n" markup
)
1610 end
(format "#+end_%s" markup
))))
1611 (insert (or start
""))
1612 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1613 (or (bolp) (newline))
1614 (insert (or end
""))))))
1616 (defun org-symname-or-string (s)
1618 (if s
(symbol-name s
) s
)
1621 ;;; Fontification of code
1622 ;; Currently only for th HTML backend, but who knows....
1623 (defun org-export-replace-src-segments ()
1624 "Replace source code segments with special code for export."
1625 (let (lang code trans
)
1626 (goto-char (point-min))
1627 (while (re-search-forward
1628 "^#\\+BEGIN_SRC[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1630 (setq lang
(match-string 1) code
(match-string 2)
1631 trans
(org-export-format-source-code lang code
))
1632 (replace-match trans t t
))))
1634 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1636 (defun org-export-format-source-code (lang code
)
1637 "Format CODE from language LANG and return it formatted for export.
1638 Currently, this only does something for HTML export, for all other
1639 backends, it converts the segment into an EXAMPLE segment."
1643 ;; We are exporting to HTML
1644 (condition-case nil
(require 'htmlize
) (nil t
))
1645 (if (not (fboundp 'htmlize-region-for-paste
))
1647 ;; we do not have htmlize.el, or an old version of it
1649 "htmlize.el 1.34 or later is needed for source code formatting")
1650 (concat "#+BEGIN_EXAMPLE\n" code
1651 (if (string-match "\n\\'" code
) "" "\n")
1653 ;; ok, we are good to go
1654 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1655 (org-inhibit-startup t
)
1656 (org-startup-folded nil
)
1660 ;; Free up the protected stuff
1661 (goto-char (point-min))
1662 (while (re-search-forward "^," nil t
)
1664 (if (functionp mode
)
1667 (font-lock-fontify-buffer)
1668 ;; silence the byte-compiler
1669 (when (fboundp 'htmlize-region-for-paste
)
1670 ;; transform the region to HTML
1671 (htmlize-region-for-paste (point-min) (point-max))))))
1672 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1673 (setq htmltext
(replace-match "<pre class=\"src\">"
1675 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1677 ;; This is not HTML, so just make it an example.
1678 (concat "#+BEGIN_EXAMPLE\n" code
1679 (if (string-match "\n\\'" code
) "" "\n")
1680 "#+END_EXAMPLE\n")))))
1684 (defvar org-last-level nil
) ; dynamically scoped variable
1685 (defvar org-min-level nil
) ; dynamically scoped variable
1686 (defvar org-levels-open nil
) ; dynamically scoped parameter
1687 (defvar org-ascii-current-indentation nil
) ; For communication
1690 (defun org-export-as-ascii (arg)
1691 "Export the outline as a pretty ASCII file.
1692 If there is an active region, export only the region.
1693 The prefix ARG specifies how many levels of the outline should become
1694 underlined headlines. The default is 3."
1696 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1697 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1698 (org-infile-export-plist)))
1699 (region-p (org-region-active-p))
1703 (goto-char (region-beginning))
1704 (and (org-at-heading-p)
1705 (>= (org-end-of-subtree t t
) (region-end))))))
1706 (custom-times org-display-custom-times
)
1707 (org-ascii-current-indentation '(0 .
0))
1711 (case-fold-search nil
)
1712 (filename (concat (file-name-as-directory
1713 (org-export-directory :ascii opt-plist
))
1714 (file-name-sans-extension
1716 (org-entry-get (region-beginning)
1717 "EXPORT_FILE_NAME" t
))
1718 (file-name-nondirectory buffer-file-name
)))
1720 (filename (if (equal (file-truename filename
)
1721 (file-truename buffer-file-name
))
1722 (concat filename
".txt")
1724 (buffer (find-file-noselect filename
))
1725 (org-levels-open (make-vector org-level-max nil
))
1726 (odd org-odd-levels-only
)
1727 (date (plist-get opt-plist
:date
))
1728 (author (plist-get opt-plist
:author
))
1729 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1730 (plist-get opt-plist
:title
)
1732 (plist-get opt-plist
:skip-before-1st-heading
))
1733 (org-export-grab-title-from-buffer))
1734 (file-name-sans-extension
1735 (file-name-nondirectory buffer-file-name
))))
1736 (email (plist-get opt-plist
:email
))
1737 (language (plist-get opt-plist
:language
))
1738 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1739 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1744 (if (org-region-active-p) (region-beginning) (point-min))
1745 (if (org-region-active-p) (region-end) (point-max))))
1746 (lines (org-split-string
1747 (org-export-preprocess-string
1750 :skip-before-1st-heading
1751 (plist-get opt-plist
:skip-before-1st-heading
)
1752 :drawers
(plist-get opt-plist
:drawers
)
1753 :verbatim-multiline t
1755 (plist-get opt-plist
:archived-trees
)
1756 :add-text
(plist-get opt-plist
:text
))
1758 thetoc have-headings first-heading-pos
1759 table-open table-buffer
)
1761 (let ((inhibit-read-only t
))
1763 (remove-text-properties (point-min) (point-max)
1764 '(:org-license-to-kill t
))))
1766 (setq org-min-level
(org-get-min-level lines
))
1767 (setq org-last-level org-min-level
)
1768 (org-init-section-numbers)
1770 (find-file-noselect filename
)
1772 (setq lang-words
(or (assoc language org-export-language-setup
)
1773 (assoc "en" org-export-language-setup
)))
1774 (switch-to-buffer-other-window buffer
)
1777 ;; create local variables for all options, to make sure all called
1778 ;; functions get the correct information
1780 (set (make-local-variable (cdr x
))
1781 (plist-get opt-plist
(car x
))))
1782 org-export-plist-vars
)
1783 (org-set-local 'org-odd-levels-only odd
)
1784 (setq umax
(if arg
(prefix-numeric-value arg
)
1785 org-export-headline-levels
))
1786 (setq umax-toc
(if (integerp org-export-with-toc
)
1787 (min org-export-with-toc umax
)
1791 (if title
(org-insert-centered title ?
=))
1793 (if (and (or author email
)
1794 org-export-author-info
)
1795 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1796 (if email
(concat " <" email
">") "")
1800 ((and date
(string-match "%" date
))
1801 (setq date
(format-time-string date
)))
1803 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1805 (if (and date org-export-time-stamp-file
)
1806 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1810 (if org-export-with-toc
1812 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1813 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1814 (mapc '(lambda (line)
1815 (if (string-match org-todo-line-regexp
1817 ;; This is a headline
1819 (setq have-headings t
)
1820 (setq level
(- (match-end 1) (match-beginning 1))
1821 level
(org-tr-level level
)
1822 txt
(match-string 3 line
)
1824 (or (and org-export-mark-todo-in-toc
1826 (not (member (match-string 2 line
)
1827 org-done-keywords
)))
1829 (and org-export-mark-todo-in-toc
1831 (org-search-todo-below
1832 line lines level
))))
1833 (setq txt
(org-html-expand-for-ascii txt
))
1835 (while (string-match org-bracket-link-regexp txt
)
1838 (match-string (if (match-end 2) 3 1) txt
)
1841 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1843 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1845 (setq txt
(replace-match "" t t txt
)))
1846 (if (string-match quote-re0 txt
)
1847 (setq txt
(replace-match "" t t txt
)))
1849 (if org-export-with-section-numbers
1850 (setq txt
(concat (org-section-number level
)
1852 (if (<= level umax-toc
)
1857 (* (max 0 (- level org-min-level
)) 4) ?\
)
1858 (format (if todo
"%s (*)\n" "%s\n") txt
))
1860 (setq org-last-level level
))
1863 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1865 (org-init-section-numbers)
1866 (while (setq line
(pop lines
))
1867 ;; Remove the quoted HTML tags.
1868 (setq line
(org-html-expand-for-ascii line
))
1870 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1871 (setq line
(replace-match "" t t line
)))
1872 ;; Replace internal links
1873 (while (string-match org-bracket-link-regexp line
)
1874 (setq line
(replace-match
1875 (if (match-end 3) "[\\3]" "[\\1]")
1878 (setq line
(org-translate-time line
)))
1880 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1882 (setq first-heading-pos
(or first-heading-pos
(point)))
1883 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1884 txt
(match-string 2 line
))
1885 (org-ascii-level-start level txt umax lines
))
1887 ((and org-export-with-tables
1888 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1889 (if (not table-open
)
1891 (setq table-open t table-buffer nil
))
1893 (setq table-buffer
(cons line table-buffer
))
1894 (when (or (not lines
)
1895 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1897 (setq table-open nil
1898 table-buffer
(nreverse table-buffer
))
1901 (org-fix-indentation x org-ascii-current-indentation
))
1902 (org-format-table-ascii table-buffer
)
1905 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1906 (if (and org-export-with-fixed-width
1907 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1908 (setq line
(replace-match "\\1" nil nil line
)))
1909 (insert line
"\n"))))
1913 ;; insert the table of contents
1915 (goto-char (point-min))
1916 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1918 (goto-char (match-beginning 0))
1920 (goto-char first-heading-pos
))
1921 (mapc 'insert thetoc
)
1922 (or (looking-at "[ \t]*\n[ \t]*\n")
1925 ;; Convert whitespace place holders
1926 (goto-char (point-min))
1928 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1929 (setq end
(next-single-property-change beg
'org-whitespace
))
1931 (delete-region beg end
)
1932 (insert (make-string (- end beg
) ?\
))))
1935 ;; remove display and invisible chars
1937 (goto-char (point-min))
1938 (while (setq beg
(next-single-property-change (point) 'display
))
1939 (setq end
(next-single-property-change beg
'display
))
1940 (delete-region beg end
)
1943 (goto-char (point-min))
1944 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1945 (setq end
(next-single-property-change beg
'org-cwidth
))
1946 (delete-region beg end
)
1948 (goto-char (point-min))))
1950 (defun org-export-ascii-clean-string ()
1951 "Do extra work for ASCII export"
1952 (goto-char (point-min))
1953 (while (re-search-forward org-verbatim-re nil t
)
1954 (goto-char (match-end 2))
1955 (backward-delete-char 1) (insert "'")
1956 (goto-char (match-beginning 2))
1957 (delete-char 1) (insert "`")
1958 (goto-char (match-end 2))))
1960 (defun org-search-todo-below (line lines level
)
1961 "Search the subtree below LINE for any TODO entries."
1962 (let ((rest (cdr (memq line lines
)))
1963 (re org-todo-line-regexp
)
1966 (while (setq line
(pop rest
))
1967 (if (string-match re line
)
1969 (setq lv
(- (match-end 1) (match-beginning 1))
1970 todo
(and (match-beginning 2)
1971 (not (member (match-string 2 line
)
1972 org-done-keywords
))))
1974 (if (<= lv level
) (throw 'exit nil
))
1975 (if todo
(throw 'exit t
))))))))
1977 (defun org-html-expand-for-ascii (line)
1978 "Handle quoted HTML for ASCII export."
1979 (if org-export-html-expand
1980 (while (string-match "@<[^<>\n]*>" line
)
1981 ;; We just remove the tags for now.
1982 (setq line
(replace-match "" nil nil line
))))
1985 (defun org-insert-centered (s &optional underline
)
1986 "Insert the string S centered and underline it with character UNDERLINE."
1987 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
1988 (insert (make-string ind ?\
) s
"\n")
1990 (insert (make-string ind ?\
)
1991 (make-string (string-width s
) underline
)
1994 (defun org-ascii-level-start (level title umax
&optional lines
)
1995 "Insert a new level in ASCII export."
1996 (let (char (n (- level umax
1)) (ind 0))
1999 (insert (make-string (* 2 n
) ?\
)
2000 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2001 org-export-ascii-bullets
))
2003 ;; find the indentation of the next non-empty line
2006 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2007 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2008 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2010 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2011 (if (or (not (equal (char-before) ?
\n))
2012 (not (equal (char-before (1- (point))) ?
\n)))
2014 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2015 (unless org-export-with-tags
2016 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2017 (setq title
(replace-match "" t t title
))))
2018 (if org-export-with-section-numbers
2019 (setq title
(concat (org-section-number level
) " " title
)))
2020 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2021 (setq org-ascii-current-indentation
'(0 .
0)))))
2024 (defun org-export-visible (type arg
)
2025 "Create a copy of the visible part of the current buffer, and export it.
2026 The copy is created in a temporary buffer and removed after use.
2027 TYPE is the final key (as a string) that also select the export command in
2028 the `C-c C-e' export dispatcher.
2029 As a special case, if the you type SPC at the prompt, the temporary
2030 org-mode file will not be removed but presented to you so that you can
2031 continue to use it. The prefix arg ARG is passed through to the exporting
2035 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2036 (read-char-exclusive))
2037 current-prefix-arg
))
2038 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2039 (error "Invalid export key"))
2040 (let* ((binding (cdr (assoc type
2041 '((?a . org-export-as-ascii
)
2042 (?\C-a . org-export-as-ascii
)
2043 (?b . org-export-as-html-and-open
)
2044 (?\C-b . org-export-as-html-and-open
)
2045 (?h . org-export-as-html
)
2046 (?H . org-export-as-html-to-buffer
)
2047 (?R . org-export-region-as-html
)
2048 (?x . org-export-as-xoxo
)))))
2049 (keepp (equal type ?\
))
2050 (file buffer-file-name
)
2051 (buffer (get-buffer-create "*Org Export Visible*"))
2053 ;; Need to hack the drawers here.
2055 (goto-char (point-min))
2056 (while (re-search-forward org-drawer-regexp nil t
)
2057 (goto-char (match-beginning 1))
2058 (or (org-invisible-p) (org-flag-drawer nil
))))
2059 (with-current-buffer buffer
(erase-buffer))
2061 (setq s
(goto-char (point-min)))
2062 (while (not (= (point) (point-max)))
2063 (goto-char (org-find-invisible))
2064 (append-to-buffer buffer s
(point))
2065 (setq s
(goto-char (org-find-visible))))
2066 (org-cycle-hide-drawers 'all
)
2067 (goto-char (point-min))
2069 ;; Copy all comment lines to the end, to make sure #+ settings are
2070 ;; still available for the second export step. Kind of a hack, but
2071 ;; does do the trick.
2072 (if (looking-at "#[^\r\n]*")
2073 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2074 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2075 (append-to-buffer buffer
(1+ (match-beginning 0))
2076 (min (point-max) (1+ (match-end 0))))))
2078 (let ((buffer-file-name file
)
2079 (org-inhibit-startup t
))
2082 (unless keepp
(funcall binding arg
))))
2084 (kill-buffer buffer
)
2085 (switch-to-buffer-other-window buffer
)
2086 (goto-char (point-min)))))
2088 (defun org-find-visible ()
2090 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2091 (get-char-property s
'invisible
)))
2093 (defun org-find-invisible ()
2095 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2096 (not (get-char-property s
'invisible
))))
2101 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2102 (defun org-get-current-options ()
2103 "Return a string with current options as keyword options.
2104 Does include HTML export options as well as TODO and CATEGORY stuff."
2105 (require 'org-archive
)
2112 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2113 #+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
2120 #+PRIORITIES: %c %c %c
2122 #+STARTUP: %s %s %s %s %s
2127 (buffer-name) (user-full-name) user-mail-address
2128 (format-time-string (car org-time-stamp-formats
))
2129 org-export-default-language
2130 org-export-headline-levels
2131 org-export-with-section-numbers
2133 org-export-preserve-breaks
2134 org-export-html-expand
2135 org-export-with-fixed-width
2136 org-export-with-tables
2137 org-export-with-sub-superscripts
2138 org-export-with-special-strings
2139 org-export-with-footnotes
2140 org-export-with-emphasize
2141 org-export-with-TeX-macros
2142 org-export-with-LaTeX-fragments
2143 org-export-skip-text-before-1st-heading
2144 org-export-with-drawers
2145 org-export-with-tags
2146 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2147 org-export-html-link-up
2148 org-export-html-link-home
2149 (file-name-nondirectory buffer-file-name
)
2150 "TODO FEEDBACK VERIFY DONE"
2151 "Me Jason Marie DONE"
2152 org-highest-priority org-lowest-priority org-default-priority
2153 (mapconcat 'identity org-drawers
" ")
2154 (cdr (assoc org-startup-folded
2155 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2156 (if org-odd-levels-only
"odd" "oddeven")
2157 (if org-hide-leading-stars
"hidestars" "showstars")
2158 (if org-startup-align-all-tables
"align" "noalign")
2159 (cond ((eq org-log-done t
) "logdone")
2160 ((equal org-log-done
'note
) "lognotedone")
2161 ((not org-log-done
) "nologdone"))
2162 (or (mapconcat (lambda (x)
2164 ((equal '(:startgroup
) x
) "{")
2165 ((equal '(:endgroup
) x
) "}")
2166 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2168 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2169 org-archive-location
2170 "org file:~/org/%s.org"
2174 (defun org-insert-export-options-template ()
2175 "Insert into the buffer a template with information for exporting."
2177 (if (not (bolp)) (newline))
2178 (let ((s (org-get-current-options)))
2179 (and (string-match "#\\+CATEGORY" s
)
2180 (setq s
(substring s
0 (match-beginning 0))))
2184 (defun org-export-as-html-and-open (arg)
2185 "Export the outline as HTML and immediately open it with a browser.
2186 If there is an active region, export only the region.
2187 The prefix ARG specifies how many levels of the outline should become
2188 headlines. The default is 3. Lower levels will become bulleted lists."
2190 (org-export-as-html arg
'hidden
)
2191 (org-open-file buffer-file-name
))
2194 (defun org-export-as-html-batch ()
2195 "Call `org-export-as-html', may be used in batch processing as
2197 --load=$HOME/lib/emacs/org.el
2198 --eval \"(setq org-export-headline-levels 2)\"
2199 --visit=MyFile --funcall org-export-as-html-batch"
2200 (org-export-as-html org-export-headline-levels
'hidden
))
2203 (defun org-export-as-html-to-buffer (arg)
2204 "Call `org-exort-as-html` with output to a temporary buffer.
2205 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2207 (org-export-as-html arg nil nil
"*Org HTML Export*")
2208 (switch-to-buffer-other-window "*Org HTML Export*"))
2211 (defun org-replace-region-by-html (beg end
)
2212 "Assume the current region has org-mode syntax, and convert it to HTML.
2213 This can be used in any buffer. For example, you could write an
2214 itemized list in org-mode syntax in an HTML buffer and then use this
2215 command to convert it."
2217 (let (reg html buf pop-up-frames
)
2218 (save-window-excursion
2220 (setq html
(org-export-region-as-html
2222 (setq reg
(buffer-substring beg end
)
2223 buf
(get-buffer-create "*Org tmp*"))
2224 (with-current-buffer buf
2228 (setq html
(org-export-region-as-html
2229 (point-min) (point-max) t
'string
)))
2231 (delete-region beg end
)
2235 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2236 "Convert region from BEG to END in org-mode buffer to HTML.
2237 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2238 contents, and only produce the region of converted text, useful for
2239 cut-and-paste operations.
2240 If BUFFER is a buffer or a string, use/create that buffer as a target
2241 of the converted HTML. If BUFFER is the symbol `string', return the
2242 produced HTML as a string and leave not buffer behind. For example,
2243 a Lisp program could call this function in the following way:
2245 (setq html (org-export-region-as-html beg end t 'string))
2247 When called interactively, the output buffer is selected, and shown
2248 in a window. A non-interactive call will only return the buffer."
2249 (interactive "r\nP")
2250 (when (interactive-p)
2251 (setq buffer
"*Org HTML Export*"))
2252 (let ((transient-mark-mode t
) (zmacs-regions t
)
2255 (set-mark (point)) ;; to activate the region
2257 (setq rtn
(org-export-as-html
2260 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2261 (if (and (interactive-p) (bufferp rtn
))
2262 (switch-to-buffer-other-window rtn
)
2265 (defvar html-table-tag nil
) ; dynamically scoped into this.
2267 (defun org-export-as-html (arg &optional hidden ext-plist
2268 to-buffer body-only pub-dir
)
2269 "Export the outline as a pretty HTML file.
2270 If there is an active region, export only the region. The prefix
2271 ARG specifies how many levels of the outline should become
2272 headlines. The default is 3. Lower levels will become bulleted
2273 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2274 EXT-PLIST is a property list with external parameters overriding
2275 org-mode's default settings, but still inferior to file-local
2276 settings. When TO-BUFFER is non-nil, create a buffer with that
2277 name and export to that buffer. If TO-BUFFER is the symbol
2278 `string', don't leave any buffer behind but just return the
2279 resulting HTML as a string. When BODY-ONLY is set, don't produce
2280 the file header and footer, simply return the content of
2281 <body>...</body>, without even the body tags themselves. When
2282 PUB-DIR is set, use this as the publishing directory."
2285 ;; Make sure we have a file name when we need it.
2286 (when (and (not (or to-buffer body-only
))
2287 (not buffer-file-name
))
2288 (if (buffer-base-buffer)
2289 (org-set-local 'buffer-file-name
2290 (with-current-buffer (buffer-base-buffer)
2292 (error "Need a file name to be able to export.")))
2294 (message "Exporting...")
2295 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2296 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2297 (setq-default org-done-keywords org-done-keywords
)
2298 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2300 (org-export-process-option-filters
2301 (org-combine-plists (org-default-export-plist)
2303 (org-infile-export-plist))))
2305 (style (plist-get opt-plist
:style
))
2306 (html-extension (plist-get opt-plist
:html-extension
))
2307 (link-validate (plist-get opt-plist
:link-validation-function
))
2308 valid thetoc have-headings first-heading-pos
2309 (odd org-odd-levels-only
)
2310 (region-p (org-region-active-p))
2314 (goto-char (region-beginning))
2315 (and (org-at-heading-p)
2316 (>= (org-end-of-subtree t t
) (region-end))))))
2317 ;; The following two are dynamically scoped into other
2319 (org-current-export-dir
2320 (or pub-dir
(org-export-directory :html opt-plist
)))
2321 (org-current-export-file buffer-file-name
)
2322 (level 0) (line "") (origline "") txt todo
2325 (filename (if to-buffer nil
2328 (file-name-sans-extension
2330 (org-entry-get (region-beginning)
2331 "EXPORT_FILE_NAME" t
))
2332 (file-name-nondirectory buffer-file-name
)))
2334 (file-name-as-directory
2335 (or pub-dir
(org-export-directory :html opt-plist
))))))
2336 (current-dir (if buffer-file-name
2337 (file-name-directory buffer-file-name
)
2339 (buffer (if to-buffer
2341 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2342 (t (get-buffer-create to-buffer
)))
2343 (find-file-noselect filename
)))
2344 (org-levels-open (make-vector org-level-max nil
))
2345 (date (plist-get opt-plist
:date
))
2346 (author (plist-get opt-plist
:author
))
2347 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2348 (plist-get opt-plist
:title
)
2350 (plist-get opt-plist
:skip-before-1st-heading
))
2351 (org-export-grab-title-from-buffer))
2352 (and buffer-file-name
2353 (file-name-sans-extension
2354 (file-name-nondirectory buffer-file-name
)))
2356 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2357 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2358 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2362 (local-list-type nil
)
2363 (local-list-indent nil
)
2364 (llt org-plain-list-ordered-item-terminator
)
2365 (email (plist-get opt-plist
:email
))
2366 (language (plist-get opt-plist
:language
))
2370 (coding-system (and (boundp 'buffer-file-coding-system
)
2371 buffer-file-coding-system
))
2372 (coding-system-for-write (or org-export-html-coding-system
2374 (save-buffer-coding-system (or org-export-html-coding-system
2376 (charset (and coding-system-for-write
2377 (fboundp 'coding-system-get
)
2378 (coding-system-get coding-system-for-write
2382 (if region-p
(region-beginning) (point-min))
2383 (if region-p
(region-end) (point-max))))
2386 (org-export-preprocess-string
2390 :skip-before-1st-heading
2391 (plist-get opt-plist
:skip-before-1st-heading
)
2392 :drawers
(plist-get opt-plist
:drawers
)
2394 (plist-get opt-plist
:archived-trees
)
2396 (plist-get opt-plist
:text
)
2398 (plist-get opt-plist
:LaTeX-fragments
))
2401 table-buffer table-orig-buffer
2402 ind item-type starter didclose
2403 rpl path desc descp desc1 desc2 link
2404 snumber fnc item-tag
2407 (let ((inhibit-read-only t
))
2409 (remove-text-properties (point-min) (point-max)
2410 '(:org-license-to-kill t
))))
2412 (message "Exporting...")
2414 (setq org-min-level
(org-get-min-level lines
))
2415 (setq org-last-level org-min-level
)
2416 (org-init-section-numbers)
2419 ((and date
(string-match "%" date
))
2420 (setq date
(format-time-string date
)))
2422 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2424 ;; Get the language-dependent settings
2425 (setq lang-words
(or (assoc language org-export-language-setup
)
2426 (assoc "en" org-export-language-setup
)))
2428 ;; Switch to the output buffer
2430 (let ((inhibit-read-only t
)) (erase-buffer))
2433 (and (fboundp 'set-buffer-file-coding-system
)
2434 (set-buffer-file-coding-system coding-system-for-write
))
2436 (let ((case-fold-search nil
)
2437 (org-odd-levels-only odd
))
2438 ;; create local variables for all options, to make sure all called
2439 ;; functions get the correct information
2441 (set (make-local-variable (cdr x
))
2442 (plist-get opt-plist
(car x
))))
2443 org-export-plist-vars
)
2444 (setq umax
(if arg
(prefix-numeric-value arg
)
2445 org-export-headline-levels
))
2446 (setq umax-toc
(if (integerp org-export-with-toc
)
2447 (min org-export-with-toc umax
)
2452 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2453 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2454 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2455 lang=\"%s\" xml:lang=\"%s\">
2458 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2459 <meta name=\"generator\" content=\"Org-mode\"/>
2460 <meta name=\"generated\" content=\"%s\"/>
2461 <meta name=\"author\" content=\"%s\"/>
2465 language language
(org-html-expand title
)
2466 (or charset
"iso-8859-1") date author style
))
2468 (insert (or (plist-get opt-plist
:preamble
) ""))
2470 (when (plist-get opt-plist
:auto-preamble
)
2471 (if title
(insert (format org-export-html-title-format
2472 (org-html-expand title
))))))
2474 (if (and org-export-with-toc
(not body-only
))
2476 (push (format "<h%d>%s</h%d>\n"
2477 org-export-html-toplevel-hlevel
2479 org-export-html-toplevel-hlevel
)
2481 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2482 (push "<ul>\n<li>" thetoc
)
2484 (mapcar '(lambda (line)
2485 (if (string-match org-todo-line-regexp line
)
2486 ;; This is a headline
2488 (setq have-headings t
)
2489 (setq level
(- (match-end 1) (match-beginning 1))
2490 level
(org-tr-level level
)
2491 txt
(save-match-data
2493 (org-export-cleanup-toc-line
2494 (match-string 3 line
))))
2496 (or (and org-export-mark-todo-in-toc
2498 (not (member (match-string 2 line
)
2499 org-done-keywords
)))
2501 (and org-export-mark-todo-in-toc
2503 (org-search-todo-below
2504 line lines level
))))
2506 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2507 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2508 (if (string-match quote-re0 txt
)
2509 (setq txt
(replace-match "" t t txt
)))
2510 (setq snumber
(org-section-number level
))
2511 (if org-export-with-section-numbers
2512 (setq txt
(concat snumber
" " txt
)))
2513 (if (<= level
(max umax umax-toc
))
2514 (setq head-count
(+ head-count
1)))
2515 (if (<= level umax-toc
)
2517 (if (> level org-last-level
)
2519 (setq cnt
(- level org-last-level
))
2520 (while (>= (setq cnt
(1- cnt
)) 0)
2521 (push "\n<ul>\n<li>" thetoc
))
2522 (push "\n" thetoc
)))
2523 (if (< level org-last-level
)
2525 (setq cnt
(- org-last-level level
))
2526 (while (>= (setq cnt
(1- cnt
)) 0)
2527 (push "</li>\n</ul>" thetoc
))
2528 (push "\n" thetoc
)))
2529 ;; Check for targets
2530 (while (string-match org-any-target-regexp line
)
2531 (setq line
(replace-match
2532 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2534 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2535 (setq txt
(replace-match "" t t txt
)))
2539 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2540 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2541 snumber txt
) thetoc
)
2543 (setq org-last-level level
))
2547 (while (> org-last-level
(1- org-min-level
))
2548 (setq org-last-level
(1- org-last-level
))
2549 (push "</li>\n</ul>\n" thetoc
))
2550 (push "</div>\n" thetoc
)
2551 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2554 (org-init-section-numbers)
2556 (while (setq line
(pop lines
) origline line
)
2559 ;; end of quote section?
2560 (when (and inquote
(string-match "^\\*+ " line
))
2563 ;; inside a quote section?
2565 (insert (org-html-protect line
) "\n")
2566 (throw 'nextline nil
))
2569 (when (and org-export-with-fixed-width
2570 (string-match "^[ \t]*:\\(.*\\)" line
))
2574 (insert (org-html-protect (match-string 1 line
)) "\n")
2576 (not (string-match "^[ \t]*\\(:.*\\)"
2579 (insert "</pre>\n"))
2580 (throw 'nextline nil
))
2583 (when (get-text-property 0 'org-protected line
)
2585 (when (re-search-backward
2586 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2587 (setq par
(match-string 1))
2588 (replace-match "\\2\n"))
2591 (not (string-match "^[ \t]*:" (car lines
)))
2592 (or (= (length (car lines
)) 0)
2593 (get-text-property 0 'org-protected
(car lines
))))
2594 (insert (pop lines
) "\n"))
2595 (and par
(insert "<p>\n")))
2596 (throw 'nextline nil
))
2599 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2600 (insert "\n<hr/>\n")
2601 (throw 'nextline nil
))
2604 (when (equal "ORG-BLOCKQUOTE-START" line
)
2605 (insert "<blockquote>\n<p>\n")
2606 (throw 'nextline nil
))
2607 (when (equal "ORG-BLOCKQUOTE-END" line
)
2608 (insert "</p>\n</blockquote>\n")
2609 (throw 'nextline nil
))
2611 ;; make targets to anchors
2612 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2615 (setq line
(replace-match
2616 (concat "@<a name=\""
2617 (org-solidify-link-text (match-string 1 line
))
2620 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2621 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2622 (setq line
(replace-match
2623 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2624 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2627 (setq line
(replace-match
2628 (concat "@<a name=\""
2629 (org-solidify-link-text (match-string 1 line
))
2630 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2633 (setq line
(org-html-handle-time-stamps line
))
2635 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2636 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2637 ;; Also handle sub_superscripts and checkboxes
2638 (or (string-match org-table-hline-regexp line
)
2639 (setq line
(org-html-expand line
)))
2643 (while (string-match org-bracket-link-analytic-regexp line start
)
2644 (setq start
(match-beginning 0))
2645 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2646 (setq path
(match-string 3 line
))
2647 (setq desc1
(if (match-end 5) (match-string 5 line
))
2648 desc2
(if (match-end 2) (concat type
":" path
) path
)
2649 descp
(and desc1
(not (equal desc1 desc2
)))
2650 desc
(or desc1 desc2
))
2651 ;; Make an image out of the description if that is so wanted
2652 (when (and descp
(org-file-image-p desc
))
2654 (if (string-match "^file:" desc
)
2655 (setq desc
(substring desc
(match-end 0)))))
2656 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2657 ;; FIXME: do we need to unescape here somewhere?
2659 ((equal type
"internal")
2663 (org-solidify-link-text
2664 (save-match-data (org-link-unescape path
)) nil
)
2665 "\">" desc
"</a>")))
2666 ((member type
'("http" "https"))
2667 ;; standard URL, just check if we need to inline an image
2668 (if (and (or (eq t org-export-html-inline-images
)
2669 (and org-export-html-inline-images
(not descp
)))
2670 (org-file-image-p path
))
2671 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2672 (setq link
(concat type
":" path
))
2673 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2674 ((member type
'("ftp" "mailto" "news"))
2676 (setq link
(concat type
":" path
))
2677 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2678 ((string= type
"file")
2680 (let* ((filename path
)
2681 (abs-p (file-name-absolute-p filename
))
2682 thefile file-is-image-p search
)
2684 (if (string-match "::\\(.*\\)" filename
)
2685 (setq search
(match-string 1 filename
)
2686 filename
(replace-match "" t nil filename
)))
2688 (if (functionp link-validate
)
2689 (funcall link-validate filename current-dir
)
2691 (setq file-is-image-p
(org-file-image-p filename
))
2692 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2693 (when (and org-export-html-link-org-files-as-html
2694 (string-match "\\.org$" thefile
))
2695 (setq thefile
(concat (substring thefile
0
2696 (match-beginning 0))
2697 "." html-extension
))
2699 ;; make sure this is can be used as target search
2700 (not (string-match "^[0-9]*$" search
))
2701 (not (string-match "^\\*" search
))
2702 (not (string-match "^/.*/$" search
)))
2703 (setq thefile
(concat thefile
"#"
2704 (org-solidify-link-text
2705 (org-link-unescape search
)))))
2706 (when (string-match "^file:" desc
)
2707 (setq desc
(replace-match "" t t desc
))
2708 (if (string-match "\\.org$" desc
)
2709 (setq desc
(replace-match "" t t desc
))))))
2710 (setq rpl
(if (and file-is-image-p
2711 (or (eq t org-export-html-inline-images
)
2712 (and org-export-html-inline-images
2714 (concat "<img src=\"" thefile
"\"/>")
2715 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2716 (if (not valid
) (setq rpl desc
))))
2718 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2721 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2724 ;; just publish the path, as default
2725 (setq rpl
(concat "<i><" type
":"
2726 (save-match-data (org-link-unescape path
))
2728 (setq line
(replace-match rpl t t line
)
2729 start
(+ start
(length rpl
))))
2732 (if (and (string-match org-todo-line-regexp line
)
2733 (match-beginning 2))
2736 (concat (substring line
0 (match-beginning 2))
2738 (if (member (match-string 2 line
)
2741 "\">" (match-string 2 line
)
2742 "</span>" (substring line
(match-end 2)))))
2744 ;; Does this contain a reference to a footnote?
2745 (when org-export-with-footnotes
2747 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2748 (if (get-text-property (match-beginning 2) 'org-protected line
)
2749 (setq start
(match-end 2))
2750 (let ((n (match-string 2 line
)))
2754 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2755 (match-string 1 line
) n n n
)
2759 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2760 ;; This is a headline
2761 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2762 txt
(match-string 2 line
))
2763 (if (string-match quote-re0 txt
)
2764 (setq txt
(replace-match "" t t txt
)))
2765 (if (<= level
(max umax umax-toc
))
2766 (setq head-count
(+ head-count
1)))
2768 ;; Close any local lists before inserting a new header line
2769 (while local-list-type
2770 (org-close-li (car local-list-type
))
2771 (insert (format "</%sl>\n" (car local-list-type
)))
2772 (pop local-list-type
))
2773 (setq local-list-indent nil
2775 (setq first-heading-pos
(or first-heading-pos
(point)))
2776 (org-html-level-start level txt umax
2777 (and org-export-with-toc
(<= level umax
))
2780 (when (string-match quote-re line
)
2784 ((and org-export-with-tables
2785 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2786 (if (not table-open
)
2788 (setq table-open t table-buffer nil table-orig-buffer nil
))
2790 (setq table-buffer
(cons line table-buffer
)
2791 table-orig-buffer
(cons origline table-orig-buffer
))
2792 (when (or (not lines
)
2793 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2795 (setq table-open nil
2796 table-buffer
(nreverse table-buffer
)
2797 table-orig-buffer
(nreverse table-orig-buffer
))
2798 (org-close-par-maybe)
2799 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2804 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2805 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2806 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2807 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2809 (setq ind
(org-get-string-indentation line
)
2810 item-type
(if (match-beginning 4) "o" "u")
2811 starter
(if (match-beginning 2)
2812 (substring (match-string 2 line
) 0 -
1))
2813 line
(substring line
(match-beginning 5))
2815 (if (string-match "\\(.*?\\) ::[ \t]*" line
)
2817 item-tag
(match-string 1 line
)
2818 line
(substring line
(match-end 0))))
2819 (unless (string-match "[^ \t]" line
)
2820 ;; empty line. Pretend indentation is large.
2821 (setq ind
(if org-empty-line-terminates-plain-lists
2823 (1+ (or (car local-list-indent
) 1)))))
2825 (while (and in-local-list
2826 (or (and (= ind
(car local-list-indent
))
2828 (< ind
(car local-list-indent
))))
2830 (org-close-li (car local-list-type
))
2831 (insert (format "</%sl>\n" (car local-list-type
)))
2832 (pop local-list-type
) (pop local-list-indent
)
2833 (setq in-local-list local-list-indent
))
2836 (or (not in-local-list
)
2837 (> ind
(car local-list-indent
))))
2838 ;; Start new (level of) list
2839 (org-close-par-maybe)
2841 ((equal item-type
"u") "<ul>\n<li>\n")
2842 ((equal item-type
"o") "<ol>\n<li>\n")
2843 ((equal item-type
"d")
2844 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2845 (push item-type local-list-type
)
2846 (push ind local-list-indent
)
2847 (setq in-local-list t
))
2849 ;; continue current list
2850 (org-close-li (car local-list-type
))
2852 ((equal (car local-list-type
) "d")
2853 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2856 ;; we did close a list, normal text follows: need <p>
2858 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2861 (if (equal (match-string 1 line
) "X")
2863 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2866 ;; Empty lines start a new paragraph. If hand-formatted lists
2867 ;; are not fully interpreted, lines starting with "-", "+", "*"
2868 ;; also start a new paragraph.
2869 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2871 ;; Is this the start of a footnote?
2872 (when org-export-with-footnotes
2873 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2874 (org-close-par-maybe)
2875 (let ((n (match-string 1 line
)))
2876 (setq line
(replace-match
2877 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2879 ;; Check if the line break needs to be conserved
2881 ((string-match "\\\\\\\\[ \t]*$" line
)
2882 (setq line
(replace-match "<br/>" t t line
)))
2883 (org-export-preserve-breaks
2884 (setq line
(concat line
"<br/>"))))
2886 (insert line
"\n")))))
2888 ;; Properly close all local lists and other lists
2889 (when inquote
(insert "</pre>\n"))
2891 ;; Close any local lists before inserting a new header line
2892 (while local-list-type
2893 (org-close-li (car local-list-type
))
2894 (insert (format "</%sl>\n" (car local-list-type
)))
2895 (pop local-list-type
))
2896 (setq local-list-indent nil
2898 (org-html-level-start 1 nil umax
2899 (and org-export-with-toc
(<= level umax
))
2901 ;; the </div> to lose the last text-... div.
2905 (when (plist-get opt-plist
:auto-postamble
)
2906 (insert "<div id=\"postamble\">")
2907 (when (and org-export-author-info author
)
2908 (insert "<p class=\"author\"> "
2909 (nth 1 lang-words
) ": " author
"\n")
2911 (if (listp (split-string email
",+ *"))
2913 (insert "<a href=\"mailto:" e
"\"><"
2915 (split-string email
",+ *"))
2916 (insert "<a href=\"mailto:" email
"\"><"
2917 email
"></a>\n")))
2919 (when (and date org-export-time-stamp-file
)
2920 (insert "<p class=\"date\"> "
2921 (nth 2 lang-words
) ": "
2925 (if org-export-html-with-timestamp
2926 (insert org-export-html-html-helper-timestamp
))
2927 (insert (or (plist-get opt-plist
:postamble
) ""))
2928 (insert "</body>\n</html>\n"))
2931 (if (eq major-mode default-major-mode
) (html-mode))
2933 ;; insert the table of contents
2934 (goto-char (point-min))
2936 (if (or (re-search-forward
2937 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2939 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2941 (goto-char (match-beginning 0))
2943 (goto-char first-heading-pos
)
2944 (when (looking-at "\\s-*</p>")
2945 (goto-char (match-end 0))
2947 (insert "<div id=\"table-of-contents\">\n")
2948 (mapc 'insert thetoc
)
2949 (insert "</div>\n"))
2950 ;; remove empty paragraphs and lists
2951 (goto-char (point-min))
2952 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2954 (goto-char (point-min))
2955 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2957 (goto-char (point-min))
2958 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
2960 ;; Convert whitespace place holders
2961 (goto-char (point-min))
2963 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2964 (setq n
(get-text-property beg
'org-whitespace
)
2965 end
(next-single-property-change beg
'org-whitespace
))
2967 (delete-region beg end
)
2968 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2969 (make-string n ?x
)))))
2970 (or to-buffer
(save-buffer))
2971 (goto-char (point-min))
2972 (message "Exporting... done")
2973 (if (eq to-buffer
'string
)
2974 (prog1 (buffer-substring (point-min) (point-max))
2975 (kill-buffer (current-buffer)))
2976 (current-buffer)))))
2978 (defvar org-table-colgroup-info nil
)
2979 (defun org-format-table-ascii (lines)
2980 "Format a table for ascii export."
2982 (setq lines
(org-split-string lines
"\n")))
2983 (if (not (string-match "^[ \t]*|" (car lines
)))
2984 ;; Table made by table.el - test for spanning
2987 ;; A normal org table
2988 ;; Get rid of hlines at beginning and end
2989 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2990 (setq lines
(nreverse lines
))
2991 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2992 (setq lines
(nreverse lines
))
2993 (when org-export-table-remove-special-lines
2994 ;; Check if the table has a marking column. If yes remove the
2995 ;; column and the special lines
2996 (setq lines
(org-table-clean-before-export lines
)))
2997 ;; Get rid of the vertical lines except for grouping
2998 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3000 (while (setq line
(pop lines
))
3001 (if (string-match org-table-hline-regexp line
)
3002 (and (string-match "|\\(.*\\)|" line
)
3003 (setq line
(replace-match " \\1" t nil line
)))
3004 (setq start
0 vl1 vl
)
3005 (while (string-match "|" line start
)
3006 (setq start
(match-end 0))
3007 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3011 (defun org-colgroup-info-to-vline-list (info)
3014 (setq last new new
(pop info
))
3015 (if (or (memq last
'(:end
:startend
))
3016 (memq new
'(:start
:startend
)))
3019 (setq vl
(nreverse vl
))
3020 (and vl
(setcar vl nil
))
3023 (defvar org-table-number-regexp
) ; defined in org-table.el
3024 (defun org-format-table-html (lines olines
)
3025 "Find out which HTML converter to use and return the HTML code."
3027 (setq lines
(org-split-string lines
"\n")))
3028 (if (string-match "^[ \t]*|" (car lines
))
3029 ;; A normal org table
3030 (org-format-org-table-html lines
)
3031 ;; Table made by table.el - test for spanning
3032 (let* ((hlines (delq nil
(mapcar
3034 (if (string-match "^[ \t]*\\+-" x
) x
3037 (first (car hlines
))
3038 (ll (and (string-match "\\S-+" first
)
3039 (match-string 0 first
)))
3040 (re (concat "^[ \t]*" (regexp-quote ll
)))
3041 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3043 (if (and (not spanning
)
3044 (not org-export-prefer-native-exporter-for-tables
))
3045 ;; We can use my own converter with HTML conversions
3046 (org-format-table-table-html lines
)
3047 ;; Need to use the code generator in table.el, with the original text.
3048 (org-format-table-table-html-using-table-generate-source olines
)))))
3050 (defvar org-table-number-fraction
) ; defined in org-table.el
3051 (defun org-format-org-table-html (lines &optional splice
)
3052 "Format a table into HTML."
3053 (require 'org-table
)
3054 ;; Get rid of hlines at beginning and end
3055 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3056 (setq lines
(nreverse lines
))
3057 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3058 (setq lines
(nreverse lines
))
3059 (when org-export-table-remove-special-lines
3060 ;; Check if the table has a marking column. If yes remove the
3061 ;; column and the special lines
3062 (setq lines
(org-table-clean-before-export lines
)))
3064 (let ((head (and org-export-highlight-first-table-line
3066 (lambda (x) (string-match "^[ \t]*|-" x
))
3069 tbopen line fields html gr colgropen
)
3070 (if splice
(setq head nil
))
3071 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3073 (while (setq line
(pop lines
))
3075 (if (string-match "^[ \t]*|-" line
)
3078 (push (if head
"</thead>" "</tbody>") html
)
3079 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3080 (setq head nil
) ;; head ends here, first time around
3082 (throw 'next-line t
)))
3083 ;; Break the line into fields
3084 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3085 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3086 (setq nlines
(1+ nlines
) i -
1)
3087 (push (concat "<tr>"
3091 (if (and (< i nlines
)
3092 (string-match org-table-number-regexp x
))
3093 (incf (aref fnum i
)))
3095 (concat (car org-export-table-header-tags
) x
3096 (cdr org-export-table-header-tags
))
3097 (concat (car org-export-table-data-tags
) x
3098 (cdr org-export-table-data-tags
))))
3102 (unless splice
(if tbopen
(push "</tbody>" html
)))
3103 (unless splice
(push "</table>\n" html
))
3104 (setq html
(nreverse html
))
3106 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3109 (setq gr
(pop org-table-colgroup-info
))
3110 (format "%s<col align=\"%s\"></col>%s"
3111 (if (memq gr
'(:start
:startend
))
3113 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3116 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3118 (if (memq gr
'(:end
:startend
))
3119 (progn (setq colgropen nil
) "</colgroup>")
3123 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3124 (push html-table-tag html
))
3125 (concat (mapconcat 'identity html
"\n") "\n")))
3127 (defun org-table-clean-before-export (lines)
3128 "Check if the table has a marking column.
3129 If yes remove the column and the special lines."
3130 (setq org-table-colgroup-info nil
)
3133 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3134 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3137 (setq org-table-clean-did-remove-column nil
)
3142 ((string-match "^[ \t]*| */ *|" x
)
3143 (setq org-table-colgroup-info
3145 (cond ((member x
'("<" "<")) :start
)
3146 ((member x
'(">" ">")) :end
)
3147 ((member x
'("<>" "<>")) :startend
)
3149 (org-split-string x
"[ \t]*|[ \t]*")))
3153 (setq org-table-clean-did-remove-column t
)
3158 ((string-match "^[ \t]*| */ *|" x
)
3159 (setq org-table-colgroup-info
3161 (cond ((member x
'("<" "<")) :start
)
3162 ((member x
'(">" ">")) :end
)
3163 ((member x
'("<>" "<>")) :startend
)
3165 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3167 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3168 nil
) ; ignore this line
3169 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3170 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3171 ;; remove the first column
3172 (replace-match "\\1|" t nil x
))))
3175 (defun org-format-table-table-html (lines)
3176 "Format a table generated by table.el into HTML.
3177 This conversion does *not* use `table-generate-source' from table.el.
3178 This has the advantage that Org-mode's HTML conversions can be used.
3179 But it has the disadvantage, that no cell- or row-spanning is allowed."
3180 (let (line field-buffer
3181 (head org-export-highlight-first-table-line
)
3183 (setq html
(concat html-table-tag
"\n"))
3184 (while (setq line
(pop lines
))
3185 (setq empty
" ")
3187 (if (string-match "^[ \t]*\\+-" line
)
3198 (if (equal x
"") (setq x empty
))
3200 (concat (car org-export-table-header-tags
) x
3201 (cdr org-export-table-header-tags
))
3202 (concat (car org-export-table-data-tags
) x
3203 (cdr org-export-table-data-tags
))))
3207 (setq field-buffer nil
)))
3209 (throw 'next-line t
)))
3210 ;; Break the line into fields and store the fields
3211 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3213 (setq field-buffer
(mapcar
3215 (concat x
"<br/>" (pop fields
)))
3217 (setq field-buffer fields
))))
3218 (setq html
(concat html
"</table>\n"))
3221 (defun org-format-table-table-html-using-table-generate-source (lines)
3222 "Format a table into html, using `table-generate-source' from table.el.
3223 This has the advantage that cell- or row-spanning is allowed.
3224 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3226 (with-current-buffer (get-buffer-create " org-tmp1 ")
3228 (insert (mapconcat 'identity lines
"\n"))
3229 (goto-char (point-min))
3230 (if (not (re-search-forward "|[^+]" nil t
))
3231 (error "Error processing table"))
3232 (table-recognize-table)
3233 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3234 (table-generate-source 'html
" org-tmp2 ")
3235 (set-buffer " org-tmp2 ")
3236 (buffer-substring (point-min) (point-max))))
3238 (defun org-html-handle-time-stamps (s)
3239 "Format time stamps in string S, or remove them."
3242 (while (string-match org-maybe-keyword-time-regexp s
)
3243 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3244 ;; never export CLOCK
3246 (or b
(setq b
(substring s
0 (match-beginning 0))))
3247 (if (not org-export-with-timestamps
)
3248 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3249 s
(substring s
(match-end 0)))
3251 r
(substring s
0 (match-beginning 0))
3253 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3254 (match-string 1 s
)))
3255 (format " @<span class=\"timestamp\">%s@</span>"
3257 (org-translate-time (match-string 3 s
)) 1 -
1)))
3258 s
(substring s
(match-end 0)))))
3259 ;; Line break if line started and ended with time stamp stuff
3262 (setq r
(concat r s
))
3263 (unless (string-match "\\S-" (concat b s
))
3264 (setq r
(concat r
"@<br/>")))
3267 (defun org-html-protect (s)
3268 ;; convert & to &, < to < and > to >
3270 (while (string-match "&" s start
)
3271 (setq s
(replace-match "&" t t s
)
3272 start
(1+ (match-beginning 0))))
3273 (while (string-match "<" s
)
3274 (setq s
(replace-match "<" t t s
)))
3275 (while (string-match ">" s
)
3276 (setq s
(replace-match ">" t t s
))))
3279 (defun org-export-cleanup-toc-line (s)
3280 "Remove tags and time staps from lines going into the toc."
3281 (when (memq org-export-with-tags
'(not-in-toc nil
))
3282 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3283 (setq s
(replace-match "" t t s
))))
3284 (when org-export-remove-timestamps-from-toc
3285 (while (string-match org-maybe-keyword-time-regexp s
)
3286 (setq s
(replace-match "" t t s
))))
3287 (while (string-match org-bracket-link-regexp s
)
3288 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3292 (defun org-html-expand (string)
3293 "Prepare STRING for HTML export. Applies all active conversions.
3294 If there are links in the string, don't modify these."
3295 (let* ((re (concat org-bracket-link-regexp
"\\|"
3296 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3298 (while (setq m
(string-match re string
))
3299 (setq s
(substring string
0 m
)
3300 l
(match-string 0 string
)
3301 string
(substring string
(match-end 0)))
3302 (push (org-html-do-expand s
) res
)
3304 (push (org-html-do-expand string
) res
)
3305 (apply 'concat
(nreverse res
))))
3307 (defun org-html-do-expand (s)
3308 "Apply all active conversions to translate special ASCII to HTML."
3309 (setq s
(org-html-protect s
))
3310 (if org-export-html-expand
3312 (while (string-match "@<\\([^&]*\\)>" s
)
3313 (setq s
(replace-match "<\\1>" t nil s
)))))
3314 (if org-export-with-emphasize
3315 (setq s
(org-export-html-convert-emphasize s
)))
3316 (if org-export-with-special-strings
3317 (setq s
(org-export-html-convert-special-strings s
)))
3318 (if org-export-with-sub-superscripts
3319 (setq s
(org-export-html-convert-sub-super s
)))
3320 (if org-export-with-TeX-macros
3321 (let ((start 0) wd ass
)
3322 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3323 (if (get-text-property (match-beginning 0) 'org-protected s
)
3324 (setq start
(match-end 0))
3325 (setq wd
(match-string 1 s
))
3326 (if (setq ass
(assoc wd org-html-entities
))
3327 (setq s
(replace-match (or (cdr ass
)
3328 (concat "&" (car ass
) ";"))
3330 (setq start
(+ start
(length wd
))))))))
3333 (defun org-create-multibrace-regexp (left right n
)
3334 "Create a regular expression which will match a balanced sexp.
3335 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3336 as single character strings.
3337 The regexp returned will match the entire expression including the
3338 delimiters. It will also define a single group which contains the
3339 match except for the outermost delimiters. The maximum depth of
3340 stacked delimiters is N. Escaping delimiters is not possible."
3341 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3344 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3347 re
(concat re or next
)
3348 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3349 (concat left
"\\(" re
"\\)" right
)))
3351 (defvar org-match-substring-regexp
3353 "\\([^\\]\\)\\([_^]\\)\\("
3354 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3356 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3358 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3359 "The regular expression matching a sub- or superscript.")
3361 (defvar org-match-substring-with-braces-regexp
3363 "\\([^\\]\\)\\([_^]\\)\\("
3364 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3366 "The regular expression matching a sub- or superscript, forcing braces.")
3368 (defconst org-export-html-special-string-regexps
3369 '(("\\\\-" .
"­")
3370 ("---\\([^-]\\)" .
"—\\1")
3371 ("--\\([^-]\\)" .
"–\\1")
3372 ("\\.\\.\\." .
"…"))
3373 "Regular expressions for special string conversion.")
3375 (defun org-export-html-convert-special-strings (string)
3376 "Convert special characters in STRING to HTML."
3377 (let ((all org-export-html-special-string-regexps
)
3379 (while (setq a
(pop all
))
3380 (setq re
(car a
) rpl
(cdr a
) start
0)
3381 (while (string-match re string start
)
3382 (if (get-text-property (match-beginning 0) 'org-protected string
)
3383 (setq start
(match-end 0))
3384 (setq string
(replace-match rpl t nil string
)))))
3387 (defun org-export-html-convert-sub-super (string)
3388 "Convert sub- and superscripts in STRING to HTML."
3389 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3390 (while (string-match org-match-substring-regexp string s
)
3392 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3393 ((get-text-property (match-beginning 2) 'org-protected string
)
3394 (setq s
(match-end 2)))
3396 (setq s
(match-end 1)
3397 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3398 c
(or (match-string 8 string
)
3399 (match-string 6 string
)
3400 (match-string 5 string
))
3401 string
(replace-match
3402 (concat (match-string 1 string
)
3403 "<" key
">" c
"</" key
">")
3405 (while (string-match "\\\\\\([_^]\\)" string
)
3406 (setq string
(replace-match (match-string 1 string
) t t string
)))
3409 (defun org-export-html-convert-emphasize (string)
3412 (while (string-match org-emph-re string s
)
3414 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3415 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3416 (setq s
(match-beginning 0)
3419 (match-string 1 string
)
3420 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3421 (match-string 4 string
)
3422 (nth 3 (assoc (match-string 3 string
)
3423 org-emphasis-alist
))
3424 (match-string 5 string
))
3425 string
(replace-match rpl t t string
)
3426 s
(+ s
(- (length rpl
) 2)))
3430 (defvar org-par-open nil
)
3431 (defun org-open-par ()
3432 "Insert <p>, but first close previous paragraph if any."
3433 (org-close-par-maybe)
3435 (setq org-par-open t
))
3436 (defun org-close-par-maybe ()
3437 "Close paragraph if there is one open."
3440 (setq org-par-open nil
)))
3441 (defun org-close-li (&optional type
)
3442 "Close <li> if necessary."
3443 (org-close-par-maybe)
3444 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3446 (defvar body-only
) ; dynamically scoped into this.
3447 (defun org-html-level-start (level title umax with-toc head-count
)
3448 "Insert a new level in HTML export.
3449 When TITLE is nil, just close all open levels."
3450 (org-close-par-maybe)
3451 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3455 (if (aref org-levels-open
(1- l
))
3457 (org-html-level-close l umax
)
3458 (aset org-levels-open
(1- l
) nil
)))
3461 ;; If title is nil, this means this function is called to close
3462 ;; all levels, so the rest is done only if title is given
3463 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3464 (setq title
(replace-match
3465 (if org-export-with-tags
3468 " <span class=\"tag\">"
3469 (mapconcat 'identity
(org-split-string
3470 (match-string 1 title
) ":")
3477 (if (aref org-levels-open
(1- level
))
3481 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3482 (insert "<li>" title
"<br/>\n")))
3483 (aset org-levels-open
(1- level
) t
)
3484 (org-close-par-maybe)
3486 (insert (format "<ul>\n<li id=\"%s\">" target
)
3488 (insert "<ul>\n<li>" title
"<br/>\n"))))
3489 (aset org-levels-open
(1- level
) t
)
3490 (setq snumber
(org-section-number level
))
3491 (if (and org-export-with-section-numbers
(not body-only
))
3492 (setq title
(concat snumber
" " title
)))
3493 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3494 (unless (= head-count
1) (insert "\n</div>\n"))
3495 (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"
3496 snumber level level snumber title level snumber
))
3499 (defun org-get-text-property-any (pos prop
&optional object
)
3500 (or (get-text-property pos prop object
)
3501 (and (setq pos
(next-single-property-change pos prop object
))
3502 (get-text-property pos prop object
))))
3504 (defun org-html-level-close (level max-outline-level
)
3505 "Terminate one level in HTML export."
3506 (if (<= level max-outline-level
)
3509 (insert "</ul>\n")))
3511 ;;; iCalendar export
3514 (defun org-export-icalendar-this-file ()
3515 "Export current file as an iCalendar file.
3516 The iCalendar file will be located in the same directory as the Org-mode
3517 file, but with extension `.ics'."
3519 (org-export-icalendar nil buffer-file-name
))
3522 (defun org-export-icalendar-all-agenda-files ()
3523 "Export all files in `org-agenda-files' to iCalendar .ics files.
3524 Each iCalendar file will be located in the same directory as the Org-mode
3525 file, but with extension `.ics'."
3527 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3530 (defun org-export-icalendar-combine-agenda-files ()
3531 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3532 The file is stored under the name `org-combined-agenda-icalendar-file'."
3534 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3536 (defun org-export-icalendar (combine &rest files
)
3537 "Create iCalendar files for all elements of FILES.
3538 If COMBINE is non-nil, combine all calendar entries into a single large
3539 file and store it under the name `org-combined-agenda-icalendar-file'."
3541 (org-prepare-agenda-buffers files
)
3542 (let* ((dir (org-export-directory
3543 :ical
(list :publishing-directory
3544 org-export-publishing-directory
)))
3545 file ical-file ical-buffer category started org-agenda-new-buffers
)
3546 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3549 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3550 org-combined-agenda-icalendar-file
3551 (expand-file-name org-combined-agenda-icalendar-file dir
))
3552 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3553 (set-buffer ical-buffer
) (erase-buffer))
3554 (while (setq file
(pop files
))
3556 (org-check-agenda-file file
)
3557 (set-buffer (org-get-agenda-file-buffer file
))
3559 (setq ical-file
(concat (file-name-as-directory dir
)
3560 (file-name-sans-extension
3561 (file-name-nondirectory buffer-file-name
))
3563 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3564 (with-current-buffer ical-buffer
(erase-buffer)))
3565 (setq category
(or org-category
3566 (file-name-sans-extension
3567 (file-name-nondirectory buffer-file-name
))))
3568 (if (symbolp category
) (setq category
(symbol-name category
)))
3569 (let ((standard-output ical-buffer
))
3571 (and (not started
) (setq started t
)
3572 (org-start-icalendar-file org-icalendar-combined-name
))
3573 (org-start-icalendar-file category
))
3574 (org-print-icalendar-entries combine
)
3575 (when (or (and combine
(not files
)) (not combine
))
3576 (org-finish-icalendar-file)
3577 (set-buffer ical-buffer
)
3579 (run-hooks 'org-after-save-iCalendar-file-hook
)
3580 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3582 (org-release-buffers org-agenda-new-buffers
))))
3584 (defvar org-after-save-iCalendar-file-hook nil
3585 "Hook run after an iCalendar file has been saved.
3586 The iCalendar buffer is still current when this hook is run.
3587 A good way to use this is to tell a desktop calenndar application to re-read
3588 the iCalendar file.")
3590 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3591 (defun org-print-icalendar-entries (&optional combine
)
3592 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3593 When COMBINE is non nil, add the category to each line."
3594 (require 'org-agenda
)
3595 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3596 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3597 (dts (org-ical-ts-to-string
3598 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3600 hd ts ts2 state status
(inc t
) pos b sexp rrule
3601 scheduledp deadlinep tmp pri category entry location summary desc
3602 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3603 (org-refresh-category-properties)
3605 (goto-char (point-min))
3606 (while (re-search-forward re1 nil t
)
3609 (when (boundp 'org-icalendar-verify-function
)
3610 (unless (funcall org-icalendar-verify-function
)
3611 (outline-next-heading)
3614 (setq pos
(match-beginning 0)
3617 hd
(condition-case nil
3618 (org-icalendar-cleanup-string
3620 (error (throw :skip nil
)))
3621 summary
(org-icalendar-cleanup-string
3622 (org-entry-get nil
"SUMMARY"))
3623 desc
(org-icalendar-cleanup-string
3624 (or (org-entry-get nil
"DESCRIPTION")
3625 (and org-icalendar-include-body
(org-get-entry)))
3626 t org-icalendar-include-body
)
3627 location
(org-icalendar-cleanup-string
3628 (org-entry-get nil
"LOCATION"))
3629 category
(org-get-category))
3630 (if (looking-at re2
)
3632 (goto-char (match-end 0))
3633 (setq ts2
(match-string 1) inc nil
))
3634 (setq tmp
(buffer-substring (max (point-min)
3635 (- pos org-ds-keyword-length
))
3637 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3640 (replace-match "\\1" t nil ts
))
3642 deadlinep
(string-match org-deadline-regexp tmp
)
3643 scheduledp
(string-match org-scheduled-regexp tmp
)
3644 ;; donep (org-entry-is-done-p)
3646 (if (or (string-match org-tr-regexp hd
)
3647 (string-match org-ts-regexp hd
))
3648 (setq hd
(replace-match "" t t hd
)))
3649 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3651 (concat "\nRRULE:FREQ="
3654 '(("d" .
"DAILY")("w" .
"WEEKLY")
3655 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3656 ";INTERVAL=" (match-string 1 ts
)))
3658 (setq summary
(or summary hd
))
3659 (if (string-match org-bracket-link-regexp summary
)
3661 (replace-match (if (match-end 3)
3662 (match-string 3 summary
)
3663 (match-string 1 summary
))
3665 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3666 (if scheduledp
(setq summary
(concat "S: " summary
)))
3667 (if (string-match "\\`<%%" ts
)
3668 (with-current-buffer sexp-buffer
3669 (insert (substring ts
1 -
1) " " summary
"\n"))
3670 (princ (format "BEGIN:VEVENT
3676 (org-ical-ts-to-string ts
"DTSTART")
3677 (org-ical-ts-to-string ts2
"DTEND" inc
)
3679 (if (and desc
(string-match "\\S-" desc
))
3680 (concat "\nDESCRIPTION: " desc
) "")
3681 (if (and location
(string-match "\\S-" location
))
3682 (concat "\nLOCATION: " location
) "")
3685 (when (and org-icalendar-include-sexps
3686 (condition-case nil
(require 'icalendar
) (error nil
))
3687 (fboundp 'icalendar-export-region
))
3688 ;; Get all the literal sexps
3689 (goto-char (point-min))
3690 (while (re-search-forward "^&?%%(" nil t
)
3693 (setq b
(match-beginning 0))
3694 (goto-char (1- (match-end 0)))
3697 (setq sexp
(buffer-substring b
(point)))
3698 (with-current-buffer sexp-buffer
3700 (princ (org-diary-to-ical-string sexp-buffer
)))))
3702 (when org-icalendar-include-todo
3703 (goto-char (point-min))
3704 (while (re-search-forward org-todo-line-regexp nil t
)
3707 (when (boundp 'org-icalendar-verify-function
)
3708 (unless (funcall org-icalendar-verify-function
)
3709 (outline-next-heading)
3712 (setq state
(match-string 2))
3713 (setq status
(if (member state org-done-keywords
)
3714 "COMPLETED" "NEEDS-ACTION"))
3716 (or (not (member state org-done-keywords
))
3717 (eq org-icalendar-include-todo
'all
))
3718 (not (member org-archive-tag
(org-get-tags-at)))
3720 (setq hd
(match-string 3)
3721 summary
(org-icalendar-cleanup-string
3722 (org-entry-get nil
"SUMMARY"))
3723 desc
(org-icalendar-cleanup-string
3724 (or (org-entry-get nil
"DESCRIPTION")
3725 (and org-icalendar-include-body
(org-get-entry)))
3726 t org-icalendar-include-body
)
3727 location
(org-icalendar-cleanup-string
3728 (org-entry-get nil
"LOCATION")))
3729 (if (string-match org-bracket-link-regexp hd
)
3730 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3731 (match-string 1 hd
))
3733 (if (string-match org-priority-regexp hd
)
3734 (setq pri
(string-to-char (match-string 2 hd
))
3735 hd
(concat (substring hd
0 (match-beginning 1))
3736 (substring hd
(match-end 1))))
3737 (setq pri org-default-priority
))
3738 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3739 (- org-lowest-priority org-highest-priority
))))))
3741 (princ (format "BEGIN:VTODO
3751 (if (and location
(string-match "\\S-" location
))
3752 (concat "\nLOCATION: " location
) "")
3753 (if (and desc
(string-match "\\S-" desc
))
3754 (concat "\nDESCRIPTION: " desc
) "")
3755 category pri status
)))))))))
3757 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3758 "Take out stuff and quote what needs to be quoted.
3759 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3760 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3765 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3766 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3767 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3768 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3770 (while (string-match "\\([,;]\\)" s start
)
3771 (setq start
(+ (match-beginning 0) 2)
3772 s
(replace-match "\\\\\\1" nil nil s
))))
3774 (while (string-match "[ \t]*\n[ \t]*" s
)
3775 (setq s
(replace-match "\\n" t t s
))))
3776 (setq s
(org-trim s
))
3779 (if (and (numberp maxlength
)
3780 (> (length s
) maxlength
))
3781 (setq s
(substring s
0 maxlength
)))))
3784 (defun org-get-entry ()
3785 "Clean-up description string."
3787 (org-back-to-heading t
)
3788 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3790 (defun org-start-icalendar-file (name)
3791 "Start an iCalendar file by inserting the header."
3792 (let ((user user-full-name
)
3793 (name (or name
"unknown"))
3794 (timezone (cadr (current-time-zone))))
3796 (format "BEGIN:VCALENDAR
3799 PRODID:-//%s//Emacs with Org-mode//EN
3801 CALSCALE:GREGORIAN\n" name user timezone
))))
3803 (defun org-finish-icalendar-file ()
3804 "Finish an iCalendar file by inserting the END statement."
3805 (princ "END:VCALENDAR\n"))
3807 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3808 "Take a time string S and convert it to iCalendar format.
3809 KEYWORD is added in front, to make a complete line like DTSTART....
3810 When INC is non-nil, increase the hour by two (if time string contains
3811 a time), or the day by one (if it does not contain a time)."
3812 (let ((t1 (org-parse-time-string s
'nodefault
))
3813 t2 fmt have-time time
)
3814 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3815 (setq t2 t1 have-time t
)
3816 (setq t2
(org-parse-time-string s
)))
3817 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3818 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3821 (if org-agenda-default-appointment-duration
3822 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3825 (setq time
(encode-time s mi h d m y
)))
3826 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3827 (concat keyword
(format-time-string fmt time
))))
3831 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3832 (with-current-buffer buffer
3833 (apply 'insert output
)))
3834 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3837 (defun org-export-as-xoxo (&optional buffer
)
3838 "Export the org buffer as XOXO.
3839 The XOXO buffer is named *xoxo-<source buffer name>*"
3840 (interactive (list (current-buffer)))
3841 ;; A quickie abstraction
3843 ;; Output everything as XOXO
3844 (with-current-buffer (get-buffer buffer
)
3845 (let* ((pos (point))
3846 (opt-plist (org-combine-plists (org-default-export-plist)
3847 (org-infile-export-plist)))
3848 (filename (concat (file-name-as-directory
3849 (org-export-directory :xoxo opt-plist
))
3850 (file-name-sans-extension
3851 (file-name-nondirectory buffer-file-name
))
3853 (out (find-file-noselect filename
))
3856 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3857 ;; Check the output buffer is empty.
3858 (with-current-buffer out
(erase-buffer))
3859 ;; Kick off the output
3860 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3861 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3862 (let* ((hd (match-string-no-properties 1))
3865 (match-string-no-properties 2)
3867 (goto-char (match-end 0))
3872 (if (looking-at "^[ \t]\\(.*\\)")
3873 (setq str
(concat str
(match-string-no-properties 1)))
3874 (throw 'loop str
)))))))))
3876 ;; Handle level rendering
3878 ((> level last-level
)
3879 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3881 ((< level last-level
)
3882 (dotimes (- (- last-level level
) 1)
3884 (org-export-as-xoxo-insert-into out
"</li>\n"))
3885 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3887 (org-export-as-xoxo-insert-into out
"</li>\n")
3888 (setq hanging-li nil
)))
3890 ((equal level last-level
)
3892 (org-export-as-xoxo-insert-into out
"</li>\n")))
3895 (setq last-level level
)
3897 ;; And output the new li
3898 (setq hanging-li
't
)
3899 (if (equal ?
+ (elt text
0))
3900 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3901 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3903 ;; Finally finish off the ol
3904 (dotimes (- last-level
1)
3906 (org-export-as-xoxo-insert-into out
"</li>\n"))
3907 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3910 ;; Finish the buffer off and clean it up.
3911 (switch-to-buffer-other-window out
)
3912 (indent-region (point-min) (point-max) nil
)
3914 (goto-char (point-min))
3919 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3921 ;;; org-exp.el ends here