1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (defvar htmlize-buffer-places
) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
68 (defcustom org-export-select-tags
'("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-exclude-tags'."
74 :group
'org-export-general
75 :type
'(repeat (string :tag
"Tag")))
77 (defcustom org-export-exclude-tags
'("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without contition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group
'org-export-general
83 :type
'(repeat (string :tag
"Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
90 -----+----------+--------
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group
'org-export-translation
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents")
102 ("cs" "Autor" "Datum" "Obsah")
103 ("da" "Ophavsmand" "Dato" "Indhold")
104 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
105 ("es" "Autor" "Fecha" "\xcdndice")
106 ("fr" "Auteur" "Date" "Table des mati\xe8res")
107 ("it" "Autore" "Data" "Indice")
108 ("nl" "Auteur" "Datum" "Inhoudsopgave")
109 ("no" "Forfatter" "Dato" "Innhold")
110 ("nb" "Forfatter" "Dato" "Innhold") ;; nb = Norsk (bokm.l)
111 ("nn" "Forfattar" "Dato" "Innhald") ;; nn = Norsk (nynorsk)
112 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
113 "Terms used in export text, translated to different languages.
114 Use the variable `org-export-default-language' to set the language,
115 or use the +OPTION lines for a per-file setting."
116 :group
'org-export-general
119 (string :tag
"HTML language tag")
120 (string :tag
"Author")
122 (string :tag
"Table of Contents"))))
124 (defcustom org-export-default-language
"en"
125 "The default language of HTML export, as a string.
126 This should have an association in `org-export-language-setup'."
127 :group
'org-export-general
130 (defcustom org-export-skip-text-before-1st-heading nil
131 "Non-nil means, skip all text before the first headline when exporting.
132 When nil, that text is exported as well."
133 :group
'org-export-general
136 (defcustom org-export-headline-levels
3
137 "The last level which is still exported as a headline.
138 Inferior levels will produce itemize lists when exported.
139 Note that a numeric prefix argument to an exporter function overrides
142 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
143 :group
'org-export-general
146 (defcustom org-export-with-section-numbers t
147 "Non-nil means, add section numbers to headlines when exporting.
149 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
150 :group
'org-export-general
153 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
154 "Format of section numbers for export.
155 The variable has two components.
156 1. A list of lists, each indicating a counter type and a separator.
157 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
158 It causes causes numeric, alphabetic, or roman counters, respectively.
159 The separator is only used if another counter for a subsection is being
161 If there are more numbered section levels than entries in this lists,
162 then the last entry will be reused.
163 2. A terminator string that will be added after the entire
165 :group
'org-export-general
169 (string :tag
"Counter Type")
170 (string :tag
"Separator ")))
171 (string :tag
"Terminator")))
173 (defcustom org-export-with-toc t
174 "Non-nil means, create a table of contents in exported files.
175 The TOC contains headlines with levels up to`org-export-headline-levels'.
176 When an integer, include levels up to N in the toc, this may then be
177 different from `org-export-headline-levels', but it will not be allowed
178 to be larger than the number of headline levels.
179 When nil, no table of contents is made.
181 Headlines which contain any TODO items will be marked with \"(*)\" in
182 ASCII export, and with red color in HTML output, if the option
183 `org-export-mark-todo-in-toc' is set.
185 In HTML output, the TOC will be clickable.
187 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
189 :group
'org-export-general
191 (const :tag
"No Table of Contents" nil
)
192 (const :tag
"Full Table of Contents" t
)
193 (integer :tag
"TOC to level")))
195 (defcustom org-export-mark-todo-in-toc nil
196 "Non-nil means, mark TOC lines that contain any open TODO items."
197 :group
'org-export-general
200 (defcustom org-export-preserve-breaks nil
201 "Non-nil means, preserve all line breaks when exporting.
202 Normally, in HTML output paragraphs will be reformatted. In ASCII
203 export, line breaks will always be preserved, regardless of this variable.
205 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
206 :group
'org-export-general
209 (defcustom org-export-with-archived-trees
'headline
210 "Whether subtrees with the ARCHIVE tag should be exported.
211 This can have three different values
212 nil Do not export, pretend this tree is not present
213 t Do export the entire tree
214 headline Only export the headline, but skip the tree below it."
215 :group
'org-export-general
218 (const :tag
"not at all" nil
)
219 (const :tag
"headline only" 'headline
)
220 (const :tag
"entirely" t
)))
222 (defcustom org-export-author-info t
223 "Non-nil means, insert author name and email into the exported file.
225 This option can also be set with the +OPTIONS line,
226 e.g. \"author-info:nil\"."
227 :group
'org-export-general
230 (defcustom org-export-creator-info t
231 "Non-nil means, the postamle should contain a creator sentence.
232 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
233 :group
'org-export-general
236 (defcustom org-export-time-stamp-file t
237 "Non-nil means, insert a time stamp into the exported file.
238 The time stamp shows when the file was created.
240 This option can also be set with the +OPTIONS line,
241 e.g. \"timestamp:nil\"."
242 :group
'org-export-general
245 (defcustom org-export-with-timestamps t
246 "If nil, do not export time stamps and associated keywords."
247 :group
'org-export-general
250 (defcustom org-export-remove-timestamps-from-toc t
251 "If nil, remove timestamps from the table of contents entries."
252 :group
'org-export-general
255 (defcustom org-export-with-tags
'not-in-toc
256 "If nil, do not export tags, just remove them from headlines.
257 If this is the symbol `not-in-toc', tags will be removed from table of
258 contents entries, but still be shown in the headlines of the document.
260 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
261 :group
'org-export-general
263 (const :tag
"Off" nil
)
264 (const :tag
"Not in TOC" not-in-toc
)
265 (const :tag
"On" t
)))
267 (defcustom org-export-with-drawers nil
268 "Non-nil means, export with drawers like the property drawer.
269 When t, all drawers are exported. This may also be a list of
270 drawer names to export."
271 :group
'org-export-general
273 (const :tag
"All drawers" t
)
274 (const :tag
"None" nil
)
275 (repeat :tag
"Selected drawers"
276 (string :tag
"Drawer name"))))
278 (defvar org-export-preprocess-hook nil
279 "Hook for preprocessing an export buffer.
280 Pretty much the first thing when exporting is running this hook.")
282 (defgroup org-export-translation nil
283 "Options for translating special ascii sequences for the export backends."
284 :tag
"Org Export Translation"
287 (defcustom org-export-with-emphasize t
288 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
289 If the export target supports emphasizing text, the word will be
290 typeset in bold, italic, or underlined, respectively. Works only for
291 single words, but you can say: I *really* *mean* *this*.
292 Not all export backends support this.
294 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
295 :group
'org-export-translation
298 (defcustom org-export-with-footnotes t
299 "If nil, export [1] as a footnote marker.
300 Lines starting with [1] will be formatted as footnotes.
302 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
303 :group
'org-export-translation
306 (defcustom org-export-with-sub-superscripts t
307 "Non-nil means, interpret \"_\" and \"^\" for export.
308 When this option is turned on, you can use TeX-like syntax for sub- and
309 superscripts. Several characters after \"_\" or \"^\" will be
310 considered as a single item - so grouping with {} is normally not
311 needed. For example, the following things will be parsed as single
312 sub- or superscripts.
314 10^24 or 10^tau several digits will be considered 1 item.
315 10^-12 or 10^-tau a leading sign with digits or a word
316 x^2-y^3 will be read as x^2 - y^3, because items are
317 terminated by almost any nonword/nondigit char.
318 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
320 Still, ambiguity is possible - so when in doubt use {} to enclose the
321 sub/superscript. If you set this variable to the symbol `{}',
322 the braces are *required* in order to trigger interpretations as
323 sub/superscript. This can be helpful in documents that need \"_\"
324 frequently in plain text.
326 Not all export backends support this, but HTML does.
328 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
329 :group
'org-export-translation
331 (const :tag
"Always interpret" t
)
332 (const :tag
"Only with braces" {})
333 (const :tag
"Never interpret" nil
)))
335 (defcustom org-export-with-special-strings t
336 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
337 When this option is turned on, these strings will be exported as:
343 Not all export backends support this, but HTML does.
345 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
346 :group
'org-export-translation
349 (defcustom org-export-with-TeX-macros t
350 "Non-nil means, interpret simple TeX-like macros when exporting.
351 For example, HTML export converts \\alpha to α and \\AA to Å.
352 No only real TeX macros will work here, but the standard HTML entities
353 for math can be used as macro names as well. For a list of supported
354 names in HTML export, see the constant `org-html-entities'.
355 Not all export backends support this.
357 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
358 :group
'org-export-translation
359 :group
'org-export-latex
362 (defcustom org-export-with-LaTeX-fragments nil
363 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
364 When set, the exporter will find LaTeX environments if the \\begin line is
365 the first non-white thing on a line. It will also find the math delimiters
366 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
369 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
370 :group
'org-export-translation
371 :group
'org-export-latex
374 (defcustom org-export-with-fixed-width t
375 "Non-nil means, lines starting with \":\" will be in fixed width font.
376 This can be used to have pre-formatted text, fragments of code etc. For
378 : ;; Some Lisp examples
381 will be looking just like this in also HTML. See also the QUOTE keyword.
382 Not all export backends support this.
384 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
385 :group
'org-export-translation
388 (defcustom org-match-sexp-depth
3
389 "Number of stacked braces for sub/superscript matching.
390 This has to be set before loading org.el to be effective."
391 :group
'org-export-translation
394 (defgroup org-export-tables nil
395 "Options for exporting tables in Org-mode."
396 :tag
"Org Export Tables"
399 (defcustom org-export-with-tables t
400 "If non-nil, lines starting with \"|\" define a table.
403 | Name | Address | Birthday |
404 |-------------+----------+-----------|
405 | Arthur Dent | England | 29.2.2100 |
407 Not all export backends support this.
409 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
410 :group
'org-export-tables
413 (defcustom org-export-highlight-first-table-line t
414 "Non-nil means, highlight the first table line.
415 In HTML export, this means use <th> instead of <td>.
416 In tables created with table.el, this applies to the first table line.
417 In Org-mode tables, all lines before the first horizontal separator
418 line will be formatted with <th> tags."
419 :group
'org-export-tables
422 (defcustom org-export-table-remove-special-lines t
423 "Remove special lines and marking characters in calculating tables.
424 This removes the special marking character column from tables that are set
425 up for spreadsheet calculations. It also removes the entire lines
426 marked with `!', `_', or `^'. The lines with `$' are kept, because
427 the values of constants may be useful to have."
428 :group
'org-export-tables
431 (defcustom org-export-prefer-native-exporter-for-tables nil
432 "Non-nil means, always export tables created with table.el natively.
433 Natively means, use the HTML code generator in table.el.
434 When nil, Org-mode's own HTML generator is used when possible (i.e. if
435 the table does not use row- or column-spanning). This has the
436 advantage, that the automatic HTML conversions for math symbols and
437 sub/superscripts can be applied. Org-mode's HTML generator is also
439 :group
'org-export-tables
442 (defgroup org-export-ascii nil
443 "Options specific for ASCII export of Org-mode files."
444 :tag
"Org Export ASCII"
447 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
448 "Characters for underlining headings in ASCII export.
449 In the given sequence, these characters will be used for level 1, 2, ..."
450 :group
'org-export-ascii
451 :type
'(repeat character
))
453 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
454 "Bullet characters for headlines converted to lists in ASCII export.
455 The first character is used for the first lest level generated in this
456 way, and so on. If there are more levels than characters given here,
457 the list will be repeated.
458 Note that plain lists will keep the same bullets as the have in the
460 :group
'org-export-ascii
461 :type
'(repeat character
))
463 (defgroup org-export-xml nil
464 "Options specific for XML export of Org-mode files."
465 :tag
"Org Export XML"
468 (defgroup org-export-html nil
469 "Options specific for HTML export of Org-mode files."
470 :tag
"Org Export HTML"
473 (defcustom org-export-html-coding-system nil
474 "Coding system for HTML export, defaults to buffer-file-coding-system."
475 :group
'org-export-html
476 :type
'coding-system
)
478 (defcustom org-export-html-extension
"html"
479 "The extension for exported HTML files."
480 :group
'org-export-html
483 (defcustom org-export-html-link-up
""
484 "Where should the \"UP\" link of exported HTML pages lead?"
485 :group
'org-export-html
486 :type
'(string :tag
"File or URL"))
488 (defcustom org-export-html-link-home
""
489 "Where should the \"HOME\" link of exported HTML pages lead?"
490 :group
'org-export-html
491 :type
'(string :tag
"File or URL"))
493 (defconst org-export-html-style-default
494 "<style type=\"text/css\">
495 html { font-family: Times, serif; font-size: 12pt; }
496 .title { text-align: center; }
497 .todo { color: red; }
498 .done { color: green; }
499 .tag { background-color:lightblue; font-weight:normal }
501 .timestamp { color: grey }
502 .timestamp-kwd { color: CadetBlue }
503 p.verse { margin-left: 3% }
505 border: 1pt solid #AEBDCC;
506 background-color: #F3F5F7;
508 font-family: courier, monospace;
512 table { border-collapse: collapse; }
513 td, th { vertical-align: top; }
514 dt { font-weight: bold; }
516 .org-info-js_info-navigation { border-style:none; }
517 #org-info-js_console-label { font-size:10px; font-weight:bold;
518 white-space:nowrap; }
519 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
523 "The default style specification for exported HTML files.
524 Please use the variables `org-export-html-style' and
525 `org-export-html-style-extra' to add to this style.")
527 (defcustom org-export-html-style
""
528 "Org-wide style definitions for exported HTML files.
530 This variable needs to contain the full HTML structure to provide a style,
531 including the surrounding HTML tags. If you set the value of this variable,
532 you should consider to include definitions for the following classes:
533 title, todo, done, timestamp, timestamp-kwd, tag, target.
535 For example, a valid value would be:
537 <style type=\"text/css\">
538 p { font-weight: normal; color: gray; }
540 .title { text-align: center; }
541 .todo, .timestamp-kwd { color: red; }
542 .done { color: green; }
545 If you'd like to refer to en external style file, use something like
547 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
549 As the value of this option simply gets inserted into the HTML <head> header,
550 you can \"misuse\" it to add arbitrary text to the header.
551 See also the variable `org-export-html-style-extra'."
552 :group
'org-export-html
555 (put 'org-export-html-style
'safe-local-variable
'stringp
)
557 (defcustom org-export-html-style-extra
""
558 "Additional style information for HTML export.
559 The value of this variable is inserted into the HTML buffer right after
560 the value of `org-export-html-style'. Use this variable for per-file
561 settings of style information, and do not forget to surround the style
562 settings with <style>...</style> tags."
563 :group
'org-export-html
566 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
569 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
570 "Format for typesetting the document title in HTML export."
571 :group
'org-export-html
574 (defcustom org-export-html-toplevel-hlevel
2
575 "The <H> level for level 1 headings in HTML export."
576 :group
'org-export-html
579 (defcustom org-export-html-link-org-files-as-html t
580 "Non-nil means, make file links to `file.org' point to `file.html'.
581 When org-mode is exporting an org-mode file to HTML, links to
582 non-html files are directly put into a href tag in HTML.
583 However, links to other Org-mode files (recognized by the
584 extension `.org.) should become links to the corresponding html
585 file, assuming that the linked org-mode file will also be
587 When nil, the links still point to the plain `.org' file."
588 :group
'org-export-html
591 (defcustom org-export-html-inline-images
'maybe
592 "Non-nil means, inline images into exported HTML pages.
593 This is done using an <img> tag. When nil, an anchor with href is used to
594 link to the image. If this option is `maybe', then images in links with
595 an empty description will be inlined, while images with a description will
597 :group
'org-export-html
598 :type
'(choice (const :tag
"Never" nil
)
599 (const :tag
"Always" t
)
600 (const :tag
"When there is no description" maybe
)))
603 (defcustom org-export-html-expand t
604 "Non-nil means, for HTML export, treat @<...> as HTML tag.
605 When nil, these tags will be exported as plain text and therefore
606 not be interpreted by a browser.
608 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
609 :group
'org-export-html
612 (defcustom org-export-html-table-tag
613 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
614 "The HTML tag that is used to start a table.
615 This must be a <table> tag, but you may change the options like
616 borders and spacing."
617 :group
'org-export-html
620 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
621 "The opening tag for table header fields.
622 This is customizable so that alignment options can be specified."
623 :group
'org-export-tables
624 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
626 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
627 "The opening tag for table data fields.
628 This is customizable so that alignment options can be specified."
629 :group
'org-export-tables
630 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
632 (defcustom org-export-html-with-timestamp nil
633 "If non-nil, write `org-export-html-html-helper-timestamp'
634 into the exported HTML text. Otherwise, the buffer will just be saved
636 :group
'org-export-html
639 (defcustom org-export-html-html-helper-timestamp
640 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
641 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
642 :group
'org-export-html
645 (defgroup org-export-htmlize nil
646 "Options for processing examples with htmlize.el."
647 :tag
"Org Export Htmlize"
648 :group
'org-export-html
)
650 (defcustom org-export-htmlize-output-type
'inline-css
651 "Output type to be used by htmlize when formatting code snippets.
652 Normally this is `inline-css', but if you have defined to appropriate
653 classes in your css style file, setting this to `css' means that the
654 fontification will use the class names.
655 See also the function `org-export-htmlize-generate-css'."
656 :group
'org-export-htmlize
657 :type
'(choice (const css
) (const inline-css
)))
659 (defcustom org-export-htmlize-css-font-prefix
"org-"
660 "The prefix for CSS class names for htmlize font specifications."
661 :group
'org-export-htmlize
664 (defgroup org-export-icalendar nil
665 "Options specific for iCalendar export of Org-mode files."
666 :tag
"Org Export iCalendar"
669 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
670 "The file name for the iCalendar file covering all agenda files.
671 This file is created with the command \\[org-export-icalendar-all-agenda-files].
672 The file name should be absolute, the file will be overwritten without warning."
673 :group
'org-export-icalendar
676 (defcustom org-icalendar-combined-name
"OrgMode"
677 "Calendar name for the combined iCalendar representing all agenda files."
678 :group
'org-export-icalendar
681 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
682 "Contexts where iCalendar export should use a deadline time stamp.
683 This is a list with several symbols in it. Valid symbol are:
685 event-if-todo Deadlines in TODO entries become calendar events.
686 event-if-not-todo Deadlines in non-TODO entries become calendar events.
687 todo-due Use deadlines in TODO entries as due-dates"
688 :group
'org-export-icalendar
689 :type
'(set :greedy t
690 (const :tag
"Deadlines in non-TODO entries become events"
692 (const :tag
"Deadline in TODO entries become events"
694 (const :tag
"Deadlines in TODO entries become due-dates"
697 (defcustom org-icalendar-use-scheduled
'(todo-start)
698 "Contexts where iCalendar export should use a scheduling time stamp.
699 This is a list with several symbols in it. Valid symbol are:
701 event-if-todo Scheduling time stamps in TODO entries become an event.
702 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
703 todo-start Scheduling time stamps in TODO entries become start date.
704 Some calendar applications show TODO entries only after
706 :group
'org-export-icalendar
707 :type
'(set :greedy t
709 "SCHEDULED timestamps in non-TODO entries become events"
711 (const :tag
"SCHEDULED timestamps in TODO entries become events"
713 (const :tag
"SCHEDULED in TODO entries become start date"
716 (defcustom org-icalendar-categories
'(local-tags category
)
717 "Items that should be entered into the categories field.
718 This is a list of symbols, the following are valid:
720 category The Org-mode category of the current file or tree
721 todo-state The todo state, if any
722 local-tags The tags, defined in the current line
723 all-tags All tags, including inherited ones."
724 :group
'org-export-icalendar
727 (const :tag
"The file or tree category" category
)
728 (const :tag
"The TODO state" todo-state
)
729 (const :tag
"Tags defined in current line" local-tags
)
730 (const :tag
"All tags, including inherited ones" all-tags
))))
732 (defcustom org-icalendar-include-todo nil
733 "Non-nil means, export to iCalendar files should also cover TODO items."
734 :group
'org-export-icalendar
736 (const :tag
"None" nil
)
737 (const :tag
"Unfinished" t
)
738 (const :tag
"All" all
)))
740 (defcustom org-icalendar-include-sexps t
741 "Non-nil means, export to iCalendar files should also cover sexp entries.
742 These are entries like in the diary, but directly in an Org-mode file."
743 :group
'org-export-icalendar
746 (defcustom org-icalendar-include-body
100
747 "Amount of text below headline to be included in iCalendar export.
748 This is a number of characters that should maximally be included.
749 Properties, scheduling and clocking lines will always be removed.
750 The text will be inserted into the DESCRIPTION field."
751 :group
'org-export-icalendar
753 (const :tag
"Nothing" nil
)
754 (const :tag
"Everything" t
)
755 (integer :tag
"Max characters")))
757 (defcustom org-icalendar-store-UID nil
758 "Non-nil means, store any created UIDs in properties.
759 The iCalendar standard requires that all entries have a unique identifyer.
760 Org will create these identifiers as needed. When this variable is non-nil,
761 the created UIDs will be stored in the ID property of the entry. Then the
762 next time this entry is exported, it will be exported with the same UID,
763 superceeding the previous form of it. This is essential for
764 synchronization services.
765 This variable is not turned on by default because we want to avoid creating
766 a property drawer in every entry if people are only playing with this feature,
767 or if they are only using it locally."
768 :group
'org-export-icalendar
773 ;;; Variables, constants, and parameter plists
775 (defconst org-level-max
20)
777 (defvar org-export-html-preamble nil
778 "Preamble, to be inserted just before <body>. Set by publishing functions.")
779 (defvar org-export-html-postamble nil
780 "Preamble, to be inserted just after </body>. Set by publishing functions.")
781 (defvar org-export-html-auto-preamble t
782 "Should default preamble be inserted? Set by publishing functions.")
783 (defvar org-export-html-auto-postamble t
784 "Should default postamble be inserted? Set by publishing functions.")
785 (defvar org-current-export-file nil
) ; dynamically scoped parameter
786 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
788 (defconst org-export-plist-vars
789 '((:link-up . org-export-html-link-up
)
790 (:link-home . org-export-html-link-home
)
791 (:language . org-export-default-language
)
792 (:customtime . org-display-custom-times
)
793 (:headline-levels . org-export-headline-levels
)
794 (:section-numbers . org-export-with-section-numbers
)
795 (:section-number-format . org-export-section-number-format
)
796 (:table-of-contents . org-export-with-toc
)
797 (:preserve-breaks . org-export-preserve-breaks
)
798 (:archived-trees . org-export-with-archived-trees
)
799 (:emphasize . org-export-with-emphasize
)
800 (:sub-superscript . org-export-with-sub-superscripts
)
801 (:special-strings . org-export-with-special-strings
)
802 (:footnotes . org-export-with-footnotes
)
803 (:drawers . org-export-with-drawers
)
804 (:tags . org-export-with-tags
)
805 (:TeX-macros . org-export-with-TeX-macros
)
806 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
807 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
808 (:fixed-width . org-export-with-fixed-width
)
809 (:timestamps . org-export-with-timestamps
)
810 (:author-info . org-export-author-info
)
811 (:creator-info . org-export-creator-info
)
812 (:time-stamp-file . org-export-time-stamp-file
)
813 (:tables . org-export-with-tables
)
814 (:table-auto-headline . org-export-highlight-first-table-line
)
815 (:style . org-export-html-style
)
816 (:style-extra . org-export-html-style-extra
)
817 (:agenda-style . org-agenda-export-html-style
)
818 (:convert-org-links . org-export-html-link-org-files-as-html
)
819 (:inline-images . org-export-html-inline-images
)
820 (:html-extension . org-export-html-extension
)
821 (:html-table-tag . org-export-html-table-tag
)
822 (:expand-quoted-html . org-export-html-expand
)
823 (:timestamp . org-export-html-with-timestamp
)
824 (:publishing-directory . org-export-publishing-directory
)
825 (:preamble . org-export-html-preamble
)
826 (:postamble . org-export-html-postamble
)
827 (:auto-preamble . org-export-html-auto-preamble
)
828 (:auto-postamble . org-export-html-auto-postamble
)
829 (:author . user-full-name
)
830 (:email . user-mail-address
)
831 (:select-tags . org-export-select-tags
)
832 (:exclude-tags . org-export-exclude-tags
)))
834 (defun org-default-export-plist ()
835 "Return the property list with default settings for the export variables."
836 (let ((l org-export-plist-vars
) rtn e
)
837 (while (setq e
(pop l
))
838 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
841 (defvar org-export-inbuffer-options-extra nil
842 "List of additional in-buffer options that should be detected.
843 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
844 etc. Extensions can add to this list to get their options detected, and they
845 can then add a function to `org-export-options-filters' to process these
847 Each element in this list must be a list, with the in-buffer keyword as car,
848 and a property (a symbol) as the next element. All occurences of the
849 keyword will be found, the values concatenated with a space character
850 in between, and the result stored in the export options property list.")
852 (defvar org-export-options-filters nil
853 "Functions to be called to finalize the export/publishing options.
854 All these options are stored in a property list, and each of the functions
855 in this hook gets a chance to modify this property list. Each function
856 must accept the property list as an argument, and must return the (possibly
859 ;; FIXME: should we fold case here?
860 (defun org-infile-export-plist ()
861 "Return the property list with file-local settings for export."
865 (goto-char (point-min))
866 (let ((re (org-make-options-regexp
868 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
869 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
870 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
871 (mapcar 'car org-export-inbuffer-options-extra
))))
872 p key val text options js-up js-main js-css js-opt a pr style
874 ext-setup-or-nil setup-contents
(start 0))
875 (while (or (and ext-setup-or-nil
876 (string-match re ext-setup-or-nil start
)
877 (setq start
(match-end 0)))
878 (and (setq ext-setup-or-nil nil start
0)
879 (re-search-forward re nil t
)))
880 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
881 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
883 ((setq a
(assoc key org-export-inbuffer-options-extra
))
885 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
886 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
887 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
888 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
889 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
890 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
891 ((string-equal key
"STYLE")
892 (setq style
(concat style
"\n" val
)))
893 ((string-equal key
"LATEX_HEADER")
894 (setq latex-header
(concat latex-header
"\n" val
)))
895 ((string-equal key
"TEXT")
896 (setq text
(if text
(concat text
"\n" val
) val
)))
897 ((string-equal key
"OPTIONS")
898 (setq options
(concat val
" " options
)))
899 ((string-equal key
"LINK_UP")
900 (setq p
(plist-put p
:link-up val
)))
901 ((string-equal key
"LINK_HOME")
902 (setq p
(plist-put p
:link-home val
)))
903 ((string-equal key
"EXPORT_SELECT_TAGS")
904 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
905 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
906 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
907 ((equal key
"SETUPFILE")
908 (setq setup-contents
(org-file-contents
910 (org-remove-double-quotes
913 (if (not ext-setup-or-nil
)
914 (setq ext-setup-or-nil setup-contents start
0)
915 (setq ext-setup-or-nil
916 (concat (substring ext-setup-or-nil
0 start
)
917 "\n" setup-contents
"\n"
918 (substring ext-setup-or-nil start
)))))))
919 (setq p
(plist-put p
:text text
))
920 (when style
(setq p
(plist-put p
:style-extra style
)))
922 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
924 (setq p
(org-export-add-options-to-plist p options
)))
927 (defun org-export-add-options-to-plist (p options
)
928 "Parse an OPTONS line and set values in the property list P."
931 (let ((op '(("H" .
:headline-levels
)
932 ("num" .
:section-numbers
)
933 ("toc" .
:table-of-contents
)
934 ("\\n" .
:preserve-breaks
)
935 ("@" .
:expand-quoted-html
)
938 ("^" .
:sub-superscript
)
939 ("-" .
:special-strings
)
944 ("TeX" .
:TeX-macros
)
945 ("LaTeX" .
:LaTeX-fragments
)
946 ("skip" .
:skip-before-1st-heading
)
947 ("author" .
:author-info
)
948 ("creator" .
:creator-info
)
949 ("timestamp" .
:time-stamp-file
)))
951 (while (setq o
(pop op
))
952 (if (string-match (concat (regexp-quote (car o
))
953 ":\\([^ \t\n\r;,.]*\\)")
955 (setq p
(plist-put p
(cdr o
)
956 (car (read-from-string
957 (match-string 1 options
))))))))))
960 (defun org-export-add-subtree-options (p pos
)
961 "Add options in subtree at position POS to property list P."
964 (when (org-at-heading-p)
966 ;; This is actually read in `org-export-get-title-from-subtree'
967 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
968 ;; (setq p (plist-put p :title a)))
969 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
970 (setq p
(plist-put p
:text a
)))
971 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
972 (setq p
(org-export-add-options-to-plist p a
)))))
975 (defun org-export-directory (type plist
)
976 (let* ((val (plist-get plist
:publishing-directory
))
978 (or (cdr (assoc type val
)) ".")
982 (defun org-export-process-option-filters (plist)
983 (let ((functions org-export-options-filters
) f
)
984 (while (setq f
(pop functions
))
985 (setq plist
(funcall f plist
))))
989 (defun org-export (&optional arg
)
990 "Export dispatcher for Org-mode.
991 When `org-export-run-in-background' is non-nil, try to run the command
992 in the background. This will be done only for commands that write
993 to a file. For details see the docstring of `org-export-run-in-background'.
995 The prefix argument ARG will be passed to the exporter. However, if
996 ARG is a double universal prefix `C-u C-u', that means to inverse the
997 value of `org-export-run-in-background'."
999 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1000 (help "[t] insert the export option template
1001 \[v] limit export to visible part of outline tree
1003 \[a] export as ASCII
1006 \[H] export as HTML to temporary buffer
1007 \[R] export region as HTML
1008 \[b] export as HTML and browse immediately
1011 \[l] export as LaTeX
1012 \[p] export as LaTeX and process to PDF
1013 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1014 \[L] export as LaTeX to temporary buffer
1016 \[i] export current file as iCalendar file
1017 \[I] export all agenda files as iCalendar files
1018 \[c] export agenda files into combined iCalendar file
1020 \[F] publish current file
1021 \[P] publish current project
1022 \[X] publish... (project will be prompted for)
1023 \[A] publish all projects")
1025 '((?t org-insert-export-options-template nil
)
1026 (?v org-export-visible nil
)
1027 (?a org-export-as-ascii t
)
1028 (?h org-export-as-html t
)
1029 (?b org-export-as-html-and-open t
)
1030 (?H org-export-as-html-to-buffer nil
)
1031 (?R org-export-region-as-html nil
)
1032 (?x org-export-as-xoxo t
)
1033 (?l org-export-as-latex t
)
1034 (?p org-export-as-pdf t
)
1035 (?d org-export-as-pdf-and-open t
)
1036 (?L org-export-as-latex-to-buffer nil
)
1037 (?i org-export-icalendar-this-file t
)
1038 (?I org-export-icalendar-all-agenda-files t
)
1039 (?c org-export-icalendar-combine-agenda-files t
)
1040 (?F org-publish-current-file t
)
1041 (?P org-publish-current-project t
)
1043 (?A org-publish-all t
)))
1045 (save-window-excursion
1046 (delete-other-windows)
1047 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1049 (if (fboundp 'fit-window-to-buffer
)
1050 (fit-window-to-buffer (get-buffer-window
1051 "*Org Export/Publishing Help*")))
1052 (message "Select command: ")
1053 (setq r1
(read-char-exclusive)))
1054 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1055 (unless (setq ass
(assq r2 cmds
))
1056 (error "No command associated with key %c" r1
))
1057 (if (and bg
(nth 2 ass
)
1058 (not (buffer-base-buffer))
1059 (not (org-region-active-p)))
1060 ;; execute in background
1061 (let ((p (start-process
1062 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1064 (expand-file-name invocation-name invocation-directory
)
1067 "--eval" "(require 'org-exp)"
1068 "--eval" "(setq org-wait .2)"
1070 "-f" (symbol-name (nth 1 ass
)))))
1071 (set-process-sentinel p
'org-export-process-sentinel
)
1072 (message "Background process \"%s\": started" p
))
1073 ;; background processing not requested, or not possible
1074 (call-interactively (nth 1 ass
)))))
1076 (defun org-export-process-sentinel (process status
)
1077 (if (string-match "\n+\\'" status
)
1078 (setq status
(substring status
0 -
1)))
1079 (message "Background process \"%s\": %s" process status
))
1081 (defconst org-html-entities
1122 ("Aring") ("AA".
"Å")
1211 ("varepsilon".
"ε")
1224 ("sigmaf") ("varsigma".
"ς")
1232 ("thetasym") ("vartheta".
"ϑ")
1235 ("bull") ("bullet".
"•")
1236 ("hellip") ("dots".
"…")
1246 ("larr") ("leftarrow".
"←") ("gets".
"←")
1247 ("uarr") ("uparrow".
"↑")
1248 ("rarr") ("to".
"→") ("rightarrow".
"→")
1249 ("darr")("downarrow".
"↓")
1250 ("harr") ("leftrightarrow".
"↔")
1251 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1252 ("lArr") ("Leftarrow".
"⇐")
1253 ("uArr") ("Uparrow".
"⇑")
1254 ("rArr") ("Rightarrow".
"⇒")
1255 ("dArr") ("Downarrow".
"⇓")
1256 ("hArr") ("Leftrightarrow".
"⇔")
1258 ("part") ("partial".
"∂")
1259 ("exist") ("exists".
"∃")
1260 ("empty") ("emptyset".
"∅")
1262 ("isin") ("in".
"∈")
1268 ("lowast") ("ast".
"∗")
1270 ("prop") ("proptp".
"∝")
1271 ("infin") ("infty".
"∞")
1272 ("ang") ("angle".
"∠")
1273 ("and") ("wedge".
"∧")
1274 ("or") ("vee".
"∨")
1280 ("cong") ("simeq".
"≅")
1281 ("asymp")("approx".
"≈")
1282 ("ne") ("neq".
"≠")
1286 ("sub") ("subset".
"⊂")
1287 ("sup") ("supset".
"⊃")
1294 ("sdot") ("cdot".
"⋅")
1301 ("loz") ("Diamond".
"◊")
1302 ("spades") ("spadesuit".
"♠")
1303 ("clubs") ("clubsuit".
"♣")
1304 ("hearts") ("diamondsuit".
"♥")
1305 ("diams") ("diamondsuit".
"♦")
1306 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1373 "Entities for TeX->HTML translation.
1374 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1375 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1376 In that case, \"\\ent\" will be translated to \"&other;\".
1377 The list contains HTML entities for Latin-1, Greek and other symbols.
1378 It is supplemented by a number of commonly used TeX macros with appropriate
1379 translations. There is currently no way for users to extend this.")
1381 ;;; General functions for all backends
1383 (defun org-export-preprocess-string (string &rest parameters
)
1384 "Cleanup STRING so that that the true exported has a more consistent source.
1385 This function takes STRING, which should be a buffer-string of an org-file
1386 to export. It then creates a temporary buffer where it does its job.
1387 The result is then again returned as a string, and the exporter works
1388 on this string to produce the exported version."
1390 (let* ((htmlp (plist-get parameters
:for-html
))
1391 (asciip (plist-get parameters
:for-ascii
))
1392 (latexp (plist-get parameters
:for-LaTeX
))
1393 (archived-trees (plist-get parameters
:archived-trees
))
1394 (inhibit-read-only t
)
1395 (drawers org-drawers
)
1396 (outline-regexp "\\*+ ")
1399 (with-current-buffer (get-buffer-create " org-mode-tmp")
1402 (setq case-fold-search t
)
1404 (run-hooks 'org-export-preprocess-hook
)
1406 ;; Remove license-to-kill stuff
1407 ;; The caller markes some stuff fo killing, stuff that has been
1408 ;; used to create the page title, for example.
1409 (org-export-kill-licensed-text)
1411 (let ((org-inhibit-startup t
)) (org-mode))
1412 (setq case-fold-search t
)
1413 (untabify (point-min) (point-max))
1415 ;; Handle include files
1416 (org-export-handle-include-files)
1418 ;; Get rid of excluded trees
1419 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1420 (plist-get parameters
:exclude-tags
))
1422 ;; Handle source code snippets
1423 (org-export-replace-src-segments)
1425 ;; Get rid of drawers
1426 (org-export-remove-or-extract-drawers drawers
1427 (plist-get parameters
:drawers
))
1429 ;; Get the correct stuff before the first headline
1430 (when (plist-get parameters
:skip-before-1st-heading
)
1431 (goto-char (point-min))
1432 (when (re-search-forward "^\\*+[ \t]" nil t
)
1433 (delete-region (point-min) (match-beginning 0))
1434 (goto-char (point-min))
1436 (when (plist-get parameters
:add-text
)
1437 (goto-char (point-min))
1438 (insert (plist-get parameters
:add-text
) "\n"))
1440 ;; Get rid of archived trees
1441 (org-export-remove-archived-trees archived-trees
)
1443 ;; Find all headings and compute the targets for them
1444 (setq target-alist
(org-export-define-heading-targets target-alist
))
1446 ;; Find targets in comments and move them out of comments,
1447 ;; but mark them as targets that should be invisible
1448 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1451 (org-export-protect-examples (if asciip
'indent nil
))
1453 ;; Protect backend specific stuff, throw away the others.
1454 (org-export-select-backend-specific-text
1455 (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1457 ;; Protect quoted subtrees
1458 (org-export-protect-quoted-subtrees)
1460 ;; Protect verbatim elements
1461 (org-export-protect-verbatim)
1463 ;; Blockquotes and verse
1464 (org-export-mark-blockquote-and-verse)
1466 ;; Remove comment environment and comment subtrees
1467 (org-export-remove-comment-blocks-and-subtrees)
1470 ;; Find matches for radio targets and turn them into internal links
1471 (org-export-mark-radio-links)
1473 ;; Find all links that contain a newline and put them into a single line
1474 (org-export-concatenate-multiline-links)
1476 ;; Normalize links: Convert angle and plain links into bracket links
1477 ;; and expand link abbreviations
1478 (org-export-normalize-links)
1480 ;; Find all internal links. If they have a fuzzy match (i.e. not
1481 ;; a *dedicated* target match, let the link point to the
1482 ;; corresponding section.
1483 (org-export-target-internal-links target-alist
)
1485 ;; Find multiline emphasis and put them into single line
1486 (when (plist-get parameters
:emph-multiline
)
1487 (org-export-concatenate-multiline-emphasis))
1489 ;; Remove special table lines
1490 (when org-export-table-remove-special-lines
1491 (org-export-remove-special-table-lines))
1493 ;; Specific LaTeX stuff
1495 (require 'org-export-latex nil
)
1496 (org-export-latex-preprocess))
1498 ;; Specific ASCII stuff
1500 (org-export-ascii-preprocess))
1502 ;; Specific HTML stuff
1504 (org-export-html-preprocess parameters
))
1506 ;; Remove or replace comments
1507 (org-export-handle-comments (plist-get parameters
:comments
))
1509 (setq rtn
(buffer-string)))
1510 (kill-buffer " org-mode-tmp")
1513 (defun org-export-kill-licensed-text ()
1514 "Remove all text that is marked with a :org-license-to-kill property."
1516 (while (setq p
(text-property-any (point-min) (point-max)
1517 :org-license-to-kill t
))
1519 p
(or (next-single-property-change p
:org-license-to-kill
)
1522 (defun org-export-define-heading-targets (target-alist)
1523 "Find all headings and define the targets for them.
1524 The new targets are added to TARGET-ALIST, which is also returned."
1525 (goto-char (point-min))
1526 (org-init-section-numbers)
1527 (let ((re (concat "^" org-outline-regexp
))
1529 (while (re-search-forward re nil t
)
1530 (setq level
(org-reduced-level
1531 (save-excursion (goto-char (point-at-bol))
1532 (org-outline-level))))
1533 (setq target
(org-solidify-link-text
1534 (format "sec-%s" (org-section-number level
))))
1535 (push (cons target target
) target-alist
)
1536 (add-text-properties
1537 (point-at-bol) (point-at-eol)
1538 (list 'target target
))))
1541 (defun org-export-handle-invisible-targets (target-alist)
1542 "Find targets in comments and move them out of comments.
1543 Mark them as invisible targets."
1545 (goto-char (point-min))
1546 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1547 ;; Check if the line before or after is a headline with a target
1548 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1549 (get-text-property (point-at-bol 2) 'target
)))
1551 ;; use the existing target in a neighboring line
1552 (setq tmp
(match-string 2))
1554 (and (looking-at "\n") (delete-char 1))
1555 (push (cons (org-solidify-link-text tmp
) target
)
1557 ;; Make an invisible target
1558 (replace-match "\\1(INVISIBLE)"))))
1561 (defun org-export-target-internal-links (target-alist)
1562 "Find all internal links and assign target to them.
1563 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1564 let the link point to the corresponding section."
1565 (goto-char (point-min))
1566 (while (re-search-forward org-bracket-link-regexp nil t
)
1568 (let* ((md (match-data))
1569 (desc (match-end 2))
1570 (link (org-link-unescape (match-string 1)))
1571 (slink (org-solidify-link-text link
))
1575 ((cdr (assoc slink target-alist
)))
1576 ((string-match org-link-types-re link
) nil
)
1577 ((or (file-name-absolute-p link
)
1578 (string-match "^\\." link
))
1582 (setq found
(condition-case nil
(org-link-search link
)
1585 (or (org-on-heading-p)
1586 (not (eq found
'dedicated
))))
1587 (or (get-text-property (point) 'target
)
1590 (1- (previous-single-property-change
1595 (goto-char (match-beginning 1))
1596 (setq props
(text-properties-at (point)))
1597 (delete-region (match-beginning 1) (match-end 1))
1600 (unless desc
(insert "][" link
))
1601 (add-text-properties pos
(point) props
))))))
1603 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1604 "Remove drawers, or extract the content.
1605 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1606 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1607 whose content to keep."
1608 (unless (eq t exp-drawers
)
1609 (goto-char (point-min))
1610 (let ((re (concat "^[ \t]*:\\("
1613 (org-delete-all exp-drawers
1614 (copy-sequence all-drawers
))
1616 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1617 (while (re-search-forward re nil t
)
1618 (replace-match "")))))
1620 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1621 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1622 Both arguments are lists of tags.
1623 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1625 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1627 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1628 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1631 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1635 (goto-char (point-min))
1636 (when (and select-tags
1638 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1639 ;; At least one tree is marked for export, this means
1640 ;; all the unmarked stuff needs to go.
1641 ;; Dig out the trees that should be exported
1642 (goto-char (point-min))
1643 (outline-next-heading)
1645 (put-text-property beg
(point-max) :org-delete t
)
1646 (while (re-search-forward re-sel nil t
)
1647 (when (org-on-heading-p)
1648 (org-back-to-heading)
1649 (remove-text-properties
1650 (max (1- (point)) (point-min))
1651 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1653 (while (and (org-up-heading-safe)
1654 (get-text-property (point) :org-delete
))
1655 (remove-text-properties (max (1- (point)) (point-min))
1656 (point-at-eol) '(:org-delete t
)))
1658 ;; Remove the trees explicitly marked for noexport
1660 (goto-char (point-min))
1661 (while (re-search-forward re-excl nil t
)
1662 (when (org-at-heading-p)
1663 (org-back-to-heading t
)
1665 (org-end-of-subtree t
)
1666 (delete-region beg
(point)))))
1667 ;; Remove everything that is now still marked for deletion
1668 (goto-char (point-min))
1669 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1670 (setq end
(or (next-single-property-change beg
:org-delete
)
1672 (delete-region beg end
))))
1674 (defun org-export-remove-archived-trees (export-archived-trees)
1675 "Remove archived trees.
1676 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1677 When it is t, the entire archived tree will be exported.
1678 When it is nil the entire tree including the headline will be removed
1680 (let ((re-archive (concat ":" org-archive-tag
":"))
1682 (when (not (eq export-archived-trees t
))
1683 (goto-char (point-min))
1684 (while (re-search-forward re-archive nil t
)
1685 (if (not (org-on-heading-p t
))
1686 (org-end-of-subtree t
)
1687 (beginning-of-line 1)
1688 (setq a
(if export-archived-trees
1689 (1+ (point-at-eol)) (point))
1690 b
(org-end-of-subtree t
))
1691 (if (> b a
) (delete-region a b
)))))))
1693 (defun org-export-protect-quoted-subtrees ()
1694 "Mark quoted subtrees with the protection property."
1695 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1696 (goto-char (point-min))
1697 (while (re-search-forward re-quote nil t
)
1698 (goto-char (match-beginning 0))
1700 (add-text-properties (point) (org-end-of-subtree t
)
1701 '(org-protected t
)))))
1703 (defun org-export-protect-verbatim ()
1704 "Mark verbatim snippets with the protection property."
1705 (goto-char (point-min))
1706 (while (re-search-forward org-verbatim-re nil t
)
1707 (add-text-properties (match-beginning 4) (match-end 4)
1709 (goto-char (1+ (match-end 4)))))
1711 (defun org-export-protect-examples (&optional indent
)
1712 "Protect code that should be exported as monospaced examples."
1713 (goto-char (point-min))
1714 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1715 (goto-char (match-end 0))
1716 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1717 (insert (if indent
": " ":"))
1718 (beginning-of-line 2)))
1719 (goto-char (point-min))
1720 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1721 (add-text-properties (match-beginning 0) (match-end 0)
1722 '(org-protected t
))))
1724 (defun org-export-select-backend-specific-text (backend)
1726 '((html "HTML" "BEGIN_HTML" "END_HTML")
1727 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1728 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1732 (setq fmt
(pop formatters
))
1733 (when (eq (car fmt
) backend
)
1734 ;; This is selected code, put it into the file for real
1735 (goto-char (point-min))
1736 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1737 ":[ \t]*\\(.*\\)") nil t
)
1738 (replace-match "\\1" t
)
1739 (add-text-properties
1740 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1741 '(org-protected t
))))
1742 (goto-char (point-min))
1743 (while (re-search-forward
1745 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1746 (cadddr fmt
) "\\>.*\n?") nil t
)
1747 (if (eq (car fmt
) backend
)
1749 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1751 ;; No, this is for a different backend, kill it
1752 (delete-region (match-beginning 0) (match-end 0)))))))
1754 (defun org-export-mark-blockquote-and-verse ()
1755 "Mark block quote and verse environments with special cookies.
1756 These special cookies will later be interpreted by the backend."
1758 (goto-char (point-min))
1759 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1761 (replace-match (if (equal (downcase (match-string 1)) "end")
1762 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1765 (goto-char (point-min))
1766 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1767 (replace-match (if (equal (downcase (match-string 1)) "end")
1768 "ORG-VERSE-END" "ORG-VERSE-START")
1771 (defun org-export-remove-comment-blocks-and-subtrees ()
1772 "Remove the comment environment, and also commented subtrees."
1773 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1774 (case-fold-search nil
))
1775 ;; Remove comment environment
1776 (goto-char (point-min))
1777 (while (re-search-forward
1778 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1779 (replace-match "" t t
))
1780 ;; Remove subtrees that are commented
1781 (goto-char (point-min))
1782 (while (re-search-forward re-commented nil t
)
1783 (goto-char (match-beginning 0))
1784 (delete-region (point) (org-end-of-subtree t
)))))
1786 (defun org-export-handle-comments (commentsp)
1787 "Remove comments, or convert to backend-specific format.
1788 COMMENTSP can be a format string for publishing comments.
1789 When it is nil, all comments will be removed."
1790 (let ((re "^#\\(.*\n?\\)")
1792 (goto-char (point-min))
1793 (while (or (looking-at re
)
1794 (re-search-forward re nil t
))
1795 (setq pos
(match-beginning 0))
1797 (progn (add-text-properties
1798 (match-beginning 0) (match-end 0) '(org-protected t
))
1799 (replace-match (format commentsp
(match-string 1)) t t
))
1800 (goto-char (1+ pos
))
1803 (goto-char (max (point-min) (1- pos
))))))))
1805 (defun org-export-mark-radio-links ()
1806 "Find all matches for radio targets and turn them into internal links."
1807 (let ((re-radio (and org-target-link-regexp
1808 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1809 (goto-char (point-min))
1811 (while (re-search-forward re-radio nil t
)
1813 (replace-match "\\1[[\\2]]"))))))
1815 (defun org-export-remove-special-table-lines ()
1816 "Remove tables lines that are used for internal purposes."
1817 (goto-char (point-min))
1818 (while (re-search-forward "^[ \t]*|" nil t
)
1819 (beginning-of-line 1)
1820 (if (or (looking-at "[ \t]*| *[!_^] *|")
1821 (and (looking-at ".*?| *<[0-9]+> *|")
1822 (not (looking-at ".*?| *[^ <|]"))))
1823 (delete-region (max (point-min) (1- (point-at-bol)))
1827 (defun org-export-normalize-links ()
1828 "Convert all links to bracket links, and expand link abbreviations."
1829 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1830 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1831 (goto-char (point-min))
1832 (while (re-search-forward re-plain-link nil t
)
1833 (goto-char (1- (match-end 0)))
1835 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1836 ":" (match-string 3) "]]")))
1837 ;; added 'org-link face to links
1838 (put-text-property 0 (length s
) 'face
'org-link s
)
1839 (replace-match s t t
))))
1840 (goto-char (point-min))
1841 (while (re-search-forward re-angle-link nil t
)
1842 (goto-char (1- (match-end 0)))
1844 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1845 ":" (match-string 3) "]]")))
1846 (put-text-property 0 (length s
) 'face
'org-link s
)
1847 (replace-match s t t
))))
1848 (goto-char (point-min))
1849 (while (re-search-forward org-bracket-link-regexp nil t
)
1850 (goto-char (1- (match-end 0)))
1852 (let* ((xx (save-match-data
1853 (org-link-expand-abbrev (match-string 1))))
1858 (concat "[" xx
"]"))
1860 (put-text-property 0 (length s
) 'face
'org-link s
)
1861 (replace-match s t t
))))))
1863 (defun org-export-concatenate-multiline-links ()
1864 "Find multi-line links and put it all into a single line.
1865 This is to make sure that the line-processing export backends
1866 can work correctly."
1867 (goto-char (point-min))
1868 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1870 (replace-match "\\1 \\3")
1871 (goto-char (match-beginning 0)))))
1873 (defun org-export-concatenate-multiline-emphasis ()
1874 "Find multi-line emphasis and put it all into a single line.
1875 This is to make sure that the line-processing export backends
1876 can work correctly."
1877 (goto-char (point-min))
1878 (while (re-search-forward org-emph-re nil t
)
1879 (if (not (= (char-after (match-beginning 3))
1880 (char-after (match-beginning 4))))
1882 (subst-char-in-region (match-beginning 0) (match-end 0)
1884 (goto-char (1- (match-end 0))))
1885 (goto-char (1+ (match-beginning 0))))))
1887 (defun org-export-grab-title-from-buffer ()
1888 "Get a title for the current document, from looking at the buffer."
1889 (let ((inhibit-read-only t
))
1891 (goto-char (point-min))
1892 (let ((end (if (looking-at org-outline-regexp
)
1894 (save-excursion (outline-next-heading) (point)))))
1895 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1896 ;; Mark the line so that it will not be exported as normal text.
1898 (add-text-properties (match-beginning 0) (match-end 0)
1899 (list :org-license-to-kill t
)))
1900 ;; Return the title string
1901 (org-trim (match-string 0)))))))
1903 (defun org-export-get-title-from-subtree ()
1904 "Return subtree title and exclude it from export."
1905 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1908 (when (and (org-at-heading-p)
1909 (>= (org-end-of-subtree t t
) rend
))
1910 ;; This is a subtree, we take the title from the first heading
1912 (looking-at org-todo-line-regexp
)
1913 (setq title
(match-string 3))
1915 (add-text-properties (point) (1+ (point-at-eol))
1916 (list :org-license-to-kill t
)))
1917 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1920 (defun org-solidify-link-text (s &optional alist
)
1921 "Take link text and make a safe target out of it."
1926 (org-split-string s
"[ \t\r\n]+") "=="))
1927 (a (assoc rtn alist
)))
1930 (defun org-get-min-level (lines)
1931 "Get the minimum level in LINES."
1932 (let ((re "^\\(\\*+\\) ") l min
)
1934 (while (setq l
(pop lines
))
1935 (if (string-match re l
)
1936 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1939 ;; Variable holding the vector with section numbers
1940 (defvar org-section-numbers
(make-vector org-level-max
0))
1942 (defun org-init-section-numbers ()
1943 "Initialize the vector for the section numbers."
1945 (numbers (nreverse (org-split-string "" "\\.")))
1946 (depth (1- (length org-section-numbers
)))
1947 (i depth
) number-string
)
1950 (aset org-section-numbers i
0)
1951 (setq number-string
(or (car numbers
) "0"))
1952 (if (string-match "\\`[A-Z]\\'" number-string
)
1953 (aset org-section-numbers i
1954 (- (string-to-char number-string
) ?A -
1))
1955 (aset org-section-numbers i
(string-to-number number-string
)))
1959 (defun org-section-number (&optional level
)
1960 "Return a string with the current section number.
1961 When LEVEL is non-nil, increase section numbers on that level."
1962 (let* ((depth (1- (length org-section-numbers
)))
1964 (fmts (car org-export-section-number-format
))
1965 (term (cdr org-export-section-number-format
))
1970 (aset org-section-numbers
1971 level
(1+ (aref org-section-numbers level
))))
1972 (setq idx
(1+ level
))
1973 (while (<= idx depth
)
1975 (aset org-section-numbers idx
0))
1976 (setq idx
(1+ idx
))))
1978 (while (<= idx depth
)
1979 (when (> (aref org-section-numbers idx
) 0)
1980 (setq fmt
(or (pop fmts
) fmt
)
1982 n
(aref org-section-numbers idx
)
1984 (concat string sep
(org-number-to-counter n ctype
))
1985 (concat string
".0"))
1987 (setq idx
(1+ idx
)))
1989 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1990 (setq string
(replace-match "" t nil string
)))
1991 (if (string-match "\\(\\.0\\)+\\'" string
)
1992 (setq string
(replace-match "" t nil string
))))
1993 (concat string term
)))
1995 (defun org-number-to-counter (n type
)
1996 "Concert number N to a string counter, according to TYPE.
1997 TYPE must be a string, any of:
2001 I uppper case roman numeral
2002 i lower case roman numeral"
2004 ((equal type
"1") (number-to-string n
))
2005 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2006 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2007 ((equal type
"I") (org-number-to-roman n
))
2008 ((equal type
"i") (downcase (org-number-to-roman n
)))
2009 (t (error "Invalid counter type `%s'" type
))))
2011 (defun org-number-to-roman (n)
2012 "Convert integer N into a roman numeral."
2013 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2014 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2015 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2019 (number-to-string n
)
2021 (if (>= n
(caar roman
))
2022 (setq n
(- n
(caar roman
))
2023 res
(concat res
(cdar roman
)))
2027 (org-number-to-roman 1961)
2032 (defun org-export-handle-include-files ()
2033 "Include the contents of include files, with proper formatting."
2034 (let ((case-fold-search t
)
2035 params file markup lang start end prefix prefix1
)
2036 (goto-char (point-min))
2037 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2038 (setq params
(read (concat "(" (match-string 1) ")"))
2039 prefix
(org-get-and-remove-property 'params
:prefix
)
2040 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2041 file
(org-symname-or-string (pop params
))
2042 markup
(org-symname-or-string (pop params
))
2043 lang
(org-symname-or-string (pop params
)))
2044 (delete-region (match-beginning 0) (match-end 0))
2046 (not (file-exists-p file
))
2047 (not (file-readable-p file
)))
2048 (insert (format "CANNOT INCLUDE FILE %s" file
))
2050 (if (equal (downcase markup
) "src")
2051 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2053 (setq start
(format "#+begin_%s\n" markup
)
2054 end
(format "#+end_%s" markup
))))
2055 (insert (or start
""))
2056 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2057 (or (bolp) (newline))
2058 (insert (or end
""))))))
2060 (defun org-get-file-contents (file &optional prefix prefix1
)
2061 "Get the contents of FILE and return them as a string.
2062 If PREFIX is a string, prepend it to each line. If PREFIX1
2063 is a string, prepend it to the first line instead of PREFIX."
2065 (insert-file-contents file
)
2066 (when (or prefix prefix1
)
2067 (goto-char (point-min))
2069 (insert (or prefix1 prefix
))
2071 (beginning-of-line 2)))
2074 (defun org-get-and-remove-property (listvar prop
)
2075 "Check if the value of LISTVAR contains PROP as a property.
2076 If yes, return the value of that property (i.e. the element following
2077 in the list) and remove property and value from the list in LISTVAR."
2078 (let ((list (symbol-value listvar
)) m v
)
2079 (when (setq m
(member prop list
))
2081 (if (equal (car list
) prop
)
2082 (set listvar
(cddr list
))
2083 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2085 (set listvar list
)))
2088 (defun org-symname-or-string (s)
2090 (if s
(symbol-name s
) s
)
2093 ;;; Fontification of code
2094 ;; Currently only for the HTML backend, but who knows....
2095 (defun org-export-replace-src-segments ()
2096 "Replace source code segments with special code for export."
2097 (let ((case-fold-search t
)
2099 (goto-char (point-min))
2100 (while (re-search-forward
2101 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2103 (setq lang
(match-string 1) code
(match-string 2)
2104 trans
(org-export-format-source-code lang code
))
2105 (replace-match trans t t
))))
2107 (defvar htmlp
) ;; dynamically scoped from org-exp.el
2109 (defun org-export-format-source-code (lang code
)
2110 "Format CODE from language LANG and return it formatted for export.
2111 Currently, this only does something for HTML export, for all other
2112 backends, it converts the segment into an EXAMPLE segment."
2116 ;; We are exporting to HTML
2117 (condition-case nil
(require 'htmlize
) (nil t
))
2118 (if (not (fboundp 'htmlize-region-for-paste
))
2120 ;; we do not have htmlize.el, or an old version of it
2122 "htmlize.el 1.34 or later is needed for source code formatting")
2123 (concat "#+BEGIN_EXAMPLE\n" code
2124 (if (string-match "\n\\'" code
) "" "\n")
2126 ;; ok, we are good to go
2127 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2128 (org-inhibit-startup t
)
2129 (org-startup-folded nil
)
2133 ;; Free up the protected stuff
2134 (goto-char (point-min))
2135 (while (re-search-forward "^," nil t
)
2138 (if (functionp mode
)
2141 (font-lock-fontify-buffer)
2142 (org-export-htmlize-region-for-paste
2143 (point-min) (point-max)))))
2144 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
2145 (setq htmltext
(replace-match
2146 (format "<pre class=\"src src-%s\">" lang
)
2148 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
2150 ;; This is not HTML, so just make it an example.
2151 (when (equal lang
"org")
2152 (while (string-match "^," code
)
2153 (setq code
(replace-match "" t t code
))))
2154 (concat "#+BEGIN_EXAMPLE\n" code
2155 (if (string-match "\n\\'" code
) "" "\n")
2156 "#+END_EXAMPLE\n")))))
2160 (defvar org-last-level nil
) ; dynamically scoped variable
2161 (defvar org-min-level nil
) ; dynamically scoped variable
2162 (defvar org-levels-open nil
) ; dynamically scoped parameter
2163 (defvar org-ascii-current-indentation nil
) ; For communication
2166 (defun org-export-as-ascii (arg)
2167 "Export the outline as a pretty ASCII file.
2168 If there is an active region, export only the region.
2169 The prefix ARG specifies how many levels of the outline should become
2170 underlined headlines. The default is 3."
2172 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2173 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2174 (org-infile-export-plist)))
2175 (region-p (org-region-active-p))
2176 (rbeg (and region-p
(region-beginning)))
2177 (rend (and region-p
(region-end)))
2182 (and (org-at-heading-p)
2183 (>= (org-end-of-subtree t t
) rend
)))))
2184 (opt-plist (if subtree-p
2185 (org-export-add-subtree-options opt-plist rbeg
)
2187 (custom-times org-display-custom-times
)
2188 (org-ascii-current-indentation '(0 .
0))
2192 (case-fold-search nil
)
2193 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2194 (filename (concat (file-name-as-directory
2195 (org-export-directory :ascii opt-plist
))
2196 (file-name-sans-extension
2198 (org-entry-get (region-beginning)
2199 "EXPORT_FILE_NAME" t
))
2200 (file-name-nondirectory bfname
)))
2202 (filename (if (equal (file-truename filename
)
2203 (file-truename bfname
))
2204 (concat filename
".txt")
2206 (buffer (find-file-noselect filename
))
2207 (org-levels-open (make-vector org-level-max nil
))
2208 (odd org-odd-levels-only
)
2209 (date (plist-get opt-plist
:date
))
2210 (author (plist-get opt-plist
:author
))
2211 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2212 (plist-get opt-plist
:title
)
2214 (plist-get opt-plist
:skip-before-1st-heading
))
2215 (org-export-grab-title-from-buffer))
2216 (file-name-sans-extension
2217 (file-name-nondirectory bfname
))))
2218 (email (plist-get opt-plist
:email
))
2219 (language (plist-get opt-plist
:language
))
2220 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2221 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2226 (if (org-region-active-p) (region-beginning) (point-min))
2227 (if (org-region-active-p) (region-end) (point-max))))
2228 (lines (org-split-string
2229 (org-export-preprocess-string
2232 :skip-before-1st-heading
2233 (plist-get opt-plist
:skip-before-1st-heading
)
2234 :drawers
(plist-get opt-plist
:drawers
)
2235 :verbatim-multiline t
2236 :select-tags
(plist-get opt-plist
:select-tags
)
2237 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2239 (plist-get opt-plist
:archived-trees
)
2240 :add-text
(plist-get opt-plist
:text
))
2242 thetoc have-headings first-heading-pos
2243 table-open table-buffer
)
2245 (let ((inhibit-read-only t
))
2247 (remove-text-properties (point-min) (point-max)
2248 '(:org-license-to-kill t
))))
2250 (setq org-min-level
(org-get-min-level lines
))
2251 (setq org-last-level org-min-level
)
2252 (org-init-section-numbers)
2254 (find-file-noselect filename
)
2256 (setq lang-words
(or (assoc language org-export-language-setup
)
2257 (assoc "en" org-export-language-setup
)))
2258 (switch-to-buffer-other-window buffer
)
2261 ;; create local variables for all options, to make sure all called
2262 ;; functions get the correct information
2264 (set (make-local-variable (cdr x
))
2265 (plist-get opt-plist
(car x
))))
2266 org-export-plist-vars
)
2267 (org-set-local 'org-odd-levels-only odd
)
2268 (setq umax
(if arg
(prefix-numeric-value arg
)
2269 org-export-headline-levels
))
2270 (setq umax-toc
(if (integerp org-export-with-toc
)
2271 (min org-export-with-toc umax
)
2275 (if title
(org-insert-centered title ?
=))
2277 (if (and (or author email
)
2278 org-export-author-info
)
2279 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2280 (if email
(concat " <" email
">") "")
2284 ((and date
(string-match "%" date
))
2285 (setq date
(format-time-string date
)))
2287 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2289 (if (and date org-export-time-stamp-file
)
2290 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2294 (if org-export-with-toc
2296 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2297 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2299 (mapc '(lambda (line)
2300 (if (string-match org-todo-line-regexp
2302 ;; This is a headline
2304 (setq have-headings t
)
2305 (setq level
(- (match-end 1) (match-beginning 1))
2306 level
(org-tr-level level
)
2307 txt
(match-string 3 line
)
2309 (or (and org-export-mark-todo-in-toc
2311 (not (member (match-string 2 line
)
2312 org-done-keywords
)))
2314 (and org-export-mark-todo-in-toc
2316 (org-search-todo-below
2317 line lines level
))))
2318 (setq txt
(org-html-expand-for-ascii txt
))
2320 (while (string-match org-bracket-link-regexp txt
)
2323 (match-string (if (match-end 2) 3 1) txt
)
2326 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2328 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2330 (setq txt
(replace-match "" t t txt
)))
2331 (if (string-match quote-re0 txt
)
2332 (setq txt
(replace-match "" t t txt
)))
2334 (if org-export-with-section-numbers
2335 (setq txt
(concat (org-section-number level
)
2337 (if (<= level umax-toc
)
2342 (* (max 0 (- level org-min-level
)) 4) ?\
)
2343 (format (if todo
"%s (*)\n" "%s\n") txt
))
2345 (setq org-last-level level
))
2348 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2350 (org-init-section-numbers)
2351 (while (setq line
(pop lines
))
2352 ;; Remove the quoted HTML tags.
2353 (setq line
(org-html-expand-for-ascii line
))
2355 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
2356 (setq line
(replace-match "" t t line
)))
2357 ;; Replace internal links
2358 (while (string-match org-bracket-link-regexp line
)
2359 (setq line
(replace-match
2360 (if (match-end 3) "[\\3]" "[\\1]")
2363 (setq line
(org-translate-time line
)))
2365 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2367 (setq first-heading-pos
(or first-heading-pos
(point)))
2368 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2369 txt
(match-string 2 line
))
2370 (org-ascii-level-start level txt umax lines
))
2372 ((and org-export-with-tables
2373 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2374 (if (not table-open
)
2376 (setq table-open t table-buffer nil
))
2378 (setq table-buffer
(cons line table-buffer
))
2379 (when (or (not lines
)
2380 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2382 (setq table-open nil
2383 table-buffer
(nreverse table-buffer
))
2386 (org-fix-indentation x org-ascii-current-indentation
))
2387 (org-format-table-ascii table-buffer
)
2390 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2391 (if (and org-export-with-fixed-width
2392 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2393 (setq line
(replace-match "\\1" nil nil line
)))
2394 (insert line
"\n"))))
2398 ;; insert the table of contents
2400 (goto-char (point-min))
2401 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2403 (goto-char (match-beginning 0))
2405 (goto-char first-heading-pos
))
2406 (mapc 'insert thetoc
)
2407 (or (looking-at "[ \t]*\n[ \t]*\n")
2410 ;; Convert whitespace place holders
2411 (goto-char (point-min))
2413 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2414 (setq end
(next-single-property-change beg
'org-whitespace
))
2416 (delete-region beg end
)
2417 (insert (make-string (- end beg
) ?\
))))
2420 ;; remove display and invisible chars
2422 (goto-char (point-min))
2423 (while (setq beg
(next-single-property-change (point) 'display
))
2424 (setq end
(next-single-property-change beg
'display
))
2425 (delete-region beg end
)
2428 (goto-char (point-min))
2429 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2430 (setq end
(next-single-property-change beg
'org-cwidth
))
2431 (delete-region beg end
)
2433 (goto-char (point-min))))
2435 (defun org-export-ascii-preprocess ()
2436 "Do extra work for ASCII export"
2437 (goto-char (point-min))
2438 (while (re-search-forward org-verbatim-re nil t
)
2439 (goto-char (match-end 2))
2440 (backward-delete-char 1) (insert "'")
2441 (goto-char (match-beginning 2))
2442 (delete-char 1) (insert "`")
2443 (goto-char (match-end 2))))
2445 (defun org-search-todo-below (line lines level
)
2446 "Search the subtree below LINE for any TODO entries."
2447 (let ((rest (cdr (memq line lines
)))
2448 (re org-todo-line-regexp
)
2451 (while (setq line
(pop rest
))
2452 (if (string-match re line
)
2454 (setq lv
(- (match-end 1) (match-beginning 1))
2455 todo
(and (match-beginning 2)
2456 (not (member (match-string 2 line
)
2457 org-done-keywords
))))
2459 (if (<= lv level
) (throw 'exit nil
))
2460 (if todo
(throw 'exit t
))))))))
2462 (defun org-html-expand-for-ascii (line)
2463 "Handle quoted HTML for ASCII export."
2464 (if org-export-html-expand
2465 (while (string-match "@<[^<>\n]*>" line
)
2466 ;; We just remove the tags for now.
2467 (setq line
(replace-match "" nil nil line
))))
2470 (defun org-insert-centered (s &optional underline
)
2471 "Insert the string S centered and underline it with character UNDERLINE."
2472 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2473 (insert (make-string ind ?\
) s
"\n")
2475 (insert (make-string ind ?\
)
2476 (make-string (string-width s
) underline
)
2479 (defun org-ascii-level-start (level title umax
&optional lines
)
2480 "Insert a new level in ASCII export."
2481 (let (char (n (- level umax
1)) (ind 0))
2484 (insert (make-string (* 2 n
) ?\
)
2485 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2486 org-export-ascii-bullets
))
2488 ;; find the indentation of the next non-empty line
2491 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2492 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2493 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2495 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2496 (if (or (not (equal (char-before) ?
\n))
2497 (not (equal (char-before (1- (point))) ?
\n)))
2499 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2500 (unless org-export-with-tags
2501 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2502 (setq title
(replace-match "" t t title
))))
2503 (if org-export-with-section-numbers
2504 (setq title
(concat (org-section-number level
) " " title
)))
2505 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2506 (setq org-ascii-current-indentation
'(0 .
0)))))
2509 (defun org-export-visible (type arg
)
2510 "Create a copy of the visible part of the current buffer, and export it.
2511 The copy is created in a temporary buffer and removed after use.
2512 TYPE is the final key (as a string) that also select the export command in
2513 the `C-c C-e' export dispatcher.
2514 As a special case, if the you type SPC at the prompt, the temporary
2515 org-mode file will not be removed but presented to you so that you can
2516 continue to use it. The prefix arg ARG is passed through to the exporting
2520 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2521 (read-char-exclusive))
2522 current-prefix-arg
))
2523 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2524 (error "Invalid export key"))
2525 (let* ((binding (cdr (assoc type
2526 '((?a . org-export-as-ascii
)
2527 (?\C-a . org-export-as-ascii
)
2528 (?b . org-export-as-html-and-open
)
2529 (?\C-b . org-export-as-html-and-open
)
2530 (?h . org-export-as-html
)
2531 (?H . org-export-as-html-to-buffer
)
2532 (?R . org-export-region-as-html
)
2533 (?x . org-export-as-xoxo
)))))
2534 (keepp (equal type ?\
))
2535 (file buffer-file-name
)
2536 (buffer (get-buffer-create "*Org Export Visible*"))
2538 ;; Need to hack the drawers here.
2540 (goto-char (point-min))
2541 (while (re-search-forward org-drawer-regexp nil t
)
2542 (goto-char (match-beginning 1))
2543 (or (org-invisible-p) (org-flag-drawer nil
))))
2544 (with-current-buffer buffer
(erase-buffer))
2546 (setq s
(goto-char (point-min)))
2547 (while (not (= (point) (point-max)))
2548 (goto-char (org-find-invisible))
2549 (append-to-buffer buffer s
(point))
2550 (setq s
(goto-char (org-find-visible))))
2551 (org-cycle-hide-drawers 'all
)
2552 (goto-char (point-min))
2554 ;; Copy all comment lines to the end, to make sure #+ settings are
2555 ;; still available for the second export step. Kind of a hack, but
2556 ;; does do the trick.
2557 (if (looking-at "#[^\r\n]*")
2558 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2559 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2560 (append-to-buffer buffer
(1+ (match-beginning 0))
2561 (min (point-max) (1+ (match-end 0))))))
2563 (let ((buffer-file-name file
)
2564 (org-inhibit-startup t
))
2567 (unless keepp
(funcall binding arg
))))
2569 (kill-buffer buffer
)
2570 (switch-to-buffer-other-window buffer
)
2571 (goto-char (point-min)))))
2573 (defun org-find-visible ()
2575 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2576 (get-char-property s
'invisible
)))
2578 (defun org-find-invisible ()
2580 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2581 (not (get-char-property s
'invisible
))))
2586 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2587 (defun org-get-current-options ()
2588 "Return a string with current options as keyword options.
2589 Does include HTML export options as well as TODO and CATEGORY stuff."
2590 (require 'org-archive
)
2597 #+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
2599 #+EXPORT_SELECT_TAGS: %s
2600 #+EXPORT_EXCLUDE_TAGS: %s
2606 #+PRIORITIES: %c %c %c
2608 #+STARTUP: %s %s %s %s %s
2614 (buffer-name) (user-full-name) user-mail-address
2615 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2616 org-export-default-language
2617 org-export-headline-levels
2618 org-export-with-section-numbers
2620 org-export-preserve-breaks
2621 org-export-html-expand
2622 org-export-with-fixed-width
2623 org-export-with-tables
2624 org-export-with-sub-superscripts
2625 org-export-with-special-strings
2626 org-export-with-footnotes
2627 org-export-with-emphasize
2628 org-export-with-TeX-macros
2629 org-export-with-LaTeX-fragments
2630 org-export-skip-text-before-1st-heading
2631 org-export-with-drawers
2632 org-export-with-tags
2633 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2634 (mapconcat 'identity org-export-select-tags
" ")
2635 (mapconcat 'identity org-export-exclude-tags
" ")
2636 org-export-html-link-up
2637 org-export-html-link-home
2638 (file-name-nondirectory buffer-file-name
)
2639 "TODO FEEDBACK VERIFY DONE"
2640 "Me Jason Marie DONE"
2641 org-highest-priority org-lowest-priority org-default-priority
2642 (mapconcat 'identity org-drawers
" ")
2643 (cdr (assoc org-startup-folded
2644 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2645 (if org-odd-levels-only
"odd" "oddeven")
2646 (if org-hide-leading-stars
"hidestars" "showstars")
2647 (if org-startup-align-all-tables
"align" "noalign")
2648 (cond ((eq org-log-done t
) "logdone")
2649 ((equal org-log-done
'note
) "lognotedone")
2650 ((not org-log-done
) "nologdone"))
2651 (or (mapconcat (lambda (x)
2653 ((equal '(:startgroup
) x
) "{")
2654 ((equal '(:endgroup
) x
) "}")
2655 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2657 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2658 (mapconcat 'identity org-file-tags
" ")
2659 org-archive-location
2660 "org file:~/org/%s.org"
2663 (defun org-export-html-preprocess (parameters)
2664 ;; Convert LaTeX fragments to images
2665 (when (plist-get parameters
:LaTeX-fragments
)
2667 (concat "ltxpng/" (file-name-sans-extension
2668 (file-name-nondirectory
2669 org-current-export-file
)))
2670 org-current-export-dir nil
"Creating LaTeX image %s"))
2671 (message "Exporting..."))
2674 (defun org-insert-export-options-template ()
2675 "Insert into the buffer a template with information for exporting."
2677 (if (not (bolp)) (newline))
2678 (let ((s (org-get-current-options)))
2679 (and (string-match "#\\+CATEGORY" s
)
2680 (setq s
(substring s
0 (match-beginning 0))))
2684 (defun org-export-as-html-and-open (arg)
2685 "Export the outline as HTML and immediately open it with a browser.
2686 If there is an active region, export only the region.
2687 The prefix ARG specifies how many levels of the outline should become
2688 headlines. The default is 3. Lower levels will become bulleted lists."
2690 (org-export-as-html arg
'hidden
)
2691 (org-open-file buffer-file-name
))
2694 (defun org-export-as-html-batch ()
2695 "Call `org-export-as-html', may be used in batch processing as
2697 --load=$HOME/lib/emacs/org.el
2698 --eval \"(setq org-export-headline-levels 2)\"
2699 --visit=MyFile --funcall org-export-as-html-batch"
2700 (org-export-as-html org-export-headline-levels
'hidden
))
2703 (defun org-export-as-html-to-buffer (arg)
2704 "Call `org-exort-as-html` with output to a temporary buffer.
2705 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2707 (org-export-as-html arg nil nil
"*Org HTML Export*")
2708 (switch-to-buffer-other-window "*Org HTML Export*"))
2711 (defun org-replace-region-by-html (beg end
)
2712 "Assume the current region has org-mode syntax, and convert it to HTML.
2713 This can be used in any buffer. For example, you could write an
2714 itemized list in org-mode syntax in an HTML buffer and then use this
2715 command to convert it."
2717 (let (reg html buf pop-up-frames
)
2718 (save-window-excursion
2720 (setq html
(org-export-region-as-html
2722 (setq reg
(buffer-substring beg end
)
2723 buf
(get-buffer-create "*Org tmp*"))
2724 (with-current-buffer buf
2728 (setq html
(org-export-region-as-html
2729 (point-min) (point-max) t
'string
)))
2731 (delete-region beg end
)
2735 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2736 "Convert region from BEG to END in org-mode buffer to HTML.
2737 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2738 contents, and only produce the region of converted text, useful for
2739 cut-and-paste operations.
2740 If BUFFER is a buffer or a string, use/create that buffer as a target
2741 of the converted HTML. If BUFFER is the symbol `string', return the
2742 produced HTML as a string and leave not buffer behind. For example,
2743 a Lisp program could call this function in the following way:
2745 (setq html (org-export-region-as-html beg end t 'string))
2747 When called interactively, the output buffer is selected, and shown
2748 in a window. A non-interactive call will only return the buffer."
2749 (interactive "r\nP")
2750 (when (interactive-p)
2751 (setq buffer
"*Org HTML Export*"))
2752 (let ((transient-mark-mode t
) (zmacs-regions t
)
2754 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
2756 (set-mark (point)) ;; to activate the region
2758 (setq rtn
(org-export-as-html
2761 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2762 (if (and (interactive-p) (bufferp rtn
))
2763 (switch-to-buffer-other-window rtn
)
2766 (defvar html-table-tag nil
) ; dynamically scoped into this.
2768 (defun org-export-as-html (arg &optional hidden ext-plist
2769 to-buffer body-only pub-dir
)
2770 "Export the outline as a pretty HTML file.
2771 If there is an active region, export only the region. The prefix
2772 ARG specifies how many levels of the outline should become
2773 headlines. The default is 3. Lower levels will become bulleted
2774 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2775 EXT-PLIST is a property list with external parameters overriding
2776 org-mode's default settings, but still inferior to file-local
2777 settings. When TO-BUFFER is non-nil, create a buffer with that
2778 name and export to that buffer. If TO-BUFFER is the symbol
2779 `string', don't leave any buffer behind but just return the
2780 resulting HTML as a string. When BODY-ONLY is set, don't produce
2781 the file header and footer, simply return the content of
2782 <body>...</body>, without even the body tags themselves. When
2783 PUB-DIR is set, use this as the publishing directory."
2786 ;; Make sure we have a file name when we need it.
2787 (when (and (not (or to-buffer body-only
))
2788 (not buffer-file-name
))
2789 (if (buffer-base-buffer)
2790 (org-set-local 'buffer-file-name
2791 (with-current-buffer (buffer-base-buffer)
2793 (error "Need a file name to be able to export.")))
2795 (message "Exporting...")
2796 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2797 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2798 (setq-default org-done-keywords org-done-keywords
)
2799 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2801 (org-export-process-option-filters
2802 (org-combine-plists (org-default-export-plist)
2804 (org-infile-export-plist))))
2806 (style (concat org-export-html-style-default
2807 (plist-get opt-plist
:style
)
2808 (plist-get opt-plist
:style-extra
)))
2809 (html-extension (plist-get opt-plist
:html-extension
))
2810 (link-validate (plist-get opt-plist
:link-validation-function
))
2811 valid thetoc have-headings first-heading-pos
2812 (odd org-odd-levels-only
)
2813 (region-p (org-region-active-p))
2814 (rbeg (and region-p
(region-beginning)))
2815 (rend (and region-p
(region-end)))
2817 (if (plist-get opt-plist
:ignore-subree-p
)
2822 (and (org-at-heading-p)
2823 (>= (org-end-of-subtree t t
) rend
))))))
2824 (opt-plist (if subtree-p
2825 (org-export-add-subtree-options opt-plist rbeg
)
2827 ;; The following two are dynamically scoped into other
2829 (org-current-export-dir
2830 (or pub-dir
(org-export-directory :html opt-plist
)))
2831 (org-current-export-file buffer-file-name
)
2832 (level 0) (line "") (origline "") txt todo
2835 (filename (if to-buffer nil
2838 (file-name-sans-extension
2840 (org-entry-get (region-beginning)
2841 "EXPORT_FILE_NAME" t
))
2842 (file-name-nondirectory buffer-file-name
)))
2844 (file-name-as-directory
2845 (or pub-dir
(org-export-directory :html opt-plist
))))))
2846 (current-dir (if buffer-file-name
2847 (file-name-directory buffer-file-name
)
2849 (buffer (if to-buffer
2851 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2852 (t (get-buffer-create to-buffer
)))
2853 (find-file-noselect filename
)))
2854 (org-levels-open (make-vector org-level-max nil
))
2855 (date (plist-get opt-plist
:date
))
2856 (author (plist-get opt-plist
:author
))
2857 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2858 (plist-get opt-plist
:title
)
2860 (plist-get opt-plist
:skip-before-1st-heading
))
2861 (org-export-grab-title-from-buffer))
2862 (and buffer-file-name
2863 (file-name-sans-extension
2864 (file-name-nondirectory buffer-file-name
)))
2866 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2867 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2868 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2873 (local-list-type nil
)
2874 (local-list-indent nil
)
2875 (llt org-plain-list-ordered-item-terminator
)
2876 (email (plist-get opt-plist
:email
))
2877 (language (plist-get opt-plist
:language
))
2881 (coding-system (and (boundp 'buffer-file-coding-system
)
2882 buffer-file-coding-system
))
2883 (coding-system-for-write (or org-export-html-coding-system
2885 (save-buffer-coding-system (or org-export-html-coding-system
2887 (charset (and coding-system-for-write
2888 (fboundp 'coding-system-get
)
2889 (coding-system-get coding-system-for-write
2893 (if region-p
(region-beginning) (point-min))
2894 (if region-p
(region-end) (point-max))))
2897 (org-export-preprocess-string
2901 :skip-before-1st-heading
2902 (plist-get opt-plist
:skip-before-1st-heading
)
2903 :drawers
(plist-get opt-plist
:drawers
)
2905 (plist-get opt-plist
:archived-trees
)
2906 :select-tags
(plist-get opt-plist
:select-tags
)
2907 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2909 (plist-get opt-plist
:text
)
2911 (plist-get opt-plist
:LaTeX-fragments
))
2914 table-buffer table-orig-buffer
2915 ind item-type starter didclose
2916 rpl path attr desc descp desc1 desc2 link
2917 snumber fnc item-tag
2920 (let ((inhibit-read-only t
))
2922 (remove-text-properties (point-min) (point-max)
2923 '(:org-license-to-kill t
))))
2925 (message "Exporting...")
2927 (setq org-min-level
(org-get-min-level lines
))
2928 (setq org-last-level org-min-level
)
2929 (org-init-section-numbers)
2932 ((and date
(string-match "%" date
))
2933 (setq date
(format-time-string date
)))
2935 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2937 ;; Get the language-dependent settings
2938 (setq lang-words
(or (assoc language org-export-language-setup
)
2939 (assoc "en" org-export-language-setup
)))
2941 ;; Switch to the output buffer
2943 (let ((inhibit-read-only t
)) (erase-buffer))
2946 (and (fboundp 'set-buffer-file-coding-system
)
2947 (set-buffer-file-coding-system coding-system-for-write
))
2949 (let ((case-fold-search nil
)
2950 (org-odd-levels-only odd
))
2951 ;; create local variables for all options, to make sure all called
2952 ;; functions get the correct information
2954 (set (make-local-variable (cdr x
))
2955 (plist-get opt-plist
(car x
))))
2956 org-export-plist-vars
)
2957 (setq umax
(if arg
(prefix-numeric-value arg
)
2958 org-export-headline-levels
))
2959 (setq umax-toc
(if (integerp org-export-with-toc
)
2960 (min org-export-with-toc umax
)
2965 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2966 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2967 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2968 lang=\"%s\" xml:lang=\"%s\">
2971 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2972 <meta name=\"generator\" content=\"Org-mode\"/>
2973 <meta name=\"generated\" content=\"%s\"/>
2974 <meta name=\"author\" content=\"%s\"/>
2978 language language
(org-html-expand title
)
2979 (or charset
"iso-8859-1") date author style
))
2981 (insert (or (plist-get opt-plist
:preamble
) ""))
2983 (when (plist-get opt-plist
:auto-preamble
)
2984 (if title
(insert (format org-export-html-title-format
2985 (org-html-expand title
))))))
2987 (if (and org-export-with-toc
(not body-only
))
2989 (push (format "<h%d>%s</h%d>\n"
2990 org-export-html-toplevel-hlevel
2992 org-export-html-toplevel-hlevel
)
2994 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2995 (push "<ul>\n<li>" thetoc
)
2997 (mapcar '(lambda (line)
2998 (if (string-match org-todo-line-regexp line
)
2999 ;; This is a headline
3001 (setq have-headings t
)
3002 (setq level
(- (match-end 1) (match-beginning 1))
3003 level
(org-tr-level level
)
3004 txt
(save-match-data
3006 (org-export-cleanup-toc-line
3007 (match-string 3 line
))))
3009 (or (and org-export-mark-todo-in-toc
3011 (not (member (match-string 2 line
)
3012 org-done-keywords
)))
3014 (and org-export-mark-todo-in-toc
3016 (org-search-todo-below
3017 line lines level
))))
3019 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3020 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3021 (if (string-match quote-re0 txt
)
3022 (setq txt
(replace-match "" t t txt
)))
3023 (setq snumber
(org-section-number level
))
3024 (if org-export-with-section-numbers
3025 (setq txt
(concat snumber
" " txt
)))
3026 (if (<= level
(max umax umax-toc
))
3027 (setq head-count
(+ head-count
1)))
3028 (if (<= level umax-toc
)
3030 (if (> level org-last-level
)
3032 (setq cnt
(- level org-last-level
))
3033 (while (>= (setq cnt
(1- cnt
)) 0)
3034 (push "\n<ul>\n<li>" thetoc
))
3035 (push "\n" thetoc
)))
3036 (if (< level org-last-level
)
3038 (setq cnt
(- org-last-level level
))
3039 (while (>= (setq cnt
(1- cnt
)) 0)
3040 (push "</li>\n</ul>" thetoc
))
3041 (push "\n" thetoc
)))
3042 ;; Check for targets
3043 (while (string-match org-any-target-regexp line
)
3044 (setq line
(replace-match
3045 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3047 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3048 (setq txt
(replace-match "" t t txt
)))
3052 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3053 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3054 snumber txt
) thetoc
)
3056 (setq org-last-level level
))
3060 (while (> org-last-level
(1- org-min-level
))
3061 (setq org-last-level
(1- org-last-level
))
3062 (push "</li>\n</ul>\n" thetoc
))
3063 (push "</div>\n" thetoc
)
3064 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3067 (org-init-section-numbers)
3071 (while (setq line
(pop lines
) origline line
)
3074 ;; end of quote section?
3075 (when (and inquote
(string-match "^\\*+ " line
))
3078 ;; inside a quote section?
3080 (insert (org-html-protect line
) "\n")
3081 (throw 'nextline nil
))
3083 ;; Fixed-width, verbatim lines (examples)
3084 (when (and org-export-with-fixed-width
3085 (string-match "^[ \t]*:\\(.*\\)" line
))
3088 (insert "<pre class=\"example\">\n"))
3089 (insert (org-html-protect (match-string 1 line
)) "\n")
3090 (when (or (not lines
)
3091 (not (string-match "^[ \t]*\\(:.*\\)"
3094 (insert "</pre>\n"))
3095 (throw 'nextline nil
))
3098 (when (get-text-property 0 'org-protected line
)
3100 (when (re-search-backward
3101 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3102 (setq par
(match-string 1))
3103 (replace-match "\\2\n"))
3106 (not (string-match "^[ \t]*:" (car lines
)))
3107 (or (= (length (car lines
)) 0)
3108 (get-text-property 0 'org-protected
(car lines
))))
3109 (insert (pop lines
) "\n"))
3110 (and par
(insert "<p>\n")))
3111 (throw 'nextline nil
))
3114 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3115 (insert "\n<hr/>\n")
3116 (throw 'nextline nil
))
3118 ;; Blockquotes and verse
3119 (when (equal "ORG-BLOCKQUOTE-START" line
)
3120 (insert "<blockquote>\n<p>\n")
3121 (throw 'nextline nil
))
3122 (when (equal "ORG-BLOCKQUOTE-END" line
)
3123 (insert "</p>\n</blockquote>\n")
3124 (throw 'nextline nil
))
3125 (when (equal "ORG-VERSE-START" line
)
3126 (insert "\n<p class=\"verse\">\n")
3128 (throw 'nextline nil
))
3129 (when (equal "ORG-VERSE-END" line
)
3132 (throw 'nextline nil
))
3134 (let ((i (org-get-string-indentation line
)))
3136 (setq line
(concat (mapconcat 'identity
3137 (make-list (* 2 i
) "\\nbsp") "")
3138 " " (org-trim line
))))
3139 (setq line
(concat line
" \\\\"))))
3141 ;; make targets to anchors
3142 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3145 (setq line
(replace-match
3146 (concat "@<a name=\""
3147 (org-solidify-link-text (match-string 1 line
))
3150 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3151 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3152 (setq line
(replace-match
3153 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3154 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3157 (setq line
(replace-match
3158 (concat "@<a name=\""
3159 (org-solidify-link-text (match-string 1 line
))
3160 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3163 (setq line
(org-html-handle-time-stamps line
))
3165 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3166 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3167 ;; Also handle sub_superscripts and checkboxes
3168 (or (string-match org-table-hline-regexp line
)
3169 (setq line
(org-html-expand line
)))
3173 (while (string-match org-bracket-link-analytic-regexp line start
)
3174 (setq start
(match-beginning 0))
3175 (setq path
(save-match-data (org-link-unescape
3176 (match-string 3 line
))))
3178 ((match-end 2) (match-string 2 line
))
3180 (or (file-name-absolute-p path
)
3181 (string-match "^\\.\\.?/" path
)))
3184 (setq path
(org-extract-attributes path
))
3185 (setq attr
(org-attributes-to-string
3186 (get-text-property 0 'org-attributes path
)))
3187 (setq desc1
(if (match-end 5) (match-string 5 line
))
3188 desc2
(if (match-end 2) (concat type
":" path
) path
)
3189 descp
(and desc1
(not (equal desc1 desc2
)))
3190 desc
(or desc1 desc2
))
3191 ;; Make an image out of the description if that is so wanted
3192 (when (and descp
(org-file-image-p desc
))
3194 (if (string-match "^file:" desc
)
3195 (setq desc
(substring desc
(match-end 0)))))
3196 (setq desc
(concat "<img src=\"" desc
"\"/>")))
3197 ;; FIXME: do we need to unescape here somewhere?
3199 ((equal type
"internal")
3203 (org-solidify-link-text
3204 (save-match-data (org-link-unescape path
)) nil
)
3205 "\"" attr
">" desc
"</a>")))
3206 ((member type
'("http" "https"))
3207 ;; standard URL, just check if we need to inline an image
3208 (if (and (or (eq t org-export-html-inline-images
)
3209 (and org-export-html-inline-images
(not descp
)))
3210 (org-file-image-p path
))
3211 (setq rpl
(concat "<img src=\"" type
":" path
"\"" attr
"/>"))
3212 (setq link
(concat type
":" path
))
3213 (setq rpl
(concat "<a href=\"" link
"\"" attr
">"
3215 ((member type
'("ftp" "mailto" "news"))
3217 (setq link
(concat type
":" path
))
3218 (setq rpl
(concat "<a href=\"" link
"\"" attr
">" desc
"</a>")))
3220 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3221 ;; The link protocol has a function for format the link
3224 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3226 ((string= type
"file")
3228 (let* ((filename path
)
3229 (abs-p (file-name-absolute-p filename
))
3230 thefile file-is-image-p search
)
3232 (if (string-match "::\\(.*\\)" filename
)
3233 (setq search
(match-string 1 filename
)
3234 filename
(replace-match "" t nil filename
)))
3236 (if (functionp link-validate
)
3237 (funcall link-validate filename current-dir
)
3239 (setq file-is-image-p
(org-file-image-p filename
))
3240 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3241 (when (and org-export-html-link-org-files-as-html
3242 (string-match "\\.org$" thefile
))
3243 (setq thefile
(concat (substring thefile
0
3244 (match-beginning 0))
3245 "." html-extension
))
3247 ;; make sure this is can be used as target search
3248 (not (string-match "^[0-9]*$" search
))
3249 (not (string-match "^\\*" search
))
3250 (not (string-match "^/.*/$" search
)))
3251 (setq thefile
(concat thefile
"#"
3252 (org-solidify-link-text
3253 (org-link-unescape search
)))))
3254 (when (string-match "^file:" desc
)
3255 (setq desc
(replace-match "" t t desc
))
3256 (if (string-match "\\.org$" desc
)
3257 (setq desc
(replace-match "" t t desc
))))))
3258 (setq rpl
(if (and file-is-image-p
3259 (or (eq t org-export-html-inline-images
)
3260 (and org-export-html-inline-images
3262 (concat "<img src=\"" thefile
"\"" attr
"/>")
3263 (concat "<a href=\"" thefile
"\"" attr
">"
3265 (if (not valid
) (setq rpl desc
))))
3268 ;; just publish the path, as default
3269 (setq rpl
(concat "<i><" type
":"
3270 (save-match-data (org-link-unescape path
))
3272 (setq line
(replace-match rpl t t line
)
3273 start
(+ start
(length rpl
))))
3276 (if (and (string-match org-todo-line-regexp line
)
3277 (match-beginning 2))
3280 (concat (substring line
0 (match-beginning 2))
3282 (if (member (match-string 2 line
)
3285 "\">" (match-string 2 line
)
3286 "</span>" (substring line
(match-end 2)))))
3288 ;; Does this contain a reference to a footnote?
3289 (when org-export-with-footnotes
3291 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3292 (if (get-text-property (match-beginning 2) 'org-protected line
)
3293 (setq start
(match-end 2))
3294 (let ((n (match-string 2 line
)))
3298 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3299 (match-string 1 line
) n n n
)
3303 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3304 ;; This is a headline
3305 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3306 txt
(match-string 2 line
))
3307 (if (string-match quote-re0 txt
)
3308 (setq txt
(replace-match "" t t txt
)))
3309 (if (<= level
(max umax umax-toc
))
3310 (setq head-count
(+ head-count
1)))
3312 ;; Close any local lists before inserting a new header line
3313 (while local-list-type
3314 (org-close-li (car local-list-type
))
3315 (insert (format "</%sl>\n" (car local-list-type
)))
3316 (pop local-list-type
))
3317 (setq local-list-indent nil
3319 (setq first-heading-pos
(or first-heading-pos
(point)))
3320 (org-html-level-start level txt umax
3321 (and org-export-with-toc
(<= level umax
))
3324 (when (string-match quote-re line
)
3328 ((and org-export-with-tables
3329 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3330 (if (not table-open
)
3332 (setq table-open t table-buffer nil table-orig-buffer nil
))
3334 (setq table-buffer
(cons line table-buffer
)
3335 table-orig-buffer
(cons origline table-orig-buffer
))
3336 (when (or (not lines
)
3337 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3339 (setq table-open nil
3340 table-buffer
(nreverse table-buffer
)
3341 table-orig-buffer
(nreverse table-orig-buffer
))
3342 (org-close-par-maybe)
3343 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3348 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3349 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3350 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3351 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3353 (setq ind
(org-get-string-indentation line
)
3354 item-type
(if (match-beginning 4) "o" "u")
3355 starter
(if (match-beginning 2)
3356 (substring (match-string 2 line
) 0 -
1))
3357 line
(substring line
(match-beginning 5))
3359 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3361 item-tag
(match-string 1 line
)
3362 line
(substring line
(match-end 0))))
3363 (when (and (not (equal item-type
"d"))
3364 (not (string-match "[^ \t]" line
)))
3365 ;; empty line. Pretend indentation is large.
3366 (setq ind
(if org-empty-line-terminates-plain-lists
3368 (1+ (or (car local-list-indent
) 1)))))
3370 (while (and in-local-list
3371 (or (and (= ind
(car local-list-indent
))
3373 (< ind
(car local-list-indent
))))
3375 (org-close-li (car local-list-type
))
3376 (insert (format "</%sl>\n" (car local-list-type
)))
3377 (pop local-list-type
) (pop local-list-indent
)
3378 (setq in-local-list local-list-indent
))
3381 (or (not in-local-list
)
3382 (> ind
(car local-list-indent
))))
3383 ;; Start new (level of) list
3384 (org-close-par-maybe)
3386 ((equal item-type
"u") "<ul>\n<li>\n")
3387 ((equal item-type
"o") "<ol>\n<li>\n")
3388 ((equal item-type
"d")
3389 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3390 (push item-type local-list-type
)
3391 (push ind local-list-indent
)
3392 (setq in-local-list t
))
3394 ;; continue current list
3395 (org-close-li (car local-list-type
))
3397 ((equal (car local-list-type
) "d")
3398 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3401 ;; we did close a list, normal text follows: need <p>
3403 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3406 (if (equal (match-string 1 line
) "X")
3408 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3411 ;; Empty lines start a new paragraph. If hand-formatted lists
3412 ;; are not fully interpreted, lines starting with "-", "+", "*"
3413 ;; also start a new paragraph.
3414 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3416 ;; Is this the start of a footnote?
3417 (when org-export-with-footnotes
3418 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3419 (org-close-par-maybe)
3420 (let ((n (match-string 1 line
)))
3421 (setq line
(replace-match
3422 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
))
3423 (setq line
(concat line
"</p>")))))
3425 ;; Check if the line break needs to be conserved
3427 ((string-match "\\\\\\\\[ \t]*$" line
)
3428 (setq line
(replace-match "<br/>" t t line
)))
3429 (org-export-preserve-breaks
3430 (setq line
(concat line
"<br/>"))))
3432 (insert line
"\n")))))
3434 ;; Properly close all local lists and other lists
3435 (when inquote
(insert "</pre>\n"))
3437 ;; Close any local lists before inserting a new header line
3438 (while local-list-type
3439 (org-close-li (car local-list-type
))
3440 (insert (format "</%sl>\n" (car local-list-type
)))
3441 (pop local-list-type
))
3442 (setq local-list-indent nil
3444 (org-html-level-start 1 nil umax
3445 (and org-export-with-toc
(<= level umax
))
3447 ;; the </div> to close the last text-... div.
3451 (when (plist-get opt-plist
:auto-postamble
)
3452 (insert "<div id=\"postamble\">")
3453 (when (and org-export-author-info author
)
3454 (insert "<p class=\"author\"> "
3455 (nth 1 lang-words
) ": " author
"\n")
3457 (if (listp (split-string email
",+ *"))
3459 (insert "<a href=\"mailto:" e
"\"><"
3461 (split-string email
",+ *"))
3462 (insert "<a href=\"mailto:" email
"\"><"
3463 email
"></a>\n")))
3465 (when (and date org-export-time-stamp-file
)
3466 (insert "<p class=\"date\"> "
3467 (nth 2 lang-words
) ": "
3469 (when org-export-creator-info
3470 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3471 org-version emacs-major-version
)))
3474 (if org-export-html-with-timestamp
3475 (insert org-export-html-html-helper-timestamp
))
3476 (insert (or (plist-get opt-plist
:postamble
) ""))
3477 (insert "</body>\n</html>\n"))
3479 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3481 (if (eq major-mode default-major-mode
) (html-mode)))
3483 ;; insert the table of contents
3484 (goto-char (point-min))
3486 (if (or (re-search-forward
3487 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3489 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3491 (goto-char (match-beginning 0))
3493 (goto-char first-heading-pos
)
3494 (when (looking-at "\\s-*</p>")
3495 (goto-char (match-end 0))
3497 (insert "<div id=\"table-of-contents\">\n")
3498 (mapc 'insert thetoc
)
3499 (insert "</div>\n"))
3500 ;; remove empty paragraphs and lists
3501 (goto-char (point-min))
3502 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3504 (goto-char (point-min))
3505 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3507 (goto-char (point-min))
3508 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3510 ;; Convert whitespace place holders
3511 (goto-char (point-min))
3513 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3514 (setq n
(get-text-property beg
'org-whitespace
)
3515 end
(next-single-property-change beg
'org-whitespace
))
3517 (delete-region beg end
)
3518 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3519 (make-string n ?x
)))))
3520 (or to-buffer
(save-buffer))
3521 (goto-char (point-min))
3522 (message "Exporting... done")
3523 (if (eq to-buffer
'string
)
3524 (prog1 (buffer-substring (point-min) (point-max))
3525 (kill-buffer (current-buffer)))
3526 (current-buffer)))))
3529 (defvar org-table-colgroup-info nil
)
3530 (defun org-format-table-ascii (lines)
3531 "Format a table for ascii export."
3533 (setq lines
(org-split-string lines
"\n")))
3534 (if (not (string-match "^[ \t]*|" (car lines
)))
3535 ;; Table made by table.el - test for spanning
3538 ;; A normal org table
3539 ;; Get rid of hlines at beginning and end
3540 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3541 (setq lines
(nreverse lines
))
3542 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3543 (setq lines
(nreverse lines
))
3544 (when org-export-table-remove-special-lines
3545 ;; Check if the table has a marking column. If yes remove the
3546 ;; column and the special lines
3547 (setq lines
(org-table-clean-before-export lines
)))
3548 ;; Get rid of the vertical lines except for grouping
3549 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3551 (while (setq line
(pop lines
))
3552 (if (string-match org-table-hline-regexp line
)
3553 (and (string-match "|\\(.*\\)|" line
)
3554 (setq line
(replace-match " \\1" t nil line
)))
3555 (setq start
0 vl1 vl
)
3556 (while (string-match "|" line start
)
3557 (setq start
(match-end 0))
3558 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3562 (defun org-colgroup-info-to-vline-list (info)
3565 (setq last new new
(pop info
))
3566 (if (or (memq last
'(:end
:startend
))
3567 (memq new
'(:start
:startend
)))
3570 (setq vl
(nreverse vl
))
3571 (and vl
(setcar vl nil
))
3574 (defvar org-table-number-regexp
) ; defined in org-table.el
3575 (defun org-format-table-html (lines olines
)
3576 "Find out which HTML converter to use and return the HTML code."
3578 (setq lines
(org-split-string lines
"\n")))
3579 (if (string-match "^[ \t]*|" (car lines
))
3580 ;; A normal org table
3581 (org-format-org-table-html lines
)
3582 ;; Table made by table.el - test for spanning
3583 (let* ((hlines (delq nil
(mapcar
3585 (if (string-match "^[ \t]*\\+-" x
) x
3588 (first (car hlines
))
3589 (ll (and (string-match "\\S-+" first
)
3590 (match-string 0 first
)))
3591 (re (concat "^[ \t]*" (regexp-quote ll
)))
3592 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3594 (if (and (not spanning
)
3595 (not org-export-prefer-native-exporter-for-tables
))
3596 ;; We can use my own converter with HTML conversions
3597 (org-format-table-table-html lines
)
3598 ;; Need to use the code generator in table.el, with the original text.
3599 (org-format-table-table-html-using-table-generate-source olines
)))))
3601 (defvar org-table-number-fraction
) ; defined in org-table.el
3602 (defun org-format-org-table-html (lines &optional splice
)
3603 "Format a table into HTML."
3604 (require 'org-table
)
3605 ;; Get rid of hlines at beginning and end
3606 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3607 (setq lines
(nreverse lines
))
3608 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3609 (setq lines
(nreverse lines
))
3610 (when org-export-table-remove-special-lines
3611 ;; Check if the table has a marking column. If yes remove the
3612 ;; column and the special lines
3613 (setq lines
(org-table-clean-before-export lines
)))
3615 (let ((head (and org-export-highlight-first-table-line
3617 (lambda (x) (string-match "^[ \t]*|-" x
))
3620 tbopen line fields html gr colgropen
)
3621 (if splice
(setq head nil
))
3622 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3624 (while (setq line
(pop lines
))
3626 (if (string-match "^[ \t]*|-" line
)
3629 (push (if head
"</thead>" "</tbody>") html
)
3630 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3631 (setq head nil
) ;; head ends here, first time around
3633 (throw 'next-line t
)))
3634 ;; Break the line into fields
3635 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3636 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3637 (setq nlines
(1+ nlines
) i -
1)
3638 (push (concat "<tr>"
3642 (if (and (< i nlines
)
3643 (string-match org-table-number-regexp x
))
3644 (incf (aref fnum i
)))
3646 (concat (car org-export-table-header-tags
) x
3647 (cdr org-export-table-header-tags
))
3648 (concat (car org-export-table-data-tags
) x
3649 (cdr org-export-table-data-tags
))))
3653 (unless splice
(if tbopen
(push "</tbody>" html
)))
3654 (unless splice
(push "</table>\n" html
))
3655 (setq html
(nreverse html
))
3657 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3660 (setq gr
(pop org-table-colgroup-info
))
3661 (format "%s<col align=\"%s\"></col>%s"
3662 (if (memq gr
'(:start
:startend
))
3664 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3667 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3669 (if (memq gr
'(:end
:startend
))
3670 (progn (setq colgropen nil
) "</colgroup>")
3674 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3675 (push html-table-tag html
))
3676 (concat (mapconcat 'identity html
"\n") "\n")))
3678 (defun org-table-clean-before-export (lines)
3679 "Check if the table has a marking column.
3680 If yes remove the column and the special lines."
3681 (setq org-table-colgroup-info nil
)
3684 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3685 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3688 (setq org-table-clean-did-remove-column nil
)
3693 ((string-match "^[ \t]*| */ *|" x
)
3694 (setq org-table-colgroup-info
3696 (cond ((member x
'("<" "<")) :start
)
3697 ((member x
'(">" ">")) :end
)
3698 ((member x
'("<>" "<>")) :startend
)
3700 (org-split-string x
"[ \t]*|[ \t]*")))
3704 (setq org-table-clean-did-remove-column t
)
3709 ((string-match "^[ \t]*| */ *|" x
)
3710 (setq org-table-colgroup-info
3712 (cond ((member x
'("<" "<")) :start
)
3713 ((member x
'(">" ">")) :end
)
3714 ((member x
'("<>" "<>")) :startend
)
3716 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3718 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3719 nil
) ; ignore this line
3720 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3721 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3722 ;; remove the first column
3723 (replace-match "\\1|" t nil x
))))
3726 (defun org-format-table-table-html (lines)
3727 "Format a table generated by table.el into HTML.
3728 This conversion does *not* use `table-generate-source' from table.el.
3729 This has the advantage that Org-mode's HTML conversions can be used.
3730 But it has the disadvantage, that no cell- or row-spanning is allowed."
3731 (let (line field-buffer
3732 (head org-export-highlight-first-table-line
)
3734 (setq html
(concat html-table-tag
"\n"))
3735 (while (setq line
(pop lines
))
3736 (setq empty
" ")
3738 (if (string-match "^[ \t]*\\+-" line
)
3749 (if (equal x
"") (setq x empty
))
3751 (concat (car org-export-table-header-tags
) x
3752 (cdr org-export-table-header-tags
))
3753 (concat (car org-export-table-data-tags
) x
3754 (cdr org-export-table-data-tags
))))
3758 (setq field-buffer nil
)))
3760 (throw 'next-line t
)))
3761 ;; Break the line into fields and store the fields
3762 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3764 (setq field-buffer
(mapcar
3766 (concat x
"<br/>" (pop fields
)))
3768 (setq field-buffer fields
))))
3769 (setq html
(concat html
"</table>\n"))
3772 (defun org-format-table-table-html-using-table-generate-source (lines)
3773 "Format a table into html, using `table-generate-source' from table.el.
3774 This has the advantage that cell- or row-spanning is allowed.
3775 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3777 (with-current-buffer (get-buffer-create " org-tmp1 ")
3779 (insert (mapconcat 'identity lines
"\n"))
3780 (goto-char (point-min))
3781 (if (not (re-search-forward "|[^+]" nil t
))
3782 (error "Error processing table"))
3783 (table-recognize-table)
3784 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3785 (table-generate-source 'html
" org-tmp2 ")
3786 (set-buffer " org-tmp2 ")
3787 (buffer-substring (point-min) (point-max))))
3789 (defun org-export-splice-style (style extra
)
3790 "Splice EXTRA into STYLE, just before \"</style>\"."
3791 (if (and (stringp extra
)
3792 (string-match "\\S-" extra
)
3793 (string-match "</style>" style
))
3794 (concat (substring style
0 (match-beginning 0))
3796 (substring style
(match-beginning 0)))
3799 (defun org-html-handle-time-stamps (s)
3800 "Format time stamps in string S, or remove them."
3803 (while (string-match org-maybe-keyword-time-regexp s
)
3804 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3805 ;; never export CLOCK
3807 (or b
(setq b
(substring s
0 (match-beginning 0))))
3808 (if (not org-export-with-timestamps
)
3809 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3810 s
(substring s
(match-end 0)))
3812 r
(substring s
0 (match-beginning 0))
3814 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3815 (match-string 1 s
)))
3816 (format " @<span class=\"timestamp\">%s@</span>"
3818 (org-translate-time (match-string 3 s
)) 1 -
1)))
3819 s
(substring s
(match-end 0)))))
3820 ;; Line break if line started and ended with time stamp stuff
3823 (setq r
(concat r s
))
3824 (unless (string-match "\\S-" (concat b s
))
3825 (setq r
(concat r
"@<br/>")))
3828 (defun org-export-htmlize-region-for-paste (beg end
)
3829 "Convert the region to HTML, using htmlize.el.
3830 This is much like `htmlize-region-for-paste', only that it uses
3831 the settings define in the org-... variables."
3832 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3833 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3834 (htmlbuf (htmlize-region beg end
)))
3836 (with-current-buffer htmlbuf
3837 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3838 (plist-get htmlize-buffer-places
'content-end
)))
3839 (kill-buffer htmlbuf
))))
3842 (defun org-export-htmlize-generate-css ()
3843 "Create the CSS for all font definitions in the current Emacs session.
3844 Use this to create face definitions in your CSS style file that can then
3845 be used by code snippets transformed by htmlize.
3846 This command just produces a buffer that contains class definitions for all
3847 faces used in the current Emacs session. You can copy and paste the ones you
3848 need into your CSS file.
3850 If you then set `org-export-htmlize-output-type' to `css', calls to
3851 the function `org-export-htmlize-region-for-paste' will produce code
3852 that uses these same face definitions."
3855 (and (get-buffer "*html*") (kill-buffer "*html*"))
3857 (let ((fl (face-list))
3858 (htmlize-css-name-prefix "org-")
3859 (htmlize-output-type 'css
)
3861 (while (setq f
(pop fl
)
3862 i
(and f
(face-attribute f
:inherit
)))
3863 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3864 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3865 (htmlize-region (point-min) (point-max))))
3866 (switch-to-buffer "*html*")
3867 (goto-char (point-min))
3868 (if (re-search-forward "<style" nil t
)
3869 (delete-region (point-min) (match-beginning 0)))
3870 (if (re-search-forward "</style>" nil t
)
3871 (delete-region (1+ (match-end 0)) (point-max)))
3872 (beginning-of-line 1)
3873 (if (looking-at " +") (replace-match ""))
3874 (goto-char (point-min)))
3876 (defun org-html-protect (s)
3877 ;; convert & to &, < to < and > to >
3879 (while (string-match "&" s start
)
3880 (setq s
(replace-match "&" t t s
)
3881 start
(1+ (match-beginning 0))))
3882 (while (string-match "<" s
)
3883 (setq s
(replace-match "<" t t s
)))
3884 (while (string-match ">" s
)
3885 (setq s
(replace-match ">" t t s
))))
3888 (defun org-export-cleanup-toc-line (s)
3889 "Remove tags and time staps from lines going into the toc."
3890 (when (memq org-export-with-tags
'(not-in-toc nil
))
3891 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3892 (setq s
(replace-match "" t t s
))))
3893 (when org-export-remove-timestamps-from-toc
3894 (while (string-match org-maybe-keyword-time-regexp s
)
3895 (setq s
(replace-match "" t t s
))))
3896 (while (string-match org-bracket-link-regexp s
)
3897 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3901 (defun org-html-expand (string)
3902 "Prepare STRING for HTML export. Applies all active conversions.
3903 If there are links in the string, don't modify these."
3904 (let* ((re (concat org-bracket-link-regexp
"\\|"
3905 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3907 (while (setq m
(string-match re string
))
3908 (setq s
(substring string
0 m
)
3909 l
(match-string 0 string
)
3910 string
(substring string
(match-end 0)))
3911 (push (org-html-do-expand s
) res
)
3913 (push (org-html-do-expand string
) res
)
3914 (apply 'concat
(nreverse res
))))
3916 (defun org-html-do-expand (s)
3917 "Apply all active conversions to translate special ASCII to HTML."
3918 (setq s
(org-html-protect s
))
3919 (if org-export-html-expand
3921 (while (string-match "@<\\([^&]*\\)>" s
)
3922 (setq s
(replace-match "<\\1>" t nil s
)))))
3923 (if org-export-with-emphasize
3924 (setq s
(org-export-html-convert-emphasize s
)))
3925 (if org-export-with-special-strings
3926 (setq s
(org-export-html-convert-special-strings s
)))
3927 (if org-export-with-sub-superscripts
3928 (setq s
(org-export-html-convert-sub-super s
)))
3929 (if org-export-with-TeX-macros
3930 (let ((start 0) wd ass
)
3931 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
3933 (if (get-text-property (match-beginning 0) 'org-protected s
)
3934 (setq start
(match-end 0))
3935 (setq wd
(match-string 1 s
))
3936 (if (setq ass
(assoc wd org-html-entities
))
3937 (setq s
(replace-match (or (cdr ass
)
3938 (concat "&" (car ass
) ";"))
3940 (setq start
(+ start
(length wd
))))))))
3943 (defun org-create-multibrace-regexp (left right n
)
3944 "Create a regular expression which will match a balanced sexp.
3945 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3946 as single character strings.
3947 The regexp returned will match the entire expression including the
3948 delimiters. It will also define a single group which contains the
3949 match except for the outermost delimiters. The maximum depth of
3950 stacked delimiters is N. Escaping delimiters is not possible."
3951 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3954 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3957 re
(concat re or next
)
3958 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3959 (concat left
"\\(" re
"\\)" right
)))
3961 (defvar org-match-substring-regexp
3963 "\\([^\\]\\)\\([_^]\\)\\("
3964 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3966 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3968 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3969 "The regular expression matching a sub- or superscript.")
3971 (defvar org-match-substring-with-braces-regexp
3973 "\\([^\\]\\)\\([_^]\\)\\("
3974 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3976 "The regular expression matching a sub- or superscript, forcing braces.")
3978 (defconst org-export-html-special-string-regexps
3979 '(("\\\\-" .
"­")
3980 ("---\\([^-]\\)" .
"—\\1")
3981 ("--\\([^-]\\)" .
"–\\1")
3982 ("\\.\\.\\." .
"…"))
3983 "Regular expressions for special string conversion.")
3985 (defun org-export-html-convert-special-strings (string)
3986 "Convert special characters in STRING to HTML."
3987 (let ((all org-export-html-special-string-regexps
)
3989 (while (setq a
(pop all
))
3990 (setq re
(car a
) rpl
(cdr a
) start
0)
3991 (while (string-match re string start
)
3992 (if (get-text-property (match-beginning 0) 'org-protected string
)
3993 (setq start
(match-end 0))
3994 (setq string
(replace-match rpl t nil string
)))))
3997 (defun org-export-html-convert-sub-super (string)
3998 "Convert sub- and superscripts in STRING to HTML."
3999 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4000 (while (string-match org-match-substring-regexp string s
)
4002 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4003 ((get-text-property (match-beginning 2) 'org-protected string
)
4004 (setq s
(match-end 2)))
4006 (setq s
(match-end 1)
4007 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4008 c
(or (match-string 8 string
)
4009 (match-string 6 string
)
4010 (match-string 5 string
))
4011 string
(replace-match
4012 (concat (match-string 1 string
)
4013 "<" key
">" c
"</" key
">")
4015 (while (string-match "\\\\\\([_^]\\)" string
)
4016 (setq string
(replace-match (match-string 1 string
) t t string
)))
4019 (defun org-export-html-convert-emphasize (string)
4022 (while (string-match org-emph-re string s
)
4024 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4025 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4026 (setq s
(match-beginning 0)
4029 (match-string 1 string
)
4030 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4031 (match-string 4 string
)
4032 (nth 3 (assoc (match-string 3 string
)
4033 org-emphasis-alist
))
4034 (match-string 5 string
))
4035 string
(replace-match rpl t t string
)
4036 s
(+ s
(- (length rpl
) 2)))
4040 (defvar org-par-open nil
)
4041 (defun org-open-par ()
4042 "Insert <p>, but first close previous paragraph if any."
4043 (org-close-par-maybe)
4045 (setq org-par-open t
))
4046 (defun org-close-par-maybe ()
4047 "Close paragraph if there is one open."
4050 (setq org-par-open nil
)))
4051 (defun org-close-li (&optional type
)
4052 "Close <li> if necessary."
4053 (org-close-par-maybe)
4054 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4056 (defvar body-only
) ; dynamically scoped into this.
4057 (defun org-html-level-start (level title umax with-toc head-count
)
4058 "Insert a new level in HTML export.
4059 When TITLE is nil, just close all open levels."
4060 (org-close-par-maybe)
4061 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
4065 (if (aref org-levels-open
(1- l
))
4067 (org-html-level-close l umax
)
4068 (aset org-levels-open
(1- l
) nil
)))
4071 ;; If title is nil, this means this function is called to close
4072 ;; all levels, so the rest is done only if title is given
4073 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4074 (setq title
(replace-match
4075 (if org-export-with-tags
4078 " <span class=\"tag\">"
4079 (mapconcat 'identity
(org-split-string
4080 (match-string 1 title
) ":")
4087 (if (aref org-levels-open
(1- level
))
4091 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
4092 (insert "<li>" title
"<br/>\n")))
4093 (aset org-levels-open
(1- level
) t
)
4094 (org-close-par-maybe)
4096 (insert (format "<ul>\n<li id=\"%s\">" target
)
4098 (insert "<ul>\n<li>" title
"<br/>\n"))))
4099 (aset org-levels-open
(1- level
) t
)
4100 (setq snumber
(org-section-number level
))
4101 (if (and org-export-with-section-numbers
(not body-only
))
4102 (setq title
(concat snumber
" " title
)))
4103 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4104 (unless (= head-count
1) (insert "\n</div>\n"))
4105 (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"
4106 snumber level level snumber title level snumber
))
4109 (defun org-get-text-property-any (pos prop
&optional object
)
4110 (or (get-text-property pos prop object
)
4111 (and (setq pos
(next-single-property-change pos prop object
))
4112 (get-text-property pos prop object
))))
4114 (defun org-html-level-close (level max-outline-level
)
4115 "Terminate one level in HTML export."
4116 (if (<= level max-outline-level
)
4119 (insert "</ul>\n")))
4121 ;;; iCalendar export
4124 (defun org-export-icalendar-this-file ()
4125 "Export current file as an iCalendar file.
4126 The iCalendar file will be located in the same directory as the Org-mode
4127 file, but with extension `.ics'."
4129 (org-export-icalendar nil buffer-file-name
))
4132 (defun org-export-icalendar-all-agenda-files ()
4133 "Export all files in `org-agenda-files' to iCalendar .ics files.
4134 Each iCalendar file will be located in the same directory as the Org-mode
4135 file, but with extension `.ics'."
4137 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4140 (defun org-export-icalendar-combine-agenda-files ()
4141 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4142 The file is stored under the name `org-combined-agenda-icalendar-file'."
4144 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4146 (defun org-export-icalendar (combine &rest files
)
4147 "Create iCalendar files for all elements of FILES.
4148 If COMBINE is non-nil, combine all calendar entries into a single large
4149 file and store it under the name `org-combined-agenda-icalendar-file'."
4151 (org-prepare-agenda-buffers files
)
4152 (let* ((dir (org-export-directory
4153 :ical
(list :publishing-directory
4154 org-export-publishing-directory
)))
4155 file ical-file ical-buffer category started org-agenda-new-buffers
)
4156 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4159 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4160 org-combined-agenda-icalendar-file
4161 (expand-file-name org-combined-agenda-icalendar-file dir
))
4162 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4163 (set-buffer ical-buffer
) (erase-buffer))
4164 (while (setq file
(pop files
))
4166 (org-check-agenda-file file
)
4167 (set-buffer (org-get-agenda-file-buffer file
))
4169 (setq ical-file
(concat (file-name-as-directory dir
)
4170 (file-name-sans-extension
4171 (file-name-nondirectory buffer-file-name
))
4173 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4174 (with-current-buffer ical-buffer
(erase-buffer)))
4175 (setq category
(or org-category
4176 (file-name-sans-extension
4177 (file-name-nondirectory buffer-file-name
))))
4178 (if (symbolp category
) (setq category
(symbol-name category
)))
4179 (let ((standard-output ical-buffer
))
4181 (and (not started
) (setq started t
)
4182 (org-start-icalendar-file org-icalendar-combined-name
))
4183 (org-start-icalendar-file category
))
4184 (org-print-icalendar-entries combine
)
4185 (when (or (and combine
(not files
)) (not combine
))
4186 (org-finish-icalendar-file)
4187 (set-buffer ical-buffer
)
4188 (run-hooks 'org-before-save-iCalendar-file-hook
)
4190 (run-hooks 'org-after-save-iCalendar-file-hook
)
4191 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4193 (org-release-buffers org-agenda-new-buffers
))))
4195 (defvar org-before-save-iCalendar-file-hook nil
4196 "Hook run before an iCalendar file has been saved.
4197 This can be used to modify the result of the export.")
4199 (defvar org-after-save-iCalendar-file-hook nil
4200 "Hook run after an iCalendar file has been saved.
4201 The iCalendar buffer is still current when this hook is run.
4202 A good way to use this is to tell a desktop calenndar application to re-read
4203 the iCalendar file.")
4205 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4206 (defun org-print-icalendar-entries (&optional combine
)
4207 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4208 When COMBINE is non nil, add the category to each line."
4209 (require 'org-agenda
)
4210 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4211 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4212 (dts (org-ical-ts-to-string
4213 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4215 hd ts ts2 state status
(inc t
) pos b sexp rrule
4216 scheduledp deadlinep todo prefix due start
4217 tmp pri categories entry location summary desc uid
4218 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4219 (org-refresh-category-properties)
4221 (goto-char (point-min))
4222 (while (re-search-forward re1 nil t
)
4225 (when (boundp 'org-icalendar-verify-function
)
4226 (unless (funcall org-icalendar-verify-function
)
4227 (outline-next-heading)
4230 (setq pos
(match-beginning 0)
4233 hd
(condition-case nil
4234 (org-icalendar-cleanup-string
4236 (error (throw :skip nil
)))
4237 summary
(org-icalendar-cleanup-string
4238 (org-entry-get nil
"SUMMARY"))
4239 desc
(org-icalendar-cleanup-string
4240 (or (org-entry-get nil
"DESCRIPTION")
4241 (and org-icalendar-include-body
(org-get-entry)))
4242 t org-icalendar-include-body
)
4243 location
(org-icalendar-cleanup-string
4244 (org-entry-get nil
"LOCATION"))
4245 uid
(if org-icalendar-store-UID
4247 (or (org-id-get) (org-id-new)))
4248 categories
(org-export-get-categories)
4249 deadlinep nil scheduledp nil
)
4250 (if (looking-at re2
)
4252 (goto-char (match-end 0))
4253 (setq ts2
(match-string 1)
4254 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4255 (setq tmp
(buffer-substring (max (point-min)
4256 (- pos org-ds-keyword-length
))
4258 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4261 (replace-match "\\1" t nil ts
))
4263 deadlinep
(string-match org-deadline-regexp tmp
)
4264 scheduledp
(string-match org-scheduled-regexp tmp
)
4265 todo
(org-get-todo-state)
4266 ;; donep (org-entry-is-done-p)
4271 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4272 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4277 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4278 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4280 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4281 (if (or (string-match org-tr-regexp hd
)
4282 (string-match org-ts-regexp hd
))
4283 (setq hd
(replace-match "" t t hd
)))
4284 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4286 (concat "\nRRULE:FREQ="
4289 '(("d" .
"DAILY")("w" .
"WEEKLY")
4290 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4291 ";INTERVAL=" (match-string 1 ts
)))
4293 (setq summary
(or summary hd
))
4294 (if (string-match org-bracket-link-regexp summary
)
4296 (replace-match (if (match-end 3)
4297 (match-string 3 summary
)
4298 (match-string 1 summary
))
4300 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4301 (if scheduledp
(setq summary
(concat "S: " summary
)))
4302 (if (string-match "\\`<%%" ts
)
4303 (with-current-buffer sexp-buffer
4304 (insert (substring ts
1 -
1) " " summary
"\n"))
4305 (princ (format "BEGIN:VEVENT
4313 (org-ical-ts-to-string ts
"DTSTART")
4314 (org-ical-ts-to-string ts2
"DTEND" inc
)
4316 (if (and desc
(string-match "\\S-" desc
))
4317 (concat "\nDESCRIPTION: " desc
) "")
4318 (if (and location
(string-match "\\S-" location
))
4319 (concat "\nLOCATION: " location
) "")
4321 (when (and org-icalendar-include-sexps
4322 (condition-case nil
(require 'icalendar
) (error nil
))
4323 (fboundp 'icalendar-export-region
))
4324 ;; Get all the literal sexps
4325 (goto-char (point-min))
4326 (while (re-search-forward "^&?%%(" nil t
)
4329 (setq b
(match-beginning 0))
4330 (goto-char (1- (match-end 0)))
4333 (setq sexp
(buffer-substring b
(point)))
4334 (with-current-buffer sexp-buffer
4335 (insert sexp
"\n"))))
4336 (princ (org-diary-to-ical-string sexp-buffer
))
4337 (kill-buffer sexp-buffer
))
4339 (when org-icalendar-include-todo
4340 (setq prefix
"TODO-")
4341 (goto-char (point-min))
4342 (while (re-search-forward org-todo-line-regexp nil t
)
4345 (when (boundp 'org-icalendar-verify-function
)
4346 (unless (funcall org-icalendar-verify-function
)
4347 (outline-next-heading)
4350 (setq state
(match-string 2))
4351 (setq status
(if (member state org-done-keywords
)
4352 "COMPLETED" "NEEDS-ACTION"))
4354 (or (not (member state org-done-keywords
))
4355 (eq org-icalendar-include-todo
'all
))
4356 (not (member org-archive-tag
(org-get-tags-at)))
4358 (setq hd
(match-string 3)
4359 summary
(org-icalendar-cleanup-string
4360 (org-entry-get nil
"SUMMARY"))
4361 desc
(org-icalendar-cleanup-string
4362 (or (org-entry-get nil
"DESCRIPTION")
4363 (and org-icalendar-include-body
(org-get-entry)))
4364 t org-icalendar-include-body
)
4365 location
(org-icalendar-cleanup-string
4366 (org-entry-get nil
"LOCATION"))
4367 due
(and (member 'todo-due org-icalendar-use-deadline
)
4368 (org-entry-get nil
"DEADLINE"))
4369 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4370 (org-entry-get nil
"SCHEDULED"))
4371 categories
(org-export-get-categories)
4372 uid
(if org-icalendar-store-UID
4374 (or (org-id-get) (org-id-new))))
4375 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4376 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4378 (if (string-match org-bracket-link-regexp hd
)
4379 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4380 (match-string 1 hd
))
4382 (if (string-match org-priority-regexp hd
)
4383 (setq pri
(string-to-char (match-string 2 hd
))
4384 hd
(concat (substring hd
0 (match-beginning 1))
4385 (substring hd
(match-end 1))))
4386 (setq pri org-default-priority
))
4387 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4388 (- org-lowest-priority org-highest-priority
))))))
4390 (princ (format "BEGIN:VTODO
4402 (if (and location
(string-match "\\S-" location
))
4403 (concat "\nLOCATION: " location
) "")
4404 (if (and desc
(string-match "\\S-" desc
))
4405 (concat "\nDESCRIPTION: " desc
) "")
4406 (if due
(concat "\n" due
) "")
4410 (defun org-export-get-categories ()
4411 "Get categories according to `org-icalendar-categories'."
4412 (let ((cs org-icalendar-categories
) c rtn tmp
)
4413 (while (setq c
(pop cs
))
4415 ((eq c
'category
) (push (org-get-category) rtn
))
4417 (setq tmp
(org-get-todo-state))
4418 (and tmp
(push tmp rtn
)))
4420 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4422 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4423 (mapconcat 'identity
(nreverse rtn
) ",")))
4425 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4426 "Take out stuff and quote what needs to be quoted.
4427 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4428 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4433 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4434 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4435 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4436 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4438 (while (string-match "\\([,;]\\)" s start
)
4439 (setq start
(+ (match-beginning 0) 2)
4440 s
(replace-match "\\\\\\1" nil nil s
))))
4442 (while (string-match "[ \t]*\n[ \t]*" s
)
4443 (setq s
(replace-match "\\n" t t s
))))
4444 (setq s
(org-trim s
))
4447 (if (and (numberp maxlength
)
4448 (> (length s
) maxlength
))
4449 (setq s
(substring s
0 maxlength
)))))
4452 (defun org-get-entry ()
4453 "Clean-up description string."
4455 (org-back-to-heading t
)
4456 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4458 (defun org-start-icalendar-file (name)
4459 "Start an iCalendar file by inserting the header."
4460 (let ((user user-full-name
)
4461 (name (or name
"unknown"))
4462 (timezone (cadr (current-time-zone))))
4464 (format "BEGIN:VCALENDAR
4467 PRODID:-//%s//Emacs with Org-mode//EN
4469 CALSCALE:GREGORIAN\n" name user timezone
))))
4471 (defun org-finish-icalendar-file ()
4472 "Finish an iCalendar file by inserting the END statement."
4473 (princ "END:VCALENDAR\n"))
4475 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4476 "Take a time string S and convert it to iCalendar format.
4477 KEYWORD is added in front, to make a complete line like DTSTART....
4478 When INC is non-nil, increase the hour by two (if time string contains
4479 a time), or the day by one (if it does not contain a time)."
4480 (let ((t1 (org-parse-time-string s
'nodefault
))
4481 t2 fmt have-time time
)
4482 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4483 (setq t2 t1 have-time t
)
4484 (setq t2
(org-parse-time-string s
)))
4485 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4486 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4489 (if org-agenda-default-appointment-duration
4490 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4493 (setq time
(encode-time s mi h d m y
)))
4494 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4495 (concat keyword
(format-time-string fmt time
))))
4499 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4500 (with-current-buffer buffer
4501 (apply 'insert output
)))
4502 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4505 (defun org-export-as-xoxo (&optional buffer
)
4506 "Export the org buffer as XOXO.
4507 The XOXO buffer is named *xoxo-<source buffer name>*"
4508 (interactive (list (current-buffer)))
4509 ;; A quickie abstraction
4511 ;; Output everything as XOXO
4512 (with-current-buffer (get-buffer buffer
)
4513 (let* ((pos (point))
4514 (opt-plist (org-combine-plists (org-default-export-plist)
4515 (org-infile-export-plist)))
4516 (filename (concat (file-name-as-directory
4517 (org-export-directory :xoxo opt-plist
))
4518 (file-name-sans-extension
4519 (file-name-nondirectory buffer-file-name
))
4521 (out (find-file-noselect filename
))
4524 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4525 ;; Check the output buffer is empty.
4526 (with-current-buffer out
(erase-buffer))
4527 ;; Kick off the output
4528 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4529 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4530 (let* ((hd (match-string-no-properties 1))
4533 (match-string-no-properties 2)
4535 (goto-char (match-end 0))
4540 (if (looking-at "^[ \t]\\(.*\\)")
4541 (setq str
(concat str
(match-string-no-properties 1)))
4542 (throw 'loop str
)))))))))
4544 ;; Handle level rendering
4546 ((> level last-level
)
4547 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4549 ((< level last-level
)
4550 (dotimes (- (- last-level level
) 1)
4552 (org-export-as-xoxo-insert-into out
"</li>\n"))
4553 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4555 (org-export-as-xoxo-insert-into out
"</li>\n")
4556 (setq hanging-li nil
)))
4558 ((equal level last-level
)
4560 (org-export-as-xoxo-insert-into out
"</li>\n")))
4563 (setq last-level level
)
4565 ;; And output the new li
4566 (setq hanging-li
't
)
4567 (if (equal ?
+ (elt text
0))
4568 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4569 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4571 ;; Finally finish off the ol
4572 (dotimes (- last-level
1)
4574 (org-export-as-xoxo-insert-into out
"</li>\n"))
4575 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4578 ;; Finish the buffer off and clean it up.
4579 (switch-to-buffer-other-window out
)
4580 (indent-region (point-min) (point-max) nil
)
4582 (goto-char (point-min))
4587 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4589 ;;; org-exp.el ends here