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-excude-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 (defun org-infile-export-plist ()
860 "Return the property list with file-local settings for export."
864 (goto-char (point-min))
865 (let ((re (org-make-options-regexp
867 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
868 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
869 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
870 (mapcar 'car org-export-inbuffer-options-extra
))))
871 p key val text options js-up js-main js-css js-opt a pr style
872 ext-setup-or-nil setup-contents
(start 0))
873 (while (or (and ext-setup-or-nil
874 (string-match re ext-setup-or-nil start
)
875 (setq start
(match-end 0)))
876 (and (setq ext-setup-or-nil nil start
0)
877 (re-search-forward re nil t
)))
878 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
879 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
881 ((setq a
(assoc key org-export-inbuffer-options-extra
))
883 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
884 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
885 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
886 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
887 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
888 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
889 ((string-equal key
"STYLE")
890 (setq style
(concat style
"\n" val
)))
891 ((string-equal key
"TEXT")
892 (setq text
(if text
(concat text
"\n" val
) val
)))
893 ((string-equal key
"OPTIONS")
894 (setq options
(concat val
" " options
)))
895 ((string-equal key
"LINK_UP")
896 (setq p
(plist-put p
:link-up val
)))
897 ((string-equal key
"LINK_HOME")
898 (setq p
(plist-put p
:link-home val
)))
899 ((string-equal key
"EXPORT_SELECT_TAGS")
900 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
901 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
902 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
903 ((equal key
"SETUPFILE")
904 (setq setup-contents
(org-file-contents
906 (org-remove-double-quotes
909 (if (not ext-setup-or-nil
)
910 (setq ext-setup-or-nil setup-contents start
0)
911 (setq ext-setup-or-nil
912 (concat (substring ext-setup-or-nil
0 start
)
913 "\n" setup-contents
"\n"
914 (substring ext-setup-or-nil start
)))))))
915 (setq p
(plist-put p
:text text
))
916 (if style
(setq p
(plist-put p
:style-extra style
)))
918 (setq p
(org-export-add-options-to-plist p options
)))
921 (defun org-export-add-options-to-plist (p options
)
922 "Parse an OPTONS line and set values in the property list P."
925 (let ((op '(("H" .
:headline-levels
)
926 ("num" .
:section-numbers
)
927 ("toc" .
:table-of-contents
)
928 ("\\n" .
:preserve-breaks
)
929 ("@" .
:expand-quoted-html
)
932 ("^" .
:sub-superscript
)
933 ("-" .
:special-strings
)
938 ("TeX" .
:TeX-macros
)
939 ("LaTeX" .
:LaTeX-fragments
)
940 ("skip" .
:skip-before-1st-heading
)
941 ("author" .
:author-info
)
942 ("creator" .
:creator-info
)
943 ("timestamp" .
:time-stamp-file
)))
945 (while (setq o
(pop op
))
946 (if (string-match (concat (regexp-quote (car o
))
947 ":\\([^ \t\n\r;,.]*\\)")
949 (setq p
(plist-put p
(cdr o
)
950 (car (read-from-string
951 (match-string 1 options
))))))))))
954 (defun org-export-add-subtree-options (p pos
)
955 "Add options in subtree at position POS to property list P."
958 (when (org-at-heading-p)
960 ;; This is actually read in `org-export-get-title-from-subtree'
961 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
962 ;; (setq p (plist-put p :title a)))
963 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
964 (setq p
(plist-put p
:text a
)))
965 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
966 (setq p
(org-export-add-options-to-plist p a
)))))
969 (defun org-export-directory (type plist
)
970 (let* ((val (plist-get plist
:publishing-directory
))
972 (or (cdr (assoc type val
)) ".")
976 (defun org-export-process-option-filters (plist)
977 (let ((functions org-export-options-filters
) f
)
978 (while (setq f
(pop functions
))
979 (setq plist
(funcall f plist
))))
983 (defun org-export (&optional arg
)
984 "Export dispatcher for Org-mode.
985 When `org-export-run-in-background' is non-nil, try to run the command
986 in the background. This will be done only for commands that write
987 to a file. For details see the docstring of `org-export-run-in-background'.
989 The prefix argument ARG will be passed to the exporter. However, if
990 ARG is a double universal prefix `C-u C-u', that means to inverse the
991 value of `org-export-run-in-background'."
993 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
994 (help "[t] insert the export option template
995 \[v] limit export to visible part of outline tree
1000 \[H] export as HTML to temporary buffer
1001 \[R] export region as HTML
1002 \[b] export as HTML and browse immediately
1005 \[l] export as LaTeX
1006 \[L] export as LaTeX to temporary buffer
1008 \[i] export current file as iCalendar file
1009 \[I] export all agenda files as iCalendar files
1010 \[c] export agenda files into combined iCalendar file
1012 \[F] publish current file
1013 \[P] publish current project
1014 \[X] publish... (project will be prompted for)
1015 \[A] publish all projects")
1017 '((?t org-insert-export-options-template nil
)
1018 (?v org-export-visible nil
)
1019 (?a org-export-as-ascii t
)
1020 (?h org-export-as-html t
)
1021 (?b org-export-as-html-and-open t
)
1022 (?H org-export-as-html-to-buffer nil
)
1023 (?R org-export-region-as-html nil
)
1024 (?x org-export-as-xoxo t
)
1025 (?l org-export-as-latex t
)
1026 (?L org-export-as-latex-to-buffer nil
)
1027 (?i org-export-icalendar-this-file t
)
1028 (?I org-export-icalendar-all-agenda-files t
)
1029 (?c org-export-icalendar-combine-agenda-files t
)
1030 (?F org-publish-current-file t
)
1031 (?P org-publish-current-project t
)
1033 (?A org-publish-all t
)))
1035 (save-window-excursion
1036 (delete-other-windows)
1037 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1039 (message "Select command: ")
1040 (setq r1
(read-char-exclusive)))
1041 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1042 (unless (setq ass
(assq r2 cmds
))
1043 (error "No command associated with key %c" r1
))
1044 (if (and bg
(nth 2 ass
))
1045 ;; execute in background
1046 (let ((p (start-process
1047 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1049 (expand-file-name invocation-name invocation-directory
)
1052 "--eval" "(require 'org-exp)"
1053 "--eval" "(setq org-wait .2)"
1055 "-f" (symbol-name (nth 1 ass
)))))
1056 (set-process-sentinel p
'org-export-process-sentinel
)
1057 (message "Background process \"%s\": started" p
))
1058 ;; background processing not requested, or not possible
1059 (call-interactively (nth 1 ass
)))))
1061 (defun org-export-process-sentinel (process status
)
1062 (if (string-match "\n+\\'" status
)
1063 (setq status
(substring status
0 -
1)))
1064 (message "Background process \"%s\": %s" process status
))
1066 (defconst org-html-entities
1107 ("Aring") ("AA".
"Å")
1196 ("varepsilon".
"ε")
1209 ("sigmaf") ("varsigma".
"ς")
1217 ("thetasym") ("vartheta".
"ϑ")
1220 ("bull") ("bullet".
"•")
1221 ("hellip") ("dots".
"…")
1231 ("larr") ("leftarrow".
"←") ("gets".
"←")
1232 ("uarr") ("uparrow".
"↑")
1233 ("rarr") ("to".
"→") ("rightarrow".
"→")
1234 ("darr")("downarrow".
"↓")
1235 ("harr") ("leftrightarrow".
"↔")
1236 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1237 ("lArr") ("Leftarrow".
"⇐")
1238 ("uArr") ("Uparrow".
"⇑")
1239 ("rArr") ("Rightarrow".
"⇒")
1240 ("dArr") ("Downarrow".
"⇓")
1241 ("hArr") ("Leftrightarrow".
"⇔")
1243 ("part") ("partial".
"∂")
1244 ("exist") ("exists".
"∃")
1245 ("empty") ("emptyset".
"∅")
1247 ("isin") ("in".
"∈")
1253 ("lowast") ("ast".
"∗")
1255 ("prop") ("proptp".
"∝")
1256 ("infin") ("infty".
"∞")
1257 ("ang") ("angle".
"∠")
1258 ("and") ("wedge".
"∧")
1259 ("or") ("vee".
"∨")
1265 ("cong") ("simeq".
"≅")
1266 ("asymp")("approx".
"≈")
1267 ("ne") ("neq".
"≠")
1271 ("sub") ("subset".
"⊂")
1272 ("sup") ("supset".
"⊃")
1279 ("sdot") ("cdot".
"⋅")
1286 ("loz") ("Diamond".
"◊")
1287 ("spades") ("spadesuit".
"♠")
1288 ("clubs") ("clubsuit".
"♣")
1289 ("hearts") ("diamondsuit".
"♥")
1290 ("diams") ("diamondsuit".
"♦")
1291 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1358 "Entities for TeX->HTML translation.
1359 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1360 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1361 In that case, \"\\ent\" will be translated to \"&other;\".
1362 The list contains HTML entities for Latin-1, Greek and other symbols.
1363 It is supplemented by a number of commonly used TeX macros with appropriate
1364 translations. There is currently no way for users to extend this.")
1366 ;;; General functions for all backends
1368 (defun org-export-preprocess-string (string &rest parameters
)
1369 "Cleanup STRING so that that the true exported has a more consistent source.
1370 This function takes STRING, which should be a buffer-string of an org-file
1371 to export. It then creates a temporary buffer where it does its job.
1372 The result is then again returned as a string, and the exporter works
1373 on this string to produce the exported version."
1375 (let* ((htmlp (plist-get parameters
:for-html
))
1376 (asciip (plist-get parameters
:for-ascii
))
1377 (latexp (plist-get parameters
:for-LaTeX
))
1378 (archived-trees (plist-get parameters
:archived-trees
))
1379 (inhibit-read-only t
)
1380 (drawers org-drawers
)
1381 (outline-regexp "\\*+ ")
1384 (with-current-buffer (get-buffer-create " org-mode-tmp")
1387 (setq case-fold-search t
)
1389 (run-hooks 'org-export-preprocess-hook
)
1391 ;; Remove license-to-kill stuff
1392 ;; The caller markes some stuff fo killing, stuff that has been
1393 ;; used to create the page title, for example.
1394 (org-export-kill-licensed-text)
1396 (let ((org-inhibit-startup t
)) (org-mode))
1397 (setq case-fold-search t
)
1398 (untabify (point-min) (point-max))
1400 ;; Handle include files
1401 (org-export-handle-include-files)
1403 ;; Get rid of excluded trees
1404 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1405 (plist-get parameters
:exclude-tags
))
1407 ;; Handle source code snippets
1408 (org-export-replace-src-segments)
1410 ;; Get rid of drawers
1411 (org-export-remove-or-extract-drawers drawers
1412 (plist-get parameters
:drawers
))
1414 ;; Get the correct stuff before the first headline
1415 (when (plist-get parameters
:skip-before-1st-heading
)
1416 (goto-char (point-min))
1417 (when (re-search-forward "^\\*+[ \t]" nil t
)
1418 (delete-region (point-min) (match-beginning 0))
1419 (goto-char (point-min))
1421 (when (plist-get parameters
:add-text
)
1422 (goto-char (point-min))
1423 (insert (plist-get parameters
:add-text
) "\n"))
1425 ;; Get rid of archived trees
1426 (org-export-remove-archived-trees archived-trees
)
1428 ;; Find all headings and compute the targets for them
1429 (setq target-alist
(org-export-define-heading-targets target-alist
))
1431 ;; Find targets in comments and move them out of comments,
1432 ;; but mark them as targets that should be invisible
1433 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1436 (org-export-protect-examples (if asciip
'indent nil
))
1438 ;; Protect backend specific stuff, throw away the others.
1439 (org-export-select-backend-specific-text
1440 (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1442 ;; Protect quoted subtrees
1443 (org-export-protect-quoted-subtrees)
1445 ;; Protect verbatim elements
1446 (org-export-protect-verbatim)
1448 ;; Blockquotes and verse
1449 (org-export-mark-blockquote-and-verse)
1451 ;; Remove comment environment and comment subtrees
1452 (org-export-remove-comment-blocks-and-subtrees)
1454 ;; Remove special table lines
1455 (when org-export-table-remove-special-lines
1456 (org-export-remove-special-table-lines))
1458 ;; Specific LaTeX stuff
1460 (require 'org-export-latex nil
)
1461 (org-export-latex-preprocess))
1463 ;; Specific ASCII stuff
1465 (org-export-ascii-preprocess))
1467 ;; Specific HTML stuff
1469 (org-export-html-preprocess parameters
))
1471 ;; Remove or replace comments
1472 (org-export-handle-comments (plist-get parameters
:comments
))
1474 ;; Find matches for radio targets and turn them into internal links
1475 (org-export-mark-radio-links)
1477 ;; Find all links that contain a newline and put them into a single line
1478 (org-export-concatenate-multiline-links)
1480 ;; Normalize links: Convert angle and plain links into bracket links
1481 ;; and expand link abbreviations
1482 (org-export-normalize-links)
1484 ;; Find all internal links. If they have a fuzzy match (i.e. not
1485 ;; a *dedicated* target match, let the link point to the
1486 ;; corresponding section.
1487 (org-export-target-internal-links target-alist
)
1489 ;; Find multiline emphasis and put them into single line
1490 (when (plist-get parameters
:emph-multiline
)
1491 (org-export-concatenate-multiline-emphasis))
1493 (setq rtn
(buffer-string)))
1494 (kill-buffer " org-mode-tmp")
1497 (defun org-export-kill-licensed-text ()
1498 "Remove all text that is marked with a :org-license-to-kill property."
1500 (while (setq p
(text-property-any (point-min) (point-max)
1501 :org-license-to-kill t
))
1503 p
(or (next-single-property-change p
:org-license-to-kill
)
1506 (defun org-export-define-heading-targets (target-alist)
1507 "Find all headings and define the targets for them.
1508 The new targets are added to TARGET-ALIST, which is also returned."
1509 (goto-char (point-min))
1510 (org-init-section-numbers)
1511 (let ((re (concat "^" org-outline-regexp
))
1513 (while (re-search-forward re nil t
)
1514 (setq level
(org-reduced-level
1515 (save-excursion (goto-char (point-at-bol))
1516 (org-outline-level))))
1517 (setq target
(org-solidify-link-text
1518 (format "sec-%s" (org-section-number level
))))
1519 (push (cons target target
) target-alist
)
1520 (add-text-properties
1521 (point-at-bol) (point-at-eol)
1522 (list 'target target
))))
1525 (defun org-export-handle-invisible-targets (target-alist)
1526 "Find targets in comments and move them out of comments.
1527 Mark them as invisible targets."
1529 (goto-char (point-min))
1530 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1531 ;; Check if the line before or after is a headline with a target
1532 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1533 (get-text-property (point-at-bol 2) 'target
)))
1535 ;; use the existing target in a neighboring line
1536 (setq tmp
(match-string 2))
1538 (and (looking-at "\n") (delete-char 1))
1539 (push (cons (org-solidify-link-text tmp
) target
)
1541 ;; Make an invisible target
1542 (replace-match "\\1(INVISIBLE)"))))
1545 (defun org-export-target-internal-links (target-alist)
1546 "Find all internal links and assign target to them.
1547 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1548 let the link point to the corresponding section."
1549 (goto-char (point-min))
1550 (while (re-search-forward org-bracket-link-regexp nil t
)
1552 (let* ((md (match-data))
1553 (desc (match-end 2))
1554 (link (org-link-unescape (match-string 1)))
1555 (slink (org-solidify-link-text link
))
1559 ((cdr (assoc slink target-alist
)))
1560 ((string-match org-link-types-re link
) nil
)
1561 ((or (file-name-absolute-p link
)
1562 (string-match "^\\." link
))
1566 (setq found
(condition-case nil
(org-link-search link
)
1569 (or (org-on-heading-p)
1570 (not (eq found
'dedicated
))))
1571 (or (get-text-property (point) 'target
)
1574 (1- (previous-single-property-change
1579 (goto-char (match-beginning 1))
1580 (setq props
(text-properties-at (point)))
1581 (delete-region (match-beginning 1) (match-end 1))
1584 (unless desc
(insert "][" link
))
1585 (add-text-properties pos
(point) props
))))))
1587 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1588 "Remove drawers, or extract the content.
1589 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1590 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1591 whose content to keep."
1592 (unless (eq t exp-drawers
)
1593 (goto-char (point-min))
1594 (let ((re (concat "^[ \t]*:\\("
1597 (org-delete-all exp-drawers
1598 (copy-sequence all-drawers
))
1600 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1601 (while (re-search-forward re nil t
)
1602 (replace-match "")))))
1604 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1605 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1606 Both arguments are lists of tags.
1607 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1609 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1611 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1612 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1615 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1619 (goto-char (point-min))
1620 (when (and select-tags
1622 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1623 ;; At least one tree is marked for export, this means
1624 ;; all the unmarked stuff needs to go.
1625 ;; Dig out the trees that should be exported
1626 (goto-char (point-min))
1627 (outline-next-heading)
1629 (put-text-property beg
(point-max) :org-delete t
)
1630 (while (re-search-forward re-sel nil t
)
1631 (when (org-on-heading-p)
1632 (org-back-to-heading)
1633 (remove-text-properties
1634 (max (1- (point)) (point-min))
1635 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1637 (while (and (org-up-heading-safe)
1638 (get-text-property (point) :org-delete
))
1639 (remove-text-properties (max (1- (point)) (point-min))
1640 (point-at-eol) '(:org-delete t
)))
1642 ;; Remove the trees explicitly marked for noexport
1644 (goto-char (point-min))
1645 (while (re-search-forward re-excl nil t
)
1646 (when (org-at-heading-p)
1647 (org-back-to-heading t
)
1649 (org-end-of-subtree t
)
1650 (delete-region beg
(point)))))
1651 ;; Remove everything that is now still marked for deletion
1652 (goto-char (point-min))
1653 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1654 (setq end
(or (next-single-property-change beg
:org-delete
)
1656 (delete-region beg end
))))
1658 (defun org-export-remove-archived-trees (export-archived-trees)
1659 "Remove archived trees.
1660 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1661 When it is t, the entire archived tree will be exported.
1662 When it is nil the entire tree including the headline will be removed
1664 (let ((re-archive (concat ":" org-archive-tag
":"))
1666 (when (not (eq export-archived-trees t
))
1667 (goto-char (point-min))
1668 (while (re-search-forward re-archive nil t
)
1669 (if (not (org-on-heading-p t
))
1670 (org-end-of-subtree t
)
1671 (beginning-of-line 1)
1672 (setq a
(if export-archived-trees
1673 (1+ (point-at-eol)) (point))
1674 b
(org-end-of-subtree t
))
1675 (if (> b a
) (delete-region a b
)))))))
1677 (defun org-export-protect-quoted-subtrees ()
1678 "Mark quoted subtrees with the protection property."
1679 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1680 (goto-char (point-min))
1681 (while (re-search-forward re-quote nil t
)
1682 (goto-char (match-beginning 0))
1684 (add-text-properties (point) (org-end-of-subtree t
)
1685 '(org-protected t
)))))
1687 (defun org-export-protect-verbatim ()
1688 "Mark verbatim snippets with the protection property."
1689 (goto-char (point-min))
1690 (while (re-search-forward org-verbatim-re nil t
)
1691 (add-text-properties (match-beginning 4) (match-end 4)
1693 (goto-char (1+ (match-end 4)))))
1695 (defun org-export-protect-examples (&optional indent
)
1696 "Protect code that should be exported as monospaced examples."
1697 (goto-char (point-min))
1698 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1699 (goto-char (match-end 0))
1700 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1701 (insert (if indent
": " ":"))
1702 (beginning-of-line 2)))
1703 (goto-char (point-min))
1704 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1705 (add-text-properties (match-beginning 0) (match-end 0)
1706 '(org-protected t
))))
1708 (defun org-export-select-backend-specific-text (backend)
1710 '((html "HTML" "BEGIN_HTML" "END_HTML")
1711 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1712 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1716 (setq fmt
(pop formatters
))
1717 (when (eq (car fmt
) backend
)
1718 ;; This is selected code, put it into the file for real
1719 (goto-char (point-min))
1720 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1721 ":[ \t]*\\(.*\\)") nil t
)
1722 (replace-match "\\1" t
)
1723 (add-text-properties
1724 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1725 '(org-protected t
))))
1726 (goto-char (point-min))
1727 (while (re-search-forward
1729 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1730 (cadddr fmt
) "\\>.*\n?") nil t
)
1731 (if (eq (car fmt
) backend
)
1733 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1735 ;; No, this is for a different backend, kill it
1736 (delete-region (match-beginning 0) (match-end 0)))))))
1738 (defun org-export-mark-blockquote-and-verse ()
1739 "Mark block quote and verse environments with special cookies.
1740 These special cookies will later be interpreted by the backend."
1742 (goto-char (point-min))
1743 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1745 (replace-match (if (equal (downcase (match-string 1)) "end")
1746 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1749 (goto-char (point-min))
1750 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1751 (replace-match (if (equal (downcase (match-string 1)) "end")
1752 "ORG-VERSE-END" "ORG-VERSE-START")
1755 (defun org-export-remove-comment-blocks-and-subtrees ()
1756 "Remove the comment environment, and also commented subtrees."
1757 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1758 (case-fold-search nil
))
1759 ;; Remove comment environment
1760 (goto-char (point-min))
1761 (while (re-search-forward
1762 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1763 (replace-match "" t t
))
1764 ;; Remove subtrees that are commented
1765 (goto-char (point-min))
1766 (while (re-search-forward re-commented nil t
)
1767 (goto-char (match-beginning 0))
1768 (delete-region (point) (org-end-of-subtree t
)))))
1770 (defun org-export-handle-comments (commentsp)
1771 "Remove comments, or convert to backend-specific format.
1772 COMMENTSP can be a format string for publishing comments.
1773 When it is nil, all comments will be removed."
1774 (let ((re "^#\\(.*\n?\\)")
1776 (goto-char (point-min))
1777 (while (or (looking-at re
)
1778 (re-search-forward re nil t
))
1779 (setq pos
(match-beginning 0))
1781 (progn (add-text-properties
1782 (match-beginning 0) (match-end 0) '(org-protected t
))
1783 (replace-match (format commentsp
(match-string 1)) t t
))
1784 (goto-char (1+ pos
))
1787 (goto-char (max (point-min) (1- pos
))))))))
1789 (defun org-export-mark-radio-links ()
1790 "Find all matches for radio targets and turn them into internal links."
1791 (let ((re-radio (and org-target-link-regexp
1792 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1793 (goto-char (point-min))
1795 (while (re-search-forward re-radio nil t
)
1797 (replace-match "\\1[[\\2]]"))))))
1799 (defun org-export-remove-special-table-lines ()
1800 "Remove tables lines that are used for internal purposes."
1801 (goto-char (point-min))
1802 (while (re-search-forward "^[ \t]*|" nil t
)
1803 (beginning-of-line 1)
1804 (if (or (looking-at "[ \t]*| *[!_^] *|")
1805 (and (looking-at ".*?| *<[0-9]+> *|")
1806 (not (looking-at ".*?| *[^ <|]"))))
1807 (delete-region (max (point-min) (1- (point-at-bol)))
1811 (defun org-export-normalize-links ()
1812 "Convert all links to bracket links, and expand link abbreviations."
1813 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1814 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1815 (goto-char (point-min))
1816 (while (re-search-forward re-plain-link nil t
)
1817 (goto-char (1- (match-end 0)))
1819 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1820 ":" (match-string 3) "]]")))
1821 ;; added 'org-link face to links
1822 (put-text-property 0 (length s
) 'face
'org-link s
)
1823 (replace-match s t t
))))
1824 (goto-char (point-min))
1825 (while (re-search-forward re-angle-link nil t
)
1826 (goto-char (1- (match-end 0)))
1828 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1829 ":" (match-string 3) "]]")))
1830 (put-text-property 0 (length s
) 'face
'org-link s
)
1831 (replace-match s t t
))))
1832 (goto-char (point-min))
1833 (while (re-search-forward org-bracket-link-regexp nil t
)
1834 (goto-char (1- (match-end 0)))
1836 (let* ((xx (save-match-data
1837 (org-link-expand-abbrev (match-string 1))))
1842 (concat "[" xx
"]"))
1844 (put-text-property 0 (length s
) 'face
'org-link s
)
1845 (replace-match s t t
))))))
1847 (defun org-export-concatenate-multiline-links ()
1848 "Find multi-line links and put it all into a single line.
1849 This is to make sure that the line-processing export backends
1850 can work correctly."
1851 (goto-char (point-min))
1852 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1854 (replace-match "\\1 \\3")
1855 (goto-char (match-beginning 0)))))
1857 (defun org-export-concatenate-multiline-emphasis ()
1858 "Find multi-line emphasis and put it all into a single line.
1859 This is to make sure that the line-processing export backends
1860 can work correctly."
1861 (goto-char (point-min))
1862 (while (re-search-forward org-emph-re nil t
)
1863 (if (not (= (char-after (match-beginning 3))
1864 (char-after (match-beginning 4))))
1866 (subst-char-in-region (match-beginning 0) (match-end 0)
1868 (goto-char (1- (match-end 0))))
1869 (goto-char (1+ (match-beginning 0))))))
1871 (defun org-export-grab-title-from-buffer ()
1872 "Get a title for the current document, from looking at the buffer."
1873 (let ((inhibit-read-only t
))
1875 (goto-char (point-min))
1876 (let ((end (save-excursion (outline-next-heading) (point))))
1877 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1878 ;; Mark the line so that it will not be exported as normal text.
1880 (add-text-properties (match-beginning 0) (match-end 0)
1881 (list :org-license-to-kill t
)))
1882 ;; Return the title string
1883 (org-trim (match-string 0)))))))
1885 (defun org-export-get-title-from-subtree ()
1886 "Return subtree title and exclude it from export."
1887 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1890 (when (and (org-at-heading-p)
1891 (>= (org-end-of-subtree t t
) rend
))
1892 ;; This is a subtree, we take the title from the first heading
1894 (looking-at org-todo-line-regexp
)
1895 (setq title
(match-string 3))
1897 (add-text-properties (point) (1+ (point-at-eol))
1898 (list :org-license-to-kill t
)))
1899 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1902 (defun org-solidify-link-text (s &optional alist
)
1903 "Take link text and make a safe target out of it."
1908 (org-split-string s
"[ \t\r\n]+") "=="))
1909 (a (assoc rtn alist
)))
1912 (defun org-get-min-level (lines)
1913 "Get the minimum level in LINES."
1914 (let ((re "^\\(\\*+\\) ") l min
)
1916 (while (setq l
(pop lines
))
1917 (if (string-match re l
)
1918 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1921 ;; Variable holding the vector with section numbers
1922 (defvar org-section-numbers
(make-vector org-level-max
0))
1924 (defun org-init-section-numbers ()
1925 "Initialize the vector for the section numbers."
1927 (numbers (nreverse (org-split-string "" "\\.")))
1928 (depth (1- (length org-section-numbers
)))
1929 (i depth
) number-string
)
1932 (aset org-section-numbers i
0)
1933 (setq number-string
(or (car numbers
) "0"))
1934 (if (string-match "\\`[A-Z]\\'" number-string
)
1935 (aset org-section-numbers i
1936 (- (string-to-char number-string
) ?A -
1))
1937 (aset org-section-numbers i
(string-to-number number-string
)))
1941 (defun org-section-number (&optional level
)
1942 "Return a string with the current section number.
1943 When LEVEL is non-nil, increase section numbers on that level."
1944 (let* ((depth (1- (length org-section-numbers
)))
1946 (fmts (car org-export-section-number-format
))
1947 (term (cdr org-export-section-number-format
))
1952 (aset org-section-numbers
1953 level
(1+ (aref org-section-numbers level
))))
1954 (setq idx
(1+ level
))
1955 (while (<= idx depth
)
1957 (aset org-section-numbers idx
0))
1958 (setq idx
(1+ idx
))))
1960 (while (<= idx depth
)
1961 (when (> (aref org-section-numbers idx
) 0)
1962 (setq fmt
(or (pop fmts
) fmt
)
1964 n
(aref org-section-numbers idx
)
1966 (concat string sep
(org-number-to-counter n ctype
))
1967 (concat string
".0"))
1969 (setq idx
(1+ idx
)))
1971 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1972 (setq string
(replace-match "" t nil string
)))
1973 (if (string-match "\\(\\.0\\)+\\'" string
)
1974 (setq string
(replace-match "" t nil string
))))
1975 (concat string term
)))
1977 (defun org-number-to-counter (n type
)
1978 "Concert number N to a string counter, according to TYPE.
1979 TYPE must be a string, any of:
1983 I uppper case roman numeral
1984 i lower case roman numeral"
1986 ((equal type
"1") (number-to-string n
))
1987 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1988 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1989 ((equal type
"I") (org-number-to-roman n
))
1990 ((equal type
"i") (downcase (org-number-to-roman n
)))
1991 (t (error "Invalid counter type `%s'" type
))))
1993 (defun org-number-to-roman (n)
1994 "Convert integer N into a roman numeral."
1995 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1996 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1997 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2001 (number-to-string n
)
2003 (if (>= n
(caar roman
))
2004 (setq n
(- n
(caar roman
))
2005 res
(concat res
(cdar roman
)))
2009 (org-number-to-roman 1961)
2014 (defun org-export-handle-include-files ()
2015 "Include the contents of include files, with proper formatting."
2016 (let ((case-fold-search t
)
2017 params file markup lang start end prefix prefix1
)
2018 (goto-char (point-min))
2019 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2020 (setq params
(read (concat "(" (match-string 1) ")"))
2021 prefix
(org-get-and-remove-property 'params
:prefix
)
2022 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2023 file
(org-symname-or-string (pop params
))
2024 markup
(org-symname-or-string (pop params
))
2025 lang
(org-symname-or-string (pop params
)))
2026 (delete-region (match-beginning 0) (match-end 0))
2028 (not (file-exists-p file
))
2029 (not (file-readable-p file
)))
2030 (insert (format "CANNOT INCLUDE FILE %s" file
))
2032 (if (equal (downcase markup
) "src")
2033 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2035 (setq start
(format "#+begin_%s\n" markup
)
2036 end
(format "#+end_%s" markup
))))
2037 (insert (or start
""))
2038 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2039 (or (bolp) (newline))
2040 (insert (or end
""))))))
2042 (defun org-get-file-contents (file &optional prefix prefix1
)
2043 "Get the contents of FILE and return them as a string.
2044 If PREFIX is a string, prepend it to each line. If PREFIX1
2045 is a string, prepend it to the first line instead of PREFIX."
2047 (insert-file-contents file
)
2048 (when (or prefix prefix1
)
2049 (goto-char (point-min))
2051 (insert (or prefix1 prefix
))
2053 (beginning-of-line 2)))
2056 (defun org-get-and-remove-property (listvar prop
)
2057 "Check if the value of LISTVAR contains PROP as a property.
2058 If yes, return the value of that property (i.e. the element following
2059 in the list) and remove property and value from the list in LISTVAR."
2060 (let ((list (symbol-value listvar
)) m v
)
2061 (when (setq m
(member prop list
))
2063 (if (equal (car list
) prop
)
2064 (set listvar
(cddr list
))
2065 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2067 (set listvar list
)))
2070 (defun org-symname-or-string (s)
2072 (if s
(symbol-name s
) s
)
2075 ;;; Fontification of code
2076 ;; Currently only for the HTML backend, but who knows....
2077 (defun org-export-replace-src-segments ()
2078 "Replace source code segments with special code for export."
2079 (let ((case-fold-search t
)
2081 (goto-char (point-min))
2082 (while (re-search-forward
2083 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2085 (setq lang
(match-string 1) code
(match-string 2)
2086 trans
(org-export-format-source-code lang code
))
2087 (replace-match trans t t
))))
2089 (defvar htmlp
) ;; dynamically scoped from org-exp.el
2091 (defun org-export-format-source-code (lang code
)
2092 "Format CODE from language LANG and return it formatted for export.
2093 Currently, this only does something for HTML export, for all other
2094 backends, it converts the segment into an EXAMPLE segment."
2098 ;; We are exporting to HTML
2099 (condition-case nil
(require 'htmlize
) (nil t
))
2100 (if (not (fboundp 'htmlize-region-for-paste
))
2102 ;; we do not have htmlize.el, or an old version of it
2104 "htmlize.el 1.34 or later is needed for source code formatting")
2105 (concat "#+BEGIN_EXAMPLE\n" code
2106 (if (string-match "\n\\'" code
) "" "\n")
2108 ;; ok, we are good to go
2109 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2110 (org-inhibit-startup t
)
2111 (org-startup-folded nil
)
2115 ;; Free up the protected stuff
2116 (goto-char (point-min))
2117 (while (re-search-forward "^," nil t
)
2120 (if (functionp mode
)
2123 (font-lock-fontify-buffer)
2124 (org-export-htmlize-region-for-paste
2125 (point-min) (point-max)))))
2126 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
2127 (setq htmltext
(replace-match
2128 (format "<pre class=\"src src-%s\">" lang
)
2130 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
2132 ;; This is not HTML, so just make it an example.
2133 (when (equal lang
"org")
2134 (while (string-match "^," code
)
2135 (setq code
(replace-match "" t t code
))))
2136 (concat "#+BEGIN_EXAMPLE\n" code
2137 (if (string-match "\n\\'" code
) "" "\n")
2138 "#+END_EXAMPLE\n")))))
2142 (defvar org-last-level nil
) ; dynamically scoped variable
2143 (defvar org-min-level nil
) ; dynamically scoped variable
2144 (defvar org-levels-open nil
) ; dynamically scoped parameter
2145 (defvar org-ascii-current-indentation nil
) ; For communication
2148 (defun org-export-as-ascii (arg)
2149 "Export the outline as a pretty ASCII file.
2150 If there is an active region, export only the region.
2151 The prefix ARG specifies how many levels of the outline should become
2152 underlined headlines. The default is 3."
2154 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2155 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2156 (org-infile-export-plist)))
2157 (region-p (org-region-active-p))
2158 (rbeg (and region-p
(region-beginning)))
2159 (rend (and region-p
(region-end)))
2164 (and (org-at-heading-p)
2165 (>= (org-end-of-subtree t t
) rend
)))))
2166 (opt-plist (if subtree-p
2167 (org-export-add-subtree-options opt-plist rbeg
)
2169 (custom-times org-display-custom-times
)
2170 (org-ascii-current-indentation '(0 .
0))
2174 (case-fold-search nil
)
2175 (filename (concat (file-name-as-directory
2176 (org-export-directory :ascii opt-plist
))
2177 (file-name-sans-extension
2179 (org-entry-get (region-beginning)
2180 "EXPORT_FILE_NAME" t
))
2181 (file-name-nondirectory buffer-file-name
)))
2183 (filename (if (equal (file-truename filename
)
2184 (file-truename buffer-file-name
))
2185 (concat filename
".txt")
2187 (buffer (find-file-noselect filename
))
2188 (org-levels-open (make-vector org-level-max nil
))
2189 (odd org-odd-levels-only
)
2190 (date (plist-get opt-plist
:date
))
2191 (author (plist-get opt-plist
:author
))
2192 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2193 (plist-get opt-plist
:title
)
2195 (plist-get opt-plist
:skip-before-1st-heading
))
2196 (org-export-grab-title-from-buffer))
2197 (file-name-sans-extension
2198 (file-name-nondirectory buffer-file-name
))))
2199 (email (plist-get opt-plist
:email
))
2200 (language (plist-get opt-plist
:language
))
2201 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2202 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2207 (if (org-region-active-p) (region-beginning) (point-min))
2208 (if (org-region-active-p) (region-end) (point-max))))
2209 (lines (org-split-string
2210 (org-export-preprocess-string
2213 :skip-before-1st-heading
2214 (plist-get opt-plist
:skip-before-1st-heading
)
2215 :drawers
(plist-get opt-plist
:drawers
)
2216 :verbatim-multiline t
2217 :select-tags
(plist-get opt-plist
:select-tags
)
2218 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2220 (plist-get opt-plist
:archived-trees
)
2221 :add-text
(plist-get opt-plist
:text
))
2223 thetoc have-headings first-heading-pos
2224 table-open table-buffer
)
2226 (let ((inhibit-read-only t
))
2228 (remove-text-properties (point-min) (point-max)
2229 '(:org-license-to-kill t
))))
2231 (setq org-min-level
(org-get-min-level lines
))
2232 (setq org-last-level org-min-level
)
2233 (org-init-section-numbers)
2235 (find-file-noselect filename
)
2237 (setq lang-words
(or (assoc language org-export-language-setup
)
2238 (assoc "en" org-export-language-setup
)))
2239 (switch-to-buffer-other-window buffer
)
2242 ;; create local variables for all options, to make sure all called
2243 ;; functions get the correct information
2245 (set (make-local-variable (cdr x
))
2246 (plist-get opt-plist
(car x
))))
2247 org-export-plist-vars
)
2248 (org-set-local 'org-odd-levels-only odd
)
2249 (setq umax
(if arg
(prefix-numeric-value arg
)
2250 org-export-headline-levels
))
2251 (setq umax-toc
(if (integerp org-export-with-toc
)
2252 (min org-export-with-toc umax
)
2256 (if title
(org-insert-centered title ?
=))
2258 (if (and (or author email
)
2259 org-export-author-info
)
2260 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2261 (if email
(concat " <" email
">") "")
2265 ((and date
(string-match "%" date
))
2266 (setq date
(format-time-string date
)))
2268 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2270 (if (and date org-export-time-stamp-file
)
2271 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2275 (if org-export-with-toc
2277 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2278 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2280 (mapc '(lambda (line)
2281 (if (string-match org-todo-line-regexp
2283 ;; This is a headline
2285 (setq have-headings t
)
2286 (setq level
(- (match-end 1) (match-beginning 1))
2287 level
(org-tr-level level
)
2288 txt
(match-string 3 line
)
2290 (or (and org-export-mark-todo-in-toc
2292 (not (member (match-string 2 line
)
2293 org-done-keywords
)))
2295 (and org-export-mark-todo-in-toc
2297 (org-search-todo-below
2298 line lines level
))))
2299 (setq txt
(org-html-expand-for-ascii txt
))
2301 (while (string-match org-bracket-link-regexp txt
)
2304 (match-string (if (match-end 2) 3 1) txt
)
2307 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2309 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2311 (setq txt
(replace-match "" t t txt
)))
2312 (if (string-match quote-re0 txt
)
2313 (setq txt
(replace-match "" t t txt
)))
2315 (if org-export-with-section-numbers
2316 (setq txt
(concat (org-section-number level
)
2318 (if (<= level umax-toc
)
2323 (* (max 0 (- level org-min-level
)) 4) ?\
)
2324 (format (if todo
"%s (*)\n" "%s\n") txt
))
2326 (setq org-last-level level
))
2329 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2331 (org-init-section-numbers)
2332 (while (setq line
(pop lines
))
2333 ;; Remove the quoted HTML tags.
2334 (setq line
(org-html-expand-for-ascii line
))
2336 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
2337 (setq line
(replace-match "" t t line
)))
2338 ;; Replace internal links
2339 (while (string-match org-bracket-link-regexp line
)
2340 (setq line
(replace-match
2341 (if (match-end 3) "[\\3]" "[\\1]")
2344 (setq line
(org-translate-time line
)))
2346 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2348 (setq first-heading-pos
(or first-heading-pos
(point)))
2349 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2350 txt
(match-string 2 line
))
2351 (org-ascii-level-start level txt umax lines
))
2353 ((and org-export-with-tables
2354 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2355 (if (not table-open
)
2357 (setq table-open t table-buffer nil
))
2359 (setq table-buffer
(cons line table-buffer
))
2360 (when (or (not lines
)
2361 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2363 (setq table-open nil
2364 table-buffer
(nreverse table-buffer
))
2367 (org-fix-indentation x org-ascii-current-indentation
))
2368 (org-format-table-ascii table-buffer
)
2371 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2372 (if (and org-export-with-fixed-width
2373 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2374 (setq line
(replace-match "\\1" nil nil line
)))
2375 (insert line
"\n"))))
2379 ;; insert the table of contents
2381 (goto-char (point-min))
2382 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2384 (goto-char (match-beginning 0))
2386 (goto-char first-heading-pos
))
2387 (mapc 'insert thetoc
)
2388 (or (looking-at "[ \t]*\n[ \t]*\n")
2391 ;; Convert whitespace place holders
2392 (goto-char (point-min))
2394 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2395 (setq end
(next-single-property-change beg
'org-whitespace
))
2397 (delete-region beg end
)
2398 (insert (make-string (- end beg
) ?\
))))
2401 ;; remove display and invisible chars
2403 (goto-char (point-min))
2404 (while (setq beg
(next-single-property-change (point) 'display
))
2405 (setq end
(next-single-property-change beg
'display
))
2406 (delete-region beg end
)
2409 (goto-char (point-min))
2410 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2411 (setq end
(next-single-property-change beg
'org-cwidth
))
2412 (delete-region beg end
)
2414 (goto-char (point-min))))
2416 (defun org-export-ascii-preprocess ()
2417 "Do extra work for ASCII export"
2418 (goto-char (point-min))
2419 (while (re-search-forward org-verbatim-re nil t
)
2420 (goto-char (match-end 2))
2421 (backward-delete-char 1) (insert "'")
2422 (goto-char (match-beginning 2))
2423 (delete-char 1) (insert "`")
2424 (goto-char (match-end 2))))
2426 (defun org-search-todo-below (line lines level
)
2427 "Search the subtree below LINE for any TODO entries."
2428 (let ((rest (cdr (memq line lines
)))
2429 (re org-todo-line-regexp
)
2432 (while (setq line
(pop rest
))
2433 (if (string-match re line
)
2435 (setq lv
(- (match-end 1) (match-beginning 1))
2436 todo
(and (match-beginning 2)
2437 (not (member (match-string 2 line
)
2438 org-done-keywords
))))
2440 (if (<= lv level
) (throw 'exit nil
))
2441 (if todo
(throw 'exit t
))))))))
2443 (defun org-html-expand-for-ascii (line)
2444 "Handle quoted HTML for ASCII export."
2445 (if org-export-html-expand
2446 (while (string-match "@<[^<>\n]*>" line
)
2447 ;; We just remove the tags for now.
2448 (setq line
(replace-match "" nil nil line
))))
2451 (defun org-insert-centered (s &optional underline
)
2452 "Insert the string S centered and underline it with character UNDERLINE."
2453 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2454 (insert (make-string ind ?\
) s
"\n")
2456 (insert (make-string ind ?\
)
2457 (make-string (string-width s
) underline
)
2460 (defun org-ascii-level-start (level title umax
&optional lines
)
2461 "Insert a new level in ASCII export."
2462 (let (char (n (- level umax
1)) (ind 0))
2465 (insert (make-string (* 2 n
) ?\
)
2466 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2467 org-export-ascii-bullets
))
2469 ;; find the indentation of the next non-empty line
2472 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2473 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2474 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2476 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2477 (if (or (not (equal (char-before) ?
\n))
2478 (not (equal (char-before (1- (point))) ?
\n)))
2480 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2481 (unless org-export-with-tags
2482 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2483 (setq title
(replace-match "" t t title
))))
2484 (if org-export-with-section-numbers
2485 (setq title
(concat (org-section-number level
) " " title
)))
2486 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2487 (setq org-ascii-current-indentation
'(0 .
0)))))
2490 (defun org-export-visible (type arg
)
2491 "Create a copy of the visible part of the current buffer, and export it.
2492 The copy is created in a temporary buffer and removed after use.
2493 TYPE is the final key (as a string) that also select the export command in
2494 the `C-c C-e' export dispatcher.
2495 As a special case, if the you type SPC at the prompt, the temporary
2496 org-mode file will not be removed but presented to you so that you can
2497 continue to use it. The prefix arg ARG is passed through to the exporting
2501 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2502 (read-char-exclusive))
2503 current-prefix-arg
))
2504 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2505 (error "Invalid export key"))
2506 (let* ((binding (cdr (assoc type
2507 '((?a . org-export-as-ascii
)
2508 (?\C-a . org-export-as-ascii
)
2509 (?b . org-export-as-html-and-open
)
2510 (?\C-b . org-export-as-html-and-open
)
2511 (?h . org-export-as-html
)
2512 (?H . org-export-as-html-to-buffer
)
2513 (?R . org-export-region-as-html
)
2514 (?x . org-export-as-xoxo
)))))
2515 (keepp (equal type ?\
))
2516 (file buffer-file-name
)
2517 (buffer (get-buffer-create "*Org Export Visible*"))
2519 ;; Need to hack the drawers here.
2521 (goto-char (point-min))
2522 (while (re-search-forward org-drawer-regexp nil t
)
2523 (goto-char (match-beginning 1))
2524 (or (org-invisible-p) (org-flag-drawer nil
))))
2525 (with-current-buffer buffer
(erase-buffer))
2527 (setq s
(goto-char (point-min)))
2528 (while (not (= (point) (point-max)))
2529 (goto-char (org-find-invisible))
2530 (append-to-buffer buffer s
(point))
2531 (setq s
(goto-char (org-find-visible))))
2532 (org-cycle-hide-drawers 'all
)
2533 (goto-char (point-min))
2535 ;; Copy all comment lines to the end, to make sure #+ settings are
2536 ;; still available for the second export step. Kind of a hack, but
2537 ;; does do the trick.
2538 (if (looking-at "#[^\r\n]*")
2539 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2540 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2541 (append-to-buffer buffer
(1+ (match-beginning 0))
2542 (min (point-max) (1+ (match-end 0))))))
2544 (let ((buffer-file-name file
)
2545 (org-inhibit-startup t
))
2548 (unless keepp
(funcall binding arg
))))
2550 (kill-buffer buffer
)
2551 (switch-to-buffer-other-window buffer
)
2552 (goto-char (point-min)))))
2554 (defun org-find-visible ()
2556 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2557 (get-char-property s
'invisible
)))
2559 (defun org-find-invisible ()
2561 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2562 (not (get-char-property s
'invisible
))))
2567 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2568 (defun org-get-current-options ()
2569 "Return a string with current options as keyword options.
2570 Does include HTML export options as well as TODO and CATEGORY stuff."
2571 (require 'org-archive
)
2578 #+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
2580 #+EXPORT_SELECT_TAGS: %s
2581 #+EXPORT_EXCUDE_TAGS: %s
2587 #+PRIORITIES: %c %c %c
2589 #+STARTUP: %s %s %s %s %s
2595 (buffer-name) (user-full-name) user-mail-address
2596 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2597 org-export-default-language
2598 org-export-headline-levels
2599 org-export-with-section-numbers
2601 org-export-preserve-breaks
2602 org-export-html-expand
2603 org-export-with-fixed-width
2604 org-export-with-tables
2605 org-export-with-sub-superscripts
2606 org-export-with-special-strings
2607 org-export-with-footnotes
2608 org-export-with-emphasize
2609 org-export-with-TeX-macros
2610 org-export-with-LaTeX-fragments
2611 org-export-skip-text-before-1st-heading
2612 org-export-with-drawers
2613 org-export-with-tags
2614 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2615 (mapconcat 'identity org-export-select-tags
" ")
2616 (mapconcat 'identity org-export-exclude-tags
" ")
2617 org-export-html-link-up
2618 org-export-html-link-home
2619 (file-name-nondirectory buffer-file-name
)
2620 "TODO FEEDBACK VERIFY DONE"
2621 "Me Jason Marie DONE"
2622 org-highest-priority org-lowest-priority org-default-priority
2623 (mapconcat 'identity org-drawers
" ")
2624 (cdr (assoc org-startup-folded
2625 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2626 (if org-odd-levels-only
"odd" "oddeven")
2627 (if org-hide-leading-stars
"hidestars" "showstars")
2628 (if org-startup-align-all-tables
"align" "noalign")
2629 (cond ((eq org-log-done t
) "logdone")
2630 ((equal org-log-done
'note
) "lognotedone")
2631 ((not org-log-done
) "nologdone"))
2632 (or (mapconcat (lambda (x)
2634 ((equal '(:startgroup
) x
) "{")
2635 ((equal '(:endgroup
) x
) "}")
2636 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2638 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2639 (mapconcat 'identity org-file-tags
" ")
2640 org-archive-location
2641 "org file:~/org/%s.org"
2644 (defun org-export-html-preprocess (parameters)
2645 ;; Convert LaTeX fragments to images
2646 (when (plist-get parameters
:LaTeX-fragments
)
2648 (concat "ltxpng/" (file-name-sans-extension
2649 (file-name-nondirectory
2650 org-current-export-file
)))
2651 org-current-export-dir nil
"Creating LaTeX image %s"))
2652 (message "Exporting..."))
2655 (defun org-insert-export-options-template ()
2656 "Insert into the buffer a template with information for exporting."
2658 (if (not (bolp)) (newline))
2659 (let ((s (org-get-current-options)))
2660 (and (string-match "#\\+CATEGORY" s
)
2661 (setq s
(substring s
0 (match-beginning 0))))
2665 (defun org-export-as-html-and-open (arg)
2666 "Export the outline as HTML and immediately open it with a browser.
2667 If there is an active region, export only the region.
2668 The prefix ARG specifies how many levels of the outline should become
2669 headlines. The default is 3. Lower levels will become bulleted lists."
2671 (org-export-as-html arg
'hidden
)
2672 (org-open-file buffer-file-name
))
2675 (defun org-export-as-html-batch ()
2676 "Call `org-export-as-html', may be used in batch processing as
2678 --load=$HOME/lib/emacs/org.el
2679 --eval \"(setq org-export-headline-levels 2)\"
2680 --visit=MyFile --funcall org-export-as-html-batch"
2681 (org-export-as-html org-export-headline-levels
'hidden
))
2684 (defun org-export-as-html-to-buffer (arg)
2685 "Call `org-exort-as-html` with output to a temporary buffer.
2686 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2688 (org-export-as-html arg nil nil
"*Org HTML Export*")
2689 (switch-to-buffer-other-window "*Org HTML Export*"))
2692 (defun org-replace-region-by-html (beg end
)
2693 "Assume the current region has org-mode syntax, and convert it to HTML.
2694 This can be used in any buffer. For example, you could write an
2695 itemized list in org-mode syntax in an HTML buffer and then use this
2696 command to convert it."
2698 (let (reg html buf pop-up-frames
)
2699 (save-window-excursion
2701 (setq html
(org-export-region-as-html
2703 (setq reg
(buffer-substring beg end
)
2704 buf
(get-buffer-create "*Org tmp*"))
2705 (with-current-buffer buf
2709 (setq html
(org-export-region-as-html
2710 (point-min) (point-max) t
'string
)))
2712 (delete-region beg end
)
2716 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2717 "Convert region from BEG to END in org-mode buffer to HTML.
2718 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2719 contents, and only produce the region of converted text, useful for
2720 cut-and-paste operations.
2721 If BUFFER is a buffer or a string, use/create that buffer as a target
2722 of the converted HTML. If BUFFER is the symbol `string', return the
2723 produced HTML as a string and leave not buffer behind. For example,
2724 a Lisp program could call this function in the following way:
2726 (setq html (org-export-region-as-html beg end t 'string))
2728 When called interactively, the output buffer is selected, and shown
2729 in a window. A non-interactive call will only return the buffer."
2730 (interactive "r\nP")
2731 (when (interactive-p)
2732 (setq buffer
"*Org HTML Export*"))
2733 (let ((transient-mark-mode t
) (zmacs-regions t
)
2735 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
2737 (set-mark (point)) ;; to activate the region
2739 (setq rtn
(org-export-as-html
2742 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2743 (if (and (interactive-p) (bufferp rtn
))
2744 (switch-to-buffer-other-window rtn
)
2747 (defvar html-table-tag nil
) ; dynamically scoped into this.
2749 (defun org-export-as-html (arg &optional hidden ext-plist
2750 to-buffer body-only pub-dir
)
2751 "Export the outline as a pretty HTML file.
2752 If there is an active region, export only the region. The prefix
2753 ARG specifies how many levels of the outline should become
2754 headlines. The default is 3. Lower levels will become bulleted
2755 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2756 EXT-PLIST is a property list with external parameters overriding
2757 org-mode's default settings, but still inferior to file-local
2758 settings. When TO-BUFFER is non-nil, create a buffer with that
2759 name and export to that buffer. If TO-BUFFER is the symbol
2760 `string', don't leave any buffer behind but just return the
2761 resulting HTML as a string. When BODY-ONLY is set, don't produce
2762 the file header and footer, simply return the content of
2763 <body>...</body>, without even the body tags themselves. When
2764 PUB-DIR is set, use this as the publishing directory."
2767 ;; Make sure we have a file name when we need it.
2768 (when (and (not (or to-buffer body-only
))
2769 (not buffer-file-name
))
2770 (if (buffer-base-buffer)
2771 (org-set-local 'buffer-file-name
2772 (with-current-buffer (buffer-base-buffer)
2774 (error "Need a file name to be able to export.")))
2776 (message "Exporting...")
2777 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2778 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2779 (setq-default org-done-keywords org-done-keywords
)
2780 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2782 (org-export-process-option-filters
2783 (org-combine-plists (org-default-export-plist)
2785 (org-infile-export-plist))))
2787 (style (concat org-export-html-style-default
2788 (plist-get opt-plist
:style
)
2789 (plist-get opt-plist
:style-extra
)))
2790 (html-extension (plist-get opt-plist
:html-extension
))
2791 (link-validate (plist-get opt-plist
:link-validation-function
))
2792 valid thetoc have-headings first-heading-pos
2793 (odd org-odd-levels-only
)
2794 (region-p (org-region-active-p))
2795 (rbeg (and region-p
(region-beginning)))
2796 (rend (and region-p
(region-end)))
2798 (if (plist-get opt-plist
:ignore-subree-p
)
2803 (and (org-at-heading-p)
2804 (>= (org-end-of-subtree t t
) rend
))))))
2805 (opt-plist (if subtree-p
2806 (org-export-add-subtree-options opt-plist rbeg
)
2808 ;; The following two are dynamically scoped into other
2810 (org-current-export-dir
2811 (or pub-dir
(org-export-directory :html opt-plist
)))
2812 (org-current-export-file buffer-file-name
)
2813 (level 0) (line "") (origline "") txt todo
2816 (filename (if to-buffer nil
2819 (file-name-sans-extension
2821 (org-entry-get (region-beginning)
2822 "EXPORT_FILE_NAME" t
))
2823 (file-name-nondirectory buffer-file-name
)))
2825 (file-name-as-directory
2826 (or pub-dir
(org-export-directory :html opt-plist
))))))
2827 (current-dir (if buffer-file-name
2828 (file-name-directory buffer-file-name
)
2830 (buffer (if to-buffer
2832 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2833 (t (get-buffer-create to-buffer
)))
2834 (find-file-noselect filename
)))
2835 (org-levels-open (make-vector org-level-max nil
))
2836 (date (plist-get opt-plist
:date
))
2837 (author (plist-get opt-plist
:author
))
2838 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2839 (plist-get opt-plist
:title
)
2841 (plist-get opt-plist
:skip-before-1st-heading
))
2842 (org-export-grab-title-from-buffer))
2843 (and buffer-file-name
2844 (file-name-sans-extension
2845 (file-name-nondirectory buffer-file-name
)))
2847 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2848 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2849 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2854 (local-list-type nil
)
2855 (local-list-indent nil
)
2856 (llt org-plain-list-ordered-item-terminator
)
2857 (email (plist-get opt-plist
:email
))
2858 (language (plist-get opt-plist
:language
))
2862 (coding-system (and (boundp 'buffer-file-coding-system
)
2863 buffer-file-coding-system
))
2864 (coding-system-for-write (or org-export-html-coding-system
2866 (save-buffer-coding-system (or org-export-html-coding-system
2868 (charset (and coding-system-for-write
2869 (fboundp 'coding-system-get
)
2870 (coding-system-get coding-system-for-write
2874 (if region-p
(region-beginning) (point-min))
2875 (if region-p
(region-end) (point-max))))
2878 (org-export-preprocess-string
2882 :skip-before-1st-heading
2883 (plist-get opt-plist
:skip-before-1st-heading
)
2884 :drawers
(plist-get opt-plist
:drawers
)
2886 (plist-get opt-plist
:archived-trees
)
2887 :select-tags
(plist-get opt-plist
:select-tags
)
2888 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2890 (plist-get opt-plist
:text
)
2892 (plist-get opt-plist
:LaTeX-fragments
))
2895 table-buffer table-orig-buffer
2896 ind item-type starter didclose
2897 rpl path attr desc descp desc1 desc2 link
2898 snumber fnc item-tag
2901 (let ((inhibit-read-only t
))
2903 (remove-text-properties (point-min) (point-max)
2904 '(:org-license-to-kill t
))))
2906 (message "Exporting...")
2908 (setq org-min-level
(org-get-min-level lines
))
2909 (setq org-last-level org-min-level
)
2910 (org-init-section-numbers)
2913 ((and date
(string-match "%" date
))
2914 (setq date
(format-time-string date
)))
2916 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2918 ;; Get the language-dependent settings
2919 (setq lang-words
(or (assoc language org-export-language-setup
)
2920 (assoc "en" org-export-language-setup
)))
2922 ;; Switch to the output buffer
2924 (let ((inhibit-read-only t
)) (erase-buffer))
2927 (and (fboundp 'set-buffer-file-coding-system
)
2928 (set-buffer-file-coding-system coding-system-for-write
))
2930 (let ((case-fold-search nil
)
2931 (org-odd-levels-only odd
))
2932 ;; create local variables for all options, to make sure all called
2933 ;; functions get the correct information
2935 (set (make-local-variable (cdr x
))
2936 (plist-get opt-plist
(car x
))))
2937 org-export-plist-vars
)
2938 (setq umax
(if arg
(prefix-numeric-value arg
)
2939 org-export-headline-levels
))
2940 (setq umax-toc
(if (integerp org-export-with-toc
)
2941 (min org-export-with-toc umax
)
2946 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2947 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2948 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2949 lang=\"%s\" xml:lang=\"%s\">
2952 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2953 <meta name=\"generator\" content=\"Org-mode\"/>
2954 <meta name=\"generated\" content=\"%s\"/>
2955 <meta name=\"author\" content=\"%s\"/>
2959 language language
(org-html-expand title
)
2960 (or charset
"iso-8859-1") date author style
))
2962 (insert (or (plist-get opt-plist
:preamble
) ""))
2964 (when (plist-get opt-plist
:auto-preamble
)
2965 (if title
(insert (format org-export-html-title-format
2966 (org-html-expand title
))))))
2968 (if (and org-export-with-toc
(not body-only
))
2970 (push (format "<h%d>%s</h%d>\n"
2971 org-export-html-toplevel-hlevel
2973 org-export-html-toplevel-hlevel
)
2975 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2976 (push "<ul>\n<li>" thetoc
)
2978 (mapcar '(lambda (line)
2979 (if (string-match org-todo-line-regexp line
)
2980 ;; This is a headline
2982 (setq have-headings t
)
2983 (setq level
(- (match-end 1) (match-beginning 1))
2984 level
(org-tr-level level
)
2985 txt
(save-match-data
2987 (org-export-cleanup-toc-line
2988 (match-string 3 line
))))
2990 (or (and org-export-mark-todo-in-toc
2992 (not (member (match-string 2 line
)
2993 org-done-keywords
)))
2995 (and org-export-mark-todo-in-toc
2997 (org-search-todo-below
2998 line lines level
))))
3000 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3001 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3002 (if (string-match quote-re0 txt
)
3003 (setq txt
(replace-match "" t t txt
)))
3004 (setq snumber
(org-section-number level
))
3005 (if org-export-with-section-numbers
3006 (setq txt
(concat snumber
" " txt
)))
3007 (if (<= level
(max umax umax-toc
))
3008 (setq head-count
(+ head-count
1)))
3009 (if (<= level umax-toc
)
3011 (if (> level org-last-level
)
3013 (setq cnt
(- level org-last-level
))
3014 (while (>= (setq cnt
(1- cnt
)) 0)
3015 (push "\n<ul>\n<li>" thetoc
))
3016 (push "\n" thetoc
)))
3017 (if (< level org-last-level
)
3019 (setq cnt
(- org-last-level level
))
3020 (while (>= (setq cnt
(1- cnt
)) 0)
3021 (push "</li>\n</ul>" thetoc
))
3022 (push "\n" thetoc
)))
3023 ;; Check for targets
3024 (while (string-match org-any-target-regexp line
)
3025 (setq line
(replace-match
3026 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3028 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3029 (setq txt
(replace-match "" t t txt
)))
3033 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3034 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3035 snumber txt
) thetoc
)
3037 (setq org-last-level level
))
3041 (while (> org-last-level
(1- org-min-level
))
3042 (setq org-last-level
(1- org-last-level
))
3043 (push "</li>\n</ul>\n" thetoc
))
3044 (push "</div>\n" thetoc
)
3045 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3048 (org-init-section-numbers)
3052 (while (setq line
(pop lines
) origline line
)
3055 ;; end of quote section?
3056 (when (and inquote
(string-match "^\\*+ " line
))
3059 ;; inside a quote section?
3061 (insert (org-html-protect line
) "\n")
3062 (throw 'nextline nil
))
3064 ;; Fixed-width, verbatim lines (examples)
3065 (when (and org-export-with-fixed-width
3066 (string-match "^[ \t]*:\\(.*\\)" line
))
3069 (insert "<pre class=\"example\">\n"))
3070 (insert (org-html-protect (match-string 1 line
)) "\n")
3071 (when (or (not lines
)
3072 (not (string-match "^[ \t]*\\(:.*\\)"
3075 (insert "</pre>\n"))
3076 (throw 'nextline nil
))
3079 (when (get-text-property 0 'org-protected line
)
3081 (when (re-search-backward
3082 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3083 (setq par
(match-string 1))
3084 (replace-match "\\2\n"))
3087 (not (string-match "^[ \t]*:" (car lines
)))
3088 (or (= (length (car lines
)) 0)
3089 (get-text-property 0 'org-protected
(car lines
))))
3090 (insert (pop lines
) "\n"))
3091 (and par
(insert "<p>\n")))
3092 (throw 'nextline nil
))
3095 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3096 (insert "\n<hr/>\n")
3097 (throw 'nextline nil
))
3099 ;; Blockquotes and verse
3100 (when (equal "ORG-BLOCKQUOTE-START" line
)
3101 (insert "<blockquote>\n<p>\n")
3102 (throw 'nextline nil
))
3103 (when (equal "ORG-BLOCKQUOTE-END" line
)
3104 (insert "</p>\n</blockquote>\n")
3105 (throw 'nextline nil
))
3106 (when (equal "ORG-VERSE-START" line
)
3107 (insert "\n<p class=\"verse\">\n")
3109 (throw 'nextline nil
))
3110 (when (equal "ORG-VERSE-END" line
)
3113 (throw 'nextline nil
))
3115 (let ((i (org-get-string-indentation line
)))
3117 (setq line
(concat (mapconcat 'identity
3118 (make-list (* 2 i
) "\\nbsp") "")
3119 " " (org-trim line
))))
3120 (setq line
(concat line
" \\\\"))))
3122 ;; make targets to anchors
3123 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3126 (setq line
(replace-match
3127 (concat "@<a name=\""
3128 (org-solidify-link-text (match-string 1 line
))
3131 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3132 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3133 (setq line
(replace-match
3134 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3135 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3138 (setq line
(replace-match
3139 (concat "@<a name=\""
3140 (org-solidify-link-text (match-string 1 line
))
3141 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3144 (setq line
(org-html-handle-time-stamps line
))
3146 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3147 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3148 ;; Also handle sub_superscripts and checkboxes
3149 (or (string-match org-table-hline-regexp line
)
3150 (setq line
(org-html-expand line
)))
3154 (while (string-match org-bracket-link-analytic-regexp line start
)
3155 (setq start
(match-beginning 0))
3156 (setq path
(save-match-data (org-link-unescape
3157 (match-string 3 line
))))
3159 ((match-end 2) (match-string 2 line
))
3161 (or (file-name-absolute-p path
)
3162 (string-match "^\\.\\.?/" path
)))
3165 (setq path
(org-extract-attributes path
))
3166 (setq attr
(org-attributes-to-string
3167 (get-text-property 0 'org-attributes path
)))
3168 (setq desc1
(if (match-end 5) (match-string 5 line
))
3169 desc2
(if (match-end 2) (concat type
":" path
) path
)
3170 descp
(and desc1
(not (equal desc1 desc2
)))
3171 desc
(or desc1 desc2
))
3172 ;; Make an image out of the description if that is so wanted
3173 (when (and descp
(org-file-image-p desc
))
3175 (if (string-match "^file:" desc
)
3176 (setq desc
(substring desc
(match-end 0)))))
3177 (setq desc
(concat "<img src=\"" desc
"\"/>")))
3178 ;; FIXME: do we need to unescape here somewhere?
3180 ((equal type
"internal")
3184 (org-solidify-link-text
3185 (save-match-data (org-link-unescape path
)) nil
)
3186 "\"" attr
">" desc
"</a>")))
3187 ((member type
'("http" "https"))
3188 ;; standard URL, just check if we need to inline an image
3189 (if (and (or (eq t org-export-html-inline-images
)
3190 (and org-export-html-inline-images
(not descp
)))
3191 (org-file-image-p path
))
3192 (setq rpl
(concat "<img src=\"" type
":" path
"\"" attr
"/>"))
3193 (setq link
(concat type
":" path
))
3194 (setq rpl
(concat "<a href=\"" link
"\"" attr
">"
3196 ((member type
'("ftp" "mailto" "news"))
3198 (setq link
(concat type
":" path
))
3199 (setq rpl
(concat "<a href=\"" link
"\"" attr
">" desc
"</a>")))
3201 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3202 ;; The link protocol has a function for format the link
3205 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3207 ((string= type
"file")
3209 (let* ((filename path
)
3210 (abs-p (file-name-absolute-p filename
))
3211 thefile file-is-image-p search
)
3213 (if (string-match "::\\(.*\\)" filename
)
3214 (setq search
(match-string 1 filename
)
3215 filename
(replace-match "" t nil filename
)))
3217 (if (functionp link-validate
)
3218 (funcall link-validate filename current-dir
)
3220 (setq file-is-image-p
(org-file-image-p filename
))
3221 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3222 (when (and org-export-html-link-org-files-as-html
3223 (string-match "\\.org$" thefile
))
3224 (setq thefile
(concat (substring thefile
0
3225 (match-beginning 0))
3226 "." html-extension
))
3228 ;; make sure this is can be used as target search
3229 (not (string-match "^[0-9]*$" search
))
3230 (not (string-match "^\\*" search
))
3231 (not (string-match "^/.*/$" search
)))
3232 (setq thefile
(concat thefile
"#"
3233 (org-solidify-link-text
3234 (org-link-unescape search
)))))
3235 (when (string-match "^file:" desc
)
3236 (setq desc
(replace-match "" t t desc
))
3237 (if (string-match "\\.org$" desc
)
3238 (setq desc
(replace-match "" t t desc
))))))
3239 (setq rpl
(if (and file-is-image-p
3240 (or (eq t org-export-html-inline-images
)
3241 (and org-export-html-inline-images
3243 (concat "<img src=\"" thefile
"\"" attr
"/>")
3244 (concat "<a href=\"" thefile
"\"" attr
">"
3246 (if (not valid
) (setq rpl desc
))))
3249 ;; just publish the path, as default
3250 (setq rpl
(concat "<i><" type
":"
3251 (save-match-data (org-link-unescape path
))
3253 (setq line
(replace-match rpl t t line
)
3254 start
(+ start
(length rpl
))))
3257 (if (and (string-match org-todo-line-regexp line
)
3258 (match-beginning 2))
3261 (concat (substring line
0 (match-beginning 2))
3263 (if (member (match-string 2 line
)
3266 "\">" (match-string 2 line
)
3267 "</span>" (substring line
(match-end 2)))))
3269 ;; Does this contain a reference to a footnote?
3270 (when org-export-with-footnotes
3272 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3273 (if (get-text-property (match-beginning 2) 'org-protected line
)
3274 (setq start
(match-end 2))
3275 (let ((n (match-string 2 line
)))
3279 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3280 (match-string 1 line
) n n n
)
3284 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3285 ;; This is a headline
3286 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3287 txt
(match-string 2 line
))
3288 (if (string-match quote-re0 txt
)
3289 (setq txt
(replace-match "" t t txt
)))
3290 (if (<= level
(max umax umax-toc
))
3291 (setq head-count
(+ head-count
1)))
3293 ;; Close any local lists before inserting a new header line
3294 (while local-list-type
3295 (org-close-li (car local-list-type
))
3296 (insert (format "</%sl>\n" (car local-list-type
)))
3297 (pop local-list-type
))
3298 (setq local-list-indent nil
3300 (setq first-heading-pos
(or first-heading-pos
(point)))
3301 (org-html-level-start level txt umax
3302 (and org-export-with-toc
(<= level umax
))
3305 (when (string-match quote-re line
)
3309 ((and org-export-with-tables
3310 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3311 (if (not table-open
)
3313 (setq table-open t table-buffer nil table-orig-buffer nil
))
3315 (setq table-buffer
(cons line table-buffer
)
3316 table-orig-buffer
(cons origline table-orig-buffer
))
3317 (when (or (not lines
)
3318 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3320 (setq table-open nil
3321 table-buffer
(nreverse table-buffer
)
3322 table-orig-buffer
(nreverse table-orig-buffer
))
3323 (org-close-par-maybe)
3324 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3329 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3330 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3331 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3332 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3334 (setq ind
(org-get-string-indentation line
)
3335 item-type
(if (match-beginning 4) "o" "u")
3336 starter
(if (match-beginning 2)
3337 (substring (match-string 2 line
) 0 -
1))
3338 line
(substring line
(match-beginning 5))
3340 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3342 item-tag
(match-string 1 line
)
3343 line
(substring line
(match-end 0))))
3344 (when (and (not (equal item-type
"d"))
3345 (not (string-match "[^ \t]" line
)))
3346 ;; empty line. Pretend indentation is large.
3347 (setq ind
(if org-empty-line-terminates-plain-lists
3349 (1+ (or (car local-list-indent
) 1)))))
3351 (while (and in-local-list
3352 (or (and (= ind
(car local-list-indent
))
3354 (< ind
(car local-list-indent
))))
3356 (org-close-li (car local-list-type
))
3357 (insert (format "</%sl>\n" (car local-list-type
)))
3358 (pop local-list-type
) (pop local-list-indent
)
3359 (setq in-local-list local-list-indent
))
3362 (or (not in-local-list
)
3363 (> ind
(car local-list-indent
))))
3364 ;; Start new (level of) list
3365 (org-close-par-maybe)
3367 ((equal item-type
"u") "<ul>\n<li>\n")
3368 ((equal item-type
"o") "<ol>\n<li>\n")
3369 ((equal item-type
"d")
3370 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3371 (push item-type local-list-type
)
3372 (push ind local-list-indent
)
3373 (setq in-local-list t
))
3375 ;; continue current list
3376 (org-close-li (car local-list-type
))
3378 ((equal (car local-list-type
) "d")
3379 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3382 ;; we did close a list, normal text follows: need <p>
3384 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3387 (if (equal (match-string 1 line
) "X")
3389 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3392 ;; Empty lines start a new paragraph. If hand-formatted lists
3393 ;; are not fully interpreted, lines starting with "-", "+", "*"
3394 ;; also start a new paragraph.
3395 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3397 ;; Is this the start of a footnote?
3398 (when org-export-with-footnotes
3399 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3400 (org-close-par-maybe)
3401 (let ((n (match-string 1 line
)))
3402 (setq line
(replace-match
3403 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
))
3404 (setq line
(concat line
"</p>")))))
3406 ;; Check if the line break needs to be conserved
3408 ((string-match "\\\\\\\\[ \t]*$" line
)
3409 (setq line
(replace-match "<br/>" t t line
)))
3410 (org-export-preserve-breaks
3411 (setq line
(concat line
"<br/>"))))
3413 (insert line
"\n")))))
3415 ;; Properly close all local lists and other lists
3416 (when inquote
(insert "</pre>\n"))
3418 ;; Close any local lists before inserting a new header line
3419 (while local-list-type
3420 (org-close-li (car local-list-type
))
3421 (insert (format "</%sl>\n" (car local-list-type
)))
3422 (pop local-list-type
))
3423 (setq local-list-indent nil
3425 (org-html-level-start 1 nil umax
3426 (and org-export-with-toc
(<= level umax
))
3428 ;; the </div> to close the last text-... div.
3432 (when (plist-get opt-plist
:auto-postamble
)
3433 (insert "<div id=\"postamble\">")
3434 (when (and org-export-author-info author
)
3435 (insert "<p class=\"author\"> "
3436 (nth 1 lang-words
) ": " author
"\n")
3438 (if (listp (split-string email
",+ *"))
3440 (insert "<a href=\"mailto:" e
"\"><"
3442 (split-string email
",+ *"))
3443 (insert "<a href=\"mailto:" email
"\"><"
3444 email
"></a>\n")))
3446 (when (and date org-export-time-stamp-file
)
3447 (insert "<p class=\"date\"> "
3448 (nth 2 lang-words
) ": "
3450 (when org-export-creator-info
3451 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3452 org-version emacs-major-version
)))
3455 (if org-export-html-with-timestamp
3456 (insert org-export-html-html-helper-timestamp
))
3457 (insert (or (plist-get opt-plist
:postamble
) ""))
3458 (insert "</body>\n</html>\n"))
3460 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3462 (if (eq major-mode default-major-mode
) (html-mode)))
3464 ;; insert the table of contents
3465 (goto-char (point-min))
3467 (if (or (re-search-forward
3468 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3470 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3472 (goto-char (match-beginning 0))
3474 (goto-char first-heading-pos
)
3475 (when (looking-at "\\s-*</p>")
3476 (goto-char (match-end 0))
3478 (insert "<div id=\"table-of-contents\">\n")
3479 (mapc 'insert thetoc
)
3480 (insert "</div>\n"))
3481 ;; remove empty paragraphs and lists
3482 (goto-char (point-min))
3483 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3485 (goto-char (point-min))
3486 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3488 (goto-char (point-min))
3489 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3491 ;; Convert whitespace place holders
3492 (goto-char (point-min))
3494 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3495 (setq n
(get-text-property beg
'org-whitespace
)
3496 end
(next-single-property-change beg
'org-whitespace
))
3498 (delete-region beg end
)
3499 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3500 (make-string n ?x
)))))
3501 (or to-buffer
(save-buffer))
3502 (goto-char (point-min))
3503 (message "Exporting... done")
3504 (if (eq to-buffer
'string
)
3505 (prog1 (buffer-substring (point-min) (point-max))
3506 (kill-buffer (current-buffer)))
3507 (current-buffer)))))
3510 (defvar org-table-colgroup-info nil
)
3511 (defun org-format-table-ascii (lines)
3512 "Format a table for ascii export."
3514 (setq lines
(org-split-string lines
"\n")))
3515 (if (not (string-match "^[ \t]*|" (car lines
)))
3516 ;; Table made by table.el - test for spanning
3519 ;; A normal org table
3520 ;; Get rid of hlines at beginning and end
3521 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3522 (setq lines
(nreverse lines
))
3523 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3524 (setq lines
(nreverse lines
))
3525 (when org-export-table-remove-special-lines
3526 ;; Check if the table has a marking column. If yes remove the
3527 ;; column and the special lines
3528 (setq lines
(org-table-clean-before-export lines
)))
3529 ;; Get rid of the vertical lines except for grouping
3530 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3532 (while (setq line
(pop lines
))
3533 (if (string-match org-table-hline-regexp line
)
3534 (and (string-match "|\\(.*\\)|" line
)
3535 (setq line
(replace-match " \\1" t nil line
)))
3536 (setq start
0 vl1 vl
)
3537 (while (string-match "|" line start
)
3538 (setq start
(match-end 0))
3539 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3543 (defun org-colgroup-info-to-vline-list (info)
3546 (setq last new new
(pop info
))
3547 (if (or (memq last
'(:end
:startend
))
3548 (memq new
'(:start
:startend
)))
3551 (setq vl
(nreverse vl
))
3552 (and vl
(setcar vl nil
))
3555 (defvar org-table-number-regexp
) ; defined in org-table.el
3556 (defun org-format-table-html (lines olines
)
3557 "Find out which HTML converter to use and return the HTML code."
3559 (setq lines
(org-split-string lines
"\n")))
3560 (if (string-match "^[ \t]*|" (car lines
))
3561 ;; A normal org table
3562 (org-format-org-table-html lines
)
3563 ;; Table made by table.el - test for spanning
3564 (let* ((hlines (delq nil
(mapcar
3566 (if (string-match "^[ \t]*\\+-" x
) x
3569 (first (car hlines
))
3570 (ll (and (string-match "\\S-+" first
)
3571 (match-string 0 first
)))
3572 (re (concat "^[ \t]*" (regexp-quote ll
)))
3573 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3575 (if (and (not spanning
)
3576 (not org-export-prefer-native-exporter-for-tables
))
3577 ;; We can use my own converter with HTML conversions
3578 (org-format-table-table-html lines
)
3579 ;; Need to use the code generator in table.el, with the original text.
3580 (org-format-table-table-html-using-table-generate-source olines
)))))
3582 (defvar org-table-number-fraction
) ; defined in org-table.el
3583 (defun org-format-org-table-html (lines &optional splice
)
3584 "Format a table into HTML."
3585 (require 'org-table
)
3586 ;; Get rid of hlines at beginning and end
3587 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3588 (setq lines
(nreverse lines
))
3589 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3590 (setq lines
(nreverse lines
))
3591 (when org-export-table-remove-special-lines
3592 ;; Check if the table has a marking column. If yes remove the
3593 ;; column and the special lines
3594 (setq lines
(org-table-clean-before-export lines
)))
3596 (let ((head (and org-export-highlight-first-table-line
3598 (lambda (x) (string-match "^[ \t]*|-" x
))
3601 tbopen line fields html gr colgropen
)
3602 (if splice
(setq head nil
))
3603 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3605 (while (setq line
(pop lines
))
3607 (if (string-match "^[ \t]*|-" line
)
3610 (push (if head
"</thead>" "</tbody>") html
)
3611 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3612 (setq head nil
) ;; head ends here, first time around
3614 (throw 'next-line t
)))
3615 ;; Break the line into fields
3616 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3617 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3618 (setq nlines
(1+ nlines
) i -
1)
3619 (push (concat "<tr>"
3623 (if (and (< i nlines
)
3624 (string-match org-table-number-regexp x
))
3625 (incf (aref fnum i
)))
3627 (concat (car org-export-table-header-tags
) x
3628 (cdr org-export-table-header-tags
))
3629 (concat (car org-export-table-data-tags
) x
3630 (cdr org-export-table-data-tags
))))
3634 (unless splice
(if tbopen
(push "</tbody>" html
)))
3635 (unless splice
(push "</table>\n" html
))
3636 (setq html
(nreverse html
))
3638 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3641 (setq gr
(pop org-table-colgroup-info
))
3642 (format "%s<col align=\"%s\"></col>%s"
3643 (if (memq gr
'(:start
:startend
))
3645 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3648 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3650 (if (memq gr
'(:end
:startend
))
3651 (progn (setq colgropen nil
) "</colgroup>")
3655 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3656 (push html-table-tag html
))
3657 (concat (mapconcat 'identity html
"\n") "\n")))
3659 (defun org-table-clean-before-export (lines)
3660 "Check if the table has a marking column.
3661 If yes remove the column and the special lines."
3662 (setq org-table-colgroup-info nil
)
3665 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3666 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3669 (setq org-table-clean-did-remove-column nil
)
3674 ((string-match "^[ \t]*| */ *|" x
)
3675 (setq org-table-colgroup-info
3677 (cond ((member x
'("<" "<")) :start
)
3678 ((member x
'(">" ">")) :end
)
3679 ((member x
'("<>" "<>")) :startend
)
3681 (org-split-string x
"[ \t]*|[ \t]*")))
3685 (setq org-table-clean-did-remove-column t
)
3690 ((string-match "^[ \t]*| */ *|" x
)
3691 (setq org-table-colgroup-info
3693 (cond ((member x
'("<" "<")) :start
)
3694 ((member x
'(">" ">")) :end
)
3695 ((member x
'("<>" "<>")) :startend
)
3697 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3699 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3700 nil
) ; ignore this line
3701 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3702 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3703 ;; remove the first column
3704 (replace-match "\\1|" t nil x
))))
3707 (defun org-format-table-table-html (lines)
3708 "Format a table generated by table.el into HTML.
3709 This conversion does *not* use `table-generate-source' from table.el.
3710 This has the advantage that Org-mode's HTML conversions can be used.
3711 But it has the disadvantage, that no cell- or row-spanning is allowed."
3712 (let (line field-buffer
3713 (head org-export-highlight-first-table-line
)
3715 (setq html
(concat html-table-tag
"\n"))
3716 (while (setq line
(pop lines
))
3717 (setq empty
" ")
3719 (if (string-match "^[ \t]*\\+-" line
)
3730 (if (equal x
"") (setq x empty
))
3732 (concat (car org-export-table-header-tags
) x
3733 (cdr org-export-table-header-tags
))
3734 (concat (car org-export-table-data-tags
) x
3735 (cdr org-export-table-data-tags
))))
3739 (setq field-buffer nil
)))
3741 (throw 'next-line t
)))
3742 ;; Break the line into fields and store the fields
3743 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3745 (setq field-buffer
(mapcar
3747 (concat x
"<br/>" (pop fields
)))
3749 (setq field-buffer fields
))))
3750 (setq html
(concat html
"</table>\n"))
3753 (defun org-format-table-table-html-using-table-generate-source (lines)
3754 "Format a table into html, using `table-generate-source' from table.el.
3755 This has the advantage that cell- or row-spanning is allowed.
3756 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3758 (with-current-buffer (get-buffer-create " org-tmp1 ")
3760 (insert (mapconcat 'identity lines
"\n"))
3761 (goto-char (point-min))
3762 (if (not (re-search-forward "|[^+]" nil t
))
3763 (error "Error processing table"))
3764 (table-recognize-table)
3765 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3766 (table-generate-source 'html
" org-tmp2 ")
3767 (set-buffer " org-tmp2 ")
3768 (buffer-substring (point-min) (point-max))))
3770 (defun org-export-splice-style (style extra
)
3771 "Splice EXTRA into STYLE, just before \"</style>\"."
3772 (if (and (stringp extra
)
3773 (string-match "\\S-" extra
)
3774 (string-match "</style>" style
))
3775 (concat (substring style
0 (match-beginning 0))
3777 (substring style
(match-beginning 0)))
3780 (defun org-html-handle-time-stamps (s)
3781 "Format time stamps in string S, or remove them."
3784 (while (string-match org-maybe-keyword-time-regexp s
)
3785 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3786 ;; never export CLOCK
3788 (or b
(setq b
(substring s
0 (match-beginning 0))))
3789 (if (not org-export-with-timestamps
)
3790 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3791 s
(substring s
(match-end 0)))
3793 r
(substring s
0 (match-beginning 0))
3795 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3796 (match-string 1 s
)))
3797 (format " @<span class=\"timestamp\">%s@</span>"
3799 (org-translate-time (match-string 3 s
)) 1 -
1)))
3800 s
(substring s
(match-end 0)))))
3801 ;; Line break if line started and ended with time stamp stuff
3804 (setq r
(concat r s
))
3805 (unless (string-match "\\S-" (concat b s
))
3806 (setq r
(concat r
"@<br/>")))
3809 (defun org-export-htmlize-region-for-paste (beg end
)
3810 "Convert the region to HTML, using htmlize.el.
3811 This is much like `htmlize-region-for-paste', only that it uses
3812 the settings define in the org-... variables."
3813 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3814 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3815 (htmlbuf (htmlize-region beg end
)))
3817 (with-current-buffer htmlbuf
3818 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3819 (plist-get htmlize-buffer-places
'content-end
)))
3820 (kill-buffer htmlbuf
))))
3823 (defun org-export-htmlize-generate-css ()
3824 "Create the CSS for all font definitions in the current Emacs session.
3825 Use this to create face definitions in your CSS style file that can then
3826 be used by code snippets transformed by htmlize.
3827 This command just produces a buffer that contains class definitions for all
3828 faces used in the current Emacs session. You can copy and paste the ones you
3829 need into your CSS file.
3831 If you then set `org-export-htmlize-output-type' to `css', calls to
3832 the function `org-export-htmlize-region-for-paste' will produce code
3833 that uses these same face definitions."
3836 (and (get-buffer "*html*") (kill-buffer "*html*"))
3838 (let ((fl (face-list))
3839 (htmlize-css-name-prefix "org-")
3840 (htmlize-output-type 'css
)
3842 (while (setq f
(pop fl
)
3843 i
(and f
(face-attribute f
:inherit
)))
3844 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3845 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3846 (htmlize-region (point-min) (point-max))))
3847 (switch-to-buffer "*html*")
3848 (goto-char (point-min))
3849 (if (re-search-forward "<style" nil t
)
3850 (delete-region (point-min) (match-beginning 0)))
3851 (if (re-search-forward "</style>" nil t
)
3852 (delete-region (1+ (match-end 0)) (point-max)))
3853 (beginning-of-line 1)
3854 (if (looking-at " +") (replace-match ""))
3855 (goto-char (point-min)))
3857 (defun org-html-protect (s)
3858 ;; convert & to &, < to < and > to >
3860 (while (string-match "&" s start
)
3861 (setq s
(replace-match "&" t t s
)
3862 start
(1+ (match-beginning 0))))
3863 (while (string-match "<" s
)
3864 (setq s
(replace-match "<" t t s
)))
3865 (while (string-match ">" s
)
3866 (setq s
(replace-match ">" t t s
))))
3869 (defun org-export-cleanup-toc-line (s)
3870 "Remove tags and time staps from lines going into the toc."
3871 (when (memq org-export-with-tags
'(not-in-toc nil
))
3872 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3873 (setq s
(replace-match "" t t s
))))
3874 (when org-export-remove-timestamps-from-toc
3875 (while (string-match org-maybe-keyword-time-regexp s
)
3876 (setq s
(replace-match "" t t s
))))
3877 (while (string-match org-bracket-link-regexp s
)
3878 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3882 (defun org-html-expand (string)
3883 "Prepare STRING for HTML export. Applies all active conversions.
3884 If there are links in the string, don't modify these."
3885 (let* ((re (concat org-bracket-link-regexp
"\\|"
3886 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3888 (while (setq m
(string-match re string
))
3889 (setq s
(substring string
0 m
)
3890 l
(match-string 0 string
)
3891 string
(substring string
(match-end 0)))
3892 (push (org-html-do-expand s
) res
)
3894 (push (org-html-do-expand string
) res
)
3895 (apply 'concat
(nreverse res
))))
3897 (defun org-html-do-expand (s)
3898 "Apply all active conversions to translate special ASCII to HTML."
3899 (setq s
(org-html-protect s
))
3900 (if org-export-html-expand
3902 (while (string-match "@<\\([^&]*\\)>" s
)
3903 (setq s
(replace-match "<\\1>" t nil s
)))))
3904 (if org-export-with-emphasize
3905 (setq s
(org-export-html-convert-emphasize s
)))
3906 (if org-export-with-special-strings
3907 (setq s
(org-export-html-convert-special-strings s
)))
3908 (if org-export-with-sub-superscripts
3909 (setq s
(org-export-html-convert-sub-super s
)))
3910 (if org-export-with-TeX-macros
3911 (let ((start 0) wd ass
)
3912 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
3914 (if (get-text-property (match-beginning 0) 'org-protected s
)
3915 (setq start
(match-end 0))
3916 (setq wd
(match-string 1 s
))
3917 (if (setq ass
(assoc wd org-html-entities
))
3918 (setq s
(replace-match (or (cdr ass
)
3919 (concat "&" (car ass
) ";"))
3921 (setq start
(+ start
(length wd
))))))))
3924 (defun org-create-multibrace-regexp (left right n
)
3925 "Create a regular expression which will match a balanced sexp.
3926 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3927 as single character strings.
3928 The regexp returned will match the entire expression including the
3929 delimiters. It will also define a single group which contains the
3930 match except for the outermost delimiters. The maximum depth of
3931 stacked delimiters is N. Escaping delimiters is not possible."
3932 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3935 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3938 re
(concat re or next
)
3939 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3940 (concat left
"\\(" re
"\\)" right
)))
3942 (defvar org-match-substring-regexp
3944 "\\([^\\]\\)\\([_^]\\)\\("
3945 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3947 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3949 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3950 "The regular expression matching a sub- or superscript.")
3952 (defvar org-match-substring-with-braces-regexp
3954 "\\([^\\]\\)\\([_^]\\)\\("
3955 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3957 "The regular expression matching a sub- or superscript, forcing braces.")
3959 (defconst org-export-html-special-string-regexps
3960 '(("\\\\-" .
"­")
3961 ("---\\([^-]\\)" .
"—\\1")
3962 ("--\\([^-]\\)" .
"–\\1")
3963 ("\\.\\.\\." .
"…"))
3964 "Regular expressions for special string conversion.")
3966 (defun org-export-html-convert-special-strings (string)
3967 "Convert special characters in STRING to HTML."
3968 (let ((all org-export-html-special-string-regexps
)
3970 (while (setq a
(pop all
))
3971 (setq re
(car a
) rpl
(cdr a
) start
0)
3972 (while (string-match re string start
)
3973 (if (get-text-property (match-beginning 0) 'org-protected string
)
3974 (setq start
(match-end 0))
3975 (setq string
(replace-match rpl t nil string
)))))
3978 (defun org-export-html-convert-sub-super (string)
3979 "Convert sub- and superscripts in STRING to HTML."
3980 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3981 (while (string-match org-match-substring-regexp string s
)
3983 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3984 ((get-text-property (match-beginning 2) 'org-protected string
)
3985 (setq s
(match-end 2)))
3987 (setq s
(match-end 1)
3988 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3989 c
(or (match-string 8 string
)
3990 (match-string 6 string
)
3991 (match-string 5 string
))
3992 string
(replace-match
3993 (concat (match-string 1 string
)
3994 "<" key
">" c
"</" key
">")
3996 (while (string-match "\\\\\\([_^]\\)" string
)
3997 (setq string
(replace-match (match-string 1 string
) t t string
)))
4000 (defun org-export-html-convert-emphasize (string)
4003 (while (string-match org-emph-re string s
)
4005 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4006 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4007 (setq s
(match-beginning 0)
4010 (match-string 1 string
)
4011 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4012 (match-string 4 string
)
4013 (nth 3 (assoc (match-string 3 string
)
4014 org-emphasis-alist
))
4015 (match-string 5 string
))
4016 string
(replace-match rpl t t string
)
4017 s
(+ s
(- (length rpl
) 2)))
4021 (defvar org-par-open nil
)
4022 (defun org-open-par ()
4023 "Insert <p>, but first close previous paragraph if any."
4024 (org-close-par-maybe)
4026 (setq org-par-open t
))
4027 (defun org-close-par-maybe ()
4028 "Close paragraph if there is one open."
4031 (setq org-par-open nil
)))
4032 (defun org-close-li (&optional type
)
4033 "Close <li> if necessary."
4034 (org-close-par-maybe)
4035 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4037 (defvar body-only
) ; dynamically scoped into this.
4038 (defun org-html-level-start (level title umax with-toc head-count
)
4039 "Insert a new level in HTML export.
4040 When TITLE is nil, just close all open levels."
4041 (org-close-par-maybe)
4042 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
4046 (if (aref org-levels-open
(1- l
))
4048 (org-html-level-close l umax
)
4049 (aset org-levels-open
(1- l
) nil
)))
4052 ;; If title is nil, this means this function is called to close
4053 ;; all levels, so the rest is done only if title is given
4054 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4055 (setq title
(replace-match
4056 (if org-export-with-tags
4059 " <span class=\"tag\">"
4060 (mapconcat 'identity
(org-split-string
4061 (match-string 1 title
) ":")
4068 (if (aref org-levels-open
(1- level
))
4072 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
4073 (insert "<li>" title
"<br/>\n")))
4074 (aset org-levels-open
(1- level
) t
)
4075 (org-close-par-maybe)
4077 (insert (format "<ul>\n<li id=\"%s\">" target
)
4079 (insert "<ul>\n<li>" title
"<br/>\n"))))
4080 (aset org-levels-open
(1- level
) t
)
4081 (setq snumber
(org-section-number level
))
4082 (if (and org-export-with-section-numbers
(not body-only
))
4083 (setq title
(concat snumber
" " title
)))
4084 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4085 (unless (= head-count
1) (insert "\n</div>\n"))
4086 (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"
4087 snumber level level snumber title level snumber
))
4090 (defun org-get-text-property-any (pos prop
&optional object
)
4091 (or (get-text-property pos prop object
)
4092 (and (setq pos
(next-single-property-change pos prop object
))
4093 (get-text-property pos prop object
))))
4095 (defun org-html-level-close (level max-outline-level
)
4096 "Terminate one level in HTML export."
4097 (if (<= level max-outline-level
)
4100 (insert "</ul>\n")))
4102 ;;; iCalendar export
4105 (defun org-export-icalendar-this-file ()
4106 "Export current file as an iCalendar file.
4107 The iCalendar file will be located in the same directory as the Org-mode
4108 file, but with extension `.ics'."
4110 (org-export-icalendar nil buffer-file-name
))
4113 (defun org-export-icalendar-all-agenda-files ()
4114 "Export all files in `org-agenda-files' to iCalendar .ics files.
4115 Each iCalendar file will be located in the same directory as the Org-mode
4116 file, but with extension `.ics'."
4118 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4121 (defun org-export-icalendar-combine-agenda-files ()
4122 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4123 The file is stored under the name `org-combined-agenda-icalendar-file'."
4125 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4127 (defun org-export-icalendar (combine &rest files
)
4128 "Create iCalendar files for all elements of FILES.
4129 If COMBINE is non-nil, combine all calendar entries into a single large
4130 file and store it under the name `org-combined-agenda-icalendar-file'."
4132 (org-prepare-agenda-buffers files
)
4133 (let* ((dir (org-export-directory
4134 :ical
(list :publishing-directory
4135 org-export-publishing-directory
)))
4136 file ical-file ical-buffer category started org-agenda-new-buffers
)
4137 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4140 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4141 org-combined-agenda-icalendar-file
4142 (expand-file-name org-combined-agenda-icalendar-file dir
))
4143 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4144 (set-buffer ical-buffer
) (erase-buffer))
4145 (while (setq file
(pop files
))
4147 (org-check-agenda-file file
)
4148 (set-buffer (org-get-agenda-file-buffer file
))
4150 (setq ical-file
(concat (file-name-as-directory dir
)
4151 (file-name-sans-extension
4152 (file-name-nondirectory buffer-file-name
))
4154 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4155 (with-current-buffer ical-buffer
(erase-buffer)))
4156 (setq category
(or org-category
4157 (file-name-sans-extension
4158 (file-name-nondirectory buffer-file-name
))))
4159 (if (symbolp category
) (setq category
(symbol-name category
)))
4160 (let ((standard-output ical-buffer
))
4162 (and (not started
) (setq started t
)
4163 (org-start-icalendar-file org-icalendar-combined-name
))
4164 (org-start-icalendar-file category
))
4165 (org-print-icalendar-entries combine
)
4166 (when (or (and combine
(not files
)) (not combine
))
4167 (org-finish-icalendar-file)
4168 (set-buffer ical-buffer
)
4169 (run-hooks 'org-before-save-iCalendar-file-hook
)
4171 (run-hooks 'org-after-save-iCalendar-file-hook
)
4172 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4174 (org-release-buffers org-agenda-new-buffers
))))
4176 (defvar org-before-save-iCalendar-file-hook nil
4177 "Hook run before an iCalendar file has been saved.
4178 This can be used to modify the result of the export.")
4180 (defvar org-after-save-iCalendar-file-hook nil
4181 "Hook run after an iCalendar file has been saved.
4182 The iCalendar buffer is still current when this hook is run.
4183 A good way to use this is to tell a desktop calenndar application to re-read
4184 the iCalendar file.")
4186 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4187 (defun org-print-icalendar-entries (&optional combine
)
4188 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4189 When COMBINE is non nil, add the category to each line."
4190 (require 'org-agenda
)
4191 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4192 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4193 (dts (org-ical-ts-to-string
4194 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4196 hd ts ts2 state status
(inc t
) pos b sexp rrule
4197 scheduledp deadlinep todo prefix due start
4198 tmp pri categories entry location summary desc uid
4199 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4200 (org-refresh-category-properties)
4202 (goto-char (point-min))
4203 (while (re-search-forward re1 nil t
)
4206 (when (boundp 'org-icalendar-verify-function
)
4207 (unless (funcall org-icalendar-verify-function
)
4208 (outline-next-heading)
4211 (setq pos
(match-beginning 0)
4214 hd
(condition-case nil
4215 (org-icalendar-cleanup-string
4217 (error (throw :skip nil
)))
4218 summary
(org-icalendar-cleanup-string
4219 (org-entry-get nil
"SUMMARY"))
4220 desc
(org-icalendar-cleanup-string
4221 (or (org-entry-get nil
"DESCRIPTION")
4222 (and org-icalendar-include-body
(org-get-entry)))
4223 t org-icalendar-include-body
)
4224 location
(org-icalendar-cleanup-string
4225 (org-entry-get nil
"LOCATION"))
4226 uid
(if org-icalendar-store-UID
4228 (or (org-id-get) (org-id-new)))
4229 categories
(org-export-get-categories)
4230 deadlinep nil scheduledp nil
)
4231 (if (looking-at re2
)
4233 (goto-char (match-end 0))
4234 (setq ts2
(match-string 1)
4235 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4236 (setq tmp
(buffer-substring (max (point-min)
4237 (- pos org-ds-keyword-length
))
4239 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4242 (replace-match "\\1" t nil ts
))
4244 deadlinep
(string-match org-deadline-regexp tmp
)
4245 scheduledp
(string-match org-scheduled-regexp tmp
)
4246 todo
(org-get-todo-state)
4247 ;; donep (org-entry-is-done-p)
4252 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4253 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4258 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4259 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4261 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4262 (if (or (string-match org-tr-regexp hd
)
4263 (string-match org-ts-regexp hd
))
4264 (setq hd
(replace-match "" t t hd
)))
4265 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4267 (concat "\nRRULE:FREQ="
4270 '(("d" .
"DAILY")("w" .
"WEEKLY")
4271 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4272 ";INTERVAL=" (match-string 1 ts
)))
4274 (setq summary
(or summary hd
))
4275 (if (string-match org-bracket-link-regexp summary
)
4277 (replace-match (if (match-end 3)
4278 (match-string 3 summary
)
4279 (match-string 1 summary
))
4281 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4282 (if scheduledp
(setq summary
(concat "S: " summary
)))
4283 (if (string-match "\\`<%%" ts
)
4284 (with-current-buffer sexp-buffer
4285 (insert (substring ts
1 -
1) " " summary
"\n"))
4286 (princ (format "BEGIN:VEVENT
4294 (org-ical-ts-to-string ts
"DTSTART")
4295 (org-ical-ts-to-string ts2
"DTEND" inc
)
4297 (if (and desc
(string-match "\\S-" desc
))
4298 (concat "\nDESCRIPTION: " desc
) "")
4299 (if (and location
(string-match "\\S-" location
))
4300 (concat "\nLOCATION: " location
) "")
4302 (when (and org-icalendar-include-sexps
4303 (condition-case nil
(require 'icalendar
) (error nil
))
4304 (fboundp 'icalendar-export-region
))
4305 ;; Get all the literal sexps
4306 (goto-char (point-min))
4307 (while (re-search-forward "^&?%%(" nil t
)
4310 (setq b
(match-beginning 0))
4311 (goto-char (1- (match-end 0)))
4314 (setq sexp
(buffer-substring b
(point)))
4315 (with-current-buffer sexp-buffer
4316 (insert sexp
"\n"))))
4317 (princ (org-diary-to-ical-string sexp-buffer
))
4318 (kill-buffer sexp-buffer
))
4320 (when org-icalendar-include-todo
4321 (setq prefix
"TODO-")
4322 (goto-char (point-min))
4323 (while (re-search-forward org-todo-line-regexp nil t
)
4326 (when (boundp 'org-icalendar-verify-function
)
4327 (unless (funcall org-icalendar-verify-function
)
4328 (outline-next-heading)
4331 (setq state
(match-string 2))
4332 (setq status
(if (member state org-done-keywords
)
4333 "COMPLETED" "NEEDS-ACTION"))
4335 (or (not (member state org-done-keywords
))
4336 (eq org-icalendar-include-todo
'all
))
4337 (not (member org-archive-tag
(org-get-tags-at)))
4339 (setq hd
(match-string 3)
4340 summary
(org-icalendar-cleanup-string
4341 (org-entry-get nil
"SUMMARY"))
4342 desc
(org-icalendar-cleanup-string
4343 (or (org-entry-get nil
"DESCRIPTION")
4344 (and org-icalendar-include-body
(org-get-entry)))
4345 t org-icalendar-include-body
)
4346 location
(org-icalendar-cleanup-string
4347 (org-entry-get nil
"LOCATION"))
4348 due
(and (member 'todo-due org-icalendar-use-deadline
)
4349 (org-entry-get nil
"DEADLINE"))
4350 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4351 (org-entry-get nil
"SCHEDULED"))
4352 categories
(org-export-get-categories)
4353 uid
(if org-icalendar-store-UID
4355 (or (org-id-get) (org-id-new))))
4356 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4357 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4359 (if (string-match org-bracket-link-regexp hd
)
4360 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4361 (match-string 1 hd
))
4363 (if (string-match org-priority-regexp hd
)
4364 (setq pri
(string-to-char (match-string 2 hd
))
4365 hd
(concat (substring hd
0 (match-beginning 1))
4366 (substring hd
(match-end 1))))
4367 (setq pri org-default-priority
))
4368 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
4369 (- org-lowest-priority org-highest-priority
))))))
4371 (princ (format "BEGIN:VTODO
4383 (if (and location
(string-match "\\S-" location
))
4384 (concat "\nLOCATION: " location
) "")
4385 (if (and desc
(string-match "\\S-" desc
))
4386 (concat "\nDESCRIPTION: " desc
) "")
4387 (if due
(concat "\n" due
) "")
4391 (defun org-export-get-categories ()
4392 "Get categories according to `org-icalendar-categories'."
4393 (let ((cs org-icalendar-categories
) c rtn tmp
)
4394 (while (setq c
(pop cs
))
4396 ((eq c
'category
) (push (org-get-category) rtn
))
4398 (setq tmp
(org-get-todo-state))
4399 (and tmp
(push tmp rtn
)))
4401 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4403 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4404 (mapconcat 'identity
(nreverse rtn
) ",")))
4406 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4407 "Take out stuff and quote what needs to be quoted.
4408 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4409 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4414 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4415 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4416 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4417 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4419 (while (string-match "\\([,;]\\)" s start
)
4420 (setq start
(+ (match-beginning 0) 2)
4421 s
(replace-match "\\\\\\1" nil nil s
))))
4423 (while (string-match "[ \t]*\n[ \t]*" s
)
4424 (setq s
(replace-match "\\n" t t s
))))
4425 (setq s
(org-trim s
))
4428 (if (and (numberp maxlength
)
4429 (> (length s
) maxlength
))
4430 (setq s
(substring s
0 maxlength
)))))
4433 (defun org-get-entry ()
4434 "Clean-up description string."
4436 (org-back-to-heading t
)
4437 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4439 (defun org-start-icalendar-file (name)
4440 "Start an iCalendar file by inserting the header."
4441 (let ((user user-full-name
)
4442 (name (or name
"unknown"))
4443 (timezone (cadr (current-time-zone))))
4445 (format "BEGIN:VCALENDAR
4448 PRODID:-//%s//Emacs with Org-mode//EN
4450 CALSCALE:GREGORIAN\n" name user timezone
))))
4452 (defun org-finish-icalendar-file ()
4453 "Finish an iCalendar file by inserting the END statement."
4454 (princ "END:VCALENDAR\n"))
4456 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4457 "Take a time string S and convert it to iCalendar format.
4458 KEYWORD is added in front, to make a complete line like DTSTART....
4459 When INC is non-nil, increase the hour by two (if time string contains
4460 a time), or the day by one (if it does not contain a time)."
4461 (let ((t1 (org-parse-time-string s
'nodefault
))
4462 t2 fmt have-time time
)
4463 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4464 (setq t2 t1 have-time t
)
4465 (setq t2
(org-parse-time-string s
)))
4466 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4467 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4470 (if org-agenda-default-appointment-duration
4471 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4474 (setq time
(encode-time s mi h d m y
)))
4475 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4476 (concat keyword
(format-time-string fmt time
))))
4480 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4481 (with-current-buffer buffer
4482 (apply 'insert output
)))
4483 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4486 (defun org-export-as-xoxo (&optional buffer
)
4487 "Export the org buffer as XOXO.
4488 The XOXO buffer is named *xoxo-<source buffer name>*"
4489 (interactive (list (current-buffer)))
4490 ;; A quickie abstraction
4492 ;; Output everything as XOXO
4493 (with-current-buffer (get-buffer buffer
)
4494 (let* ((pos (point))
4495 (opt-plist (org-combine-plists (org-default-export-plist)
4496 (org-infile-export-plist)))
4497 (filename (concat (file-name-as-directory
4498 (org-export-directory :xoxo opt-plist
))
4499 (file-name-sans-extension
4500 (file-name-nondirectory buffer-file-name
))
4502 (out (find-file-noselect filename
))
4505 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4506 ;; Check the output buffer is empty.
4507 (with-current-buffer out
(erase-buffer))
4508 ;; Kick off the output
4509 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4510 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4511 (let* ((hd (match-string-no-properties 1))
4514 (match-string-no-properties 2)
4516 (goto-char (match-end 0))
4521 (if (looking-at "^[ \t]\\(.*\\)")
4522 (setq str
(concat str
(match-string-no-properties 1)))
4523 (throw 'loop str
)))))))))
4525 ;; Handle level rendering
4527 ((> level last-level
)
4528 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4530 ((< level last-level
)
4531 (dotimes (- (- last-level level
) 1)
4533 (org-export-as-xoxo-insert-into out
"</li>\n"))
4534 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4536 (org-export-as-xoxo-insert-into out
"</li>\n")
4537 (setq hanging-li nil
)))
4539 ((equal level last-level
)
4541 (org-export-as-xoxo-insert-into out
"</li>\n")))
4544 (setq last-level level
)
4546 ;; And output the new li
4547 (setq hanging-li
't
)
4548 (if (equal ?
+ (elt text
0))
4549 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4550 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4552 ;; Finally finish off the ol
4553 (dotimes (- last-level
1)
4555 (org-export-as-xoxo-insert-into out
"</li>\n"))
4556 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4559 ;; Finish the buffer off and clean it up.
4560 (switch-to-buffer-other-window out
)
4561 (indent-region (point-min) (point-max) nil
)
4563 (goto-char (point-min))
4568 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4570 ;;; org-exp.el ends here