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
)) ".")
768 (defun org-export (&optional arg
)
769 "Export dispatcher for Org-mode.
770 When `org-export-run-in-background' is non-nil, try to run the command
771 in the background. This will be done only for commands that write
772 to a file. For details see the docstring of `org-export-run-in-background'.
774 The prefix argument ARG will be passed to the exporter. However, if
775 ARG is a double universal prefix `C-u C-u', that means to inverse the
776 value of `org-export-run-in-background'."
778 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
779 (help "[t] insert the export option template
780 \[v] limit export to visible part of outline tree
785 \[H] export as HTML to temporary buffer
786 \[R] export region as HTML
787 \[b] export as HTML and browse immediately
791 \[L] export as LaTeX to temporary buffer
793 \[i] export current file as iCalendar file
794 \[I] export all agenda files as iCalendar files
795 \[c] export agenda files into combined iCalendar file
797 \[F] publish current file
798 \[P] publish current project
799 \[X] publish... (project will be prompted for)
800 \[A] publish all projects")
802 '((?t org-insert-export-options-template nil
)
803 (?v org-export-visible nil
)
804 (?a org-export-as-ascii t
)
805 (?h org-export-as-html t
)
806 (?b org-export-as-html-and-open t
)
807 (?H org-export-as-html-to-buffer nil
)
808 (?R org-export-region-as-html nil
)
809 (?x org-export-as-xoxo t
)
810 (?l org-export-as-latex t
)
811 (?L org-export-as-latex-to-buffer nil
)
812 (?i org-export-icalendar-this-file t
)
813 (?I org-export-icalendar-all-agenda-files t
)
814 (?c org-export-icalendar-combine-agenda-files t
)
815 (?F org-publish-current-file t
)
816 (?P org-publish-current-project t
)
818 (?A org-publish-all t
)))
820 (save-window-excursion
821 (delete-other-windows)
822 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
824 (message "Select command: ")
825 (setq r1
(read-char-exclusive)))
826 (setq r2
(if (< r1
27) (+ r1
96) r1
))
827 (unless (setq ass
(assq r2 cmds
))
828 (error "No command associated with key %c" r1
))
829 (if (and bg
(nth 2 ass
))
830 ;; execute in background
831 (let ((p (start-process
832 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
834 (expand-file-name invocation-name invocation-directory
)
837 "--eval" "(require 'org-exp)"
838 "--eval" "(setq org-wait .2)"
840 "-f" (symbol-name (nth 1 ass
)))))
841 (set-process-sentinel p
'org-export-process-sentinel
)
842 (message "Background process \"%s\": started" p
))
843 ;; background processing not requested, or not possible
844 (call-interactively (nth 1 ass
)))))
846 (defun org-export-process-sentinel (process status
)
847 (if (string-match "\n+\\'" status
)
848 (setq status
(substring status
0 -
1)))
849 (message "Background process \"%s\": %s" process status
))
851 (defconst org-html-entities
892 ("Aring") ("AA".
"Å")
981 ("varepsilon".
"ε")
994 ("sigmaf") ("varsigma".
"ς")
1002 ("thetasym") ("vartheta".
"ϑ")
1005 ("bull") ("bullet".
"•")
1006 ("hellip") ("dots".
"…")
1016 ("larr") ("leftarrow".
"←") ("gets".
"←")
1017 ("uarr") ("uparrow".
"↑")
1018 ("rarr") ("to".
"→") ("rightarrow".
"→")
1019 ("darr")("downarrow".
"↓")
1020 ("harr") ("leftrightarrow".
"↔")
1021 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1022 ("lArr") ("Leftarrow".
"⇐")
1023 ("uArr") ("Uparrow".
"⇑")
1024 ("rArr") ("Rightarrow".
"⇒")
1025 ("dArr") ("Downarrow".
"⇓")
1026 ("hArr") ("Leftrightarrow".
"⇔")
1028 ("part") ("partial".
"∂")
1029 ("exist") ("exists".
"∃")
1030 ("empty") ("emptyset".
"∅")
1032 ("isin") ("in".
"∈")
1038 ("lowast") ("ast".
"∗")
1040 ("prop") ("proptp".
"∝")
1041 ("infin") ("infty".
"∞")
1042 ("ang") ("angle".
"∠")
1043 ("and") ("wedge".
"∧")
1044 ("or") ("vee".
"∨")
1050 ("cong") ("simeq".
"≅")
1051 ("asymp")("approx".
"≈")
1052 ("ne") ("neq".
"≠")
1056 ("sub") ("subset".
"⊂")
1057 ("sup") ("supset".
"⊃")
1064 ("sdot") ("cdot".
"⋅")
1071 ("loz") ("Diamond".
"◊")
1072 ("spades") ("spadesuit".
"♠")
1073 ("clubs") ("clubsuit".
"♣")
1074 ("hearts") ("diamondsuit".
"♥")
1075 ("diams") ("diamondsuit".
"♦")
1076 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1143 "Entities for TeX->HTML translation.
1144 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1145 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1146 In that case, \"\\ent\" will be translated to \"&other;\".
1147 The list contains HTML entities for Latin-1, Greek and other symbols.
1148 It is supplemented by a number of commonly used TeX macros with appropriate
1149 translations. There is currently no way for users to extend this.")
1151 ;;; General functions for all backends
1153 (defun org-export-preprocess-string (string &rest parameters
)
1154 "Cleanup STRING so that that the true exported has a more consistent source.
1155 This function takes STRING, which should be a buffer-string of an org-file
1156 to export. It then creates a temporary buffer where it does its job.
1157 The result is then again returned as a string, and the exporter works
1158 on this string to produce the exported version."
1160 (let* ((re-radio (and org-target-link-regexp
1161 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1162 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1163 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1164 (re-archive (concat ":" org-archive-tag
":"))
1165 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1166 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1167 (htmlp (plist-get parameters
:for-html
))
1168 (asciip (plist-get parameters
:for-ascii
))
1169 (latexp (plist-get parameters
:for-LaTeX
))
1170 (commentsp (plist-get parameters
:comments
))
1171 (archived-trees (plist-get parameters
:archived-trees
))
1172 (inhibit-read-only t
)
1173 (drawers org-drawers
)
1174 (exp-drawers (plist-get parameters
:drawers
))
1175 (outline-regexp "\\*+ ")
1176 target-alist tmp target level
1179 (with-current-buffer (get-buffer-create " org-mode-tmp")
1183 (run-hooks 'org-export-preprocess-hook
)
1185 ;; Remove license-to-kill stuff
1186 ;; The caller markes some stuff fo killing, stuff that has been
1187 ;; used to create the page title, for example.
1188 (while (setq p
(text-property-any (point-min) (point-max)
1189 :org-license-to-kill t
))
1190 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1192 (let ((org-inhibit-startup t
)) (org-mode))
1193 (untabify (point-min) (point-max))
1195 ;; Get rid of drawers
1196 (unless (eq t exp-drawers
)
1197 (goto-char (point-min))
1198 (let ((re (concat "^[ \t]*:\\("
1201 (org-delete-all exp-drawers
1202 (copy-sequence drawers
))
1204 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1205 (while (re-search-forward re nil t
)
1206 (replace-match ""))))
1208 ;; Get the correct stuff before the first headline
1209 (when (plist-get parameters
:skip-before-1st-heading
)
1210 (goto-char (point-min))
1211 (when (re-search-forward "^\\*+[ \t]" nil t
)
1212 (delete-region (point-min) (match-beginning 0))
1213 (goto-char (point-min))
1215 (when (plist-get parameters
:add-text
)
1216 (goto-char (point-min))
1217 (insert (plist-get parameters
:add-text
) "\n"))
1219 ;; Get rid of archived trees
1220 (when (not (eq archived-trees t
))
1221 (goto-char (point-min))
1222 (while (re-search-forward re-archive nil t
)
1223 (if (not (org-on-heading-p t
))
1224 (org-end-of-subtree t
)
1225 (beginning-of-line 1)
1226 (setq a
(if archived-trees
1227 (1+ (point-at-eol)) (point))
1228 b
(org-end-of-subtree t
))
1229 (if (> b a
) (delete-region a b
)))))
1231 ;; Find all headings and compute the targets for them
1232 (goto-char (point-min))
1233 (org-init-section-numbers)
1234 (let ((re (concat "^" org-outline-regexp
)))
1235 (while (re-search-forward re nil t
)
1236 (setq level
(org-reduced-level
1237 (save-excursion (goto-char (point-at-bol))
1238 (org-outline-level))))
1239 (setq target
(org-solidify-link-text
1240 (format "sec-%s" (org-section-number level
))))
1241 (push (cons target target
) target-alist
)
1242 (add-text-properties
1243 (point-at-bol) (point-at-eol)
1244 (list 'target target
))))
1246 ;; Find targets in comments and move them out of comments,
1247 ;; but mark them as targets that should be invisible
1248 (goto-char (point-min))
1249 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1250 ;; Check if the line before or after is a headline with a target
1251 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1252 (get-text-property (point-at-bol 2) 'target
)))
1254 ;; use the existing target in a neighboring line
1255 (setq tmp
(match-string 2))
1257 (and (looking-at "\n") (delete-char 1))
1258 (push (cons (org-solidify-link-text tmp
) target
)
1260 ;; Make an invisible target
1261 (replace-match "\\1(INVISIBLE)")))
1263 ;; Protect backend specific stuff, throw away the others.
1265 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1266 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1267 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1269 (goto-char (point-min))
1270 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1271 (goto-char (match-end 0))
1272 (while (not (looking-at "#\\+END_EXAMPLE"))
1274 (beginning-of-line 2)))
1275 (goto-char (point-min))
1276 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1277 (add-text-properties (match-beginning 0) (match-end 0)
1278 '(org-protected t
)))
1280 (setq fmt
(pop formatters
))
1282 (goto-char (point-min))
1283 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1284 ":[ \t]*\\(.*\\)") nil t
)
1285 (replace-match "\\1" t
)
1286 (add-text-properties
1287 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1288 '(org-protected t
))))
1289 (goto-char (point-min))
1290 (while (re-search-forward
1292 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1293 (cadddr fmt
) "\\>.*\n?") nil t
)
1295 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1297 (delete-region (match-beginning 0) (match-end 0))))))
1299 ;; Protect quoted subtrees
1300 (goto-char (point-min))
1301 (while (re-search-forward re-quote nil t
)
1302 (goto-char (match-beginning 0))
1304 (add-text-properties (point) (org-end-of-subtree t
)
1305 '(org-protected t
)))
1307 ;; Protect verbatim elements
1308 (goto-char (point-min))
1309 (while (re-search-forward org-verbatim-re nil t
)
1310 (add-text-properties (match-beginning 4) (match-end 4)
1312 (goto-char (1+ (match-end 4))))
1314 ;; Remove subtrees that are commented
1315 (goto-char (point-min))
1316 (while (re-search-forward re-commented nil t
)
1317 (goto-char (match-beginning 0))
1318 (delete-region (point) (org-end-of-subtree t
)))
1320 ;; Remove special table lines
1321 (when org-export-table-remove-special-lines
1322 (goto-char (point-min))
1323 (while (re-search-forward "^[ \t]*|" nil t
)
1324 (beginning-of-line 1)
1325 (if (or (looking-at "[ \t]*| *[!_^] *|")
1326 (and (looking-at ".*?| *<[0-9]+> *|")
1327 (not (looking-at ".*?| *[^ <|]"))))
1328 (delete-region (max (point-min) (1- (point-at-bol)))
1332 ;; Specific LaTeX stuff
1334 (require 'org-export-latex nil
)
1335 (org-export-latex-preprocess))
1338 (org-export-ascii-clean-string))
1340 ;; Specific HTML stuff
1342 ;; Convert LaTeX fragments to images
1343 (when (plist-get parameters
:LaTeX-fragments
)
1345 (concat "ltxpng/" (file-name-sans-extension
1346 (file-name-nondirectory
1347 org-current-export-file
)))
1348 org-current-export-dir nil
"Creating LaTeX image %s"))
1349 (message "Exporting..."))
1351 ;; Remove or replace comments
1352 (goto-char (point-min))
1353 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1355 (progn (add-text-properties
1356 (match-beginning 0) (match-end 0) '(org-protected t
))
1357 (replace-match (format commentsp
(match-string 1)) t t
))
1358 (replace-match "")))
1360 ;; Find matches for radio targets and turn them into internal links
1361 (goto-char (point-min))
1363 (while (re-search-forward re-radio nil t
)
1365 (replace-match "\\1[[\\2]]"))))
1367 ;; Find all links that contain a newline and put them into a single line
1368 (goto-char (point-min))
1369 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1371 (replace-match "\\1 \\3")
1372 (goto-char (match-beginning 0))))
1374 ;; Find all internal links. If they have a fuzzy match (i.e. not
1375 ;; a *dedicated* target match, let the link point to the
1376 ;; correspinding section.
1378 (goto-char (point-min))
1379 (while (re-search-forward org-bracket-link-regexp nil t
)
1381 (let* ((md (match-data))
1382 (desc (match-end 2))
1383 (link (org-link-unescape (match-string 1)))
1384 (slink (org-solidify-link-text link
))
1387 (or (cdr (assoc slink target-alist
))
1389 (unless (string-match org-link-types-re link
)
1390 (setq found
(condition-case nil
(org-link-search link
)
1393 (or (org-on-heading-p)
1394 (not (eq found
'dedicated
))))
1395 (or (get-text-property (point) 'target
)
1398 (1- (previous-single-property-change
1403 (goto-char (match-beginning 1))
1404 (setq props
(text-properties-at (point)))
1405 (delete-region (match-beginning 1) (match-end 1))
1408 (unless desc
(insert "][" link
))
1409 (add-text-properties pos
(point) props
)))))
1411 ;; Normalize links: Convert angle and plain links into bracket links
1412 ;; Expand link abbreviations
1413 (goto-char (point-min))
1414 (while (re-search-forward re-plain-link nil t
)
1415 (goto-char (1- (match-end 0)))
1417 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1418 ":" (match-string 3) "]]")))
1419 ;; added 'org-link face to links
1420 (put-text-property 0 (length s
) 'face
'org-link s
)
1421 (replace-match s t t
))))
1422 (goto-char (point-min))
1423 (while (re-search-forward re-angle-link nil t
)
1424 (goto-char (1- (match-end 0)))
1426 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1427 ":" (match-string 3) "]]")))
1428 (put-text-property 0 (length s
) 'face
'org-link s
)
1429 (replace-match s t t
))))
1430 (goto-char (point-min))
1431 (while (re-search-forward org-bracket-link-regexp nil t
)
1433 (let* ((s (concat "[[" (setq xx
(save-match-data
1434 (org-link-expand-abbrev (match-string 1))))
1438 (concat "[" xx
"]"))
1440 (put-text-property 0 (length s
) 'face
'org-link s
)
1441 (replace-match s t t
))))
1443 ;; Find multiline emphasis and put them into single line
1444 (when (plist-get parameters
:emph-multiline
)
1445 (goto-char (point-min))
1446 (while (re-search-forward org-emph-re nil t
)
1447 (if (not (= (char-after (match-beginning 3))
1448 (char-after (match-beginning 4))))
1450 (subst-char-in-region (match-beginning 0) (match-end 0)
1452 (goto-char (1- (match-end 0))))
1453 (goto-char (1+ (match-beginning 0))))))
1455 (setq rtn
(buffer-string)))
1456 (kill-buffer " org-mode-tmp")
1459 (defun org-export-grab-title-from-buffer ()
1460 "Get a title for the current document, from looking at the buffer."
1461 (let ((inhibit-read-only t
))
1463 (goto-char (point-min))
1464 (let ((end (save-excursion (outline-next-heading) (point))))
1465 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1466 ;; Mark the line so that it will not be exported as normal text.
1468 (add-text-properties (match-beginning 0) (match-end 0)
1469 (list :org-license-to-kill t
)))
1470 ;; Return the title string
1471 (org-trim (match-string 0)))))))
1473 (defun org-export-get-title-from-subtree ()
1474 "Return subtree title and exclude it from export."
1475 (let (title (m (mark)))
1477 (goto-char (region-beginning))
1478 (when (and (org-at-heading-p)
1479 (>= (org-end-of-subtree t t
) (region-end)))
1480 ;; This is a subtree, we take the title from the first heading
1481 (goto-char (region-beginning))
1482 (looking-at org-todo-line-regexp
)
1483 (setq title
(match-string 3))
1485 (add-text-properties (point) (1+ (point-at-eol))
1486 (list :org-license-to-kill t
)))))
1489 (defun org-solidify-link-text (s &optional alist
)
1490 "Take link text and make a safe target out of it."
1495 (org-split-string s
"[ \t\r\n]+") "=="))
1496 (a (assoc rtn alist
)))
1499 (defun org-get-min-level (lines)
1500 "Get the minimum level in LINES."
1501 (let ((re "^\\(\\*+\\) ") l min
)
1503 (while (setq l
(pop lines
))
1504 (if (string-match re l
)
1505 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1508 ;; Variable holding the vector with section numbers
1509 (defvar org-section-numbers
(make-vector org-level-max
0))
1511 (defun org-init-section-numbers ()
1512 "Initialize the vector for the section numbers."
1514 (numbers (nreverse (org-split-string "" "\\.")))
1515 (depth (1- (length org-section-numbers
)))
1516 (i depth
) number-string
)
1519 (aset org-section-numbers i
0)
1520 (setq number-string
(or (car numbers
) "0"))
1521 (if (string-match "\\`[A-Z]\\'" number-string
)
1522 (aset org-section-numbers i
1523 (- (string-to-char number-string
) ?A -
1))
1524 (aset org-section-numbers i
(string-to-number number-string
)))
1528 (defun org-section-number (&optional level
)
1529 "Return a string with the current section number.
1530 When LEVEL is non-nil, increase section numbers on that level."
1531 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1534 (aset org-section-numbers
1535 level
(1+ (aref org-section-numbers level
))))
1536 (setq idx
(1+ level
))
1537 (while (<= idx depth
)
1539 (aset org-section-numbers idx
0))
1540 (setq idx
(1+ idx
))))
1542 (while (<= idx depth
)
1543 (setq n
(aref org-section-numbers idx
))
1544 (setq string
(concat string
(if (not (string= string
"")) "." "")
1546 (setq idx
(1+ idx
)))
1548 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1549 (setq string
(replace-match "" t nil string
)))
1550 (if (string-match "\\(\\.0\\)+\\'" string
)
1551 (setq string
(replace-match "" t nil string
))))
1556 (defvar org-last-level nil
) ; dynamically scoped variable
1557 (defvar org-min-level nil
) ; dynamically scoped variable
1558 (defvar org-levels-open nil
) ; dynamically scoped parameter
1559 (defvar org-ascii-current-indentation nil
) ; For communication
1562 (defun org-export-as-ascii (arg)
1563 "Export the outline as a pretty ASCII file.
1564 If there is an active region, export only the region.
1565 The prefix ARG specifies how many levels of the outline should become
1566 underlined headlines. The default is 3."
1568 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1569 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1570 (org-infile-export-plist)))
1571 (region-p (org-region-active-p))
1575 (goto-char (region-beginning))
1576 (and (org-at-heading-p)
1577 (>= (org-end-of-subtree t t
) (region-end))))))
1578 (custom-times org-display-custom-times
)
1579 (org-ascii-current-indentation '(0 .
0))
1583 (case-fold-search nil
)
1584 (filename (concat (file-name-as-directory
1585 (org-export-directory :ascii opt-plist
))
1586 (file-name-sans-extension
1588 (org-entry-get (region-beginning)
1589 "EXPORT_FILE_NAME" t
))
1590 (file-name-nondirectory buffer-file-name
)))
1592 (filename (if (equal (file-truename filename
)
1593 (file-truename buffer-file-name
))
1594 (concat filename
".txt")
1596 (buffer (find-file-noselect filename
))
1597 (org-levels-open (make-vector org-level-max nil
))
1598 (odd org-odd-levels-only
)
1599 (date (plist-get opt-plist
:date
))
1600 (author (plist-get opt-plist
:author
))
1601 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1602 (plist-get opt-plist
:title
)
1604 (plist-get opt-plist
:skip-before-1st-heading
))
1605 (org-export-grab-title-from-buffer))
1606 (file-name-sans-extension
1607 (file-name-nondirectory buffer-file-name
))))
1608 (email (plist-get opt-plist
:email
))
1609 (language (plist-get opt-plist
:language
))
1610 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1611 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1616 (if (org-region-active-p) (region-beginning) (point-min))
1617 (if (org-region-active-p) (region-end) (point-max))))
1618 (lines (org-split-string
1619 (org-export-preprocess-string
1622 :skip-before-1st-heading
1623 (plist-get opt-plist
:skip-before-1st-heading
)
1624 :drawers
(plist-get opt-plist
:drawers
)
1625 :verbatim-multiline t
1627 (plist-get opt-plist
:archived-trees
)
1628 :add-text
(plist-get opt-plist
:text
))
1630 thetoc have-headings first-heading-pos
1631 table-open table-buffer
)
1633 (let ((inhibit-read-only t
))
1635 (remove-text-properties (point-min) (point-max)
1636 '(:org-license-to-kill t
))))
1638 (setq org-min-level
(org-get-min-level lines
))
1639 (setq org-last-level org-min-level
)
1640 (org-init-section-numbers)
1642 (find-file-noselect filename
)
1644 (setq lang-words
(or (assoc language org-export-language-setup
)
1645 (assoc "en" org-export-language-setup
)))
1646 (switch-to-buffer-other-window buffer
)
1649 ;; create local variables for all options, to make sure all called
1650 ;; functions get the correct information
1652 (set (make-local-variable (cdr x
))
1653 (plist-get opt-plist
(car x
))))
1654 org-export-plist-vars
)
1655 (org-set-local 'org-odd-levels-only odd
)
1656 (setq umax
(if arg
(prefix-numeric-value arg
)
1657 org-export-headline-levels
))
1658 (setq umax-toc
(if (integerp org-export-with-toc
)
1659 (min org-export-with-toc umax
)
1663 (if title
(org-insert-centered title ?
=))
1665 (if (and (or author email
)
1666 org-export-author-info
)
1667 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1668 (if email
(concat " <" email
">") "")
1672 ((and date
(string-match "%" date
))
1673 (setq date
(format-time-string date
)))
1675 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1677 (if (and date org-export-time-stamp-file
)
1678 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1682 (if org-export-with-toc
1684 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1685 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1686 (mapc '(lambda (line)
1687 (if (string-match org-todo-line-regexp
1689 ;; This is a headline
1691 (setq have-headings t
)
1692 (setq level
(- (match-end 1) (match-beginning 1))
1693 level
(org-tr-level level
)
1694 txt
(match-string 3 line
)
1696 (or (and org-export-mark-todo-in-toc
1698 (not (member (match-string 2 line
)
1699 org-done-keywords
)))
1701 (and org-export-mark-todo-in-toc
1703 (org-search-todo-below
1704 line lines level
))))
1705 (setq txt
(org-html-expand-for-ascii txt
))
1707 (while (string-match org-bracket-link-regexp txt
)
1710 (match-string (if (match-end 2) 3 1) txt
)
1713 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1715 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1717 (setq txt
(replace-match "" t t txt
)))
1718 (if (string-match quote-re0 txt
)
1719 (setq txt
(replace-match "" t t txt
)))
1721 (if org-export-with-section-numbers
1722 (setq txt
(concat (org-section-number level
)
1724 (if (<= level umax-toc
)
1729 (* (max 0 (- level org-min-level
)) 4) ?\
)
1730 (format (if todo
"%s (*)\n" "%s\n") txt
))
1732 (setq org-last-level level
))
1735 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1737 (org-init-section-numbers)
1738 (while (setq line
(pop lines
))
1739 ;; Remove the quoted HTML tags.
1740 (setq line
(org-html-expand-for-ascii line
))
1742 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1743 (setq line
(replace-match "" t t line
)))
1744 ;; Replace internal links
1745 (while (string-match org-bracket-link-regexp line
)
1746 (setq line
(replace-match
1747 (if (match-end 3) "[\\3]" "[\\1]")
1750 (setq line
(org-translate-time line
)))
1752 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1754 (setq first-heading-pos
(or first-heading-pos
(point)))
1755 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1756 txt
(match-string 2 line
))
1757 (org-ascii-level-start level txt umax lines
))
1759 ((and org-export-with-tables
1760 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1761 (if (not table-open
)
1763 (setq table-open t table-buffer nil
))
1765 (setq table-buffer
(cons line table-buffer
))
1766 (when (or (not lines
)
1767 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1769 (setq table-open nil
1770 table-buffer
(nreverse table-buffer
))
1773 (org-fix-indentation x org-ascii-current-indentation
))
1774 (org-format-table-ascii table-buffer
)
1777 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1778 (if (and org-export-with-fixed-width
1779 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1780 (setq line
(replace-match "\\1" nil nil line
)))
1781 (insert line
"\n"))))
1785 ;; insert the table of contents
1787 (goto-char (point-min))
1788 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1790 (goto-char (match-beginning 0))
1792 (goto-char first-heading-pos
))
1793 (mapc 'insert thetoc
)
1794 (or (looking-at "[ \t]*\n[ \t]*\n")
1797 ;; Convert whitespace place holders
1798 (goto-char (point-min))
1800 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1801 (setq end
(next-single-property-change beg
'org-whitespace
))
1803 (delete-region beg end
)
1804 (insert (make-string (- end beg
) ?\
))))
1807 ;; remove display and invisible chars
1809 (goto-char (point-min))
1810 (while (setq beg
(next-single-property-change (point) 'display
))
1811 (setq end
(next-single-property-change beg
'display
))
1812 (delete-region beg end
)
1815 (goto-char (point-min))
1816 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1817 (setq end
(next-single-property-change beg
'org-cwidth
))
1818 (delete-region beg end
)
1820 (goto-char (point-min))))
1822 (defun org-export-ascii-clean-string ()
1823 "Do extra work for ASCII export"
1824 (goto-char (point-min))
1825 (while (re-search-forward org-verbatim-re nil t
)
1826 (goto-char (match-end 2))
1827 (backward-delete-char 1) (insert "'")
1828 (goto-char (match-beginning 2))
1829 (delete-char 1) (insert "`")
1830 (goto-char (match-end 2))))
1832 (defun org-search-todo-below (line lines level
)
1833 "Search the subtree below LINE for any TODO entries."
1834 (let ((rest (cdr (memq line lines
)))
1835 (re org-todo-line-regexp
)
1838 (while (setq line
(pop rest
))
1839 (if (string-match re line
)
1841 (setq lv
(- (match-end 1) (match-beginning 1))
1842 todo
(and (match-beginning 2)
1843 (not (member (match-string 2 line
)
1844 org-done-keywords
))))
1846 (if (<= lv level
) (throw 'exit nil
))
1847 (if todo
(throw 'exit t
))))))))
1849 (defun org-html-expand-for-ascii (line)
1850 "Handle quoted HTML for ASCII export."
1851 (if org-export-html-expand
1852 (while (string-match "@<[^<>\n]*>" line
)
1853 ;; We just remove the tags for now.
1854 (setq line
(replace-match "" nil nil line
))))
1857 (defun org-insert-centered (s &optional underline
)
1858 "Insert the string S centered and underline it with character UNDERLINE."
1859 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
1860 (insert (make-string ind ?\
) s
"\n")
1862 (insert (make-string ind ?\
)
1863 (make-string (string-width s
) underline
)
1866 (defun org-ascii-level-start (level title umax
&optional lines
)
1867 "Insert a new level in ASCII export."
1868 (let (char (n (- level umax
1)) (ind 0))
1871 (insert (make-string (* 2 n
) ?\
)
1872 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
1873 org-export-ascii-bullets
))
1875 ;; find the indentation of the next non-empty line
1878 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
1879 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
1880 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
1882 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
1883 (if (or (not (equal (char-before) ?
\n))
1884 (not (equal (char-before (1- (point))) ?
\n)))
1886 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
1887 (unless org-export-with-tags
1888 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
1889 (setq title
(replace-match "" t t title
))))
1890 (if org-export-with-section-numbers
1891 (setq title
(concat (org-section-number level
) " " title
)))
1892 (insert title
"\n" (make-string (string-width title
) char
) "\n")
1893 (setq org-ascii-current-indentation
'(0 .
0)))))
1896 (defun org-export-visible (type arg
)
1897 "Create a copy of the visible part of the current buffer, and export it.
1898 The copy is created in a temporary buffer and removed after use.
1899 TYPE is the final key (as a string) that also select the export command in
1900 the `C-c C-e' export dispatcher.
1901 As a special case, if the you type SPC at the prompt, the temporary
1902 org-mode file will not be removed but presented to you so that you can
1903 continue to use it. The prefix arg ARG is passed through to the exporting
1907 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
1908 (read-char-exclusive))
1909 current-prefix-arg
))
1910 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
1911 (error "Invalid export key"))
1912 (let* ((binding (cdr (assoc type
1913 '((?a . org-export-as-ascii
)
1914 (?\C-a . org-export-as-ascii
)
1915 (?b . org-export-as-html-and-open
)
1916 (?\C-b . org-export-as-html-and-open
)
1917 (?h . org-export-as-html
)
1918 (?H . org-export-as-html-to-buffer
)
1919 (?R . org-export-region-as-html
)
1920 (?x . org-export-as-xoxo
)))))
1921 (keepp (equal type ?\
))
1922 (file buffer-file-name
)
1923 (buffer (get-buffer-create "*Org Export Visible*"))
1925 ;; Need to hack the drawers here.
1927 (goto-char (point-min))
1928 (while (re-search-forward org-drawer-regexp nil t
)
1929 (goto-char (match-beginning 1))
1930 (or (org-invisible-p) (org-flag-drawer nil
))))
1931 (with-current-buffer buffer
(erase-buffer))
1933 (setq s
(goto-char (point-min)))
1934 (while (not (= (point) (point-max)))
1935 (goto-char (org-find-invisible))
1936 (append-to-buffer buffer s
(point))
1937 (setq s
(goto-char (org-find-visible))))
1938 (org-cycle-hide-drawers 'all
)
1939 (goto-char (point-min))
1941 ;; Copy all comment lines to the end, to make sure #+ settings are
1942 ;; still available for the second export step. Kind of a hack, but
1943 ;; does do the trick.
1944 (if (looking-at "#[^\r\n]*")
1945 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
1946 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
1947 (append-to-buffer buffer
(1+ (match-beginning 0))
1948 (min (point-max) (1+ (match-end 0))))))
1950 (let ((buffer-file-name file
)
1951 (org-inhibit-startup t
))
1954 (unless keepp
(funcall binding arg
))))
1956 (kill-buffer buffer
)
1957 (switch-to-buffer-other-window buffer
)
1958 (goto-char (point-min)))))
1960 (defun org-find-visible ()
1962 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
1963 (get-char-property s
'invisible
)))
1965 (defun org-find-invisible ()
1967 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
1968 (not (get-char-property s
'invisible
))))
1973 (defvar org-archive-location
) ;; gets loades with the org-archive require.
1974 (defun org-get-current-options ()
1975 "Return a string with current options as keyword options.
1976 Does include HTML export options as well as TODO and CATEGORY stuff."
1977 (require 'org-archive
)
1984 #+TEXT: Some descriptive text to be emitted. Several lines OK.
1985 #+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
1992 #+PRIORITIES: %c %c %c
1994 #+STARTUP: %s %s %s %s %s
1999 (buffer-name) (user-full-name) user-mail-address
2000 (format-time-string (car org-time-stamp-formats
))
2001 org-export-default-language
2002 org-export-headline-levels
2003 org-export-with-section-numbers
2005 org-export-preserve-breaks
2006 org-export-html-expand
2007 org-export-with-fixed-width
2008 org-export-with-tables
2009 org-export-with-sub-superscripts
2010 org-export-with-special-strings
2011 org-export-with-footnotes
2012 org-export-with-emphasize
2013 org-export-with-TeX-macros
2014 org-export-with-LaTeX-fragments
2015 org-export-skip-text-before-1st-heading
2016 org-export-with-drawers
2017 org-export-with-tags
2018 (if (featurep 'org-infojs
) (org-infojs-options-inbuffer-template) "")
2019 org-export-html-link-up
2020 org-export-html-link-home
2021 (file-name-nondirectory buffer-file-name
)
2022 "TODO FEEDBACK VERIFY DONE"
2023 "Me Jason Marie DONE"
2024 org-highest-priority org-lowest-priority org-default-priority
2025 (mapconcat 'identity org-drawers
" ")
2026 (cdr (assoc org-startup-folded
2027 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2028 (if org-odd-levels-only
"odd" "oddeven")
2029 (if org-hide-leading-stars
"hidestars" "showstars")
2030 (if org-startup-align-all-tables
"align" "noalign")
2031 (cond ((eq org-log-done t
) "logdone")
2032 ((equal org-log-done
'note
) "lognotedone")
2033 ((not org-log-done
) "nologdone"))
2034 (or (mapconcat (lambda (x)
2036 ((equal '(:startgroup
) x
) "{")
2037 ((equal '(:endgroup
) x
) "}")
2038 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2040 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2041 org-archive-location
2042 "org file:~/org/%s.org"
2046 (defun org-insert-export-options-template ()
2047 "Insert into the buffer a template with information for exporting."
2049 (if (not (bolp)) (newline))
2050 (let ((s (org-get-current-options)))
2051 (and (string-match "#\\+CATEGORY" s
)
2052 (setq s
(substring s
0 (match-beginning 0))))
2056 (defun org-export-as-html-and-open (arg)
2057 "Export the outline as HTML and immediately open it with a browser.
2058 If there is an active region, export only the region.
2059 The prefix ARG specifies how many levels of the outline should become
2060 headlines. The default is 3. Lower levels will become bulleted lists."
2062 (org-export-as-html arg
'hidden
)
2063 (org-open-file buffer-file-name
))
2066 (defun org-export-as-html-batch ()
2067 "Call `org-export-as-html', may be used in batch processing as
2069 --load=$HOME/lib/emacs/org.el
2070 --eval \"(setq org-export-headline-levels 2)\"
2071 --visit=MyFile --funcall org-export-as-html-batch"
2072 (org-export-as-html org-export-headline-levels
'hidden
))
2075 (defun org-export-as-html-to-buffer (arg)
2076 "Call `org-exort-as-html` with output to a temporary buffer.
2077 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2079 (org-export-as-html arg nil nil
"*Org HTML Export*")
2080 (switch-to-buffer-other-window "*Org HTML Export*"))
2083 (defun org-replace-region-by-html (beg end
)
2084 "Assume the current region has org-mode syntax, and convert it to HTML.
2085 This can be used in any buffer. For example, you could write an
2086 itemized list in org-mode syntax in an HTML buffer and then use this
2087 command to convert it."
2089 (let (reg html buf pop-up-frames
)
2090 (save-window-excursion
2092 (setq html
(org-export-region-as-html
2094 (setq reg
(buffer-substring beg end
)
2095 buf
(get-buffer-create "*Org tmp*"))
2096 (with-current-buffer buf
2100 (setq html
(org-export-region-as-html
2101 (point-min) (point-max) t
'string
)))
2103 (delete-region beg end
)
2107 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2108 "Convert region from BEG to END in org-mode buffer to HTML.
2109 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2110 contents, and only produce the region of converted text, useful for
2111 cut-and-paste operations.
2112 If BUFFER is a buffer or a string, use/create that buffer as a target
2113 of the converted HTML. If BUFFER is the symbol `string', return the
2114 produced HTML as a string and leave not buffer behind. For example,
2115 a Lisp program could call this function in the following way:
2117 (setq html (org-export-region-as-html beg end t 'string))
2119 When called interactively, the output buffer is selected, and shown
2120 in a window. A non-interactive call will only return the buffer."
2121 (interactive "r\nP")
2122 (when (interactive-p)
2123 (setq buffer
"*Org HTML Export*"))
2124 (let ((transient-mark-mode t
) (zmacs-regions t
)
2127 (set-mark (point)) ;; to activate the region
2129 (setq rtn
(org-export-as-html
2132 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2133 (if (and (interactive-p) (bufferp rtn
))
2134 (switch-to-buffer-other-window rtn
)
2137 (defvar html-table-tag nil
) ; dynamically scoped into this.
2139 (defun org-export-as-html (arg &optional hidden ext-plist
2140 to-buffer body-only pub-dir
)
2141 "Export the outline as a pretty HTML file.
2142 If there is an active region, export only the region. The prefix
2143 ARG specifies how many levels of the outline should become
2144 headlines. The default is 3. Lower levels will become bulleted
2145 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2146 EXT-PLIST is a property list with external parameters overriding
2147 org-mode's default settings, but still inferior to file-local
2148 settings. When TO-BUFFER is non-nil, create a buffer with that
2149 name and export to that buffer. If TO-BUFFER is the symbol
2150 `string', don't leave any buffer behind but just return the
2151 resulting HTML as a string. When BODY-ONLY is set, don't produce
2152 the file header and footer, simply return the content of
2153 <body>...</body>, without even the body tags themselves. When
2154 PUB-DIR is set, use this as the publishing directory."
2157 ;; Make sure we have a file name when we need it.
2158 (when (and (not (or to-buffer body-only
))
2159 (not buffer-file-name
))
2160 (if (buffer-base-buffer)
2161 (org-set-local 'buffer-file-name
2162 (with-current-buffer (buffer-base-buffer)
2164 (error "Need a file name to be able to export.")))
2166 (message "Exporting...")
2167 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2168 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2169 (setq-default org-done-keywords org-done-keywords
)
2170 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2172 (org-export-process-option-filters
2173 (org-combine-plists (org-default-export-plist)
2175 (org-infile-export-plist))))
2177 (style (plist-get opt-plist
:style
))
2178 (html-extension (plist-get opt-plist
:html-extension
))
2179 (link-validate (plist-get opt-plist
:link-validation-function
))
2180 valid thetoc have-headings first-heading-pos
2181 (odd org-odd-levels-only
)
2182 (region-p (org-region-active-p))
2186 (goto-char (region-beginning))
2187 (and (org-at-heading-p)
2188 (>= (org-end-of-subtree t t
) (region-end))))))
2189 ;; The following two are dynamically scoped into other
2191 (org-current-export-dir
2192 (or pub-dir
(org-export-directory :html opt-plist
)))
2193 (org-current-export-file buffer-file-name
)
2194 (level 0) (line "") (origline "") txt todo
2197 (filename (if to-buffer nil
2200 (file-name-sans-extension
2202 (org-entry-get (region-beginning)
2203 "EXPORT_FILE_NAME" t
))
2204 (file-name-nondirectory buffer-file-name
)))
2206 (file-name-as-directory
2207 (or pub-dir
(org-export-directory :html opt-plist
))))))
2208 (current-dir (if buffer-file-name
2209 (file-name-directory buffer-file-name
)
2211 (buffer (if to-buffer
2213 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2214 (t (get-buffer-create to-buffer
)))
2215 (find-file-noselect filename
)))
2216 (org-levels-open (make-vector org-level-max nil
))
2217 (date (plist-get opt-plist
:date
))
2218 (author (plist-get opt-plist
:author
))
2219 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2220 (plist-get opt-plist
:title
)
2222 (plist-get opt-plist
:skip-before-1st-heading
))
2223 (org-export-grab-title-from-buffer))
2224 (and buffer-file-name
2225 (file-name-sans-extension
2226 (file-name-nondirectory buffer-file-name
)))
2228 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2229 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2230 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2234 (local-list-num nil
)
2235 (local-list-indent nil
)
2236 (llt org-plain-list-ordered-item-terminator
)
2237 (email (plist-get opt-plist
:email
))
2238 (language (plist-get opt-plist
:language
))
2242 (coding-system (and (boundp 'buffer-file-coding-system
)
2243 buffer-file-coding-system
))
2244 (coding-system-for-write (or org-export-html-coding-system
2246 (save-buffer-coding-system (or org-export-html-coding-system
2248 (charset (and coding-system-for-write
2249 (fboundp 'coding-system-get
)
2250 (coding-system-get coding-system-for-write
2254 (if region-p
(region-beginning) (point-min))
2255 (if region-p
(region-end) (point-max))))
2258 (org-export-preprocess-string
2262 :skip-before-1st-heading
2263 (plist-get opt-plist
:skip-before-1st-heading
)
2264 :drawers
(plist-get opt-plist
:drawers
)
2266 (plist-get opt-plist
:archived-trees
)
2268 (plist-get opt-plist
:text
)
2270 (plist-get opt-plist
:LaTeX-fragments
))
2273 table-buffer table-orig-buffer
2274 ind start-is-num starter didclose
2275 rpl path desc descp desc1 desc2 link
2279 (let ((inhibit-read-only t
))
2281 (remove-text-properties (point-min) (point-max)
2282 '(:org-license-to-kill t
))))
2284 (message "Exporting...")
2286 (setq org-min-level
(org-get-min-level lines
))
2287 (setq org-last-level org-min-level
)
2288 (org-init-section-numbers)
2291 ((and date
(string-match "%" date
))
2292 (setq date
(format-time-string date
)))
2294 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2296 ;; Get the language-dependent settings
2297 (setq lang-words
(or (assoc language org-export-language-setup
)
2298 (assoc "en" org-export-language-setup
)))
2300 ;; Switch to the output buffer
2302 (let ((inhibit-read-only t
)) (erase-buffer))
2305 (and (fboundp 'set-buffer-file-coding-system
)
2306 (set-buffer-file-coding-system coding-system-for-write
))
2308 (let ((case-fold-search nil
)
2309 (org-odd-levels-only odd
))
2310 ;; create local variables for all options, to make sure all called
2311 ;; functions get the correct information
2313 (set (make-local-variable (cdr x
))
2314 (plist-get opt-plist
(car x
))))
2315 org-export-plist-vars
)
2316 (setq umax
(if arg
(prefix-numeric-value arg
)
2317 org-export-headline-levels
))
2318 (setq umax-toc
(if (integerp org-export-with-toc
)
2319 (min org-export-with-toc umax
)
2324 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2325 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2326 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2327 lang=\"%s\" xml:lang=\"%s\">
2330 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2331 <meta name=\"generator\" content=\"Org-mode\"/>
2332 <meta name=\"generated\" content=\"%s\"/>
2333 <meta name=\"author\" content=\"%s\"/>
2337 language language
(org-html-expand title
)
2338 (or charset
"iso-8859-1") date author style
))
2340 (insert (or (plist-get opt-plist
:preamble
) ""))
2342 (when (plist-get opt-plist
:auto-preamble
)
2343 (if title
(insert (format org-export-html-title-format
2344 (org-html-expand title
))))))
2346 (if (and org-export-with-toc
(not body-only
))
2348 (push (format "<h%d>%s</h%d>\n"
2349 org-export-html-toplevel-hlevel
2351 org-export-html-toplevel-hlevel
)
2353 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2354 (push "<ul>\n<li>" thetoc
)
2356 (mapcar '(lambda (line)
2357 (if (string-match org-todo-line-regexp line
)
2358 ;; This is a headline
2360 (setq have-headings t
)
2361 (setq level
(- (match-end 1) (match-beginning 1))
2362 level
(org-tr-level level
)
2363 txt
(save-match-data
2365 (org-export-cleanup-toc-line
2366 (match-string 3 line
))))
2368 (or (and org-export-mark-todo-in-toc
2370 (not (member (match-string 2 line
)
2371 org-done-keywords
)))
2373 (and org-export-mark-todo-in-toc
2375 (org-search-todo-below
2376 line lines level
))))
2378 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2379 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2380 (if (string-match quote-re0 txt
)
2381 (setq txt
(replace-match "" t t txt
)))
2382 (setq snumber
(org-section-number level
))
2383 (if org-export-with-section-numbers
2384 (setq txt
(concat snumber
" " txt
)))
2385 (if (<= level
(max umax umax-toc
))
2386 (setq head-count
(+ head-count
1)))
2387 (if (<= level umax-toc
)
2389 (if (> level org-last-level
)
2391 (setq cnt
(- level org-last-level
))
2392 (while (>= (setq cnt
(1- cnt
)) 0)
2393 (push "\n<ul>\n<li>" thetoc
))
2394 (push "\n" thetoc
)))
2395 (if (< level org-last-level
)
2397 (setq cnt
(- org-last-level level
))
2398 (while (>= (setq cnt
(1- cnt
)) 0)
2399 (push "</li>\n</ul>" thetoc
))
2400 (push "\n" thetoc
)))
2401 ;; Check for targets
2402 (while (string-match org-any-target-regexp line
)
2403 (setq line
(replace-match
2404 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2406 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2407 (setq txt
(replace-match "" t t txt
)))
2411 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2412 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2413 snumber txt
) thetoc
)
2415 (setq org-last-level level
))
2419 (while (> org-last-level
(1- org-min-level
))
2420 (setq org-last-level
(1- org-last-level
))
2421 (push "</li>\n</ul>\n" thetoc
))
2422 (push "</div>\n" thetoc
)
2423 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2426 (org-init-section-numbers)
2428 (while (setq line
(pop lines
) origline line
)
2431 ;; end of quote section?
2432 (when (and inquote
(string-match "^\\*+ " line
))
2435 ;; inside a quote section?
2437 (insert (org-html-protect line
) "\n")
2438 (throw 'nextline nil
))
2441 (when (and org-export-with-fixed-width
2442 (string-match "^[ \t]*:\\(.*\\)" line
))
2446 (insert (org-html-protect (match-string 1 line
)) "\n")
2448 (not (string-match "^[ \t]*\\(:.*\\)"
2451 (insert "</pre>\n"))
2452 (throw 'nextline nil
))
2455 (when (get-text-property 0 'org-protected line
)
2457 (when (re-search-backward
2458 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2459 (setq par
(match-string 1))
2460 (replace-match "\\2\n"))
2463 (or (= (length (car lines
)) 0)
2464 (get-text-property 0 'org-protected
(car lines
))))
2465 (insert (pop lines
) "\n"))
2466 (and par
(insert "<p>\n")))
2467 (throw 'nextline nil
))
2470 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2471 (insert "\n<hr/>\n")
2472 (throw 'nextline nil
))
2474 ;; make targets to anchors
2475 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2478 (setq line
(replace-match
2479 (concat "@<a name=\""
2480 (org-solidify-link-text (match-string 1 line
))
2483 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2484 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2485 (setq line
(replace-match
2486 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2487 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2490 (setq line
(replace-match
2491 (concat "@<a name=\""
2492 (org-solidify-link-text (match-string 1 line
))
2493 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2496 (setq line
(org-html-handle-time-stamps line
))
2498 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2499 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2500 ;; Also handle sub_superscripts and checkboxes
2501 (or (string-match org-table-hline-regexp line
)
2502 (setq line
(org-html-expand line
)))
2506 (while (string-match org-bracket-link-analytic-regexp line start
)
2507 (setq start
(match-beginning 0))
2508 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2509 (setq path
(match-string 3 line
))
2510 (setq desc1
(if (match-end 5) (match-string 5 line
))
2511 desc2
(if (match-end 2) (concat type
":" path
) path
)
2512 descp
(and desc1
(not (equal desc1 desc2
)))
2513 desc
(or desc1 desc2
))
2514 ;; Make an image out of the description if that is so wanted
2515 (when (and descp
(org-file-image-p desc
))
2517 (if (string-match "^file:" desc
)
2518 (setq desc
(substring desc
(match-end 0)))))
2519 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2520 ;; FIXME: do we need to unescape here somewhere?
2522 ((equal type
"internal")
2526 (org-solidify-link-text
2527 (save-match-data (org-link-unescape path
)) nil
)
2528 "\">" desc
"</a>")))
2529 ((member type
'("http" "https"))
2530 ;; standard URL, just check if we need to inline an image
2531 (if (and (or (eq t org-export-html-inline-images
)
2532 (and org-export-html-inline-images
(not descp
)))
2533 (org-file-image-p path
))
2534 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2535 (setq link
(concat type
":" path
))
2536 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2537 ((member type
'("ftp" "mailto" "news"))
2539 (setq link
(concat type
":" path
))
2540 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2541 ((string= type
"file")
2543 (let* ((filename path
)
2544 (abs-p (file-name-absolute-p filename
))
2545 thefile file-is-image-p search
)
2547 (if (string-match "::\\(.*\\)" filename
)
2548 (setq search
(match-string 1 filename
)
2549 filename
(replace-match "" t nil filename
)))
2551 (if (functionp link-validate
)
2552 (funcall link-validate filename current-dir
)
2554 (setq file-is-image-p
(org-file-image-p filename
))
2555 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2556 (when (and org-export-html-link-org-files-as-html
2557 (string-match "\\.org$" thefile
))
2558 (setq thefile
(concat (substring thefile
0
2559 (match-beginning 0))
2560 "." html-extension
))
2562 ;; make sure this is can be used as target search
2563 (not (string-match "^[0-9]*$" search
))
2564 (not (string-match "^\\*" search
))
2565 (not (string-match "^/.*/$" search
)))
2566 (setq thefile
(concat thefile
"#"
2567 (org-solidify-link-text
2568 (org-link-unescape search
)))))
2569 (when (string-match "^file:" desc
)
2570 (setq desc
(replace-match "" t t desc
))
2571 (if (string-match "\\.org$" desc
)
2572 (setq desc
(replace-match "" t t desc
))))))
2573 (setq rpl
(if (and file-is-image-p
2574 (or (eq t org-export-html-inline-images
)
2575 (and org-export-html-inline-images
2577 (concat "<img src=\"" thefile
"\"/>")
2578 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2579 (if (not valid
) (setq rpl desc
))))
2581 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2584 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2587 ;; just publish the path, as default
2588 (setq rpl
(concat "<i><" type
":"
2589 (save-match-data (org-link-unescape path
))
2591 (setq line
(replace-match rpl t t line
)
2592 start
(+ start
(length rpl
))))
2595 (if (and (string-match org-todo-line-regexp line
)
2596 (match-beginning 2))
2599 (concat (substring line
0 (match-beginning 2))
2601 (if (member (match-string 2 line
)
2604 "\">" (match-string 2 line
)
2605 "</span>" (substring line
(match-end 2)))))
2607 ;; Does this contain a reference to a footnote?
2608 (when org-export-with-footnotes
2610 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2611 (if (get-text-property (match-beginning 2) 'org-protected line
)
2612 (setq start
(match-end 2))
2613 (let ((n (match-string 2 line
)))
2617 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2618 (match-string 1 line
) n n n
)
2622 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2623 ;; This is a headline
2624 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2625 txt
(match-string 2 line
))
2626 (if (string-match quote-re0 txt
)
2627 (setq txt
(replace-match "" t t txt
)))
2628 (if (<= level
(max umax umax-toc
))
2629 (setq head-count
(+ head-count
1)))
2631 ;; Close any local lists before inserting a new header line
2632 (while local-list-num
2634 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
2635 (pop local-list-num
))
2636 (setq local-list-indent nil
2638 (setq first-heading-pos
(or first-heading-pos
(point)))
2639 (org-html-level-start level txt umax
2640 (and org-export-with-toc
(<= level umax
))
2643 (when (string-match quote-re line
)
2647 ((and org-export-with-tables
2648 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2649 (if (not table-open
)
2651 (setq table-open t table-buffer nil table-orig-buffer nil
))
2653 (setq table-buffer
(cons line table-buffer
)
2654 table-orig-buffer
(cons origline table-orig-buffer
))
2655 (when (or (not lines
)
2656 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2658 (setq table-open nil
2659 table-buffer
(nreverse table-buffer
)
2660 table-orig-buffer
(nreverse table-orig-buffer
))
2661 (org-close-par-maybe)
2662 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2667 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2668 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2669 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2670 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2672 (setq ind
(org-get-string-indentation line
)
2673 start-is-num
(match-beginning 4)
2674 starter
(if (match-beginning 2)
2675 (substring (match-string 2 line
) 0 -
1))
2676 line
(substring line
(match-beginning 5)))
2677 (unless (string-match "[^ \t]" line
)
2678 ;; empty line. Pretend indentation is large.
2679 (setq ind
(if org-empty-line-terminates-plain-lists
2681 (1+ (or (car local-list-indent
) 1)))))
2683 (while (and in-local-list
2684 (or (and (= ind
(car local-list-indent
))
2686 (< ind
(car local-list-indent
))))
2689 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
2690 (pop local-list-num
) (pop local-list-indent
)
2691 (setq in-local-list local-list-indent
))
2694 (or (not in-local-list
)
2695 (> ind
(car local-list-indent
))))
2696 ;; Start new (level of) list
2697 (org-close-par-maybe)
2698 (insert (if start-is-num
"<ol>\n<li>\n" "<ul>\n<li>\n"))
2699 (push start-is-num local-list-num
)
2700 (push ind local-list-indent
)
2701 (setq in-local-list t
))
2703 ;; continue current list
2707 ;; we did close a list, normal text follows: need <p>
2709 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2712 (if (equal (match-string 1 line
) "X")
2714 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2717 ;; Empty lines start a new paragraph. If hand-formatted lists
2718 ;; are not fully interpreted, lines starting with "-", "+", "*"
2719 ;; also start a new paragraph.
2720 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2722 ;; Is this the start of a footnote?
2723 (when org-export-with-footnotes
2724 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2725 (org-close-par-maybe)
2726 (let ((n (match-string 1 line
)))
2727 (setq line
(replace-match
2728 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2730 ;; Check if the line break needs to be conserved
2732 ((string-match "\\\\\\\\[ \t]*$" line
)
2733 (setq line
(replace-match "<br/>" t t line
)))
2734 (org-export-preserve-breaks
2735 (setq line
(concat line
"<br/>"))))
2737 (insert line
"\n")))))
2739 ;; Properly close all local lists and other lists
2740 (when inquote
(insert "</pre>\n"))
2742 ;; Close any local lists before inserting a new header line
2743 (while local-list-num
2745 (insert (if (car local-list-num
) "</ol>\n" "</ul>\n"))
2746 (pop local-list-num
))
2747 (setq local-list-indent nil
2749 (org-html-level-start 1 nil umax
2750 (and org-export-with-toc
(<= level umax
))
2752 ;; the </div> to lose the last text-... div.
2756 (when (plist-get opt-plist
:auto-postamble
)
2757 (insert "<div id=\"postamble\">")
2758 (when (and org-export-author-info author
)
2759 (insert "<p class=\"author\"> "
2760 (nth 1 lang-words
) ": " author
"\n")
2762 (if (listp (split-string email
",+ *"))
2764 (insert "<a href=\"mailto:" e
"\"><"
2766 (split-string email
",+ *"))
2767 (insert "<a href=\"mailto:" email
"\"><"
2768 email
"></a>\n")))
2770 (when (and date org-export-time-stamp-file
)
2771 (insert "<p class=\"date\"> "
2772 (nth 2 lang-words
) ": "
2776 (if org-export-html-with-timestamp
2777 (insert org-export-html-html-helper-timestamp
))
2778 (insert (or (plist-get opt-plist
:postamble
) ""))
2779 (insert "</body>\n</html>\n"))
2782 (if (eq major-mode default-major-mode
) (html-mode))
2784 ;; insert the table of contents
2785 (goto-char (point-min))
2787 (if (or (re-search-forward
2788 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2790 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2792 (goto-char (match-beginning 0))
2794 (goto-char first-heading-pos
)
2795 (when (looking-at "\\s-*</p>")
2796 (goto-char (match-end 0))
2798 (insert "<div id=\"table-of-contents\">\n")
2799 (mapc 'insert thetoc
)
2800 (insert "</div>\n"))
2801 ;; remove empty paragraphs and lists
2802 (goto-char (point-min))
2803 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2805 (goto-char (point-min))
2806 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2808 (goto-char (point-min))
2809 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
2811 ;; Convert whitespace place holders
2812 (goto-char (point-min))
2814 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2815 (setq n
(get-text-property beg
'org-whitespace
)
2816 end
(next-single-property-change beg
'org-whitespace
))
2818 (delete-region beg end
)
2819 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2820 (make-string n ?x
)))))
2821 (or to-buffer
(save-buffer))
2822 (goto-char (point-min))
2823 (message "Exporting... done")
2824 (if (eq to-buffer
'string
)
2825 (prog1 (buffer-substring (point-min) (point-max))
2826 (kill-buffer (current-buffer)))
2827 (current-buffer)))))
2829 (defvar org-table-colgroup-info nil
)
2830 (defun org-format-table-ascii (lines)
2831 "Format a table for ascii export."
2833 (setq lines
(org-split-string lines
"\n")))
2834 (if (not (string-match "^[ \t]*|" (car lines
)))
2835 ;; Table made by table.el - test for spanning
2838 ;; A normal org table
2839 ;; Get rid of hlines at beginning and end
2840 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2841 (setq lines
(nreverse lines
))
2842 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2843 (setq lines
(nreverse lines
))
2844 (when org-export-table-remove-special-lines
2845 ;; Check if the table has a marking column. If yes remove the
2846 ;; column and the special lines
2847 (setq lines
(org-table-clean-before-export lines
)))
2848 ;; Get rid of the vertical lines except for grouping
2849 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
2851 (while (setq line
(pop lines
))
2852 (if (string-match org-table-hline-regexp line
)
2853 (and (string-match "|\\(.*\\)|" line
)
2854 (setq line
(replace-match " \\1" t nil line
)))
2855 (setq start
0 vl1 vl
)
2856 (while (string-match "|" line start
)
2857 (setq start
(match-end 0))
2858 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
2862 (defun org-colgroup-info-to-vline-list (info)
2865 (setq last new new
(pop info
))
2866 (if (or (memq last
'(:end
:startend
))
2867 (memq new
'(:start
:startend
)))
2870 (setq vl
(nreverse vl
))
2871 (and vl
(setcar vl nil
))
2874 (defvar org-table-number-regexp
) ; defined in org-table.el
2875 (defun org-format-table-html (lines olines
)
2876 "Find out which HTML converter to use and return the HTML code."
2878 (setq lines
(org-split-string lines
"\n")))
2879 (if (string-match "^[ \t]*|" (car lines
))
2880 ;; A normal org table
2881 (org-format-org-table-html lines
)
2882 ;; Table made by table.el - test for spanning
2883 (let* ((hlines (delq nil
(mapcar
2885 (if (string-match "^[ \t]*\\+-" x
) x
2888 (first (car hlines
))
2889 (ll (and (string-match "\\S-+" first
)
2890 (match-string 0 first
)))
2891 (re (concat "^[ \t]*" (regexp-quote ll
)))
2892 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
2894 (if (and (not spanning
)
2895 (not org-export-prefer-native-exporter-for-tables
))
2896 ;; We can use my own converter with HTML conversions
2897 (org-format-table-table-html lines
)
2898 ;; Need to use the code generator in table.el, with the original text.
2899 (org-format-table-table-html-using-table-generate-source olines
)))))
2901 (defvar org-table-number-fraction
) ; defined in org-table.el
2902 (defun org-format-org-table-html (lines &optional splice
)
2903 "Format a table into HTML."
2904 (require 'org-table
)
2905 ;; Get rid of hlines at beginning and end
2906 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2907 (setq lines
(nreverse lines
))
2908 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2909 (setq lines
(nreverse lines
))
2910 (when org-export-table-remove-special-lines
2911 ;; Check if the table has a marking column. If yes remove the
2912 ;; column and the special lines
2913 (setq lines
(org-table-clean-before-export lines
)))
2915 (let ((head (and org-export-highlight-first-table-line
2917 (lambda (x) (string-match "^[ \t]*|-" x
))
2920 tbopen line fields html gr colgropen
)
2921 (if splice
(setq head nil
))
2922 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
2924 (while (setq line
(pop lines
))
2926 (if (string-match "^[ \t]*|-" line
)
2929 (push (if head
"</thead>" "</tbody>") html
)
2930 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
2931 (setq head nil
) ;; head ends here, first time around
2933 (throw 'next-line t
)))
2934 ;; Break the line into fields
2935 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2936 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
2937 (setq nlines
(1+ nlines
) i -
1)
2938 (push (concat "<tr>"
2942 (if (and (< i nlines
)
2943 (string-match org-table-number-regexp x
))
2944 (incf (aref fnum i
)))
2946 (concat (car org-export-table-header-tags
) x
2947 (cdr org-export-table-header-tags
))
2948 (concat (car org-export-table-data-tags
) x
2949 (cdr org-export-table-data-tags
))))
2953 (unless splice
(if tbopen
(push "</tbody>" html
)))
2954 (unless splice
(push "</table>\n" html
))
2955 (setq html
(nreverse html
))
2957 ;; Put in col tags with the alignment (unfortuntely often ignored...)
2960 (setq gr
(pop org-table-colgroup-info
))
2961 (format "%s<col align=\"%s\"></col>%s"
2962 (if (memq gr
'(:start
:startend
))
2964 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
2967 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
2969 (if (memq gr
'(:end
:startend
))
2970 (progn (setq colgropen nil
) "</colgroup>")
2974 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
2975 (push html-table-tag html
))
2976 (concat (mapconcat 'identity html
"\n") "\n")))
2978 (defun org-table-clean-before-export (lines)
2979 "Check if the table has a marking column.
2980 If yes remove the column and the special lines."
2981 (setq org-table-colgroup-info nil
)
2984 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2985 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
2988 (setq org-table-clean-did-remove-column nil
)
2993 ((string-match "^[ \t]*| */ *|" x
)
2994 (setq org-table-colgroup-info
2996 (cond ((member x
'("<" "<")) :start
)
2997 ((member x
'(">" ">")) :end
)
2998 ((member x
'("<>" "<>")) :startend
)
3000 (org-split-string x
"[ \t]*|[ \t]*")))
3004 (setq org-table-clean-did-remove-column t
)
3009 ((string-match "^[ \t]*| */ *|" x
)
3010 (setq org-table-colgroup-info
3012 (cond ((member x
'("<" "<")) :start
)
3013 ((member x
'(">" ">")) :end
)
3014 ((member x
'("<>" "<>")) :startend
)
3016 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3018 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3019 nil
) ; ignore this line
3020 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3021 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3022 ;; remove the first column
3023 (replace-match "\\1|" t nil x
))))
3026 (defun org-format-table-table-html (lines)
3027 "Format a table generated by table.el into HTML.
3028 This conversion does *not* use `table-generate-source' from table.el.
3029 This has the advantage that Org-mode's HTML conversions can be used.
3030 But it has the disadvantage, that no cell- or row-spanning is allowed."
3031 (let (line field-buffer
3032 (head org-export-highlight-first-table-line
)
3034 (setq html
(concat html-table-tag
"\n"))
3035 (while (setq line
(pop lines
))
3036 (setq empty
" ")
3038 (if (string-match "^[ \t]*\\+-" line
)
3049 (if (equal x
"") (setq x empty
))
3051 (concat (car org-export-table-header-tags
) x
3052 (cdr org-export-table-header-tags
))
3053 (concat (car org-export-table-data-tags
) x
3054 (cdr org-export-table-data-tags
))))
3058 (setq field-buffer nil
)))
3060 (throw 'next-line t
)))
3061 ;; Break the line into fields and store the fields
3062 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3064 (setq field-buffer
(mapcar
3066 (concat x
"<br/>" (pop fields
)))
3068 (setq field-buffer fields
))))
3069 (setq html
(concat html
"</table>\n"))
3072 (defun org-format-table-table-html-using-table-generate-source (lines)
3073 "Format a table into html, using `table-generate-source' from table.el.
3074 This has the advantage that cell- or row-spanning is allowed.
3075 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3077 (with-current-buffer (get-buffer-create " org-tmp1 ")
3079 (insert (mapconcat 'identity lines
"\n"))
3080 (goto-char (point-min))
3081 (if (not (re-search-forward "|[^+]" nil t
))
3082 (error "Error processing table"))
3083 (table-recognize-table)
3084 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3085 (table-generate-source 'html
" org-tmp2 ")
3086 (set-buffer " org-tmp2 ")
3087 (buffer-substring (point-min) (point-max))))
3089 (defun org-html-handle-time-stamps (s)
3090 "Format time stamps in string S, or remove them."
3093 (while (string-match org-maybe-keyword-time-regexp s
)
3094 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3095 ;; never export CLOCK
3097 (or b
(setq b
(substring s
0 (match-beginning 0))))
3098 (if (not org-export-with-timestamps
)
3099 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3100 s
(substring s
(match-end 0)))
3102 r
(substring s
0 (match-beginning 0))
3104 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3105 (match-string 1 s
)))
3106 (format " @<span class=\"timestamp\">%s@</span>"
3108 (org-translate-time (match-string 3 s
)) 1 -
1)))
3109 s
(substring s
(match-end 0)))))
3110 ;; Line break if line started and ended with time stamp stuff
3113 (setq r
(concat r s
))
3114 (unless (string-match "\\S-" (concat b s
))
3115 (setq r
(concat r
"@<br/>")))
3118 (defun org-html-protect (s)
3119 ;; convert & to &, < to < and > to >
3121 (while (string-match "&" s start
)
3122 (setq s
(replace-match "&" t t s
)
3123 start
(1+ (match-beginning 0))))
3124 (while (string-match "<" s
)
3125 (setq s
(replace-match "<" t t s
)))
3126 (while (string-match ">" s
)
3127 (setq s
(replace-match ">" t t s
))))
3130 (defun org-export-cleanup-toc-line (s)
3131 "Remove tags and time staps from lines going into the toc."
3132 (when (memq org-export-with-tags
'(not-in-toc nil
))
3133 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3134 (setq s
(replace-match "" t t s
))))
3135 (when org-export-remove-timestamps-from-toc
3136 (while (string-match org-maybe-keyword-time-regexp s
)
3137 (setq s
(replace-match "" t t s
))))
3138 (while (string-match org-bracket-link-regexp s
)
3139 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3143 (defun org-html-expand (string)
3144 "Prepare STRING for HTML export. Applies all active conversions.
3145 If there are links in the string, don't modify these."
3146 (let* ((re (concat org-bracket-link-regexp
"\\|"
3147 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3149 (while (setq m
(string-match re string
))
3150 (setq s
(substring string
0 m
)
3151 l
(match-string 0 string
)
3152 string
(substring string
(match-end 0)))
3153 (push (org-html-do-expand s
) res
)
3155 (push (org-html-do-expand string
) res
)
3156 (apply 'concat
(nreverse res
))))
3158 (defun org-html-do-expand (s)
3159 "Apply all active conversions to translate special ASCII to HTML."
3160 (setq s
(org-html-protect s
))
3161 (if org-export-html-expand
3163 (while (string-match "@<\\([^&]*\\)>" s
)
3164 (setq s
(replace-match "<\\1>" t nil s
)))))
3165 (if org-export-with-emphasize
3166 (setq s
(org-export-html-convert-emphasize s
)))
3167 (if org-export-with-special-strings
3168 (setq s
(org-export-html-convert-special-strings s
)))
3169 (if org-export-with-sub-superscripts
3170 (setq s
(org-export-html-convert-sub-super s
)))
3171 (if org-export-with-TeX-macros
3172 (let ((start 0) wd ass
)
3173 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3174 (if (get-text-property (match-beginning 0) 'org-protected s
)
3175 (setq start
(match-end 0))
3176 (setq wd
(match-string 1 s
))
3177 (if (setq ass
(assoc wd org-html-entities
))
3178 (setq s
(replace-match (or (cdr ass
)
3179 (concat "&" (car ass
) ";"))
3181 (setq start
(+ start
(length wd
))))))))
3184 (defun org-create-multibrace-regexp (left right n
)
3185 "Create a regular expression which will match a balanced sexp.
3186 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3187 as single character strings.
3188 The regexp returned will match the entire expression including the
3189 delimiters. It will also define a single group which contains the
3190 match except for the outermost delimiters. The maximum depth of
3191 stacked delimiters is N. Escaping delimiters is not possible."
3192 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3195 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3198 re
(concat re or next
)
3199 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3200 (concat left
"\\(" re
"\\)" right
)))
3202 (defvar org-match-substring-regexp
3204 "\\([^\\]\\)\\([_^]\\)\\("
3205 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3207 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3209 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3210 "The regular expression matching a sub- or superscript.")
3212 (defvar org-match-substring-with-braces-regexp
3214 "\\([^\\]\\)\\([_^]\\)\\("
3215 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3217 "The regular expression matching a sub- or superscript, forcing braces.")
3219 (defconst org-export-html-special-string-regexps
3220 '(("\\\\-" .
"­")
3221 ("---\\([^-]\\)" .
"—\\1")
3222 ("--\\([^-]\\)" .
"–\\1")
3223 ("\\.\\.\\." .
"…"))
3224 "Regular expressions for special string conversion.")
3226 (defun org-export-html-convert-special-strings (string)
3227 "Convert special characters in STRING to HTML."
3228 (let ((all org-export-html-special-string-regexps
)
3230 (while (setq a
(pop all
))
3231 (setq re
(car a
) rpl
(cdr a
) start
0)
3232 (while (string-match re string start
)
3233 (if (get-text-property (match-beginning 0) 'org-protected string
)
3234 (setq start
(match-end 0))
3235 (setq string
(replace-match rpl t nil string
)))))
3238 (defun org-export-html-convert-sub-super (string)
3239 "Convert sub- and superscripts in STRING to HTML."
3240 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3241 (while (string-match org-match-substring-regexp string s
)
3243 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3244 ((get-text-property (match-beginning 2) 'org-protected string
)
3245 (setq s
(match-end 2)))
3247 (setq s
(match-end 1)
3248 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3249 c
(or (match-string 8 string
)
3250 (match-string 6 string
)
3251 (match-string 5 string
))
3252 string
(replace-match
3253 (concat (match-string 1 string
)
3254 "<" key
">" c
"</" key
">")
3256 (while (string-match "\\\\\\([_^]\\)" string
)
3257 (setq string
(replace-match (match-string 1 string
) t t string
)))
3260 (defun org-export-html-convert-emphasize (string)
3263 (while (string-match org-emph-re string s
)
3265 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3266 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3267 (setq s
(match-beginning 0)
3270 (match-string 1 string
)
3271 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3272 (match-string 4 string
)
3273 (nth 3 (assoc (match-string 3 string
)
3274 org-emphasis-alist
))
3275 (match-string 5 string
))
3276 string
(replace-match rpl t t string
)
3277 s
(+ s
(- (length rpl
) 2)))
3281 (defvar org-par-open nil
)
3282 (defun org-open-par ()
3283 "Insert <p>, but first close previous paragraph if any."
3284 (org-close-par-maybe)
3286 (setq org-par-open t
))
3287 (defun org-close-par-maybe ()
3288 "Close paragraph if there is one open."
3291 (setq org-par-open nil
)))
3292 (defun org-close-li ()
3293 "Close <li> if necessary."
3294 (org-close-par-maybe)
3297 (defvar body-only
) ; dynamically scoped into this.
3298 (defun org-html-level-start (level title umax with-toc head-count
)
3299 "Insert a new level in HTML export.
3300 When TITLE is nil, just close all open levels."
3301 (org-close-par-maybe)
3302 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3306 (if (aref org-levels-open
(1- l
))
3308 (org-html-level-close l umax
)
3309 (aset org-levels-open
(1- l
) nil
)))
3312 ;; If title is nil, this means this function is called to close
3313 ;; all levels, so the rest is done only if title is given
3314 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3315 (setq title
(replace-match
3316 (if org-export-with-tags
3319 " <span class=\"tag\">"
3320 (mapconcat 'identity
(org-split-string
3321 (match-string 1 title
) ":")
3328 (if (aref org-levels-open
(1- level
))
3332 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3333 (insert "<li>" title
"<br/>\n")))
3334 (aset org-levels-open
(1- level
) t
)
3335 (org-close-par-maybe)
3337 (insert (format "<ul>\n<li id=\"%s\">" target
)
3339 (insert "<ul>\n<li>" title
"<br/>\n"))))
3340 (aset org-levels-open
(1- level
) t
)
3341 (setq snumber
(org-section-number level
))
3342 (if (and org-export-with-section-numbers
(not body-only
))
3343 (setq title
(concat snumber
" " title
)))
3344 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3345 (unless (= head-count
1) (insert "\n</div>\n"))
3346 (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"
3347 snumber level level snumber title level snumber
))
3350 (defun org-get-text-property-any (pos prop
&optional object
)
3351 (or (get-text-property pos prop object
)
3352 (and (setq pos
(next-single-property-change pos prop object
))
3353 (get-text-property pos prop object
))))
3355 (defun org-html-level-close (level max-outline-level
)
3356 "Terminate one level in HTML export."
3357 (if (<= level max-outline-level
)
3360 (insert "</ul>\n")))
3362 ;;; iCalendar export
3365 (defun org-export-icalendar-this-file ()
3366 "Export current file as an iCalendar file.
3367 The iCalendar file will be located in the same directory as the Org-mode
3368 file, but with extension `.ics'."
3370 (org-export-icalendar nil buffer-file-name
))
3373 (defun org-export-icalendar-all-agenda-files ()
3374 "Export all files in `org-agenda-files' to iCalendar .ics files.
3375 Each iCalendar file will be located in the same directory as the Org-mode
3376 file, but with extension `.ics'."
3378 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3381 (defun org-export-icalendar-combine-agenda-files ()
3382 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3383 The file is stored under the name `org-combined-agenda-icalendar-file'."
3385 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3387 (defun org-export-icalendar (combine &rest files
)
3388 "Create iCalendar files for all elements of FILES.
3389 If COMBINE is non-nil, combine all calendar entries into a single large
3390 file and store it under the name `org-combined-agenda-icalendar-file'."
3392 (org-prepare-agenda-buffers files
)
3393 (let* ((dir (org-export-directory
3394 :ical
(list :publishing-directory
3395 org-export-publishing-directory
)))
3396 file ical-file ical-buffer category started org-agenda-new-buffers
)
3397 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3400 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3401 org-combined-agenda-icalendar-file
3402 (expand-file-name org-combined-agenda-icalendar-file dir
))
3403 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3404 (set-buffer ical-buffer
) (erase-buffer))
3405 (while (setq file
(pop files
))
3407 (org-check-agenda-file file
)
3408 (set-buffer (org-get-agenda-file-buffer file
))
3410 (setq ical-file
(concat (file-name-as-directory dir
)
3411 (file-name-sans-extension
3412 (file-name-nondirectory buffer-file-name
))
3414 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3415 (with-current-buffer ical-buffer
(erase-buffer)))
3416 (setq category
(or org-category
3417 (file-name-sans-extension
3418 (file-name-nondirectory buffer-file-name
))))
3419 (if (symbolp category
) (setq category
(symbol-name category
)))
3420 (let ((standard-output ical-buffer
))
3422 (and (not started
) (setq started t
)
3423 (org-start-icalendar-file org-icalendar-combined-name
))
3424 (org-start-icalendar-file category
))
3425 (org-print-icalendar-entries combine
)
3426 (when (or (and combine
(not files
)) (not combine
))
3427 (org-finish-icalendar-file)
3428 (set-buffer ical-buffer
)
3430 (run-hooks 'org-after-save-iCalendar-file-hook
)
3431 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3433 (org-release-buffers org-agenda-new-buffers
))))
3435 (defvar org-after-save-iCalendar-file-hook nil
3436 "Hook run after an iCalendar file has been saved.
3437 The iCalendar buffer is still current when this hook is run.
3438 A good way to use this is to tell a desktop calenndar application to re-read
3439 the iCalendar file.")
3441 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3442 (defun org-print-icalendar-entries (&optional combine
)
3443 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3444 When COMBINE is non nil, add the category to each line."
3445 (require 'org-agenda
)
3446 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3447 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3448 (dts (org-ical-ts-to-string
3449 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3451 hd ts ts2 state status
(inc t
) pos b sexp rrule
3452 scheduledp deadlinep tmp pri category entry location summary desc
3453 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3454 (org-refresh-category-properties)
3456 (goto-char (point-min))
3457 (while (re-search-forward re1 nil t
)
3460 (when (boundp 'org-icalendar-verify-function
)
3461 (unless (funcall org-icalendar-verify-function
)
3462 (outline-next-heading)
3465 (setq pos
(match-beginning 0)
3468 hd
(condition-case nil
(org-get-heading)
3469 (error (throw :skip nil
)))
3470 summary
(org-icalendar-cleanup-string
3471 (org-entry-get nil
"SUMMARY"))
3472 desc
(org-icalendar-cleanup-string
3473 (or (org-entry-get nil
"DESCRIPTION")
3474 (and org-icalendar-include-body
(org-get-entry)))
3475 t org-icalendar-include-body
)
3476 location
(org-icalendar-cleanup-string
3477 (org-entry-get nil
"LOCATION"))
3478 category
(org-get-category))
3479 (if (looking-at re2
)
3481 (goto-char (match-end 0))
3482 (setq ts2
(match-string 1) inc nil
))
3483 (setq tmp
(buffer-substring (max (point-min)
3484 (- pos org-ds-keyword-length
))
3486 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3489 (replace-match "\\1" t nil ts
))
3491 deadlinep
(string-match org-deadline-regexp tmp
)
3492 scheduledp
(string-match org-scheduled-regexp tmp
)
3493 ;; donep (org-entry-is-done-p)
3495 (if (or (string-match org-tr-regexp hd
)
3496 (string-match org-ts-regexp hd
))
3497 (setq hd
(replace-match "" t t hd
)))
3498 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3500 (concat "\nRRULE:FREQ="
3503 '(("d" .
"DAILY")("w" .
"WEEKLY")
3504 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3505 ";INTERVAL=" (match-string 1 ts
)))
3507 (setq summary
(or summary hd
))
3508 (if (string-match org-bracket-link-regexp summary
)
3510 (replace-match (if (match-end 3)
3511 (match-string 3 summary
)
3512 (match-string 1 summary
))
3514 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3515 (if scheduledp
(setq summary
(concat "S: " summary
)))
3516 (if (string-match "\\`<%%" ts
)
3517 (with-current-buffer sexp-buffer
3518 (insert (substring ts
1 -
1) " " summary
"\n"))
3519 (princ (format "BEGIN:VEVENT
3525 (org-ical-ts-to-string ts
"DTSTART")
3526 (org-ical-ts-to-string ts2
"DTEND" inc
)
3528 (if (and desc
(string-match "\\S-" desc
))
3529 (concat "\nDESCRIPTION: " desc
) "")
3530 (if (and location
(string-match "\\S-" location
))
3531 (concat "\nLOCATION: " location
) "")
3534 (when (and org-icalendar-include-sexps
3535 (condition-case nil
(require 'icalendar
) (error nil
))
3536 (fboundp 'icalendar-export-region
))
3537 ;; Get all the literal sexps
3538 (goto-char (point-min))
3539 (while (re-search-forward "^&?%%(" nil t
)
3542 (setq b
(match-beginning 0))
3543 (goto-char (1- (match-end 0)))
3546 (setq sexp
(buffer-substring b
(point)))
3547 (with-current-buffer sexp-buffer
3549 (princ (org-diary-to-ical-string sexp-buffer
)))))
3551 (when org-icalendar-include-todo
3552 (goto-char (point-min))
3553 (while (re-search-forward org-todo-line-regexp nil t
)
3556 (when (boundp 'org-icalendar-verify-function
)
3557 (unless (funcall org-icalendar-verify-function
)
3558 (outline-next-heading)
3561 (setq state
(match-string 2))
3562 (setq status
(if (member state org-done-keywords
)
3563 "COMPLETED" "NEEDS-ACTION"))
3565 (or (not (member state org-done-keywords
))
3566 (eq org-icalendar-include-todo
'all
))
3567 (not (member org-archive-tag
(org-get-tags-at)))
3569 (setq hd
(match-string 3)
3570 summary
(org-icalendar-cleanup-string
3571 (org-entry-get nil
"SUMMARY"))
3572 desc
(org-icalendar-cleanup-string
3573 (or (org-entry-get nil
"DESCRIPTION")
3574 (and org-icalendar-include-body
(org-get-entry)))
3575 t org-icalendar-include-body
)
3576 location
(org-icalendar-cleanup-string
3577 (org-entry-get nil
"LOCATION")))
3578 (if (string-match org-bracket-link-regexp hd
)
3579 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3580 (match-string 1 hd
))
3582 (if (string-match org-priority-regexp hd
)
3583 (setq pri
(string-to-char (match-string 2 hd
))
3584 hd
(concat (substring hd
0 (match-beginning 1))
3585 (substring hd
(match-end 1))))
3586 (setq pri org-default-priority
))
3587 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3588 (- org-lowest-priority org-highest-priority
))))))
3590 (princ (format "BEGIN:VTODO
3600 (if (and location
(string-match "\\S-" location
))
3601 (concat "\nLOCATION: " location
) "")
3602 (if (and desc
(string-match "\\S-" desc
))
3603 (concat "\nDESCRIPTION: " desc
) "")
3604 category pri status
)))))))))
3606 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3607 "Take out stuff and quote what needs to be quoted.
3608 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3609 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3614 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3615 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3616 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3617 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3619 (while (string-match "\\([,;\\]\\)" s start
)
3620 (setq start
(+ (match-beginning 0) 2)
3621 s
(replace-match "\\\\\\1" nil nil s
))))
3623 (while (string-match "[ \t]*\n[ \t]*" s
)
3624 (setq s
(replace-match "\\n" t t s
))))
3625 (setq s
(org-trim s
))
3628 (if (and (numberp maxlength
)
3629 (> (length s
) maxlength
))
3630 (setq s
(substring s
0 maxlength
)))))
3633 (defun org-get-entry ()
3634 "Clean-up description string."
3636 (org-back-to-heading t
)
3637 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3639 (defun org-start-icalendar-file (name)
3640 "Start an iCalendar file by inserting the header."
3641 (let ((user user-full-name
)
3642 (name (or name
"unknown"))
3643 (timezone (cadr (current-time-zone))))
3645 (format "BEGIN:VCALENDAR
3648 PRODID:-//%s//Emacs with Org-mode//EN
3650 CALSCALE:GREGORIAN\n" name user timezone
))))
3652 (defun org-finish-icalendar-file ()
3653 "Finish an iCalendar file by inserting the END statement."
3654 (princ "END:VCALENDAR\n"))
3656 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3657 "Take a time string S and convert it to iCalendar format.
3658 KEYWORD is added in front, to make a complete line like DTSTART....
3659 When INC is non-nil, increase the hour by two (if time string contains
3660 a time), or the day by one (if it does not contain a time)."
3661 (let ((t1 (org-parse-time-string s
'nodefault
))
3662 t2 fmt have-time time
)
3663 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3664 (setq t2 t1 have-time t
)
3665 (setq t2
(org-parse-time-string s
)))
3666 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3667 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3670 (if org-agenda-default-appointment-duration
3671 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3674 (setq time
(encode-time s mi h d m y
)))
3675 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3676 (concat keyword
(format-time-string fmt time
))))
3680 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3681 (with-current-buffer buffer
3682 (apply 'insert output
)))
3683 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3686 (defun org-export-as-xoxo (&optional buffer
)
3687 "Export the org buffer as XOXO.
3688 The XOXO buffer is named *xoxo-<source buffer name>*"
3689 (interactive (list (current-buffer)))
3690 ;; A quickie abstraction
3692 ;; Output everything as XOXO
3693 (with-current-buffer (get-buffer buffer
)
3694 (let* ((pos (point))
3695 (opt-plist (org-combine-plists (org-default-export-plist)
3696 (org-infile-export-plist)))
3697 (filename (concat (file-name-as-directory
3698 (org-export-directory :xoxo opt-plist
))
3699 (file-name-sans-extension
3700 (file-name-nondirectory buffer-file-name
))
3702 (out (find-file-noselect filename
))
3705 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3706 ;; Check the output buffer is empty.
3707 (with-current-buffer out
(erase-buffer))
3708 ;; Kick off the output
3709 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3710 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3711 (let* ((hd (match-string-no-properties 1))
3714 (match-string-no-properties 2)
3716 (goto-char (match-end 0))
3721 (if (looking-at "^[ \t]\\(.*\\)")
3722 (setq str
(concat str
(match-string-no-properties 1)))
3723 (throw 'loop str
)))))))))
3725 ;; Handle level rendering
3727 ((> level last-level
)
3728 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3730 ((< level last-level
)
3731 (dotimes (- (- last-level level
) 1)
3733 (org-export-as-xoxo-insert-into out
"</li>\n"))
3734 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3736 (org-export-as-xoxo-insert-into out
"</li>\n")
3737 (setq hanging-li nil
)))
3739 ((equal level last-level
)
3741 (org-export-as-xoxo-insert-into out
"</li>\n")))
3744 (setq last-level level
)
3746 ;; And output the new li
3747 (setq hanging-li
't
)
3748 (if (equal ?
+ (elt text
0))
3749 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3750 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3752 ;; Finally finish off the ol
3753 (dotimes (- last-level
1)
3755 (org-export-as-xoxo-insert-into out
"</li>\n"))
3756 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3759 ;; Finish the buffer off and clean it up.
3760 (switch-to-buffer-other-window out
)
3761 (indent-region (point-min) (point-max) nil
)
3763 (goto-char (point-min))
3768 ;;; org-exp.el ends here
3771 (defun org-export-process-option-filters (plist)
3772 (let ((functions org-export-options-filters
) f
)
3773 (while (setq f
(pop functions
))
3774 (setq plist
(funcall f plist
))))