Fix bug with removing ical buffer too early.
[org-mode.git] / lisp / org-exp.el
blobd607f88cfe5d84b0074cb390dc4473bb6bdeb22d
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
8 ;; Version: 6.04c
9 ;;
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
29 (require 'org-agenda)
30 (eval-and-compile
31 (require 'cl))
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."
41 :tag "Org Export"
42 :group 'org)
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag "Org Export General"
47 :group 'org-export)
49 ;; FIXME
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
65 :type 'boolean)
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:
71 Org HTML LaTeX
72 -----+----------+--------
73 \\- &shy; \\-
74 -- &ndash; --
75 --- &mdash; ---
76 ... &hellip; \ldots
78 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
79 :group 'org-export-translation
80 :type 'boolean)
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
99 :type '(repeat
100 (list
101 (string :tag "HTML language tag")
102 (string :tag "Author")
103 (string :tag "Date")
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
110 :type 'string)
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
116 :type 'boolean)
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
122 this setting.
124 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
125 :group 'org-export-general
126 :type 'number)
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
133 :type 'boolean)
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
142 added.
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
146 section number."
147 :group 'org-export-general
148 :type '(cons
149 (repeat
150 (list
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\"
170 or \"toc:3\"."
171 :group 'org-export-general
172 :type '(choice
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
180 :type 'boolean)
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
189 :type 'boolean)
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
198 :group 'org-archive
199 :type '(choice
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
210 :type 'boolean)
212 (defcustom org-export-time-stamp-file t
213 "Non-nil means, insert a time stamp into the exported file.
214 The time stamp shows when the file was created.
216 This option can also be set with the +OPTIONS line,
217 e.g. \"timestamp:nil\"."
218 :group 'org-export-general
219 :type 'boolean)
221 (defcustom org-export-with-timestamps t
222 "If nil, do not export time stamps and associated keywords."
223 :group 'org-export-general
224 :type 'boolean)
226 (defcustom org-export-remove-timestamps-from-toc t
227 "If nil, remove timestamps from the table of contents entries."
228 :group 'org-export-general
229 :type 'boolean)
231 (defcustom org-export-with-tags 'not-in-toc
232 "If nil, do not export tags, just remove them from headlines.
233 If this is the symbol `not-in-toc', tags will be removed from table of
234 contents entries, but still be shown in the headlines of the document.
236 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
237 :group 'org-export-general
238 :type '(choice
239 (const :tag "Off" nil)
240 (const :tag "Not in TOC" not-in-toc)
241 (const :tag "On" t)))
243 (defcustom org-export-with-drawers nil
244 "Non-nil means, export with drawers like the property drawer.
245 When t, all drawers are exported. This may also be a list of
246 drawer names to export."
247 :group 'org-export-general
248 :type '(choice
249 (const :tag "All drawers" t)
250 (const :tag "None" nil)
251 (repeat :tag "Selected drawers"
252 (string :tag "Drawer name"))))
254 (defvar org-export-preprocess-hook nil
255 "Hook for preprocessing an export buffer.
256 Pretty much the first thing when exporting is running this hook.")
258 (defgroup org-export-translation nil
259 "Options for translating special ascii sequences for the export backends."
260 :tag "Org Export Translation"
261 :group 'org-export)
263 (defcustom org-export-with-emphasize t
264 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
265 If the export target supports emphasizing text, the word will be
266 typeset in bold, italic, or underlined, respectively. Works only for
267 single words, but you can say: I *really* *mean* *this*.
268 Not all export backends support this.
270 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
271 :group 'org-export-translation
272 :type 'boolean)
274 (defcustom org-export-with-footnotes t
275 "If nil, export [1] as a footnote marker.
276 Lines starting with [1] will be formatted as footnotes.
278 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
279 :group 'org-export-translation
280 :type 'boolean)
282 (defcustom org-export-with-sub-superscripts t
283 "Non-nil means, interpret \"_\" and \"^\" for export.
284 When this option is turned on, you can use TeX-like syntax for sub- and
285 superscripts. Several characters after \"_\" or \"^\" will be
286 considered as a single item - so grouping with {} is normally not
287 needed. For example, the following things will be parsed as single
288 sub- or superscripts.
290 10^24 or 10^tau several digits will be considered 1 item.
291 10^-12 or 10^-tau a leading sign with digits or a word
292 x^2-y^3 will be read as x^2 - y^3, because items are
293 terminated by almost any nonword/nondigit char.
294 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
296 Still, ambiguity is possible - so when in doubt use {} to enclose the
297 sub/superscript. If you set this variable to the symbol `{}',
298 the braces are *required* in order to trigger interpretations as
299 sub/superscript. This can be helpful in documents that need \"_\"
300 frequently in plain text.
302 Not all export backends support this, but HTML does.
304 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
305 :group 'org-export-translation
306 :type '(choice
307 (const :tag "Always interpret" t)
308 (const :tag "Only with braces" {})
309 (const :tag "Never interpret" nil)))
311 (defcustom org-export-with-special-strings t
312 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
313 When this option is turned on, these strings will be exported as:
315 \\- : &shy;
316 -- : &ndash;
317 --- : &mdash;
319 Not all export backends support this, but HTML does.
321 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
322 :group 'org-export-translation
323 :type 'boolean)
325 (defcustom org-export-with-TeX-macros t
326 "Non-nil means, interpret simple TeX-like macros when exporting.
327 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
328 No only real TeX macros will work here, but the standard HTML entities
329 for math can be used as macro names as well. For a list of supported
330 names in HTML export, see the constant `org-html-entities'.
331 Not all export backends support this.
333 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
334 :group 'org-export-translation
335 :group 'org-export-latex
336 :type 'boolean)
338 (defcustom org-export-with-LaTeX-fragments nil
339 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
340 When set, the exporter will find LaTeX environments if the \\begin line is
341 the first non-white thing on a line. It will also find the math delimiters
342 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
343 display math.
345 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
346 :group 'org-export-translation
347 :group 'org-export-latex
348 :type 'boolean)
350 (defcustom org-export-with-fixed-width t
351 "Non-nil means, lines starting with \":\" will be in fixed width font.
352 This can be used to have pre-formatted text, fragments of code etc. For
353 example:
354 : ;; Some Lisp examples
355 : (while (defc cnt)
356 : (ding))
357 will be looking just like this in also HTML. See also the QUOTE keyword.
358 Not all export backends support this.
360 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
361 :group 'org-export-translation
362 :type 'boolean)
364 (defcustom org-match-sexp-depth 3
365 "Number of stacked braces for sub/superscript matching.
366 This has to be set before loading org.el to be effective."
367 :group 'org-export-translation
368 :type 'integer)
370 (defgroup org-export-tables nil
371 "Options for exporting tables in Org-mode."
372 :tag "Org Export Tables"
373 :group 'org-export)
375 (defcustom org-export-with-tables t
376 "If non-nil, lines starting with \"|\" define a table.
377 For example:
379 | Name | Address | Birthday |
380 |-------------+----------+-----------|
381 | Arthur Dent | England | 29.2.2100 |
383 Not all export backends support this.
385 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
386 :group 'org-export-tables
387 :type 'boolean)
389 (defcustom org-export-highlight-first-table-line t
390 "Non-nil means, highlight the first table line.
391 In HTML export, this means use <th> instead of <td>.
392 In tables created with table.el, this applies to the first table line.
393 In Org-mode tables, all lines before the first horizontal separator
394 line will be formatted with <th> tags."
395 :group 'org-export-tables
396 :type 'boolean)
398 (defcustom org-export-table-remove-special-lines t
399 "Remove special lines and marking characters in calculating tables.
400 This removes the special marking character column from tables that are set
401 up for spreadsheet calculations. It also removes the entire lines
402 marked with `!', `_', or `^'. The lines with `$' are kept, because
403 the values of constants may be useful to have."
404 :group 'org-export-tables
405 :type 'boolean)
407 (defcustom org-export-prefer-native-exporter-for-tables nil
408 "Non-nil means, always export tables created with table.el natively.
409 Natively means, use the HTML code generator in table.el.
410 When nil, Org-mode's own HTML generator is used when possible (i.e. if
411 the table does not use row- or column-spanning). This has the
412 advantage, that the automatic HTML conversions for math symbols and
413 sub/superscripts can be applied. Org-mode's HTML generator is also
414 much faster."
415 :group 'org-export-tables
416 :type 'boolean)
418 (defgroup org-export-ascii nil
419 "Options specific for ASCII export of Org-mode files."
420 :tag "Org Export ASCII"
421 :group 'org-export)
423 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
424 "Characters for underlining headings in ASCII export.
425 In the given sequence, these characters will be used for level 1, 2, ..."
426 :group 'org-export-ascii
427 :type '(repeat character))
429 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
430 "Bullet characters for headlines converted to lists in ASCII export.
431 The first character is used for the first lest level generated in this
432 way, and so on. If there are more levels than characters given here,
433 the list will be repeated.
434 Note that plain lists will keep the same bullets as the have in the
435 Org-mode file."
436 :group 'org-export-ascii
437 :type '(repeat character))
439 (defgroup org-export-xml nil
440 "Options specific for XML export of Org-mode files."
441 :tag "Org Export XML"
442 :group 'org-export)
444 (defgroup org-export-html nil
445 "Options specific for HTML export of Org-mode files."
446 :tag "Org Export HTML"
447 :group 'org-export)
449 (defcustom org-export-html-coding-system nil
450 "Coding system for HTML export, defaults to buffer-file-coding-system."
451 :group 'org-export-html
452 :type 'coding-system)
454 (defcustom org-export-html-extension "html"
455 "The extension for exported HTML files."
456 :group 'org-export-html
457 :type 'string)
459 (defcustom org-export-html-link-up ""
460 "Where should the \"UP\" link of exported HTML pages lead?"
461 :group 'org-export-html
462 :type '(string :tag "File or URL"))
464 (defcustom org-export-html-link-home ""
465 "Where should the \"HOME\" link of exported HTML pages lead?"
466 :group 'org-export-html
467 :type '(string :tag "File or URL"))
469 (defcustom org-export-html-style
470 "<style type=\"text/css\">
471 html {
472 font-family: Times, serif;
473 font-size: 12pt;
475 .title { text-align: center; }
476 .todo { color: red; }
477 .done { color: green; }
478 .timestamp { color: grey }
479 .timestamp-kwd { color: CadetBlue }
480 .tag { background-color:lightblue; font-weight:normal }
481 .target { }
482 pre {
483 border: 1pt solid #AEBDCC;
484 background-color: #F3F5F7;
485 padding: 5pt;
486 font-family: courier, monospace;
487 font-size: 90%;
489 table { border-collapse: collapse; }
490 td, th {
491 vertical-align: top;
492 <!--border: 1pt solid #ADB9CC;-->
494 dt { font-weight: bold; }
495 </style>"
496 "The default style specification for exported HTML files.
497 Since there are different ways of setting style information, this variable
498 needs to contain the full HTML structure to provide a style, including the
499 surrounding HTML tags. The style specifications should include definitions
500 for new classes todo, done, title, and deadline. For example, valid values
501 would be:
503 <style type=\"text/css\">
504 p { font-weight: normal; color: gray; }
505 h1 { color: black; }
506 .title { text-align: center; }
507 .todo, .deadline { color: red; }
508 .done { color: green; }
509 </style>
511 or, if you want to keep the style in a file,
513 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
515 As the value of this option simply gets inserted into the HTML <head> header,
516 you can \"misuse\" it to add arbitrary text to the header."
517 :group 'org-export-html
518 :type 'string)
521 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
522 "Format for typesetting the document title in HTML export."
523 :group 'org-export-html
524 :type 'string)
526 (defcustom org-export-html-toplevel-hlevel 2
527 "The <H> level for level 1 headings in HTML export."
528 :group 'org-export-html
529 :type 'string)
531 (defcustom org-export-html-link-org-files-as-html t
532 "Non-nil means, make file links to `file.org' point to `file.html'.
533 When org-mode is exporting an org-mode file to HTML, links to
534 non-html files are directly put into a href tag in HTML.
535 However, links to other Org-mode files (recognized by the
536 extension `.org.) should become links to the corresponding html
537 file, assuming that the linked org-mode file will also be
538 converted to HTML.
539 When nil, the links still point to the plain `.org' file."
540 :group 'org-export-html
541 :type 'boolean)
543 (defcustom org-export-html-inline-images 'maybe
544 "Non-nil means, inline images into exported HTML pages.
545 This is done using an <img> tag. When nil, an anchor with href is used to
546 link to the image. If this option is `maybe', then images in links with
547 an empty description will be inlined, while images with a description will
548 be linked only."
549 :group 'org-export-html
550 :type '(choice (const :tag "Never" nil)
551 (const :tag "Always" t)
552 (const :tag "When there is no description" maybe)))
554 ;; FIXME: rename
555 (defcustom org-export-html-expand t
556 "Non-nil means, for HTML export, treat @<...> as HTML tag.
557 When nil, these tags will be exported as plain text and therefore
558 not be interpreted by a browser.
560 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
561 :group 'org-export-html
562 :type 'boolean)
564 (defcustom org-export-html-table-tag
565 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
566 "The HTML tag that is used to start a table.
567 This must be a <table> tag, but you may change the options like
568 borders and spacing."
569 :group 'org-export-html
570 :type 'string)
572 (defcustom org-export-table-header-tags '("<th>" . "</th>")
573 "The opening tag for table header fields.
574 This is customizable so that alignment options can be specified."
575 :group 'org-export-tables
576 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
578 (defcustom org-export-table-data-tags '("<td>" . "</td>")
579 "The opening tag for table data fields.
580 This is customizable so that alignment options can be specified."
581 :group 'org-export-tables
582 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
584 (defcustom org-export-html-with-timestamp nil
585 "If non-nil, write `org-export-html-html-helper-timestamp'
586 into the exported HTML text. Otherwise, the buffer will just be saved
587 to a file."
588 :group 'org-export-html
589 :type 'boolean)
591 (defcustom org-export-html-html-helper-timestamp
592 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
593 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
594 :group 'org-export-html
595 :type 'string)
597 (defgroup org-export-htmlize nil
598 "Options for processing examples with htmlize.el."
599 :tag "Org Export Htmlize"
600 :group 'org-export-html)
602 (defcustom org-export-htmlize-output-type 'inline-css
603 "Output type to be used by htmlize when formatting code snippets.
604 Normally this is `inline-css', but if you have defined to appropriate
605 classes in your css style file, setting this to `css' means that the
606 fontification will use the class names.
607 See also the function `org-export-htmlize-generate-css'."
608 :group 'org-export-htmlize
609 :type '(choice (const css) (const inline-css)))
611 (defcustom org-export-htmlize-css-font-prefix "org-"
612 "The prefix for CSS class names for htmlize font specifications."
613 :group 'org-export-htmlize
614 :type 'string)
616 (defgroup org-export-icalendar nil
617 "Options specific for iCalendar export of Org-mode files."
618 :tag "Org Export iCalendar"
619 :group 'org-export)
621 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
622 "The file name for the iCalendar file covering all agenda files.
623 This file is created with the command \\[org-export-icalendar-all-agenda-files].
624 The file name should be absolute, the file will be overwritten without warning."
625 :group 'org-export-icalendar
626 :type 'file)
628 (defcustom org-icalendar-include-todo nil
629 "Non-nil means, export to iCalendar files should also cover TODO items."
630 :group 'org-export-icalendar
631 :type '(choice
632 (const :tag "None" nil)
633 (const :tag "Unfinished" t)
634 (const :tag "All" all)))
636 (defcustom org-icalendar-include-sexps t
637 "Non-nil means, export to iCalendar files should also cover sexp entries.
638 These are entries like in the diary, but directly in an Org-mode file."
639 :group 'org-export-icalendar
640 :type 'boolean)
642 (defcustom org-icalendar-include-body 100
643 "Amount of text below headline to be included in iCalendar export.
644 This is a number of characters that should maximally be included.
645 Properties, scheduling and clocking lines will always be removed.
646 The text will be inserted into the DESCRIPTION field."
647 :group 'org-export-icalendar
648 :type '(choice
649 (const :tag "Nothing" nil)
650 (const :tag "Everything" t)
651 (integer :tag "Max characters")))
653 (defcustom org-icalendar-combined-name "OrgMode"
654 "Calendar name for the combined iCalendar representing all agenda files."
655 :group 'org-export-icalendar
656 :type 'string)
658 (defcustom org-icalendar-store-UID nil
659 "Non-nil means, store any created UIDs in properties.
660 The iCalendar standard requires that all entries have a unique identifyer.
661 Org will create these identifiers as needed. When this variable is non-nil,
662 the created UIDs will be stored in the ID property of the entry. Then the
663 next time this entry is exported, it will be exported with the same UID,
664 superceeding the previous form of it. This is essential for
665 synchronization services.
666 This variable is not turned on by default because we want to avoid creating
667 a property drawer in every entry if people are only playing with this feature,
668 or if they are only using it locally."
669 :group 'org-export-icalendar
670 :type 'boolean)
672 ;;;; Exporting
674 ;;; Variables, constants, and parameter plists
676 (defconst org-level-max 20)
678 (defvar org-export-html-preamble nil
679 "Preamble, to be inserted just after <body>. Set by publishing functions.")
680 (defvar org-export-html-postamble nil
681 "Preamble, to be inserted just before </body>. Set by publishing functions.")
682 (defvar org-export-html-auto-preamble t
683 "Should default preamble be inserted? Set by publishing functions.")
684 (defvar org-export-html-auto-postamble t
685 "Should default postamble be inserted? Set by publishing functions.")
686 (defvar org-current-export-file nil) ; dynamically scoped parameter
687 (defvar org-current-export-dir nil) ; dynamically scoped parameter
689 (defconst org-export-plist-vars
690 '((:link-up . org-export-html-link-up)
691 (:link-home . org-export-html-link-home)
692 (:language . org-export-default-language)
693 (:customtime . org-display-custom-times)
694 (:headline-levels . org-export-headline-levels)
695 (:section-numbers . org-export-with-section-numbers)
696 (:section-number-format . org-export-section-number-format)
697 (:table-of-contents . org-export-with-toc)
698 (:preserve-breaks . org-export-preserve-breaks)
699 (:archived-trees . org-export-with-archived-trees)
700 (:emphasize . org-export-with-emphasize)
701 (:sub-superscript . org-export-with-sub-superscripts)
702 (:special-strings . org-export-with-special-strings)
703 (:footnotes . org-export-with-footnotes)
704 (:drawers . org-export-with-drawers)
705 (:tags . org-export-with-tags)
706 (:TeX-macros . org-export-with-TeX-macros)
707 (:LaTeX-fragments . org-export-with-LaTeX-fragments)
708 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
709 (:fixed-width . org-export-with-fixed-width)
710 (:timestamps . org-export-with-timestamps)
711 (:author-info . org-export-author-info)
712 (:time-stamp-file . org-export-time-stamp-file)
713 (:tables . org-export-with-tables)
714 (:table-auto-headline . org-export-highlight-first-table-line)
715 (:style . org-export-html-style)
716 (:agenda-style . org-agenda-export-html-style)
717 (:convert-org-links . org-export-html-link-org-files-as-html)
718 (:inline-images . org-export-html-inline-images)
719 (:html-extension . org-export-html-extension)
720 (:html-table-tag . org-export-html-table-tag)
721 (:expand-quoted-html . org-export-html-expand)
722 (:timestamp . org-export-html-with-timestamp)
723 (:publishing-directory . org-export-publishing-directory)
724 (:preamble . org-export-html-preamble)
725 (:postamble . org-export-html-postamble)
726 (:auto-preamble . org-export-html-auto-preamble)
727 (:auto-postamble . org-export-html-auto-postamble)
728 (:author . user-full-name)
729 (:email . user-mail-address)))
731 (defun org-default-export-plist ()
732 "Return the property list with default settings for the export variables."
733 (let ((l org-export-plist-vars) rtn e)
734 (while (setq e (pop l))
735 (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
736 rtn))
738 (defvar org-export-inbuffer-options-extra nil
739 "List of additional in-buffer options that should be detected.
740 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
741 etc. Extensions can add to this list to get their options detected, and they
742 can then add a function to `org-export-options-filters' to process these
743 options.
744 Each element in this list must be a list, with the in-buffer keyword as car,
745 and a property (a symbol) as the next element. All occurences of the
746 keyword will be found, the values concatenated with a space character
747 in between, and the result stored in the export options property list.")
749 (defvar org-export-options-filters nil
750 "Functions to be called to finalize the export/publishing options.
751 All these options are stored in a property list, and each of the functions
752 in this hook gets a chance to modify this property list. Each function
753 must accept the property list as an argument, and must return the (possibly
754 modified) list.")
756 (defun org-infile-export-plist ()
757 "Return the property list with file-local settings for export."
758 (save-excursion
759 (save-restriction
760 (widen)
761 (goto-char (point-min))
762 (let ((re (org-make-options-regexp
763 (append
764 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
765 "LINK_UP" "LINK_HOME" "SETUPFILE")
766 (mapcar 'car org-export-inbuffer-options-extra))))
767 p key val text options js-up js-main js-css js-opt a pr
768 ext-setup-or-nil setup-contents (start 0))
769 (while (or (and ext-setup-or-nil
770 (string-match re ext-setup-or-nil start)
771 (setq start (match-end 0)))
772 (and (setq ext-setup-or-nil nil start 0)
773 (re-search-forward re nil t)))
774 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
775 val (org-match-string-no-properties 2 ext-setup-or-nil))
776 (cond
777 ((setq a (assoc key org-export-inbuffer-options-extra))
778 (setq pr (nth 1 a))
779 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
780 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
781 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
782 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
783 ((string-equal key "DATE") (setq p (plist-put p :date val)))
784 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
785 ((string-equal key "TEXT")
786 (setq text (if text (concat text "\n" val) val)))
787 ((string-equal key "OPTIONS")
788 (setq options (concat val " " options)))
789 ((string-equal key "LINK_UP")
790 (setq p (plist-put p :link-up val)))
791 ((string-equal key "LINK_HOME")
792 (setq p (plist-put p :link-home val)))
793 ((equal key "SETUPFILE")
794 (setq setup-contents (org-file-contents
795 (expand-file-name
796 (org-remove-double-quotes
797 (org-trim val)))
798 'noerror))
799 (if (not ext-setup-or-nil)
800 (setq ext-setup-or-nil setup-contents start 0)
801 (setq ext-setup-or-nil
802 (concat (substring ext-setup-or-nil 0 start)
803 "\n" setup-contents "\n"
804 (substring ext-setup-or-nil start)))))))
805 (setq p (plist-put p :text text))
806 (when options
807 (setq p (org-export-add-options-to-plist p options)))
808 p))))
810 (defun org-export-add-options-to-plist (p options)
811 "Parse an OPTONS line and set values in the property list P."
812 (let (o)
813 (when options
814 (let ((op '(("H" . :headline-levels)
815 ("num" . :section-numbers)
816 ("toc" . :table-of-contents)
817 ("\\n" . :preserve-breaks)
818 ("@" . :expand-quoted-html)
819 (":" . :fixed-width)
820 ("|" . :tables)
821 ("^" . :sub-superscript)
822 ("-" . :special-strings)
823 ("f" . :footnotes)
824 ("d" . :drawers)
825 ("tags" . :tags)
826 ("*" . :emphasize)
827 ("TeX" . :TeX-macros)
828 ("LaTeX" . :LaTeX-fragments)
829 ("skip" . :skip-before-1st-heading)
830 ("author" . :author-info)
831 ("timestamp" . :time-stamp-file)))
833 (while (setq o (pop op))
834 (if (string-match (concat (regexp-quote (car o))
835 ":\\([^ \t\n\r;,.]*\\)")
836 options)
837 (setq p (plist-put p (cdr o)
838 (car (read-from-string
839 (match-string 1 options))))))))))
842 (defun org-export-add-subtree-options (p pos)
843 "Add options in subtree at position POS to property list P."
844 (save-excursion
845 (goto-char pos)
846 (when (org-at-heading-p)
847 (let (a)
848 ;; This is actually read in `org-export-get-title-from-subtree'
849 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
850 ;; (setq p (plist-put p :title a)))
851 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
852 (setq p (plist-put p :text a)))
853 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
854 (setq p (org-export-add-options-to-plist p a)))))
857 (defun org-export-directory (type plist)
858 (let* ((val (plist-get plist :publishing-directory))
859 (dir (if (listp val)
860 (or (cdr (assoc type val)) ".")
861 val)))
862 dir))
864 (defun org-export-process-option-filters (plist)
865 (let ((functions org-export-options-filters) f)
866 (while (setq f (pop functions))
867 (setq plist (funcall f plist))))
868 plist)
870 ;;;###autoload
871 (defun org-export (&optional arg)
872 "Export dispatcher for Org-mode.
873 When `org-export-run-in-background' is non-nil, try to run the command
874 in the background. This will be done only for commands that write
875 to a file. For details see the docstring of `org-export-run-in-background'.
877 The prefix argument ARG will be passed to the exporter. However, if
878 ARG is a double universal prefix `C-u C-u', that means to inverse the
879 value of `org-export-run-in-background'."
880 (interactive "P")
881 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
882 (help "[t] insert the export option template
883 \[v] limit export to visible part of outline tree
885 \[a] export as ASCII
887 \[h] export as HTML
888 \[H] export as HTML to temporary buffer
889 \[R] export region as HTML
890 \[b] export as HTML and browse immediately
891 \[x] export as XOXO
893 \[l] export as LaTeX
894 \[L] export as LaTeX to temporary buffer
896 \[i] export current file as iCalendar file
897 \[I] export all agenda files as iCalendar files
898 \[c] export agenda files into combined iCalendar file
900 \[F] publish current file
901 \[P] publish current project
902 \[X] publish... (project will be prompted for)
903 \[A] publish all projects")
904 (cmds
905 '((?t org-insert-export-options-template nil)
906 (?v org-export-visible nil)
907 (?a org-export-as-ascii t)
908 (?h org-export-as-html t)
909 (?b org-export-as-html-and-open t)
910 (?H org-export-as-html-to-buffer nil)
911 (?R org-export-region-as-html nil)
912 (?x org-export-as-xoxo t)
913 (?l org-export-as-latex t)
914 (?L org-export-as-latex-to-buffer nil)
915 (?i org-export-icalendar-this-file t)
916 (?I org-export-icalendar-all-agenda-files t)
917 (?c org-export-icalendar-combine-agenda-files t)
918 (?F org-publish-current-file t)
919 (?P org-publish-current-project t)
920 (?X org-publish t)
921 (?A org-publish-all t)))
922 r1 r2 ass)
923 (save-window-excursion
924 (delete-other-windows)
925 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
926 (princ help))
927 (message "Select command: ")
928 (setq r1 (read-char-exclusive)))
929 (setq r2 (if (< r1 27) (+ r1 96) r1))
930 (unless (setq ass (assq r2 cmds))
931 (error "No command associated with key %c" r1))
932 (if (and bg (nth 2 ass))
933 ;; execute in background
934 (let ((p (start-process
935 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
936 "*Org Processes*"
937 (expand-file-name invocation-name invocation-directory)
938 "-batch"
939 "-l" user-init-file
940 "--eval" "(require 'org-exp)"
941 "--eval" "(setq org-wait .2)"
942 (buffer-file-name)
943 "-f" (symbol-name (nth 1 ass)))))
944 (set-process-sentinel p 'org-export-process-sentinel)
945 (message "Background process \"%s\": started" p))
946 ;; background processing not requested, or not possible
947 (call-interactively (nth 1 ass)))))
949 (defun org-export-process-sentinel (process status)
950 (if (string-match "\n+\\'" status)
951 (setq status (substring status 0 -1)))
952 (message "Background process \"%s\": %s" process status))
954 (defconst org-html-entities
955 '(("nbsp")
956 ("iexcl")
957 ("cent")
958 ("pound")
959 ("curren")
960 ("yen")
961 ("brvbar")
962 ("vert" . "&#124;")
963 ("sect")
964 ("uml")
965 ("copy")
966 ("ordf")
967 ("laquo")
968 ("not")
969 ("shy")
970 ("reg")
971 ("macr")
972 ("deg")
973 ("plusmn")
974 ("sup2")
975 ("sup3")
976 ("acute")
977 ("micro")
978 ("para")
979 ("middot")
980 ("odot"."o")
981 ("star"."*")
982 ("cedil")
983 ("sup1")
984 ("ordm")
985 ("raquo")
986 ("frac14")
987 ("frac12")
988 ("frac34")
989 ("iquest")
990 ("Agrave")
991 ("Aacute")
992 ("Acirc")
993 ("Atilde")
994 ("Auml")
995 ("Aring") ("AA"."&Aring;")
996 ("AElig")
997 ("Ccedil")
998 ("Egrave")
999 ("Eacute")
1000 ("Ecirc")
1001 ("Euml")
1002 ("Igrave")
1003 ("Iacute")
1004 ("Icirc")
1005 ("Iuml")
1006 ("ETH")
1007 ("Ntilde")
1008 ("Ograve")
1009 ("Oacute")
1010 ("Ocirc")
1011 ("Otilde")
1012 ("Ouml")
1013 ("times")
1014 ("Oslash")
1015 ("Ugrave")
1016 ("Uacute")
1017 ("Ucirc")
1018 ("Uuml")
1019 ("Yacute")
1020 ("THORN")
1021 ("szlig")
1022 ("agrave")
1023 ("aacute")
1024 ("acirc")
1025 ("atilde")
1026 ("auml")
1027 ("aring")
1028 ("aelig")
1029 ("ccedil")
1030 ("egrave")
1031 ("eacute")
1032 ("ecirc")
1033 ("euml")
1034 ("igrave")
1035 ("iacute")
1036 ("icirc")
1037 ("iuml")
1038 ("eth")
1039 ("ntilde")
1040 ("ograve")
1041 ("oacute")
1042 ("ocirc")
1043 ("otilde")
1044 ("ouml")
1045 ("divide")
1046 ("oslash")
1047 ("ugrave")
1048 ("uacute")
1049 ("ucirc")
1050 ("uuml")
1051 ("yacute")
1052 ("thorn")
1053 ("yuml")
1054 ("fnof")
1055 ("Alpha")
1056 ("Beta")
1057 ("Gamma")
1058 ("Delta")
1059 ("Epsilon")
1060 ("Zeta")
1061 ("Eta")
1062 ("Theta")
1063 ("Iota")
1064 ("Kappa")
1065 ("Lambda")
1066 ("Mu")
1067 ("Nu")
1068 ("Xi")
1069 ("Omicron")
1070 ("Pi")
1071 ("Rho")
1072 ("Sigma")
1073 ("Tau")
1074 ("Upsilon")
1075 ("Phi")
1076 ("Chi")
1077 ("Psi")
1078 ("Omega")
1079 ("alpha")
1080 ("beta")
1081 ("gamma")
1082 ("delta")
1083 ("epsilon")
1084 ("varepsilon"."&epsilon;")
1085 ("zeta")
1086 ("eta")
1087 ("theta")
1088 ("iota")
1089 ("kappa")
1090 ("lambda")
1091 ("mu")
1092 ("nu")
1093 ("xi")
1094 ("omicron")
1095 ("pi")
1096 ("rho")
1097 ("sigmaf") ("varsigma"."&sigmaf;")
1098 ("sigma")
1099 ("tau")
1100 ("upsilon")
1101 ("phi")
1102 ("chi")
1103 ("psi")
1104 ("omega")
1105 ("thetasym") ("vartheta"."&thetasym;")
1106 ("upsih")
1107 ("piv")
1108 ("bull") ("bullet"."&bull;")
1109 ("hellip") ("dots"."&hellip;")
1110 ("prime")
1111 ("Prime")
1112 ("oline")
1113 ("frasl")
1114 ("weierp")
1115 ("image")
1116 ("real")
1117 ("trade")
1118 ("alefsym")
1119 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1120 ("uarr") ("uparrow"."&uarr;")
1121 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1122 ("darr")("downarrow"."&darr;")
1123 ("harr") ("leftrightarrow"."&harr;")
1124 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1125 ("lArr") ("Leftarrow"."&lArr;")
1126 ("uArr") ("Uparrow"."&uArr;")
1127 ("rArr") ("Rightarrow"."&rArr;")
1128 ("dArr") ("Downarrow"."&dArr;")
1129 ("hArr") ("Leftrightarrow"."&hArr;")
1130 ("forall")
1131 ("part") ("partial"."&part;")
1132 ("exist") ("exists"."&exist;")
1133 ("empty") ("emptyset"."&empty;")
1134 ("nabla")
1135 ("isin") ("in"."&isin;")
1136 ("notin")
1137 ("ni")
1138 ("prod")
1139 ("sum")
1140 ("minus")
1141 ("lowast") ("ast"."&lowast;")
1142 ("radic")
1143 ("prop") ("proptp"."&prop;")
1144 ("infin") ("infty"."&infin;")
1145 ("ang") ("angle"."&ang;")
1146 ("and") ("wedge"."&and;")
1147 ("or") ("vee"."&or;")
1148 ("cap")
1149 ("cup")
1150 ("int")
1151 ("there4")
1152 ("sim")
1153 ("cong") ("simeq"."&cong;")
1154 ("asymp")("approx"."&asymp;")
1155 ("ne") ("neq"."&ne;")
1156 ("equiv")
1157 ("le")
1158 ("ge")
1159 ("sub") ("subset"."&sub;")
1160 ("sup") ("supset"."&sup;")
1161 ("nsub")
1162 ("sube")
1163 ("supe")
1164 ("oplus")
1165 ("otimes")
1166 ("perp")
1167 ("sdot") ("cdot"."&sdot;")
1168 ("lceil")
1169 ("rceil")
1170 ("lfloor")
1171 ("rfloor")
1172 ("lang")
1173 ("rang")
1174 ("loz") ("Diamond"."&loz;")
1175 ("spades") ("spadesuit"."&spades;")
1176 ("clubs") ("clubsuit"."&clubs;")
1177 ("hearts") ("diamondsuit"."&hearts;")
1178 ("diams") ("diamondsuit"."&diams;")
1179 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1180 ("quot")
1181 ("amp")
1182 ("lt")
1183 ("gt")
1184 ("OElig")
1185 ("oelig")
1186 ("Scaron")
1187 ("scaron")
1188 ("Yuml")
1189 ("circ")
1190 ("tilde")
1191 ("ensp")
1192 ("emsp")
1193 ("thinsp")
1194 ("zwnj")
1195 ("zwj")
1196 ("lrm")
1197 ("rlm")
1198 ("ndash")
1199 ("mdash")
1200 ("lsquo")
1201 ("rsquo")
1202 ("sbquo")
1203 ("ldquo")
1204 ("rdquo")
1205 ("bdquo")
1206 ("dagger")
1207 ("Dagger")
1208 ("permil")
1209 ("lsaquo")
1210 ("rsaquo")
1211 ("euro")
1213 ("arccos"."arccos")
1214 ("arcsin"."arcsin")
1215 ("arctan"."arctan")
1216 ("arg"."arg")
1217 ("cos"."cos")
1218 ("cosh"."cosh")
1219 ("cot"."cot")
1220 ("coth"."coth")
1221 ("csc"."csc")
1222 ("deg"."deg")
1223 ("det"."det")
1224 ("dim"."dim")
1225 ("exp"."exp")
1226 ("gcd"."gcd")
1227 ("hom"."hom")
1228 ("inf"."inf")
1229 ("ker"."ker")
1230 ("lg"."lg")
1231 ("lim"."lim")
1232 ("liminf"."liminf")
1233 ("limsup"."limsup")
1234 ("ln"."ln")
1235 ("log"."log")
1236 ("max"."max")
1237 ("min"."min")
1238 ("Pr"."Pr")
1239 ("sec"."sec")
1240 ("sin"."sin")
1241 ("sinh"."sinh")
1242 ("sup"."sup")
1243 ("tan"."tan")
1244 ("tanh"."tanh")
1246 "Entities for TeX->HTML translation.
1247 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1248 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1249 In that case, \"\\ent\" will be translated to \"&other;\".
1250 The list contains HTML entities for Latin-1, Greek and other symbols.
1251 It is supplemented by a number of commonly used TeX macros with appropriate
1252 translations. There is currently no way for users to extend this.")
1254 ;;; General functions for all backends
1256 (defun org-export-preprocess-string (string &rest parameters)
1257 "Cleanup STRING so that that the true exported has a more consistent source.
1258 This function takes STRING, which should be a buffer-string of an org-file
1259 to export. It then creates a temporary buffer where it does its job.
1260 The result is then again returned as a string, and the exporter works
1261 on this string to produce the exported version."
1262 (interactive)
1263 (let* ((htmlp (plist-get parameters :for-html))
1264 (asciip (plist-get parameters :for-ascii))
1265 (latexp (plist-get parameters :for-LaTeX))
1266 (archived-trees (plist-get parameters :archived-trees))
1267 (inhibit-read-only t)
1268 (drawers org-drawers)
1269 (outline-regexp "\\*+ ")
1270 target-alist rtn)
1272 (with-current-buffer (get-buffer-create " org-mode-tmp")
1273 (erase-buffer)
1274 (insert string)
1275 (setq case-fold-search t)
1276 ;; Call the hook
1277 (run-hooks 'org-export-preprocess-hook)
1279 ;; Remove license-to-kill stuff
1280 ;; The caller markes some stuff fo killing, stuff that has been
1281 ;; used to create the page title, for example.
1282 (org-export-kill-licensed-text)
1284 (let ((org-inhibit-startup t)) (org-mode))
1285 (setq case-fold-search t)
1286 (untabify (point-min) (point-max))
1288 ;; Handle incude files
1289 (org-export-handle-include-files)
1291 ;; Handle source code snippets
1292 (org-export-replace-src-segments)
1294 ;; Get rid of drawers
1295 (org-export-remove-or-extract-drawers drawers
1296 (plist-get parameters :drawers))
1298 ;; Get the correct stuff before the first headline
1299 (when (plist-get parameters :skip-before-1st-heading)
1300 (goto-char (point-min))
1301 (when (re-search-forward "^\\*+[ \t]" nil t)
1302 (delete-region (point-min) (match-beginning 0))
1303 (goto-char (point-min))
1304 (insert "\n")))
1305 (when (plist-get parameters :add-text)
1306 (goto-char (point-min))
1307 (insert (plist-get parameters :add-text) "\n"))
1309 ;; Get rid of archived trees
1310 (org-export-remove-archived-trees archived-trees)
1312 ;; Find all headings and compute the targets for them
1313 (setq target-alist (org-export-define-heading-targets target-alist))
1315 ;; Find targets in comments and move them out of comments,
1316 ;; but mark them as targets that should be invisible
1317 (setq target-alist (org-export-handle-invisible-targets target-alist))
1319 ;; Protect examples
1320 (org-export-protect-examples)
1322 ;; Protect backend specific stuff, throw away the others.
1323 (org-export-select-backend-specific-text
1324 (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1326 ;; Protect quoted subtrees
1327 (org-export-protect-quoted-subtrees)
1329 ;; Protect verbatim elements
1330 (org-export-protect-verbatim)
1332 ;; Blockquotes and verse
1333 (org-export-mark-blockquote-and-verse)
1335 ;; Remove comment environment and comment subtrees
1336 (org-export-remove-comment-blocks-and-subtrees)
1338 ;; Remove special table lines
1339 (when org-export-table-remove-special-lines
1340 (org-export-remove-special-table-lines))
1342 ;; Specific LaTeX stuff
1343 (when latexp
1344 (require 'org-export-latex nil)
1345 (org-export-latex-preprocess))
1347 ;; Specific ASCII stuff
1348 (when asciip
1349 (org-export-ascii-preprocess))
1351 ;; Specific HTML stuff
1352 (when htmlp
1353 (org-export-html-preprocess parameters))
1355 ;; Remove or replace comments
1356 (org-export-handle-comments (plist-get parameters :comments))
1358 ;; Find matches for radio targets and turn them into internal links
1359 (org-export-mark-radio-links)
1361 ;; Find all links that contain a newline and put them into a single line
1362 (org-export-concatenate-multiline-links)
1364 ;; Find all internal links. If they have a fuzzy match (i.e. not
1365 ;; a *dedicated* target match, let the link point to the
1366 ;; corresponding section.
1367 (org-export-target-internal-links target-alist)
1369 ;; Normalize links: Convert angle and plain links into bracket links
1370 ;; and expand link abbreviations
1371 (org-export-normalize-links)
1373 ;; Find multiline emphasis and put them into single line
1374 (when (plist-get parameters :emph-multiline)
1375 (org-export-concatenate-multiline-emphasis))
1377 (setq rtn (buffer-string)))
1378 (kill-buffer " org-mode-tmp")
1379 rtn))
1381 (defun org-export-kill-licensed-text ()
1382 "Remove all text that is marked with a :org-license-to-kill property."
1383 (let (p)
1384 (while (setq p (text-property-any (point-min) (point-max)
1385 :org-license-to-kill t))
1386 (delete-region p (next-single-property-change p :org-license-to-kill)))))
1388 (defun org-export-define-heading-targets (target-alist)
1389 "Find all headings and define the targets for them.
1390 The new targets are added to TARGET-ALIST, which is also returned."
1391 (goto-char (point-min))
1392 (org-init-section-numbers)
1393 (let ((re (concat "^" org-outline-regexp))
1394 level target)
1395 (while (re-search-forward re nil t)
1396 (setq level (org-reduced-level
1397 (save-excursion (goto-char (point-at-bol))
1398 (org-outline-level))))
1399 (setq target (org-solidify-link-text
1400 (format "sec-%s" (org-section-number level))))
1401 (push (cons target target) target-alist)
1402 (add-text-properties
1403 (point-at-bol) (point-at-eol)
1404 (list 'target target))))
1405 target-alist)
1407 (defun org-export-handle-invisible-targets (target-alist)
1408 "Find targets in comments and move them out of comments.
1409 Mark them as invisible targets."
1410 (let (target tmp)
1411 (goto-char (point-min))
1412 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1413 ;; Check if the line before or after is a headline with a target
1414 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1415 (get-text-property (point-at-bol 2) 'target)))
1416 (progn
1417 ;; use the existing target in a neighboring line
1418 (setq tmp (match-string 2))
1419 (replace-match "")
1420 (and (looking-at "\n") (delete-char 1))
1421 (push (cons (org-solidify-link-text tmp) target)
1422 target-alist))
1423 ;; Make an invisible target
1424 (replace-match "\\1(INVISIBLE)"))))
1425 target-alist)
1427 (defun org-export-target-internal-links (target-alist)
1428 "Find all internal links and assign target to them.
1429 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1430 let the link point to the corresponding section."
1431 (goto-char (point-min))
1432 (while (re-search-forward org-bracket-link-regexp nil t)
1433 (org-if-unprotected
1434 (let* ((md (match-data))
1435 (desc (match-end 2))
1436 (link (org-link-unescape (match-string 1)))
1437 (slink (org-solidify-link-text link))
1438 found props pos
1439 (target
1440 (or (cdr (assoc slink target-alist))
1441 (save-excursion
1442 (unless (string-match org-link-types-re link)
1443 (setq found (condition-case nil (org-link-search link)
1444 (error nil)))
1445 (when (and found
1446 (or (org-on-heading-p)
1447 (not (eq found 'dedicated))))
1448 (or (get-text-property (point) 'target)
1449 (get-text-property
1450 (max (point-min)
1451 (1- (previous-single-property-change
1452 (point) 'target)))
1453 'target))))))))
1454 (when target
1455 (set-match-data md)
1456 (goto-char (match-beginning 1))
1457 (setq props (text-properties-at (point)))
1458 (delete-region (match-beginning 1) (match-end 1))
1459 (setq pos (point))
1460 (insert target)
1461 (unless desc (insert "][" link))
1462 (add-text-properties pos (point) props))))))
1464 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1465 "Remove drawers, or extract the content.
1466 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1467 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1468 whose content to keep."
1469 (unless (eq t exp-drawers)
1470 (goto-char (point-min))
1471 (let ((re (concat "^[ \t]*:\\("
1472 (mapconcat
1473 'identity
1474 (org-delete-all exp-drawers
1475 (copy-sequence all-drawers))
1476 "\\|")
1477 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1478 (while (re-search-forward re nil t)
1479 (replace-match "")))))
1481 (defun org-export-remove-archived-trees (export-archived-trees)
1482 "Remove archived trees.
1483 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1484 When it is t, the entire archived tree will be exported.
1485 When it is nil the entire tree including the headline will be removed
1486 from the buffer."
1487 (let ((re-archive (concat ":" org-archive-tag ":"))
1488 a b)
1489 (when (not (eq export-archived-trees t))
1490 (goto-char (point-min))
1491 (while (re-search-forward re-archive nil t)
1492 (if (not (org-on-heading-p t))
1493 (org-end-of-subtree t)
1494 (beginning-of-line 1)
1495 (setq a (if export-archived-trees
1496 (1+ (point-at-eol)) (point))
1497 b (org-end-of-subtree t))
1498 (if (> b a) (delete-region a b)))))))
1500 (defun org-export-protect-quoted-subtrees ()
1501 "Mark quoted subtrees with the protection property."
1502 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1503 (goto-char (point-min))
1504 (while (re-search-forward re-quote nil t)
1505 (goto-char (match-beginning 0))
1506 (end-of-line 1)
1507 (add-text-properties (point) (org-end-of-subtree t)
1508 '(org-protected t)))))
1510 (defun org-export-protect-verbatim ()
1511 "Mark verbatim snippets with the protection property."
1512 (goto-char (point-min))
1513 (while (re-search-forward org-verbatim-re nil t)
1514 (add-text-properties (match-beginning 4) (match-end 4)
1515 '(org-protected t))
1516 (goto-char (1+ (match-end 4)))))
1518 (defun org-export-protect-examples ()
1519 "Protect code that should be exported as monospaced examples."
1520 (goto-char (point-min))
1521 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1522 (goto-char (match-end 0))
1523 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1524 (insert ": ")
1525 (beginning-of-line 2)))
1526 (goto-char (point-min))
1527 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1528 (add-text-properties (match-beginning 0) (match-end 0)
1529 '(org-protected t))))
1531 (defun org-export-select-backend-specific-text (backend)
1532 (let ((formatters
1533 '((html "HTML" "BEGIN_HTML" "END_HTML")
1534 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1535 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1536 fmt)
1538 (while formatters
1539 (setq fmt (pop formatters))
1540 (when (eq (car fmt) backend)
1541 ;; This is selected code, put it into the file for real
1542 (goto-char (point-min))
1543 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1544 ":[ \t]*\\(.*\\)") nil t)
1545 (replace-match "\\1" t)
1546 (add-text-properties
1547 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1548 '(org-protected t))))
1549 (goto-char (point-min))
1550 (while (re-search-forward
1551 (concat "^#\\+"
1552 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1553 (cadddr fmt) "\\>.*\n?") nil t)
1554 (if (eq (car fmt) backend)
1555 ;; yes, keep this
1556 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1557 '(org-protected t))
1558 ;; No, this is for a different backend, kill it
1559 (delete-region (match-beginning 0) (match-end 0)))))))
1561 (defun org-export-mark-blockquote-and-verse ()
1562 "Mark block quote and verse environments with special cookies.
1563 These special cookies will later be interpreted by the backend."
1564 ;; Blockquotes
1565 (goto-char (point-min))
1566 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1567 nil t)
1568 (replace-match (if (equal (downcase (match-string 1)) "end")
1569 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1570 t t))
1571 ;; Verse
1572 (goto-char (point-min))
1573 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1574 (replace-match (if (equal (downcase (match-string 1)) "end")
1575 "ORG-VERSE-END" "ORG-VERSE-START")
1576 t t)))
1578 (defun org-export-remove-comment-blocks-and-subtrees ()
1579 "Remove the comment environment, and also commented subtrees."
1580 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>")))
1581 ;; Remove comment environment
1582 (goto-char (point-min))
1583 (while (re-search-forward
1584 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1585 (replace-match "" t t))
1586 ;; Remove subtrees that are commented
1587 (goto-char (point-min))
1588 (while (re-search-forward re-commented nil t)
1589 (goto-char (match-beginning 0))
1590 (delete-region (point) (org-end-of-subtree t)))))
1592 (defun org-export-handle-comments (commentsp)
1593 "Remove comments, or convert to backend-specific format.
1594 COMMENTSP can be a format string for publishing comments.
1595 When it is nil, all comments will be removed."
1596 (let ((re "^#\\(.*\n?\\)")
1597 pos)
1598 (goto-char (point-min))
1599 (while (or (looking-at re)
1600 (re-search-forward re nil t))
1601 (setq pos (match-beginning 0))
1602 (if commentsp
1603 (progn (add-text-properties
1604 (match-beginning 0) (match-end 0) '(org-protected t))
1605 (replace-match (format commentsp (match-string 1)) t t))
1606 (goto-char (1+ pos))
1607 (org-if-unprotected
1608 (replace-match "")
1609 (goto-char (max (point-min) (1- pos))))))))
1611 (defun org-export-mark-radio-links ()
1612 "Find all matches for radio targets and turn them into internal links."
1613 (let ((re-radio (and org-target-link-regexp
1614 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1615 (goto-char (point-min))
1616 (when re-radio
1617 (while (re-search-forward re-radio nil t)
1618 (org-if-unprotected
1619 (replace-match "\\1[[\\2]]"))))))
1621 (defun org-export-remove-special-table-lines ()
1622 "Remove tables lines that are used for internal purposes."
1623 (goto-char (point-min))
1624 (while (re-search-forward "^[ \t]*|" nil t)
1625 (beginning-of-line 1)
1626 (if (or (looking-at "[ \t]*| *[!_^] *|")
1627 (and (looking-at ".*?| *<[0-9]+> *|")
1628 (not (looking-at ".*?| *[^ <|]"))))
1629 (delete-region (max (point-min) (1- (point-at-bol)))
1630 (point-at-eol))
1631 (end-of-line 1))))
1633 (defun org-export-normalize-links ()
1634 "Convert all links to bracket links, and expand link abbreviations."
1635 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1636 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1637 (goto-char (point-min))
1638 (while (re-search-forward re-plain-link nil t)
1639 (goto-char (1- (match-end 0)))
1640 (org-if-unprotected
1641 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1642 ":" (match-string 3) "]]")))
1643 ;; added 'org-link face to links
1644 (put-text-property 0 (length s) 'face 'org-link s)
1645 (replace-match s t t))))
1646 (goto-char (point-min))
1647 (while (re-search-forward re-angle-link nil t)
1648 (goto-char (1- (match-end 0)))
1649 (org-if-unprotected
1650 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1651 ":" (match-string 3) "]]")))
1652 (put-text-property 0 (length s) 'face 'org-link s)
1653 (replace-match s t t))))
1654 (goto-char (point-min))
1655 (while (re-search-forward org-bracket-link-regexp nil t)
1656 (org-if-unprotected
1657 (let* ((xx (save-match-data
1658 (org-link-expand-abbrev (match-string 1))))
1659 (s (concat
1660 "[[" xx "]"
1661 (if (match-end 3)
1662 (match-string 2)
1663 (concat "[" xx "]"))
1664 "]")))
1665 (put-text-property 0 (length s) 'face 'org-link s)
1666 (replace-match s t t))))))
1668 (defun org-export-concatenate-multiline-links ()
1669 "Find multi-line links and put it all into a single line.
1670 This is to make sure that the line-processing export backends
1671 can work correctly."
1672 (goto-char (point-min))
1673 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1674 (org-if-unprotected
1675 (replace-match "\\1 \\3")
1676 (goto-char (match-beginning 0)))))
1678 (defun org-export-concatenate-multiline-emphasis ()
1679 "Find multi-line emphasis and put it all into a single line.
1680 This is to make sure that the line-processing export backends
1681 can work correctly."
1682 (goto-char (point-min))
1683 (while (re-search-forward org-emph-re nil t)
1684 (if (not (= (char-after (match-beginning 3))
1685 (char-after (match-beginning 4))))
1686 (org-if-unprotected
1687 (subst-char-in-region (match-beginning 0) (match-end 0)
1688 ?\n ?\ t)
1689 (goto-char (1- (match-end 0))))
1690 (goto-char (1+ (match-beginning 0))))))
1692 (defun org-export-grab-title-from-buffer ()
1693 "Get a title for the current document, from looking at the buffer."
1694 (let ((inhibit-read-only t))
1695 (save-excursion
1696 (goto-char (point-min))
1697 (let ((end (save-excursion (outline-next-heading) (point))))
1698 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1699 ;; Mark the line so that it will not be exported as normal text.
1700 (org-unmodified
1701 (add-text-properties (match-beginning 0) (match-end 0)
1702 (list :org-license-to-kill t)))
1703 ;; Return the title string
1704 (org-trim (match-string 0)))))))
1706 (defun org-export-get-title-from-subtree ()
1707 "Return subtree title and exclude it from export."
1708 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1709 (save-excursion
1710 (goto-char rbeg)
1711 (when (and (org-at-heading-p)
1712 (>= (org-end-of-subtree t t) rend))
1713 ;; This is a subtree, we take the title from the first heading
1714 (goto-char rbeg)
1715 (looking-at org-todo-line-regexp)
1716 (setq title (match-string 3))
1717 (org-unmodified
1718 (add-text-properties (point) (1+ (point-at-eol))
1719 (list :org-license-to-kill t)))
1720 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1721 title))
1723 (defun org-solidify-link-text (s &optional alist)
1724 "Take link text and make a safe target out of it."
1725 (save-match-data
1726 (let* ((rtn
1727 (mapconcat
1728 'identity
1729 (org-split-string s "[ \t\r\n]+") "=="))
1730 (a (assoc rtn alist)))
1731 (or (cdr a) rtn))))
1733 (defun org-get-min-level (lines)
1734 "Get the minimum level in LINES."
1735 (let ((re "^\\(\\*+\\) ") l min)
1736 (catch 'exit
1737 (while (setq l (pop lines))
1738 (if (string-match re l)
1739 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1740 1)))
1742 ;; Variable holding the vector with section numbers
1743 (defvar org-section-numbers (make-vector org-level-max 0))
1745 (defun org-init-section-numbers ()
1746 "Initialize the vector for the section numbers."
1747 (let* ((level -1)
1748 (numbers (nreverse (org-split-string "" "\\.")))
1749 (depth (1- (length org-section-numbers)))
1750 (i depth) number-string)
1751 (while (>= i 0)
1752 (if (> i level)
1753 (aset org-section-numbers i 0)
1754 (setq number-string (or (car numbers) "0"))
1755 (if (string-match "\\`[A-Z]\\'" number-string)
1756 (aset org-section-numbers i
1757 (- (string-to-char number-string) ?A -1))
1758 (aset org-section-numbers i (string-to-number number-string)))
1759 (pop numbers))
1760 (setq i (1- i)))))
1762 (defun org-section-number (&optional level)
1763 "Return a string with the current section number.
1764 When LEVEL is non-nil, increase section numbers on that level."
1765 (let* ((depth (1- (length org-section-numbers)))
1766 (string "")
1767 (fmts (car org-export-section-number-format))
1768 (term (cdr org-export-section-number-format))
1769 (sep "")
1770 ctype fmt idx n)
1771 (when level
1772 (when (> level -1)
1773 (aset org-section-numbers
1774 level (1+ (aref org-section-numbers level))))
1775 (setq idx (1+ level))
1776 (while (<= idx depth)
1777 (if (not (= idx 1))
1778 (aset org-section-numbers idx 0))
1779 (setq idx (1+ idx))))
1780 (setq idx 0)
1781 (while (<= idx depth)
1782 (when (> (aref org-section-numbers idx) 0)
1783 (setq fmt (or (pop fmts) fmt)
1784 ctype (car fmt)
1785 n (aref org-section-numbers idx)
1786 string (if (> n 0)
1787 (concat string sep (org-number-to-counter n ctype))
1788 (concat string ".0"))
1789 sep (nth 1 fmt)))
1790 (setq idx (1+ idx)))
1791 (save-match-data
1792 (if (string-match "\\`\\([@0]\\.\\)+" string)
1793 (setq string (replace-match "" t nil string)))
1794 (if (string-match "\\(\\.0\\)+\\'" string)
1795 (setq string (replace-match "" t nil string))))
1796 (concat string term)))
1798 (defun org-number-to-counter (n type)
1799 "Concert number N to a string counter, according to TYPE.
1800 TYPE must be a string, any of:
1801 1 number
1802 A A,B,....
1803 a a,b,....
1804 I uppper case roman numeral
1805 i lower case roman numeral"
1806 (cond
1807 ((equal type "1") (number-to-string n))
1808 ((equal type "A") (char-to-string (+ ?A n -1)))
1809 ((equal type "a") (char-to-string (+ ?a n -1)))
1810 ((equal type "I") (org-number-to-roman n))
1811 ((equal type "i") (downcase (org-number-to-roman n)))
1812 (t (error "Invalid counter type `%s'" type))))
1814 (defun org-number-to-roman (n)
1815 "Convert integer N into a roman numeral."
1816 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1817 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1818 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1819 ( 1 . "I")))
1820 (res ""))
1821 (if (<= n 0)
1822 (number-to-string n)
1823 (while roman
1824 (if (>= n (caar roman))
1825 (setq n (- n (caar roman))
1826 res (concat res (cdar roman)))
1827 (pop roman)))
1828 res)))
1830 (org-number-to-roman 1961)
1833 ;;; Include files
1835 (defun org-export-handle-include-files ()
1836 "Include the contents of include files, with proper formatting."
1837 (let ((case-fold-search t)
1838 params file markup lang start end)
1839 (goto-char (point-min))
1840 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
1841 (setq params (read (concat "(" (match-string 1) ")"))
1842 file (org-symname-or-string (pop params))
1843 markup (org-symname-or-string (pop params))
1844 lang (org-symname-or-string (pop params)))
1845 (delete-region (match-beginning 0) (match-end 0))
1846 (if (or (not file)
1847 (not (file-exists-p file))
1848 (not (file-readable-p file)))
1849 (insert (format "CANNOT INCLUDE FILE %s" file))
1850 (when markup
1851 (if (equal (downcase markup) "src")
1852 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
1853 end "#+end_src")
1854 (setq start (format "#+begin_%s\n" markup)
1855 end (format "#+end_%s" markup))))
1856 (insert (or start ""))
1857 (forward-char (nth 1 (insert-file-contents (expand-file-name file))))
1858 (or (bolp) (newline))
1859 (insert (or end ""))))))
1861 (defun org-symname-or-string (s)
1862 (if (symbolp s)
1863 (if s (symbol-name s) s)
1866 ;;; Fontification of code
1867 ;; Currently only for th HTML backend, but who knows....
1868 (defun org-export-replace-src-segments ()
1869 "Replace source code segments with special code for export."
1870 (let ((case-fold-search t)
1871 lang code trans)
1872 (goto-char (point-min))
1873 (while (re-search-forward
1874 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1875 nil t)
1876 (setq lang (match-string 1) code (match-string 2)
1877 trans (org-export-format-source-code lang code))
1878 (replace-match trans t t))))
1880 (defvar htmlp) ;; dynamically scoped from org-exp.el
1882 (defun org-export-format-source-code (lang code)
1883 "Format CODE from language LANG and return it formatted for export.
1884 Currently, this only does something for HTML export, for all other
1885 backends, it converts the segment into an EXAMPLE segment."
1886 (save-match-data
1887 (cond
1888 (htmlp
1889 ;; We are exporting to HTML
1890 (condition-case nil (require 'htmlize) (nil t))
1891 (if (not (fboundp 'htmlize-region-for-paste))
1892 (progn
1893 ;; we do not have htmlize.el, or an old version of it
1894 (message
1895 "htmlize.el 1.34 or later is needed for source code formatting")
1896 (concat "#+BEGIN_EXAMPLE\n" code
1897 (if (string-match "\n\\'" code) "" "\n")
1898 "#+END_EXAMPLE\n"))
1899 ;; ok, we are good to go
1900 (let* ((mode (and lang (intern (concat lang "-mode"))))
1901 (org-inhibit-startup t)
1902 (org-startup-folded nil)
1903 (htmltext
1904 (with-temp-buffer
1905 (insert code)
1906 ;; Free up the protected stuff
1907 (goto-char (point-min))
1908 (while (re-search-forward "^," nil t)
1909 (replace-match "")
1910 (end-of-line 1))
1911 (if (functionp mode)
1912 (funcall mode)
1913 (fundamental-mode))
1914 (font-lock-fontify-buffer)
1915 (org-export-htmlize-region-for-paste
1916 (point-min) (point-max)))))
1917 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
1918 (setq htmltext (replace-match "<pre class=\"src\">"
1919 t t htmltext)))
1920 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
1922 ;; This is not HTML, so just make it an example.
1923 (when (equal lang "org")
1924 (while (string-match "^," code)
1925 (setq code (replace-match "" t t code))))
1926 (concat "#+BEGIN_EXAMPLE\n" code
1927 (if (string-match "\n\\'" code) "" "\n")
1928 "#+END_EXAMPLE\n")))))
1930 ;;; ASCII export
1932 (defvar org-last-level nil) ; dynamically scoped variable
1933 (defvar org-min-level nil) ; dynamically scoped variable
1934 (defvar org-levels-open nil) ; dynamically scoped parameter
1935 (defvar org-ascii-current-indentation nil) ; For communication
1937 ;;;###autoload
1938 (defun org-export-as-ascii (arg)
1939 "Export the outline as a pretty ASCII file.
1940 If there is an active region, export only the region.
1941 The prefix ARG specifies how many levels of the outline should become
1942 underlined headlines. The default is 3."
1943 (interactive "P")
1944 (setq-default org-todo-line-regexp org-todo-line-regexp)
1945 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1946 (org-infile-export-plist)))
1947 (region-p (org-region-active-p))
1948 (rbeg (and region-p (region-beginning)))
1949 (rend (and region-p (region-end)))
1950 (subtree-p
1951 (when region-p
1952 (save-excursion
1953 (goto-char rbeg)
1954 (and (org-at-heading-p)
1955 (>= (org-end-of-subtree t t) rend)))))
1956 (opt-plist (if subtree-p
1957 (org-export-add-subtree-options opt-plist rbeg)
1958 opt-plist))
1959 (custom-times org-display-custom-times)
1960 (org-ascii-current-indentation '(0 . 0))
1961 (level 0) line txt
1962 (umax nil)
1963 (umax-toc nil)
1964 (case-fold-search nil)
1965 (filename (concat (file-name-as-directory
1966 (org-export-directory :ascii opt-plist))
1967 (file-name-sans-extension
1968 (or (and subtree-p
1969 (org-entry-get (region-beginning)
1970 "EXPORT_FILE_NAME" t))
1971 (file-name-nondirectory buffer-file-name)))
1972 ".txt"))
1973 (filename (if (equal (file-truename filename)
1974 (file-truename buffer-file-name))
1975 (concat filename ".txt")
1976 filename))
1977 (buffer (find-file-noselect filename))
1978 (org-levels-open (make-vector org-level-max nil))
1979 (odd org-odd-levels-only)
1980 (date (plist-get opt-plist :date))
1981 (author (plist-get opt-plist :author))
1982 (title (or (and subtree-p (org-export-get-title-from-subtree))
1983 (plist-get opt-plist :title)
1984 (and (not
1985 (plist-get opt-plist :skip-before-1st-heading))
1986 (org-export-grab-title-from-buffer))
1987 (file-name-sans-extension
1988 (file-name-nondirectory buffer-file-name))))
1989 (email (plist-get opt-plist :email))
1990 (language (plist-get opt-plist :language))
1991 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1992 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1993 (todo nil)
1994 (lang-words nil)
1995 (region
1996 (buffer-substring
1997 (if (org-region-active-p) (region-beginning) (point-min))
1998 (if (org-region-active-p) (region-end) (point-max))))
1999 (lines (org-split-string
2000 (org-export-preprocess-string
2001 region
2002 :for-ascii t
2003 :skip-before-1st-heading
2004 (plist-get opt-plist :skip-before-1st-heading)
2005 :drawers (plist-get opt-plist :drawers)
2006 :verbatim-multiline t
2007 :archived-trees
2008 (plist-get opt-plist :archived-trees)
2009 :add-text (plist-get opt-plist :text))
2010 "\n"))
2011 thetoc have-headings first-heading-pos
2012 table-open table-buffer)
2014 (let ((inhibit-read-only t))
2015 (org-unmodified
2016 (remove-text-properties (point-min) (point-max)
2017 '(:org-license-to-kill t))))
2019 (setq org-min-level (org-get-min-level lines))
2020 (setq org-last-level org-min-level)
2021 (org-init-section-numbers)
2023 (find-file-noselect filename)
2025 (setq lang-words (or (assoc language org-export-language-setup)
2026 (assoc "en" org-export-language-setup)))
2027 (switch-to-buffer-other-window buffer)
2028 (erase-buffer)
2029 (fundamental-mode)
2030 ;; create local variables for all options, to make sure all called
2031 ;; functions get the correct information
2032 (mapc (lambda (x)
2033 (set (make-local-variable (cdr x))
2034 (plist-get opt-plist (car x))))
2035 org-export-plist-vars)
2036 (org-set-local 'org-odd-levels-only odd)
2037 (setq umax (if arg (prefix-numeric-value arg)
2038 org-export-headline-levels))
2039 (setq umax-toc (if (integerp org-export-with-toc)
2040 (min org-export-with-toc umax)
2041 umax))
2043 ;; File header
2044 (if title (org-insert-centered title ?=))
2045 (insert "\n")
2046 (if (and (or author email)
2047 org-export-author-info)
2048 (insert (concat (nth 1 lang-words) ": " (or author "")
2049 (if email (concat " <" email ">") "")
2050 "\n")))
2052 (cond
2053 ((and date (string-match "%" date))
2054 (setq date (format-time-string date)))
2055 (date)
2056 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2058 (if (and date org-export-time-stamp-file)
2059 (insert (concat (nth 2 lang-words) ": " date"\n")))
2061 (insert "\n\n")
2063 (if org-export-with-toc
2064 (progn
2065 (push (concat (nth 3 lang-words) "\n") thetoc)
2066 (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
2067 (mapc '(lambda (line)
2068 (if (string-match org-todo-line-regexp
2069 line)
2070 ;; This is a headline
2071 (progn
2072 (setq have-headings t)
2073 (setq level (- (match-end 1) (match-beginning 1))
2074 level (org-tr-level level)
2075 txt (match-string 3 line)
2076 todo
2077 (or (and org-export-mark-todo-in-toc
2078 (match-beginning 2)
2079 (not (member (match-string 2 line)
2080 org-done-keywords)))
2081 ; TODO, not DONE
2082 (and org-export-mark-todo-in-toc
2083 (= level umax-toc)
2084 (org-search-todo-below
2085 line lines level))))
2086 (setq txt (org-html-expand-for-ascii txt))
2088 (while (string-match org-bracket-link-regexp txt)
2089 (setq txt
2090 (replace-match
2091 (match-string (if (match-end 2) 3 1) txt)
2092 t t txt)))
2094 (if (and (memq org-export-with-tags '(not-in-toc nil))
2095 (string-match
2096 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2097 txt))
2098 (setq txt (replace-match "" t t txt)))
2099 (if (string-match quote-re0 txt)
2100 (setq txt (replace-match "" t t txt)))
2102 (if org-export-with-section-numbers
2103 (setq txt (concat (org-section-number level)
2104 " " txt)))
2105 (if (<= level umax-toc)
2106 (progn
2107 (push
2108 (concat
2109 (make-string
2110 (* (max 0 (- level org-min-level)) 4) ?\ )
2111 (format (if todo "%s (*)\n" "%s\n") txt))
2112 thetoc)
2113 (setq org-last-level level))
2114 ))))
2115 lines)
2116 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2118 (org-init-section-numbers)
2119 (while (setq line (pop lines))
2120 ;; Remove the quoted HTML tags.
2121 (setq line (org-html-expand-for-ascii line))
2122 ;; Remove targets
2123 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2124 (setq line (replace-match "" t t line)))
2125 ;; Replace internal links
2126 (while (string-match org-bracket-link-regexp line)
2127 (setq line (replace-match
2128 (if (match-end 3) "[\\3]" "[\\1]")
2129 t nil line)))
2130 (when custom-times
2131 (setq line (org-translate-time line)))
2132 (cond
2133 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2134 ;; a Headline
2135 (setq first-heading-pos (or first-heading-pos (point)))
2136 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2137 txt (match-string 2 line))
2138 (org-ascii-level-start level txt umax lines))
2140 ((and org-export-with-tables
2141 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2142 (if (not table-open)
2143 ;; New table starts
2144 (setq table-open t table-buffer nil))
2145 ;; Accumulate lines
2146 (setq table-buffer (cons line table-buffer))
2147 (when (or (not lines)
2148 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2149 (car lines))))
2150 (setq table-open nil
2151 table-buffer (nreverse table-buffer))
2152 (insert (mapconcat
2153 (lambda (x)
2154 (org-fix-indentation x org-ascii-current-indentation))
2155 (org-format-table-ascii table-buffer)
2156 "\n") "\n")))
2158 (setq line (org-fix-indentation line org-ascii-current-indentation))
2159 (if (and org-export-with-fixed-width
2160 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2161 (setq line (replace-match "\\1" nil nil line)))
2162 (insert line "\n"))))
2164 (normal-mode)
2166 ;; insert the table of contents
2167 (when thetoc
2168 (goto-char (point-min))
2169 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2170 (progn
2171 (goto-char (match-beginning 0))
2172 (replace-match ""))
2173 (goto-char first-heading-pos))
2174 (mapc 'insert thetoc)
2175 (or (looking-at "[ \t]*\n[ \t]*\n")
2176 (insert "\n\n")))
2178 ;; Convert whitespace place holders
2179 (goto-char (point-min))
2180 (let (beg end)
2181 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2182 (setq end (next-single-property-change beg 'org-whitespace))
2183 (goto-char beg)
2184 (delete-region beg end)
2185 (insert (make-string (- end beg) ?\ ))))
2187 (save-buffer)
2188 ;; remove display and invisible chars
2189 (let (beg end)
2190 (goto-char (point-min))
2191 (while (setq beg (next-single-property-change (point) 'display))
2192 (setq end (next-single-property-change beg 'display))
2193 (delete-region beg end)
2194 (goto-char beg)
2195 (insert "=>"))
2196 (goto-char (point-min))
2197 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2198 (setq end (next-single-property-change beg 'org-cwidth))
2199 (delete-region beg end)
2200 (goto-char beg)))
2201 (goto-char (point-min))))
2203 (defun org-export-ascii-preprocess ()
2204 "Do extra work for ASCII export"
2205 (goto-char (point-min))
2206 (while (re-search-forward org-verbatim-re nil t)
2207 (goto-char (match-end 2))
2208 (backward-delete-char 1) (insert "'")
2209 (goto-char (match-beginning 2))
2210 (delete-char 1) (insert "`")
2211 (goto-char (match-end 2))))
2213 (defun org-search-todo-below (line lines level)
2214 "Search the subtree below LINE for any TODO entries."
2215 (let ((rest (cdr (memq line lines)))
2216 (re org-todo-line-regexp)
2217 line lv todo)
2218 (catch 'exit
2219 (while (setq line (pop rest))
2220 (if (string-match re line)
2221 (progn
2222 (setq lv (- (match-end 1) (match-beginning 1))
2223 todo (and (match-beginning 2)
2224 (not (member (match-string 2 line)
2225 org-done-keywords))))
2226 ; TODO, not DONE
2227 (if (<= lv level) (throw 'exit nil))
2228 (if todo (throw 'exit t))))))))
2230 (defun org-html-expand-for-ascii (line)
2231 "Handle quoted HTML for ASCII export."
2232 (if org-export-html-expand
2233 (while (string-match "@<[^<>\n]*>" line)
2234 ;; We just remove the tags for now.
2235 (setq line (replace-match "" nil nil line))))
2236 line)
2238 (defun org-insert-centered (s &optional underline)
2239 "Insert the string S centered and underline it with character UNDERLINE."
2240 (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
2241 (insert (make-string ind ?\ ) s "\n")
2242 (if underline
2243 (insert (make-string ind ?\ )
2244 (make-string (string-width s) underline)
2245 "\n"))))
2247 (defun org-ascii-level-start (level title umax &optional lines)
2248 "Insert a new level in ASCII export."
2249 (let (char (n (- level umax 1)) (ind 0))
2250 (if (> level umax)
2251 (progn
2252 (insert (make-string (* 2 n) ?\ )
2253 (char-to-string (nth (% n (length org-export-ascii-bullets))
2254 org-export-ascii-bullets))
2255 " " title "\n")
2256 ;; find the indentation of the next non-empty line
2257 (catch 'stop
2258 (while lines
2259 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2260 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2261 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2262 (pop lines)))
2263 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2264 (if (or (not (equal (char-before) ?\n))
2265 (not (equal (char-before (1- (point))) ?\n)))
2266 (insert "\n"))
2267 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2268 (unless org-export-with-tags
2269 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2270 (setq title (replace-match "" t t title))))
2271 (if org-export-with-section-numbers
2272 (setq title (concat (org-section-number level) " " title)))
2273 (insert title "\n" (make-string (string-width title) char) "\n")
2274 (setq org-ascii-current-indentation '(0 . 0)))))
2276 ;;;###autoload
2277 (defun org-export-visible (type arg)
2278 "Create a copy of the visible part of the current buffer, and export it.
2279 The copy is created in a temporary buffer and removed after use.
2280 TYPE is the final key (as a string) that also select the export command in
2281 the `C-c C-e' export dispatcher.
2282 As a special case, if the you type SPC at the prompt, the temporary
2283 org-mode file will not be removed but presented to you so that you can
2284 continue to use it. The prefix arg ARG is passed through to the exporting
2285 command."
2286 (interactive
2287 (list (progn
2288 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2289 (read-char-exclusive))
2290 current-prefix-arg))
2291 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2292 (error "Invalid export key"))
2293 (let* ((binding (cdr (assoc type
2294 '((?a . org-export-as-ascii)
2295 (?\C-a . org-export-as-ascii)
2296 (?b . org-export-as-html-and-open)
2297 (?\C-b . org-export-as-html-and-open)
2298 (?h . org-export-as-html)
2299 (?H . org-export-as-html-to-buffer)
2300 (?R . org-export-region-as-html)
2301 (?x . org-export-as-xoxo)))))
2302 (keepp (equal type ?\ ))
2303 (file buffer-file-name)
2304 (buffer (get-buffer-create "*Org Export Visible*"))
2305 s e)
2306 ;; Need to hack the drawers here.
2307 (save-excursion
2308 (goto-char (point-min))
2309 (while (re-search-forward org-drawer-regexp nil t)
2310 (goto-char (match-beginning 1))
2311 (or (org-invisible-p) (org-flag-drawer nil))))
2312 (with-current-buffer buffer (erase-buffer))
2313 (save-excursion
2314 (setq s (goto-char (point-min)))
2315 (while (not (= (point) (point-max)))
2316 (goto-char (org-find-invisible))
2317 (append-to-buffer buffer s (point))
2318 (setq s (goto-char (org-find-visible))))
2319 (org-cycle-hide-drawers 'all)
2320 (goto-char (point-min))
2321 (unless keepp
2322 ;; Copy all comment lines to the end, to make sure #+ settings are
2323 ;; still available for the second export step. Kind of a hack, but
2324 ;; does do the trick.
2325 (if (looking-at "#[^\r\n]*")
2326 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2327 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2328 (append-to-buffer buffer (1+ (match-beginning 0))
2329 (min (point-max) (1+ (match-end 0))))))
2330 (set-buffer buffer)
2331 (let ((buffer-file-name file)
2332 (org-inhibit-startup t))
2333 (org-mode)
2334 (show-all)
2335 (unless keepp (funcall binding arg))))
2336 (if (not keepp)
2337 (kill-buffer buffer)
2338 (switch-to-buffer-other-window buffer)
2339 (goto-char (point-min)))))
2341 (defun org-find-visible ()
2342 (let ((s (point)))
2343 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2344 (get-char-property s 'invisible)))
2346 (defun org-find-invisible ()
2347 (let ((s (point)))
2348 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2349 (not (get-char-property s 'invisible))))
2352 ;;; HTML export
2354 (defvar org-archive-location) ;; gets loades with the org-archive require.
2355 (defun org-get-current-options ()
2356 "Return a string with current options as keyword options.
2357 Does include HTML export options as well as TODO and CATEGORY stuff."
2358 (require 'org-archive)
2359 (format
2360 "#+TITLE: %s
2361 #+AUTHOR: %s
2362 #+EMAIL: %s
2363 #+DATE: %s
2364 #+LANGUAGE: %s
2365 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2366 #+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
2368 #+LINK_UP: %s
2369 #+LINK_HOME: %s
2370 #+CATEGORY: %s
2371 #+SEQ_TODO: %s
2372 #+TYP_TODO: %s
2373 #+PRIORITIES: %c %c %c
2374 #+DRAWERS: %s
2375 #+STARTUP: %s %s %s %s %s
2376 #+TAGS: %s
2377 #+FILETAGS: %s
2378 #+ARCHIVE: %s
2379 #+LINK: %s
2381 (buffer-name) (user-full-name) user-mail-address
2382 (format-time-string (car org-time-stamp-formats))
2383 org-export-default-language
2384 org-export-headline-levels
2385 org-export-with-section-numbers
2386 org-export-with-toc
2387 org-export-preserve-breaks
2388 org-export-html-expand
2389 org-export-with-fixed-width
2390 org-export-with-tables
2391 org-export-with-sub-superscripts
2392 org-export-with-special-strings
2393 org-export-with-footnotes
2394 org-export-with-emphasize
2395 org-export-with-TeX-macros
2396 org-export-with-LaTeX-fragments
2397 org-export-skip-text-before-1st-heading
2398 org-export-with-drawers
2399 org-export-with-tags
2400 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2401 org-export-html-link-up
2402 org-export-html-link-home
2403 (file-name-nondirectory buffer-file-name)
2404 "TODO FEEDBACK VERIFY DONE"
2405 "Me Jason Marie DONE"
2406 org-highest-priority org-lowest-priority org-default-priority
2407 (mapconcat 'identity org-drawers " ")
2408 (cdr (assoc org-startup-folded
2409 '((nil . "showall") (t . "overview") (content . "content"))))
2410 (if org-odd-levels-only "odd" "oddeven")
2411 (if org-hide-leading-stars "hidestars" "showstars")
2412 (if org-startup-align-all-tables "align" "noalign")
2413 (cond ((eq org-log-done t) "logdone")
2414 ((equal org-log-done 'note) "lognotedone")
2415 ((not org-log-done) "nologdone"))
2416 (or (mapconcat (lambda (x)
2417 (cond
2418 ((equal '(:startgroup) x) "{")
2419 ((equal '(:endgroup) x) "}")
2420 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2421 (t (car x))))
2422 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2423 (mapconcat 'identity org-file-tags " ")
2424 org-archive-location
2425 "org file:~/org/%s.org"
2428 (defun org-export-html-preprocess (parameters)
2429 ;; Convert LaTeX fragments to images
2430 (when (plist-get parameters :LaTeX-fragments)
2431 (org-format-latex
2432 (concat "ltxpng/" (file-name-sans-extension
2433 (file-name-nondirectory
2434 org-current-export-file)))
2435 org-current-export-dir nil "Creating LaTeX image %s"))
2436 (message "Exporting..."))
2438 ;;;###autoload
2439 (defun org-insert-export-options-template ()
2440 "Insert into the buffer a template with information for exporting."
2441 (interactive)
2442 (if (not (bolp)) (newline))
2443 (let ((s (org-get-current-options)))
2444 (and (string-match "#\\+CATEGORY" s)
2445 (setq s (substring s 0 (match-beginning 0))))
2446 (insert s)))
2448 ;;;###autoload
2449 (defun org-export-as-html-and-open (arg)
2450 "Export the outline as HTML and immediately open it with a browser.
2451 If there is an active region, export only the region.
2452 The prefix ARG specifies how many levels of the outline should become
2453 headlines. The default is 3. Lower levels will become bulleted lists."
2454 (interactive "P")
2455 (org-export-as-html arg 'hidden)
2456 (org-open-file buffer-file-name))
2458 ;;;###autoload
2459 (defun org-export-as-html-batch ()
2460 "Call `org-export-as-html', may be used in batch processing as
2461 emacs --batch
2462 --load=$HOME/lib/emacs/org.el
2463 --eval \"(setq org-export-headline-levels 2)\"
2464 --visit=MyFile --funcall org-export-as-html-batch"
2465 (org-export-as-html org-export-headline-levels 'hidden))
2467 ;;;###autoload
2468 (defun org-export-as-html-to-buffer (arg)
2469 "Call `org-exort-as-html` with output to a temporary buffer.
2470 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2471 (interactive "P")
2472 (org-export-as-html arg nil nil "*Org HTML Export*")
2473 (switch-to-buffer-other-window "*Org HTML Export*"))
2475 ;;;###autoload
2476 (defun org-replace-region-by-html (beg end)
2477 "Assume the current region has org-mode syntax, and convert it to HTML.
2478 This can be used in any buffer. For example, you could write an
2479 itemized list in org-mode syntax in an HTML buffer and then use this
2480 command to convert it."
2481 (interactive "r")
2482 (let (reg html buf pop-up-frames)
2483 (save-window-excursion
2484 (if (org-mode-p)
2485 (setq html (org-export-region-as-html
2486 beg end t 'string))
2487 (setq reg (buffer-substring beg end)
2488 buf (get-buffer-create "*Org tmp*"))
2489 (with-current-buffer buf
2490 (erase-buffer)
2491 (insert reg)
2492 (org-mode)
2493 (setq html (org-export-region-as-html
2494 (point-min) (point-max) t 'string)))
2495 (kill-buffer buf)))
2496 (delete-region beg end)
2497 (insert html)))
2499 ;;;###autoload
2500 (defun org-export-region-as-html (beg end &optional body-only buffer)
2501 "Convert region from BEG to END in org-mode buffer to HTML.
2502 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2503 contents, and only produce the region of converted text, useful for
2504 cut-and-paste operations.
2505 If BUFFER is a buffer or a string, use/create that buffer as a target
2506 of the converted HTML. If BUFFER is the symbol `string', return the
2507 produced HTML as a string and leave not buffer behind. For example,
2508 a Lisp program could call this function in the following way:
2510 (setq html (org-export-region-as-html beg end t 'string))
2512 When called interactively, the output buffer is selected, and shown
2513 in a window. A non-interactive call will only return the buffer."
2514 (interactive "r\nP")
2515 (when (interactive-p)
2516 (setq buffer "*Org HTML Export*"))
2517 (let ((transient-mark-mode t) (zmacs-regions t)
2518 rtn)
2519 (goto-char end)
2520 (set-mark (point)) ;; to activate the region
2521 (goto-char beg)
2522 (setq rtn (org-export-as-html
2523 nil nil nil
2524 buffer body-only))
2525 (if (fboundp 'deactivate-mark) (deactivate-mark))
2526 (if (and (interactive-p) (bufferp rtn))
2527 (switch-to-buffer-other-window rtn)
2528 rtn)))
2530 (defvar html-table-tag nil) ; dynamically scoped into this.
2531 ;;;###autoload
2532 (defun org-export-as-html (arg &optional hidden ext-plist
2533 to-buffer body-only pub-dir)
2534 "Export the outline as a pretty HTML file.
2535 If there is an active region, export only the region. The prefix
2536 ARG specifies how many levels of the outline should become
2537 headlines. The default is 3. Lower levels will become bulleted
2538 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2539 EXT-PLIST is a property list with external parameters overriding
2540 org-mode's default settings, but still inferior to file-local
2541 settings. When TO-BUFFER is non-nil, create a buffer with that
2542 name and export to that buffer. If TO-BUFFER is the symbol
2543 `string', don't leave any buffer behind but just return the
2544 resulting HTML as a string. When BODY-ONLY is set, don't produce
2545 the file header and footer, simply return the content of
2546 <body>...</body>, without even the body tags themselves. When
2547 PUB-DIR is set, use this as the publishing directory."
2548 (interactive "P")
2550 ;; Make sure we have a file name when we need it.
2551 (when (and (not (or to-buffer body-only))
2552 (not buffer-file-name))
2553 (if (buffer-base-buffer)
2554 (org-set-local 'buffer-file-name
2555 (with-current-buffer (buffer-base-buffer)
2556 buffer-file-name))
2557 (error "Need a file name to be able to export.")))
2559 (message "Exporting...")
2560 (setq-default org-todo-line-regexp org-todo-line-regexp)
2561 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2562 (setq-default org-done-keywords org-done-keywords)
2563 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2564 (let* ((opt-plist
2565 (org-export-process-option-filters
2566 (org-combine-plists (org-default-export-plist)
2567 ext-plist
2568 (org-infile-export-plist))))
2570 (style (plist-get opt-plist :style))
2571 (html-extension (plist-get opt-plist :html-extension))
2572 (link-validate (plist-get opt-plist :link-validation-function))
2573 valid thetoc have-headings first-heading-pos
2574 (odd org-odd-levels-only)
2575 (region-p (org-region-active-p))
2576 (rbeg (and region-p (region-beginning)))
2577 (rend (and region-p (region-end)))
2578 (subtree-p
2579 (when region-p
2580 (save-excursion
2581 (goto-char rbeg)
2582 (and (org-at-heading-p)
2583 (>= (org-end-of-subtree t t) rend)))))
2584 (opt-plist (if subtree-p
2585 (org-export-add-subtree-options opt-plist rbeg)
2586 opt-plist))
2587 ;; The following two are dynamically scoped into other
2588 ;; routines below.
2589 (org-current-export-dir
2590 (or pub-dir (org-export-directory :html opt-plist)))
2591 (org-current-export-file buffer-file-name)
2592 (level 0) (line "") (origline "") txt todo
2593 (umax nil)
2594 (umax-toc nil)
2595 (filename (if to-buffer nil
2596 (expand-file-name
2597 (concat
2598 (file-name-sans-extension
2599 (or (and subtree-p
2600 (org-entry-get (region-beginning)
2601 "EXPORT_FILE_NAME" t))
2602 (file-name-nondirectory buffer-file-name)))
2603 "." html-extension)
2604 (file-name-as-directory
2605 (or pub-dir (org-export-directory :html opt-plist))))))
2606 (current-dir (if buffer-file-name
2607 (file-name-directory buffer-file-name)
2608 default-directory))
2609 (buffer (if to-buffer
2610 (cond
2611 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2612 (t (get-buffer-create to-buffer)))
2613 (find-file-noselect filename)))
2614 (org-levels-open (make-vector org-level-max nil))
2615 (date (plist-get opt-plist :date))
2616 (author (plist-get opt-plist :author))
2617 (title (or (and subtree-p (org-export-get-title-from-subtree))
2618 (plist-get opt-plist :title)
2619 (and (not
2620 (plist-get opt-plist :skip-before-1st-heading))
2621 (org-export-grab-title-from-buffer))
2622 (and buffer-file-name
2623 (file-name-sans-extension
2624 (file-name-nondirectory buffer-file-name)))
2625 "UNTITLED"))
2626 (html-table-tag (plist-get opt-plist :html-table-tag))
2627 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2628 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2629 (inquote nil)
2630 (infixed nil)
2631 (in-local-list nil)
2632 (local-list-type nil)
2633 (local-list-indent nil)
2634 (llt org-plain-list-ordered-item-terminator)
2635 (email (plist-get opt-plist :email))
2636 (language (plist-get opt-plist :language))
2637 (lang-words nil)
2638 (head-count 0) cnt
2639 (start 0)
2640 (coding-system (and (boundp 'buffer-file-coding-system)
2641 buffer-file-coding-system))
2642 (coding-system-for-write (or org-export-html-coding-system
2643 coding-system))
2644 (save-buffer-coding-system (or org-export-html-coding-system
2645 coding-system))
2646 (charset (and coding-system-for-write
2647 (fboundp 'coding-system-get)
2648 (coding-system-get coding-system-for-write
2649 'mime-charset)))
2650 (region
2651 (buffer-substring
2652 (if region-p (region-beginning) (point-min))
2653 (if region-p (region-end) (point-max))))
2654 (lines
2655 (org-split-string
2656 (org-export-preprocess-string
2657 region
2658 :emph-multiline t
2659 :for-html t
2660 :skip-before-1st-heading
2661 (plist-get opt-plist :skip-before-1st-heading)
2662 :drawers (plist-get opt-plist :drawers)
2663 :archived-trees
2664 (plist-get opt-plist :archived-trees)
2665 :add-text
2666 (plist-get opt-plist :text)
2667 :LaTeX-fragments
2668 (plist-get opt-plist :LaTeX-fragments))
2669 "[\r\n]"))
2670 table-open type
2671 table-buffer table-orig-buffer
2672 ind item-type starter didclose
2673 rpl path desc descp desc1 desc2 link
2674 snumber fnc item-tag
2677 (let ((inhibit-read-only t))
2678 (org-unmodified
2679 (remove-text-properties (point-min) (point-max)
2680 '(:org-license-to-kill t))))
2682 (message "Exporting...")
2684 (setq org-min-level (org-get-min-level lines))
2685 (setq org-last-level org-min-level)
2686 (org-init-section-numbers)
2688 (cond
2689 ((and date (string-match "%" date))
2690 (setq date (format-time-string date)))
2691 (date)
2692 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2694 ;; Get the language-dependent settings
2695 (setq lang-words (or (assoc language org-export-language-setup)
2696 (assoc "en" org-export-language-setup)))
2698 ;; Switch to the output buffer
2699 (set-buffer buffer)
2700 (let ((inhibit-read-only t)) (erase-buffer))
2701 (fundamental-mode)
2703 (and (fboundp 'set-buffer-file-coding-system)
2704 (set-buffer-file-coding-system coding-system-for-write))
2706 (let ((case-fold-search nil)
2707 (org-odd-levels-only odd))
2708 ;; create local variables for all options, to make sure all called
2709 ;; functions get the correct information
2710 (mapc (lambda (x)
2711 (set (make-local-variable (cdr x))
2712 (plist-get opt-plist (car x))))
2713 org-export-plist-vars)
2714 (setq umax (if arg (prefix-numeric-value arg)
2715 org-export-headline-levels))
2716 (setq umax-toc (if (integerp org-export-with-toc)
2717 (min org-export-with-toc umax)
2718 umax))
2719 (unless body-only
2720 ;; File header
2721 (insert (format
2722 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2723 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2724 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2725 lang=\"%s\" xml:lang=\"%s\">
2726 <head>
2727 <title>%s</title>
2728 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2729 <meta name=\"generator\" content=\"Org-mode\"/>
2730 <meta name=\"generated\" content=\"%s\"/>
2731 <meta name=\"author\" content=\"%s\"/>
2733 </head><body>
2735 language language (org-html-expand title)
2736 (or charset "iso-8859-1") date author style))
2738 (insert (or (plist-get opt-plist :preamble) ""))
2740 (when (plist-get opt-plist :auto-preamble)
2741 (if title (insert (format org-export-html-title-format
2742 (org-html-expand title))))))
2744 (if (and org-export-with-toc (not body-only))
2745 (progn
2746 (push (format "<h%d>%s</h%d>\n"
2747 org-export-html-toplevel-hlevel
2748 (nth 3 lang-words)
2749 org-export-html-toplevel-hlevel)
2750 thetoc)
2751 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2752 (push "<ul>\n<li>" thetoc)
2753 (setq lines
2754 (mapcar '(lambda (line)
2755 (if (string-match org-todo-line-regexp line)
2756 ;; This is a headline
2757 (progn
2758 (setq have-headings t)
2759 (setq level (- (match-end 1) (match-beginning 1))
2760 level (org-tr-level level)
2761 txt (save-match-data
2762 (org-html-expand
2763 (org-export-cleanup-toc-line
2764 (match-string 3 line))))
2765 todo
2766 (or (and org-export-mark-todo-in-toc
2767 (match-beginning 2)
2768 (not (member (match-string 2 line)
2769 org-done-keywords)))
2770 ; TODO, not DONE
2771 (and org-export-mark-todo-in-toc
2772 (= level umax-toc)
2773 (org-search-todo-below
2774 line lines level))))
2775 (if (string-match
2776 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2777 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2778 (if (string-match quote-re0 txt)
2779 (setq txt (replace-match "" t t txt)))
2780 (setq snumber (org-section-number level))
2781 (if org-export-with-section-numbers
2782 (setq txt (concat snumber " " txt)))
2783 (if (<= level (max umax umax-toc))
2784 (setq head-count (+ head-count 1)))
2785 (if (<= level umax-toc)
2786 (progn
2787 (if (> level org-last-level)
2788 (progn
2789 (setq cnt (- level org-last-level))
2790 (while (>= (setq cnt (1- cnt)) 0)
2791 (push "\n<ul>\n<li>" thetoc))
2792 (push "\n" thetoc)))
2793 (if (< level org-last-level)
2794 (progn
2795 (setq cnt (- org-last-level level))
2796 (while (>= (setq cnt (1- cnt)) 0)
2797 (push "</li>\n</ul>" thetoc))
2798 (push "\n" thetoc)))
2799 ;; Check for targets
2800 (while (string-match org-any-target-regexp line)
2801 (setq line (replace-match
2802 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2803 t t line)))
2804 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2805 (setq txt (replace-match "" t t txt)))
2806 (push
2807 (format
2808 (if todo
2809 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2810 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2811 snumber txt) thetoc)
2813 (setq org-last-level level))
2815 line)
2816 lines))
2817 (while (> org-last-level (1- org-min-level))
2818 (setq org-last-level (1- org-last-level))
2819 (push "</li>\n</ul>\n" thetoc))
2820 (push "</div>\n" thetoc)
2821 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2823 (setq head-count 0)
2824 (org-init-section-numbers)
2826 (while (setq line (pop lines) origline line)
2827 (catch 'nextline
2829 ;; end of quote section?
2830 (when (and inquote (string-match "^\\*+ " line))
2831 (insert "</pre>\n")
2832 (setq inquote nil))
2833 ;; inside a quote section?
2834 (when inquote
2835 (insert (org-html-protect line) "\n")
2836 (throw 'nextline nil))
2838 ;; verbatim lines
2839 (when (and org-export-with-fixed-width
2840 (string-match "^[ \t]*:\\(.*\\)" line))
2841 (when (not infixed)
2842 (setq infixed t)
2843 (insert "<pre>\n"))
2844 (insert (org-html-protect (match-string 1 line)) "\n")
2845 (when (or (not lines)
2846 (not (string-match "^[ \t]*\\(:.*\\)"
2847 (car lines))))
2848 (setq infixed nil)
2849 (insert "</pre>\n"))
2850 (throw 'nextline nil))
2852 ;; Protected HTML
2853 (when (get-text-property 0 'org-protected line)
2854 (let (par)
2855 (when (re-search-backward
2856 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2857 (setq par (match-string 1))
2858 (replace-match "\\2\n"))
2859 (insert line "\n")
2860 (while (and lines
2861 (not (string-match "^[ \t]*:" (car lines)))
2862 (or (= (length (car lines)) 0)
2863 (get-text-property 0 'org-protected (car lines))))
2864 (insert (pop lines) "\n"))
2865 (and par (insert "<p>\n")))
2866 (throw 'nextline nil))
2868 ;; Horizontal line
2869 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2870 (insert "\n<hr/>\n")
2871 (throw 'nextline nil))
2873 ;; Blockquotes and verse
2874 (when (equal "ORG-BLOCKQUOTE-START" line)
2875 (insert "<blockquote>\n<p>\n")
2876 (throw 'nextline nil))
2877 (when (equal "ORG-BLOCKQUOTE-END" line)
2878 (insert "</p>\n</blockquote>\n")
2879 (throw 'nextline nil))
2880 (when (equal "ORG-VERSE-START" line)
2881 (insert "<verse>\n<p>\n")
2882 (throw 'nextline nil))
2883 (when (equal "ORG-VERSE-END" line)
2884 (insert "</p>\n</verse>\n")
2885 (throw 'nextline nil))
2887 ;; make targets to anchors
2888 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2889 (cond
2890 ((match-end 2)
2891 (setq line (replace-match
2892 (concat "@<a name=\""
2893 (org-solidify-link-text (match-string 1 line))
2894 "\">\\nbsp@</a>")
2895 t t line)))
2896 ((and org-export-with-toc (equal (string-to-char line) ?*))
2897 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2898 (setq line (replace-match
2899 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2900 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2901 t t line)))
2903 (setq line (replace-match
2904 (concat "@<a name=\""
2905 (org-solidify-link-text (match-string 1 line))
2906 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2907 t t line)))))
2909 (setq line (org-html-handle-time-stamps line))
2911 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2912 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2913 ;; Also handle sub_superscripts and checkboxes
2914 (or (string-match org-table-hline-regexp line)
2915 (setq line (org-html-expand line)))
2917 ;; Format the links
2918 (setq start 0)
2919 (while (string-match org-bracket-link-analytic-regexp line start)
2920 (setq start (match-beginning 0))
2921 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2922 (setq path (match-string 3 line))
2923 (setq desc1 (if (match-end 5) (match-string 5 line))
2924 desc2 (if (match-end 2) (concat type ":" path) path)
2925 descp (and desc1 (not (equal desc1 desc2)))
2926 desc (or desc1 desc2))
2927 ;; Make an image out of the description if that is so wanted
2928 (when (and descp (org-file-image-p desc))
2929 (save-match-data
2930 (if (string-match "^file:" desc)
2931 (setq desc (substring desc (match-end 0)))))
2932 (setq desc (concat "<img src=\"" desc "\"/>")))
2933 ;; FIXME: do we need to unescape here somewhere?
2934 (cond
2935 ((equal type "internal")
2936 (setq rpl
2937 (concat
2938 "<a href=\"#"
2939 (org-solidify-link-text
2940 (save-match-data (org-link-unescape path)) nil)
2941 "\">" desc "</a>")))
2942 ((member type '("http" "https"))
2943 ;; standard URL, just check if we need to inline an image
2944 (if (and (or (eq t org-export-html-inline-images)
2945 (and org-export-html-inline-images (not descp)))
2946 (org-file-image-p path))
2947 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2948 (setq link (concat type ":" path))
2949 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2950 ((member type '("ftp" "mailto" "news"))
2951 ;; standard URL
2952 (setq link (concat type ":" path))
2953 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2954 ((string= type "file")
2955 ;; FILE link
2956 (let* ((filename path)
2957 (abs-p (file-name-absolute-p filename))
2958 thefile file-is-image-p search)
2959 (save-match-data
2960 (if (string-match "::\\(.*\\)" filename)
2961 (setq search (match-string 1 filename)
2962 filename (replace-match "" t nil filename)))
2963 (setq valid
2964 (if (functionp link-validate)
2965 (funcall link-validate filename current-dir)
2967 (setq file-is-image-p (org-file-image-p filename))
2968 (setq thefile (if abs-p (expand-file-name filename) filename))
2969 (when (and org-export-html-link-org-files-as-html
2970 (string-match "\\.org$" thefile))
2971 (setq thefile (concat (substring thefile 0
2972 (match-beginning 0))
2973 "." html-extension))
2974 (if (and search
2975 ;; make sure this is can be used as target search
2976 (not (string-match "^[0-9]*$" search))
2977 (not (string-match "^\\*" search))
2978 (not (string-match "^/.*/$" search)))
2979 (setq thefile (concat thefile "#"
2980 (org-solidify-link-text
2981 (org-link-unescape search)))))
2982 (when (string-match "^file:" desc)
2983 (setq desc (replace-match "" t t desc))
2984 (if (string-match "\\.org$" desc)
2985 (setq desc (replace-match "" t t desc))))))
2986 (setq rpl (if (and file-is-image-p
2987 (or (eq t org-export-html-inline-images)
2988 (and org-export-html-inline-images
2989 (not descp))))
2990 (concat "<img src=\"" thefile "\"/>")
2991 (concat "<a href=\"" thefile "\">" desc "</a>")))
2992 (if (not valid) (setq rpl desc))))
2994 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2995 (setq rpl
2996 (save-match-data
2997 (funcall fnc (org-link-unescape path) desc1 'html))))
3000 ;; just publish the path, as default
3001 (setq rpl (concat "<i>&lt;" type ":"
3002 (save-match-data (org-link-unescape path))
3003 "&gt;</i>"))))
3004 (setq line (replace-match rpl t t line)
3005 start (+ start (length rpl))))
3007 ;; TODO items
3008 (if (and (string-match org-todo-line-regexp line)
3009 (match-beginning 2))
3011 (setq line
3012 (concat (substring line 0 (match-beginning 2))
3013 "<span class=\""
3014 (if (member (match-string 2 line)
3015 org-done-keywords)
3016 "done" "todo")
3017 "\">" (match-string 2 line)
3018 "</span>" (substring line (match-end 2)))))
3020 ;; Does this contain a reference to a footnote?
3021 (when org-export-with-footnotes
3022 (setq start 0)
3023 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3024 (if (get-text-property (match-beginning 2) 'org-protected line)
3025 (setq start (match-end 2))
3026 (let ((n (match-string 2 line)))
3027 (setq line
3028 (replace-match
3029 (format
3030 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3031 (match-string 1 line) n n n)
3032 t t line))))))
3034 (cond
3035 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3036 ;; This is a headline
3037 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3038 txt (match-string 2 line))
3039 (if (string-match quote-re0 txt)
3040 (setq txt (replace-match "" t t txt)))
3041 (if (<= level (max umax umax-toc))
3042 (setq head-count (+ head-count 1)))
3043 (when in-local-list
3044 ;; Close any local lists before inserting a new header line
3045 (while local-list-type
3046 (org-close-li (car local-list-type))
3047 (insert (format "</%sl>\n" (car local-list-type)))
3048 (pop local-list-type))
3049 (setq local-list-indent nil
3050 in-local-list nil))
3051 (setq first-heading-pos (or first-heading-pos (point)))
3052 (org-html-level-start level txt umax
3053 (and org-export-with-toc (<= level umax))
3054 head-count)
3055 ;; QUOTES
3056 (when (string-match quote-re line)
3057 (insert "<pre>")
3058 (setq inquote t)))
3060 ((and org-export-with-tables
3061 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3062 (if (not table-open)
3063 ;; New table starts
3064 (setq table-open t table-buffer nil table-orig-buffer nil))
3065 ;; Accumulate lines
3066 (setq table-buffer (cons line table-buffer)
3067 table-orig-buffer (cons origline table-orig-buffer))
3068 (when (or (not lines)
3069 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3070 (car lines))))
3071 (setq table-open nil
3072 table-buffer (nreverse table-buffer)
3073 table-orig-buffer (nreverse table-orig-buffer))
3074 (org-close-par-maybe)
3075 (insert (org-format-table-html table-buffer table-orig-buffer))))
3077 ;; Normal lines
3078 (when (string-match
3079 (cond
3080 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3081 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3082 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3083 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3084 line)
3085 (setq ind (org-get-string-indentation line)
3086 item-type (if (match-beginning 4) "o" "u")
3087 starter (if (match-beginning 2)
3088 (substring (match-string 2 line) 0 -1))
3089 line (substring line (match-beginning 5))
3090 item-tag nil)
3091 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3092 (setq item-type "d"
3093 item-tag (match-string 1 line)
3094 line (substring line (match-end 0))))
3095 (when (and (not (equal item-type "d"))
3096 (not (string-match "[^ \t]" line)))
3097 ;; empty line. Pretend indentation is large.
3098 (setq ind (if org-empty-line-terminates-plain-lists
3100 (1+ (or (car local-list-indent) 1)))))
3101 (setq didclose nil)
3102 (while (and in-local-list
3103 (or (and (= ind (car local-list-indent))
3104 (not starter))
3105 (< ind (car local-list-indent))))
3106 (setq didclose t)
3107 (org-close-li (car local-list-type))
3108 (insert (format "</%sl>\n" (car local-list-type)))
3109 (pop local-list-type) (pop local-list-indent)
3110 (setq in-local-list local-list-indent))
3111 (cond
3112 ((and starter
3113 (or (not in-local-list)
3114 (> ind (car local-list-indent))))
3115 ;; Start new (level of) list
3116 (org-close-par-maybe)
3117 (insert (cond
3118 ((equal item-type "u") "<ul>\n<li>\n")
3119 ((equal item-type "o") "<ol>\n<li>\n")
3120 ((equal item-type "d")
3121 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3122 (push item-type local-list-type)
3123 (push ind local-list-indent)
3124 (setq in-local-list t))
3125 (starter
3126 ;; continue current list
3127 (org-close-li (car local-list-type))
3128 (insert (cond
3129 ((equal (car local-list-type) "d")
3130 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3131 (t "<li>\n"))))
3132 (didclose
3133 ;; we did close a list, normal text follows: need <p>
3134 (org-open-par)))
3135 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3136 (setq line
3137 (replace-match
3138 (if (equal (match-string 1 line) "X")
3139 "<b>[X]</b>"
3140 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3141 t t line))))
3143 ;; Empty lines start a new paragraph. If hand-formatted lists
3144 ;; are not fully interpreted, lines starting with "-", "+", "*"
3145 ;; also start a new paragraph.
3146 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3148 ;; Is this the start of a footnote?
3149 (when org-export-with-footnotes
3150 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3151 (org-close-par-maybe)
3152 (let ((n (match-string 1 line)))
3153 (setq line (replace-match
3154 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3155 (setq line (concat line "</p>")))))
3157 ;; Check if the line break needs to be conserved
3158 (cond
3159 ((string-match "\\\\\\\\[ \t]*$" line)
3160 (setq line (replace-match "<br/>" t t line)))
3161 (org-export-preserve-breaks
3162 (setq line (concat line "<br/>"))))
3164 (insert line "\n")))))
3166 ;; Properly close all local lists and other lists
3167 (when inquote (insert "</pre>\n"))
3168 (when in-local-list
3169 ;; Close any local lists before inserting a new header line
3170 (while local-list-type
3171 (org-close-li (car local-list-type))
3172 (insert (format "</%sl>\n" (car local-list-type)))
3173 (pop local-list-type))
3174 (setq local-list-indent nil
3175 in-local-list nil))
3176 (org-html-level-start 1 nil umax
3177 (and org-export-with-toc (<= level umax))
3178 head-count)
3179 ;; the </div> to lose the last text-... div.
3180 (insert "</div>\n")
3182 (unless body-only
3183 (when (plist-get opt-plist :auto-postamble)
3184 (insert "<div id=\"postamble\">")
3185 (when (and org-export-author-info author)
3186 (insert "<p class=\"author\"> "
3187 (nth 1 lang-words) ": " author "\n")
3188 (when email
3189 (if (listp (split-string email ",+ *"))
3190 (mapc (lambda(e)
3191 (insert "<a href=\"mailto:" e "\">&lt;"
3192 e "&gt;</a>\n"))
3193 (split-string email ",+ *"))
3194 (insert "<a href=\"mailto:" email "\">&lt;"
3195 email "&gt;</a>\n")))
3196 (insert "</p>\n"))
3197 (when (and date org-export-time-stamp-file)
3198 (insert "<p class=\"date\"> "
3199 (nth 2 lang-words) ": "
3200 date "</p>\n"))
3201 (insert "</div>"))
3203 (if org-export-html-with-timestamp
3204 (insert org-export-html-html-helper-timestamp))
3205 (insert (or (plist-get opt-plist :postamble) ""))
3206 (insert "</body>\n</html>\n"))
3208 (normal-mode)
3209 (if (eq major-mode default-major-mode) (html-mode))
3211 ;; insert the table of contents
3212 (goto-char (point-min))
3213 (when thetoc
3214 (if (or (re-search-forward
3215 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3216 (re-search-forward
3217 "\\[TABLE-OF-CONTENTS\\]" nil t))
3218 (progn
3219 (goto-char (match-beginning 0))
3220 (replace-match ""))
3221 (goto-char first-heading-pos)
3222 (when (looking-at "\\s-*</p>")
3223 (goto-char (match-end 0))
3224 (insert "\n")))
3225 (insert "<div id=\"table-of-contents\">\n")
3226 (mapc 'insert thetoc)
3227 (insert "</div>\n"))
3228 ;; remove empty paragraphs and lists
3229 (goto-char (point-min))
3230 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3231 (replace-match ""))
3232 (goto-char (point-min))
3233 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3234 (replace-match ""))
3235 (goto-char (point-min))
3236 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3237 (replace-match ""))
3238 ;; Convert whitespace place holders
3239 (goto-char (point-min))
3240 (let (beg end n)
3241 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3242 (setq n (get-text-property beg 'org-whitespace)
3243 end (next-single-property-change beg 'org-whitespace))
3244 (goto-char beg)
3245 (delete-region beg end)
3246 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3247 (make-string n ?x)))))
3248 (or to-buffer (save-buffer))
3249 (goto-char (point-min))
3250 (message "Exporting... done")
3251 (if (eq to-buffer 'string)
3252 (prog1 (buffer-substring (point-min) (point-max))
3253 (kill-buffer (current-buffer)))
3254 (current-buffer)))))
3256 (defvar org-table-colgroup-info nil)
3257 (defun org-format-table-ascii (lines)
3258 "Format a table for ascii export."
3259 (if (stringp lines)
3260 (setq lines (org-split-string lines "\n")))
3261 (if (not (string-match "^[ \t]*|" (car lines)))
3262 ;; Table made by table.el - test for spanning
3263 lines
3265 ;; A normal org table
3266 ;; Get rid of hlines at beginning and end
3267 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3268 (setq lines (nreverse lines))
3269 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3270 (setq lines (nreverse lines))
3271 (when org-export-table-remove-special-lines
3272 ;; Check if the table has a marking column. If yes remove the
3273 ;; column and the special lines
3274 (setq lines (org-table-clean-before-export lines)))
3275 ;; Get rid of the vertical lines except for grouping
3276 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3277 rtn line vl1 start)
3278 (while (setq line (pop lines))
3279 (if (string-match org-table-hline-regexp line)
3280 (and (string-match "|\\(.*\\)|" line)
3281 (setq line (replace-match " \\1" t nil line)))
3282 (setq start 0 vl1 vl)
3283 (while (string-match "|" line start)
3284 (setq start (match-end 0))
3285 (or (pop vl1) (setq line (replace-match " " t t line)))))
3286 (push line rtn))
3287 (nreverse rtn))))
3289 (defun org-colgroup-info-to-vline-list (info)
3290 (let (vl new last)
3291 (while info
3292 (setq last new new (pop info))
3293 (if (or (memq last '(:end :startend))
3294 (memq new '(:start :startend)))
3295 (push t vl)
3296 (push nil vl)))
3297 (setq vl (nreverse vl))
3298 (and vl (setcar vl nil))
3299 vl))
3301 (defvar org-table-number-regexp) ; defined in org-table.el
3302 (defun org-format-table-html (lines olines)
3303 "Find out which HTML converter to use and return the HTML code."
3304 (if (stringp lines)
3305 (setq lines (org-split-string lines "\n")))
3306 (if (string-match "^[ \t]*|" (car lines))
3307 ;; A normal org table
3308 (org-format-org-table-html lines)
3309 ;; Table made by table.el - test for spanning
3310 (let* ((hlines (delq nil (mapcar
3311 (lambda (x)
3312 (if (string-match "^[ \t]*\\+-" x) x
3313 nil))
3314 lines)))
3315 (first (car hlines))
3316 (ll (and (string-match "\\S-+" first)
3317 (match-string 0 first)))
3318 (re (concat "^[ \t]*" (regexp-quote ll)))
3319 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3320 hlines))))
3321 (if (and (not spanning)
3322 (not org-export-prefer-native-exporter-for-tables))
3323 ;; We can use my own converter with HTML conversions
3324 (org-format-table-table-html lines)
3325 ;; Need to use the code generator in table.el, with the original text.
3326 (org-format-table-table-html-using-table-generate-source olines)))))
3328 (defvar org-table-number-fraction) ; defined in org-table.el
3329 (defun org-format-org-table-html (lines &optional splice)
3330 "Format a table into HTML."
3331 (require 'org-table)
3332 ;; Get rid of hlines at beginning and end
3333 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3334 (setq lines (nreverse lines))
3335 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3336 (setq lines (nreverse lines))
3337 (when org-export-table-remove-special-lines
3338 ;; Check if the table has a marking column. If yes remove the
3339 ;; column and the special lines
3340 (setq lines (org-table-clean-before-export lines)))
3342 (let ((head (and org-export-highlight-first-table-line
3343 (delq nil (mapcar
3344 (lambda (x) (string-match "^[ \t]*|-" x))
3345 (cdr lines)))))
3346 (nlines 0) fnum i
3347 tbopen line fields html gr colgropen)
3348 (if splice (setq head nil))
3349 (unless splice (push (if head "<thead>" "<tbody>") html))
3350 (setq tbopen t)
3351 (while (setq line (pop lines))
3352 (catch 'next-line
3353 (if (string-match "^[ \t]*|-" line)
3354 (progn
3355 (unless splice
3356 (push (if head "</thead>" "</tbody>") html)
3357 (if lines (push "<tbody>" html) (setq tbopen nil)))
3358 (setq head nil) ;; head ends here, first time around
3359 ;; ignore this line
3360 (throw 'next-line t)))
3361 ;; Break the line into fields
3362 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3363 (unless fnum (setq fnum (make-vector (length fields) 0)))
3364 (setq nlines (1+ nlines) i -1)
3365 (push (concat "<tr>"
3366 (mapconcat
3367 (lambda (x)
3368 (setq i (1+ i))
3369 (if (and (< i nlines)
3370 (string-match org-table-number-regexp x))
3371 (incf (aref fnum i)))
3372 (if head
3373 (concat (car org-export-table-header-tags) x
3374 (cdr org-export-table-header-tags))
3375 (concat (car org-export-table-data-tags) x
3376 (cdr org-export-table-data-tags))))
3377 fields "")
3378 "</tr>")
3379 html)))
3380 (unless splice (if tbopen (push "</tbody>" html)))
3381 (unless splice (push "</table>\n" html))
3382 (setq html (nreverse html))
3383 (unless splice
3384 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3385 (push (mapconcat
3386 (lambda (x)
3387 (setq gr (pop org-table-colgroup-info))
3388 (format "%s<col align=\"%s\"></col>%s"
3389 (if (memq gr '(:start :startend))
3390 (prog1
3391 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3392 (setq colgropen t))
3394 (if (> (/ (float x) nlines) org-table-number-fraction)
3395 "right" "left")
3396 (if (memq gr '(:end :startend))
3397 (progn (setq colgropen nil) "</colgroup>")
3398 "")))
3399 fnum "")
3400 html)
3401 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3402 (push html-table-tag html))
3403 (concat (mapconcat 'identity html "\n") "\n")))
3405 (defun org-table-clean-before-export (lines)
3406 "Check if the table has a marking column.
3407 If yes remove the column and the special lines."
3408 (setq org-table-colgroup-info nil)
3409 (if (memq nil
3410 (mapcar
3411 (lambda (x) (or (string-match "^[ \t]*|-" x)
3412 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3413 lines))
3414 (progn
3415 (setq org-table-clean-did-remove-column nil)
3416 (delq nil
3417 (mapcar
3418 (lambda (x)
3419 (cond
3420 ((string-match "^[ \t]*| */ *|" x)
3421 (setq org-table-colgroup-info
3422 (mapcar (lambda (x)
3423 (cond ((member x '("<" "&lt;")) :start)
3424 ((member x '(">" "&gt;")) :end)
3425 ((member x '("<>" "&lt;&gt;")) :startend)
3426 (t nil)))
3427 (org-split-string x "[ \t]*|[ \t]*")))
3428 nil)
3429 (t x)))
3430 lines)))
3431 (setq org-table-clean-did-remove-column t)
3432 (delq nil
3433 (mapcar
3434 (lambda (x)
3435 (cond
3436 ((string-match "^[ \t]*| */ *|" x)
3437 (setq org-table-colgroup-info
3438 (mapcar (lambda (x)
3439 (cond ((member x '("<" "&lt;")) :start)
3440 ((member x '(">" "&gt;")) :end)
3441 ((member x '("<>" "&lt;&gt;")) :startend)
3442 (t nil)))
3443 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3444 nil)
3445 ((string-match "^[ \t]*| *[!_^/] *|" x)
3446 nil) ; ignore this line
3447 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3448 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3449 ;; remove the first column
3450 (replace-match "\\1|" t nil x))))
3451 lines))))
3453 (defun org-format-table-table-html (lines)
3454 "Format a table generated by table.el into HTML.
3455 This conversion does *not* use `table-generate-source' from table.el.
3456 This has the advantage that Org-mode's HTML conversions can be used.
3457 But it has the disadvantage, that no cell- or row-spanning is allowed."
3458 (let (line field-buffer
3459 (head org-export-highlight-first-table-line)
3460 fields html empty)
3461 (setq html (concat html-table-tag "\n"))
3462 (while (setq line (pop lines))
3463 (setq empty "&nbsp;")
3464 (catch 'next-line
3465 (if (string-match "^[ \t]*\\+-" line)
3466 (progn
3467 (if field-buffer
3468 (progn
3469 (setq
3470 html
3471 (concat
3472 html
3473 "<tr>"
3474 (mapconcat
3475 (lambda (x)
3476 (if (equal x "") (setq x empty))
3477 (if head
3478 (concat (car org-export-table-header-tags) x
3479 (cdr org-export-table-header-tags))
3480 (concat (car org-export-table-data-tags) x
3481 (cdr org-export-table-data-tags))))
3482 field-buffer "\n")
3483 "</tr>\n"))
3484 (setq head nil)
3485 (setq field-buffer nil)))
3486 ;; Ignore this line
3487 (throw 'next-line t)))
3488 ;; Break the line into fields and store the fields
3489 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3490 (if field-buffer
3491 (setq field-buffer (mapcar
3492 (lambda (x)
3493 (concat x "<br/>" (pop fields)))
3494 field-buffer))
3495 (setq field-buffer fields))))
3496 (setq html (concat html "</table>\n"))
3497 html))
3499 (defun org-format-table-table-html-using-table-generate-source (lines)
3500 "Format a table into html, using `table-generate-source' from table.el.
3501 This has the advantage that cell- or row-spanning is allowed.
3502 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3503 (require 'table)
3504 (with-current-buffer (get-buffer-create " org-tmp1 ")
3505 (erase-buffer)
3506 (insert (mapconcat 'identity lines "\n"))
3507 (goto-char (point-min))
3508 (if (not (re-search-forward "|[^+]" nil t))
3509 (error "Error processing table"))
3510 (table-recognize-table)
3511 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3512 (table-generate-source 'html " org-tmp2 ")
3513 (set-buffer " org-tmp2 ")
3514 (buffer-substring (point-min) (point-max))))
3516 (defun org-html-handle-time-stamps (s)
3517 "Format time stamps in string S, or remove them."
3518 (catch 'exit
3519 (let (r b)
3520 (while (string-match org-maybe-keyword-time-regexp s)
3521 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3522 ;; never export CLOCK
3523 (throw 'exit ""))
3524 (or b (setq b (substring s 0 (match-beginning 0))))
3525 (if (not org-export-with-timestamps)
3526 (setq r (concat r (substring s 0 (match-beginning 0)))
3527 s (substring s (match-end 0)))
3528 (setq r (concat
3529 r (substring s 0 (match-beginning 0))
3530 (if (match-end 1)
3531 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3532 (match-string 1 s)))
3533 (format " @<span class=\"timestamp\">%s@</span>"
3534 (substring
3535 (org-translate-time (match-string 3 s)) 1 -1)))
3536 s (substring s (match-end 0)))))
3537 ;; Line break if line started and ended with time stamp stuff
3538 (if (not r)
3540 (setq r (concat r s))
3541 (unless (string-match "\\S-" (concat b s))
3542 (setq r (concat r "@<br/>")))
3543 r))))
3545 (defun org-export-htmlize-region-for-paste (beg end)
3546 "Convert the region to HTML, using htmlize.el.
3547 This is much like `htmlize-region-for-paste', only that it uses
3548 the settings define in the org-... variables."
3549 (let* ((htmlize-output-type org-export-htmlize-output-type)
3550 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3551 (htmlbuf (htmlize-region beg end)))
3552 (unwind-protect
3553 (with-current-buffer htmlbuf
3554 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3555 (plist-get htmlize-buffer-places 'content-end)))
3556 (kill-buffer htmlbuf))))
3558 ;;;###autoload
3559 (defun org-export-htmlize-generate-css ()
3560 "Create the CSS for all font definitions in the current Emacs session.
3561 Use this to create face definitions in your CSS style file that can then
3562 be used by code snippets transformed by htmlize.
3563 This command just produces a buffer that contains class definitions for all
3564 faces used in the current Emacs session. You can copy and paste the ones you
3565 need into your CSS file.
3567 If you then set `org-export-htmlize-output-type' to `css', calls to
3568 the function `org-export-htmlize-region-for-paste' will produce code
3569 that uses these same face definitions."
3570 (interactive)
3571 (require 'htmlize)
3572 (and (get-buffer "*html*") (kill-buffer "*html*"))
3573 (with-temp-buffer
3574 (let ((fl (face-list))
3575 (htmlize-css-name-prefix "org-")
3576 (htmlize-output-type 'css)
3577 f i)
3578 (while (setq f (pop fl)
3579 i (and f (face-attribute f :inherit)))
3580 (when (and (symbolp f) (or (not i) (not (listp i))))
3581 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3582 (htmlize-region (point-min) (point-max))))
3583 (switch-to-buffer "*html*")
3584 (goto-char (point-min))
3585 (if (re-search-forward "<style" nil t)
3586 (delete-region (point-min) (match-beginning 0)))
3587 (if (re-search-forward "</style>" nil t)
3588 (delete-region (1+ (match-end 0)) (point-max)))
3589 (beginning-of-line 1)
3590 (if (looking-at " +") (replace-match ""))
3591 (goto-char (point-min)))
3593 (defun org-html-protect (s)
3594 ;; convert & to &amp;, < to &lt; and > to &gt;
3595 (let ((start 0))
3596 (while (string-match "&" s start)
3597 (setq s (replace-match "&amp;" t t s)
3598 start (1+ (match-beginning 0))))
3599 (while (string-match "<" s)
3600 (setq s (replace-match "&lt;" t t s)))
3601 (while (string-match ">" s)
3602 (setq s (replace-match "&gt;" t t s))))
3605 (defun org-export-cleanup-toc-line (s)
3606 "Remove tags and time staps from lines going into the toc."
3607 (when (memq org-export-with-tags '(not-in-toc nil))
3608 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3609 (setq s (replace-match "" t t s))))
3610 (when org-export-remove-timestamps-from-toc
3611 (while (string-match org-maybe-keyword-time-regexp s)
3612 (setq s (replace-match "" t t s))))
3613 (while (string-match org-bracket-link-regexp s)
3614 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3615 t t s)))
3618 (defun org-html-expand (string)
3619 "Prepare STRING for HTML export. Applies all active conversions.
3620 If there are links in the string, don't modify these."
3621 (let* ((re (concat org-bracket-link-regexp "\\|"
3622 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3623 m s l res)
3624 (while (setq m (string-match re string))
3625 (setq s (substring string 0 m)
3626 l (match-string 0 string)
3627 string (substring string (match-end 0)))
3628 (push (org-html-do-expand s) res)
3629 (push l res))
3630 (push (org-html-do-expand string) res)
3631 (apply 'concat (nreverse res))))
3633 (defun org-html-do-expand (s)
3634 "Apply all active conversions to translate special ASCII to HTML."
3635 (setq s (org-html-protect s))
3636 (if org-export-html-expand
3637 (let ((start 0))
3638 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3639 (setq s (replace-match "<\\1>" t nil s)))))
3640 (if org-export-with-emphasize
3641 (setq s (org-export-html-convert-emphasize s)))
3642 (if org-export-with-special-strings
3643 (setq s (org-export-html-convert-special-strings s)))
3644 (if org-export-with-sub-superscripts
3645 (setq s (org-export-html-convert-sub-super s)))
3646 (if org-export-with-TeX-macros
3647 (let ((start 0) wd ass)
3648 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3649 (if (get-text-property (match-beginning 0) 'org-protected s)
3650 (setq start (match-end 0))
3651 (setq wd (match-string 1 s))
3652 (if (setq ass (assoc wd org-html-entities))
3653 (setq s (replace-match (or (cdr ass)
3654 (concat "&" (car ass) ";"))
3655 t t s))
3656 (setq start (+ start (length wd))))))))
3659 (defun org-create-multibrace-regexp (left right n)
3660 "Create a regular expression which will match a balanced sexp.
3661 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3662 as single character strings.
3663 The regexp returned will match the entire expression including the
3664 delimiters. It will also define a single group which contains the
3665 match except for the outermost delimiters. The maximum depth of
3666 stacked delimiters is N. Escaping delimiters is not possible."
3667 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3668 (or "\\|")
3669 (re nothing)
3670 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3671 (while (> n 1)
3672 (setq n (1- n)
3673 re (concat re or next)
3674 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3675 (concat left "\\(" re "\\)" right)))
3677 (defvar org-match-substring-regexp
3678 (concat
3679 "\\([^\\]\\)\\([_^]\\)\\("
3680 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3681 "\\|"
3682 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3683 "\\|"
3684 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3685 "The regular expression matching a sub- or superscript.")
3687 (defvar org-match-substring-with-braces-regexp
3688 (concat
3689 "\\([^\\]\\)\\([_^]\\)\\("
3690 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3691 "\\)")
3692 "The regular expression matching a sub- or superscript, forcing braces.")
3694 (defconst org-export-html-special-string-regexps
3695 '(("\\\\-" . "&shy;")
3696 ("---\\([^-]\\)" . "&mdash;\\1")
3697 ("--\\([^-]\\)" . "&ndash;\\1")
3698 ("\\.\\.\\." . "&hellip;"))
3699 "Regular expressions for special string conversion.")
3701 (defun org-export-html-convert-special-strings (string)
3702 "Convert special characters in STRING to HTML."
3703 (let ((all org-export-html-special-string-regexps)
3704 e a re rpl start)
3705 (while (setq a (pop all))
3706 (setq re (car a) rpl (cdr a) start 0)
3707 (while (string-match re string start)
3708 (if (get-text-property (match-beginning 0) 'org-protected string)
3709 (setq start (match-end 0))
3710 (setq string (replace-match rpl t nil string)))))
3711 string))
3713 (defun org-export-html-convert-sub-super (string)
3714 "Convert sub- and superscripts in STRING to HTML."
3715 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3716 (while (string-match org-match-substring-regexp string s)
3717 (cond
3718 ((and requireb (match-end 8)) (setq s (match-end 2)))
3719 ((get-text-property (match-beginning 2) 'org-protected string)
3720 (setq s (match-end 2)))
3722 (setq s (match-end 1)
3723 key (if (string= (match-string 2 string) "_") "sub" "sup")
3724 c (or (match-string 8 string)
3725 (match-string 6 string)
3726 (match-string 5 string))
3727 string (replace-match
3728 (concat (match-string 1 string)
3729 "<" key ">" c "</" key ">")
3730 t t string)))))
3731 (while (string-match "\\\\\\([_^]\\)" string)
3732 (setq string (replace-match (match-string 1 string) t t string)))
3733 string))
3735 (defun org-export-html-convert-emphasize (string)
3736 "Apply emphasis."
3737 (let ((s 0) rpl)
3738 (while (string-match org-emph-re string s)
3739 (if (not (equal
3740 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3741 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3742 (setq s (match-beginning 0)
3744 (concat
3745 (match-string 1 string)
3746 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3747 (match-string 4 string)
3748 (nth 3 (assoc (match-string 3 string)
3749 org-emphasis-alist))
3750 (match-string 5 string))
3751 string (replace-match rpl t t string)
3752 s (+ s (- (length rpl) 2)))
3753 (setq s (1+ s))))
3754 string))
3756 (defvar org-par-open nil)
3757 (defun org-open-par ()
3758 "Insert <p>, but first close previous paragraph if any."
3759 (org-close-par-maybe)
3760 (insert "\n<p>")
3761 (setq org-par-open t))
3762 (defun org-close-par-maybe ()
3763 "Close paragraph if there is one open."
3764 (when org-par-open
3765 (insert "</p>")
3766 (setq org-par-open nil)))
3767 (defun org-close-li (&optional type)
3768 "Close <li> if necessary."
3769 (org-close-par-maybe)
3770 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
3772 (defvar body-only) ; dynamically scoped into this.
3773 (defun org-html-level-start (level title umax with-toc head-count)
3774 "Insert a new level in HTML export.
3775 When TITLE is nil, just close all open levels."
3776 (org-close-par-maybe)
3777 (let ((target (and title (org-get-text-property-any 0 'target title)))
3778 (l org-level-max)
3779 snumber)
3780 (while (>= l level)
3781 (if (aref org-levels-open (1- l))
3782 (progn
3783 (org-html-level-close l umax)
3784 (aset org-levels-open (1- l) nil)))
3785 (setq l (1- l)))
3786 (when title
3787 ;; If title is nil, this means this function is called to close
3788 ;; all levels, so the rest is done only if title is given
3789 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3790 (setq title (replace-match
3791 (if org-export-with-tags
3792 (save-match-data
3793 (concat
3794 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3795 (mapconcat 'identity (org-split-string
3796 (match-string 1 title) ":")
3797 "&nbsp;")
3798 "</span>"))
3800 t t title)))
3801 (if (> level umax)
3802 (progn
3803 (if (aref org-levels-open (1- level))
3804 (progn
3805 (org-close-li)
3806 (if target
3807 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3808 (insert "<li>" title "<br/>\n")))
3809 (aset org-levels-open (1- level) t)
3810 (org-close-par-maybe)
3811 (if target
3812 (insert (format "<ul>\n<li id=\"%s\">" target)
3813 title "<br/>\n")
3814 (insert "<ul>\n<li>" title "<br/>\n"))))
3815 (aset org-levels-open (1- level) t)
3816 (setq snumber (org-section-number level))
3817 (if (and org-export-with-section-numbers (not body-only))
3818 (setq title (concat snumber " " title)))
3819 (setq level (+ level org-export-html-toplevel-hlevel -1))
3820 (unless (= head-count 1) (insert "\n</div>\n"))
3821 (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"
3822 snumber level level snumber title level snumber))
3823 (org-open-par)))))
3825 (defun org-get-text-property-any (pos prop &optional object)
3826 (or (get-text-property pos prop object)
3827 (and (setq pos (next-single-property-change pos prop object))
3828 (get-text-property pos prop object))))
3830 (defun org-html-level-close (level max-outline-level)
3831 "Terminate one level in HTML export."
3832 (if (<= level max-outline-level)
3833 (insert "</div>\n")
3834 (org-close-li)
3835 (insert "</ul>\n")))
3837 ;;; iCalendar export
3839 ;;;###autoload
3840 (defun org-export-icalendar-this-file ()
3841 "Export current file as an iCalendar file.
3842 The iCalendar file will be located in the same directory as the Org-mode
3843 file, but with extension `.ics'."
3844 (interactive)
3845 (org-export-icalendar nil buffer-file-name))
3847 ;;;###autoload
3848 (defun org-export-icalendar-all-agenda-files ()
3849 "Export all files in `org-agenda-files' to iCalendar .ics files.
3850 Each iCalendar file will be located in the same directory as the Org-mode
3851 file, but with extension `.ics'."
3852 (interactive)
3853 (apply 'org-export-icalendar nil (org-agenda-files t)))
3855 ;;;###autoload
3856 (defun org-export-icalendar-combine-agenda-files ()
3857 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3858 The file is stored under the name `org-combined-agenda-icalendar-file'."
3859 (interactive)
3860 (apply 'org-export-icalendar t (org-agenda-files t)))
3862 (defun org-export-icalendar (combine &rest files)
3863 "Create iCalendar files for all elements of FILES.
3864 If COMBINE is non-nil, combine all calendar entries into a single large
3865 file and store it under the name `org-combined-agenda-icalendar-file'."
3866 (save-excursion
3867 (org-prepare-agenda-buffers files)
3868 (let* ((dir (org-export-directory
3869 :ical (list :publishing-directory
3870 org-export-publishing-directory)))
3871 file ical-file ical-buffer category started org-agenda-new-buffers)
3872 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3873 (when combine
3874 (setq ical-file
3875 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3876 org-combined-agenda-icalendar-file
3877 (expand-file-name org-combined-agenda-icalendar-file dir))
3878 ical-buffer (org-get-agenda-file-buffer ical-file))
3879 (set-buffer ical-buffer) (erase-buffer))
3880 (while (setq file (pop files))
3881 (catch 'nextfile
3882 (org-check-agenda-file file)
3883 (set-buffer (org-get-agenda-file-buffer file))
3884 (unless combine
3885 (setq ical-file (concat (file-name-as-directory dir)
3886 (file-name-sans-extension
3887 (file-name-nondirectory buffer-file-name))
3888 ".ics"))
3889 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3890 (with-current-buffer ical-buffer (erase-buffer)))
3891 (setq category (or org-category
3892 (file-name-sans-extension
3893 (file-name-nondirectory buffer-file-name))))
3894 (if (symbolp category) (setq category (symbol-name category)))
3895 (let ((standard-output ical-buffer))
3896 (if combine
3897 (and (not started) (setq started t)
3898 (org-start-icalendar-file org-icalendar-combined-name))
3899 (org-start-icalendar-file category))
3900 (org-print-icalendar-entries combine)
3901 (when (or (and combine (not files)) (not combine))
3902 (org-finish-icalendar-file)
3903 (set-buffer ical-buffer)
3904 (save-buffer)
3905 (run-hooks 'org-after-save-iCalendar-file-hook)
3906 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
3907 ))))
3908 (org-release-buffers org-agenda-new-buffers))))
3910 (defvar org-after-save-iCalendar-file-hook nil
3911 "Hook run after an iCalendar file has been saved.
3912 The iCalendar buffer is still current when this hook is run.
3913 A good way to use this is to tell a desktop calenndar application to re-read
3914 the iCalendar file.")
3916 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3917 (defun org-print-icalendar-entries (&optional combine)
3918 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3919 When COMBINE is non nil, add the category to each line."
3920 (require 'org-agenda)
3921 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3922 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3923 (dts (org-ical-ts-to-string
3924 (format-time-string (cdr org-time-stamp-formats) (current-time))
3925 "DTSTART"))
3926 hd ts ts2 state status (inc t) pos b sexp rrule
3927 scheduledp deadlinep prefix
3928 tmp pri category entry location summary desc uid
3929 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3930 (org-refresh-category-properties)
3931 (save-excursion
3932 (goto-char (point-min))
3933 (while (re-search-forward re1 nil t)
3934 (catch :skip
3935 (org-agenda-skip)
3936 (when (boundp 'org-icalendar-verify-function)
3937 (unless (funcall org-icalendar-verify-function)
3938 (outline-next-heading)
3939 (backward-char 1)
3940 (throw :skip nil)))
3941 (setq pos (match-beginning 0)
3942 ts (match-string 0)
3943 inc t
3944 hd (condition-case nil
3945 (org-icalendar-cleanup-string
3946 (org-get-heading))
3947 (error (throw :skip nil)))
3948 summary (org-icalendar-cleanup-string
3949 (org-entry-get nil "SUMMARY"))
3950 desc (org-icalendar-cleanup-string
3951 (or (org-entry-get nil "DESCRIPTION")
3952 (and org-icalendar-include-body (org-get-entry)))
3953 t org-icalendar-include-body)
3954 location (org-icalendar-cleanup-string
3955 (org-entry-get nil "LOCATION"))
3956 uid (if org-icalendar-store-UID
3957 (org-id-get-create)
3958 (or (org-id-get) (org-id-new)))
3959 category (org-get-category)
3960 deadlinep nil scheduledp nil)
3961 (if (looking-at re2)
3962 (progn
3963 (goto-char (match-end 0))
3964 (setq ts2 (match-string 1)
3965 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
3966 (setq tmp (buffer-substring (max (point-min)
3967 (- pos org-ds-keyword-length))
3968 pos)
3969 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3970 (progn
3971 (setq inc nil)
3972 (replace-match "\\1" t nil ts))
3974 deadlinep (string-match org-deadline-regexp tmp)
3975 scheduledp (string-match org-scheduled-regexp tmp)
3976 ;; donep (org-entry-is-done-p)
3978 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
3979 (if (or (string-match org-tr-regexp hd)
3980 (string-match org-ts-regexp hd))
3981 (setq hd (replace-match "" t t hd)))
3982 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3983 (setq rrule
3984 (concat "\nRRULE:FREQ="
3985 (cdr (assoc
3986 (match-string 2 ts)
3987 '(("d" . "DAILY")("w" . "WEEKLY")
3988 ("m" . "MONTHLY")("y" . "YEARLY"))))
3989 ";INTERVAL=" (match-string 1 ts)))
3990 (setq rrule ""))
3991 (setq summary (or summary hd))
3992 (if (string-match org-bracket-link-regexp summary)
3993 (setq summary
3994 (replace-match (if (match-end 3)
3995 (match-string 3 summary)
3996 (match-string 1 summary))
3997 t t summary)))
3998 (if deadlinep (setq summary (concat "DL: " summary)))
3999 (if scheduledp (setq summary (concat "S: " summary)))
4000 (if (string-match "\\`<%%" ts)
4001 (with-current-buffer sexp-buffer
4002 (insert (substring ts 1 -1) " " summary "\n"))
4003 (princ (format "BEGIN:VEVENT
4004 UID: %s
4006 %s%s
4007 SUMMARY:%s%s%s
4008 CATEGORIES:%s
4009 END:VEVENT\n"
4010 (concat prefix uid)
4011 (org-ical-ts-to-string ts "DTSTART")
4012 (org-ical-ts-to-string ts2 "DTEND" inc)
4013 rrule summary
4014 (if (and desc (string-match "\\S-" desc))
4015 (concat "\nDESCRIPTION: " desc) "")
4016 (if (and location (string-match "\\S-" location))
4017 (concat "\nLOCATION: " location) "")
4018 category)))))
4019 (when (and org-icalendar-include-sexps
4020 (condition-case nil (require 'icalendar) (error nil))
4021 (fboundp 'icalendar-export-region))
4022 ;; Get all the literal sexps
4023 (goto-char (point-min))
4024 (while (re-search-forward "^&?%%(" nil t)
4025 (catch :skip
4026 (org-agenda-skip)
4027 (setq b (match-beginning 0))
4028 (goto-char (1- (match-end 0)))
4029 (forward-sexp 1)
4030 (end-of-line 1)
4031 (setq sexp (buffer-substring b (point)))
4032 (with-current-buffer sexp-buffer
4033 (insert sexp "\n"))))
4034 (princ (org-diary-to-ical-string sexp-buffer))
4035 (kill-buffer sexp-buffer))
4037 (when org-icalendar-include-todo
4038 (setq prefix "TODO-")
4039 (goto-char (point-min))
4040 (while (re-search-forward org-todo-line-regexp nil t)
4041 (catch :skip
4042 (org-agenda-skip)
4043 (when (boundp 'org-icalendar-verify-function)
4044 (unless (funcall org-icalendar-verify-function)
4045 (outline-next-heading)
4046 (backward-char 1)
4047 (throw :skip nil)))
4048 (setq state (match-string 2))
4049 (setq status (if (member state org-done-keywords)
4050 "COMPLETED" "NEEDS-ACTION"))
4051 (when (and state
4052 (or (not (member state org-done-keywords))
4053 (eq org-icalendar-include-todo 'all))
4054 (not (member org-archive-tag (org-get-tags-at)))
4056 (setq hd (match-string 3)
4057 summary (org-icalendar-cleanup-string
4058 (org-entry-get nil "SUMMARY"))
4059 desc (org-icalendar-cleanup-string
4060 (or (org-entry-get nil "DESCRIPTION")
4061 (and org-icalendar-include-body (org-get-entry)))
4062 t org-icalendar-include-body)
4063 location (org-icalendar-cleanup-string
4064 (org-entry-get nil "LOCATION"))
4065 uid (if org-icalendar-store-UID
4066 (org-id-get-create)
4067 (or (org-id-get) (org-id-new))))
4068 (if (string-match org-bracket-link-regexp hd)
4069 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4070 (match-string 1 hd))
4071 t t hd)))
4072 (if (string-match org-priority-regexp hd)
4073 (setq pri (string-to-char (match-string 2 hd))
4074 hd (concat (substring hd 0 (match-beginning 1))
4075 (substring hd (match-end 1))))
4076 (setq pri org-default-priority))
4077 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4078 (- org-lowest-priority org-highest-priority))))))
4080 (princ (format "BEGIN:VTODO
4081 UID: %s
4083 SUMMARY:%s%s%s
4084 CATEGORIES:%s
4085 SEQUENCE:1
4086 PRIORITY:%d
4087 STATUS:%s
4088 END:VTODO\n"
4089 (concat prefix uid)
4091 (or summary hd)
4092 (if (and location (string-match "\\S-" location))
4093 (concat "\nLOCATION: " location) "")
4094 (if (and desc (string-match "\\S-" desc))
4095 (concat "\nDESCRIPTION: " desc) "")
4096 category
4097 pri status)))))))))
4099 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4100 "Take out stuff and quote what needs to be quoted.
4101 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4102 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4103 characters."
4104 (if (not s)
4106 (when is-body
4107 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4108 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4109 (while (string-match re s) (setq s (replace-match "" t t s)))
4110 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4111 (let ((start 0))
4112 (while (string-match "\\([,;]\\)" s start)
4113 (setq start (+ (match-beginning 0) 2)
4114 s (replace-match "\\\\\\1" nil nil s))))
4115 (when is-body
4116 (while (string-match "[ \t]*\n[ \t]*" s)
4117 (setq s (replace-match "\\n" t t s))))
4118 (setq s (org-trim s))
4119 (if is-body
4120 (if maxlength
4121 (if (and (numberp maxlength)
4122 (> (length s) maxlength))
4123 (setq s (substring s 0 maxlength)))))
4126 (defun org-get-entry ()
4127 "Clean-up description string."
4128 (save-excursion
4129 (org-back-to-heading t)
4130 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4132 (defun org-start-icalendar-file (name)
4133 "Start an iCalendar file by inserting the header."
4134 (let ((user user-full-name)
4135 (name (or name "unknown"))
4136 (timezone (cadr (current-time-zone))))
4137 (princ
4138 (format "BEGIN:VCALENDAR
4139 VERSION:2.0
4140 X-WR-CALNAME:%s
4141 PRODID:-//%s//Emacs with Org-mode//EN
4142 X-WR-TIMEZONE:%s
4143 CALSCALE:GREGORIAN\n" name user timezone))))
4145 (defun org-finish-icalendar-file ()
4146 "Finish an iCalendar file by inserting the END statement."
4147 (princ "END:VCALENDAR\n"))
4149 (defun org-ical-ts-to-string (s keyword &optional inc)
4150 "Take a time string S and convert it to iCalendar format.
4151 KEYWORD is added in front, to make a complete line like DTSTART....
4152 When INC is non-nil, increase the hour by two (if time string contains
4153 a time), or the day by one (if it does not contain a time)."
4154 (let ((t1 (org-parse-time-string s 'nodefault))
4155 t2 fmt have-time time)
4156 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4157 (setq t2 t1 have-time t)
4158 (setq t2 (org-parse-time-string s)))
4159 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4160 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4161 (when inc
4162 (if have-time
4163 (if org-agenda-default-appointment-duration
4164 (setq mi (+ org-agenda-default-appointment-duration mi))
4165 (setq h (+ 2 h)))
4166 (setq d (1+ d))))
4167 (setq time (encode-time s mi h d m y)))
4168 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4169 (concat keyword (format-time-string fmt time))))
4171 ;;; XOXO export
4173 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4174 (with-current-buffer buffer
4175 (apply 'insert output)))
4176 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4178 ;;;###autoload
4179 (defun org-export-as-xoxo (&optional buffer)
4180 "Export the org buffer as XOXO.
4181 The XOXO buffer is named *xoxo-<source buffer name>*"
4182 (interactive (list (current-buffer)))
4183 ;; A quickie abstraction
4185 ;; Output everything as XOXO
4186 (with-current-buffer (get-buffer buffer)
4187 (let* ((pos (point))
4188 (opt-plist (org-combine-plists (org-default-export-plist)
4189 (org-infile-export-plist)))
4190 (filename (concat (file-name-as-directory
4191 (org-export-directory :xoxo opt-plist))
4192 (file-name-sans-extension
4193 (file-name-nondirectory buffer-file-name))
4194 ".html"))
4195 (out (find-file-noselect filename))
4196 (last-level 1)
4197 (hanging-li nil))
4198 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4199 ;; Check the output buffer is empty.
4200 (with-current-buffer out (erase-buffer))
4201 ;; Kick off the output
4202 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4203 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4204 (let* ((hd (match-string-no-properties 1))
4205 (level (length hd))
4206 (text (concat
4207 (match-string-no-properties 2)
4208 (save-excursion
4209 (goto-char (match-end 0))
4210 (let ((str ""))
4211 (catch 'loop
4212 (while 't
4213 (forward-line)
4214 (if (looking-at "^[ \t]\\(.*\\)")
4215 (setq str (concat str (match-string-no-properties 1)))
4216 (throw 'loop str)))))))))
4218 ;; Handle level rendering
4219 (cond
4220 ((> level last-level)
4221 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4223 ((< level last-level)
4224 (dotimes (- (- last-level level) 1)
4225 (if hanging-li
4226 (org-export-as-xoxo-insert-into out "</li>\n"))
4227 (org-export-as-xoxo-insert-into out "</ol>\n"))
4228 (when hanging-li
4229 (org-export-as-xoxo-insert-into out "</li>\n")
4230 (setq hanging-li nil)))
4232 ((equal level last-level)
4233 (if hanging-li
4234 (org-export-as-xoxo-insert-into out "</li>\n")))
4237 (setq last-level level)
4239 ;; And output the new li
4240 (setq hanging-li 't)
4241 (if (equal ?+ (elt text 0))
4242 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4243 (org-export-as-xoxo-insert-into out "<li>" text))))
4245 ;; Finally finish off the ol
4246 (dotimes (- last-level 1)
4247 (if hanging-li
4248 (org-export-as-xoxo-insert-into out "</li>\n"))
4249 (org-export-as-xoxo-insert-into out "</ol>\n"))
4251 (goto-char pos)
4252 ;; Finish the buffer off and clean it up.
4253 (switch-to-buffer-other-window out)
4254 (indent-region (point-min) (point-max) nil)
4255 (save-buffer)
4256 (goto-char (point-min))
4259 (provide 'org-exp)
4261 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4263 ;;; org-exp.el ends here