Release 6.05b.
[org-mode.git] / lisp / org-exp.el
blob6a4a56976bdb4ed623e57fb526462ac25a4a2a42
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.05b
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 (string-width (nth 3 lang-words)) ?=)
2067 "\n") thetoc)
2068 (mapc '(lambda (line)
2069 (if (string-match org-todo-line-regexp
2070 line)
2071 ;; This is a headline
2072 (progn
2073 (setq have-headings t)
2074 (setq level (- (match-end 1) (match-beginning 1))
2075 level (org-tr-level level)
2076 txt (match-string 3 line)
2077 todo
2078 (or (and org-export-mark-todo-in-toc
2079 (match-beginning 2)
2080 (not (member (match-string 2 line)
2081 org-done-keywords)))
2082 ; TODO, not DONE
2083 (and org-export-mark-todo-in-toc
2084 (= level umax-toc)
2085 (org-search-todo-below
2086 line lines level))))
2087 (setq txt (org-html-expand-for-ascii txt))
2089 (while (string-match org-bracket-link-regexp txt)
2090 (setq txt
2091 (replace-match
2092 (match-string (if (match-end 2) 3 1) txt)
2093 t t txt)))
2095 (if (and (memq org-export-with-tags '(not-in-toc nil))
2096 (string-match
2097 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2098 txt))
2099 (setq txt (replace-match "" t t txt)))
2100 (if (string-match quote-re0 txt)
2101 (setq txt (replace-match "" t t txt)))
2103 (if org-export-with-section-numbers
2104 (setq txt (concat (org-section-number level)
2105 " " txt)))
2106 (if (<= level umax-toc)
2107 (progn
2108 (push
2109 (concat
2110 (make-string
2111 (* (max 0 (- level org-min-level)) 4) ?\ )
2112 (format (if todo "%s (*)\n" "%s\n") txt))
2113 thetoc)
2114 (setq org-last-level level))
2115 ))))
2116 lines)
2117 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2119 (org-init-section-numbers)
2120 (while (setq line (pop lines))
2121 ;; Remove the quoted HTML tags.
2122 (setq line (org-html-expand-for-ascii line))
2123 ;; Remove targets
2124 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
2125 (setq line (replace-match "" t t line)))
2126 ;; Replace internal links
2127 (while (string-match org-bracket-link-regexp line)
2128 (setq line (replace-match
2129 (if (match-end 3) "[\\3]" "[\\1]")
2130 t nil line)))
2131 (when custom-times
2132 (setq line (org-translate-time line)))
2133 (cond
2134 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2135 ;; a Headline
2136 (setq first-heading-pos (or first-heading-pos (point)))
2137 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2138 txt (match-string 2 line))
2139 (org-ascii-level-start level txt umax lines))
2141 ((and org-export-with-tables
2142 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2143 (if (not table-open)
2144 ;; New table starts
2145 (setq table-open t table-buffer nil))
2146 ;; Accumulate lines
2147 (setq table-buffer (cons line table-buffer))
2148 (when (or (not lines)
2149 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2150 (car lines))))
2151 (setq table-open nil
2152 table-buffer (nreverse table-buffer))
2153 (insert (mapconcat
2154 (lambda (x)
2155 (org-fix-indentation x org-ascii-current-indentation))
2156 (org-format-table-ascii table-buffer)
2157 "\n") "\n")))
2159 (setq line (org-fix-indentation line org-ascii-current-indentation))
2160 (if (and org-export-with-fixed-width
2161 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2162 (setq line (replace-match "\\1" nil nil line)))
2163 (insert line "\n"))))
2165 (normal-mode)
2167 ;; insert the table of contents
2168 (when thetoc
2169 (goto-char (point-min))
2170 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2171 (progn
2172 (goto-char (match-beginning 0))
2173 (replace-match ""))
2174 (goto-char first-heading-pos))
2175 (mapc 'insert thetoc)
2176 (or (looking-at "[ \t]*\n[ \t]*\n")
2177 (insert "\n\n")))
2179 ;; Convert whitespace place holders
2180 (goto-char (point-min))
2181 (let (beg end)
2182 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2183 (setq end (next-single-property-change beg 'org-whitespace))
2184 (goto-char beg)
2185 (delete-region beg end)
2186 (insert (make-string (- end beg) ?\ ))))
2188 (save-buffer)
2189 ;; remove display and invisible chars
2190 (let (beg end)
2191 (goto-char (point-min))
2192 (while (setq beg (next-single-property-change (point) 'display))
2193 (setq end (next-single-property-change beg 'display))
2194 (delete-region beg end)
2195 (goto-char beg)
2196 (insert "=>"))
2197 (goto-char (point-min))
2198 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2199 (setq end (next-single-property-change beg 'org-cwidth))
2200 (delete-region beg end)
2201 (goto-char beg)))
2202 (goto-char (point-min))))
2204 (defun org-export-ascii-preprocess ()
2205 "Do extra work for ASCII export"
2206 (goto-char (point-min))
2207 (while (re-search-forward org-verbatim-re nil t)
2208 (goto-char (match-end 2))
2209 (backward-delete-char 1) (insert "'")
2210 (goto-char (match-beginning 2))
2211 (delete-char 1) (insert "`")
2212 (goto-char (match-end 2))))
2214 (defun org-search-todo-below (line lines level)
2215 "Search the subtree below LINE for any TODO entries."
2216 (let ((rest (cdr (memq line lines)))
2217 (re org-todo-line-regexp)
2218 line lv todo)
2219 (catch 'exit
2220 (while (setq line (pop rest))
2221 (if (string-match re line)
2222 (progn
2223 (setq lv (- (match-end 1) (match-beginning 1))
2224 todo (and (match-beginning 2)
2225 (not (member (match-string 2 line)
2226 org-done-keywords))))
2227 ; TODO, not DONE
2228 (if (<= lv level) (throw 'exit nil))
2229 (if todo (throw 'exit t))))))))
2231 (defun org-html-expand-for-ascii (line)
2232 "Handle quoted HTML for ASCII export."
2233 (if org-export-html-expand
2234 (while (string-match "@<[^<>\n]*>" line)
2235 ;; We just remove the tags for now.
2236 (setq line (replace-match "" nil nil line))))
2237 line)
2239 (defun org-insert-centered (s &optional underline)
2240 "Insert the string S centered and underline it with character UNDERLINE."
2241 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2242 (insert (make-string ind ?\ ) s "\n")
2243 (if underline
2244 (insert (make-string ind ?\ )
2245 (make-string (string-width s) underline)
2246 "\n"))))
2248 (defun org-ascii-level-start (level title umax &optional lines)
2249 "Insert a new level in ASCII export."
2250 (let (char (n (- level umax 1)) (ind 0))
2251 (if (> level umax)
2252 (progn
2253 (insert (make-string (* 2 n) ?\ )
2254 (char-to-string (nth (% n (length org-export-ascii-bullets))
2255 org-export-ascii-bullets))
2256 " " title "\n")
2257 ;; find the indentation of the next non-empty line
2258 (catch 'stop
2259 (while lines
2260 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2261 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2262 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2263 (pop lines)))
2264 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2265 (if (or (not (equal (char-before) ?\n))
2266 (not (equal (char-before (1- (point))) ?\n)))
2267 (insert "\n"))
2268 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2269 (unless org-export-with-tags
2270 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2271 (setq title (replace-match "" t t title))))
2272 (if org-export-with-section-numbers
2273 (setq title (concat (org-section-number level) " " title)))
2274 (insert title "\n" (make-string (string-width title) char) "\n")
2275 (setq org-ascii-current-indentation '(0 . 0)))))
2277 ;;;###autoload
2278 (defun org-export-visible (type arg)
2279 "Create a copy of the visible part of the current buffer, and export it.
2280 The copy is created in a temporary buffer and removed after use.
2281 TYPE is the final key (as a string) that also select the export command in
2282 the `C-c C-e' export dispatcher.
2283 As a special case, if the you type SPC at the prompt, the temporary
2284 org-mode file will not be removed but presented to you so that you can
2285 continue to use it. The prefix arg ARG is passed through to the exporting
2286 command."
2287 (interactive
2288 (list (progn
2289 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2290 (read-char-exclusive))
2291 current-prefix-arg))
2292 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2293 (error "Invalid export key"))
2294 (let* ((binding (cdr (assoc type
2295 '((?a . org-export-as-ascii)
2296 (?\C-a . org-export-as-ascii)
2297 (?b . org-export-as-html-and-open)
2298 (?\C-b . org-export-as-html-and-open)
2299 (?h . org-export-as-html)
2300 (?H . org-export-as-html-to-buffer)
2301 (?R . org-export-region-as-html)
2302 (?x . org-export-as-xoxo)))))
2303 (keepp (equal type ?\ ))
2304 (file buffer-file-name)
2305 (buffer (get-buffer-create "*Org Export Visible*"))
2306 s e)
2307 ;; Need to hack the drawers here.
2308 (save-excursion
2309 (goto-char (point-min))
2310 (while (re-search-forward org-drawer-regexp nil t)
2311 (goto-char (match-beginning 1))
2312 (or (org-invisible-p) (org-flag-drawer nil))))
2313 (with-current-buffer buffer (erase-buffer))
2314 (save-excursion
2315 (setq s (goto-char (point-min)))
2316 (while (not (= (point) (point-max)))
2317 (goto-char (org-find-invisible))
2318 (append-to-buffer buffer s (point))
2319 (setq s (goto-char (org-find-visible))))
2320 (org-cycle-hide-drawers 'all)
2321 (goto-char (point-min))
2322 (unless keepp
2323 ;; Copy all comment lines to the end, to make sure #+ settings are
2324 ;; still available for the second export step. Kind of a hack, but
2325 ;; does do the trick.
2326 (if (looking-at "#[^\r\n]*")
2327 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2328 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2329 (append-to-buffer buffer (1+ (match-beginning 0))
2330 (min (point-max) (1+ (match-end 0))))))
2331 (set-buffer buffer)
2332 (let ((buffer-file-name file)
2333 (org-inhibit-startup t))
2334 (org-mode)
2335 (show-all)
2336 (unless keepp (funcall binding arg))))
2337 (if (not keepp)
2338 (kill-buffer buffer)
2339 (switch-to-buffer-other-window buffer)
2340 (goto-char (point-min)))))
2342 (defun org-find-visible ()
2343 (let ((s (point)))
2344 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2345 (get-char-property s 'invisible)))
2347 (defun org-find-invisible ()
2348 (let ((s (point)))
2349 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2350 (not (get-char-property s 'invisible))))
2353 ;;; HTML export
2355 (defvar org-archive-location) ;; gets loades with the org-archive require.
2356 (defun org-get-current-options ()
2357 "Return a string with current options as keyword options.
2358 Does include HTML export options as well as TODO and CATEGORY stuff."
2359 (require 'org-archive)
2360 (format
2361 "#+TITLE: %s
2362 #+AUTHOR: %s
2363 #+EMAIL: %s
2364 #+DATE: %s
2365 #+LANGUAGE: %s
2366 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2367 #+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
2369 #+LINK_UP: %s
2370 #+LINK_HOME: %s
2371 #+CATEGORY: %s
2372 #+SEQ_TODO: %s
2373 #+TYP_TODO: %s
2374 #+PRIORITIES: %c %c %c
2375 #+DRAWERS: %s
2376 #+STARTUP: %s %s %s %s %s
2377 #+TAGS: %s
2378 #+FILETAGS: %s
2379 #+ARCHIVE: %s
2380 #+LINK: %s
2382 (buffer-name) (user-full-name) user-mail-address
2383 (format-time-string (car org-time-stamp-formats))
2384 org-export-default-language
2385 org-export-headline-levels
2386 org-export-with-section-numbers
2387 org-export-with-toc
2388 org-export-preserve-breaks
2389 org-export-html-expand
2390 org-export-with-fixed-width
2391 org-export-with-tables
2392 org-export-with-sub-superscripts
2393 org-export-with-special-strings
2394 org-export-with-footnotes
2395 org-export-with-emphasize
2396 org-export-with-TeX-macros
2397 org-export-with-LaTeX-fragments
2398 org-export-skip-text-before-1st-heading
2399 org-export-with-drawers
2400 org-export-with-tags
2401 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2402 org-export-html-link-up
2403 org-export-html-link-home
2404 (file-name-nondirectory buffer-file-name)
2405 "TODO FEEDBACK VERIFY DONE"
2406 "Me Jason Marie DONE"
2407 org-highest-priority org-lowest-priority org-default-priority
2408 (mapconcat 'identity org-drawers " ")
2409 (cdr (assoc org-startup-folded
2410 '((nil . "showall") (t . "overview") (content . "content"))))
2411 (if org-odd-levels-only "odd" "oddeven")
2412 (if org-hide-leading-stars "hidestars" "showstars")
2413 (if org-startup-align-all-tables "align" "noalign")
2414 (cond ((eq org-log-done t) "logdone")
2415 ((equal org-log-done 'note) "lognotedone")
2416 ((not org-log-done) "nologdone"))
2417 (or (mapconcat (lambda (x)
2418 (cond
2419 ((equal '(:startgroup) x) "{")
2420 ((equal '(:endgroup) x) "}")
2421 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2422 (t (car x))))
2423 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2424 (mapconcat 'identity org-file-tags " ")
2425 org-archive-location
2426 "org file:~/org/%s.org"
2429 (defun org-export-html-preprocess (parameters)
2430 ;; Convert LaTeX fragments to images
2431 (when (plist-get parameters :LaTeX-fragments)
2432 (org-format-latex
2433 (concat "ltxpng/" (file-name-sans-extension
2434 (file-name-nondirectory
2435 org-current-export-file)))
2436 org-current-export-dir nil "Creating LaTeX image %s"))
2437 (message "Exporting..."))
2439 ;;;###autoload
2440 (defun org-insert-export-options-template ()
2441 "Insert into the buffer a template with information for exporting."
2442 (interactive)
2443 (if (not (bolp)) (newline))
2444 (let ((s (org-get-current-options)))
2445 (and (string-match "#\\+CATEGORY" s)
2446 (setq s (substring s 0 (match-beginning 0))))
2447 (insert s)))
2449 ;;;###autoload
2450 (defun org-export-as-html-and-open (arg)
2451 "Export the outline as HTML and immediately open it with a browser.
2452 If there is an active region, export only the region.
2453 The prefix ARG specifies how many levels of the outline should become
2454 headlines. The default is 3. Lower levels will become bulleted lists."
2455 (interactive "P")
2456 (org-export-as-html arg 'hidden)
2457 (org-open-file buffer-file-name))
2459 ;;;###autoload
2460 (defun org-export-as-html-batch ()
2461 "Call `org-export-as-html', may be used in batch processing as
2462 emacs --batch
2463 --load=$HOME/lib/emacs/org.el
2464 --eval \"(setq org-export-headline-levels 2)\"
2465 --visit=MyFile --funcall org-export-as-html-batch"
2466 (org-export-as-html org-export-headline-levels 'hidden))
2468 ;;;###autoload
2469 (defun org-export-as-html-to-buffer (arg)
2470 "Call `org-exort-as-html` with output to a temporary buffer.
2471 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2472 (interactive "P")
2473 (org-export-as-html arg nil nil "*Org HTML Export*")
2474 (switch-to-buffer-other-window "*Org HTML Export*"))
2476 ;;;###autoload
2477 (defun org-replace-region-by-html (beg end)
2478 "Assume the current region has org-mode syntax, and convert it to HTML.
2479 This can be used in any buffer. For example, you could write an
2480 itemized list in org-mode syntax in an HTML buffer and then use this
2481 command to convert it."
2482 (interactive "r")
2483 (let (reg html buf pop-up-frames)
2484 (save-window-excursion
2485 (if (org-mode-p)
2486 (setq html (org-export-region-as-html
2487 beg end t 'string))
2488 (setq reg (buffer-substring beg end)
2489 buf (get-buffer-create "*Org tmp*"))
2490 (with-current-buffer buf
2491 (erase-buffer)
2492 (insert reg)
2493 (org-mode)
2494 (setq html (org-export-region-as-html
2495 (point-min) (point-max) t 'string)))
2496 (kill-buffer buf)))
2497 (delete-region beg end)
2498 (insert html)))
2500 ;;;###autoload
2501 (defun org-export-region-as-html (beg end &optional body-only buffer)
2502 "Convert region from BEG to END in org-mode buffer to HTML.
2503 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2504 contents, and only produce the region of converted text, useful for
2505 cut-and-paste operations.
2506 If BUFFER is a buffer or a string, use/create that buffer as a target
2507 of the converted HTML. If BUFFER is the symbol `string', return the
2508 produced HTML as a string and leave not buffer behind. For example,
2509 a Lisp program could call this function in the following way:
2511 (setq html (org-export-region-as-html beg end t 'string))
2513 When called interactively, the output buffer is selected, and shown
2514 in a window. A non-interactive call will only return the buffer."
2515 (interactive "r\nP")
2516 (when (interactive-p)
2517 (setq buffer "*Org HTML Export*"))
2518 (let ((transient-mark-mode t) (zmacs-regions t)
2519 rtn)
2520 (goto-char end)
2521 (set-mark (point)) ;; to activate the region
2522 (goto-char beg)
2523 (setq rtn (org-export-as-html
2524 nil nil nil
2525 buffer body-only))
2526 (if (fboundp 'deactivate-mark) (deactivate-mark))
2527 (if (and (interactive-p) (bufferp rtn))
2528 (switch-to-buffer-other-window rtn)
2529 rtn)))
2531 (defvar html-table-tag nil) ; dynamically scoped into this.
2532 ;;;###autoload
2533 (defun org-export-as-html (arg &optional hidden ext-plist
2534 to-buffer body-only pub-dir)
2535 "Export the outline as a pretty HTML file.
2536 If there is an active region, export only the region. The prefix
2537 ARG specifies how many levels of the outline should become
2538 headlines. The default is 3. Lower levels will become bulleted
2539 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2540 EXT-PLIST is a property list with external parameters overriding
2541 org-mode's default settings, but still inferior to file-local
2542 settings. When TO-BUFFER is non-nil, create a buffer with that
2543 name and export to that buffer. If TO-BUFFER is the symbol
2544 `string', don't leave any buffer behind but just return the
2545 resulting HTML as a string. When BODY-ONLY is set, don't produce
2546 the file header and footer, simply return the content of
2547 <body>...</body>, without even the body tags themselves. When
2548 PUB-DIR is set, use this as the publishing directory."
2549 (interactive "P")
2551 ;; Make sure we have a file name when we need it.
2552 (when (and (not (or to-buffer body-only))
2553 (not buffer-file-name))
2554 (if (buffer-base-buffer)
2555 (org-set-local 'buffer-file-name
2556 (with-current-buffer (buffer-base-buffer)
2557 buffer-file-name))
2558 (error "Need a file name to be able to export.")))
2560 (message "Exporting...")
2561 (setq-default org-todo-line-regexp org-todo-line-regexp)
2562 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2563 (setq-default org-done-keywords org-done-keywords)
2564 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2565 (let* ((opt-plist
2566 (org-export-process-option-filters
2567 (org-combine-plists (org-default-export-plist)
2568 ext-plist
2569 (org-infile-export-plist))))
2571 (style (plist-get opt-plist :style))
2572 (html-extension (plist-get opt-plist :html-extension))
2573 (link-validate (plist-get opt-plist :link-validation-function))
2574 valid thetoc have-headings first-heading-pos
2575 (odd org-odd-levels-only)
2576 (region-p (org-region-active-p))
2577 (rbeg (and region-p (region-beginning)))
2578 (rend (and region-p (region-end)))
2579 (subtree-p
2580 (when region-p
2581 (save-excursion
2582 (goto-char rbeg)
2583 (and (org-at-heading-p)
2584 (>= (org-end-of-subtree t t) rend)))))
2585 (opt-plist (if subtree-p
2586 (org-export-add-subtree-options opt-plist rbeg)
2587 opt-plist))
2588 ;; The following two are dynamically scoped into other
2589 ;; routines below.
2590 (org-current-export-dir
2591 (or pub-dir (org-export-directory :html opt-plist)))
2592 (org-current-export-file buffer-file-name)
2593 (level 0) (line "") (origline "") txt todo
2594 (umax nil)
2595 (umax-toc nil)
2596 (filename (if to-buffer nil
2597 (expand-file-name
2598 (concat
2599 (file-name-sans-extension
2600 (or (and subtree-p
2601 (org-entry-get (region-beginning)
2602 "EXPORT_FILE_NAME" t))
2603 (file-name-nondirectory buffer-file-name)))
2604 "." html-extension)
2605 (file-name-as-directory
2606 (or pub-dir (org-export-directory :html opt-plist))))))
2607 (current-dir (if buffer-file-name
2608 (file-name-directory buffer-file-name)
2609 default-directory))
2610 (buffer (if to-buffer
2611 (cond
2612 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2613 (t (get-buffer-create to-buffer)))
2614 (find-file-noselect filename)))
2615 (org-levels-open (make-vector org-level-max nil))
2616 (date (plist-get opt-plist :date))
2617 (author (plist-get opt-plist :author))
2618 (title (or (and subtree-p (org-export-get-title-from-subtree))
2619 (plist-get opt-plist :title)
2620 (and (not
2621 (plist-get opt-plist :skip-before-1st-heading))
2622 (org-export-grab-title-from-buffer))
2623 (and buffer-file-name
2624 (file-name-sans-extension
2625 (file-name-nondirectory buffer-file-name)))
2626 "UNTITLED"))
2627 (html-table-tag (plist-get opt-plist :html-table-tag))
2628 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2629 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2630 (inquote nil)
2631 (infixed nil)
2632 (in-local-list nil)
2633 (local-list-type nil)
2634 (local-list-indent nil)
2635 (llt org-plain-list-ordered-item-terminator)
2636 (email (plist-get opt-plist :email))
2637 (language (plist-get opt-plist :language))
2638 (lang-words nil)
2639 (head-count 0) cnt
2640 (start 0)
2641 (coding-system (and (boundp 'buffer-file-coding-system)
2642 buffer-file-coding-system))
2643 (coding-system-for-write (or org-export-html-coding-system
2644 coding-system))
2645 (save-buffer-coding-system (or org-export-html-coding-system
2646 coding-system))
2647 (charset (and coding-system-for-write
2648 (fboundp 'coding-system-get)
2649 (coding-system-get coding-system-for-write
2650 'mime-charset)))
2651 (region
2652 (buffer-substring
2653 (if region-p (region-beginning) (point-min))
2654 (if region-p (region-end) (point-max))))
2655 (lines
2656 (org-split-string
2657 (org-export-preprocess-string
2658 region
2659 :emph-multiline t
2660 :for-html t
2661 :skip-before-1st-heading
2662 (plist-get opt-plist :skip-before-1st-heading)
2663 :drawers (plist-get opt-plist :drawers)
2664 :archived-trees
2665 (plist-get opt-plist :archived-trees)
2666 :add-text
2667 (plist-get opt-plist :text)
2668 :LaTeX-fragments
2669 (plist-get opt-plist :LaTeX-fragments))
2670 "[\r\n]"))
2671 table-open type
2672 table-buffer table-orig-buffer
2673 ind item-type starter didclose
2674 rpl path desc descp desc1 desc2 link
2675 snumber fnc item-tag
2678 (let ((inhibit-read-only t))
2679 (org-unmodified
2680 (remove-text-properties (point-min) (point-max)
2681 '(:org-license-to-kill t))))
2683 (message "Exporting...")
2685 (setq org-min-level (org-get-min-level lines))
2686 (setq org-last-level org-min-level)
2687 (org-init-section-numbers)
2689 (cond
2690 ((and date (string-match "%" date))
2691 (setq date (format-time-string date)))
2692 (date)
2693 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2695 ;; Get the language-dependent settings
2696 (setq lang-words (or (assoc language org-export-language-setup)
2697 (assoc "en" org-export-language-setup)))
2699 ;; Switch to the output buffer
2700 (set-buffer buffer)
2701 (let ((inhibit-read-only t)) (erase-buffer))
2702 (fundamental-mode)
2704 (and (fboundp 'set-buffer-file-coding-system)
2705 (set-buffer-file-coding-system coding-system-for-write))
2707 (let ((case-fold-search nil)
2708 (org-odd-levels-only odd))
2709 ;; create local variables for all options, to make sure all called
2710 ;; functions get the correct information
2711 (mapc (lambda (x)
2712 (set (make-local-variable (cdr x))
2713 (plist-get opt-plist (car x))))
2714 org-export-plist-vars)
2715 (setq umax (if arg (prefix-numeric-value arg)
2716 org-export-headline-levels))
2717 (setq umax-toc (if (integerp org-export-with-toc)
2718 (min org-export-with-toc umax)
2719 umax))
2720 (unless body-only
2721 ;; File header
2722 (insert (format
2723 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2724 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2725 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2726 lang=\"%s\" xml:lang=\"%s\">
2727 <head>
2728 <title>%s</title>
2729 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2730 <meta name=\"generator\" content=\"Org-mode\"/>
2731 <meta name=\"generated\" content=\"%s\"/>
2732 <meta name=\"author\" content=\"%s\"/>
2734 </head><body>
2736 language language (org-html-expand title)
2737 (or charset "iso-8859-1") date author style))
2739 (insert (or (plist-get opt-plist :preamble) ""))
2741 (when (plist-get opt-plist :auto-preamble)
2742 (if title (insert (format org-export-html-title-format
2743 (org-html-expand title))))))
2745 (if (and org-export-with-toc (not body-only))
2746 (progn
2747 (push (format "<h%d>%s</h%d>\n"
2748 org-export-html-toplevel-hlevel
2749 (nth 3 lang-words)
2750 org-export-html-toplevel-hlevel)
2751 thetoc)
2752 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2753 (push "<ul>\n<li>" thetoc)
2754 (setq lines
2755 (mapcar '(lambda (line)
2756 (if (string-match org-todo-line-regexp line)
2757 ;; This is a headline
2758 (progn
2759 (setq have-headings t)
2760 (setq level (- (match-end 1) (match-beginning 1))
2761 level (org-tr-level level)
2762 txt (save-match-data
2763 (org-html-expand
2764 (org-export-cleanup-toc-line
2765 (match-string 3 line))))
2766 todo
2767 (or (and org-export-mark-todo-in-toc
2768 (match-beginning 2)
2769 (not (member (match-string 2 line)
2770 org-done-keywords)))
2771 ; TODO, not DONE
2772 (and org-export-mark-todo-in-toc
2773 (= level umax-toc)
2774 (org-search-todo-below
2775 line lines level))))
2776 (if (string-match
2777 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2778 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2779 (if (string-match quote-re0 txt)
2780 (setq txt (replace-match "" t t txt)))
2781 (setq snumber (org-section-number level))
2782 (if org-export-with-section-numbers
2783 (setq txt (concat snumber " " txt)))
2784 (if (<= level (max umax umax-toc))
2785 (setq head-count (+ head-count 1)))
2786 (if (<= level umax-toc)
2787 (progn
2788 (if (> level org-last-level)
2789 (progn
2790 (setq cnt (- level org-last-level))
2791 (while (>= (setq cnt (1- cnt)) 0)
2792 (push "\n<ul>\n<li>" thetoc))
2793 (push "\n" thetoc)))
2794 (if (< level org-last-level)
2795 (progn
2796 (setq cnt (- org-last-level level))
2797 (while (>= (setq cnt (1- cnt)) 0)
2798 (push "</li>\n</ul>" thetoc))
2799 (push "\n" thetoc)))
2800 ;; Check for targets
2801 (while (string-match org-any-target-regexp line)
2802 (setq line (replace-match
2803 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2804 t t line)))
2805 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2806 (setq txt (replace-match "" t t txt)))
2807 (push
2808 (format
2809 (if todo
2810 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2811 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2812 snumber txt) thetoc)
2814 (setq org-last-level level))
2816 line)
2817 lines))
2818 (while (> org-last-level (1- org-min-level))
2819 (setq org-last-level (1- org-last-level))
2820 (push "</li>\n</ul>\n" thetoc))
2821 (push "</div>\n" thetoc)
2822 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2824 (setq head-count 0)
2825 (org-init-section-numbers)
2827 (while (setq line (pop lines) origline line)
2828 (catch 'nextline
2830 ;; end of quote section?
2831 (when (and inquote (string-match "^\\*+ " line))
2832 (insert "</pre>\n")
2833 (setq inquote nil))
2834 ;; inside a quote section?
2835 (when inquote
2836 (insert (org-html-protect line) "\n")
2837 (throw 'nextline nil))
2839 ;; verbatim lines
2840 (when (and org-export-with-fixed-width
2841 (string-match "^[ \t]*:\\(.*\\)" line))
2842 (when (not infixed)
2843 (setq infixed t)
2844 (insert "<pre>\n"))
2845 (insert (org-html-protect (match-string 1 line)) "\n")
2846 (when (or (not lines)
2847 (not (string-match "^[ \t]*\\(:.*\\)"
2848 (car lines))))
2849 (setq infixed nil)
2850 (insert "</pre>\n"))
2851 (throw 'nextline nil))
2853 ;; Protected HTML
2854 (when (get-text-property 0 'org-protected line)
2855 (let (par)
2856 (when (re-search-backward
2857 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2858 (setq par (match-string 1))
2859 (replace-match "\\2\n"))
2860 (insert line "\n")
2861 (while (and lines
2862 (not (string-match "^[ \t]*:" (car lines)))
2863 (or (= (length (car lines)) 0)
2864 (get-text-property 0 'org-protected (car lines))))
2865 (insert (pop lines) "\n"))
2866 (and par (insert "<p>\n")))
2867 (throw 'nextline nil))
2869 ;; Horizontal line
2870 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2871 (insert "\n<hr/>\n")
2872 (throw 'nextline nil))
2874 ;; Blockquotes and verse
2875 (when (equal "ORG-BLOCKQUOTE-START" line)
2876 (insert "<blockquote>\n<p>\n")
2877 (throw 'nextline nil))
2878 (when (equal "ORG-BLOCKQUOTE-END" line)
2879 (insert "</p>\n</blockquote>\n")
2880 (throw 'nextline nil))
2881 (when (equal "ORG-VERSE-START" line)
2882 (insert "<verse>\n<p>\n")
2883 (throw 'nextline nil))
2884 (when (equal "ORG-VERSE-END" line)
2885 (insert "</p>\n</verse>\n")
2886 (throw 'nextline nil))
2888 ;; make targets to anchors
2889 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2890 (cond
2891 ((match-end 2)
2892 (setq line (replace-match
2893 (concat "@<a name=\""
2894 (org-solidify-link-text (match-string 1 line))
2895 "\">\\nbsp@</a>")
2896 t t line)))
2897 ((and org-export-with-toc (equal (string-to-char line) ?*))
2898 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2899 (setq line (replace-match
2900 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2901 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2902 t t line)))
2904 (setq line (replace-match
2905 (concat "@<a name=\""
2906 (org-solidify-link-text (match-string 1 line))
2907 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2908 t t line)))))
2910 (setq line (org-html-handle-time-stamps line))
2912 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2913 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2914 ;; Also handle sub_superscripts and checkboxes
2915 (or (string-match org-table-hline-regexp line)
2916 (setq line (org-html-expand line)))
2918 ;; Format the links
2919 (setq start 0)
2920 (while (string-match org-bracket-link-analytic-regexp line start)
2921 (setq start (match-beginning 0))
2922 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2923 (setq path (match-string 3 line))
2924 (setq desc1 (if (match-end 5) (match-string 5 line))
2925 desc2 (if (match-end 2) (concat type ":" path) path)
2926 descp (and desc1 (not (equal desc1 desc2)))
2927 desc (or desc1 desc2))
2928 ;; Make an image out of the description if that is so wanted
2929 (when (and descp (org-file-image-p desc))
2930 (save-match-data
2931 (if (string-match "^file:" desc)
2932 (setq desc (substring desc (match-end 0)))))
2933 (setq desc (concat "<img src=\"" desc "\"/>")))
2934 ;; FIXME: do we need to unescape here somewhere?
2935 (cond
2936 ((equal type "internal")
2937 (setq rpl
2938 (concat
2939 "<a href=\"#"
2940 (org-solidify-link-text
2941 (save-match-data (org-link-unescape path)) nil)
2942 "\">" desc "</a>")))
2943 ((member type '("http" "https"))
2944 ;; standard URL, just check if we need to inline an image
2945 (if (and (or (eq t org-export-html-inline-images)
2946 (and org-export-html-inline-images (not descp)))
2947 (org-file-image-p path))
2948 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2949 (setq link (concat type ":" path))
2950 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2951 ((member type '("ftp" "mailto" "news"))
2952 ;; standard URL
2953 (setq link (concat type ":" path))
2954 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2955 ((string= type "file")
2956 ;; FILE link
2957 (let* ((filename path)
2958 (abs-p (file-name-absolute-p filename))
2959 thefile file-is-image-p search)
2960 (save-match-data
2961 (if (string-match "::\\(.*\\)" filename)
2962 (setq search (match-string 1 filename)
2963 filename (replace-match "" t nil filename)))
2964 (setq valid
2965 (if (functionp link-validate)
2966 (funcall link-validate filename current-dir)
2968 (setq file-is-image-p (org-file-image-p filename))
2969 (setq thefile (if abs-p (expand-file-name filename) filename))
2970 (when (and org-export-html-link-org-files-as-html
2971 (string-match "\\.org$" thefile))
2972 (setq thefile (concat (substring thefile 0
2973 (match-beginning 0))
2974 "." html-extension))
2975 (if (and search
2976 ;; make sure this is can be used as target search
2977 (not (string-match "^[0-9]*$" search))
2978 (not (string-match "^\\*" search))
2979 (not (string-match "^/.*/$" search)))
2980 (setq thefile (concat thefile "#"
2981 (org-solidify-link-text
2982 (org-link-unescape search)))))
2983 (when (string-match "^file:" desc)
2984 (setq desc (replace-match "" t t desc))
2985 (if (string-match "\\.org$" desc)
2986 (setq desc (replace-match "" t t desc))))))
2987 (setq rpl (if (and file-is-image-p
2988 (or (eq t org-export-html-inline-images)
2989 (and org-export-html-inline-images
2990 (not descp))))
2991 (concat "<img src=\"" thefile "\"/>")
2992 (concat "<a href=\"" thefile "\">" desc "</a>")))
2993 (if (not valid) (setq rpl desc))))
2995 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2996 ;; The link protocol has a function for format the link
2997 (setq rpl
2998 (save-match-data
2999 (funcall fnc (org-link-unescape path) desc1 'html))))
3002 ;; just publish the path, as default
3003 (setq rpl (concat "<i>&lt;" type ":"
3004 (save-match-data (org-link-unescape path))
3005 "&gt;</i>"))))
3006 (setq line (replace-match rpl t t line)
3007 start (+ start (length rpl))))
3009 ;; TODO items
3010 (if (and (string-match org-todo-line-regexp line)
3011 (match-beginning 2))
3013 (setq line
3014 (concat (substring line 0 (match-beginning 2))
3015 "<span class=\""
3016 (if (member (match-string 2 line)
3017 org-done-keywords)
3018 "done" "todo")
3019 "\">" (match-string 2 line)
3020 "</span>" (substring line (match-end 2)))))
3022 ;; Does this contain a reference to a footnote?
3023 (when org-export-with-footnotes
3024 (setq start 0)
3025 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3026 (if (get-text-property (match-beginning 2) 'org-protected line)
3027 (setq start (match-end 2))
3028 (let ((n (match-string 2 line)))
3029 (setq line
3030 (replace-match
3031 (format
3032 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3033 (match-string 1 line) n n n)
3034 t t line))))))
3036 (cond
3037 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3038 ;; This is a headline
3039 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3040 txt (match-string 2 line))
3041 (if (string-match quote-re0 txt)
3042 (setq txt (replace-match "" t t txt)))
3043 (if (<= level (max umax umax-toc))
3044 (setq head-count (+ head-count 1)))
3045 (when in-local-list
3046 ;; Close any local lists before inserting a new header line
3047 (while local-list-type
3048 (org-close-li (car local-list-type))
3049 (insert (format "</%sl>\n" (car local-list-type)))
3050 (pop local-list-type))
3051 (setq local-list-indent nil
3052 in-local-list nil))
3053 (setq first-heading-pos (or first-heading-pos (point)))
3054 (org-html-level-start level txt umax
3055 (and org-export-with-toc (<= level umax))
3056 head-count)
3057 ;; QUOTES
3058 (when (string-match quote-re line)
3059 (insert "<pre>")
3060 (setq inquote t)))
3062 ((and org-export-with-tables
3063 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3064 (if (not table-open)
3065 ;; New table starts
3066 (setq table-open t table-buffer nil table-orig-buffer nil))
3067 ;; Accumulate lines
3068 (setq table-buffer (cons line table-buffer)
3069 table-orig-buffer (cons origline table-orig-buffer))
3070 (when (or (not lines)
3071 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3072 (car lines))))
3073 (setq table-open nil
3074 table-buffer (nreverse table-buffer)
3075 table-orig-buffer (nreverse table-orig-buffer))
3076 (org-close-par-maybe)
3077 (insert (org-format-table-html table-buffer table-orig-buffer))))
3079 ;; Normal lines
3080 (when (string-match
3081 (cond
3082 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3083 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3084 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3085 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3086 line)
3087 (setq ind (org-get-string-indentation line)
3088 item-type (if (match-beginning 4) "o" "u")
3089 starter (if (match-beginning 2)
3090 (substring (match-string 2 line) 0 -1))
3091 line (substring line (match-beginning 5))
3092 item-tag nil)
3093 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3094 (setq item-type "d"
3095 item-tag (match-string 1 line)
3096 line (substring line (match-end 0))))
3097 (when (and (not (equal item-type "d"))
3098 (not (string-match "[^ \t]" line)))
3099 ;; empty line. Pretend indentation is large.
3100 (setq ind (if org-empty-line-terminates-plain-lists
3102 (1+ (or (car local-list-indent) 1)))))
3103 (setq didclose nil)
3104 (while (and in-local-list
3105 (or (and (= ind (car local-list-indent))
3106 (not starter))
3107 (< ind (car local-list-indent))))
3108 (setq didclose t)
3109 (org-close-li (car local-list-type))
3110 (insert (format "</%sl>\n" (car local-list-type)))
3111 (pop local-list-type) (pop local-list-indent)
3112 (setq in-local-list local-list-indent))
3113 (cond
3114 ((and starter
3115 (or (not in-local-list)
3116 (> ind (car local-list-indent))))
3117 ;; Start new (level of) list
3118 (org-close-par-maybe)
3119 (insert (cond
3120 ((equal item-type "u") "<ul>\n<li>\n")
3121 ((equal item-type "o") "<ol>\n<li>\n")
3122 ((equal item-type "d")
3123 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3124 (push item-type local-list-type)
3125 (push ind local-list-indent)
3126 (setq in-local-list t))
3127 (starter
3128 ;; continue current list
3129 (org-close-li (car local-list-type))
3130 (insert (cond
3131 ((equal (car local-list-type) "d")
3132 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3133 (t "<li>\n"))))
3134 (didclose
3135 ;; we did close a list, normal text follows: need <p>
3136 (org-open-par)))
3137 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3138 (setq line
3139 (replace-match
3140 (if (equal (match-string 1 line) "X")
3141 "<b>[X]</b>"
3142 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3143 t t line))))
3145 ;; Empty lines start a new paragraph. If hand-formatted lists
3146 ;; are not fully interpreted, lines starting with "-", "+", "*"
3147 ;; also start a new paragraph.
3148 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3150 ;; Is this the start of a footnote?
3151 (when org-export-with-footnotes
3152 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3153 (org-close-par-maybe)
3154 (let ((n (match-string 1 line)))
3155 (setq line (replace-match
3156 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line))
3157 (setq line (concat line "</p>")))))
3159 ;; Check if the line break needs to be conserved
3160 (cond
3161 ((string-match "\\\\\\\\[ \t]*$" line)
3162 (setq line (replace-match "<br/>" t t line)))
3163 (org-export-preserve-breaks
3164 (setq line (concat line "<br/>"))))
3166 (insert line "\n")))))
3168 ;; Properly close all local lists and other lists
3169 (when inquote (insert "</pre>\n"))
3170 (when in-local-list
3171 ;; Close any local lists before inserting a new header line
3172 (while local-list-type
3173 (org-close-li (car local-list-type))
3174 (insert (format "</%sl>\n" (car local-list-type)))
3175 (pop local-list-type))
3176 (setq local-list-indent nil
3177 in-local-list nil))
3178 (org-html-level-start 1 nil umax
3179 (and org-export-with-toc (<= level umax))
3180 head-count)
3181 ;; the </div> to lose the last text-... div.
3182 (insert "</div>\n")
3184 (unless body-only
3185 (when (plist-get opt-plist :auto-postamble)
3186 (insert "<div id=\"postamble\">")
3187 (when (and org-export-author-info author)
3188 (insert "<p class=\"author\"> "
3189 (nth 1 lang-words) ": " author "\n")
3190 (when email
3191 (if (listp (split-string email ",+ *"))
3192 (mapc (lambda(e)
3193 (insert "<a href=\"mailto:" e "\">&lt;"
3194 e "&gt;</a>\n"))
3195 (split-string email ",+ *"))
3196 (insert "<a href=\"mailto:" email "\">&lt;"
3197 email "&gt;</a>\n")))
3198 (insert "</p>\n"))
3199 (when (and date org-export-time-stamp-file)
3200 (insert "<p class=\"date\"> "
3201 (nth 2 lang-words) ": "
3202 date "</p>\n"))
3203 (insert (format "<p>HTML generated by org-mode %s in emacs %s<\p>\n"
3204 org-version emacs-major-version))
3205 (insert "</div>"))
3207 (if org-export-html-with-timestamp
3208 (insert org-export-html-html-helper-timestamp))
3209 (insert (or (plist-get opt-plist :postamble) ""))
3210 (insert "</body>\n</html>\n"))
3212 (normal-mode)
3213 (if (eq major-mode default-major-mode) (html-mode))
3215 ;; insert the table of contents
3216 (goto-char (point-min))
3217 (when thetoc
3218 (if (or (re-search-forward
3219 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3220 (re-search-forward
3221 "\\[TABLE-OF-CONTENTS\\]" nil t))
3222 (progn
3223 (goto-char (match-beginning 0))
3224 (replace-match ""))
3225 (goto-char first-heading-pos)
3226 (when (looking-at "\\s-*</p>")
3227 (goto-char (match-end 0))
3228 (insert "\n")))
3229 (insert "<div id=\"table-of-contents\">\n")
3230 (mapc 'insert thetoc)
3231 (insert "</div>\n"))
3232 ;; remove empty paragraphs and lists
3233 (goto-char (point-min))
3234 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3235 (replace-match ""))
3236 (goto-char (point-min))
3237 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3238 (replace-match ""))
3239 (goto-char (point-min))
3240 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3241 (replace-match ""))
3242 ;; Convert whitespace place holders
3243 (goto-char (point-min))
3244 (let (beg end n)
3245 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3246 (setq n (get-text-property beg 'org-whitespace)
3247 end (next-single-property-change beg 'org-whitespace))
3248 (goto-char beg)
3249 (delete-region beg end)
3250 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3251 (make-string n ?x)))))
3252 (or to-buffer (save-buffer))
3253 (goto-char (point-min))
3254 (message "Exporting... done")
3255 (if (eq to-buffer 'string)
3256 (prog1 (buffer-substring (point-min) (point-max))
3257 (kill-buffer (current-buffer)))
3258 (current-buffer)))))
3260 (defvar org-table-colgroup-info nil)
3261 (defun org-format-table-ascii (lines)
3262 "Format a table for ascii export."
3263 (if (stringp lines)
3264 (setq lines (org-split-string lines "\n")))
3265 (if (not (string-match "^[ \t]*|" (car lines)))
3266 ;; Table made by table.el - test for spanning
3267 lines
3269 ;; A normal org table
3270 ;; Get rid of hlines at beginning and end
3271 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3272 (setq lines (nreverse lines))
3273 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3274 (setq lines (nreverse lines))
3275 (when org-export-table-remove-special-lines
3276 ;; Check if the table has a marking column. If yes remove the
3277 ;; column and the special lines
3278 (setq lines (org-table-clean-before-export lines)))
3279 ;; Get rid of the vertical lines except for grouping
3280 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3281 rtn line vl1 start)
3282 (while (setq line (pop lines))
3283 (if (string-match org-table-hline-regexp line)
3284 (and (string-match "|\\(.*\\)|" line)
3285 (setq line (replace-match " \\1" t nil line)))
3286 (setq start 0 vl1 vl)
3287 (while (string-match "|" line start)
3288 (setq start (match-end 0))
3289 (or (pop vl1) (setq line (replace-match " " t t line)))))
3290 (push line rtn))
3291 (nreverse rtn))))
3293 (defun org-colgroup-info-to-vline-list (info)
3294 (let (vl new last)
3295 (while info
3296 (setq last new new (pop info))
3297 (if (or (memq last '(:end :startend))
3298 (memq new '(:start :startend)))
3299 (push t vl)
3300 (push nil vl)))
3301 (setq vl (nreverse vl))
3302 (and vl (setcar vl nil))
3303 vl))
3305 (defvar org-table-number-regexp) ; defined in org-table.el
3306 (defun org-format-table-html (lines olines)
3307 "Find out which HTML converter to use and return the HTML code."
3308 (if (stringp lines)
3309 (setq lines (org-split-string lines "\n")))
3310 (if (string-match "^[ \t]*|" (car lines))
3311 ;; A normal org table
3312 (org-format-org-table-html lines)
3313 ;; Table made by table.el - test for spanning
3314 (let* ((hlines (delq nil (mapcar
3315 (lambda (x)
3316 (if (string-match "^[ \t]*\\+-" x) x
3317 nil))
3318 lines)))
3319 (first (car hlines))
3320 (ll (and (string-match "\\S-+" first)
3321 (match-string 0 first)))
3322 (re (concat "^[ \t]*" (regexp-quote ll)))
3323 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3324 hlines))))
3325 (if (and (not spanning)
3326 (not org-export-prefer-native-exporter-for-tables))
3327 ;; We can use my own converter with HTML conversions
3328 (org-format-table-table-html lines)
3329 ;; Need to use the code generator in table.el, with the original text.
3330 (org-format-table-table-html-using-table-generate-source olines)))))
3332 (defvar org-table-number-fraction) ; defined in org-table.el
3333 (defun org-format-org-table-html (lines &optional splice)
3334 "Format a table into HTML."
3335 (require 'org-table)
3336 ;; Get rid of hlines at beginning and end
3337 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3338 (setq lines (nreverse lines))
3339 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3340 (setq lines (nreverse lines))
3341 (when org-export-table-remove-special-lines
3342 ;; Check if the table has a marking column. If yes remove the
3343 ;; column and the special lines
3344 (setq lines (org-table-clean-before-export lines)))
3346 (let ((head (and org-export-highlight-first-table-line
3347 (delq nil (mapcar
3348 (lambda (x) (string-match "^[ \t]*|-" x))
3349 (cdr lines)))))
3350 (nlines 0) fnum i
3351 tbopen line fields html gr colgropen)
3352 (if splice (setq head nil))
3353 (unless splice (push (if head "<thead>" "<tbody>") html))
3354 (setq tbopen t)
3355 (while (setq line (pop lines))
3356 (catch 'next-line
3357 (if (string-match "^[ \t]*|-" line)
3358 (progn
3359 (unless splice
3360 (push (if head "</thead>" "</tbody>") html)
3361 (if lines (push "<tbody>" html) (setq tbopen nil)))
3362 (setq head nil) ;; head ends here, first time around
3363 ;; ignore this line
3364 (throw 'next-line t)))
3365 ;; Break the line into fields
3366 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3367 (unless fnum (setq fnum (make-vector (length fields) 0)))
3368 (setq nlines (1+ nlines) i -1)
3369 (push (concat "<tr>"
3370 (mapconcat
3371 (lambda (x)
3372 (setq i (1+ i))
3373 (if (and (< i nlines)
3374 (string-match org-table-number-regexp x))
3375 (incf (aref fnum i)))
3376 (if head
3377 (concat (car org-export-table-header-tags) x
3378 (cdr org-export-table-header-tags))
3379 (concat (car org-export-table-data-tags) x
3380 (cdr org-export-table-data-tags))))
3381 fields "")
3382 "</tr>")
3383 html)))
3384 (unless splice (if tbopen (push "</tbody>" html)))
3385 (unless splice (push "</table>\n" html))
3386 (setq html (nreverse html))
3387 (unless splice
3388 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3389 (push (mapconcat
3390 (lambda (x)
3391 (setq gr (pop org-table-colgroup-info))
3392 (format "%s<col align=\"%s\"></col>%s"
3393 (if (memq gr '(:start :startend))
3394 (prog1
3395 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3396 (setq colgropen t))
3398 (if (> (/ (float x) nlines) org-table-number-fraction)
3399 "right" "left")
3400 (if (memq gr '(:end :startend))
3401 (progn (setq colgropen nil) "</colgroup>")
3402 "")))
3403 fnum "")
3404 html)
3405 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3406 (push html-table-tag html))
3407 (concat (mapconcat 'identity html "\n") "\n")))
3409 (defun org-table-clean-before-export (lines)
3410 "Check if the table has a marking column.
3411 If yes remove the column and the special lines."
3412 (setq org-table-colgroup-info nil)
3413 (if (memq nil
3414 (mapcar
3415 (lambda (x) (or (string-match "^[ \t]*|-" x)
3416 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3417 lines))
3418 (progn
3419 (setq org-table-clean-did-remove-column nil)
3420 (delq nil
3421 (mapcar
3422 (lambda (x)
3423 (cond
3424 ((string-match "^[ \t]*| */ *|" x)
3425 (setq org-table-colgroup-info
3426 (mapcar (lambda (x)
3427 (cond ((member x '("<" "&lt;")) :start)
3428 ((member x '(">" "&gt;")) :end)
3429 ((member x '("<>" "&lt;&gt;")) :startend)
3430 (t nil)))
3431 (org-split-string x "[ \t]*|[ \t]*")))
3432 nil)
3433 (t x)))
3434 lines)))
3435 (setq org-table-clean-did-remove-column t)
3436 (delq nil
3437 (mapcar
3438 (lambda (x)
3439 (cond
3440 ((string-match "^[ \t]*| */ *|" x)
3441 (setq org-table-colgroup-info
3442 (mapcar (lambda (x)
3443 (cond ((member x '("<" "&lt;")) :start)
3444 ((member x '(">" "&gt;")) :end)
3445 ((member x '("<>" "&lt;&gt;")) :startend)
3446 (t nil)))
3447 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3448 nil)
3449 ((string-match "^[ \t]*| *[!_^/] *|" x)
3450 nil) ; ignore this line
3451 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3452 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3453 ;; remove the first column
3454 (replace-match "\\1|" t nil x))))
3455 lines))))
3457 (defun org-format-table-table-html (lines)
3458 "Format a table generated by table.el into HTML.
3459 This conversion does *not* use `table-generate-source' from table.el.
3460 This has the advantage that Org-mode's HTML conversions can be used.
3461 But it has the disadvantage, that no cell- or row-spanning is allowed."
3462 (let (line field-buffer
3463 (head org-export-highlight-first-table-line)
3464 fields html empty)
3465 (setq html (concat html-table-tag "\n"))
3466 (while (setq line (pop lines))
3467 (setq empty "&nbsp;")
3468 (catch 'next-line
3469 (if (string-match "^[ \t]*\\+-" line)
3470 (progn
3471 (if field-buffer
3472 (progn
3473 (setq
3474 html
3475 (concat
3476 html
3477 "<tr>"
3478 (mapconcat
3479 (lambda (x)
3480 (if (equal x "") (setq x empty))
3481 (if head
3482 (concat (car org-export-table-header-tags) x
3483 (cdr org-export-table-header-tags))
3484 (concat (car org-export-table-data-tags) x
3485 (cdr org-export-table-data-tags))))
3486 field-buffer "\n")
3487 "</tr>\n"))
3488 (setq head nil)
3489 (setq field-buffer nil)))
3490 ;; Ignore this line
3491 (throw 'next-line t)))
3492 ;; Break the line into fields and store the fields
3493 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3494 (if field-buffer
3495 (setq field-buffer (mapcar
3496 (lambda (x)
3497 (concat x "<br/>" (pop fields)))
3498 field-buffer))
3499 (setq field-buffer fields))))
3500 (setq html (concat html "</table>\n"))
3501 html))
3503 (defun org-format-table-table-html-using-table-generate-source (lines)
3504 "Format a table into html, using `table-generate-source' from table.el.
3505 This has the advantage that cell- or row-spanning is allowed.
3506 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3507 (require 'table)
3508 (with-current-buffer (get-buffer-create " org-tmp1 ")
3509 (erase-buffer)
3510 (insert (mapconcat 'identity lines "\n"))
3511 (goto-char (point-min))
3512 (if (not (re-search-forward "|[^+]" nil t))
3513 (error "Error processing table"))
3514 (table-recognize-table)
3515 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3516 (table-generate-source 'html " org-tmp2 ")
3517 (set-buffer " org-tmp2 ")
3518 (buffer-substring (point-min) (point-max))))
3520 (defun org-html-handle-time-stamps (s)
3521 "Format time stamps in string S, or remove them."
3522 (catch 'exit
3523 (let (r b)
3524 (while (string-match org-maybe-keyword-time-regexp s)
3525 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3526 ;; never export CLOCK
3527 (throw 'exit ""))
3528 (or b (setq b (substring s 0 (match-beginning 0))))
3529 (if (not org-export-with-timestamps)
3530 (setq r (concat r (substring s 0 (match-beginning 0)))
3531 s (substring s (match-end 0)))
3532 (setq r (concat
3533 r (substring s 0 (match-beginning 0))
3534 (if (match-end 1)
3535 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3536 (match-string 1 s)))
3537 (format " @<span class=\"timestamp\">%s@</span>"
3538 (substring
3539 (org-translate-time (match-string 3 s)) 1 -1)))
3540 s (substring s (match-end 0)))))
3541 ;; Line break if line started and ended with time stamp stuff
3542 (if (not r)
3544 (setq r (concat r s))
3545 (unless (string-match "\\S-" (concat b s))
3546 (setq r (concat r "@<br/>")))
3547 r))))
3549 (defun org-export-htmlize-region-for-paste (beg end)
3550 "Convert the region to HTML, using htmlize.el.
3551 This is much like `htmlize-region-for-paste', only that it uses
3552 the settings define in the org-... variables."
3553 (let* ((htmlize-output-type org-export-htmlize-output-type)
3554 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3555 (htmlbuf (htmlize-region beg end)))
3556 (unwind-protect
3557 (with-current-buffer htmlbuf
3558 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3559 (plist-get htmlize-buffer-places 'content-end)))
3560 (kill-buffer htmlbuf))))
3562 ;;;###autoload
3563 (defun org-export-htmlize-generate-css ()
3564 "Create the CSS for all font definitions in the current Emacs session.
3565 Use this to create face definitions in your CSS style file that can then
3566 be used by code snippets transformed by htmlize.
3567 This command just produces a buffer that contains class definitions for all
3568 faces used in the current Emacs session. You can copy and paste the ones you
3569 need into your CSS file.
3571 If you then set `org-export-htmlize-output-type' to `css', calls to
3572 the function `org-export-htmlize-region-for-paste' will produce code
3573 that uses these same face definitions."
3574 (interactive)
3575 (require 'htmlize)
3576 (and (get-buffer "*html*") (kill-buffer "*html*"))
3577 (with-temp-buffer
3578 (let ((fl (face-list))
3579 (htmlize-css-name-prefix "org-")
3580 (htmlize-output-type 'css)
3581 f i)
3582 (while (setq f (pop fl)
3583 i (and f (face-attribute f :inherit)))
3584 (when (and (symbolp f) (or (not i) (not (listp i))))
3585 (insert (org-add-props (copy-sequence "1") nil 'face f))))
3586 (htmlize-region (point-min) (point-max))))
3587 (switch-to-buffer "*html*")
3588 (goto-char (point-min))
3589 (if (re-search-forward "<style" nil t)
3590 (delete-region (point-min) (match-beginning 0)))
3591 (if (re-search-forward "</style>" nil t)
3592 (delete-region (1+ (match-end 0)) (point-max)))
3593 (beginning-of-line 1)
3594 (if (looking-at " +") (replace-match ""))
3595 (goto-char (point-min)))
3597 (defun org-html-protect (s)
3598 ;; convert & to &amp;, < to &lt; and > to &gt;
3599 (let ((start 0))
3600 (while (string-match "&" s start)
3601 (setq s (replace-match "&amp;" t t s)
3602 start (1+ (match-beginning 0))))
3603 (while (string-match "<" s)
3604 (setq s (replace-match "&lt;" t t s)))
3605 (while (string-match ">" s)
3606 (setq s (replace-match "&gt;" t t s))))
3609 (defun org-export-cleanup-toc-line (s)
3610 "Remove tags and time staps from lines going into the toc."
3611 (when (memq org-export-with-tags '(not-in-toc nil))
3612 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3613 (setq s (replace-match "" t t s))))
3614 (when org-export-remove-timestamps-from-toc
3615 (while (string-match org-maybe-keyword-time-regexp s)
3616 (setq s (replace-match "" t t s))))
3617 (while (string-match org-bracket-link-regexp s)
3618 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3619 t t s)))
3622 (defun org-html-expand (string)
3623 "Prepare STRING for HTML export. Applies all active conversions.
3624 If there are links in the string, don't modify these."
3625 (let* ((re (concat org-bracket-link-regexp "\\|"
3626 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3627 m s l res)
3628 (while (setq m (string-match re string))
3629 (setq s (substring string 0 m)
3630 l (match-string 0 string)
3631 string (substring string (match-end 0)))
3632 (push (org-html-do-expand s) res)
3633 (push l res))
3634 (push (org-html-do-expand string) res)
3635 (apply 'concat (nreverse res))))
3637 (defun org-html-do-expand (s)
3638 "Apply all active conversions to translate special ASCII to HTML."
3639 (setq s (org-html-protect s))
3640 (if org-export-html-expand
3641 (let ((start 0))
3642 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3643 (setq s (replace-match "<\\1>" t nil s)))))
3644 (if org-export-with-emphasize
3645 (setq s (org-export-html-convert-emphasize s)))
3646 (if org-export-with-special-strings
3647 (setq s (org-export-html-convert-special-strings s)))
3648 (if org-export-with-sub-superscripts
3649 (setq s (org-export-html-convert-sub-super s)))
3650 (if org-export-with-TeX-macros
3651 (let ((start 0) wd ass)
3652 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3653 (if (get-text-property (match-beginning 0) 'org-protected s)
3654 (setq start (match-end 0))
3655 (setq wd (match-string 1 s))
3656 (if (setq ass (assoc wd org-html-entities))
3657 (setq s (replace-match (or (cdr ass)
3658 (concat "&" (car ass) ";"))
3659 t t s))
3660 (setq start (+ start (length wd))))))))
3663 (defun org-create-multibrace-regexp (left right n)
3664 "Create a regular expression which will match a balanced sexp.
3665 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3666 as single character strings.
3667 The regexp returned will match the entire expression including the
3668 delimiters. It will also define a single group which contains the
3669 match except for the outermost delimiters. The maximum depth of
3670 stacked delimiters is N. Escaping delimiters is not possible."
3671 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3672 (or "\\|")
3673 (re nothing)
3674 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3675 (while (> n 1)
3676 (setq n (1- n)
3677 re (concat re or next)
3678 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3679 (concat left "\\(" re "\\)" right)))
3681 (defvar org-match-substring-regexp
3682 (concat
3683 "\\([^\\]\\)\\([_^]\\)\\("
3684 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3685 "\\|"
3686 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3687 "\\|"
3688 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3689 "The regular expression matching a sub- or superscript.")
3691 (defvar org-match-substring-with-braces-regexp
3692 (concat
3693 "\\([^\\]\\)\\([_^]\\)\\("
3694 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3695 "\\)")
3696 "The regular expression matching a sub- or superscript, forcing braces.")
3698 (defconst org-export-html-special-string-regexps
3699 '(("\\\\-" . "&shy;")
3700 ("---\\([^-]\\)" . "&mdash;\\1")
3701 ("--\\([^-]\\)" . "&ndash;\\1")
3702 ("\\.\\.\\." . "&hellip;"))
3703 "Regular expressions for special string conversion.")
3705 (defun org-export-html-convert-special-strings (string)
3706 "Convert special characters in STRING to HTML."
3707 (let ((all org-export-html-special-string-regexps)
3708 e a re rpl start)
3709 (while (setq a (pop all))
3710 (setq re (car a) rpl (cdr a) start 0)
3711 (while (string-match re string start)
3712 (if (get-text-property (match-beginning 0) 'org-protected string)
3713 (setq start (match-end 0))
3714 (setq string (replace-match rpl t nil string)))))
3715 string))
3717 (defun org-export-html-convert-sub-super (string)
3718 "Convert sub- and superscripts in STRING to HTML."
3719 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3720 (while (string-match org-match-substring-regexp string s)
3721 (cond
3722 ((and requireb (match-end 8)) (setq s (match-end 2)))
3723 ((get-text-property (match-beginning 2) 'org-protected string)
3724 (setq s (match-end 2)))
3726 (setq s (match-end 1)
3727 key (if (string= (match-string 2 string) "_") "sub" "sup")
3728 c (or (match-string 8 string)
3729 (match-string 6 string)
3730 (match-string 5 string))
3731 string (replace-match
3732 (concat (match-string 1 string)
3733 "<" key ">" c "</" key ">")
3734 t t string)))))
3735 (while (string-match "\\\\\\([_^]\\)" string)
3736 (setq string (replace-match (match-string 1 string) t t string)))
3737 string))
3739 (defun org-export-html-convert-emphasize (string)
3740 "Apply emphasis."
3741 (let ((s 0) rpl)
3742 (while (string-match org-emph-re string s)
3743 (if (not (equal
3744 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3745 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3746 (setq s (match-beginning 0)
3748 (concat
3749 (match-string 1 string)
3750 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3751 (match-string 4 string)
3752 (nth 3 (assoc (match-string 3 string)
3753 org-emphasis-alist))
3754 (match-string 5 string))
3755 string (replace-match rpl t t string)
3756 s (+ s (- (length rpl) 2)))
3757 (setq s (1+ s))))
3758 string))
3760 (defvar org-par-open nil)
3761 (defun org-open-par ()
3762 "Insert <p>, but first close previous paragraph if any."
3763 (org-close-par-maybe)
3764 (insert "\n<p>")
3765 (setq org-par-open t))
3766 (defun org-close-par-maybe ()
3767 "Close paragraph if there is one open."
3768 (when org-par-open
3769 (insert "</p>")
3770 (setq org-par-open nil)))
3771 (defun org-close-li (&optional type)
3772 "Close <li> if necessary."
3773 (org-close-par-maybe)
3774 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
3776 (defvar body-only) ; dynamically scoped into this.
3777 (defun org-html-level-start (level title umax with-toc head-count)
3778 "Insert a new level in HTML export.
3779 When TITLE is nil, just close all open levels."
3780 (org-close-par-maybe)
3781 (let ((target (and title (org-get-text-property-any 0 'target title)))
3782 (l org-level-max)
3783 snumber)
3784 (while (>= l level)
3785 (if (aref org-levels-open (1- l))
3786 (progn
3787 (org-html-level-close l umax)
3788 (aset org-levels-open (1- l) nil)))
3789 (setq l (1- l)))
3790 (when title
3791 ;; If title is nil, this means this function is called to close
3792 ;; all levels, so the rest is done only if title is given
3793 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3794 (setq title (replace-match
3795 (if org-export-with-tags
3796 (save-match-data
3797 (concat
3798 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3799 (mapconcat 'identity (org-split-string
3800 (match-string 1 title) ":")
3801 "&nbsp;")
3802 "</span>"))
3804 t t title)))
3805 (if (> level umax)
3806 (progn
3807 (if (aref org-levels-open (1- level))
3808 (progn
3809 (org-close-li)
3810 (if target
3811 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3812 (insert "<li>" title "<br/>\n")))
3813 (aset org-levels-open (1- level) t)
3814 (org-close-par-maybe)
3815 (if target
3816 (insert (format "<ul>\n<li id=\"%s\">" target)
3817 title "<br/>\n")
3818 (insert "<ul>\n<li>" title "<br/>\n"))))
3819 (aset org-levels-open (1- level) t)
3820 (setq snumber (org-section-number level))
3821 (if (and org-export-with-section-numbers (not body-only))
3822 (setq title (concat snumber " " title)))
3823 (setq level (+ level org-export-html-toplevel-hlevel -1))
3824 (unless (= head-count 1) (insert "\n</div>\n"))
3825 (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"
3826 snumber level level snumber title level snumber))
3827 (org-open-par)))))
3829 (defun org-get-text-property-any (pos prop &optional object)
3830 (or (get-text-property pos prop object)
3831 (and (setq pos (next-single-property-change pos prop object))
3832 (get-text-property pos prop object))))
3834 (defun org-html-level-close (level max-outline-level)
3835 "Terminate one level in HTML export."
3836 (if (<= level max-outline-level)
3837 (insert "</div>\n")
3838 (org-close-li)
3839 (insert "</ul>\n")))
3841 ;;; iCalendar export
3843 ;;;###autoload
3844 (defun org-export-icalendar-this-file ()
3845 "Export current file as an iCalendar file.
3846 The iCalendar file will be located in the same directory as the Org-mode
3847 file, but with extension `.ics'."
3848 (interactive)
3849 (org-export-icalendar nil buffer-file-name))
3851 ;;;###autoload
3852 (defun org-export-icalendar-all-agenda-files ()
3853 "Export all files in `org-agenda-files' to iCalendar .ics files.
3854 Each iCalendar file will be located in the same directory as the Org-mode
3855 file, but with extension `.ics'."
3856 (interactive)
3857 (apply 'org-export-icalendar nil (org-agenda-files t)))
3859 ;;;###autoload
3860 (defun org-export-icalendar-combine-agenda-files ()
3861 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3862 The file is stored under the name `org-combined-agenda-icalendar-file'."
3863 (interactive)
3864 (apply 'org-export-icalendar t (org-agenda-files t)))
3866 (defun org-export-icalendar (combine &rest files)
3867 "Create iCalendar files for all elements of FILES.
3868 If COMBINE is non-nil, combine all calendar entries into a single large
3869 file and store it under the name `org-combined-agenda-icalendar-file'."
3870 (save-excursion
3871 (org-prepare-agenda-buffers files)
3872 (let* ((dir (org-export-directory
3873 :ical (list :publishing-directory
3874 org-export-publishing-directory)))
3875 file ical-file ical-buffer category started org-agenda-new-buffers)
3876 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3877 (when combine
3878 (setq ical-file
3879 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3880 org-combined-agenda-icalendar-file
3881 (expand-file-name org-combined-agenda-icalendar-file dir))
3882 ical-buffer (org-get-agenda-file-buffer ical-file))
3883 (set-buffer ical-buffer) (erase-buffer))
3884 (while (setq file (pop files))
3885 (catch 'nextfile
3886 (org-check-agenda-file file)
3887 (set-buffer (org-get-agenda-file-buffer file))
3888 (unless combine
3889 (setq ical-file (concat (file-name-as-directory dir)
3890 (file-name-sans-extension
3891 (file-name-nondirectory buffer-file-name))
3892 ".ics"))
3893 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3894 (with-current-buffer ical-buffer (erase-buffer)))
3895 (setq category (or org-category
3896 (file-name-sans-extension
3897 (file-name-nondirectory buffer-file-name))))
3898 (if (symbolp category) (setq category (symbol-name category)))
3899 (let ((standard-output ical-buffer))
3900 (if combine
3901 (and (not started) (setq started t)
3902 (org-start-icalendar-file org-icalendar-combined-name))
3903 (org-start-icalendar-file category))
3904 (org-print-icalendar-entries combine)
3905 (when (or (and combine (not files)) (not combine))
3906 (org-finish-icalendar-file)
3907 (set-buffer ical-buffer)
3908 (run-hooks 'org-before-save-iCalendar-file-hook)
3909 (save-buffer)
3910 (run-hooks 'org-after-save-iCalendar-file-hook)
3911 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
3912 ))))
3913 (org-release-buffers org-agenda-new-buffers))))
3915 (defvar org-before-save-iCalendar-file-hook nil
3916 "Hook run before an iCalendar file has been saved.
3917 This can be used to modify the result of the export.")
3919 (defvar org-after-save-iCalendar-file-hook nil
3920 "Hook run after an iCalendar file has been saved.
3921 The iCalendar buffer is still current when this hook is run.
3922 A good way to use this is to tell a desktop calenndar application to re-read
3923 the iCalendar file.")
3925 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3926 (defun org-print-icalendar-entries (&optional combine)
3927 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3928 When COMBINE is non nil, add the category to each line."
3929 (require 'org-agenda)
3930 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3931 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3932 (dts (org-ical-ts-to-string
3933 (format-time-string (cdr org-time-stamp-formats) (current-time))
3934 "DTSTART"))
3935 hd ts ts2 state status (inc t) pos b sexp rrule
3936 scheduledp deadlinep prefix
3937 tmp pri category entry location summary desc uid
3938 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3939 (org-refresh-category-properties)
3940 (save-excursion
3941 (goto-char (point-min))
3942 (while (re-search-forward re1 nil t)
3943 (catch :skip
3944 (org-agenda-skip)
3945 (when (boundp 'org-icalendar-verify-function)
3946 (unless (funcall org-icalendar-verify-function)
3947 (outline-next-heading)
3948 (backward-char 1)
3949 (throw :skip nil)))
3950 (setq pos (match-beginning 0)
3951 ts (match-string 0)
3952 inc t
3953 hd (condition-case nil
3954 (org-icalendar-cleanup-string
3955 (org-get-heading))
3956 (error (throw :skip nil)))
3957 summary (org-icalendar-cleanup-string
3958 (org-entry-get nil "SUMMARY"))
3959 desc (org-icalendar-cleanup-string
3960 (or (org-entry-get nil "DESCRIPTION")
3961 (and org-icalendar-include-body (org-get-entry)))
3962 t org-icalendar-include-body)
3963 location (org-icalendar-cleanup-string
3964 (org-entry-get nil "LOCATION"))
3965 uid (if org-icalendar-store-UID
3966 (org-id-get-create)
3967 (or (org-id-get) (org-id-new)))
3968 category (org-get-category)
3969 deadlinep nil scheduledp nil)
3970 (if (looking-at re2)
3971 (progn
3972 (goto-char (match-end 0))
3973 (setq ts2 (match-string 1)
3974 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
3975 (setq tmp (buffer-substring (max (point-min)
3976 (- pos org-ds-keyword-length))
3977 pos)
3978 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3979 (progn
3980 (setq inc nil)
3981 (replace-match "\\1" t nil ts))
3983 deadlinep (string-match org-deadline-regexp tmp)
3984 scheduledp (string-match org-scheduled-regexp tmp)
3985 ;; donep (org-entry-is-done-p)
3987 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
3988 (if (or (string-match org-tr-regexp hd)
3989 (string-match org-ts-regexp hd))
3990 (setq hd (replace-match "" t t hd)))
3991 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3992 (setq rrule
3993 (concat "\nRRULE:FREQ="
3994 (cdr (assoc
3995 (match-string 2 ts)
3996 '(("d" . "DAILY")("w" . "WEEKLY")
3997 ("m" . "MONTHLY")("y" . "YEARLY"))))
3998 ";INTERVAL=" (match-string 1 ts)))
3999 (setq rrule ""))
4000 (setq summary (or summary hd))
4001 (if (string-match org-bracket-link-regexp summary)
4002 (setq summary
4003 (replace-match (if (match-end 3)
4004 (match-string 3 summary)
4005 (match-string 1 summary))
4006 t t summary)))
4007 (if deadlinep (setq summary (concat "DL: " summary)))
4008 (if scheduledp (setq summary (concat "S: " summary)))
4009 (if (string-match "\\`<%%" ts)
4010 (with-current-buffer sexp-buffer
4011 (insert (substring ts 1 -1) " " summary "\n"))
4012 (princ (format "BEGIN:VEVENT
4013 UID: %s
4015 %s%s
4016 SUMMARY:%s%s%s
4017 CATEGORIES:%s
4018 END:VEVENT\n"
4019 (concat prefix uid)
4020 (org-ical-ts-to-string ts "DTSTART")
4021 (org-ical-ts-to-string ts2 "DTEND" inc)
4022 rrule summary
4023 (if (and desc (string-match "\\S-" desc))
4024 (concat "\nDESCRIPTION: " desc) "")
4025 (if (and location (string-match "\\S-" location))
4026 (concat "\nLOCATION: " location) "")
4027 category)))))
4028 (when (and org-icalendar-include-sexps
4029 (condition-case nil (require 'icalendar) (error nil))
4030 (fboundp 'icalendar-export-region))
4031 ;; Get all the literal sexps
4032 (goto-char (point-min))
4033 (while (re-search-forward "^&?%%(" nil t)
4034 (catch :skip
4035 (org-agenda-skip)
4036 (setq b (match-beginning 0))
4037 (goto-char (1- (match-end 0)))
4038 (forward-sexp 1)
4039 (end-of-line 1)
4040 (setq sexp (buffer-substring b (point)))
4041 (with-current-buffer sexp-buffer
4042 (insert sexp "\n"))))
4043 (princ (org-diary-to-ical-string sexp-buffer))
4044 (kill-buffer sexp-buffer))
4046 (when org-icalendar-include-todo
4047 (setq prefix "TODO-")
4048 (goto-char (point-min))
4049 (while (re-search-forward org-todo-line-regexp nil t)
4050 (catch :skip
4051 (org-agenda-skip)
4052 (when (boundp 'org-icalendar-verify-function)
4053 (unless (funcall org-icalendar-verify-function)
4054 (outline-next-heading)
4055 (backward-char 1)
4056 (throw :skip nil)))
4057 (setq state (match-string 2))
4058 (setq status (if (member state org-done-keywords)
4059 "COMPLETED" "NEEDS-ACTION"))
4060 (when (and state
4061 (or (not (member state org-done-keywords))
4062 (eq org-icalendar-include-todo 'all))
4063 (not (member org-archive-tag (org-get-tags-at)))
4065 (setq hd (match-string 3)
4066 summary (org-icalendar-cleanup-string
4067 (org-entry-get nil "SUMMARY"))
4068 desc (org-icalendar-cleanup-string
4069 (or (org-entry-get nil "DESCRIPTION")
4070 (and org-icalendar-include-body (org-get-entry)))
4071 t org-icalendar-include-body)
4072 location (org-icalendar-cleanup-string
4073 (org-entry-get nil "LOCATION"))
4074 uid (if org-icalendar-store-UID
4075 (org-id-get-create)
4076 (or (org-id-get) (org-id-new))))
4077 (if (string-match org-bracket-link-regexp hd)
4078 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4079 (match-string 1 hd))
4080 t t hd)))
4081 (if (string-match org-priority-regexp hd)
4082 (setq pri (string-to-char (match-string 2 hd))
4083 hd (concat (substring hd 0 (match-beginning 1))
4084 (substring hd (match-end 1))))
4085 (setq pri org-default-priority))
4086 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
4087 (- org-lowest-priority org-highest-priority))))))
4089 (princ (format "BEGIN:VTODO
4090 UID: %s
4092 SUMMARY:%s%s%s
4093 CATEGORIES:%s
4094 SEQUENCE:1
4095 PRIORITY:%d
4096 STATUS:%s
4097 END:VTODO\n"
4098 (concat prefix uid)
4100 (or summary hd)
4101 (if (and location (string-match "\\S-" location))
4102 (concat "\nLOCATION: " location) "")
4103 (if (and desc (string-match "\\S-" desc))
4104 (concat "\nDESCRIPTION: " desc) "")
4105 category
4106 pri status)))))))))
4108 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4109 "Take out stuff and quote what needs to be quoted.
4110 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4111 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4112 characters."
4113 (if (not s)
4115 (when is-body
4116 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4117 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4118 (while (string-match re s) (setq s (replace-match "" t t s)))
4119 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4120 (let ((start 0))
4121 (while (string-match "\\([,;]\\)" s start)
4122 (setq start (+ (match-beginning 0) 2)
4123 s (replace-match "\\\\\\1" nil nil s))))
4124 (when is-body
4125 (while (string-match "[ \t]*\n[ \t]*" s)
4126 (setq s (replace-match "\\n" t t s))))
4127 (setq s (org-trim s))
4128 (if is-body
4129 (if maxlength
4130 (if (and (numberp maxlength)
4131 (> (length s) maxlength))
4132 (setq s (substring s 0 maxlength)))))
4135 (defun org-get-entry ()
4136 "Clean-up description string."
4137 (save-excursion
4138 (org-back-to-heading t)
4139 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4141 (defun org-start-icalendar-file (name)
4142 "Start an iCalendar file by inserting the header."
4143 (let ((user user-full-name)
4144 (name (or name "unknown"))
4145 (timezone (cadr (current-time-zone))))
4146 (princ
4147 (format "BEGIN:VCALENDAR
4148 VERSION:2.0
4149 X-WR-CALNAME:%s
4150 PRODID:-//%s//Emacs with Org-mode//EN
4151 X-WR-TIMEZONE:%s
4152 CALSCALE:GREGORIAN\n" name user timezone))))
4154 (defun org-finish-icalendar-file ()
4155 "Finish an iCalendar file by inserting the END statement."
4156 (princ "END:VCALENDAR\n"))
4158 (defun org-ical-ts-to-string (s keyword &optional inc)
4159 "Take a time string S and convert it to iCalendar format.
4160 KEYWORD is added in front, to make a complete line like DTSTART....
4161 When INC is non-nil, increase the hour by two (if time string contains
4162 a time), or the day by one (if it does not contain a time)."
4163 (let ((t1 (org-parse-time-string s 'nodefault))
4164 t2 fmt have-time time)
4165 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4166 (setq t2 t1 have-time t)
4167 (setq t2 (org-parse-time-string s)))
4168 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4169 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4170 (when inc
4171 (if have-time
4172 (if org-agenda-default-appointment-duration
4173 (setq mi (+ org-agenda-default-appointment-duration mi))
4174 (setq h (+ 2 h)))
4175 (setq d (1+ d))))
4176 (setq time (encode-time s mi h d m y)))
4177 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4178 (concat keyword (format-time-string fmt time))))
4180 ;;; XOXO export
4182 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4183 (with-current-buffer buffer
4184 (apply 'insert output)))
4185 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4187 ;;;###autoload
4188 (defun org-export-as-xoxo (&optional buffer)
4189 "Export the org buffer as XOXO.
4190 The XOXO buffer is named *xoxo-<source buffer name>*"
4191 (interactive (list (current-buffer)))
4192 ;; A quickie abstraction
4194 ;; Output everything as XOXO
4195 (with-current-buffer (get-buffer buffer)
4196 (let* ((pos (point))
4197 (opt-plist (org-combine-plists (org-default-export-plist)
4198 (org-infile-export-plist)))
4199 (filename (concat (file-name-as-directory
4200 (org-export-directory :xoxo opt-plist))
4201 (file-name-sans-extension
4202 (file-name-nondirectory buffer-file-name))
4203 ".html"))
4204 (out (find-file-noselect filename))
4205 (last-level 1)
4206 (hanging-li nil))
4207 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4208 ;; Check the output buffer is empty.
4209 (with-current-buffer out (erase-buffer))
4210 ;; Kick off the output
4211 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4212 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4213 (let* ((hd (match-string-no-properties 1))
4214 (level (length hd))
4215 (text (concat
4216 (match-string-no-properties 2)
4217 (save-excursion
4218 (goto-char (match-end 0))
4219 (let ((str ""))
4220 (catch 'loop
4221 (while 't
4222 (forward-line)
4223 (if (looking-at "^[ \t]\\(.*\\)")
4224 (setq str (concat str (match-string-no-properties 1)))
4225 (throw 'loop str)))))))))
4227 ;; Handle level rendering
4228 (cond
4229 ((> level last-level)
4230 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4232 ((< level last-level)
4233 (dotimes (- (- last-level level) 1)
4234 (if hanging-li
4235 (org-export-as-xoxo-insert-into out "</li>\n"))
4236 (org-export-as-xoxo-insert-into out "</ol>\n"))
4237 (when hanging-li
4238 (org-export-as-xoxo-insert-into out "</li>\n")
4239 (setq hanging-li nil)))
4241 ((equal level last-level)
4242 (if hanging-li
4243 (org-export-as-xoxo-insert-into out "</li>\n")))
4246 (setq last-level level)
4248 ;; And output the new li
4249 (setq hanging-li 't)
4250 (if (equal ?+ (elt text 0))
4251 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4252 (org-export-as-xoxo-insert-into out "<li>" text))))
4254 ;; Finally finish off the ol
4255 (dotimes (- last-level 1)
4256 (if hanging-li
4257 (org-export-as-xoxo-insert-into out "</li>\n"))
4258 (org-export-as-xoxo-insert-into out "</ol>\n"))
4260 (goto-char pos)
4261 ;; Finish the buffer off and clean it up.
4262 (switch-to-buffer-other-window out)
4263 (indent-region (point-min) (point-max) nil)
4264 (save-buffer)
4265 (goto-char (point-min))
4268 (provide 'org-exp)
4270 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4272 ;;; org-exp.el ends here