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
67 (defcustom org-export-with-special-strings t
68 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
69 When this option is turned on, these strings will be exported as:
72 -----+----------+--------
78 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
79 :group
'org-export-translation
82 (defcustom org-export-language-setup
83 '(("en" "Author" "Date" "Table of Contents")
84 ("cs" "Autor" "Datum" "Obsah")
85 ("da" "Ophavsmand" "Dato" "Indhold")
86 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
87 ("es" "Autor" "Fecha" "\xcdndice")
88 ("fr" "Auteur" "Date" "Table des mati\xe8res")
89 ("it" "Autore" "Data" "Indice")
90 ("nl" "Auteur" "Datum" "Inhoudsopgave")
91 ("no" "Forfatter" "Dato" "Innhold")
92 ("nb" "Forfatter" "Dato" "Innhold") ;; nb = Norsk (bokm.l)
93 ("nn" "Forfattar" "Dato" "Innhald") ;; nn = Norsk (nynorsk)
94 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
95 "Terms used in export text, translated to different languages.
96 Use the variable `org-export-default-language' to set the language,
97 or use the +OPTION lines for a per-file setting."
98 :group
'org-export-general
101 (string :tag
"HTML language tag")
102 (string :tag
"Author")
104 (string :tag
"Table of Contents"))))
106 (defcustom org-export-default-language
"en"
107 "The default language of HTML export, as a string.
108 This should have an association in `org-export-language-setup'."
109 :group
'org-export-general
112 (defcustom org-export-skip-text-before-1st-heading nil
113 "Non-nil means, skip all text before the first headline when exporting.
114 When nil, that text is exported as well."
115 :group
'org-export-general
118 (defcustom org-export-headline-levels
3
119 "The last level which is still exported as a headline.
120 Inferior levels will produce itemize lists when exported.
121 Note that a numeric prefix argument to an exporter function overrides
124 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
125 :group
'org-export-general
128 (defcustom org-export-with-section-numbers t
129 "Non-nil means, add section numbers to headlines when exporting.
131 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
132 :group
'org-export-general
135 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
136 "Format of section numbers for export.
137 The variable has two components.
138 1. A list of lists, each indicating a counter type and a separator.
139 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
140 It causes causes numeric, alphabetic, or roman counters, respectively.
141 The separator is only used if another counter for a subsection is being
143 If there are more numbered section levels than entries in this lists,
144 then the last entry will be reused.
145 2. A terminator string that will be added after the entire
147 :group
'org-export-general
151 (string :tag
"Counter Type")
152 (string :tag
"Separator ")))
153 (string :tag
"Terminator")))
155 (defcustom org-export-with-toc t
156 "Non-nil means, create a table of contents in exported files.
157 The TOC contains headlines with levels up to`org-export-headline-levels'.
158 When an integer, include levels up to N in the toc, this may then be
159 different from `org-export-headline-levels', but it will not be allowed
160 to be larger than the number of headline levels.
161 When nil, no table of contents is made.
163 Headlines which contain any TODO items will be marked with \"(*)\" in
164 ASCII export, and with red color in HTML output, if the option
165 `org-export-mark-todo-in-toc' is set.
167 In HTML output, the TOC will be clickable.
169 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
171 :group
'org-export-general
173 (const :tag
"No Table of Contents" nil
)
174 (const :tag
"Full Table of Contents" t
)
175 (integer :tag
"TOC to level")))
177 (defcustom org-export-mark-todo-in-toc nil
178 "Non-nil means, mark TOC lines that contain any open TODO items."
179 :group
'org-export-general
182 (defcustom org-export-preserve-breaks nil
183 "Non-nil means, preserve all line breaks when exporting.
184 Normally, in HTML output paragraphs will be reformatted. In ASCII
185 export, line breaks will always be preserved, regardless of this variable.
187 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
188 :group
'org-export-general
191 (defcustom org-export-with-archived-trees
'headline
192 "Whether subtrees with the ARCHIVE tag should be exported.
193 This can have three different values
194 nil Do not export, pretend this tree is not present
195 t Do export the entire tree
196 headline Only export the headline, but skip the tree below it."
197 :group
'org-export-general
200 (const :tag
"not at all" nil
)
201 (const :tag
"headline only" 'headline
)
202 (const :tag
"entirely" t
)))
204 (defcustom org-export-author-info t
205 "Non-nil means, insert author name and email into the exported file.
207 This option can also be set with the +OPTIONS line,
208 e.g. \"author-info:nil\"."
209 :group
'org-export-general
212 (defcustom org-export-creator-info t
213 "Non-nil means, the postamle should contain a creator sentence.
214 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
215 :group
'org-export-general
218 (defcustom org-export-time-stamp-file t
219 "Non-nil means, insert a time stamp into the exported file.
220 The time stamp shows when the file was created.
222 This option can also be set with the +OPTIONS line,
223 e.g. \"timestamp:nil\"."
224 :group
'org-export-general
227 (defcustom org-export-with-timestamps t
228 "If nil, do not export time stamps and associated keywords."
229 :group
'org-export-general
232 (defcustom org-export-remove-timestamps-from-toc t
233 "If nil, remove timestamps from the table of contents entries."
234 :group
'org-export-general
237 (defcustom org-export-with-tags
'not-in-toc
238 "If nil, do not export tags, just remove them from headlines.
239 If this is the symbol `not-in-toc', tags will be removed from table of
240 contents entries, but still be shown in the headlines of the document.
242 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
243 :group
'org-export-general
245 (const :tag
"Off" nil
)
246 (const :tag
"Not in TOC" not-in-toc
)
247 (const :tag
"On" t
)))
249 (defcustom org-export-with-drawers nil
250 "Non-nil means, export with drawers like the property drawer.
251 When t, all drawers are exported. This may also be a list of
252 drawer names to export."
253 :group
'org-export-general
255 (const :tag
"All drawers" t
)
256 (const :tag
"None" nil
)
257 (repeat :tag
"Selected drawers"
258 (string :tag
"Drawer name"))))
260 (defvar org-export-preprocess-hook nil
261 "Hook for preprocessing an export buffer.
262 Pretty much the first thing when exporting is running this hook.")
264 (defgroup org-export-translation nil
265 "Options for translating special ascii sequences for the export backends."
266 :tag
"Org Export Translation"
269 (defcustom org-export-with-emphasize t
270 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
271 If the export target supports emphasizing text, the word will be
272 typeset in bold, italic, or underlined, respectively. Works only for
273 single words, but you can say: I *really* *mean* *this*.
274 Not all export backends support this.
276 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
277 :group
'org-export-translation
280 (defcustom org-export-with-footnotes t
281 "If nil, export [1] as a footnote marker.
282 Lines starting with [1] will be formatted as footnotes.
284 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
285 :group
'org-export-translation
288 (defcustom org-export-with-sub-superscripts t
289 "Non-nil means, interpret \"_\" and \"^\" for export.
290 When this option is turned on, you can use TeX-like syntax for sub- and
291 superscripts. Several characters after \"_\" or \"^\" will be
292 considered as a single item - so grouping with {} is normally not
293 needed. For example, the following things will be parsed as single
294 sub- or superscripts.
296 10^24 or 10^tau several digits will be considered 1 item.
297 10^-12 or 10^-tau a leading sign with digits or a word
298 x^2-y^3 will be read as x^2 - y^3, because items are
299 terminated by almost any nonword/nondigit char.
300 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
302 Still, ambiguity is possible - so when in doubt use {} to enclose the
303 sub/superscript. If you set this variable to the symbol `{}',
304 the braces are *required* in order to trigger interpretations as
305 sub/superscript. This can be helpful in documents that need \"_\"
306 frequently in plain text.
308 Not all export backends support this, but HTML does.
310 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
311 :group
'org-export-translation
313 (const :tag
"Always interpret" t
)
314 (const :tag
"Only with braces" {})
315 (const :tag
"Never interpret" nil
)))
317 (defcustom org-export-with-special-strings t
318 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
319 When this option is turned on, these strings will be exported as:
325 Not all export backends support this, but HTML does.
327 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
328 :group
'org-export-translation
331 (defcustom org-export-with-TeX-macros t
332 "Non-nil means, interpret simple TeX-like macros when exporting.
333 For example, HTML export converts \\alpha to α and \\AA to Å.
334 No only real TeX macros will work here, but the standard HTML entities
335 for math can be used as macro names as well. For a list of supported
336 names in HTML export, see the constant `org-html-entities'.
337 Not all export backends support this.
339 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
340 :group
'org-export-translation
341 :group
'org-export-latex
344 (defcustom org-export-with-LaTeX-fragments nil
345 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
346 When set, the exporter will find LaTeX environments if the \\begin line is
347 the first non-white thing on a line. It will also find the math delimiters
348 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
351 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
352 :group
'org-export-translation
353 :group
'org-export-latex
356 (defcustom org-export-with-fixed-width t
357 "Non-nil means, lines starting with \":\" will be in fixed width font.
358 This can be used to have pre-formatted text, fragments of code etc. For
360 : ;; Some Lisp examples
363 will be looking just like this in also HTML. See also the QUOTE keyword.
364 Not all export backends support this.
366 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
367 :group
'org-export-translation
370 (defcustom org-match-sexp-depth
3
371 "Number of stacked braces for sub/superscript matching.
372 This has to be set before loading org.el to be effective."
373 :group
'org-export-translation
376 (defgroup org-export-tables nil
377 "Options for exporting tables in Org-mode."
378 :tag
"Org Export Tables"
381 (defcustom org-export-with-tables t
382 "If non-nil, lines starting with \"|\" define a table.
385 | Name | Address | Birthday |
386 |-------------+----------+-----------|
387 | Arthur Dent | England | 29.2.2100 |
389 Not all export backends support this.
391 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
392 :group
'org-export-tables
395 (defcustom org-export-highlight-first-table-line t
396 "Non-nil means, highlight the first table line.
397 In HTML export, this means use <th> instead of <td>.
398 In tables created with table.el, this applies to the first table line.
399 In Org-mode tables, all lines before the first horizontal separator
400 line will be formatted with <th> tags."
401 :group
'org-export-tables
404 (defcustom org-export-table-remove-special-lines t
405 "Remove special lines and marking characters in calculating tables.
406 This removes the special marking character column from tables that are set
407 up for spreadsheet calculations. It also removes the entire lines
408 marked with `!', `_', or `^'. The lines with `$' are kept, because
409 the values of constants may be useful to have."
410 :group
'org-export-tables
413 (defcustom org-export-prefer-native-exporter-for-tables nil
414 "Non-nil means, always export tables created with table.el natively.
415 Natively means, use the HTML code generator in table.el.
416 When nil, Org-mode's own HTML generator is used when possible (i.e. if
417 the table does not use row- or column-spanning). This has the
418 advantage, that the automatic HTML conversions for math symbols and
419 sub/superscripts can be applied. Org-mode's HTML generator is also
421 :group
'org-export-tables
424 (defgroup org-export-ascii nil
425 "Options specific for ASCII export of Org-mode files."
426 :tag
"Org Export ASCII"
429 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
430 "Characters for underlining headings in ASCII export.
431 In the given sequence, these characters will be used for level 1, 2, ..."
432 :group
'org-export-ascii
433 :type
'(repeat character
))
435 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
436 "Bullet characters for headlines converted to lists in ASCII export.
437 The first character is used for the first lest level generated in this
438 way, and so on. If there are more levels than characters given here,
439 the list will be repeated.
440 Note that plain lists will keep the same bullets as the have in the
442 :group
'org-export-ascii
443 :type
'(repeat character
))
445 (defgroup org-export-xml nil
446 "Options specific for XML export of Org-mode files."
447 :tag
"Org Export XML"
450 (defgroup org-export-html nil
451 "Options specific for HTML export of Org-mode files."
452 :tag
"Org Export HTML"
455 (defcustom org-export-html-coding-system nil
456 "Coding system for HTML export, defaults to buffer-file-coding-system."
457 :group
'org-export-html
458 :type
'coding-system
)
460 (defcustom org-export-html-extension
"html"
461 "The extension for exported HTML files."
462 :group
'org-export-html
465 (defcustom org-export-html-link-up
""
466 "Where should the \"UP\" link of exported HTML pages lead?"
467 :group
'org-export-html
468 :type
'(string :tag
"File or URL"))
470 (defcustom org-export-html-link-home
""
471 "Where should the \"HOME\" link of exported HTML pages lead?"
472 :group
'org-export-html
473 :type
'(string :tag
"File or URL"))
475 (defconst org-export-html-style-default
476 "<style type=\"text/css\">
477 html { font-family: Times, serif; font-size: 12pt; }
478 .title { text-align: center; }
479 .todo { color: red; }
480 .done { color: green; }
481 .tag { background-color:lightblue; font-weight:normal }
483 .timestamp { color: grey }
484 .timestamp-kwd { color: CadetBlue }
485 p.verse { margin-left: 3% }
487 border: 1pt solid #AEBDCC;
488 background-color: #F3F5F7;
490 font-family: courier, monospace;
494 table { border-collapse: collapse; }
495 td, th { vertical-align: top; }
496 dt { font-weight: bold; }
498 .org-info-js_info-navigation { border-style:none; }
499 #org-info-js_console-label { font-size:10px; font-weight:bold;
500 white-space:nowrap; }
501 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
505 "The default style specification for exported HTML files.
506 Please use the variables `org-export-html-style' and
507 `org-export-html-style-extra' to add to this style.")
509 (defcustom org-export-html-style
""
510 "Org-wide style definitions for exported HTML files.
512 This variable needs to contain the full HTML structure to provide a style,
513 including the surrounding HTML tags. If you set the value of this variable,
514 you should consider to include definitions for the following classes:
515 title, todo, done, timestamp, timestamp-kwd, tag, target.
517 For example, a valid value would be:
519 <style type=\"text/css\">
520 p { font-weight: normal; color: gray; }
522 .title { text-align: center; }
523 .todo, .timestamp-kwd { color: red; }
524 .done { color: green; }
527 If you'd like to refer to en external style file, use something like
529 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
531 As the value of this option simply gets inserted into the HTML <head> header,
532 you can \"misuse\" it to add arbitrary text to the header.
533 See also the variable `org-export-html-style-extra'."
534 :group
'org-export-html
537 (put 'org-export-html-style
'safe-local-variable
'stringp
)
539 (defcustom org-export-html-style-extra
""
540 "Additional style information for HTML export.
541 The value of this variable is inserted into the HTML buffer right after
542 the value of `org-export-html-style'. Use this variable for per-file
543 settings of style information, and do not forget to surround the style
544 settings with <style>...</style> tags."
545 :group
'org-export-html
548 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
551 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
552 "Format for typesetting the document title in HTML export."
553 :group
'org-export-html
556 (defcustom org-export-html-toplevel-hlevel
2
557 "The <H> level for level 1 headings in HTML export."
558 :group
'org-export-html
561 (defcustom org-export-html-link-org-files-as-html t
562 "Non-nil means, make file links to `file.org' point to `file.html'.
563 When org-mode is exporting an org-mode file to HTML, links to
564 non-html files are directly put into a href tag in HTML.
565 However, links to other Org-mode files (recognized by the
566 extension `.org.) should become links to the corresponding html
567 file, assuming that the linked org-mode file will also be
569 When nil, the links still point to the plain `.org' file."
570 :group
'org-export-html
573 (defcustom org-export-html-inline-images
'maybe
574 "Non-nil means, inline images into exported HTML pages.
575 This is done using an <img> tag. When nil, an anchor with href is used to
576 link to the image. If this option is `maybe', then images in links with
577 an empty description will be inlined, while images with a description will
579 :group
'org-export-html
580 :type
'(choice (const :tag
"Never" nil
)
581 (const :tag
"Always" t
)
582 (const :tag
"When there is no description" maybe
)))
585 (defcustom org-export-html-expand t
586 "Non-nil means, for HTML export, treat @<...> as HTML tag.
587 When nil, these tags will be exported as plain text and therefore
588 not be interpreted by a browser.
590 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
591 :group
'org-export-html
594 (defcustom org-export-html-table-tag
595 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
596 "The HTML tag that is used to start a table.
597 This must be a <table> tag, but you may change the options like
598 borders and spacing."
599 :group
'org-export-html
602 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
603 "The opening tag for table header fields.
604 This is customizable so that alignment options can be specified."
605 :group
'org-export-tables
606 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
608 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
609 "The opening tag for table data fields.
610 This is customizable so that alignment options can be specified."
611 :group
'org-export-tables
612 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
614 (defcustom org-export-html-with-timestamp nil
615 "If non-nil, write `org-export-html-html-helper-timestamp'
616 into the exported HTML text. Otherwise, the buffer will just be saved
618 :group
'org-export-html
621 (defcustom org-export-html-html-helper-timestamp
622 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
623 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
624 :group
'org-export-html
627 (defgroup org-export-htmlize nil
628 "Options for processing examples with htmlize.el."
629 :tag
"Org Export Htmlize"
630 :group
'org-export-html
)
632 (defcustom org-export-htmlize-output-type
'inline-css
633 "Output type to be used by htmlize when formatting code snippets.
634 Normally this is `inline-css', but if you have defined to appropriate
635 classes in your css style file, setting this to `css' means that the
636 fontification will use the class names.
637 See also the function `org-export-htmlize-generate-css'."
638 :group
'org-export-htmlize
639 :type
'(choice (const css
) (const inline-css
)))
641 (defcustom org-export-htmlize-css-font-prefix
"org-"
642 "The prefix for CSS class names for htmlize font specifications."
643 :group
'org-export-htmlize
646 (defgroup org-export-icalendar nil
647 "Options specific for iCalendar export of Org-mode files."
648 :tag
"Org Export iCalendar"
651 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
652 "The file name for the iCalendar file covering all agenda files.
653 This file is created with the command \\[org-export-icalendar-all-agenda-files].
654 The file name should be absolute, the file will be overwritten without warning."
655 :group
'org-export-icalendar
658 (defcustom org-icalendar-combined-name
"OrgMode"
659 "Calendar name for the combined iCalendar representing all agenda files."
660 :group
'org-export-icalendar
663 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
664 "Contexts where iCalendar export should use a deadline time stamp.
665 This is a list with several symbols in it. Valid symbol are:
667 event-if-todo Deadlines in TODO entries become calendar events.
668 event-if-not-todo Deadlines in non-TODO entries become calendar events.
669 todo-due Use deadlines in TODO entries as due-dates"
670 :group
'org-export-icalendar
671 :type
'(set :greedy t
672 (const :tag
"Deadlines in non-TODO entries become events"
674 (const :tag
"Deadline in TODO entries become events"
676 (const :tag
"Deadlines in TODO entries become due-dates"
679 (defcustom org-icalendar-use-scheduled
'(todo-start)
680 "Contexts where iCalendar export should use a scheduling time stamp.
681 This is a list with several symbols in it. Valid symbol are:
683 event-if-todo Scheduling time stamps in TODO entries become an event.
684 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
685 todo-start Scheduling time stamps in TODO entries become start date.
686 Some calendar applications show TODO entries only after
688 :group
'org-export-icalendar
689 :type
'(set :greedy t
691 "SCHEDULED timestamps in non-TODO entries become events"
693 (const :tag
"SCHEDULED timestamps in TODO entries become events"
695 (const :tag
"SCHEDULED in TODO entries become start date"
698 (defcustom org-icalendar-include-todo nil
699 "Non-nil means, export to iCalendar files should also cover TODO items."
700 :group
'org-export-icalendar
702 (const :tag
"None" nil
)
703 (const :tag
"Unfinished" t
)
704 (const :tag
"All" all
)))
706 (defcustom org-icalendar-include-sexps t
707 "Non-nil means, export to iCalendar files should also cover sexp entries.
708 These are entries like in the diary, but directly in an Org-mode file."
709 :group
'org-export-icalendar
712 (defcustom org-icalendar-include-body
100
713 "Amount of text below headline to be included in iCalendar export.
714 This is a number of characters that should maximally be included.
715 Properties, scheduling and clocking lines will always be removed.
716 The text will be inserted into the DESCRIPTION field."
717 :group
'org-export-icalendar
719 (const :tag
"Nothing" nil
)
720 (const :tag
"Everything" t
)
721 (integer :tag
"Max characters")))
723 (defcustom org-icalendar-store-UID nil
724 "Non-nil means, store any created UIDs in properties.
725 The iCalendar standard requires that all entries have a unique identifyer.
726 Org will create these identifiers as needed. When this variable is non-nil,
727 the created UIDs will be stored in the ID property of the entry. Then the
728 next time this entry is exported, it will be exported with the same UID,
729 superceeding the previous form of it. This is essential for
730 synchronization services.
731 This variable is not turned on by default because we want to avoid creating
732 a property drawer in every entry if people are only playing with this feature,
733 or if they are only using it locally."
734 :group
'org-export-icalendar
739 ;;; Variables, constants, and parameter plists
741 (defconst org-level-max
20)
743 (defvar org-export-html-preamble nil
744 "Preamble, to be inserted just after <body>. Set by publishing functions.")
745 (defvar org-export-html-postamble nil
746 "Preamble, to be inserted just before </body>. Set by publishing functions.")
747 (defvar org-export-html-auto-preamble t
748 "Should default preamble be inserted? Set by publishing functions.")
749 (defvar org-export-html-auto-postamble t
750 "Should default postamble be inserted? Set by publishing functions.")
751 (defvar org-current-export-file nil
) ; dynamically scoped parameter
752 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
754 (defconst org-export-plist-vars
755 '((:link-up . org-export-html-link-up
)
756 (:link-home . org-export-html-link-home
)
757 (:language . org-export-default-language
)
758 (:customtime . org-display-custom-times
)
759 (:headline-levels . org-export-headline-levels
)
760 (:section-numbers . org-export-with-section-numbers
)
761 (:section-number-format . org-export-section-number-format
)
762 (:table-of-contents . org-export-with-toc
)
763 (:preserve-breaks . org-export-preserve-breaks
)
764 (:archived-trees . org-export-with-archived-trees
)
765 (:emphasize . org-export-with-emphasize
)
766 (:sub-superscript . org-export-with-sub-superscripts
)
767 (:special-strings . org-export-with-special-strings
)
768 (:footnotes . org-export-with-footnotes
)
769 (:drawers . org-export-with-drawers
)
770 (:tags . org-export-with-tags
)
771 (:TeX-macros . org-export-with-TeX-macros
)
772 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
773 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
774 (:fixed-width . org-export-with-fixed-width
)
775 (:timestamps . org-export-with-timestamps
)
776 (:author-info . org-export-author-info
)
777 (:creator-info . org-export-creator-info
)
778 (:time-stamp-file . org-export-time-stamp-file
)
779 (:tables . org-export-with-tables
)
780 (:table-auto-headline . org-export-highlight-first-table-line
)
781 (:style . org-export-html-style
)
782 (:style-extra . org-export-html-style-extra
)
783 (:agenda-style . org-agenda-export-html-style
)
784 (:convert-org-links . org-export-html-link-org-files-as-html
)
785 (:inline-images . org-export-html-inline-images
)
786 (:html-extension . org-export-html-extension
)
787 (:html-table-tag . org-export-html-table-tag
)
788 (:expand-quoted-html . org-export-html-expand
)
789 (:timestamp . org-export-html-with-timestamp
)
790 (:publishing-directory . org-export-publishing-directory
)
791 (:preamble . org-export-html-preamble
)
792 (:postamble . org-export-html-postamble
)
793 (:auto-preamble . org-export-html-auto-preamble
)
794 (:auto-postamble . org-export-html-auto-postamble
)
795 (:author . user-full-name
)
796 (:email . user-mail-address
)))
798 (defun org-default-export-plist ()
799 "Return the property list with default settings for the export variables."
800 (let ((l org-export-plist-vars
) rtn e
)
801 (while (setq e
(pop l
))
802 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
805 (defvar org-export-inbuffer-options-extra nil
806 "List of additional in-buffer options that should be detected.
807 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
808 etc. Extensions can add to this list to get their options detected, and they
809 can then add a function to `org-export-options-filters' to process these
811 Each element in this list must be a list, with the in-buffer keyword as car,
812 and a property (a symbol) as the next element. All occurences of the
813 keyword will be found, the values concatenated with a space character
814 in between, and the result stored in the export options property list.")
816 (defvar org-export-options-filters nil
817 "Functions to be called to finalize the export/publishing options.
818 All these options are stored in a property list, and each of the functions
819 in this hook gets a chance to modify this property list. Each function
820 must accept the property list as an argument, and must return the (possibly
823 (defun org-infile-export-plist ()
824 "Return the property list with file-local settings for export."
828 (goto-char (point-min))
829 (let ((re (org-make-options-regexp
831 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
832 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE")
833 (mapcar 'car org-export-inbuffer-options-extra
))))
834 p key val text options js-up js-main js-css js-opt a pr
835 ext-setup-or-nil setup-contents
(start 0))
836 (while (or (and ext-setup-or-nil
837 (string-match re ext-setup-or-nil start
)
838 (setq start
(match-end 0)))
839 (and (setq ext-setup-or-nil nil start
0)
840 (re-search-forward re nil t
)))
841 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
842 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
844 ((setq a
(assoc key org-export-inbuffer-options-extra
))
846 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
847 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
848 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
849 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
850 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
851 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
852 ((string-equal key
"STYLE") (setq p
(plist-put p
:style-extra val
)))
853 ((string-equal key
"TEXT")
854 (setq text
(if text
(concat text
"\n" val
) val
)))
855 ((string-equal key
"OPTIONS")
856 (setq options
(concat val
" " options
)))
857 ((string-equal key
"LINK_UP")
858 (setq p
(plist-put p
:link-up val
)))
859 ((string-equal key
"LINK_HOME")
860 (setq p
(plist-put p
:link-home val
)))
861 ((equal key
"SETUPFILE")
862 (setq setup-contents
(org-file-contents
864 (org-remove-double-quotes
867 (if (not ext-setup-or-nil
)
868 (setq ext-setup-or-nil setup-contents start
0)
869 (setq ext-setup-or-nil
870 (concat (substring ext-setup-or-nil
0 start
)
871 "\n" setup-contents
"\n"
872 (substring ext-setup-or-nil start
)))))))
873 (setq p
(plist-put p
:text text
))
875 (setq p
(org-export-add-options-to-plist p options
)))
878 (defun org-export-add-options-to-plist (p options
)
879 "Parse an OPTONS line and set values in the property list P."
882 (let ((op '(("H" .
:headline-levels
)
883 ("num" .
:section-numbers
)
884 ("toc" .
:table-of-contents
)
885 ("\\n" .
:preserve-breaks
)
886 ("@" .
:expand-quoted-html
)
889 ("^" .
:sub-superscript
)
890 ("-" .
:special-strings
)
895 ("TeX" .
:TeX-macros
)
896 ("LaTeX" .
:LaTeX-fragments
)
897 ("skip" .
:skip-before-1st-heading
)
898 ("author" .
:author-info
)
899 ("creator" .
:creator-info
)
900 ("timestamp" .
:time-stamp-file
)))
902 (while (setq o
(pop op
))
903 (if (string-match (concat (regexp-quote (car o
))
904 ":\\([^ \t\n\r;,.]*\\)")
906 (setq p
(plist-put p
(cdr o
)
907 (car (read-from-string
908 (match-string 1 options
))))))))))
911 (defun org-export-add-subtree-options (p pos
)
912 "Add options in subtree at position POS to property list P."
915 (when (org-at-heading-p)
917 ;; This is actually read in `org-export-get-title-from-subtree'
918 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
919 ;; (setq p (plist-put p :title a)))
920 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
921 (setq p
(plist-put p
:text a
)))
922 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
923 (setq p
(org-export-add-options-to-plist p a
)))))
926 (defun org-export-directory (type plist
)
927 (let* ((val (plist-get plist
:publishing-directory
))
929 (or (cdr (assoc type val
)) ".")
933 (defun org-export-process-option-filters (plist)
934 (let ((functions org-export-options-filters
) f
)
935 (while (setq f
(pop functions
))
936 (setq plist
(funcall f plist
))))
940 (defun org-export (&optional arg
)
941 "Export dispatcher for Org-mode.
942 When `org-export-run-in-background' is non-nil, try to run the command
943 in the background. This will be done only for commands that write
944 to a file. For details see the docstring of `org-export-run-in-background'.
946 The prefix argument ARG will be passed to the exporter. However, if
947 ARG is a double universal prefix `C-u C-u', that means to inverse the
948 value of `org-export-run-in-background'."
950 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
951 (help "[t] insert the export option template
952 \[v] limit export to visible part of outline tree
957 \[H] export as HTML to temporary buffer
958 \[R] export region as HTML
959 \[b] export as HTML and browse immediately
963 \[L] export as LaTeX to temporary buffer
965 \[i] export current file as iCalendar file
966 \[I] export all agenda files as iCalendar files
967 \[c] export agenda files into combined iCalendar file
969 \[F] publish current file
970 \[P] publish current project
971 \[X] publish... (project will be prompted for)
972 \[A] publish all projects")
974 '((?t org-insert-export-options-template nil
)
975 (?v org-export-visible nil
)
976 (?a org-export-as-ascii t
)
977 (?h org-export-as-html t
)
978 (?b org-export-as-html-and-open t
)
979 (?H org-export-as-html-to-buffer nil
)
980 (?R org-export-region-as-html nil
)
981 (?x org-export-as-xoxo t
)
982 (?l org-export-as-latex t
)
983 (?L org-export-as-latex-to-buffer nil
)
984 (?i org-export-icalendar-this-file t
)
985 (?I org-export-icalendar-all-agenda-files t
)
986 (?c org-export-icalendar-combine-agenda-files t
)
987 (?F org-publish-current-file t
)
988 (?P org-publish-current-project t
)
990 (?A org-publish-all t
)))
992 (save-window-excursion
993 (delete-other-windows)
994 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
996 (message "Select command: ")
997 (setq r1
(read-char-exclusive)))
998 (setq r2
(if (< r1
27) (+ r1
96) r1
))
999 (unless (setq ass
(assq r2 cmds
))
1000 (error "No command associated with key %c" r1
))
1001 (if (and bg
(nth 2 ass
))
1002 ;; execute in background
1003 (let ((p (start-process
1004 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1006 (expand-file-name invocation-name invocation-directory
)
1009 "--eval" "(require 'org-exp)"
1010 "--eval" "(setq org-wait .2)"
1012 "-f" (symbol-name (nth 1 ass
)))))
1013 (set-process-sentinel p
'org-export-process-sentinel
)
1014 (message "Background process \"%s\": started" p
))
1015 ;; background processing not requested, or not possible
1016 (call-interactively (nth 1 ass
)))))
1018 (defun org-export-process-sentinel (process status
)
1019 (if (string-match "\n+\\'" status
)
1020 (setq status
(substring status
0 -
1)))
1021 (message "Background process \"%s\": %s" process status
))
1023 (defconst org-html-entities
1064 ("Aring") ("AA".
"Å")
1153 ("varepsilon".
"ε")
1166 ("sigmaf") ("varsigma".
"ς")
1174 ("thetasym") ("vartheta".
"ϑ")
1177 ("bull") ("bullet".
"•")
1178 ("hellip") ("dots".
"…")
1188 ("larr") ("leftarrow".
"←") ("gets".
"←")
1189 ("uarr") ("uparrow".
"↑")
1190 ("rarr") ("to".
"→") ("rightarrow".
"→")
1191 ("darr")("downarrow".
"↓")
1192 ("harr") ("leftrightarrow".
"↔")
1193 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1194 ("lArr") ("Leftarrow".
"⇐")
1195 ("uArr") ("Uparrow".
"⇑")
1196 ("rArr") ("Rightarrow".
"⇒")
1197 ("dArr") ("Downarrow".
"⇓")
1198 ("hArr") ("Leftrightarrow".
"⇔")
1200 ("part") ("partial".
"∂")
1201 ("exist") ("exists".
"∃")
1202 ("empty") ("emptyset".
"∅")
1204 ("isin") ("in".
"∈")
1210 ("lowast") ("ast".
"∗")
1212 ("prop") ("proptp".
"∝")
1213 ("infin") ("infty".
"∞")
1214 ("ang") ("angle".
"∠")
1215 ("and") ("wedge".
"∧")
1216 ("or") ("vee".
"∨")
1222 ("cong") ("simeq".
"≅")
1223 ("asymp")("approx".
"≈")
1224 ("ne") ("neq".
"≠")
1228 ("sub") ("subset".
"⊂")
1229 ("sup") ("supset".
"⊃")
1236 ("sdot") ("cdot".
"⋅")
1243 ("loz") ("Diamond".
"◊")
1244 ("spades") ("spadesuit".
"♠")
1245 ("clubs") ("clubsuit".
"♣")
1246 ("hearts") ("diamondsuit".
"♥")
1247 ("diams") ("diamondsuit".
"♦")
1248 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1315 "Entities for TeX->HTML translation.
1316 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1317 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1318 In that case, \"\\ent\" will be translated to \"&other;\".
1319 The list contains HTML entities for Latin-1, Greek and other symbols.
1320 It is supplemented by a number of commonly used TeX macros with appropriate
1321 translations. There is currently no way for users to extend this.")
1323 ;;; General functions for all backends
1325 (defun org-export-preprocess-string (string &rest parameters
)
1326 "Cleanup STRING so that that the true exported has a more consistent source.
1327 This function takes STRING, which should be a buffer-string of an org-file
1328 to export. It then creates a temporary buffer where it does its job.
1329 The result is then again returned as a string, and the exporter works
1330 on this string to produce the exported version."
1332 (let* ((htmlp (plist-get parameters
:for-html
))
1333 (asciip (plist-get parameters
:for-ascii
))
1334 (latexp (plist-get parameters
:for-LaTeX
))
1335 (archived-trees (plist-get parameters
:archived-trees
))
1336 (inhibit-read-only t
)
1337 (drawers org-drawers
)
1338 (outline-regexp "\\*+ ")
1341 (with-current-buffer (get-buffer-create " org-mode-tmp")
1344 (setq case-fold-search t
)
1346 (run-hooks 'org-export-preprocess-hook
)
1348 ;; Remove license-to-kill stuff
1349 ;; The caller markes some stuff fo killing, stuff that has been
1350 ;; used to create the page title, for example.
1351 (org-export-kill-licensed-text)
1353 (let ((org-inhibit-startup t
)) (org-mode))
1354 (setq case-fold-search t
)
1355 (untabify (point-min) (point-max))
1357 ;; Handle include files
1358 (org-export-handle-include-files)
1360 ;; Handle source code snippets
1361 (org-export-replace-src-segments)
1363 ;; Get rid of drawers
1364 (org-export-remove-or-extract-drawers drawers
1365 (plist-get parameters
:drawers
))
1367 ;; Get the correct stuff before the first headline
1368 (when (plist-get parameters
:skip-before-1st-heading
)
1369 (goto-char (point-min))
1370 (when (re-search-forward "^\\*+[ \t]" nil t
)
1371 (delete-region (point-min) (match-beginning 0))
1372 (goto-char (point-min))
1374 (when (plist-get parameters
:add-text
)
1375 (goto-char (point-min))
1376 (insert (plist-get parameters
:add-text
) "\n"))
1378 ;; Get rid of archived trees
1379 (org-export-remove-archived-trees archived-trees
)
1381 ;; Find all headings and compute the targets for them
1382 (setq target-alist
(org-export-define-heading-targets target-alist
))
1384 ;; Find targets in comments and move them out of comments,
1385 ;; but mark them as targets that should be invisible
1386 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1389 (org-export-protect-examples (if asciip
'indent nil
))
1391 ;; Protect backend specific stuff, throw away the others.
1392 (org-export-select-backend-specific-text
1393 (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1395 ;; Protect quoted subtrees
1396 (org-export-protect-quoted-subtrees)
1398 ;; Protect verbatim elements
1399 (org-export-protect-verbatim)
1401 ;; Blockquotes and verse
1402 (org-export-mark-blockquote-and-verse)
1404 ;; Remove comment environment and comment subtrees
1405 (org-export-remove-comment-blocks-and-subtrees)
1407 ;; Remove special table lines
1408 (when org-export-table-remove-special-lines
1409 (org-export-remove-special-table-lines))
1411 ;; Specific LaTeX stuff
1413 (require 'org-export-latex nil
)
1414 (org-export-latex-preprocess))
1416 ;; Specific ASCII stuff
1418 (org-export-ascii-preprocess))
1420 ;; Specific HTML stuff
1422 (org-export-html-preprocess parameters
))
1424 ;; Remove or replace comments
1425 (org-export-handle-comments (plist-get parameters
:comments
))
1427 ;; Find matches for radio targets and turn them into internal links
1428 (org-export-mark-radio-links)
1430 ;; Find all links that contain a newline and put them into a single line
1431 (org-export-concatenate-multiline-links)
1433 ;; Normalize links: Convert angle and plain links into bracket links
1434 ;; and expand link abbreviations
1435 (org-export-normalize-links)
1437 ;; Find all internal links. If they have a fuzzy match (i.e. not
1438 ;; a *dedicated* target match, let the link point to the
1439 ;; corresponding section.
1440 (org-export-target-internal-links target-alist
)
1442 ;; Find multiline emphasis and put them into single line
1443 (when (plist-get parameters
:emph-multiline
)
1444 (org-export-concatenate-multiline-emphasis))
1446 (setq rtn
(buffer-string)))
1447 (kill-buffer " org-mode-tmp")
1450 (defun org-export-kill-licensed-text ()
1451 "Remove all text that is marked with a :org-license-to-kill property."
1453 (while (setq p
(text-property-any (point-min) (point-max)
1454 :org-license-to-kill t
))
1456 p
(or (next-single-property-change p
:org-license-to-kill
)
1459 (defun org-export-define-heading-targets (target-alist)
1460 "Find all headings and define the targets for them.
1461 The new targets are added to TARGET-ALIST, which is also returned."
1462 (goto-char (point-min))
1463 (org-init-section-numbers)
1464 (let ((re (concat "^" org-outline-regexp
))
1466 (while (re-search-forward re nil t
)
1467 (setq level
(org-reduced-level
1468 (save-excursion (goto-char (point-at-bol))
1469 (org-outline-level))))
1470 (setq target
(org-solidify-link-text
1471 (format "sec-%s" (org-section-number level
))))
1472 (push (cons target target
) target-alist
)
1473 (add-text-properties
1474 (point-at-bol) (point-at-eol)
1475 (list 'target target
))))
1478 (defun org-export-handle-invisible-targets (target-alist)
1479 "Find targets in comments and move them out of comments.
1480 Mark them as invisible targets."
1482 (goto-char (point-min))
1483 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1484 ;; Check if the line before or after is a headline with a target
1485 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1486 (get-text-property (point-at-bol 2) 'target
)))
1488 ;; use the existing target in a neighboring line
1489 (setq tmp
(match-string 2))
1491 (and (looking-at "\n") (delete-char 1))
1492 (push (cons (org-solidify-link-text tmp
) target
)
1494 ;; Make an invisible target
1495 (replace-match "\\1(INVISIBLE)"))))
1498 (defun org-export-target-internal-links (target-alist)
1499 "Find all internal links and assign target to them.
1500 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1501 let the link point to the corresponding section."
1502 (goto-char (point-min))
1503 (while (re-search-forward org-bracket-link-regexp nil t
)
1505 (let* ((md (match-data))
1506 (desc (match-end 2))
1507 (link (org-link-unescape (match-string 1)))
1508 (slink (org-solidify-link-text link
))
1512 ((cdr (assoc slink target-alist
)))
1513 ((string-match org-link-types-re link
) nil
)
1514 ((or (file-name-absolute-p link
)
1515 (string-match "^\\." link
))
1519 (setq found
(condition-case nil
(org-link-search link
)
1522 (or (org-on-heading-p)
1523 (not (eq found
'dedicated
))))
1524 (or (get-text-property (point) 'target
)
1527 (1- (previous-single-property-change
1532 (goto-char (match-beginning 1))
1533 (setq props
(text-properties-at (point)))
1534 (delete-region (match-beginning 1) (match-end 1))
1537 (unless desc
(insert "][" link
))
1538 (add-text-properties pos
(point) props
))))))
1540 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1541 "Remove drawers, or extract the content.
1542 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1543 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1544 whose content to keep."
1545 (unless (eq t exp-drawers
)
1546 (goto-char (point-min))
1547 (let ((re (concat "^[ \t]*:\\("
1550 (org-delete-all exp-drawers
1551 (copy-sequence all-drawers
))
1553 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1554 (while (re-search-forward re nil t
)
1555 (replace-match "")))))
1557 (defun org-export-remove-archived-trees (export-archived-trees)
1558 "Remove archived trees.
1559 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1560 When it is t, the entire archived tree will be exported.
1561 When it is nil the entire tree including the headline will be removed
1563 (let ((re-archive (concat ":" org-archive-tag
":"))
1565 (when (not (eq export-archived-trees t
))
1566 (goto-char (point-min))
1567 (while (re-search-forward re-archive nil t
)
1568 (if (not (org-on-heading-p t
))
1569 (org-end-of-subtree t
)
1570 (beginning-of-line 1)
1571 (setq a
(if export-archived-trees
1572 (1+ (point-at-eol)) (point))
1573 b
(org-end-of-subtree t
))
1574 (if (> b a
) (delete-region a b
)))))))
1576 (defun org-export-protect-quoted-subtrees ()
1577 "Mark quoted subtrees with the protection property."
1578 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1579 (goto-char (point-min))
1580 (while (re-search-forward re-quote nil t
)
1581 (goto-char (match-beginning 0))
1583 (add-text-properties (point) (org-end-of-subtree t
)
1584 '(org-protected t
)))))
1586 (defun org-export-protect-verbatim ()
1587 "Mark verbatim snippets with the protection property."
1588 (goto-char (point-min))
1589 (while (re-search-forward org-verbatim-re nil t
)
1590 (add-text-properties (match-beginning 4) (match-end 4)
1592 (goto-char (1+ (match-end 4)))))
1594 (defun org-export-protect-examples (&optional indent
)
1595 "Protect code that should be exported as monospaced examples."
1596 (goto-char (point-min))
1597 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1598 (goto-char (match-end 0))
1599 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1600 (insert (if indent
": " ":"))
1601 (beginning-of-line 2)))
1602 (goto-char (point-min))
1603 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1604 (add-text-properties (match-beginning 0) (match-end 0)
1605 '(org-protected t
))))
1607 (defun org-export-select-backend-specific-text (backend)
1609 '((html "HTML" "BEGIN_HTML" "END_HTML")
1610 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1611 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1615 (setq fmt
(pop formatters
))
1616 (when (eq (car fmt
) backend
)
1617 ;; This is selected code, put it into the file for real
1618 (goto-char (point-min))
1619 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1620 ":[ \t]*\\(.*\\)") nil t
)
1621 (replace-match "\\1" t
)
1622 (add-text-properties
1623 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1624 '(org-protected t
))))
1625 (goto-char (point-min))
1626 (while (re-search-forward
1628 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1629 (cadddr fmt
) "\\>.*\n?") nil t
)
1630 (if (eq (car fmt
) backend
)
1632 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1634 ;; No, this is for a different backend, kill it
1635 (delete-region (match-beginning 0) (match-end 0)))))))
1637 (defun org-export-mark-blockquote-and-verse ()
1638 "Mark block quote and verse environments with special cookies.
1639 These special cookies will later be interpreted by the backend."
1641 (goto-char (point-min))
1642 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1644 (replace-match (if (equal (downcase (match-string 1)) "end")
1645 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1648 (goto-char (point-min))
1649 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1650 (replace-match (if (equal (downcase (match-string 1)) "end")
1651 "ORG-VERSE-END" "ORG-VERSE-START")
1654 (defun org-export-remove-comment-blocks-and-subtrees ()
1655 "Remove the comment environment, and also commented subtrees."
1656 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1657 (case-fold-search nil
))
1658 ;; Remove comment environment
1659 (goto-char (point-min))
1660 (while (re-search-forward
1661 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1662 (replace-match "" t t
))
1663 ;; Remove subtrees that are commented
1664 (goto-char (point-min))
1665 (while (re-search-forward re-commented nil t
)
1666 (goto-char (match-beginning 0))
1667 (delete-region (point) (org-end-of-subtree t
)))))
1669 (defun org-export-handle-comments (commentsp)
1670 "Remove comments, or convert to backend-specific format.
1671 COMMENTSP can be a format string for publishing comments.
1672 When it is nil, all comments will be removed."
1673 (let ((re "^#\\(.*\n?\\)")
1675 (goto-char (point-min))
1676 (while (or (looking-at re
)
1677 (re-search-forward re nil t
))
1678 (setq pos
(match-beginning 0))
1680 (progn (add-text-properties
1681 (match-beginning 0) (match-end 0) '(org-protected t
))
1682 (replace-match (format commentsp
(match-string 1)) t t
))
1683 (goto-char (1+ pos
))
1686 (goto-char (max (point-min) (1- pos
))))))))
1688 (defun org-export-mark-radio-links ()
1689 "Find all matches for radio targets and turn them into internal links."
1690 (let ((re-radio (and org-target-link-regexp
1691 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1692 (goto-char (point-min))
1694 (while (re-search-forward re-radio nil t
)
1696 (replace-match "\\1[[\\2]]"))))))
1698 (defun org-export-remove-special-table-lines ()
1699 "Remove tables lines that are used for internal purposes."
1700 (goto-char (point-min))
1701 (while (re-search-forward "^[ \t]*|" nil t
)
1702 (beginning-of-line 1)
1703 (if (or (looking-at "[ \t]*| *[!_^] *|")
1704 (and (looking-at ".*?| *<[0-9]+> *|")
1705 (not (looking-at ".*?| *[^ <|]"))))
1706 (delete-region (max (point-min) (1- (point-at-bol)))
1710 (defun org-export-normalize-links ()
1711 "Convert all links to bracket links, and expand link abbreviations."
1712 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1713 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1714 (goto-char (point-min))
1715 (while (re-search-forward re-plain-link nil t
)
1716 (goto-char (1- (match-end 0)))
1718 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1719 ":" (match-string 3) "]]")))
1720 ;; added 'org-link face to links
1721 (put-text-property 0 (length s
) 'face
'org-link s
)
1722 (replace-match s t t
))))
1723 (goto-char (point-min))
1724 (while (re-search-forward re-angle-link nil t
)
1725 (goto-char (1- (match-end 0)))
1727 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1728 ":" (match-string 3) "]]")))
1729 (put-text-property 0 (length s
) 'face
'org-link s
)
1730 (replace-match s t t
))))
1731 (goto-char (point-min))
1732 (while (re-search-forward org-bracket-link-regexp nil t
)
1733 (goto-char (1- (match-end 0)))
1735 (let* ((xx (save-match-data
1736 (org-link-expand-abbrev (match-string 1))))
1741 (concat "[" xx
"]"))
1743 (put-text-property 0 (length s
) 'face
'org-link s
)
1744 (replace-match s t t
))))))
1746 (defun org-export-concatenate-multiline-links ()
1747 "Find multi-line links and put it all into a single line.
1748 This is to make sure that the line-processing export backends
1749 can work correctly."
1750 (goto-char (point-min))
1751 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1753 (replace-match "\\1 \\3")
1754 (goto-char (match-beginning 0)))))
1756 (defun org-export-concatenate-multiline-emphasis ()
1757 "Find multi-line emphasis and put it all into a single line.
1758 This is to make sure that the line-processing export backends
1759 can work correctly."
1760 (goto-char (point-min))
1761 (while (re-search-forward org-emph-re nil t
)
1762 (if (not (= (char-after (match-beginning 3))
1763 (char-after (match-beginning 4))))
1765 (subst-char-in-region (match-beginning 0) (match-end 0)
1767 (goto-char (1- (match-end 0))))
1768 (goto-char (1+ (match-beginning 0))))))
1770 (defun org-export-grab-title-from-buffer ()
1771 "Get a title for the current document, from looking at the buffer."
1772 (let ((inhibit-read-only t
))
1774 (goto-char (point-min))
1775 (let ((end (save-excursion (outline-next-heading) (point))))
1776 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1777 ;; Mark the line so that it will not be exported as normal text.
1779 (add-text-properties (match-beginning 0) (match-end 0)
1780 (list :org-license-to-kill t
)))
1781 ;; Return the title string
1782 (org-trim (match-string 0)))))))
1784 (defun org-export-get-title-from-subtree ()
1785 "Return subtree title and exclude it from export."
1786 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1789 (when (and (org-at-heading-p)
1790 (>= (org-end-of-subtree t t
) rend
))
1791 ;; This is a subtree, we take the title from the first heading
1793 (looking-at org-todo-line-regexp
)
1794 (setq title
(match-string 3))
1796 (add-text-properties (point) (1+ (point-at-eol))
1797 (list :org-license-to-kill t
)))
1798 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1801 (defun org-solidify-link-text (s &optional alist
)
1802 "Take link text and make a safe target out of it."
1807 (org-split-string s
"[ \t\r\n]+") "=="))
1808 (a (assoc rtn alist
)))
1811 (defun org-get-min-level (lines)
1812 "Get the minimum level in LINES."
1813 (let ((re "^\\(\\*+\\) ") l min
)
1815 (while (setq l
(pop lines
))
1816 (if (string-match re l
)
1817 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1820 ;; Variable holding the vector with section numbers
1821 (defvar org-section-numbers
(make-vector org-level-max
0))
1823 (defun org-init-section-numbers ()
1824 "Initialize the vector for the section numbers."
1826 (numbers (nreverse (org-split-string "" "\\.")))
1827 (depth (1- (length org-section-numbers
)))
1828 (i depth
) number-string
)
1831 (aset org-section-numbers i
0)
1832 (setq number-string
(or (car numbers
) "0"))
1833 (if (string-match "\\`[A-Z]\\'" number-string
)
1834 (aset org-section-numbers i
1835 (- (string-to-char number-string
) ?A -
1))
1836 (aset org-section-numbers i
(string-to-number number-string
)))
1840 (defun org-section-number (&optional level
)
1841 "Return a string with the current section number.
1842 When LEVEL is non-nil, increase section numbers on that level."
1843 (let* ((depth (1- (length org-section-numbers
)))
1845 (fmts (car org-export-section-number-format
))
1846 (term (cdr org-export-section-number-format
))
1851 (aset org-section-numbers
1852 level
(1+ (aref org-section-numbers level
))))
1853 (setq idx
(1+ level
))
1854 (while (<= idx depth
)
1856 (aset org-section-numbers idx
0))
1857 (setq idx
(1+ idx
))))
1859 (while (<= idx depth
)
1860 (when (> (aref org-section-numbers idx
) 0)
1861 (setq fmt
(or (pop fmts
) fmt
)
1863 n
(aref org-section-numbers idx
)
1865 (concat string sep
(org-number-to-counter n ctype
))
1866 (concat string
".0"))
1868 (setq idx
(1+ idx
)))
1870 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1871 (setq string
(replace-match "" t nil string
)))
1872 (if (string-match "\\(\\.0\\)+\\'" string
)
1873 (setq string
(replace-match "" t nil string
))))
1874 (concat string term
)))
1876 (defun org-number-to-counter (n type
)
1877 "Concert number N to a string counter, according to TYPE.
1878 TYPE must be a string, any of:
1882 I uppper case roman numeral
1883 i lower case roman numeral"
1885 ((equal type
"1") (number-to-string n
))
1886 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1887 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1888 ((equal type
"I") (org-number-to-roman n
))
1889 ((equal type
"i") (downcase (org-number-to-roman n
)))
1890 (t (error "Invalid counter type `%s'" type
))))
1892 (defun org-number-to-roman (n)
1893 "Convert integer N into a roman numeral."
1894 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1895 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1896 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1900 (number-to-string n
)
1902 (if (>= n
(caar roman
))
1903 (setq n
(- n
(caar roman
))
1904 res
(concat res
(cdar roman
)))
1908 (org-number-to-roman 1961)
1913 (defun org-export-handle-include-files ()
1914 "Include the contents of include files, with proper formatting."
1915 (let ((case-fold-search t
)
1916 params file markup lang start end prefix prefix1
)
1917 (goto-char (point-min))
1918 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1919 (setq params
(read (concat "(" (match-string 1) ")"))
1920 prefix
(org-get-and-remove-property 'params
:prefix
)
1921 prefix1
(org-get-and-remove-property 'params
:prefix1
)
1922 file
(org-symname-or-string (pop params
))
1923 markup
(org-symname-or-string (pop params
))
1924 lang
(org-symname-or-string (pop params
)))
1925 (delete-region (match-beginning 0) (match-end 0))
1927 (not (file-exists-p file
))
1928 (not (file-readable-p file
)))
1929 (insert (format "CANNOT INCLUDE FILE %s" file
))
1931 (if (equal (downcase markup
) "src")
1932 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1934 (setq start
(format "#+begin_%s\n" markup
)
1935 end
(format "#+end_%s" markup
))))
1936 (insert (or start
""))
1937 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
1938 (or (bolp) (newline))
1939 (insert (or end
""))))))
1941 (defun org-get-file-contents (file &optional prefix prefix1
)
1942 "Get the contents of FILE and return them as a string.
1943 If PREFIX is a string, prepend it to each line. If PREFIX1
1944 is a string, prepend it to the first line instead of PREFIX."
1946 (insert-file-contents file
)
1947 (when (or prefix prefix1
)
1948 (goto-char (point-min))
1950 (insert (or prefix1 prefix
))
1952 (beginning-of-line 2)))
1955 (defun org-get-and-remove-property (listvar prop
)
1956 "Check if the value of LISTVAR contains PROP as a property.
1957 If yes, return the value of that property (i.e. the element following
1958 in the list) and remove property and value from the list in LISTVAR."
1959 (let ((list (symbol-value listvar
)) m v
)
1960 (when (setq m
(member prop list
))
1962 (if (equal (car list
) prop
)
1963 (set listvar
(cddr list
))
1964 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
1966 (set listvar list
)))
1969 (defun org-symname-or-string (s)
1971 (if s
(symbol-name s
) s
)
1974 ;;; Fontification of code
1975 ;; Currently only for the HTML backend, but who knows....
1976 (defun org-export-replace-src-segments ()
1977 "Replace source code segments with special code for export."
1978 (let ((case-fold-search t
)
1980 (goto-char (point-min))
1981 (while (re-search-forward
1982 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1984 (setq lang
(match-string 1) code
(match-string 2)
1985 trans
(org-export-format-source-code lang code
))
1986 (replace-match trans t t
))))
1988 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1990 (defun org-export-format-source-code (lang code
)
1991 "Format CODE from language LANG and return it formatted for export.
1992 Currently, this only does something for HTML export, for all other
1993 backends, it converts the segment into an EXAMPLE segment."
1997 ;; We are exporting to HTML
1998 (condition-case nil
(require 'htmlize
) (nil t
))
1999 (if (not (fboundp 'htmlize-region-for-paste
))
2001 ;; we do not have htmlize.el, or an old version of it
2003 "htmlize.el 1.34 or later is needed for source code formatting")
2004 (concat "#+BEGIN_EXAMPLE\n" code
2005 (if (string-match "\n\\'" code
) "" "\n")
2007 ;; ok, we are good to go
2008 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2009 (org-inhibit-startup t
)
2010 (org-startup-folded nil
)
2014 ;; Free up the protected stuff
2015 (goto-char (point-min))
2016 (while (re-search-forward "^," nil t
)
2019 (if (functionp mode
)
2022 (font-lock-fontify-buffer)
2023 (org-export-htmlize-region-for-paste
2024 (point-min) (point-max)))))
2025 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
2026 (setq htmltext
(replace-match
2027 (format "<pre class=\"src src-%s\">" lang
)
2029 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
2031 ;; This is not HTML, so just make it an example.
2032 (when (equal lang
"org")
2033 (while (string-match "^," code
)
2034 (setq code
(replace-match "" t t code
))))
2035 (concat "#+BEGIN_EXAMPLE\n" code
2036 (if (string-match "\n\\'" code
) "" "\n")
2037 "#+END_EXAMPLE\n")))))
2041 (defvar org-last-level nil
) ; dynamically scoped variable
2042 (defvar org-min-level nil
) ; dynamically scoped variable
2043 (defvar org-levels-open nil
) ; dynamically scoped parameter
2044 (defvar org-ascii-current-indentation nil
) ; For communication
2047 (defun org-export-as-ascii (arg)
2048 "Export the outline as a pretty ASCII file.
2049 If there is an active region, export only the region.
2050 The prefix ARG specifies how many levels of the outline should become
2051 underlined headlines. The default is 3."
2053 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2054 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2055 (org-infile-export-plist)))
2056 (region-p (org-region-active-p))
2057 (rbeg (and region-p
(region-beginning)))
2058 (rend (and region-p
(region-end)))
2063 (and (org-at-heading-p)
2064 (>= (org-end-of-subtree t t
) rend
)))))
2065 (opt-plist (if subtree-p
2066 (org-export-add-subtree-options opt-plist rbeg
)
2068 (custom-times org-display-custom-times
)
2069 (org-ascii-current-indentation '(0 .
0))
2073 (case-fold-search nil
)
2074 (filename (concat (file-name-as-directory
2075 (org-export-directory :ascii opt-plist
))
2076 (file-name-sans-extension
2078 (org-entry-get (region-beginning)
2079 "EXPORT_FILE_NAME" t
))
2080 (file-name-nondirectory buffer-file-name
)))
2082 (filename (if (equal (file-truename filename
)
2083 (file-truename buffer-file-name
))
2084 (concat filename
".txt")
2086 (buffer (find-file-noselect filename
))
2087 (org-levels-open (make-vector org-level-max nil
))
2088 (odd org-odd-levels-only
)
2089 (date (plist-get opt-plist
:date
))
2090 (author (plist-get opt-plist
:author
))
2091 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2092 (plist-get opt-plist
:title
)
2094 (plist-get opt-plist
:skip-before-1st-heading
))
2095 (org-export-grab-title-from-buffer))
2096 (file-name-sans-extension
2097 (file-name-nondirectory buffer-file-name
))))
2098 (email (plist-get opt-plist
:email
))
2099 (language (plist-get opt-plist
:language
))
2100 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2101 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2106 (if (org-region-active-p) (region-beginning) (point-min))
2107 (if (org-region-active-p) (region-end) (point-max))))
2108 (lines (org-split-string
2109 (org-export-preprocess-string
2112 :skip-before-1st-heading
2113 (plist-get opt-plist
:skip-before-1st-heading
)
2114 :drawers
(plist-get opt-plist
:drawers
)
2115 :verbatim-multiline t
2117 (plist-get opt-plist
:archived-trees
)
2118 :add-text
(plist-get opt-plist
:text
))
2120 thetoc have-headings first-heading-pos
2121 table-open table-buffer
)
2123 (let ((inhibit-read-only t
))
2125 (remove-text-properties (point-min) (point-max)
2126 '(:org-license-to-kill t
))))
2128 (setq org-min-level
(org-get-min-level lines
))
2129 (setq org-last-level org-min-level
)
2130 (org-init-section-numbers)
2132 (find-file-noselect filename
)
2134 (setq lang-words
(or (assoc language org-export-language-setup
)
2135 (assoc "en" org-export-language-setup
)))
2136 (switch-to-buffer-other-window buffer
)
2139 ;; create local variables for all options, to make sure all called
2140 ;; functions get the correct information
2142 (set (make-local-variable (cdr x
))
2143 (plist-get opt-plist
(car x
))))
2144 org-export-plist-vars
)
2145 (org-set-local 'org-odd-levels-only odd
)
2146 (setq umax
(if arg
(prefix-numeric-value arg
)
2147 org-export-headline-levels
))
2148 (setq umax-toc
(if (integerp org-export-with-toc
)
2149 (min org-export-with-toc umax
)
2153 (if title
(org-insert-centered title ?
=))
2155 (if (and (or author email
)
2156 org-export-author-info
)
2157 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2158 (if email
(concat " <" email
">") "")
2162 ((and date
(string-match "%" date
))
2163 (setq date
(format-time-string date
)))
2165 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2167 (if (and date org-export-time-stamp-file
)
2168 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2172 (if org-export-with-toc
2174 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2175 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2177 (mapc '(lambda (line)
2178 (if (string-match org-todo-line-regexp
2180 ;; This is a headline
2182 (setq have-headings t
)
2183 (setq level
(- (match-end 1) (match-beginning 1))
2184 level
(org-tr-level level
)
2185 txt
(match-string 3 line
)
2187 (or (and org-export-mark-todo-in-toc
2189 (not (member (match-string 2 line
)
2190 org-done-keywords
)))
2192 (and org-export-mark-todo-in-toc
2194 (org-search-todo-below
2195 line lines level
))))
2196 (setq txt
(org-html-expand-for-ascii txt
))
2198 (while (string-match org-bracket-link-regexp txt
)
2201 (match-string (if (match-end 2) 3 1) txt
)
2204 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2206 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2208 (setq txt
(replace-match "" t t txt
)))
2209 (if (string-match quote-re0 txt
)
2210 (setq txt
(replace-match "" t t txt
)))
2212 (if org-export-with-section-numbers
2213 (setq txt
(concat (org-section-number level
)
2215 (if (<= level umax-toc
)
2220 (* (max 0 (- level org-min-level
)) 4) ?\
)
2221 (format (if todo
"%s (*)\n" "%s\n") txt
))
2223 (setq org-last-level level
))
2226 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2228 (org-init-section-numbers)
2229 (while (setq line
(pop lines
))
2230 ;; Remove the quoted HTML tags.
2231 (setq line
(org-html-expand-for-ascii line
))
2233 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
2234 (setq line
(replace-match "" t t line
)))
2235 ;; Replace internal links
2236 (while (string-match org-bracket-link-regexp line
)
2237 (setq line
(replace-match
2238 (if (match-end 3) "[\\3]" "[\\1]")
2241 (setq line
(org-translate-time line
)))
2243 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2245 (setq first-heading-pos
(or first-heading-pos
(point)))
2246 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2247 txt
(match-string 2 line
))
2248 (org-ascii-level-start level txt umax lines
))
2250 ((and org-export-with-tables
2251 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2252 (if (not table-open
)
2254 (setq table-open t table-buffer nil
))
2256 (setq table-buffer
(cons line table-buffer
))
2257 (when (or (not lines
)
2258 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2260 (setq table-open nil
2261 table-buffer
(nreverse table-buffer
))
2264 (org-fix-indentation x org-ascii-current-indentation
))
2265 (org-format-table-ascii table-buffer
)
2268 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2269 (if (and org-export-with-fixed-width
2270 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2271 (setq line
(replace-match "\\1" nil nil line
)))
2272 (insert line
"\n"))))
2276 ;; insert the table of contents
2278 (goto-char (point-min))
2279 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2281 (goto-char (match-beginning 0))
2283 (goto-char first-heading-pos
))
2284 (mapc 'insert thetoc
)
2285 (or (looking-at "[ \t]*\n[ \t]*\n")
2288 ;; Convert whitespace place holders
2289 (goto-char (point-min))
2291 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2292 (setq end
(next-single-property-change beg
'org-whitespace
))
2294 (delete-region beg end
)
2295 (insert (make-string (- end beg
) ?\
))))
2298 ;; remove display and invisible chars
2300 (goto-char (point-min))
2301 (while (setq beg
(next-single-property-change (point) 'display
))
2302 (setq end
(next-single-property-change beg
'display
))
2303 (delete-region beg end
)
2306 (goto-char (point-min))
2307 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2308 (setq end
(next-single-property-change beg
'org-cwidth
))
2309 (delete-region beg end
)
2311 (goto-char (point-min))))
2313 (defun org-export-ascii-preprocess ()
2314 "Do extra work for ASCII export"
2315 (goto-char (point-min))
2316 (while (re-search-forward org-verbatim-re nil t
)
2317 (goto-char (match-end 2))
2318 (backward-delete-char 1) (insert "'")
2319 (goto-char (match-beginning 2))
2320 (delete-char 1) (insert "`")
2321 (goto-char (match-end 2))))
2323 (defun org-search-todo-below (line lines level
)
2324 "Search the subtree below LINE for any TODO entries."
2325 (let ((rest (cdr (memq line lines
)))
2326 (re org-todo-line-regexp
)
2329 (while (setq line
(pop rest
))
2330 (if (string-match re line
)
2332 (setq lv
(- (match-end 1) (match-beginning 1))
2333 todo
(and (match-beginning 2)
2334 (not (member (match-string 2 line
)
2335 org-done-keywords
))))
2337 (if (<= lv level
) (throw 'exit nil
))
2338 (if todo
(throw 'exit t
))))))))
2340 (defun org-html-expand-for-ascii (line)
2341 "Handle quoted HTML for ASCII export."
2342 (if org-export-html-expand
2343 (while (string-match "@<[^<>\n]*>" line
)
2344 ;; We just remove the tags for now.
2345 (setq line
(replace-match "" nil nil line
))))
2348 (defun org-insert-centered (s &optional underline
)
2349 "Insert the string S centered and underline it with character UNDERLINE."
2350 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2351 (insert (make-string ind ?\
) s
"\n")
2353 (insert (make-string ind ?\
)
2354 (make-string (string-width s
) underline
)
2357 (defun org-ascii-level-start (level title umax
&optional lines
)
2358 "Insert a new level in ASCII export."
2359 (let (char (n (- level umax
1)) (ind 0))
2362 (insert (make-string (* 2 n
) ?\
)
2363 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2364 org-export-ascii-bullets
))
2366 ;; find the indentation of the next non-empty line
2369 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2370 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2371 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2373 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2374 (if (or (not (equal (char-before) ?
\n))
2375 (not (equal (char-before (1- (point))) ?
\n)))
2377 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2378 (unless org-export-with-tags
2379 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2380 (setq title
(replace-match "" t t title
))))
2381 (if org-export-with-section-numbers
2382 (setq title
(concat (org-section-number level
) " " title
)))
2383 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2384 (setq org-ascii-current-indentation
'(0 .
0)))))
2387 (defun org-export-visible (type arg
)
2388 "Create a copy of the visible part of the current buffer, and export it.
2389 The copy is created in a temporary buffer and removed after use.
2390 TYPE is the final key (as a string) that also select the export command in
2391 the `C-c C-e' export dispatcher.
2392 As a special case, if the you type SPC at the prompt, the temporary
2393 org-mode file will not be removed but presented to you so that you can
2394 continue to use it. The prefix arg ARG is passed through to the exporting
2398 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2399 (read-char-exclusive))
2400 current-prefix-arg
))
2401 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2402 (error "Invalid export key"))
2403 (let* ((binding (cdr (assoc type
2404 '((?a . org-export-as-ascii
)
2405 (?\C-a . org-export-as-ascii
)
2406 (?b . org-export-as-html-and-open
)
2407 (?\C-b . org-export-as-html-and-open
)
2408 (?h . org-export-as-html
)
2409 (?H . org-export-as-html-to-buffer
)
2410 (?R . org-export-region-as-html
)
2411 (?x . org-export-as-xoxo
)))))
2412 (keepp (equal type ?\
))
2413 (file buffer-file-name
)
2414 (buffer (get-buffer-create "*Org Export Visible*"))
2416 ;; Need to hack the drawers here.
2418 (goto-char (point-min))
2419 (while (re-search-forward org-drawer-regexp nil t
)
2420 (goto-char (match-beginning 1))
2421 (or (org-invisible-p) (org-flag-drawer nil
))))
2422 (with-current-buffer buffer
(erase-buffer))
2424 (setq s
(goto-char (point-min)))
2425 (while (not (= (point) (point-max)))
2426 (goto-char (org-find-invisible))
2427 (append-to-buffer buffer s
(point))
2428 (setq s
(goto-char (org-find-visible))))
2429 (org-cycle-hide-drawers 'all
)
2430 (goto-char (point-min))
2432 ;; Copy all comment lines to the end, to make sure #+ settings are
2433 ;; still available for the second export step. Kind of a hack, but
2434 ;; does do the trick.
2435 (if (looking-at "#[^\r\n]*")
2436 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2437 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2438 (append-to-buffer buffer
(1+ (match-beginning 0))
2439 (min (point-max) (1+ (match-end 0))))))
2441 (let ((buffer-file-name file
)
2442 (org-inhibit-startup t
))
2445 (unless keepp
(funcall binding arg
))))
2447 (kill-buffer buffer
)
2448 (switch-to-buffer-other-window buffer
)
2449 (goto-char (point-min)))))
2451 (defun org-find-visible ()
2453 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2454 (get-char-property s
'invisible
)))
2456 (defun org-find-invisible ()
2458 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2459 (not (get-char-property s
'invisible
))))
2464 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2465 (defun org-get-current-options ()
2466 "Return a string with current options as keyword options.
2467 Does include HTML export options as well as TODO and CATEGORY stuff."
2468 (require 'org-archive
)
2475 #+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
2482 #+PRIORITIES: %c %c %c
2484 #+STARTUP: %s %s %s %s %s
2490 (buffer-name) (user-full-name) user-mail-address
2491 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2492 org-export-default-language
2493 org-export-headline-levels
2494 org-export-with-section-numbers
2496 org-export-preserve-breaks
2497 org-export-html-expand
2498 org-export-with-fixed-width
2499 org-export-with-tables
2500 org-export-with-sub-superscripts
2501 org-export-with-special-strings
2502 org-export-with-footnotes
2503 org-export-with-emphasize
2504 org-export-with-TeX-macros
2505 org-export-with-LaTeX-fragments
2506 org-export-skip-text-before-1st-heading
2507 org-export-with-drawers
2508 org-export-with-tags
2509 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2510 org-export-html-link-up
2511 org-export-html-link-home
2512 (file-name-nondirectory buffer-file-name
)
2513 "TODO FEEDBACK VERIFY DONE"
2514 "Me Jason Marie DONE"
2515 org-highest-priority org-lowest-priority org-default-priority
2516 (mapconcat 'identity org-drawers
" ")
2517 (cdr (assoc org-startup-folded
2518 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2519 (if org-odd-levels-only
"odd" "oddeven")
2520 (if org-hide-leading-stars
"hidestars" "showstars")
2521 (if org-startup-align-all-tables
"align" "noalign")
2522 (cond ((eq org-log-done t
) "logdone")
2523 ((equal org-log-done
'note
) "lognotedone")
2524 ((not org-log-done
) "nologdone"))
2525 (or (mapconcat (lambda (x)
2527 ((equal '(:startgroup
) x
) "{")
2528 ((equal '(:endgroup
) x
) "}")
2529 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2531 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2532 (mapconcat 'identity org-file-tags
" ")
2533 org-archive-location
2534 "org file:~/org/%s.org"
2537 (defun org-export-html-preprocess (parameters)
2538 ;; Convert LaTeX fragments to images
2539 (when (plist-get parameters
:LaTeX-fragments
)
2541 (concat "ltxpng/" (file-name-sans-extension
2542 (file-name-nondirectory
2543 org-current-export-file
)))
2544 org-current-export-dir nil
"Creating LaTeX image %s"))
2545 (message "Exporting..."))
2548 (defun org-insert-export-options-template ()
2549 "Insert into the buffer a template with information for exporting."
2551 (if (not (bolp)) (newline))
2552 (let ((s (org-get-current-options)))
2553 (and (string-match "#\\+CATEGORY" s
)
2554 (setq s
(substring s
0 (match-beginning 0))))
2558 (defun org-export-as-html-and-open (arg)
2559 "Export the outline as HTML and immediately open it with a browser.
2560 If there is an active region, export only the region.
2561 The prefix ARG specifies how many levels of the outline should become
2562 headlines. The default is 3. Lower levels will become bulleted lists."
2564 (org-export-as-html arg
'hidden
)
2565 (org-open-file buffer-file-name
))
2568 (defun org-export-as-html-batch ()
2569 "Call `org-export-as-html', may be used in batch processing as
2571 --load=$HOME/lib/emacs/org.el
2572 --eval \"(setq org-export-headline-levels 2)\"
2573 --visit=MyFile --funcall org-export-as-html-batch"
2574 (org-export-as-html org-export-headline-levels
'hidden
))
2577 (defun org-export-as-html-to-buffer (arg)
2578 "Call `org-exort-as-html` with output to a temporary buffer.
2579 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2581 (org-export-as-html arg nil nil
"*Org HTML Export*")
2582 (switch-to-buffer-other-window "*Org HTML Export*"))
2585 (defun org-replace-region-by-html (beg end
)
2586 "Assume the current region has org-mode syntax, and convert it to HTML.
2587 This can be used in any buffer. For example, you could write an
2588 itemized list in org-mode syntax in an HTML buffer and then use this
2589 command to convert it."
2591 (let (reg html buf pop-up-frames
)
2592 (save-window-excursion
2594 (setq html
(org-export-region-as-html
2596 (setq reg
(buffer-substring beg end
)
2597 buf
(get-buffer-create "*Org tmp*"))
2598 (with-current-buffer buf
2602 (setq html
(org-export-region-as-html
2603 (point-min) (point-max) t
'string
)))
2605 (delete-region beg end
)
2609 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2610 "Convert region from BEG to END in org-mode buffer to HTML.
2611 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2612 contents, and only produce the region of converted text, useful for
2613 cut-and-paste operations.
2614 If BUFFER is a buffer or a string, use/create that buffer as a target
2615 of the converted HTML. If BUFFER is the symbol `string', return the
2616 produced HTML as a string and leave not buffer behind. For example,
2617 a Lisp program could call this function in the following way:
2619 (setq html (org-export-region-as-html beg end t 'string))
2621 When called interactively, the output buffer is selected, and shown
2622 in a window. A non-interactive call will only return the buffer."
2623 (interactive "r\nP")
2624 (when (interactive-p)
2625 (setq buffer
"*Org HTML Export*"))
2626 (let ((transient-mark-mode t
) (zmacs-regions t
)
2628 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
2630 (set-mark (point)) ;; to activate the region
2632 (setq rtn
(org-export-as-html
2635 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2636 (if (and (interactive-p) (bufferp rtn
))
2637 (switch-to-buffer-other-window rtn
)
2640 (defvar html-table-tag nil
) ; dynamically scoped into this.
2642 (defun org-export-as-html (arg &optional hidden ext-plist
2643 to-buffer body-only pub-dir
)
2644 "Export the outline as a pretty HTML file.
2645 If there is an active region, export only the region. The prefix
2646 ARG specifies how many levels of the outline should become
2647 headlines. The default is 3. Lower levels will become bulleted
2648 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2649 EXT-PLIST is a property list with external parameters overriding
2650 org-mode's default settings, but still inferior to file-local
2651 settings. When TO-BUFFER is non-nil, create a buffer with that
2652 name and export to that buffer. If TO-BUFFER is the symbol
2653 `string', don't leave any buffer behind but just return the
2654 resulting HTML as a string. When BODY-ONLY is set, don't produce
2655 the file header and footer, simply return the content of
2656 <body>...</body>, without even the body tags themselves. When
2657 PUB-DIR is set, use this as the publishing directory."
2660 ;; Make sure we have a file name when we need it.
2661 (when (and (not (or to-buffer body-only
))
2662 (not buffer-file-name
))
2663 (if (buffer-base-buffer)
2664 (org-set-local 'buffer-file-name
2665 (with-current-buffer (buffer-base-buffer)
2667 (error "Need a file name to be able to export.")))
2669 (message "Exporting...")
2670 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2671 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2672 (setq-default org-done-keywords org-done-keywords
)
2673 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2675 (org-export-process-option-filters
2676 (org-combine-plists (org-default-export-plist)
2678 (org-infile-export-plist))))
2680 (style (concat org-export-html-style-default
2681 (plist-get opt-plist
:style
)
2682 (plist-get opt-plist
:style-extra
)))
2683 (html-extension (plist-get opt-plist
:html-extension
))
2684 (link-validate (plist-get opt-plist
:link-validation-function
))
2685 valid thetoc have-headings first-heading-pos
2686 (odd org-odd-levels-only
)
2687 (region-p (org-region-active-p))
2688 (rbeg (and region-p
(region-beginning)))
2689 (rend (and region-p
(region-end)))
2691 (if (plist-get opt-plist
:ignore-subree-p
)
2696 (and (org-at-heading-p)
2697 (>= (org-end-of-subtree t t
) rend
))))))
2698 (opt-plist (if subtree-p
2699 (org-export-add-subtree-options opt-plist rbeg
)
2701 ;; The following two are dynamically scoped into other
2703 (org-current-export-dir
2704 (or pub-dir
(org-export-directory :html opt-plist
)))
2705 (org-current-export-file buffer-file-name
)
2706 (level 0) (line "") (origline "") txt todo
2709 (filename (if to-buffer nil
2712 (file-name-sans-extension
2714 (org-entry-get (region-beginning)
2715 "EXPORT_FILE_NAME" t
))
2716 (file-name-nondirectory buffer-file-name
)))
2718 (file-name-as-directory
2719 (or pub-dir
(org-export-directory :html opt-plist
))))))
2720 (current-dir (if buffer-file-name
2721 (file-name-directory buffer-file-name
)
2723 (buffer (if to-buffer
2725 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2726 (t (get-buffer-create to-buffer
)))
2727 (find-file-noselect filename
)))
2728 (org-levels-open (make-vector org-level-max nil
))
2729 (date (plist-get opt-plist
:date
))
2730 (author (plist-get opt-plist
:author
))
2731 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2732 (plist-get opt-plist
:title
)
2734 (plist-get opt-plist
:skip-before-1st-heading
))
2735 (org-export-grab-title-from-buffer))
2736 (and buffer-file-name
2737 (file-name-sans-extension
2738 (file-name-nondirectory buffer-file-name
)))
2740 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2741 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2742 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2747 (local-list-type nil
)
2748 (local-list-indent nil
)
2749 (llt org-plain-list-ordered-item-terminator
)
2750 (email (plist-get opt-plist
:email
))
2751 (language (plist-get opt-plist
:language
))
2755 (coding-system (and (boundp 'buffer-file-coding-system
)
2756 buffer-file-coding-system
))
2757 (coding-system-for-write (or org-export-html-coding-system
2759 (save-buffer-coding-system (or org-export-html-coding-system
2761 (charset (and coding-system-for-write
2762 (fboundp 'coding-system-get
)
2763 (coding-system-get coding-system-for-write
2767 (if region-p
(region-beginning) (point-min))
2768 (if region-p
(region-end) (point-max))))
2771 (org-export-preprocess-string
2775 :skip-before-1st-heading
2776 (plist-get opt-plist
:skip-before-1st-heading
)
2777 :drawers
(plist-get opt-plist
:drawers
)
2779 (plist-get opt-plist
:archived-trees
)
2781 (plist-get opt-plist
:text
)
2783 (plist-get opt-plist
:LaTeX-fragments
))
2786 table-buffer table-orig-buffer
2787 ind item-type starter didclose
2788 rpl path attr desc descp desc1 desc2 link
2789 snumber fnc item-tag
2792 (let ((inhibit-read-only t
))
2794 (remove-text-properties (point-min) (point-max)
2795 '(:org-license-to-kill t
))))
2797 (message "Exporting...")
2799 (setq org-min-level
(org-get-min-level lines
))
2800 (setq org-last-level org-min-level
)
2801 (org-init-section-numbers)
2804 ((and date
(string-match "%" date
))
2805 (setq date
(format-time-string date
)))
2807 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2809 ;; Get the language-dependent settings
2810 (setq lang-words
(or (assoc language org-export-language-setup
)
2811 (assoc "en" org-export-language-setup
)))
2813 ;; Switch to the output buffer
2815 (let ((inhibit-read-only t
)) (erase-buffer))
2818 (and (fboundp 'set-buffer-file-coding-system
)
2819 (set-buffer-file-coding-system coding-system-for-write
))
2821 (let ((case-fold-search nil
)
2822 (org-odd-levels-only odd
))
2823 ;; create local variables for all options, to make sure all called
2824 ;; functions get the correct information
2826 (set (make-local-variable (cdr x
))
2827 (plist-get opt-plist
(car x
))))
2828 org-export-plist-vars
)
2829 (setq umax
(if arg
(prefix-numeric-value arg
)
2830 org-export-headline-levels
))
2831 (setq umax-toc
(if (integerp org-export-with-toc
)
2832 (min org-export-with-toc umax
)
2837 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2838 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2839 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2840 lang=\"%s\" xml:lang=\"%s\">
2843 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2844 <meta name=\"generator\" content=\"Org-mode\"/>
2845 <meta name=\"generated\" content=\"%s\"/>
2846 <meta name=\"author\" content=\"%s\"/>
2850 language language
(org-html-expand title
)
2851 (or charset
"iso-8859-1") date author style
))
2853 (insert (or (plist-get opt-plist
:preamble
) ""))
2855 (when (plist-get opt-plist
:auto-preamble
)
2856 (if title
(insert (format org-export-html-title-format
2857 (org-html-expand title
))))))
2859 (if (and org-export-with-toc
(not body-only
))
2861 (push (format "<h%d>%s</h%d>\n"
2862 org-export-html-toplevel-hlevel
2864 org-export-html-toplevel-hlevel
)
2866 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2867 (push "<ul>\n<li>" thetoc
)
2869 (mapcar '(lambda (line)
2870 (if (string-match org-todo-line-regexp line
)
2871 ;; This is a headline
2873 (setq have-headings t
)
2874 (setq level
(- (match-end 1) (match-beginning 1))
2875 level
(org-tr-level level
)
2876 txt
(save-match-data
2878 (org-export-cleanup-toc-line
2879 (match-string 3 line
))))
2881 (or (and org-export-mark-todo-in-toc
2883 (not (member (match-string 2 line
)
2884 org-done-keywords
)))
2886 (and org-export-mark-todo-in-toc
2888 (org-search-todo-below
2889 line lines level
))))
2891 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2892 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2893 (if (string-match quote-re0 txt
)
2894 (setq txt
(replace-match "" t t txt
)))
2895 (setq snumber
(org-section-number level
))
2896 (if org-export-with-section-numbers
2897 (setq txt
(concat snumber
" " txt
)))
2898 (if (<= level
(max umax umax-toc
))
2899 (setq head-count
(+ head-count
1)))
2900 (if (<= level umax-toc
)
2902 (if (> level org-last-level
)
2904 (setq cnt
(- level org-last-level
))
2905 (while (>= (setq cnt
(1- cnt
)) 0)
2906 (push "\n<ul>\n<li>" thetoc
))
2907 (push "\n" thetoc
)))
2908 (if (< level org-last-level
)
2910 (setq cnt
(- org-last-level level
))
2911 (while (>= (setq cnt
(1- cnt
)) 0)
2912 (push "</li>\n</ul>" thetoc
))
2913 (push "\n" thetoc
)))
2914 ;; Check for targets
2915 (while (string-match org-any-target-regexp line
)
2916 (setq line
(replace-match
2917 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2919 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2920 (setq txt
(replace-match "" t t txt
)))
2924 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2925 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2926 snumber txt
) thetoc
)
2928 (setq org-last-level level
))
2932 (while (> org-last-level
(1- org-min-level
))
2933 (setq org-last-level
(1- org-last-level
))
2934 (push "</li>\n</ul>\n" thetoc
))
2935 (push "</div>\n" thetoc
)
2936 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2939 (org-init-section-numbers)
2943 (while (setq line
(pop lines
) origline line
)
2946 ;; end of quote section?
2947 (when (and inquote
(string-match "^\\*+ " line
))
2950 ;; inside a quote section?
2952 (insert (org-html-protect line
) "\n")
2953 (throw 'nextline nil
))
2955 ;; Fixed-width, verbatim lines (examples)
2956 (when (and org-export-with-fixed-width
2957 (string-match "^[ \t]*:\\(.*\\)" line
))
2960 (insert "<pre class=\"example\">\n"))
2961 (insert (org-html-protect (match-string 1 line
)) "\n")
2962 (when (or (not lines
)
2963 (not (string-match "^[ \t]*\\(:.*\\)"
2966 (insert "</pre>\n"))
2967 (throw 'nextline nil
))
2970 (when (get-text-property 0 'org-protected line
)
2972 (when (re-search-backward
2973 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2974 (setq par
(match-string 1))
2975 (replace-match "\\2\n"))
2978 (not (string-match "^[ \t]*:" (car lines
)))
2979 (or (= (length (car lines
)) 0)
2980 (get-text-property 0 'org-protected
(car lines
))))
2981 (insert (pop lines
) "\n"))
2982 (and par
(insert "<p>\n")))
2983 (throw 'nextline nil
))
2986 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2987 (insert "\n<hr/>\n")
2988 (throw 'nextline nil
))
2990 ;; Blockquotes and verse
2991 (when (equal "ORG-BLOCKQUOTE-START" line
)
2992 (insert "<blockquote>\n<p>\n")
2993 (throw 'nextline nil
))
2994 (when (equal "ORG-BLOCKQUOTE-END" line
)
2995 (insert "</p>\n</blockquote>\n")
2996 (throw 'nextline nil
))
2997 (when (equal "ORG-VERSE-START" line
)
2998 (insert "\n<p class=\"verse\">\n")
3000 (throw 'nextline nil
))
3001 (when (equal "ORG-VERSE-END" line
)
3004 (throw 'nextline nil
))
3006 (setq i
(org-get-string-indentation line
))
3008 (setq line
(concat (mapconcat 'identity
3009 (make-list (* 2 i
) "\\nbsp") "")
3010 " " (org-trim line
))))
3011 (setq line
(concat line
" \\\\")))
3013 ;; make targets to anchors
3014 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3017 (setq line
(replace-match
3018 (concat "@<a name=\""
3019 (org-solidify-link-text (match-string 1 line
))
3022 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3023 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3024 (setq line
(replace-match
3025 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3026 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3029 (setq line
(replace-match
3030 (concat "@<a name=\""
3031 (org-solidify-link-text (match-string 1 line
))
3032 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3035 (setq line
(org-html-handle-time-stamps line
))
3037 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3038 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3039 ;; Also handle sub_superscripts and checkboxes
3040 (or (string-match org-table-hline-regexp line
)
3041 (setq line
(org-html-expand line
)))
3045 (while (string-match org-bracket-link-analytic-regexp line start
)
3046 (setq start
(match-beginning 0))
3047 (setq path
(save-match-data (org-link-unescape
3048 (match-string 3 line
))))
3050 ((match-end 2) (match-string 2 line
))
3052 (or (file-name-absolute-p path
)
3053 (string-match "^\\.\\.?/" path
)))
3056 (setq path
(org-extract-attributes path
))
3057 (setq attr
(org-attributes-to-string
3058 (get-text-property 0 'org-attributes path
)))
3059 (setq desc1
(if (match-end 5) (match-string 5 line
))
3060 desc2
(if (match-end 2) (concat type
":" path
) path
)
3061 descp
(and desc1
(not (equal desc1 desc2
)))
3062 desc
(or desc1 desc2
))
3063 ;; Make an image out of the description if that is so wanted
3064 (when (and descp
(org-file-image-p desc
))
3066 (if (string-match "^file:" desc
)
3067 (setq desc
(substring desc
(match-end 0)))))
3068 (setq desc
(concat "<img src=\"" desc
"\"/>")))
3069 ;; FIXME: do we need to unescape here somewhere?
3071 ((equal type
"internal")
3075 (org-solidify-link-text
3076 (save-match-data (org-link-unescape path
)) nil
)
3077 "\"" attr
">" desc
"</a>")))
3078 ((member type
'("http" "https"))
3079 ;; standard URL, just check if we need to inline an image
3080 (if (and (or (eq t org-export-html-inline-images
)
3081 (and org-export-html-inline-images
(not descp
)))
3082 (org-file-image-p path
))
3083 (setq rpl
(concat "<img src=\"" type
":" path
"\"" attr
"/>"))
3084 (setq link
(concat type
":" path
))
3085 (setq rpl
(concat "<a href=\"" link
"\"" attr
">"
3087 ((member type
'("ftp" "mailto" "news"))
3089 (setq link
(concat type
":" path
))
3090 (setq rpl
(concat "<a href=\"" link
"\"" attr
">" desc
"</a>")))
3092 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3093 ;; The link protocol has a function for format the link
3096 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3098 ((string= type
"file")
3100 (let* ((filename path
)
3101 (abs-p (file-name-absolute-p filename
))
3102 thefile file-is-image-p search
)
3104 (if (string-match "::\\(.*\\)" filename
)
3105 (setq search
(match-string 1 filename
)
3106 filename
(replace-match "" t nil filename
)))
3108 (if (functionp link-validate
)
3109 (funcall link-validate filename current-dir
)
3111 (setq file-is-image-p
(org-file-image-p filename
))
3112 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3113 (when (and org-export-html-link-org-files-as-html
3114 (string-match "\\.org$" thefile
))
3115 (setq thefile
(concat (substring thefile
0
3116 (match-beginning 0))
3117 "." html-extension
))
3119 ;; make sure this is can be used as target search
3120 (not (string-match "^[0-9]*$" search
))
3121 (not (string-match "^\\*" search
))
3122 (not (string-match "^/.*/$" search
)))
3123 (setq thefile
(concat thefile
"#"
3124 (org-solidify-link-text
3125 (org-link-unescape search
)))))
3126 (when (string-match "^file:" desc
)
3127 (setq desc
(replace-match "" t t desc
))
3128 (if (string-match "\\.org$" desc
)
3129 (setq desc
(replace-match "" t t desc
))))))
3130 (setq rpl
(if (and file-is-image-p
3131 (or (eq t org-export-html-inline-images
)
3132 (and org-export-html-inline-images
3134 (concat "<img src=\"" thefile
"\"" attr
"/>")
3135 (concat "<a href=\"" thefile
"\"" attr
">"
3137 (if (not valid
) (setq rpl desc
))))
3140 ;; just publish the path, as default
3141 (setq rpl
(concat "<i><" type
":"
3142 (save-match-data (org-link-unescape path
))
3144 (setq line
(replace-match rpl t t line
)
3145 start
(+ start
(length rpl
))))
3148 (if (and (string-match org-todo-line-regexp line
)
3149 (match-beginning 2))
3152 (concat (substring line
0 (match-beginning 2))
3154 (if (member (match-string 2 line
)
3157 "\">" (match-string 2 line
)
3158 "</span>" (substring line
(match-end 2)))))
3160 ;; Does this contain a reference to a footnote?
3161 (when org-export-with-footnotes
3163 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3164 (if (get-text-property (match-beginning 2) 'org-protected line
)
3165 (setq start
(match-end 2))
3166 (let ((n (match-string 2 line
)))
3170 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3171 (match-string 1 line
) n n n
)
3175 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3176 ;; This is a headline
3177 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3178 txt
(match-string 2 line
))
3179 (if (string-match quote-re0 txt
)
3180 (setq txt
(replace-match "" t t txt
)))
3181 (if (<= level
(max umax umax-toc
))
3182 (setq head-count
(+ head-count
1)))
3184 ;; Close any local lists before inserting a new header line
3185 (while local-list-type
3186 (org-close-li (car local-list-type
))
3187 (insert (format "</%sl>\n" (car local-list-type
)))
3188 (pop local-list-type
))
3189 (setq local-list-indent nil
3191 (setq first-heading-pos
(or first-heading-pos
(point)))
3192 (org-html-level-start level txt umax
3193 (and org-export-with-toc
(<= level umax
))
3196 (when (string-match quote-re line
)
3200 ((and org-export-with-tables
3201 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3202 (if (not table-open
)
3204 (setq table-open t table-buffer nil table-orig-buffer nil
))
3206 (setq table-buffer
(cons line table-buffer
)
3207 table-orig-buffer
(cons origline table-orig-buffer
))
3208 (when (or (not lines
)
3209 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3211 (setq table-open nil
3212 table-buffer
(nreverse table-buffer
)
3213 table-orig-buffer
(nreverse table-orig-buffer
))
3214 (org-close-par-maybe)
3215 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3220 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3221 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3222 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3223 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3225 (setq ind
(org-get-string-indentation line
)
3226 item-type
(if (match-beginning 4) "o" "u")
3227 starter
(if (match-beginning 2)
3228 (substring (match-string 2 line
) 0 -
1))
3229 line
(substring line
(match-beginning 5))
3231 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3233 item-tag
(match-string 1 line
)
3234 line
(substring line
(match-end 0))))
3235 (when (and (not (equal item-type
"d"))
3236 (not (string-match "[^ \t]" line
)))
3237 ;; empty line. Pretend indentation is large.
3238 (setq ind
(if org-empty-line-terminates-plain-lists
3240 (1+ (or (car local-list-indent
) 1)))))
3242 (while (and in-local-list
3243 (or (and (= ind
(car local-list-indent
))
3245 (< ind
(car local-list-indent
))))
3247 (org-close-li (car local-list-type
))
3248 (insert (format "</%sl>\n" (car local-list-type
)))
3249 (pop local-list-type
) (pop local-list-indent
)
3250 (setq in-local-list local-list-indent
))
3253 (or (not in-local-list
)
3254 (> ind
(car local-list-indent
))))
3255 ;; Start new (level of) list
3256 (org-close-par-maybe)
3258 ((equal item-type
"u") "<ul>\n<li>\n")
3259 ((equal item-type
"o") "<ol>\n<li>\n")
3260 ((equal item-type
"d")
3261 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3262 (push item-type local-list-type
)
3263 (push ind local-list-indent
)
3264 (setq in-local-list t
))
3266 ;; continue current list
3267 (org-close-li (car local-list-type
))
3269 ((equal (car local-list-type
) "d")
3270 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3273 ;; we did close a list, normal text follows: need <p>
3275 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3278 (if (equal (match-string 1 line
) "X")
3280 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3283 ;; Empty lines start a new paragraph. If hand-formatted lists
3284 ;; are not fully interpreted, lines starting with "-", "+", "*"
3285 ;; also start a new paragraph.
3286 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3288 ;; Is this the start of a footnote?
3289 (when org-export-with-footnotes
3290 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3291 (org-close-par-maybe)
3292 (let ((n (match-string 1 line
)))
3293 (setq line
(replace-match
3294 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
))
3295 (setq line
(concat line
"</p>")))))
3297 ;; Check if the line break needs to be conserved
3299 ((string-match "\\\\\\\\[ \t]*$" line
)
3300 (setq line
(replace-match "<br/>" t t line
)))
3301 (org-export-preserve-breaks
3302 (setq line
(concat line
"<br/>"))))
3304 (insert line
"\n")))))
3306 ;; Properly close all local lists and other lists
3307 (when inquote
(insert "</pre>\n"))
3309 ;; Close any local lists before inserting a new header line
3310 (while local-list-type
3311 (org-close-li (car local-list-type
))
3312 (insert (format "</%sl>\n" (car local-list-type
)))
3313 (pop local-list-type
))
3314 (setq local-list-indent nil
3316 (org-html-level-start 1 nil umax
3317 (and org-export-with-toc
(<= level umax
))
3319 ;; the </div> to lose the last text-... div.
3323 (when (plist-get opt-plist
:auto-postamble
)
3324 (insert "<div id=\"postamble\">")
3325 (when (and org-export-author-info author
)
3326 (insert "<p class=\"author\"> "
3327 (nth 1 lang-words
) ": " author
"\n")
3329 (if (listp (split-string email
",+ *"))
3331 (insert "<a href=\"mailto:" e
"\"><"
3333 (split-string email
",+ *"))
3334 (insert "<a href=\"mailto:" email
"\"><"
3335 email
"></a>\n")))
3337 (when (and date org-export-time-stamp-file
)
3338 (insert "<p class=\"date\"> "
3339 (nth 2 lang-words
) ": "
3341 (when org-export-creator-info
3342 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3343 org-version emacs-major-version
)))
3346 (if org-export-html-with-timestamp
3347 (insert org-export-html-html-helper-timestamp
))
3348 (insert (or (plist-get opt-plist
:postamble
) ""))
3349 (insert "</body>\n</html>\n"))
3351 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3353 (if (eq major-mode default-major-mode
) (html-mode)))
3355 ;; insert the table of contents
3356 (goto-char (point-min))
3358 (if (or (re-search-forward
3359 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3361 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3363 (goto-char (match-beginning 0))
3365 (goto-char first-heading-pos
)
3366 (when (looking-at "\\s-*</p>")
3367 (goto-char (match-end 0))
3369 (insert "<div id=\"table-of-contents\">\n")
3370 (mapc 'insert thetoc
)
3371 (insert "</div>\n"))
3372 ;; remove empty paragraphs and lists
3373 (goto-char (point-min))
3374 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3376 (goto-char (point-min))
3377 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3379 (goto-char (point-min))
3380 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3382 ;; Convert whitespace place holders
3383 (goto-char (point-min))
3385 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3386 (setq n
(get-text-property beg
'org-whitespace
)
3387 end
(next-single-property-change beg
'org-whitespace
))
3389 (delete-region beg end
)
3390 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3391 (make-string n ?x
)))))
3392 (or to-buffer
(save-buffer))
3393 (goto-char (point-min))
3394 (message "Exporting... done")
3395 (if (eq to-buffer
'string
)
3396 (prog1 (buffer-substring (point-min) (point-max))
3397 (kill-buffer (current-buffer)))
3398 (current-buffer)))))
3401 (defvar org-table-colgroup-info nil
)
3402 (defun org-format-table-ascii (lines)
3403 "Format a table for ascii export."
3405 (setq lines
(org-split-string lines
"\n")))
3406 (if (not (string-match "^[ \t]*|" (car lines
)))
3407 ;; Table made by table.el - test for spanning
3410 ;; A normal org table
3411 ;; Get rid of hlines at beginning and end
3412 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3413 (setq lines
(nreverse lines
))
3414 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3415 (setq lines
(nreverse lines
))
3416 (when org-export-table-remove-special-lines
3417 ;; Check if the table has a marking column. If yes remove the
3418 ;; column and the special lines
3419 (setq lines
(org-table-clean-before-export lines
)))
3420 ;; Get rid of the vertical lines except for grouping
3421 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3423 (while (setq line
(pop lines
))
3424 (if (string-match org-table-hline-regexp line
)
3425 (and (string-match "|\\(.*\\)|" line
)
3426 (setq line
(replace-match " \\1" t nil line
)))
3427 (setq start
0 vl1 vl
)
3428 (while (string-match "|" line start
)
3429 (setq start
(match-end 0))
3430 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3434 (defun org-colgroup-info-to-vline-list (info)
3437 (setq last new new
(pop info
))
3438 (if (or (memq last
'(:end
:startend
))
3439 (memq new
'(:start
:startend
)))
3442 (setq vl
(nreverse vl
))
3443 (and vl
(setcar vl nil
))
3446 (defvar org-table-number-regexp
) ; defined in org-table.el
3447 (defun org-format-table-html (lines olines
)
3448 "Find out which HTML converter to use and return the HTML code."
3450 (setq lines
(org-split-string lines
"\n")))
3451 (if (string-match "^[ \t]*|" (car lines
))
3452 ;; A normal org table
3453 (org-format-org-table-html lines
)
3454 ;; Table made by table.el - test for spanning
3455 (let* ((hlines (delq nil
(mapcar
3457 (if (string-match "^[ \t]*\\+-" x
) x
3460 (first (car hlines
))
3461 (ll (and (string-match "\\S-+" first
)
3462 (match-string 0 first
)))
3463 (re (concat "^[ \t]*" (regexp-quote ll
)))
3464 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3466 (if (and (not spanning
)
3467 (not org-export-prefer-native-exporter-for-tables
))
3468 ;; We can use my own converter with HTML conversions
3469 (org-format-table-table-html lines
)
3470 ;; Need to use the code generator in table.el, with the original text.
3471 (org-format-table-table-html-using-table-generate-source olines
)))))
3473 (defvar org-table-number-fraction
) ; defined in org-table.el
3474 (defun org-format-org-table-html (lines &optional splice
)
3475 "Format a table into HTML."
3476 (require 'org-table
)
3477 ;; Get rid of hlines at beginning and end
3478 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3479 (setq lines
(nreverse lines
))
3480 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3481 (setq lines
(nreverse lines
))
3482 (when org-export-table-remove-special-lines
3483 ;; Check if the table has a marking column. If yes remove the
3484 ;; column and the special lines
3485 (setq lines
(org-table-clean-before-export lines
)))
3487 (let ((head (and org-export-highlight-first-table-line
3489 (lambda (x) (string-match "^[ \t]*|-" x
))
3492 tbopen line fields html gr colgropen
)
3493 (if splice
(setq head nil
))
3494 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3496 (while (setq line
(pop lines
))
3498 (if (string-match "^[ \t]*|-" line
)
3501 (push (if head
"</thead>" "</tbody>") html
)
3502 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3503 (setq head nil
) ;; head ends here, first time around
3505 (throw 'next-line t
)))
3506 ;; Break the line into fields
3507 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3508 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3509 (setq nlines
(1+ nlines
) i -
1)
3510 (push (concat "<tr>"
3514 (if (and (< i nlines
)
3515 (string-match org-table-number-regexp x
))
3516 (incf (aref fnum i
)))
3518 (concat (car org-export-table-header-tags
) x
3519 (cdr org-export-table-header-tags
))
3520 (concat (car org-export-table-data-tags
) x
3521 (cdr org-export-table-data-tags
))))
3525 (unless splice
(if tbopen
(push "</tbody>" html
)))
3526 (unless splice
(push "</table>\n" html
))
3527 (setq html
(nreverse html
))
3529 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3532 (setq gr
(pop org-table-colgroup-info
))
3533 (format "%s<col align=\"%s\"></col>%s"
3534 (if (memq gr
'(:start
:startend
))
3536 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3539 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3541 (if (memq gr
'(:end
:startend
))
3542 (progn (setq colgropen nil
) "</colgroup>")
3546 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3547 (push html-table-tag html
))
3548 (concat (mapconcat 'identity html
"\n") "\n")))
3550 (defun org-table-clean-before-export (lines)
3551 "Check if the table has a marking column.
3552 If yes remove the column and the special lines."
3553 (setq org-table-colgroup-info nil
)
3556 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3557 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3560 (setq org-table-clean-did-remove-column nil
)
3565 ((string-match "^[ \t]*| */ *|" x
)
3566 (setq org-table-colgroup-info
3568 (cond ((member x
'("<" "<")) :start
)
3569 ((member x
'(">" ">")) :end
)
3570 ((member x
'("<>" "<>")) :startend
)
3572 (org-split-string x
"[ \t]*|[ \t]*")))
3576 (setq org-table-clean-did-remove-column t
)
3581 ((string-match "^[ \t]*| */ *|" x
)
3582 (setq org-table-colgroup-info
3584 (cond ((member x
'("<" "<")) :start
)
3585 ((member x
'(">" ">")) :end
)
3586 ((member x
'("<>" "<>")) :startend
)
3588 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3590 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3591 nil
) ; ignore this line
3592 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3593 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3594 ;; remove the first column
3595 (replace-match "\\1|" t nil x
))))
3598 (defun org-format-table-table-html (lines)
3599 "Format a table generated by table.el into HTML.
3600 This conversion does *not* use `table-generate-source' from table.el.
3601 This has the advantage that Org-mode's HTML conversions can be used.
3602 But it has the disadvantage, that no cell- or row-spanning is allowed."
3603 (let (line field-buffer
3604 (head org-export-highlight-first-table-line
)
3606 (setq html
(concat html-table-tag
"\n"))
3607 (while (setq line
(pop lines
))
3608 (setq empty
" ")
3610 (if (string-match "^[ \t]*\\+-" line
)
3621 (if (equal x
"") (setq x empty
))
3623 (concat (car org-export-table-header-tags
) x
3624 (cdr org-export-table-header-tags
))
3625 (concat (car org-export-table-data-tags
) x
3626 (cdr org-export-table-data-tags
))))
3630 (setq field-buffer nil
)))
3632 (throw 'next-line t
)))
3633 ;; Break the line into fields and store the fields
3634 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3636 (setq field-buffer
(mapcar
3638 (concat x
"<br/>" (pop fields
)))
3640 (setq field-buffer fields
))))
3641 (setq html
(concat html
"</table>\n"))
3644 (defun org-format-table-table-html-using-table-generate-source (lines)
3645 "Format a table into html, using `table-generate-source' from table.el.
3646 This has the advantage that cell- or row-spanning is allowed.
3647 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3649 (with-current-buffer (get-buffer-create " org-tmp1 ")
3651 (insert (mapconcat 'identity lines
"\n"))
3652 (goto-char (point-min))
3653 (if (not (re-search-forward "|[^+]" nil t
))
3654 (error "Error processing table"))
3655 (table-recognize-table)
3656 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3657 (table-generate-source 'html
" org-tmp2 ")
3658 (set-buffer " org-tmp2 ")
3659 (buffer-substring (point-min) (point-max))))
3661 (defun org-export-splice-style (style extra
)
3662 "Splice EXTRA into STYLE, just before \"</style>\"."
3663 (if (and (stringp extra
)
3664 (string-match "\\S-" extra
)
3665 (string-match "</style>" style
))
3666 (concat (substring style
0 (match-beginning 0))
3668 (substring style
(match-beginning 0)))
3671 (defun org-html-handle-time-stamps (s)
3672 "Format time stamps in string S, or remove them."
3675 (while (string-match org-maybe-keyword-time-regexp s
)
3676 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3677 ;; never export CLOCK
3679 (or b
(setq b
(substring s
0 (match-beginning 0))))
3680 (if (not org-export-with-timestamps
)
3681 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3682 s
(substring s
(match-end 0)))
3684 r
(substring s
0 (match-beginning 0))
3686 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3687 (match-string 1 s
)))
3688 (format " @<span class=\"timestamp\">%s@</span>"
3690 (org-translate-time (match-string 3 s
)) 1 -
1)))
3691 s
(substring s
(match-end 0)))))
3692 ;; Line break if line started and ended with time stamp stuff
3695 (setq r
(concat r s
))
3696 (unless (string-match "\\S-" (concat b s
))
3697 (setq r
(concat r
"@<br/>")))
3700 (defun org-export-htmlize-region-for-paste (beg end
)
3701 "Convert the region to HTML, using htmlize.el.
3702 This is much like `htmlize-region-for-paste', only that it uses
3703 the settings define in the org-... variables."
3704 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3705 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3706 (htmlbuf (htmlize-region beg end
)))
3708 (with-current-buffer htmlbuf
3709 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3710 (plist-get htmlize-buffer-places
'content-end
)))
3711 (kill-buffer htmlbuf
))))
3714 (defun org-export-htmlize-generate-css ()
3715 "Create the CSS for all font definitions in the current Emacs session.
3716 Use this to create face definitions in your CSS style file that can then
3717 be used by code snippets transformed by htmlize.
3718 This command just produces a buffer that contains class definitions for all
3719 faces used in the current Emacs session. You can copy and paste the ones you
3720 need into your CSS file.
3722 If you then set `org-export-htmlize-output-type' to `css', calls to
3723 the function `org-export-htmlize-region-for-paste' will produce code
3724 that uses these same face definitions."
3727 (and (get-buffer "*html*") (kill-buffer "*html*"))
3729 (let ((fl (face-list))
3730 (htmlize-css-name-prefix "org-")
3731 (htmlize-output-type 'css
)
3733 (while (setq f
(pop fl
)
3734 i
(and f
(face-attribute f
:inherit
)))
3735 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3736 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3737 (htmlize-region (point-min) (point-max))))
3738 (switch-to-buffer "*html*")
3739 (goto-char (point-min))
3740 (if (re-search-forward "<style" nil t
)
3741 (delete-region (point-min) (match-beginning 0)))
3742 (if (re-search-forward "</style>" nil t
)
3743 (delete-region (1+ (match-end 0)) (point-max)))
3744 (beginning-of-line 1)
3745 (if (looking-at " +") (replace-match ""))
3746 (goto-char (point-min)))
3748 (defun org-html-protect (s)
3749 ;; convert & to &, < to < and > to >
3751 (while (string-match "&" s start
)
3752 (setq s
(replace-match "&" t t s
)
3753 start
(1+ (match-beginning 0))))
3754 (while (string-match "<" s
)
3755 (setq s
(replace-match "<" t t s
)))
3756 (while (string-match ">" s
)
3757 (setq s
(replace-match ">" t t s
))))
3760 (defun org-export-cleanup-toc-line (s)
3761 "Remove tags and time staps from lines going into the toc."
3762 (when (memq org-export-with-tags
'(not-in-toc nil
))
3763 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3764 (setq s
(replace-match "" t t s
))))
3765 (when org-export-remove-timestamps-from-toc
3766 (while (string-match org-maybe-keyword-time-regexp s
)
3767 (setq s
(replace-match "" t t s
))))
3768 (while (string-match org-bracket-link-regexp s
)
3769 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3773 (defun org-html-expand (string)
3774 "Prepare STRING for HTML export. Applies all active conversions.
3775 If there are links in the string, don't modify these."
3776 (let* ((re (concat org-bracket-link-regexp
"\\|"
3777 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3779 (while (setq m
(string-match re string
))
3780 (setq s
(substring string
0 m
)
3781 l
(match-string 0 string
)
3782 string
(substring string
(match-end 0)))
3783 (push (org-html-do-expand s
) res
)
3785 (push (org-html-do-expand string
) res
)
3786 (apply 'concat
(nreverse res
))))
3788 (defun org-html-do-expand (s)
3789 "Apply all active conversions to translate special ASCII to HTML."
3790 (setq s
(org-html-protect s
))
3791 (if org-export-html-expand
3793 (while (string-match "@<\\([^&]*\\)>" s
)
3794 (setq s
(replace-match "<\\1>" t nil s
)))))
3795 (if org-export-with-emphasize
3796 (setq s
(org-export-html-convert-emphasize s
)))
3797 (if org-export-with-special-strings
3798 (setq s
(org-export-html-convert-special-strings s
)))
3799 (if org-export-with-sub-superscripts
3800 (setq s
(org-export-html-convert-sub-super s
)))
3801 (if org-export-with-TeX-macros
3802 (let ((start 0) wd ass
)
3803 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
3805 (if (get-text-property (match-beginning 0) 'org-protected s
)
3806 (setq start
(match-end 0))
3807 (setq wd
(match-string 1 s
))
3808 (if (setq ass
(assoc wd org-html-entities
))
3809 (setq s
(replace-match (or (cdr ass
)
3810 (concat "&" (car ass
) ";"))
3812 (setq start
(+ start
(length wd
))))))))
3815 (defun org-create-multibrace-regexp (left right n
)
3816 "Create a regular expression which will match a balanced sexp.
3817 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3818 as single character strings.
3819 The regexp returned will match the entire expression including the
3820 delimiters. It will also define a single group which contains the
3821 match except for the outermost delimiters. The maximum depth of
3822 stacked delimiters is N. Escaping delimiters is not possible."
3823 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3826 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3829 re
(concat re or next
)
3830 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3831 (concat left
"\\(" re
"\\)" right
)))
3833 (defvar org-match-substring-regexp
3835 "\\([^\\]\\)\\([_^]\\)\\("
3836 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3838 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3840 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3841 "The regular expression matching a sub- or superscript.")
3843 (defvar org-match-substring-with-braces-regexp
3845 "\\([^\\]\\)\\([_^]\\)\\("
3846 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3848 "The regular expression matching a sub- or superscript, forcing braces.")
3850 (defconst org-export-html-special-string-regexps
3851 '(("\\\\-" .
"­")
3852 ("---\\([^-]\\)" .
"—\\1")
3853 ("--\\([^-]\\)" .
"–\\1")
3854 ("\\.\\.\\." .
"…"))
3855 "Regular expressions for special string conversion.")
3857 (defun org-export-html-convert-special-strings (string)
3858 "Convert special characters in STRING to HTML."
3859 (let ((all org-export-html-special-string-regexps
)
3861 (while (setq a
(pop all
))
3862 (setq re
(car a
) rpl
(cdr a
) start
0)
3863 (while (string-match re string start
)
3864 (if (get-text-property (match-beginning 0) 'org-protected string
)
3865 (setq start
(match-end 0))
3866 (setq string
(replace-match rpl t nil string
)))))
3869 (defun org-export-html-convert-sub-super (string)
3870 "Convert sub- and superscripts in STRING to HTML."
3871 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3872 (while (string-match org-match-substring-regexp string s
)
3874 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3875 ((get-text-property (match-beginning 2) 'org-protected string
)
3876 (setq s
(match-end 2)))
3878 (setq s
(match-end 1)
3879 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3880 c
(or (match-string 8 string
)
3881 (match-string 6 string
)
3882 (match-string 5 string
))
3883 string
(replace-match
3884 (concat (match-string 1 string
)
3885 "<" key
">" c
"</" key
">")
3887 (while (string-match "\\\\\\([_^]\\)" string
)
3888 (setq string
(replace-match (match-string 1 string
) t t string
)))
3891 (defun org-export-html-convert-emphasize (string)
3894 (while (string-match org-emph-re string s
)
3896 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3897 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3898 (setq s
(match-beginning 0)
3901 (match-string 1 string
)
3902 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3903 (match-string 4 string
)
3904 (nth 3 (assoc (match-string 3 string
)
3905 org-emphasis-alist
))
3906 (match-string 5 string
))
3907 string
(replace-match rpl t t string
)
3908 s
(+ s
(- (length rpl
) 2)))
3912 (defvar org-par-open nil
)
3913 (defun org-open-par ()
3914 "Insert <p>, but first close previous paragraph if any."
3915 (org-close-par-maybe)
3917 (setq org-par-open t
))
3918 (defun org-close-par-maybe ()
3919 "Close paragraph if there is one open."
3922 (setq org-par-open nil
)))
3923 (defun org-close-li (&optional type
)
3924 "Close <li> if necessary."
3925 (org-close-par-maybe)
3926 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3928 (defvar body-only
) ; dynamically scoped into this.
3929 (defun org-html-level-start (level title umax with-toc head-count
)
3930 "Insert a new level in HTML export.
3931 When TITLE is nil, just close all open levels."
3932 (org-close-par-maybe)
3933 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3937 (if (aref org-levels-open
(1- l
))
3939 (org-html-level-close l umax
)
3940 (aset org-levels-open
(1- l
) nil
)))
3943 ;; If title is nil, this means this function is called to close
3944 ;; all levels, so the rest is done only if title is given
3945 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3946 (setq title
(replace-match
3947 (if org-export-with-tags
3950 " <span class=\"tag\">"
3951 (mapconcat 'identity
(org-split-string
3952 (match-string 1 title
) ":")
3959 (if (aref org-levels-open
(1- level
))
3963 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3964 (insert "<li>" title
"<br/>\n")))
3965 (aset org-levels-open
(1- level
) t
)
3966 (org-close-par-maybe)
3968 (insert (format "<ul>\n<li id=\"%s\">" target
)
3970 (insert "<ul>\n<li>" title
"<br/>\n"))))
3971 (aset org-levels-open
(1- level
) t
)
3972 (setq snumber
(org-section-number level
))
3973 (if (and org-export-with-section-numbers
(not body-only
))
3974 (setq title
(concat snumber
" " title
)))
3975 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3976 (unless (= head-count
1) (insert "\n</div>\n"))
3977 (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"
3978 snumber level level snumber title level snumber
))
3981 (defun org-get-text-property-any (pos prop
&optional object
)
3982 (or (get-text-property pos prop object
)
3983 (and (setq pos
(next-single-property-change pos prop object
))
3984 (get-text-property pos prop object
))))
3986 (defun org-html-level-close (level max-outline-level
)
3987 "Terminate one level in HTML export."
3988 (if (<= level max-outline-level
)
3991 (insert "</ul>\n")))
3993 ;;; iCalendar export
3996 (defun org-export-icalendar-this-file ()
3997 "Export current file as an iCalendar file.
3998 The iCalendar file will be located in the same directory as the Org-mode
3999 file, but with extension `.ics'."
4001 (org-export-icalendar nil buffer-file-name
))
4004 (defun org-export-icalendar-all-agenda-files ()
4005 "Export all files in `org-agenda-files' to iCalendar .ics files.
4006 Each iCalendar file will be located in the same directory as the Org-mode
4007 file, but with extension `.ics'."
4009 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4012 (defun org-export-icalendar-combine-agenda-files ()
4013 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4014 The file is stored under the name `org-combined-agenda-icalendar-file'."
4016 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4018 (defun org-export-icalendar (combine &rest files
)
4019 "Create iCalendar files for all elements of FILES.
4020 If COMBINE is non-nil, combine all calendar entries into a single large
4021 file and store it under the name `org-combined-agenda-icalendar-file'."
4023 (org-prepare-agenda-buffers files
)
4024 (let* ((dir (org-export-directory
4025 :ical
(list :publishing-directory
4026 org-export-publishing-directory
)))
4027 file ical-file ical-buffer category started org-agenda-new-buffers
)
4028 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4031 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4032 org-combined-agenda-icalendar-file
4033 (expand-file-name org-combined-agenda-icalendar-file dir
))
4034 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4035 (set-buffer ical-buffer
) (erase-buffer))
4036 (while (setq file
(pop files
))
4038 (org-check-agenda-file file
)
4039 (set-buffer (org-get-agenda-file-buffer file
))
4041 (setq ical-file
(concat (file-name-as-directory dir
)
4042 (file-name-sans-extension
4043 (file-name-nondirectory buffer-file-name
))
4045 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4046 (with-current-buffer ical-buffer
(erase-buffer)))
4047 (setq category
(or org-category
4048 (file-name-sans-extension
4049 (file-name-nondirectory buffer-file-name
))))
4050 (if (symbolp category
) (setq category
(symbol-name category
)))
4051 (let ((standard-output ical-buffer
))
4053 (and (not started
) (setq started t
)
4054 (org-start-icalendar-file org-icalendar-combined-name
))
4055 (org-start-icalendar-file category
))
4056 (org-print-icalendar-entries combine
)
4057 (when (or (and combine
(not files
)) (not combine
))
4058 (org-finish-icalendar-file)
4059 (set-buffer ical-buffer
)
4060 (run-hooks 'org-before-save-iCalendar-file-hook
)
4062 (run-hooks 'org-after-save-iCalendar-file-hook
)
4063 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4065 (org-release-buffers org-agenda-new-buffers
))))
4067 (defvar org-before-save-iCalendar-file-hook nil
4068 "Hook run before an iCalendar file has been saved.
4069 This can be used to modify the result of the export.")
4071 (defvar org-after-save-iCalendar-file-hook nil
4072 "Hook run after an iCalendar file has been saved.
4073 The iCalendar buffer is still current when this hook is run.
4074 A good way to use this is to tell a desktop calenndar application to re-read
4075 the iCalendar file.")
4077 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4078 (defun org-print-icalendar-entries (&optional combine
)
4079 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4080 When COMBINE is non nil, add the category to each line."
4081 (require 'org-agenda
)
4082 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4083 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4084 (dts (org-ical-ts-to-string
4085 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4087 hd ts ts2 state status
(inc t
) pos b sexp rrule
4088 scheduledp deadlinep todo prefix due start
4089 tmp pri category entry location summary desc uid
4090 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4091 (org-refresh-category-properties)
4093 (goto-char (point-min))
4094 (while (re-search-forward re1 nil t
)
4097 (when (boundp 'org-icalendar-verify-function
)
4098 (unless (funcall org-icalendar-verify-function
)
4099 (outline-next-heading)
4102 (setq pos
(match-beginning 0)
4105 hd
(condition-case nil
4106 (org-icalendar-cleanup-string
4108 (error (throw :skip nil
)))
4109 summary
(org-icalendar-cleanup-string
4110 (org-entry-get nil
"SUMMARY"))
4111 desc
(org-icalendar-cleanup-string
4112 (or (org-entry-get nil
"DESCRIPTION")
4113 (and org-icalendar-include-body
(org-get-entry)))
4114 t org-icalendar-include-body
)
4115 location
(org-icalendar-cleanup-string
4116 (org-entry-get nil
"LOCATION"))
4117 uid
(if org-icalendar-store-UID
4119 (or (org-id-get) (org-id-new)))
4120 category
(org-get-category)
4121 deadlinep nil scheduledp nil
)
4122 (if (looking-at re2
)
4124 (goto-char (match-end 0))
4125 (setq ts2
(match-string 1)
4126 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4127 (setq tmp
(buffer-substring (max (point-min)
4128 (- pos org-ds-keyword-length
))
4130 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4133 (replace-match "\\1" t nil ts
))
4135 deadlinep
(string-match org-deadline-regexp tmp
)
4136 scheduledp
(string-match org-scheduled-regexp tmp
)
4137 todo
(org-get-todo-state)
4138 ;; donep (org-entry-is-done-p)
4143 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4144 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4149 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4150 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4152 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4153 (if (or (string-match org-tr-regexp hd
)
4154 (string-match org-ts-regexp hd
))
4155 (setq hd
(replace-match "" t t hd
)))
4156 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4158 (concat "\nRRULE:FREQ="
4161 '(("d" .
"DAILY")("w" .
"WEEKLY")
4162 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4163 ";INTERVAL=" (match-string 1 ts
)))
4165 (setq summary
(or summary hd
))
4166 (if (string-match org-bracket-link-regexp summary
)
4168 (replace-match (if (match-end 3)
4169 (match-string 3 summary
)
4170 (match-string 1 summary
))
4172 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4173 (if scheduledp
(setq summary
(concat "S: " summary
)))
4174 (if (string-match "\\`<%%" ts
)
4175 (with-current-buffer sexp-buffer
4176 (insert (substring ts
1 -
1) " " summary
"\n"))
4177 (princ (format "BEGIN:VEVENT
4185 (org-ical-ts-to-string ts
"DTSTART")
4186 (org-ical-ts-to-string ts2
"DTEND" inc
)
4188 (if (and desc
(string-match "\\S-" desc
))
4189 (concat "\nDESCRIPTION: " desc
) "")
4190 (if (and location
(string-match "\\S-" location
))
4191 (concat "\nLOCATION: " location
) "")
4193 (when (and org-icalendar-include-sexps
4194 (condition-case nil
(require 'icalendar
) (error nil
))
4195 (fboundp 'icalendar-export-region
))
4196 ;; Get all the literal sexps
4197 (goto-char (point-min))
4198 (while (re-search-forward "^&?%%(" nil t
)
4201 (setq b
(match-beginning 0))
4202 (goto-char (1- (match-end 0)))
4205 (setq sexp
(buffer-substring b
(point)))
4206 (with-current-buffer sexp-buffer
4207 (insert sexp
"\n"))))
4208 (princ (org-diary-to-ical-string sexp-buffer
))
4209 (kill-buffer sexp-buffer
))
4211 (when org-icalendar-include-todo
4212 (setq prefix
"TODO-")
4213 (goto-char (point-min))
4214 (while (re-search-forward org-todo-line-regexp nil t
)
4217 (when (boundp 'org-icalendar-verify-function
)
4218 (unless (funcall org-icalendar-verify-function
)
4219 (outline-next-heading)
4222 (setq state
(match-string 2))
4223 (setq status
(if (member state org-done-keywords
)
4224 "COMPLETED" "NEEDS-ACTION"))
4226 (or (not (member state org-done-keywords
))
4227 (eq org-icalendar-include-todo
'all
))
4228 (not (member org-archive-tag
(org-get-tags-at)))
4230 (setq hd
(match-string 3)
4231 summary
(org-icalendar-cleanup-string
4232 (org-entry-get nil
"SUMMARY"))
4233 desc
(org-icalendar-cleanup-string
4234 (or (org-entry-get nil
"DESCRIPTION")
4235 (and org-icalendar-include-body
(org-get-entry)))
4236 t org-icalendar-include-body
)
4237 location
(org-icalendar-cleanup-string
4238 (org-entry-get nil
"LOCATION"))
4239 due
(and (member 'todo-due org-icalendar-use-deadline
)
4240 (org-entry-get nil
"DEADLINE"))
4241 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4242 (org-entry-get nil
"SCHEDULED"))
4243 uid
(if org-icalendar-store-UID
4245 (or (org-id-get) (org-id-new))))
4246 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4247 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4249 (if (string-match org-bracket-link-regexp hd
)
4250 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4251 (match-string 1 hd
))
4253 (if (string-match org-priority-regexp hd
)
4254 (setq pri
(string-to-char (match-string 2 hd
))
4255 hd
(concat (substring hd
0 (match-beginning 1))
4256 (substring hd
(match-end 1))))
4257 (setq pri org-default-priority
))
4258 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
4259 (- org-lowest-priority org-highest-priority
))))))
4261 (princ (format "BEGIN:VTODO
4273 (if (and location
(string-match "\\S-" location
))
4274 (concat "\nLOCATION: " location
) "")
4275 (if (and desc
(string-match "\\S-" desc
))
4276 (concat "\nDESCRIPTION: " desc
) "")
4277 (if due
(concat "\n" due
) "")
4281 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4282 "Take out stuff and quote what needs to be quoted.
4283 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4284 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4289 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4290 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4291 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4292 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4294 (while (string-match "\\([,;]\\)" s start
)
4295 (setq start
(+ (match-beginning 0) 2)
4296 s
(replace-match "\\\\\\1" nil nil s
))))
4298 (while (string-match "[ \t]*\n[ \t]*" s
)
4299 (setq s
(replace-match "\\n" t t s
))))
4300 (setq s
(org-trim s
))
4303 (if (and (numberp maxlength
)
4304 (> (length s
) maxlength
))
4305 (setq s
(substring s
0 maxlength
)))))
4308 (defun org-get-entry ()
4309 "Clean-up description string."
4311 (org-back-to-heading t
)
4312 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4314 (defun org-start-icalendar-file (name)
4315 "Start an iCalendar file by inserting the header."
4316 (let ((user user-full-name
)
4317 (name (or name
"unknown"))
4318 (timezone (cadr (current-time-zone))))
4320 (format "BEGIN:VCALENDAR
4323 PRODID:-//%s//Emacs with Org-mode//EN
4325 CALSCALE:GREGORIAN\n" name user timezone
))))
4327 (defun org-finish-icalendar-file ()
4328 "Finish an iCalendar file by inserting the END statement."
4329 (princ "END:VCALENDAR\n"))
4331 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4332 "Take a time string S and convert it to iCalendar format.
4333 KEYWORD is added in front, to make a complete line like DTSTART....
4334 When INC is non-nil, increase the hour by two (if time string contains
4335 a time), or the day by one (if it does not contain a time)."
4336 (let ((t1 (org-parse-time-string s
'nodefault
))
4337 t2 fmt have-time time
)
4338 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4339 (setq t2 t1 have-time t
)
4340 (setq t2
(org-parse-time-string s
)))
4341 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4342 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4345 (if org-agenda-default-appointment-duration
4346 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4349 (setq time
(encode-time s mi h d m y
)))
4350 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4351 (concat keyword
(format-time-string fmt time
))))
4355 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4356 (with-current-buffer buffer
4357 (apply 'insert output
)))
4358 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4361 (defun org-export-as-xoxo (&optional buffer
)
4362 "Export the org buffer as XOXO.
4363 The XOXO buffer is named *xoxo-<source buffer name>*"
4364 (interactive (list (current-buffer)))
4365 ;; A quickie abstraction
4367 ;; Output everything as XOXO
4368 (with-current-buffer (get-buffer buffer
)
4369 (let* ((pos (point))
4370 (opt-plist (org-combine-plists (org-default-export-plist)
4371 (org-infile-export-plist)))
4372 (filename (concat (file-name-as-directory
4373 (org-export-directory :xoxo opt-plist
))
4374 (file-name-sans-extension
4375 (file-name-nondirectory buffer-file-name
))
4377 (out (find-file-noselect filename
))
4380 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4381 ;; Check the output buffer is empty.
4382 (with-current-buffer out
(erase-buffer))
4383 ;; Kick off the output
4384 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4385 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4386 (let* ((hd (match-string-no-properties 1))
4389 (match-string-no-properties 2)
4391 (goto-char (match-end 0))
4396 (if (looking-at "^[ \t]\\(.*\\)")
4397 (setq str
(concat str
(match-string-no-properties 1)))
4398 (throw 'loop str
)))))))))
4400 ;; Handle level rendering
4402 ((> level last-level
)
4403 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4405 ((< level last-level
)
4406 (dotimes (- (- last-level level
) 1)
4408 (org-export-as-xoxo-insert-into out
"</li>\n"))
4409 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4411 (org-export-as-xoxo-insert-into out
"</li>\n")
4412 (setq hanging-li nil
)))
4414 ((equal level last-level
)
4416 (org-export-as-xoxo-insert-into out
"</li>\n")))
4419 (setq last-level level
)
4421 ;; And output the new li
4422 (setq hanging-li
't
)
4423 (if (equal ?
+ (elt text
0))
4424 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4425 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4427 ;; Finally finish off the ol
4428 (dotimes (- last-level
1)
4430 (org-export-as-xoxo-insert-into out
"</li>\n"))
4431 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4434 ;; Finish the buffer off and clean it up.
4435 (switch-to-buffer-other-window out
)
4436 (indent-region (point-min) (point-max) nil
)
4438 (goto-char (point-min))
4443 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4445 ;;; org-exp.el ends here