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, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 (declare-function org-export-latex-preprocess
"org-export-latex" ())
36 (declare-function org-agenda-skip
"org-agenda" ())
37 (declare-function org-infojs-options-inbuffer-template
"org-infojs" ())
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
67 (defcustom org-export-with-special-strings t
68 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
69 When this option is turned on, these strings will be exported as:
72 -----+----------+--------
78 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
79 :group
'org-export-translation
82 (defcustom org-export-language-setup
83 '(("en" "Author" "Date" "Table of Contents")
84 ("cs" "Autor" "Datum" "Obsah")
85 ("da" "Ophavsmand" "Dato" "Indhold")
86 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
87 ("es" "Autor" "Fecha" "\xcdndice")
88 ("fr" "Auteur" "Date" "Table des mati\xe8res")
89 ("it" "Autore" "Data" "Indice")
90 ("nl" "Auteur" "Datum" "Inhoudsopgave")
91 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
92 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
93 "Terms used in export text, translated to different languages.
94 Use the variable `org-export-default-language' to set the language,
95 or use the +OPTION lines for a per-file setting."
96 :group
'org-export-general
99 (string :tag
"HTML language tag")
100 (string :tag
"Author")
102 (string :tag
"Table of Contents"))))
104 (defcustom org-export-default-language
"en"
105 "The default language of HTML export, as a string.
106 This should have an association in `org-export-language-setup'."
107 :group
'org-export-general
110 (defcustom org-export-skip-text-before-1st-heading t
111 "Non-nil means, skip all text before the first headline when exporting.
112 When nil, that text is exported as well."
113 :group
'org-export-general
116 (defcustom org-export-headline-levels
3
117 "The last level which is still exported as a headline.
118 Inferior levels will produce itemize lists when exported.
119 Note that a numeric prefix argument to an exporter function overrides
122 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
123 :group
'org-export-general
126 (defcustom org-export-with-section-numbers t
127 "Non-nil means, add section numbers to headlines when exporting.
129 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
130 :group
'org-export-general
133 (defcustom org-export-with-toc t
134 "Non-nil means, create a table of contents in exported files.
135 The TOC contains headlines with levels up to`org-export-headline-levels'.
136 When an integer, include levels up to N in the toc, this may then be
137 different from `org-export-headline-levels', but it will not be allowed
138 to be larger than the number of headline levels.
139 When nil, no table of contents is made.
141 Headlines which contain any TODO items will be marked with \"(*)\" in
142 ASCII export, and with red color in HTML output, if the option
143 `org-export-mark-todo-in-toc' is set.
145 In HTML output, the TOC will be clickable.
147 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
149 :group
'org-export-general
151 (const :tag
"No Table of Contents" nil
)
152 (const :tag
"Full Table of Contents" t
)
153 (integer :tag
"TOC to level")))
155 (defcustom org-export-mark-todo-in-toc nil
156 "Non-nil means, mark TOC lines that contain any open TODO items."
157 :group
'org-export-general
160 (defcustom org-export-preserve-breaks nil
161 "Non-nil means, preserve all line breaks when exporting.
162 Normally, in HTML output paragraphs will be reformatted. In ASCII
163 export, line breaks will always be preserved, regardless of this variable.
165 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
166 :group
'org-export-general
169 (defcustom org-export-with-archived-trees
'headline
170 "Whether subtrees with the ARCHIVE tag should be exported.
171 This can have three different values
172 nil Do not export, pretend this tree is not present
173 t Do export the entire tree
174 headline Only export the headline, but skip the tree below it."
175 :group
'org-export-general
178 (const :tag
"not at all" nil
)
179 (const :tag
"headline only" 'headline
)
180 (const :tag
"entirely" t
)))
182 (defcustom org-export-author-info t
183 "Non-nil means, insert author name and email into the exported file.
185 This option can also be set with the +OPTIONS line,
186 e.g. \"author-info:nil\"."
187 :group
'org-export-general
190 (defcustom org-export-time-stamp-file t
191 "Non-nil means, insert a time stamp into the exported file.
192 The time stamp shows when the file was created.
194 This option can also be set with the +OPTIONS line,
195 e.g. \"timestamp:nil\"."
196 :group
'org-export-general
199 (defcustom org-export-with-timestamps t
200 "If nil, do not export time stamps and associated keywords."
201 :group
'org-export-general
204 (defcustom org-export-remove-timestamps-from-toc t
205 "If nil, remove timestamps from the table of contents entries."
206 :group
'org-export-general
209 (defcustom org-export-with-tags
'not-in-toc
210 "If nil, do not export tags, just remove them from headlines.
211 If this is the symbol `not-in-toc', tags will be removed from table of
212 contents entries, but still be shown in the headlines of the document.
214 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
215 :group
'org-export-general
217 (const :tag
"Off" nil
)
218 (const :tag
"Not in TOC" not-in-toc
)
219 (const :tag
"On" t
)))
221 (defcustom org-export-with-drawers nil
222 "Non-nil means, export with drawers like the property drawer.
223 When t, all drawers are exported. This may also be a list of
224 drawer names to export."
225 :group
'org-export-general
227 (const :tag
"All drawers" t
)
228 (const :tag
"None" nil
)
229 (repeat :tag
"Selected drawers"
230 (string :tag
"Drawer name"))))
232 (defvar org-export-preprocess-hook nil
233 "Hook for preprocessing an export buffer.
234 Pretty much the first thing when exporting is running this hook.")
236 (defgroup org-export-translation nil
237 "Options for translating special ascii sequences for the export backends."
238 :tag
"Org Export Translation"
241 (defcustom org-export-with-emphasize t
242 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
243 If the export target supports emphasizing text, the word will be
244 typeset in bold, italic, or underlined, respectively. Works only for
245 single words, but you can say: I *really* *mean* *this*.
246 Not all export backends support this.
248 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
249 :group
'org-export-translation
252 (defcustom org-export-with-footnotes t
253 "If nil, export [1] as a footnote marker.
254 Lines starting with [1] will be formatted as footnotes.
256 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
257 :group
'org-export-translation
260 (defcustom org-export-with-sub-superscripts t
261 "Non-nil means, interpret \"_\" and \"^\" for export.
262 When this option is turned on, you can use TeX-like syntax for sub- and
263 superscripts. Several characters after \"_\" or \"^\" will be
264 considered as a single item - so grouping with {} is normally not
265 needed. For example, the following things will be parsed as single
266 sub- or superscripts.
268 10^24 or 10^tau several digits will be considered 1 item.
269 10^-12 or 10^-tau a leading sign with digits or a word
270 x^2-y^3 will be read as x^2 - y^3, because items are
271 terminated by almost any nonword/nondigit char.
272 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
274 Still, ambiguity is possible - so when in doubt use {} to enclose the
275 sub/superscript. If you set this variable to the symbol `{}',
276 the braces are *required* in order to trigger interpretations as
277 sub/superscript. This can be helpful in documents that need \"_\"
278 frequently in plain text.
280 Not all export backends support this, but HTML does.
282 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
283 :group
'org-export-translation
285 (const :tag
"Always interpret" t
)
286 (const :tag
"Only with braces" {})
287 (const :tag
"Never interpret" nil
)))
289 (defcustom org-export-with-special-strings t
290 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
291 When this option is turned on, these strings will be exported as:
297 Not all export backends support this, but HTML does.
299 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
300 :group
'org-export-translation
303 (defcustom org-export-with-TeX-macros t
304 "Non-nil means, interpret simple TeX-like macros when exporting.
305 For example, HTML export converts \\alpha to α and \\AA to Å.
306 No only real TeX macros will work here, but the standard HTML entities
307 for math can be used as macro names as well. For a list of supported
308 names in HTML export, see the constant `org-html-entities'.
309 Not all export backends support this.
311 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
312 :group
'org-export-translation
313 :group
'org-export-latex
316 (defcustom org-export-with-LaTeX-fragments nil
317 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
318 When set, the exporter will find LaTeX environments if the \\begin line is
319 the first non-white thing on a line. It will also find the math delimiters
320 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
323 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
324 :group
'org-export-translation
325 :group
'org-export-latex
328 (defcustom org-export-with-fixed-width t
329 "Non-nil means, lines starting with \":\" will be in fixed width font.
330 This can be used to have pre-formatted text, fragments of code etc. For
332 : ;; Some Lisp examples
335 will be looking just like this in also HTML. See also the QUOTE keyword.
336 Not all export backends support this.
338 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
339 :group
'org-export-translation
342 (defcustom org-match-sexp-depth
3
343 "Number of stacked braces for sub/superscript matching.
344 This has to be set before loading org.el to be effective."
345 :group
'org-export-translation
348 (defgroup org-export-tables nil
349 "Options for exporting tables in Org-mode."
350 :tag
"Org Export Tables"
353 (defcustom org-export-with-tables t
354 "If non-nil, lines starting with \"|\" define a table.
357 | Name | Address | Birthday |
358 |-------------+----------+-----------|
359 | Arthur Dent | England | 29.2.2100 |
361 Not all export backends support this.
363 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
364 :group
'org-export-tables
367 (defcustom org-export-highlight-first-table-line t
368 "Non-nil means, highlight the first table line.
369 In HTML export, this means use <th> instead of <td>.
370 In tables created with table.el, this applies to the first table line.
371 In Org-mode tables, all lines before the first horizontal separator
372 line will be formatted with <th> tags."
373 :group
'org-export-tables
376 (defcustom org-export-table-remove-special-lines t
377 "Remove special lines and marking characters in calculating tables.
378 This removes the special marking character column from tables that are set
379 up for spreadsheet calculations. It also removes the entire lines
380 marked with `!', `_', or `^'. The lines with `$' are kept, because
381 the values of constants may be useful to have."
382 :group
'org-export-tables
385 (defcustom org-export-prefer-native-exporter-for-tables nil
386 "Non-nil means, always export tables created with table.el natively.
387 Natively means, use the HTML code generator in table.el.
388 When nil, Org-mode's own HTML generator is used when possible (i.e. if
389 the table does not use row- or column-spanning). This has the
390 advantage, that the automatic HTML conversions for math symbols and
391 sub/superscripts can be applied. Org-mode's HTML generator is also
393 :group
'org-export-tables
396 (defgroup org-export-ascii nil
397 "Options specific for ASCII export of Org-mode files."
398 :tag
"Org Export ASCII"
401 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
402 "Characters for underlining headings in ASCII export.
403 In the given sequence, these characters will be used for level 1, 2, ..."
404 :group
'org-export-ascii
405 :type
'(repeat character
))
407 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
408 "Bullet characters for headlines converted to lists in ASCII export.
409 The first character is used for the first lest level generated in this
410 way, and so on. If there are more levels than characters given here,
411 the list will be repeated.
412 Note that plain lists will keep the same bullets as the have in the
414 :group
'org-export-ascii
415 :type
'(repeat character
))
417 (defgroup org-export-xml nil
418 "Options specific for XML export of Org-mode files."
419 :tag
"Org Export XML"
422 (defgroup org-export-html nil
423 "Options specific for HTML export of Org-mode files."
424 :tag
"Org Export HTML"
427 (defcustom org-export-html-coding-system nil
428 "Coding system for HTML export, defaults to buffer-file-coding-system."
429 :group
'org-export-html
430 :type
'coding-system
)
432 (defcustom org-export-html-extension
"html"
433 "The extension for exported HTML files."
434 :group
'org-export-html
437 (defcustom org-export-html-link-up
""
438 "Where should the \"UP\" link of exported HTML pages lead?"
439 :group
'org-export-html
440 :type
'(string :tag
"File or URL"))
442 (defcustom org-export-html-link-home
""
443 "Where should the \"HOME\" link of exported HTML pages lead?"
444 :group
'org-export-html
445 :type
'(string :tag
"File or URL"))
447 (defcustom org-export-html-style
448 "<style type=\"text/css\">
450 font-family: Times, serif;
453 .title { text-align: center; }
454 .todo { color: red; }
455 .done { color: green; }
456 .timestamp { color: grey }
457 .timestamp-kwd { color: CadetBlue }
458 .tag { background-color:lightblue; font-weight:normal }
461 border: 1pt solid #AEBDCC;
462 background-color: #F3F5F7;
464 font-family: courier, monospace;
466 table { border-collapse: collapse; }
469 <!--border: 1pt solid #ADB9CC;-->
472 "The default style specification for exported HTML files.
473 Since there are different ways of setting style information, this variable
474 needs to contain the full HTML structure to provide a style, including the
475 surrounding HTML tags. The style specifications should include definitions
476 for new classes todo, done, title, and deadline. For example, valid values
479 <style type=\"text/css\">
480 p { font-weight: normal; color: gray; }
482 .title { text-align: center; }
483 .todo, .deadline { color: red; }
484 .done { color: green; }
487 or, if you want to keep the style in a file,
489 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
491 As the value of this option simply gets inserted into the HTML <head> header,
492 you can \"misuse\" it to add arbitrary text to the header."
493 :group
'org-export-html
497 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
498 "Format for typesetting the document title in HTML export."
499 :group
'org-export-html
502 (defcustom org-export-html-toplevel-hlevel
2
503 "The <H> level for level 1 headings in HTML export."
504 :group
'org-export-html
507 (defcustom org-export-html-link-org-files-as-html t
508 "Non-nil means, make file links to `file.org' point to `file.html'.
509 When org-mode is exporting an org-mode file to HTML, links to
510 non-html files are directly put into a href tag in HTML.
511 However, links to other Org-mode files (recognized by the
512 extension `.org.) should become links to the corresponding html
513 file, assuming that the linked org-mode file will also be
515 When nil, the links still point to the plain `.org' file."
516 :group
'org-export-html
519 (defcustom org-export-html-inline-images
'maybe
520 "Non-nil means, inline images into exported HTML pages.
521 This is done using an <img> tag. When nil, an anchor with href is used to
522 link to the image. If this option is `maybe', then images in links with
523 an empty description will be inlined, while images with a description will
525 :group
'org-export-html
526 :type
'(choice (const :tag
"Never" nil
)
527 (const :tag
"Always" t
)
528 (const :tag
"When there is no description" maybe
)))
531 (defcustom org-export-html-expand t
532 "Non-nil means, for HTML export, treat @<...> as HTML tag.
533 When nil, these tags will be exported as plain text and therefore
534 not be interpreted by a browser.
536 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
537 :group
'org-export-html
540 (defcustom org-export-html-table-tag
541 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
542 "The HTML tag that is used to start a table.
543 This must be a <table> tag, but you may change the options like
544 borders and spacing."
545 :group
'org-export-html
548 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
549 "The opening tag for table header fields.
550 This is customizable so that alignment options can be specified."
551 :group
'org-export-tables
552 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
554 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
555 "The opening tag for table data fields.
556 This is customizable so that alignment options can be specified."
557 :group
'org-export-tables
558 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
560 (defcustom org-export-html-with-timestamp nil
561 "If non-nil, write `org-export-html-html-helper-timestamp'
562 into the exported HTML text. Otherwise, the buffer will just be saved
564 :group
'org-export-html
567 (defcustom org-export-html-html-helper-timestamp
568 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
569 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
570 :group
'org-export-html
573 (defgroup org-export-icalendar nil
574 "Options specific for iCalendar export of Org-mode files."
575 :tag
"Org Export iCalendar"
578 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
579 "The file name for the iCalendar file covering all agenda files.
580 This file is created with the command \\[org-export-icalendar-all-agenda-files].
581 The file name should be absolute, the file will be overwritten without warning."
582 :group
'org-export-icalendar
585 (defcustom org-icalendar-include-todo nil
586 "Non-nil means, export to iCalendar files should also cover TODO items."
587 :group
'org-export-icalendar
589 (const :tag
"None" nil
)
590 (const :tag
"Unfinished" t
)
591 (const :tag
"All" all
)))
593 (defcustom org-icalendar-include-sexps t
594 "Non-nil means, export to iCalendar files should also cover sexp entries.
595 These are entries like in the diary, but directly in an Org-mode file."
596 :group
'org-export-icalendar
599 (defcustom org-icalendar-include-body
100
600 "Amount of text below headline to be included in iCalendar export.
601 This is a number of characters that should maximally be included.
602 Properties, scheduling and clocking lines will always be removed.
603 The text will be inserted into the DESCRIPTION field."
604 :group
'org-export-icalendar
606 (const :tag
"Nothing" nil
)
607 (const :tag
"Everything" t
)
608 (integer :tag
"Max characters")))
610 (defcustom org-icalendar-combined-name
"OrgMode"
611 "Calendar name for the combined iCalendar representing all agenda files."
612 :group
'org-export-icalendar
617 ;;; Variables, constants, and parameter plists
619 (defconst org-level-max
20)
621 (defvar org-export-html-preamble nil
622 "Preamble, to be inserted just after <body>. Set by publishing functions.")
623 (defvar org-export-html-postamble nil
624 "Preamble, to be inserted just before </body>. Set by publishing functions.")
625 (defvar org-export-html-auto-preamble t
626 "Should default preamble be inserted? Set by publishing functions.")
627 (defvar org-export-html-auto-postamble t
628 "Should default postamble be inserted? Set by publishing functions.")
629 (defvar org-current-export-file nil
) ; dynamically scoped parameter
630 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
632 (defconst org-export-plist-vars
633 '((:link-up . org-export-html-link-up
)
634 (:link-home . org-export-html-link-home
)
635 (:language . org-export-default-language
)
636 (:customtime . org-display-custom-times
)
637 (:headline-levels . org-export-headline-levels
)
638 (:section-numbers . org-export-with-section-numbers
)
639 (:table-of-contents . org-export-with-toc
)
640 (:preserve-breaks . org-export-preserve-breaks
)
641 (:archived-trees . org-export-with-archived-trees
)
642 (:emphasize . org-export-with-emphasize
)
643 (:sub-superscript . org-export-with-sub-superscripts
)
644 (:special-strings . org-export-with-special-strings
)
645 (:footnotes . org-export-with-footnotes
)
646 (:drawers . org-export-with-drawers
)
647 (:tags . org-export-with-tags
)
648 (:TeX-macros . org-export-with-TeX-macros
)
649 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
650 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
651 (:fixed-width . org-export-with-fixed-width
)
652 (:timestamps . org-export-with-timestamps
)
653 (:author-info . org-export-author-info
)
654 (:time-stamp-file . org-export-time-stamp-file
)
655 (:tables . org-export-with-tables
)
656 (:table-auto-headline . org-export-highlight-first-table-line
)
657 (:style . org-export-html-style
)
658 (:agenda-style . org-agenda-export-html-style
)
659 (:convert-org-links . org-export-html-link-org-files-as-html
)
660 (:inline-images . org-export-html-inline-images
)
661 (:html-extension . org-export-html-extension
)
662 (:html-table-tag . org-export-html-table-tag
)
663 (:expand-quoted-html . org-export-html-expand
)
664 (:timestamp . org-export-html-with-timestamp
)
665 (:publishing-directory . org-export-publishing-directory
)
666 (:preamble . org-export-html-preamble
)
667 (:postamble . org-export-html-postamble
)
668 (:auto-preamble . org-export-html-auto-preamble
)
669 (:auto-postamble . org-export-html-auto-postamble
)
670 (:author . user-full-name
)
671 (:email . user-mail-address
)))
673 (defun org-default-export-plist ()
674 "Return the property list with default settings for the export variables."
675 (let ((l org-export-plist-vars
) rtn e
)
676 (while (setq e
(pop l
))
677 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
680 (defvar org-export-inbuffer-options-extra nil
681 "List of additional in-buffer options that should be detected.
682 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
683 etc. Extensions can add to this list to get their options detected, and they
684 can then add a function to `org-export-options-filters' to process these
686 Each element in this list must be a list, with the in-buffer keyword as car,
687 and a property (a symbol) as the next element. All occurences of the
688 keyword will be found, the values concatenated with a space character
689 in between, and the result stored in the export options property list.")
691 (defvar org-export-options-filters nil
692 "Functions to be called to finalize the export/publishing options.
693 All these options are stored in a property list, and each of the functions
694 in this hook gets a chance to modify this property list. Each function
695 must accept the property list as an argument, and must return the (possibly
698 (defun org-infile-export-plist ()
699 "Return the property list with file-local settings for export."
704 (let ((re (org-make-options-regexp
706 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
707 "LINK_UP" "LINK_HOME")
708 (mapcar 'car org-export-inbuffer-options-extra
))))
709 p key val text options js-up js-main js-css js-opt a pr
)
710 (while (re-search-forward re nil t
)
711 (setq key
(org-match-string-no-properties 1)
712 val
(org-match-string-no-properties 2))
714 ((setq a
(assoc key org-export-inbuffer-options-extra
))
716 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
717 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
718 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
719 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
720 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
721 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
722 ((string-equal key
"TEXT")
723 (setq text
(if text
(concat text
"\n" val
) val
)))
724 ((string-equal key
"OPTIONS")
725 (setq options
(concat options
" " val
)))
726 ((string-equal key
"LINK_UP")
727 (setq p
(plist-put p
:link-up val
)))
728 ((string-equal key
"LINK_HOME")
729 (setq p
(plist-put p
:link-home val
)))))
730 (setq p
(plist-put p
:text text
))
732 (let ((op '(("H" .
:headline-levels
)
733 ("num" .
:section-numbers
)
734 ("toc" .
:table-of-contents
)
735 ("\\n" .
:preserve-breaks
)
736 ("@" .
:expand-quoted-html
)
739 ("^" .
:sub-superscript
)
740 ("-" .
:special-strings
)
745 ("TeX" .
:TeX-macros
)
746 ("LaTeX" .
:LaTeX-fragments
)
747 ("skip" .
:skip-before-1st-heading
)
748 ("author" .
:author-info
)
749 ("timestamp" .
:time-stamp-file
)))
751 (while (setq o
(pop op
))
752 (if (string-match (concat (regexp-quote (car o
))
753 ":\\([^ \t\n\r;,.]*\\)")
755 (setq p
(plist-put p
(cdr o
)
756 (car (read-from-string
757 (match-string 1 options
)))))))))
760 (defun org-export-directory (type plist
)
761 (let* ((val (plist-get plist
:publishing-directory
))
763 (or (cdr (assoc type val
)) ".")
767 (defun org-export-process-option-filters (plist)
768 (let ((functions org-export-options-filters
) f
)
769 (while (setq f
(pop functions
))
770 (setq plist
(funcall f plist
))))
774 (defun org-export (&optional arg
)
775 "Export dispatcher for Org-mode.
776 When `org-export-run-in-background' is non-nil, try to run the command
777 in the background. This will be done only for commands that write
778 to a file. For details see the docstring of `org-export-run-in-background'.
780 The prefix argument ARG will be passed to the exporter. However, if
781 ARG is a double universal prefix `C-u C-u', that means to inverse the
782 value of `org-export-run-in-background'."
784 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
785 (help "[t] insert the export option template
786 \[v] limit export to visible part of outline tree
791 \[H] export as HTML to temporary buffer
792 \[R] export region as HTML
793 \[b] export as HTML and browse immediately
797 \[L] export as LaTeX to temporary buffer
799 \[i] export current file as iCalendar file
800 \[I] export all agenda files as iCalendar files
801 \[c] export agenda files into combined iCalendar file
803 \[F] publish current file
804 \[P] publish current project
805 \[X] publish... (project will be prompted for)
806 \[A] publish all projects")
808 '((?t org-insert-export-options-template nil
)
809 (?v org-export-visible nil
)
810 (?a org-export-as-ascii t
)
811 (?h org-export-as-html t
)
812 (?b org-export-as-html-and-open t
)
813 (?H org-export-as-html-to-buffer nil
)
814 (?R org-export-region-as-html nil
)
815 (?x org-export-as-xoxo t
)
816 (?l org-export-as-latex t
)
817 (?L org-export-as-latex-to-buffer nil
)
818 (?i org-export-icalendar-this-file t
)
819 (?I org-export-icalendar-all-agenda-files t
)
820 (?c org-export-icalendar-combine-agenda-files t
)
821 (?F org-publish-current-file t
)
822 (?P org-publish-current-project t
)
824 (?A org-publish-all t
)))
826 (save-window-excursion
827 (delete-other-windows)
828 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
830 (message "Select command: ")
831 (setq r1
(read-char-exclusive)))
832 (setq r2
(if (< r1
27) (+ r1
96) r1
))
833 (unless (setq ass
(assq r2 cmds
))
834 (error "No command associated with key %c" r1
))
835 (if (and bg
(nth 2 ass
))
836 ;; execute in background
837 (let ((p (start-process
838 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
840 (expand-file-name invocation-name invocation-directory
)
843 "--eval" "(require 'org-exp)"
844 "--eval" "(setq org-wait .2)"
846 "-f" (symbol-name (nth 1 ass
)))))
847 (set-process-sentinel p
'org-export-process-sentinel
)
848 (message "Background process \"%s\": started" p
))
849 ;; background processing not requested, or not possible
850 (call-interactively (nth 1 ass
)))))
852 (defun org-export-process-sentinel (process status
)
853 (if (string-match "\n+\\'" status
)
854 (setq status
(substring status
0 -
1)))
855 (message "Background process \"%s\": %s" process status
))
857 (defconst org-html-entities
898 ("Aring") ("AA".
"Å")
987 ("varepsilon".
"ε")
1000 ("sigmaf") ("varsigma".
"ς")
1008 ("thetasym") ("vartheta".
"ϑ")
1011 ("bull") ("bullet".
"•")
1012 ("hellip") ("dots".
"…")
1022 ("larr") ("leftarrow".
"←") ("gets".
"←")
1023 ("uarr") ("uparrow".
"↑")
1024 ("rarr") ("to".
"→") ("rightarrow".
"→")
1025 ("darr")("downarrow".
"↓")
1026 ("harr") ("leftrightarrow".
"↔")
1027 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1028 ("lArr") ("Leftarrow".
"⇐")
1029 ("uArr") ("Uparrow".
"⇑")
1030 ("rArr") ("Rightarrow".
"⇒")
1031 ("dArr") ("Downarrow".
"⇓")
1032 ("hArr") ("Leftrightarrow".
"⇔")
1034 ("part") ("partial".
"∂")
1035 ("exist") ("exists".
"∃")
1036 ("empty") ("emptyset".
"∅")
1038 ("isin") ("in".
"∈")
1044 ("lowast") ("ast".
"∗")
1046 ("prop") ("proptp".
"∝")
1047 ("infin") ("infty".
"∞")
1048 ("ang") ("angle".
"∠")
1049 ("and") ("wedge".
"∧")
1050 ("or") ("vee".
"∨")
1056 ("cong") ("simeq".
"≅")
1057 ("asymp")("approx".
"≈")
1058 ("ne") ("neq".
"≠")
1062 ("sub") ("subset".
"⊂")
1063 ("sup") ("supset".
"⊃")
1070 ("sdot") ("cdot".
"⋅")
1077 ("loz") ("Diamond".
"◊")
1078 ("spades") ("spadesuit".
"♠")
1079 ("clubs") ("clubsuit".
"♣")
1080 ("hearts") ("diamondsuit".
"♥")
1081 ("diams") ("diamondsuit".
"♦")
1082 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1149 "Entities for TeX->HTML translation.
1150 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1151 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1152 In that case, \"\\ent\" will be translated to \"&other;\".
1153 The list contains HTML entities for Latin-1, Greek and other symbols.
1154 It is supplemented by a number of commonly used TeX macros with appropriate
1155 translations. There is currently no way for users to extend this.")
1157 ;;; General functions for all backends
1159 (defun org-export-preprocess-string (string &rest parameters
)
1160 "Cleanup STRING so that that the true exported has a more consistent source.
1161 This function takes STRING, which should be a buffer-string of an org-file
1162 to export. It then creates a temporary buffer where it does its job.
1163 The result is then again returned as a string, and the exporter works
1164 on this string to produce the exported version."
1166 (let* ((re-radio (and org-target-link-regexp
1167 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1168 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1169 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1170 (re-archive (concat ":" org-archive-tag
":"))
1171 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1172 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1173 (htmlp (plist-get parameters
:for-html
))
1174 (asciip (plist-get parameters
:for-ascii
))
1175 (latexp (plist-get parameters
:for-LaTeX
))
1176 (commentsp (plist-get parameters
:comments
))
1177 (archived-trees (plist-get parameters
:archived-trees
))
1178 (inhibit-read-only t
)
1179 (drawers org-drawers
)
1180 (exp-drawers (plist-get parameters
:drawers
))
1181 (outline-regexp "\\*+ ")
1182 target-alist tmp target level
1185 (with-current-buffer (get-buffer-create " org-mode-tmp")
1189 (run-hooks 'org-export-preprocess-hook
)
1191 ;; Remove license-to-kill stuff
1192 ;; The caller markes some stuff fo killing, stuff that has been
1193 ;; used to create the page title, for example.
1194 (while (setq p
(text-property-any (point-min) (point-max)
1195 :org-license-to-kill t
))
1196 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1198 (let ((org-inhibit-startup t
)) (org-mode))
1199 (untabify (point-min) (point-max))
1201 ;; Handle source code snippets
1202 (org-export-replace-src-segments)
1204 ;; Get rid of drawers
1205 (unless (eq t exp-drawers
)
1206 (goto-char (point-min))
1207 (let ((re (concat "^[ \t]*:\\("
1210 (org-delete-all exp-drawers
1211 (copy-sequence drawers
))
1213 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1214 (while (re-search-forward re nil t
)
1215 (replace-match ""))))
1217 ;; Get the correct stuff before the first headline
1218 (when (plist-get parameters
:skip-before-1st-heading
)
1219 (goto-char (point-min))
1220 (when (re-search-forward "^\\*+[ \t]" nil t
)
1221 (delete-region (point-min) (match-beginning 0))
1222 (goto-char (point-min))
1224 (when (plist-get parameters
:add-text
)
1225 (goto-char (point-min))
1226 (insert (plist-get parameters
:add-text
) "\n"))
1228 ;; Get rid of archived trees
1229 (when (not (eq archived-trees t
))
1230 (goto-char (point-min))
1231 (while (re-search-forward re-archive nil t
)
1232 (if (not (org-on-heading-p t
))
1233 (org-end-of-subtree t
)
1234 (beginning-of-line 1)
1235 (setq a
(if archived-trees
1236 (1+ (point-at-eol)) (point))
1237 b
(org-end-of-subtree t
))
1238 (if (> b a
) (delete-region a b
)))))
1240 ;; Find all headings and compute the targets for them
1241 (goto-char (point-min))
1242 (org-init-section-numbers)
1243 (let ((re (concat "^" org-outline-regexp
)))
1244 (while (re-search-forward re nil t
)
1245 (setq level
(org-reduced-level
1246 (save-excursion (goto-char (point-at-bol))
1247 (org-outline-level))))
1248 (setq target
(org-solidify-link-text
1249 (format "sec-%s" (org-section-number level
))))
1250 (push (cons target target
) target-alist
)
1251 (add-text-properties
1252 (point-at-bol) (point-at-eol)
1253 (list 'target target
))))
1255 ;; Find targets in comments and move them out of comments,
1256 ;; but mark them as targets that should be invisible
1257 (goto-char (point-min))
1258 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1259 ;; Check if the line before or after is a headline with a target
1260 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1261 (get-text-property (point-at-bol 2) 'target
)))
1263 ;; use the existing target in a neighboring line
1264 (setq tmp
(match-string 2))
1266 (and (looking-at "\n") (delete-char 1))
1267 (push (cons (org-solidify-link-text tmp
) target
)
1269 ;; Make an invisible target
1270 (replace-match "\\1(INVISIBLE)")))
1272 ;; Protect backend specific stuff, throw away the others.
1274 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1275 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1276 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1278 (goto-char (point-min))
1279 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1280 (goto-char (match-end 0))
1281 (while (not (looking-at "#\\+END_EXAMPLE"))
1283 (beginning-of-line 2)))
1284 (goto-char (point-min))
1285 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1286 (add-text-properties (match-beginning 0) (match-end 0)
1287 '(org-protected t
)))
1289 (setq fmt
(pop formatters
))
1291 (goto-char (point-min))
1292 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1293 ":[ \t]*\\(.*\\)") nil t
)
1294 (replace-match "\\1" t
)
1295 (add-text-properties
1296 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1297 '(org-protected t
))))
1298 (goto-char (point-min))
1299 (while (re-search-forward
1301 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1302 (cadddr fmt
) "\\>.*\n?") nil t
)
1304 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1306 (delete-region (match-beginning 0) (match-end 0))))))
1308 ;; Protect quoted subtrees
1309 (goto-char (point-min))
1310 (while (re-search-forward re-quote nil t
)
1311 (goto-char (match-beginning 0))
1313 (add-text-properties (point) (org-end-of-subtree t
)
1314 '(org-protected t
)))
1316 ;; Protect verbatim elements
1317 (goto-char (point-min))
1318 (while (re-search-forward org-verbatim-re nil t
)
1319 (add-text-properties (match-beginning 4) (match-end 4)
1321 (goto-char (1+ (match-end 4))))
1324 (goto-char (point-min))
1325 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)quote\\>.*" nil t
)
1326 (replace-match (if (equal (downcase (match-string 1)) "end")
1327 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1330 ;; Remove subtrees that are commented
1331 (goto-char (point-min))
1332 (while (re-search-forward re-commented nil t
)
1333 (goto-char (match-beginning 0))
1334 (delete-region (point) (org-end-of-subtree t
)))
1336 ;; Remove special table lines
1337 (when org-export-table-remove-special-lines
1338 (goto-char (point-min))
1339 (while (re-search-forward "^[ \t]*|" nil t
)
1340 (beginning-of-line 1)
1341 (if (or (looking-at "[ \t]*| *[!_^] *|")
1342 (and (looking-at ".*?| *<[0-9]+> *|")
1343 (not (looking-at ".*?| *[^ <|]"))))
1344 (delete-region (max (point-min) (1- (point-at-bol)))
1348 ;; Specific LaTeX stuff
1350 (require 'org-export-latex nil
)
1351 (org-export-latex-preprocess))
1354 (org-export-ascii-clean-string))
1356 ;; Specific HTML stuff
1358 ;; Convert LaTeX fragments to images
1359 (when (plist-get parameters
:LaTeX-fragments
)
1361 (concat "ltxpng/" (file-name-sans-extension
1362 (file-name-nondirectory
1363 org-current-export-file
)))
1364 org-current-export-dir nil
"Creating LaTeX image %s"))
1365 (message "Exporting..."))
1367 ;; Remove or replace comments
1368 (goto-char (point-min))
1369 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1371 (progn (add-text-properties
1372 (match-beginning 0) (match-end 0) '(org-protected t
))
1373 (replace-match (format commentsp
(match-string 1)) t t
))
1374 (replace-match "")))
1376 ;; Find matches for radio targets and turn them into internal links
1377 (goto-char (point-min))
1379 (while (re-search-forward re-radio nil t
)
1381 (replace-match "\\1[[\\2]]"))))
1383 ;; Find all links that contain a newline and put them into a single line
1384 (goto-char (point-min))
1385 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1387 (replace-match "\\1 \\3")
1388 (goto-char (match-beginning 0))))
1390 ;; Find all internal links. If they have a fuzzy match (i.e. not
1391 ;; a *dedicated* target match, let the link point to the
1392 ;; correspinding section.
1394 (goto-char (point-min))
1395 (while (re-search-forward org-bracket-link-regexp nil t
)
1397 (let* ((md (match-data))
1398 (desc (match-end 2))
1399 (link (org-link-unescape (match-string 1)))
1400 (slink (org-solidify-link-text link
))
1403 (or (cdr (assoc slink target-alist
))
1405 (unless (string-match org-link-types-re link
)
1406 (setq found
(condition-case nil
(org-link-search link
)
1409 (or (org-on-heading-p)
1410 (not (eq found
'dedicated
))))
1411 (or (get-text-property (point) 'target
)
1414 (1- (previous-single-property-change
1419 (goto-char (match-beginning 1))
1420 (setq props
(text-properties-at (point)))
1421 (delete-region (match-beginning 1) (match-end 1))
1424 (unless desc
(insert "][" link
))
1425 (add-text-properties pos
(point) props
)))))
1427 ;; Normalize links: Convert angle and plain links into bracket links
1428 ;; Expand link abbreviations
1429 (goto-char (point-min))
1430 (while (re-search-forward re-plain-link nil t
)
1431 (goto-char (1- (match-end 0)))
1433 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1434 ":" (match-string 3) "]]")))
1435 ;; added 'org-link face to links
1436 (put-text-property 0 (length s
) 'face
'org-link s
)
1437 (replace-match s t t
))))
1438 (goto-char (point-min))
1439 (while (re-search-forward re-angle-link nil t
)
1440 (goto-char (1- (match-end 0)))
1442 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1443 ":" (match-string 3) "]]")))
1444 (put-text-property 0 (length s
) 'face
'org-link s
)
1445 (replace-match s t t
))))
1446 (goto-char (point-min))
1447 (while (re-search-forward org-bracket-link-regexp nil t
)
1449 (let* ((s (concat "[[" (setq xx
(save-match-data
1450 (org-link-expand-abbrev (match-string 1))))
1454 (concat "[" xx
"]"))
1456 (put-text-property 0 (length s
) 'face
'org-link s
)
1457 (replace-match s t t
))))
1459 ;; Find multiline emphasis and put them into single line
1460 (when (plist-get parameters
:emph-multiline
)
1461 (goto-char (point-min))
1462 (while (re-search-forward org-emph-re nil t
)
1463 (if (not (= (char-after (match-beginning 3))
1464 (char-after (match-beginning 4))))
1466 (subst-char-in-region (match-beginning 0) (match-end 0)
1468 (goto-char (1- (match-end 0))))
1469 (goto-char (1+ (match-beginning 0))))))
1471 (setq rtn
(buffer-string)))
1472 (kill-buffer " org-mode-tmp")
1475 (defun org-export-grab-title-from-buffer ()
1476 "Get a title for the current document, from looking at the buffer."
1477 (let ((inhibit-read-only t
))
1479 (goto-char (point-min))
1480 (let ((end (save-excursion (outline-next-heading) (point))))
1481 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1482 ;; Mark the line so that it will not be exported as normal text.
1484 (add-text-properties (match-beginning 0) (match-end 0)
1485 (list :org-license-to-kill t
)))
1486 ;; Return the title string
1487 (org-trim (match-string 0)))))))
1489 (defun org-export-get-title-from-subtree ()
1490 "Return subtree title and exclude it from export."
1491 (let (title (m (mark)))
1493 (goto-char (region-beginning))
1494 (when (and (org-at-heading-p)
1495 (>= (org-end-of-subtree t t
) (region-end)))
1496 ;; This is a subtree, we take the title from the first heading
1497 (goto-char (region-beginning))
1498 (looking-at org-todo-line-regexp
)
1499 (setq title
(match-string 3))
1501 (add-text-properties (point) (1+ (point-at-eol))
1502 (list :org-license-to-kill t
)))))
1505 (defun org-solidify-link-text (s &optional alist
)
1506 "Take link text and make a safe target out of it."
1511 (org-split-string s
"[ \t\r\n]+") "=="))
1512 (a (assoc rtn alist
)))
1515 (defun org-get-min-level (lines)
1516 "Get the minimum level in LINES."
1517 (let ((re "^\\(\\*+\\) ") l min
)
1519 (while (setq l
(pop lines
))
1520 (if (string-match re l
)
1521 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1524 ;; Variable holding the vector with section numbers
1525 (defvar org-section-numbers
(make-vector org-level-max
0))
1527 (defun org-init-section-numbers ()
1528 "Initialize the vector for the section numbers."
1530 (numbers (nreverse (org-split-string "" "\\.")))
1531 (depth (1- (length org-section-numbers
)))
1532 (i depth
) number-string
)
1535 (aset org-section-numbers i
0)
1536 (setq number-string
(or (car numbers
) "0"))
1537 (if (string-match "\\`[A-Z]\\'" number-string
)
1538 (aset org-section-numbers i
1539 (- (string-to-char number-string
) ?A -
1))
1540 (aset org-section-numbers i
(string-to-number number-string
)))
1544 (defun org-section-number (&optional level
)
1545 "Return a string with the current section number.
1546 When LEVEL is non-nil, increase section numbers on that level."
1547 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1550 (aset org-section-numbers
1551 level
(1+ (aref org-section-numbers level
))))
1552 (setq idx
(1+ level
))
1553 (while (<= idx depth
)
1555 (aset org-section-numbers idx
0))
1556 (setq idx
(1+ idx
))))
1558 (while (<= idx depth
)
1559 (setq n
(aref org-section-numbers idx
))
1560 (setq string
(concat string
(if (not (string= string
"")) "." "")
1562 (setq idx
(1+ idx
)))
1564 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1565 (setq string
(replace-match "" t nil string
)))
1566 (if (string-match "\\(\\.0\\)+\\'" string
)
1567 (setq string
(replace-match "" t nil string
))))
1570 ;;; Fontification of code
1571 ;; Currently only for th HTML backend, but who knows....
1572 (defun org-export-replace-src-segments ()
1573 "Replace source code segments with special code for export."
1574 (let (lang code trans
)
1575 (goto-char (point-min))
1576 (while (re-search-forward
1577 "^#\\+BEGIN_SRC[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1579 (setq lang
(match-string 1) code
(match-string 2)
1580 trans
(org-export-format-source-code lang code
))
1581 (replace-match trans t t
))))
1583 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1585 (defun org-export-format-source-code (lang code
)
1586 "Format CODE from language LANG and return it formatted for export.
1587 Currently, this only does something for HTML export, for all other
1588 backends, it converts the segment into an EXAMPLE segment."
1592 ;; We are exporting to HTML
1593 (condition-case nil
(require 'htmlize
) (nil t
))
1594 (if (not (fboundp 'htmlize-region-for-paste
))
1596 ;; we do not have htmlize.el, or an old version of it
1598 "htmlize.el 1.34 or later is needed for source code formatting")
1599 (concat "#+BEGIN_EXAMPLE\n" code
1600 (if (string-match "\n\\'" code
) "" "\n")
1602 ;; ok, we are good to go
1603 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1604 (org-startup-folded nil
)
1608 (if (functionp mode
)
1611 (when (eq major-mode
'org-mode
)
1612 ;; Free up the protected stuff
1613 (goto-char (point-min))
1614 (while (re-search-forward "^@\\([*#]\\|[ \t]*:\\)" nil t
)
1615 (replace-match "\\1"))
1617 (font-lock-fontify-buffer)
1618 ;; silence the byte-compiler
1619 (when (fboundp 'htmlize-region-for-paste
)
1620 ;; transform the region to HTML
1621 (htmlize-region-for-paste (point-min) (point-max))))))
1622 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1623 (setq htmltext
(replace-match "<pre class=\"src\">"
1625 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1627 ;; This is not HTML, so just make it an example.
1628 (concat "#+BEGIN_EXAMPLE\n" code
1629 (if (string-match "\n\\'" code
) "" "\n")
1630 "#+END_EXAMPLE\n")))))
1634 (defvar org-last-level nil
) ; dynamically scoped variable
1635 (defvar org-min-level nil
) ; dynamically scoped variable
1636 (defvar org-levels-open nil
) ; dynamically scoped parameter
1637 (defvar org-ascii-current-indentation nil
) ; For communication
1640 (defun org-export-as-ascii (arg)
1641 "Export the outline as a pretty ASCII file.
1642 If there is an active region, export only the region.
1643 The prefix ARG specifies how many levels of the outline should become
1644 underlined headlines. The default is 3."
1646 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1647 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1648 (org-infile-export-plist)))
1649 (region-p (org-region-active-p))
1653 (goto-char (region-beginning))
1654 (and (org-at-heading-p)
1655 (>= (org-end-of-subtree t t
) (region-end))))))
1656 (custom-times org-display-custom-times
)
1657 (org-ascii-current-indentation '(0 .
0))
1661 (case-fold-search nil
)
1662 (filename (concat (file-name-as-directory
1663 (org-export-directory :ascii opt-plist
))
1664 (file-name-sans-extension
1666 (org-entry-get (region-beginning)
1667 "EXPORT_FILE_NAME" t
))
1668 (file-name-nondirectory buffer-file-name
)))
1670 (filename (if (equal (file-truename filename
)
1671 (file-truename buffer-file-name
))
1672 (concat filename
".txt")
1674 (buffer (find-file-noselect filename
))
1675 (org-levels-open (make-vector org-level-max nil
))
1676 (odd org-odd-levels-only
)
1677 (date (plist-get opt-plist
:date
))
1678 (author (plist-get opt-plist
:author
))
1679 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1680 (plist-get opt-plist
:title
)
1682 (plist-get opt-plist
:skip-before-1st-heading
))
1683 (org-export-grab-title-from-buffer))
1684 (file-name-sans-extension
1685 (file-name-nondirectory buffer-file-name
))))
1686 (email (plist-get opt-plist
:email
))
1687 (language (plist-get opt-plist
:language
))
1688 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1689 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1694 (if (org-region-active-p) (region-beginning) (point-min))
1695 (if (org-region-active-p) (region-end) (point-max))))
1696 (lines (org-split-string
1697 (org-export-preprocess-string
1700 :skip-before-1st-heading
1701 (plist-get opt-plist
:skip-before-1st-heading
)
1702 :drawers
(plist-get opt-plist
:drawers
)
1703 :verbatim-multiline t
1705 (plist-get opt-plist
:archived-trees
)
1706 :add-text
(plist-get opt-plist
:text
))
1708 thetoc have-headings first-heading-pos
1709 table-open table-buffer
)
1711 (let ((inhibit-read-only t
))
1713 (remove-text-properties (point-min) (point-max)
1714 '(:org-license-to-kill t
))))
1716 (setq org-min-level
(org-get-min-level lines
))
1717 (setq org-last-level org-min-level
)
1718 (org-init-section-numbers)
1720 (find-file-noselect filename
)
1722 (setq lang-words
(or (assoc language org-export-language-setup
)
1723 (assoc "en" org-export-language-setup
)))
1724 (switch-to-buffer-other-window buffer
)
1727 ;; create local variables for all options, to make sure all called
1728 ;; functions get the correct information
1730 (set (make-local-variable (cdr x
))
1731 (plist-get opt-plist
(car x
))))
1732 org-export-plist-vars
)
1733 (org-set-local 'org-odd-levels-only odd
)
1734 (setq umax
(if arg
(prefix-numeric-value arg
)
1735 org-export-headline-levels
))
1736 (setq umax-toc
(if (integerp org-export-with-toc
)
1737 (min org-export-with-toc umax
)
1741 (if title
(org-insert-centered title ?
=))
1743 (if (and (or author email
)
1744 org-export-author-info
)
1745 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1746 (if email
(concat " <" email
">") "")
1750 ((and date
(string-match "%" date
))
1751 (setq date
(format-time-string date
)))
1753 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1755 (if (and date org-export-time-stamp-file
)
1756 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1760 (if org-export-with-toc
1762 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1763 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1764 (mapc '(lambda (line)
1765 (if (string-match org-todo-line-regexp
1767 ;; This is a headline
1769 (setq have-headings t
)
1770 (setq level
(- (match-end 1) (match-beginning 1))
1771 level
(org-tr-level level
)
1772 txt
(match-string 3 line
)
1774 (or (and org-export-mark-todo-in-toc
1776 (not (member (match-string 2 line
)
1777 org-done-keywords
)))
1779 (and org-export-mark-todo-in-toc
1781 (org-search-todo-below
1782 line lines level
))))
1783 (setq txt
(org-html-expand-for-ascii txt
))
1785 (while (string-match org-bracket-link-regexp txt
)
1788 (match-string (if (match-end 2) 3 1) txt
)
1791 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1793 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1795 (setq txt
(replace-match "" t t txt
)))
1796 (if (string-match quote-re0 txt
)
1797 (setq txt
(replace-match "" t t txt
)))
1799 (if org-export-with-section-numbers
1800 (setq txt
(concat (org-section-number level
)
1802 (if (<= level umax-toc
)
1807 (* (max 0 (- level org-min-level
)) 4) ?\
)
1808 (format (if todo
"%s (*)\n" "%s\n") txt
))
1810 (setq org-last-level level
))
1813 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1815 (org-init-section-numbers)
1816 (while (setq line
(pop lines
))
1817 ;; Remove the quoted HTML tags.
1818 (setq line
(org-html-expand-for-ascii line
))
1820 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1821 (setq line
(replace-match "" t t line
)))
1822 ;; Replace internal links
1823 (while (string-match org-bracket-link-regexp line
)
1824 (setq line
(replace-match
1825 (if (match-end 3) "[\\3]" "[\\1]")
1828 (setq line
(org-translate-time line
)))
1830 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1832 (setq first-heading-pos
(or first-heading-pos
(point)))
1833 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1834 txt
(match-string 2 line
))
1835 (org-ascii-level-start level txt umax lines
))
1837 ((and org-export-with-tables
1838 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1839 (if (not table-open
)
1841 (setq table-open t table-buffer nil
))
1843 (setq table-buffer
(cons line table-buffer
))
1844 (when (or (not lines
)
1845 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1847 (setq table-open nil
1848 table-buffer
(nreverse table-buffer
))
1851 (org-fix-indentation x org-ascii-current-indentation
))
1852 (org-format-table-ascii table-buffer
)
1855 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1856 (if (and org-export-with-fixed-width
1857 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1858 (setq line
(replace-match "\\1" nil nil line
)))
1859 (insert line
"\n"))))
1863 ;; insert the table of contents
1865 (goto-char (point-min))
1866 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1868 (goto-char (match-beginning 0))
1870 (goto-char first-heading-pos
))
1871 (mapc 'insert thetoc
)
1872 (or (looking-at "[ \t]*\n[ \t]*\n")
1875 ;; Convert whitespace place holders
1876 (goto-char (point-min))
1878 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1879 (setq end
(next-single-property-change beg
'org-whitespace
))
1881 (delete-region beg end
)
1882 (insert (make-string (- end beg
) ?\
))))
1885 ;; remove display and invisible chars
1887 (goto-char (point-min))
1888 (while (setq beg
(next-single-property-change (point) 'display
))
1889 (setq end
(next-single-property-change beg
'display
))
1890 (delete-region beg end
)
1893 (goto-char (point-min))
1894 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1895 (setq end
(next-single-property-change beg
'org-cwidth
))
1896 (delete-region beg end
)
1898 (goto-char (point-min))))
1900 (defun org-export-ascii-clean-string ()
1901 "Do extra work for ASCII export"
1902 (goto-char (point-min))
1903 (while (re-search-forward org-verbatim-re nil t
)
1904 (goto-char (match-end 2))
1905 (backward-delete-char 1) (insert "'")
1906 (goto-char (match-beginning 2))
1907 (delete-char 1) (insert "`")
1908 (goto-char (match-end 2))))
1910 (defun org-search-todo-below (line lines level
)
1911 "Search the subtree below LINE for any TODO entries."
1912 (let ((rest (cdr (memq line lines
)))
1913 (re org-todo-line-regexp
)
1916 (while (setq line
(pop rest
))
1917 (if (string-match re line
)
1919 (setq lv
(- (match-end 1) (match-beginning 1))
1920 todo
(and (match-beginning 2)
1921 (not (member (match-string 2 line
)
1922 org-done-keywords
))))
1924 (if (<= lv level
) (throw 'exit nil
))
1925 (if todo
(throw 'exit t
))))))))
1927 (defun org-html-expand-for-ascii (line)
1928 "Handle quoted HTML for ASCII export."
1929 (if org-export-html-expand
1930 (while (string-match "@<[^<>\n]*>" line
)
1931 ;; We just remove the tags for now.
1932 (setq line
(replace-match "" nil nil line
))))
1935 (defun org-insert-centered (s &optional underline
)
1936 "Insert the string S centered and underline it with character UNDERLINE."
1937 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
1938 (insert (make-string ind ?\
) s
"\n")
1940 (insert (make-string ind ?\
)
1941 (make-string (string-width s
) underline
)
1944 (defun org-ascii-level-start (level title umax
&optional lines
)
1945 "Insert a new level in ASCII export."
1946 (let (char (n (- level umax
1)) (ind 0))
1949 (insert (make-string (* 2 n
) ?\
)
1950 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
1951 org-export-ascii-bullets
))
1953 ;; find the indentation of the next non-empty line
1956 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
1957 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
1958 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
1960 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
1961 (if (or (not (equal (char-before) ?
\n))
1962 (not (equal (char-before (1- (point))) ?
\n)))
1964 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
1965 (unless org-export-with-tags
1966 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
1967 (setq title
(replace-match "" t t title
))))
1968 (if org-export-with-section-numbers
1969 (setq title
(concat (org-section-number level
) " " title
)))
1970 (insert title
"\n" (make-string (string-width title
) char
) "\n")
1971 (setq org-ascii-current-indentation
'(0 .
0)))))
1974 (defun org-export-visible (type arg
)
1975 "Create a copy of the visible part of the current buffer, and export it.
1976 The copy is created in a temporary buffer and removed after use.
1977 TYPE is the final key (as a string) that also select the export command in
1978 the `C-c C-e' export dispatcher.
1979 As a special case, if the you type SPC at the prompt, the temporary
1980 org-mode file will not be removed but presented to you so that you can
1981 continue to use it. The prefix arg ARG is passed through to the exporting
1985 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
1986 (read-char-exclusive))
1987 current-prefix-arg
))
1988 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
1989 (error "Invalid export key"))
1990 (let* ((binding (cdr (assoc type
1991 '((?a . org-export-as-ascii
)
1992 (?\C-a . org-export-as-ascii
)
1993 (?b . org-export-as-html-and-open
)
1994 (?\C-b . org-export-as-html-and-open
)
1995 (?h . org-export-as-html
)
1996 (?H . org-export-as-html-to-buffer
)
1997 (?R . org-export-region-as-html
)
1998 (?x . org-export-as-xoxo
)))))
1999 (keepp (equal type ?\
))
2000 (file buffer-file-name
)
2001 (buffer (get-buffer-create "*Org Export Visible*"))
2003 ;; Need to hack the drawers here.
2005 (goto-char (point-min))
2006 (while (re-search-forward org-drawer-regexp nil t
)
2007 (goto-char (match-beginning 1))
2008 (or (org-invisible-p) (org-flag-drawer nil
))))
2009 (with-current-buffer buffer
(erase-buffer))
2011 (setq s
(goto-char (point-min)))
2012 (while (not (= (point) (point-max)))
2013 (goto-char (org-find-invisible))
2014 (append-to-buffer buffer s
(point))
2015 (setq s
(goto-char (org-find-visible))))
2016 (org-cycle-hide-drawers 'all
)
2017 (goto-char (point-min))
2019 ;; Copy all comment lines to the end, to make sure #+ settings are
2020 ;; still available for the second export step. Kind of a hack, but
2021 ;; does do the trick.
2022 (if (looking-at "#[^\r\n]*")
2023 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2024 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2025 (append-to-buffer buffer
(1+ (match-beginning 0))
2026 (min (point-max) (1+ (match-end 0))))))
2028 (let ((buffer-file-name file
)
2029 (org-inhibit-startup t
))
2032 (unless keepp
(funcall binding arg
))))
2034 (kill-buffer buffer
)
2035 (switch-to-buffer-other-window buffer
)
2036 (goto-char (point-min)))))
2038 (defun org-find-visible ()
2040 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2041 (get-char-property s
'invisible
)))
2043 (defun org-find-invisible ()
2045 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2046 (not (get-char-property s
'invisible
))))
2051 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2052 (defun org-get-current-options ()
2053 "Return a string with current options as keyword options.
2054 Does include HTML export options as well as TODO and CATEGORY stuff."
2055 (require 'org-archive
)
2062 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2063 #+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
2070 #+PRIORITIES: %c %c %c
2072 #+STARTUP: %s %s %s %s %s
2077 (buffer-name) (user-full-name) user-mail-address
2078 (format-time-string (car org-time-stamp-formats
))
2079 org-export-default-language
2080 org-export-headline-levels
2081 org-export-with-section-numbers
2083 org-export-preserve-breaks
2084 org-export-html-expand
2085 org-export-with-fixed-width
2086 org-export-with-tables
2087 org-export-with-sub-superscripts
2088 org-export-with-special-strings
2089 org-export-with-footnotes
2090 org-export-with-emphasize
2091 org-export-with-TeX-macros
2092 org-export-with-LaTeX-fragments
2093 org-export-skip-text-before-1st-heading
2094 org-export-with-drawers
2095 org-export-with-tags
2096 (if (featurep 'org-infojs
) (org-infojs-options-inbuffer-template) "")
2097 org-export-html-link-up
2098 org-export-html-link-home
2099 (file-name-nondirectory buffer-file-name
)
2100 "TODO FEEDBACK VERIFY DONE"
2101 "Me Jason Marie DONE"
2102 org-highest-priority org-lowest-priority org-default-priority
2103 (mapconcat 'identity org-drawers
" ")
2104 (cdr (assoc org-startup-folded
2105 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2106 (if org-odd-levels-only
"odd" "oddeven")
2107 (if org-hide-leading-stars
"hidestars" "showstars")
2108 (if org-startup-align-all-tables
"align" "noalign")
2109 (cond ((eq org-log-done t
) "logdone")
2110 ((equal org-log-done
'note
) "lognotedone")
2111 ((not org-log-done
) "nologdone"))
2112 (or (mapconcat (lambda (x)
2114 ((equal '(:startgroup
) x
) "{")
2115 ((equal '(:endgroup
) x
) "}")
2116 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2118 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2119 org-archive-location
2120 "org file:~/org/%s.org"
2124 (defun org-insert-export-options-template ()
2125 "Insert into the buffer a template with information for exporting."
2127 (if (not (bolp)) (newline))
2128 (let ((s (org-get-current-options)))
2129 (and (string-match "#\\+CATEGORY" s
)
2130 (setq s
(substring s
0 (match-beginning 0))))
2134 (defun org-export-as-html-and-open (arg)
2135 "Export the outline as HTML and immediately open it with a browser.
2136 If there is an active region, export only the region.
2137 The prefix ARG specifies how many levels of the outline should become
2138 headlines. The default is 3. Lower levels will become bulleted lists."
2140 (org-export-as-html arg
'hidden
)
2141 (org-open-file buffer-file-name
))
2144 (defun org-export-as-html-batch ()
2145 "Call `org-export-as-html', may be used in batch processing as
2147 --load=$HOME/lib/emacs/org.el
2148 --eval \"(setq org-export-headline-levels 2)\"
2149 --visit=MyFile --funcall org-export-as-html-batch"
2150 (org-export-as-html org-export-headline-levels
'hidden
))
2153 (defun org-export-as-html-to-buffer (arg)
2154 "Call `org-exort-as-html` with output to a temporary buffer.
2155 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2157 (org-export-as-html arg nil nil
"*Org HTML Export*")
2158 (switch-to-buffer-other-window "*Org HTML Export*"))
2161 (defun org-replace-region-by-html (beg end
)
2162 "Assume the current region has org-mode syntax, and convert it to HTML.
2163 This can be used in any buffer. For example, you could write an
2164 itemized list in org-mode syntax in an HTML buffer and then use this
2165 command to convert it."
2167 (let (reg html buf pop-up-frames
)
2168 (save-window-excursion
2170 (setq html
(org-export-region-as-html
2172 (setq reg
(buffer-substring beg end
)
2173 buf
(get-buffer-create "*Org tmp*"))
2174 (with-current-buffer buf
2178 (setq html
(org-export-region-as-html
2179 (point-min) (point-max) t
'string
)))
2181 (delete-region beg end
)
2185 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2186 "Convert region from BEG to END in org-mode buffer to HTML.
2187 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2188 contents, and only produce the region of converted text, useful for
2189 cut-and-paste operations.
2190 If BUFFER is a buffer or a string, use/create that buffer as a target
2191 of the converted HTML. If BUFFER is the symbol `string', return the
2192 produced HTML as a string and leave not buffer behind. For example,
2193 a Lisp program could call this function in the following way:
2195 (setq html (org-export-region-as-html beg end t 'string))
2197 When called interactively, the output buffer is selected, and shown
2198 in a window. A non-interactive call will only return the buffer."
2199 (interactive "r\nP")
2200 (when (interactive-p)
2201 (setq buffer
"*Org HTML Export*"))
2202 (let ((transient-mark-mode t
) (zmacs-regions t
)
2205 (set-mark (point)) ;; to activate the region
2207 (setq rtn
(org-export-as-html
2210 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2211 (if (and (interactive-p) (bufferp rtn
))
2212 (switch-to-buffer-other-window rtn
)
2215 (defvar html-table-tag nil
) ; dynamically scoped into this.
2217 (defun org-export-as-html (arg &optional hidden ext-plist
2218 to-buffer body-only pub-dir
)
2219 "Export the outline as a pretty HTML file.
2220 If there is an active region, export only the region. The prefix
2221 ARG specifies how many levels of the outline should become
2222 headlines. The default is 3. Lower levels will become bulleted
2223 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2224 EXT-PLIST is a property list with external parameters overriding
2225 org-mode's default settings, but still inferior to file-local
2226 settings. When TO-BUFFER is non-nil, create a buffer with that
2227 name and export to that buffer. If TO-BUFFER is the symbol
2228 `string', don't leave any buffer behind but just return the
2229 resulting HTML as a string. When BODY-ONLY is set, don't produce
2230 the file header and footer, simply return the content of
2231 <body>...</body>, without even the body tags themselves. When
2232 PUB-DIR is set, use this as the publishing directory."
2235 ;; Make sure we have a file name when we need it.
2236 (when (and (not (or to-buffer body-only
))
2237 (not buffer-file-name
))
2238 (if (buffer-base-buffer)
2239 (org-set-local 'buffer-file-name
2240 (with-current-buffer (buffer-base-buffer)
2242 (error "Need a file name to be able to export.")))
2244 (message "Exporting...")
2245 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2246 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2247 (setq-default org-done-keywords org-done-keywords
)
2248 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2250 (org-export-process-option-filters
2251 (org-combine-plists (org-default-export-plist)
2253 (org-infile-export-plist))))
2255 (style (plist-get opt-plist
:style
))
2256 (html-extension (plist-get opt-plist
:html-extension
))
2257 (link-validate (plist-get opt-plist
:link-validation-function
))
2258 valid thetoc have-headings first-heading-pos
2259 (odd org-odd-levels-only
)
2260 (region-p (org-region-active-p))
2264 (goto-char (region-beginning))
2265 (and (org-at-heading-p)
2266 (>= (org-end-of-subtree t t
) (region-end))))))
2267 ;; The following two are dynamically scoped into other
2269 (org-current-export-dir
2270 (or pub-dir
(org-export-directory :html opt-plist
)))
2271 (org-current-export-file buffer-file-name
)
2272 (level 0) (line "") (origline "") txt todo
2275 (filename (if to-buffer nil
2278 (file-name-sans-extension
2280 (org-entry-get (region-beginning)
2281 "EXPORT_FILE_NAME" t
))
2282 (file-name-nondirectory buffer-file-name
)))
2284 (file-name-as-directory
2285 (or pub-dir
(org-export-directory :html opt-plist
))))))
2286 (current-dir (if buffer-file-name
2287 (file-name-directory buffer-file-name
)
2289 (buffer (if to-buffer
2291 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2292 (t (get-buffer-create to-buffer
)))
2293 (find-file-noselect filename
)))
2294 (org-levels-open (make-vector org-level-max nil
))
2295 (date (plist-get opt-plist
:date
))
2296 (author (plist-get opt-plist
:author
))
2297 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2298 (plist-get opt-plist
:title
)
2300 (plist-get opt-plist
:skip-before-1st-heading
))
2301 (org-export-grab-title-from-buffer))
2302 (and buffer-file-name
2303 (file-name-sans-extension
2304 (file-name-nondirectory buffer-file-name
)))
2306 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2307 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2308 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2312 (local-list-num nil
)
2313 (local-list-indent nil
)
2314 (llt org-plain-list-ordered-item-terminator
)
2315 (email (plist-get opt-plist
:email
))
2316 (language (plist-get opt-plist
:language
))
2320 (coding-system (and (boundp 'buffer-file-coding-system
)
2321 buffer-file-coding-system
))
2322 (coding-system-for-write (or org-export-html-coding-system
2324 (save-buffer-coding-system (or org-export-html-coding-system
2326 (charset (and coding-system-for-write
2327 (fboundp 'coding-system-get
)
2328 (coding-system-get coding-system-for-write
2332 (if region-p
(region-beginning) (point-min))
2333 (if region-p
(region-end) (point-max))))
2336 (org-export-preprocess-string
2340 :skip-before-1st-heading
2341 (plist-get opt-plist
:skip-before-1st-heading
)
2342 :drawers
(plist-get opt-plist
:drawers
)
2344 (plist-get opt-plist
:archived-trees
)
2346 (plist-get opt-plist
:text
)
2348 (plist-get opt-plist
:LaTeX-fragments
))
2351 table-buffer table-orig-buffer
2352 ind start-is-num starter didclose
2353 rpl path desc descp desc1 desc2 link
2357 (let ((inhibit-read-only t
))
2359 (remove-text-properties (point-min) (point-max)
2360 '(:org-license-to-kill t
))))
2362 (message "Exporting...")
2364 (setq org-min-level
(org-get-min-level lines
))
2365 (setq org-last-level org-min-level
)
2366 (org-init-section-numbers)
2369 ((and date
(string-match "%" date
))
2370 (setq date
(format-time-string date
)))
2372 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2374 ;; Get the language-dependent settings
2375 (setq lang-words
(or (assoc language org-export-language-setup
)
2376 (assoc "en" org-export-language-setup
)))
2378 ;; Switch to the output buffer
2380 (let ((inhibit-read-only t
)) (erase-buffer))
2383 (and (fboundp 'set-buffer-file-coding-system
)
2384 (set-buffer-file-coding-system coding-system-for-write
))
2386 (let ((case-fold-search nil
)
2387 (org-odd-levels-only odd
))
2388 ;; create local variables for all options, to make sure all called
2389 ;; functions get the correct information
2391 (set (make-local-variable (cdr x
))
2392 (plist-get opt-plist
(car x
))))
2393 org-export-plist-vars
)
2394 (setq umax
(if arg
(prefix-numeric-value arg
)
2395 org-export-headline-levels
))
2396 (setq umax-toc
(if (integerp org-export-with-toc
)
2397 (min org-export-with-toc umax
)
2402 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2403 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2404 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2405 lang=\"%s\" xml:lang=\"%s\">
2408 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2409 <meta name=\"generator\" content=\"Org-mode\"/>
2410 <meta name=\"generated\" content=\"%s\"/>
2411 <meta name=\"author\" content=\"%s\"/>
2415 language language
(org-html-expand title
)
2416 (or charset
"iso-8859-1") date author style
))
2418 (insert (or (plist-get opt-plist
:preamble
) ""))
2420 (when (plist-get opt-plist
:auto-preamble
)
2421 (if title
(insert (format org-export-html-title-format
2422 (org-html-expand title
))))))
2424 (if (and org-export-with-toc
(not body-only
))
2426 (push (format "<h%d>%s</h%d>\n"
2427 org-export-html-toplevel-hlevel
2429 org-export-html-toplevel-hlevel
)
2431 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2432 (push "<ul>\n<li>" thetoc
)
2434 (mapcar '(lambda (line)
2435 (if (string-match org-todo-line-regexp line
)
2436 ;; This is a headline
2438 (setq have-headings t
)
2439 (setq level
(- (match-end 1) (match-beginning 1))
2440 level
(org-tr-level level
)
2441 txt
(save-match-data
2443 (org-export-cleanup-toc-line
2444 (match-string 3 line
))))
2446 (or (and org-export-mark-todo-in-toc
2448 (not (member (match-string 2 line
)
2449 org-done-keywords
)))
2451 (and org-export-mark-todo-in-toc
2453 (org-search-todo-below
2454 line lines level
))))
2456 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2457 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2458 (if (string-match quote-re0 txt
)
2459 (setq txt
(replace-match "" t t txt
)))
2460 (setq snumber
(org-section-number level
))
2461 (if org-export-with-section-numbers
2462 (setq txt
(concat snumber
" " txt
)))
2463 (if (<= level
(max umax umax-toc
))
2464 (setq head-count
(+ head-count
1)))
2465 (if (<= level umax-toc
)
2467 (if (> level org-last-level
)
2469 (setq cnt
(- level org-last-level
))
2470 (while (>= (setq cnt
(1- cnt
)) 0)
2471 (push "\n<ul>\n<li>" thetoc
))
2472 (push "\n" thetoc
)))
2473 (if (< level org-last-level
)
2475 (setq cnt
(- org-last-level level
))
2476 (while (>= (setq cnt
(1- cnt
)) 0)
2477 (push "</li>\n</ul>" thetoc
))
2478 (push "\n" thetoc
)))
2479 ;; Check for targets
2480 (while (string-match org-any-target-regexp line
)
2481 (setq line
(replace-match
2482 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2484 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2485 (setq txt
(replace-match "" t t txt
)))
2489 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2490 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2491 snumber txt
) thetoc
)
2493 (setq org-last-level level
))
2497 (while (> org-last-level
(1- org-min-level
))
2498 (setq org-last-level
(1- org-last-level
))
2499 (push "</li>\n</ul>\n" thetoc
))
2500 (push "</div>\n" thetoc
)
2501 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2504 (org-init-section-numbers)
2506 (while (setq line
(pop lines
) origline line
)
2509 ;; end of quote section?
2510 (when (and inquote
(string-match "^\\*+ " line
))
2513 ;; inside a quote section?
2515 (insert (org-html-protect line
) "\n")
2516 (throw 'nextline nil
))
2519 (when (and org-export-with-fixed-width
2520 (string-match "^[ \t]*:\\(.*\\)" line
))
2524 (insert (org-html-protect (match-string 1 line
)) "\n")
2526 (not (string-match "^[ \t]*\\(:.*\\)"
2529 (insert "</pre>\n"))
2530 (throw 'nextline nil
))
2533 (when (get-text-property 0 'org-protected line
)
2535 (when (re-search-backward
2536 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2537 (setq par
(match-string 1))
2538 (replace-match "\\2\n"))
2541 (not (string-match "^[ \t]*:" (car lines
)))
2542 (or (= (length (car lines
)) 0)
2543 (get-text-property 0 'org-protected
(car lines
))))
2544 (insert (pop lines
) "\n"))
2545 (and par
(insert "<p>\n")))
2546 (throw 'nextline nil
))
2549 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2550 (insert "\n<hr/>\n")
2551 (throw 'nextline nil
))
2554 (when (equal "ORG-BLOCKQUOTE-START" line
)
2555 (insert "<blockquote>\n<p>\n")
2556 (throw 'nextline nil
))
2557 (when (equal "ORG-BLOCKQUOTE-END" line
)
2558 (insert "</p>\n</blockquote>\n")
2559 (throw 'nextline nil
))
2561 ;; make targets to anchors
2562 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2565 (setq line
(replace-match
2566 (concat "@<a name=\""
2567 (org-solidify-link-text (match-string 1 line
))
2570 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2571 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2572 (setq line
(replace-match
2573 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2574 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2577 (setq line
(replace-match
2578 (concat "@<a name=\""
2579 (org-solidify-link-text (match-string 1 line
))
2580 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2583 (setq line
(org-html-handle-time-stamps line
))
2585 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2586 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2587 ;; Also handle sub_superscripts and checkboxes
2588 (or (string-match org-table-hline-regexp line
)
2589 (setq line
(org-html-expand line
)))
2593 (while (string-match org-bracket-link-analytic-regexp line start
)
2594 (setq start
(match-beginning 0))
2595 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2596 (setq path
(match-string 3 line
))
2597 (setq desc1
(if (match-end 5) (match-string 5 line
))
2598 desc2
(if (match-end 2) (concat type
":" path
) path
)
2599 descp
(and desc1
(not (equal desc1 desc2
)))
2600 desc
(or desc1 desc2
))
2601 ;; Make an image out of the description if that is so wanted
2602 (when (and descp
(org-file-image-p desc
))
2604 (if (string-match "^file:" desc
)
2605 (setq desc
(substring desc
(match-end 0)))))
2606 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2607 ;; FIXME: do we need to unescape here somewhere?
2609 ((equal type
"internal")
2613 (org-solidify-link-text
2614 (save-match-data (org-link-unescape path
)) nil
)
2615 "\">" desc
"</a>")))
2616 ((member type
'("http" "https"))
2617 ;; standard URL, just check if we need to inline an image
2618 (if (and (or (eq t org-export-html-inline-images
)
2619 (and org-export-html-inline-images
(not descp
)))
2620 (org-file-image-p path
))
2621 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2622 (setq link
(concat type
":" path
))
2623 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2624 ((member type
'("ftp" "mailto" "news"))
2626 (setq link
(concat type
":" path
))
2627 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2628 ((string= type
"file")
2630 (let* ((filename path
)
2631 (abs-p (file-name-absolute-p filename
))
2632 thefile file-is-image-p search
)
2634 (if (string-match "::\\(.*\\)" filename
)
2635 (setq search
(match-string 1 filename
)
2636 filename
(replace-match "" t nil filename
)))
2638 (if (functionp link-validate
)
2639 (funcall link-validate filename current-dir
)
2641 (setq file-is-image-p
(org-file-image-p filename
))
2642 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2643 (when (and org-export-html-link-org-files-as-html
2644 (string-match "\\.org$" thefile
))
2645 (setq thefile
(concat (substring thefile
0
2646 (match-beginning 0))
2647 "." html-extension
))
2649 ;; make sure this is can be used as target search
2650 (not (string-match "^[0-9]*$" search
))
2651 (not (string-match "^\\*" search
))
2652 (not (string-match "^/.*/$" search
)))
2653 (setq thefile
(concat thefile
"#"
2654 (org-solidify-link-text
2655 (org-link-unescape search
)))))
2656 (when (string-match "^file:" desc
)
2657 (setq desc
(replace-match "" t t desc
))
2658 (if (string-match "\\.org$" desc
)
2659 (setq desc
(replace-match "" t t desc
))))))
2660 (setq rpl
(if (and file-is-image-p
2661 (or (eq t org-export-html-inline-images
)
2662 (and org-export-html-inline-images
2664 (concat "<img src=\"" thefile
"\"/>")
2665 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2666 (if (not valid
) (setq rpl desc
))))
2668 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2671 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2674 ;; just publish the path, as default
2675 (setq rpl
(concat "<i><" type
":"
2676 (save-match-data (org-link-unescape path
))
2678 (setq line
(replace-match rpl t t line
)
2679 start
(+ start
(length rpl
))))
2682 (if (and (string-match org-todo-line-regexp line
)
2683 (match-beginning 2))
2686 (concat (substring line
0 (match-beginning 2))
2688 (if (member (match-string 2 line
)
2691 "\">" (match-string 2 line
)
2692 "</span>" (substring line
(match-end 2)))))
2694 ;; Does this contain a reference to a footnote?
2695 (when org-export-with-footnotes
2697 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2698 (if (get-text-property (match-beginning 2) 'org-protected line
)
2699 (setq start
(match-end 2))
2700 (let ((n (match-string 2 line
)))
2704 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2705 (match-string 1 line
) n n n
)
2709 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2710 ;; This is a headline
2711 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2712 txt
(match-string 2 line
))
2713 (if (string-match quote-re0 txt
)
2714 (setq txt
(replace-match "" t t txt
)))
2715 (if (<= level
(max umax umax-toc
))
2716 (setq head-count
(+ head-count
1)))
2718 ;; Close any local lists before inserting a new header line
2719 (while local-list-num
2721 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
2722 (pop local-list-num
))
2723 (setq local-list-indent nil
2725 (setq first-heading-pos
(or first-heading-pos
(point)))
2726 (org-html-level-start level txt umax
2727 (and org-export-with-toc
(<= level umax
))
2730 (when (string-match quote-re line
)
2734 ((and org-export-with-tables
2735 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2736 (if (not table-open
)
2738 (setq table-open t table-buffer nil table-orig-buffer nil
))
2740 (setq table-buffer
(cons line table-buffer
)
2741 table-orig-buffer
(cons origline table-orig-buffer
))
2742 (when (or (not lines
)
2743 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2745 (setq table-open nil
2746 table-buffer
(nreverse table-buffer
)
2747 table-orig-buffer
(nreverse table-orig-buffer
))
2748 (org-close-par-maybe)
2749 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2754 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2755 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2756 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2757 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2759 (setq ind
(org-get-string-indentation line
)
2760 start-is-num
(match-beginning 4)
2761 starter
(if (match-beginning 2)
2762 (substring (match-string 2 line
) 0 -
1))
2763 line
(substring line
(match-beginning 5)))
2764 (unless (string-match "[^ \t]" line
)
2765 ;; empty line. Pretend indentation is large.
2766 (setq ind
(if org-empty-line-terminates-plain-lists
2768 (1+ (or (car local-list-indent
) 1)))))
2770 (while (and in-local-list
2771 (or (and (= ind
(car local-list-indent
))
2773 (< ind
(car local-list-indent
))))
2776 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
2777 (pop local-list-num
) (pop local-list-indent
)
2778 (setq in-local-list local-list-indent
))
2781 (or (not in-local-list
)
2782 (> ind
(car local-list-indent
))))
2783 ;; Start new (level of) list
2784 (org-close-par-maybe)
2785 (insert (if start-is-num
"<ol>\n<li>\n" "<ul>\n<li>\n"))
2786 (push start-is-num local-list-num
)
2787 (push ind local-list-indent
)
2788 (setq in-local-list t
))
2790 ;; continue current list
2794 ;; we did close a list, normal text follows: need <p>
2796 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2799 (if (equal (match-string 1 line
) "X")
2801 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2804 ;; Empty lines start a new paragraph. If hand-formatted lists
2805 ;; are not fully interpreted, lines starting with "-", "+", "*"
2806 ;; also start a new paragraph.
2807 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2809 ;; Is this the start of a footnote?
2810 (when org-export-with-footnotes
2811 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2812 (org-close-par-maybe)
2813 (let ((n (match-string 1 line
)))
2814 (setq line
(replace-match
2815 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2817 ;; Check if the line break needs to be conserved
2819 ((string-match "\\\\\\\\[ \t]*$" line
)
2820 (setq line
(replace-match "<br/>" t t line
)))
2821 (org-export-preserve-breaks
2822 (setq line
(concat line
"<br/>"))))
2824 (insert line
"\n")))))
2826 ;; Properly close all local lists and other lists
2827 (when inquote
(insert "</pre>\n"))
2829 ;; Close any local lists before inserting a new header line
2830 (while local-list-num
2832 (insert (if (car local-list-num
) "</ol>\n" "</ul>\n"))
2833 (pop local-list-num
))
2834 (setq local-list-indent nil
2836 (org-html-level-start 1 nil umax
2837 (and org-export-with-toc
(<= level umax
))
2839 ;; the </div> to lose the last text-... div.
2843 (when (plist-get opt-plist
:auto-postamble
)
2844 (insert "<div id=\"postamble\">")
2845 (when (and org-export-author-info author
)
2846 (insert "<p class=\"author\"> "
2847 (nth 1 lang-words
) ": " author
"\n")
2849 (if (listp (split-string email
",+ *"))
2851 (insert "<a href=\"mailto:" e
"\"><"
2853 (split-string email
",+ *"))
2854 (insert "<a href=\"mailto:" email
"\"><"
2855 email
"></a>\n")))
2857 (when (and date org-export-time-stamp-file
)
2858 (insert "<p class=\"date\"> "
2859 (nth 2 lang-words
) ": "
2863 (if org-export-html-with-timestamp
2864 (insert org-export-html-html-helper-timestamp
))
2865 (insert (or (plist-get opt-plist
:postamble
) ""))
2866 (insert "</body>\n</html>\n"))
2869 (if (eq major-mode default-major-mode
) (html-mode))
2871 ;; insert the table of contents
2872 (goto-char (point-min))
2874 (if (or (re-search-forward
2875 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2877 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2879 (goto-char (match-beginning 0))
2881 (goto-char first-heading-pos
)
2882 (when (looking-at "\\s-*</p>")
2883 (goto-char (match-end 0))
2885 (insert "<div id=\"table-of-contents\">\n")
2886 (mapc 'insert thetoc
)
2887 (insert "</div>\n"))
2888 ;; remove empty paragraphs and lists
2889 (goto-char (point-min))
2890 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2892 (goto-char (point-min))
2893 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2895 (goto-char (point-min))
2896 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
2898 ;; Convert whitespace place holders
2899 (goto-char (point-min))
2901 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2902 (setq n
(get-text-property beg
'org-whitespace
)
2903 end
(next-single-property-change beg
'org-whitespace
))
2905 (delete-region beg end
)
2906 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2907 (make-string n ?x
)))))
2908 (or to-buffer
(save-buffer))
2909 (goto-char (point-min))
2910 (message "Exporting... done")
2911 (if (eq to-buffer
'string
)
2912 (prog1 (buffer-substring (point-min) (point-max))
2913 (kill-buffer (current-buffer)))
2914 (current-buffer)))))
2916 (defvar org-table-colgroup-info nil
)
2917 (defun org-format-table-ascii (lines)
2918 "Format a table for ascii export."
2920 (setq lines
(org-split-string lines
"\n")))
2921 (if (not (string-match "^[ \t]*|" (car lines
)))
2922 ;; Table made by table.el - test for spanning
2925 ;; A normal org table
2926 ;; Get rid of hlines at beginning and end
2927 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2928 (setq lines
(nreverse lines
))
2929 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2930 (setq lines
(nreverse lines
))
2931 (when org-export-table-remove-special-lines
2932 ;; Check if the table has a marking column. If yes remove the
2933 ;; column and the special lines
2934 (setq lines
(org-table-clean-before-export lines
)))
2935 ;; Get rid of the vertical lines except for grouping
2936 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
2938 (while (setq line
(pop lines
))
2939 (if (string-match org-table-hline-regexp line
)
2940 (and (string-match "|\\(.*\\)|" line
)
2941 (setq line
(replace-match " \\1" t nil line
)))
2942 (setq start
0 vl1 vl
)
2943 (while (string-match "|" line start
)
2944 (setq start
(match-end 0))
2945 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
2949 (defun org-colgroup-info-to-vline-list (info)
2952 (setq last new new
(pop info
))
2953 (if (or (memq last
'(:end
:startend
))
2954 (memq new
'(:start
:startend
)))
2957 (setq vl
(nreverse vl
))
2958 (and vl
(setcar vl nil
))
2961 (defvar org-table-number-regexp
) ; defined in org-table.el
2962 (defun org-format-table-html (lines olines
)
2963 "Find out which HTML converter to use and return the HTML code."
2965 (setq lines
(org-split-string lines
"\n")))
2966 (if (string-match "^[ \t]*|" (car lines
))
2967 ;; A normal org table
2968 (org-format-org-table-html lines
)
2969 ;; Table made by table.el - test for spanning
2970 (let* ((hlines (delq nil
(mapcar
2972 (if (string-match "^[ \t]*\\+-" x
) x
2975 (first (car hlines
))
2976 (ll (and (string-match "\\S-+" first
)
2977 (match-string 0 first
)))
2978 (re (concat "^[ \t]*" (regexp-quote ll
)))
2979 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
2981 (if (and (not spanning
)
2982 (not org-export-prefer-native-exporter-for-tables
))
2983 ;; We can use my own converter with HTML conversions
2984 (org-format-table-table-html lines
)
2985 ;; Need to use the code generator in table.el, with the original text.
2986 (org-format-table-table-html-using-table-generate-source olines
)))))
2988 (defvar org-table-number-fraction
) ; defined in org-table.el
2989 (defun org-format-org-table-html (lines &optional splice
)
2990 "Format a table into HTML."
2991 (require 'org-table
)
2992 ;; Get rid of hlines at beginning and end
2993 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2994 (setq lines
(nreverse lines
))
2995 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2996 (setq lines
(nreverse lines
))
2997 (when org-export-table-remove-special-lines
2998 ;; Check if the table has a marking column. If yes remove the
2999 ;; column and the special lines
3000 (setq lines
(org-table-clean-before-export lines
)))
3002 (let ((head (and org-export-highlight-first-table-line
3004 (lambda (x) (string-match "^[ \t]*|-" x
))
3007 tbopen line fields html gr colgropen
)
3008 (if splice
(setq head nil
))
3009 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3011 (while (setq line
(pop lines
))
3013 (if (string-match "^[ \t]*|-" line
)
3016 (push (if head
"</thead>" "</tbody>") html
)
3017 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3018 (setq head nil
) ;; head ends here, first time around
3020 (throw 'next-line t
)))
3021 ;; Break the line into fields
3022 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3023 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3024 (setq nlines
(1+ nlines
) i -
1)
3025 (push (concat "<tr>"
3029 (if (and (< i nlines
)
3030 (string-match org-table-number-regexp x
))
3031 (incf (aref fnum i
)))
3033 (concat (car org-export-table-header-tags
) x
3034 (cdr org-export-table-header-tags
))
3035 (concat (car org-export-table-data-tags
) x
3036 (cdr org-export-table-data-tags
))))
3040 (unless splice
(if tbopen
(push "</tbody>" html
)))
3041 (unless splice
(push "</table>\n" html
))
3042 (setq html
(nreverse html
))
3044 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3047 (setq gr
(pop org-table-colgroup-info
))
3048 (format "%s<col align=\"%s\"></col>%s"
3049 (if (memq gr
'(:start
:startend
))
3051 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3054 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3056 (if (memq gr
'(:end
:startend
))
3057 (progn (setq colgropen nil
) "</colgroup>")
3061 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3062 (push html-table-tag html
))
3063 (concat (mapconcat 'identity html
"\n") "\n")))
3065 (defun org-table-clean-before-export (lines)
3066 "Check if the table has a marking column.
3067 If yes remove the column and the special lines."
3068 (setq org-table-colgroup-info nil
)
3071 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3072 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3075 (setq org-table-clean-did-remove-column nil
)
3080 ((string-match "^[ \t]*| */ *|" x
)
3081 (setq org-table-colgroup-info
3083 (cond ((member x
'("<" "<")) :start
)
3084 ((member x
'(">" ">")) :end
)
3085 ((member x
'("<>" "<>")) :startend
)
3087 (org-split-string x
"[ \t]*|[ \t]*")))
3091 (setq org-table-clean-did-remove-column t
)
3096 ((string-match "^[ \t]*| */ *|" x
)
3097 (setq org-table-colgroup-info
3099 (cond ((member x
'("<" "<")) :start
)
3100 ((member x
'(">" ">")) :end
)
3101 ((member x
'("<>" "<>")) :startend
)
3103 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3105 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3106 nil
) ; ignore this line
3107 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3108 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3109 ;; remove the first column
3110 (replace-match "\\1|" t nil x
))))
3113 (defun org-format-table-table-html (lines)
3114 "Format a table generated by table.el into HTML.
3115 This conversion does *not* use `table-generate-source' from table.el.
3116 This has the advantage that Org-mode's HTML conversions can be used.
3117 But it has the disadvantage, that no cell- or row-spanning is allowed."
3118 (let (line field-buffer
3119 (head org-export-highlight-first-table-line
)
3121 (setq html
(concat html-table-tag
"\n"))
3122 (while (setq line
(pop lines
))
3123 (setq empty
" ")
3125 (if (string-match "^[ \t]*\\+-" line
)
3136 (if (equal x
"") (setq x empty
))
3138 (concat (car org-export-table-header-tags
) x
3139 (cdr org-export-table-header-tags
))
3140 (concat (car org-export-table-data-tags
) x
3141 (cdr org-export-table-data-tags
))))
3145 (setq field-buffer nil
)))
3147 (throw 'next-line t
)))
3148 ;; Break the line into fields and store the fields
3149 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3151 (setq field-buffer
(mapcar
3153 (concat x
"<br/>" (pop fields
)))
3155 (setq field-buffer fields
))))
3156 (setq html
(concat html
"</table>\n"))
3159 (defun org-format-table-table-html-using-table-generate-source (lines)
3160 "Format a table into html, using `table-generate-source' from table.el.
3161 This has the advantage that cell- or row-spanning is allowed.
3162 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3164 (with-current-buffer (get-buffer-create " org-tmp1 ")
3166 (insert (mapconcat 'identity lines
"\n"))
3167 (goto-char (point-min))
3168 (if (not (re-search-forward "|[^+]" nil t
))
3169 (error "Error processing table"))
3170 (table-recognize-table)
3171 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3172 (table-generate-source 'html
" org-tmp2 ")
3173 (set-buffer " org-tmp2 ")
3174 (buffer-substring (point-min) (point-max))))
3176 (defun org-html-handle-time-stamps (s)
3177 "Format time stamps in string S, or remove them."
3180 (while (string-match org-maybe-keyword-time-regexp s
)
3181 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3182 ;; never export CLOCK
3184 (or b
(setq b
(substring s
0 (match-beginning 0))))
3185 (if (not org-export-with-timestamps
)
3186 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3187 s
(substring s
(match-end 0)))
3189 r
(substring s
0 (match-beginning 0))
3191 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3192 (match-string 1 s
)))
3193 (format " @<span class=\"timestamp\">%s@</span>"
3195 (org-translate-time (match-string 3 s
)) 1 -
1)))
3196 s
(substring s
(match-end 0)))))
3197 ;; Line break if line started and ended with time stamp stuff
3200 (setq r
(concat r s
))
3201 (unless (string-match "\\S-" (concat b s
))
3202 (setq r
(concat r
"@<br/>")))
3205 (defun org-html-protect (s)
3206 ;; convert & to &, < to < and > to >
3208 (while (string-match "&" s start
)
3209 (setq s
(replace-match "&" t t s
)
3210 start
(1+ (match-beginning 0))))
3211 (while (string-match "<" s
)
3212 (setq s
(replace-match "<" t t s
)))
3213 (while (string-match ">" s
)
3214 (setq s
(replace-match ">" t t s
))))
3217 (defun org-export-cleanup-toc-line (s)
3218 "Remove tags and time staps from lines going into the toc."
3219 (when (memq org-export-with-tags
'(not-in-toc nil
))
3220 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3221 (setq s
(replace-match "" t t s
))))
3222 (when org-export-remove-timestamps-from-toc
3223 (while (string-match org-maybe-keyword-time-regexp s
)
3224 (setq s
(replace-match "" t t s
))))
3225 (while (string-match org-bracket-link-regexp s
)
3226 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3230 (defun org-html-expand (string)
3231 "Prepare STRING for HTML export. Applies all active conversions.
3232 If there are links in the string, don't modify these."
3233 (let* ((re (concat org-bracket-link-regexp
"\\|"
3234 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3236 (while (setq m
(string-match re string
))
3237 (setq s
(substring string
0 m
)
3238 l
(match-string 0 string
)
3239 string
(substring string
(match-end 0)))
3240 (push (org-html-do-expand s
) res
)
3242 (push (org-html-do-expand string
) res
)
3243 (apply 'concat
(nreverse res
))))
3245 (defun org-html-do-expand (s)
3246 "Apply all active conversions to translate special ASCII to HTML."
3247 (setq s
(org-html-protect s
))
3248 (if org-export-html-expand
3250 (while (string-match "@<\\([^&]*\\)>" s
)
3251 (setq s
(replace-match "<\\1>" t nil s
)))))
3252 (if org-export-with-emphasize
3253 (setq s
(org-export-html-convert-emphasize s
)))
3254 (if org-export-with-special-strings
3255 (setq s
(org-export-html-convert-special-strings s
)))
3256 (if org-export-with-sub-superscripts
3257 (setq s
(org-export-html-convert-sub-super s
)))
3258 (if org-export-with-TeX-macros
3259 (let ((start 0) wd ass
)
3260 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3261 (if (get-text-property (match-beginning 0) 'org-protected s
)
3262 (setq start
(match-end 0))
3263 (setq wd
(match-string 1 s
))
3264 (if (setq ass
(assoc wd org-html-entities
))
3265 (setq s
(replace-match (or (cdr ass
)
3266 (concat "&" (car ass
) ";"))
3268 (setq start
(+ start
(length wd
))))))))
3271 (defun org-create-multibrace-regexp (left right n
)
3272 "Create a regular expression which will match a balanced sexp.
3273 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3274 as single character strings.
3275 The regexp returned will match the entire expression including the
3276 delimiters. It will also define a single group which contains the
3277 match except for the outermost delimiters. The maximum depth of
3278 stacked delimiters is N. Escaping delimiters is not possible."
3279 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3282 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3285 re
(concat re or next
)
3286 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3287 (concat left
"\\(" re
"\\)" right
)))
3289 (defvar org-match-substring-regexp
3291 "\\([^\\]\\)\\([_^]\\)\\("
3292 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3294 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3296 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3297 "The regular expression matching a sub- or superscript.")
3299 (defvar org-match-substring-with-braces-regexp
3301 "\\([^\\]\\)\\([_^]\\)\\("
3302 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3304 "The regular expression matching a sub- or superscript, forcing braces.")
3306 (defconst org-export-html-special-string-regexps
3307 '(("\\\\-" .
"­")
3308 ("---\\([^-]\\)" .
"—\\1")
3309 ("--\\([^-]\\)" .
"–\\1")
3310 ("\\.\\.\\." .
"…"))
3311 "Regular expressions for special string conversion.")
3313 (defun org-export-html-convert-special-strings (string)
3314 "Convert special characters in STRING to HTML."
3315 (let ((all org-export-html-special-string-regexps
)
3317 (while (setq a
(pop all
))
3318 (setq re
(car a
) rpl
(cdr a
) start
0)
3319 (while (string-match re string start
)
3320 (if (get-text-property (match-beginning 0) 'org-protected string
)
3321 (setq start
(match-end 0))
3322 (setq string
(replace-match rpl t nil string
)))))
3325 (defun org-export-html-convert-sub-super (string)
3326 "Convert sub- and superscripts in STRING to HTML."
3327 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3328 (while (string-match org-match-substring-regexp string s
)
3330 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3331 ((get-text-property (match-beginning 2) 'org-protected string
)
3332 (setq s
(match-end 2)))
3334 (setq s
(match-end 1)
3335 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3336 c
(or (match-string 8 string
)
3337 (match-string 6 string
)
3338 (match-string 5 string
))
3339 string
(replace-match
3340 (concat (match-string 1 string
)
3341 "<" key
">" c
"</" key
">")
3343 (while (string-match "\\\\\\([_^]\\)" string
)
3344 (setq string
(replace-match (match-string 1 string
) t t string
)))
3347 (defun org-export-html-convert-emphasize (string)
3350 (while (string-match org-emph-re string s
)
3352 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3353 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3354 (setq s
(match-beginning 0)
3357 (match-string 1 string
)
3358 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3359 (match-string 4 string
)
3360 (nth 3 (assoc (match-string 3 string
)
3361 org-emphasis-alist
))
3362 (match-string 5 string
))
3363 string
(replace-match rpl t t string
)
3364 s
(+ s
(- (length rpl
) 2)))
3368 (defvar org-par-open nil
)
3369 (defun org-open-par ()
3370 "Insert <p>, but first close previous paragraph if any."
3371 (org-close-par-maybe)
3373 (setq org-par-open t
))
3374 (defun org-close-par-maybe ()
3375 "Close paragraph if there is one open."
3378 (setq org-par-open nil
)))
3379 (defun org-close-li ()
3380 "Close <li> if necessary."
3381 (org-close-par-maybe)
3384 (defvar body-only
) ; dynamically scoped into this.
3385 (defun org-html-level-start (level title umax with-toc head-count
)
3386 "Insert a new level in HTML export.
3387 When TITLE is nil, just close all open levels."
3388 (org-close-par-maybe)
3389 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3393 (if (aref org-levels-open
(1- l
))
3395 (org-html-level-close l umax
)
3396 (aset org-levels-open
(1- l
) nil
)))
3399 ;; If title is nil, this means this function is called to close
3400 ;; all levels, so the rest is done only if title is given
3401 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3402 (setq title
(replace-match
3403 (if org-export-with-tags
3406 " <span class=\"tag\">"
3407 (mapconcat 'identity
(org-split-string
3408 (match-string 1 title
) ":")
3415 (if (aref org-levels-open
(1- level
))
3419 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3420 (insert "<li>" title
"<br/>\n")))
3421 (aset org-levels-open
(1- level
) t
)
3422 (org-close-par-maybe)
3424 (insert (format "<ul>\n<li id=\"%s\">" target
)
3426 (insert "<ul>\n<li>" title
"<br/>\n"))))
3427 (aset org-levels-open
(1- level
) t
)
3428 (setq snumber
(org-section-number level
))
3429 (if (and org-export-with-section-numbers
(not body-only
))
3430 (setq title
(concat snumber
" " title
)))
3431 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3432 (unless (= head-count
1) (insert "\n</div>\n"))
3433 (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"
3434 snumber level level snumber title level snumber
))
3437 (defun org-get-text-property-any (pos prop
&optional object
)
3438 (or (get-text-property pos prop object
)
3439 (and (setq pos
(next-single-property-change pos prop object
))
3440 (get-text-property pos prop object
))))
3442 (defun org-html-level-close (level max-outline-level
)
3443 "Terminate one level in HTML export."
3444 (if (<= level max-outline-level
)
3447 (insert "</ul>\n")))
3449 ;;; iCalendar export
3452 (defun org-export-icalendar-this-file ()
3453 "Export current file as an iCalendar file.
3454 The iCalendar file will be located in the same directory as the Org-mode
3455 file, but with extension `.ics'."
3457 (org-export-icalendar nil buffer-file-name
))
3460 (defun org-export-icalendar-all-agenda-files ()
3461 "Export all files in `org-agenda-files' to iCalendar .ics files.
3462 Each iCalendar file will be located in the same directory as the Org-mode
3463 file, but with extension `.ics'."
3465 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3468 (defun org-export-icalendar-combine-agenda-files ()
3469 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3470 The file is stored under the name `org-combined-agenda-icalendar-file'."
3472 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3474 (defun org-export-icalendar (combine &rest files
)
3475 "Create iCalendar files for all elements of FILES.
3476 If COMBINE is non-nil, combine all calendar entries into a single large
3477 file and store it under the name `org-combined-agenda-icalendar-file'."
3479 (org-prepare-agenda-buffers files
)
3480 (let* ((dir (org-export-directory
3481 :ical
(list :publishing-directory
3482 org-export-publishing-directory
)))
3483 file ical-file ical-buffer category started org-agenda-new-buffers
)
3484 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3487 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3488 org-combined-agenda-icalendar-file
3489 (expand-file-name org-combined-agenda-icalendar-file dir
))
3490 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3491 (set-buffer ical-buffer
) (erase-buffer))
3492 (while (setq file
(pop files
))
3494 (org-check-agenda-file file
)
3495 (set-buffer (org-get-agenda-file-buffer file
))
3497 (setq ical-file
(concat (file-name-as-directory dir
)
3498 (file-name-sans-extension
3499 (file-name-nondirectory buffer-file-name
))
3501 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3502 (with-current-buffer ical-buffer
(erase-buffer)))
3503 (setq category
(or org-category
3504 (file-name-sans-extension
3505 (file-name-nondirectory buffer-file-name
))))
3506 (if (symbolp category
) (setq category
(symbol-name category
)))
3507 (let ((standard-output ical-buffer
))
3509 (and (not started
) (setq started t
)
3510 (org-start-icalendar-file org-icalendar-combined-name
))
3511 (org-start-icalendar-file category
))
3512 (org-print-icalendar-entries combine
)
3513 (when (or (and combine
(not files
)) (not combine
))
3514 (org-finish-icalendar-file)
3515 (set-buffer ical-buffer
)
3517 (run-hooks 'org-after-save-iCalendar-file-hook
)
3518 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3520 (org-release-buffers org-agenda-new-buffers
))))
3522 (defvar org-after-save-iCalendar-file-hook nil
3523 "Hook run after an iCalendar file has been saved.
3524 The iCalendar buffer is still current when this hook is run.
3525 A good way to use this is to tell a desktop calenndar application to re-read
3526 the iCalendar file.")
3528 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3529 (defun org-print-icalendar-entries (&optional combine
)
3530 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3531 When COMBINE is non nil, add the category to each line."
3532 (require 'org-agenda
)
3533 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3534 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3535 (dts (org-ical-ts-to-string
3536 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3538 hd ts ts2 state status
(inc t
) pos b sexp rrule
3539 scheduledp deadlinep tmp pri category entry location summary desc
3540 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3541 (org-refresh-category-properties)
3543 (goto-char (point-min))
3544 (while (re-search-forward re1 nil t
)
3547 (when (boundp 'org-icalendar-verify-function
)
3548 (unless (funcall org-icalendar-verify-function
)
3549 (outline-next-heading)
3552 (setq pos
(match-beginning 0)
3555 hd
(condition-case nil
3556 (org-icalendar-cleanup-string
3558 (error (throw :skip nil
)))
3559 summary
(org-icalendar-cleanup-string
3560 (org-entry-get nil
"SUMMARY"))
3561 desc
(org-icalendar-cleanup-string
3562 (or (org-entry-get nil
"DESCRIPTION")
3563 (and org-icalendar-include-body
(org-get-entry)))
3564 t org-icalendar-include-body
)
3565 location
(org-icalendar-cleanup-string
3566 (org-entry-get nil
"LOCATION"))
3567 category
(org-get-category))
3568 (if (looking-at re2
)
3570 (goto-char (match-end 0))
3571 (setq ts2
(match-string 1) inc nil
))
3572 (setq tmp
(buffer-substring (max (point-min)
3573 (- pos org-ds-keyword-length
))
3575 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3578 (replace-match "\\1" t nil ts
))
3580 deadlinep
(string-match org-deadline-regexp tmp
)
3581 scheduledp
(string-match org-scheduled-regexp tmp
)
3582 ;; donep (org-entry-is-done-p)
3584 (if (or (string-match org-tr-regexp hd
)
3585 (string-match org-ts-regexp hd
))
3586 (setq hd
(replace-match "" t t hd
)))
3587 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3589 (concat "\nRRULE:FREQ="
3592 '(("d" .
"DAILY")("w" .
"WEEKLY")
3593 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3594 ";INTERVAL=" (match-string 1 ts
)))
3596 (setq summary
(or summary hd
))
3597 (if (string-match org-bracket-link-regexp summary
)
3599 (replace-match (if (match-end 3)
3600 (match-string 3 summary
)
3601 (match-string 1 summary
))
3603 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3604 (if scheduledp
(setq summary
(concat "S: " summary
)))
3605 (if (string-match "\\`<%%" ts
)
3606 (with-current-buffer sexp-buffer
3607 (insert (substring ts
1 -
1) " " summary
"\n"))
3608 (princ (format "BEGIN:VEVENT
3614 (org-ical-ts-to-string ts
"DTSTART")
3615 (org-ical-ts-to-string ts2
"DTEND" inc
)
3617 (if (and desc
(string-match "\\S-" desc
))
3618 (concat "\nDESCRIPTION: " desc
) "")
3619 (if (and location
(string-match "\\S-" location
))
3620 (concat "\nLOCATION: " location
) "")
3623 (when (and org-icalendar-include-sexps
3624 (condition-case nil
(require 'icalendar
) (error nil
))
3625 (fboundp 'icalendar-export-region
))
3626 ;; Get all the literal sexps
3627 (goto-char (point-min))
3628 (while (re-search-forward "^&?%%(" nil t
)
3631 (setq b
(match-beginning 0))
3632 (goto-char (1- (match-end 0)))
3635 (setq sexp
(buffer-substring b
(point)))
3636 (with-current-buffer sexp-buffer
3638 (princ (org-diary-to-ical-string sexp-buffer
)))))
3640 (when org-icalendar-include-todo
3641 (goto-char (point-min))
3642 (while (re-search-forward org-todo-line-regexp nil t
)
3645 (when (boundp 'org-icalendar-verify-function
)
3646 (unless (funcall org-icalendar-verify-function
)
3647 (outline-next-heading)
3650 (setq state
(match-string 2))
3651 (setq status
(if (member state org-done-keywords
)
3652 "COMPLETED" "NEEDS-ACTION"))
3654 (or (not (member state org-done-keywords
))
3655 (eq org-icalendar-include-todo
'all
))
3656 (not (member org-archive-tag
(org-get-tags-at)))
3658 (setq hd
(match-string 3)
3659 summary
(org-icalendar-cleanup-string
3660 (org-entry-get nil
"SUMMARY"))
3661 desc
(org-icalendar-cleanup-string
3662 (or (org-entry-get nil
"DESCRIPTION")
3663 (and org-icalendar-include-body
(org-get-entry)))
3664 t org-icalendar-include-body
)
3665 location
(org-icalendar-cleanup-string
3666 (org-entry-get nil
"LOCATION")))
3667 (if (string-match org-bracket-link-regexp hd
)
3668 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3669 (match-string 1 hd
))
3671 (if (string-match org-priority-regexp hd
)
3672 (setq pri
(string-to-char (match-string 2 hd
))
3673 hd
(concat (substring hd
0 (match-beginning 1))
3674 (substring hd
(match-end 1))))
3675 (setq pri org-default-priority
))
3676 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3677 (- org-lowest-priority org-highest-priority
))))))
3679 (princ (format "BEGIN:VTODO
3689 (if (and location
(string-match "\\S-" location
))
3690 (concat "\nLOCATION: " location
) "")
3691 (if (and desc
(string-match "\\S-" desc
))
3692 (concat "\nDESCRIPTION: " desc
) "")
3693 category pri status
)))))))))
3695 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3696 "Take out stuff and quote what needs to be quoted.
3697 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3698 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3703 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3704 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3705 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3706 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3708 (while (string-match "\\([,;]\\)" s start
)
3709 (setq start
(+ (match-beginning 0) 2)
3710 s
(replace-match "\\\\\\1" nil nil s
))))
3712 (while (string-match "[ \t]*\n[ \t]*" s
)
3713 (setq s
(replace-match "\\n" t t s
))))
3714 (setq s
(org-trim s
))
3717 (if (and (numberp maxlength
)
3718 (> (length s
) maxlength
))
3719 (setq s
(substring s
0 maxlength
)))))
3722 (defun org-get-entry ()
3723 "Clean-up description string."
3725 (org-back-to-heading t
)
3726 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3728 (defun org-start-icalendar-file (name)
3729 "Start an iCalendar file by inserting the header."
3730 (let ((user user-full-name
)
3731 (name (or name
"unknown"))
3732 (timezone (cadr (current-time-zone))))
3734 (format "BEGIN:VCALENDAR
3737 PRODID:-//%s//Emacs with Org-mode//EN
3739 CALSCALE:GREGORIAN\n" name user timezone
))))
3741 (defun org-finish-icalendar-file ()
3742 "Finish an iCalendar file by inserting the END statement."
3743 (princ "END:VCALENDAR\n"))
3745 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3746 "Take a time string S and convert it to iCalendar format.
3747 KEYWORD is added in front, to make a complete line like DTSTART....
3748 When INC is non-nil, increase the hour by two (if time string contains
3749 a time), or the day by one (if it does not contain a time)."
3750 (let ((t1 (org-parse-time-string s
'nodefault
))
3751 t2 fmt have-time time
)
3752 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3753 (setq t2 t1 have-time t
)
3754 (setq t2
(org-parse-time-string s
)))
3755 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3756 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3759 (if org-agenda-default-appointment-duration
3760 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3763 (setq time
(encode-time s mi h d m y
)))
3764 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3765 (concat keyword
(format-time-string fmt time
))))
3769 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3770 (with-current-buffer buffer
3771 (apply 'insert output
)))
3772 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3775 (defun org-export-as-xoxo (&optional buffer
)
3776 "Export the org buffer as XOXO.
3777 The XOXO buffer is named *xoxo-<source buffer name>*"
3778 (interactive (list (current-buffer)))
3779 ;; A quickie abstraction
3781 ;; Output everything as XOXO
3782 (with-current-buffer (get-buffer buffer
)
3783 (let* ((pos (point))
3784 (opt-plist (org-combine-plists (org-default-export-plist)
3785 (org-infile-export-plist)))
3786 (filename (concat (file-name-as-directory
3787 (org-export-directory :xoxo opt-plist
))
3788 (file-name-sans-extension
3789 (file-name-nondirectory buffer-file-name
))
3791 (out (find-file-noselect filename
))
3794 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3795 ;; Check the output buffer is empty.
3796 (with-current-buffer out
(erase-buffer))
3797 ;; Kick off the output
3798 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3799 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3800 (let* ((hd (match-string-no-properties 1))
3803 (match-string-no-properties 2)
3805 (goto-char (match-end 0))
3810 (if (looking-at "^[ \t]\\(.*\\)")
3811 (setq str
(concat str
(match-string-no-properties 1)))
3812 (throw 'loop str
)))))))))
3814 ;; Handle level rendering
3816 ((> level last-level
)
3817 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3819 ((< level last-level
)
3820 (dotimes (- (- last-level level
) 1)
3822 (org-export-as-xoxo-insert-into out
"</li>\n"))
3823 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3825 (org-export-as-xoxo-insert-into out
"</li>\n")
3826 (setq hanging-li nil
)))
3828 ((equal level last-level
)
3830 (org-export-as-xoxo-insert-into out
"</li>\n")))
3833 (setq last-level level
)
3835 ;; And output the new li
3836 (setq hanging-li
't
)
3837 (if (equal ?
+ (elt text
0))
3838 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3839 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3841 ;; Finally finish off the ol
3842 (dotimes (- last-level
1)
3844 (org-export-as-xoxo-insert-into out
"</li>\n"))
3845 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3848 ;; Finish the buffer off and clean it up.
3849 (switch-to-buffer-other-window out
)
3850 (indent-region (point-min) (point-max) nil
)
3852 (goto-char (point-min))
3857 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3859 ;;; org-exp.el ends here