Bug fix.
[org-mode.git] / lisp / org-exp.el
blobc04b495101d5596c86620730588e77336a5bc941
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.00pre-6
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, or (at your option)
15 ;; 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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 (require 'org)
31 (require 'org-agenda)
32 (eval-and-compile
33 (require 'cl))
35 (declare-function org-export-latex-preprocess "org-export-latex" ())
36 (declare-function org-agenda-skip "org-agenda" ())
37 (declare-function org-infojs-options-inbuffer-template "org-infojs" ())
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-with-special-strings t
53 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
54 When this option is turned on, these strings will be exported as:
56 Org HTML LaTeX
57 -----+----------+--------
58 \\- &shy; \\-
59 -- &ndash; --
60 --- &mdash; ---
61 ... &hellip; \ldots
63 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
64 :group 'org-export-translation
65 :type 'boolean)
67 (defcustom org-export-language-setup
68 '(("en" "Author" "Date" "Table of Contents")
69 ("cs" "Autor" "Datum" "Obsah")
70 ("da" "Ophavsmand" "Dato" "Indhold")
71 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
72 ("es" "Autor" "Fecha" "\xcdndice")
73 ("fr" "Auteur" "Date" "Table des mati\xe8res")
74 ("it" "Autore" "Data" "Indice")
75 ("nl" "Auteur" "Datum" "Inhoudsopgave")
76 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
77 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
78 "Terms used in export text, translated to different languages.
79 Use the variable `org-export-default-language' to set the language,
80 or use the +OPTION lines for a per-file setting."
81 :group 'org-export-general
82 :type '(repeat
83 (list
84 (string :tag "HTML language tag")
85 (string :tag "Author")
86 (string :tag "Date")
87 (string :tag "Table of Contents"))))
89 (defcustom org-export-default-language "en"
90 "The default language of HTML export, as a string.
91 This should have an association in `org-export-language-setup'."
92 :group 'org-export-general
93 :type 'string)
95 (defcustom org-export-skip-text-before-1st-heading t
96 "Non-nil means, skip all text before the first headline when exporting.
97 When nil, that text is exported as well."
98 :group 'org-export-general
99 :type 'boolean)
101 (defcustom org-export-headline-levels 3
102 "The last level which is still exported as a headline.
103 Inferior levels will produce itemize lists when exported.
104 Note that a numeric prefix argument to an exporter function overrides
105 this setting.
107 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
108 :group 'org-export-general
109 :type 'number)
111 (defcustom org-export-with-section-numbers t
112 "Non-nil means, add section numbers to headlines when exporting.
114 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
115 :group 'org-export-general
116 :type 'boolean)
118 (defcustom org-export-with-toc t
119 "Non-nil means, create a table of contents in exported files.
120 The TOC contains headlines with levels up to`org-export-headline-levels'.
121 When an integer, include levels up to N in the toc, this may then be
122 different from `org-export-headline-levels', but it will not be allowed
123 to be larger than the number of headline levels.
124 When nil, no table of contents is made.
126 Headlines which contain any TODO items will be marked with \"(*)\" in
127 ASCII export, and with red color in HTML output, if the option
128 `org-export-mark-todo-in-toc' is set.
130 In HTML output, the TOC will be clickable.
132 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
133 or \"toc:3\"."
134 :group 'org-export-general
135 :type '(choice
136 (const :tag "No Table of Contents" nil)
137 (const :tag "Full Table of Contents" t)
138 (integer :tag "TOC to level")))
140 (defcustom org-export-mark-todo-in-toc nil
141 "Non-nil means, mark TOC lines that contain any open TODO items."
142 :group 'org-export-general
143 :type 'boolean)
145 (defcustom org-export-preserve-breaks nil
146 "Non-nil means, preserve all line breaks when exporting.
147 Normally, in HTML output paragraphs will be reformatted. In ASCII
148 export, line breaks will always be preserved, regardless of this variable.
150 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
151 :group 'org-export-general
152 :type 'boolean)
154 (defcustom org-export-with-archived-trees 'headline
155 "Whether subtrees with the ARCHIVE tag should be exported.
156 This can have three different values
157 nil Do not export, pretend this tree is not present
158 t Do export the entire tree
159 headline Only export the headline, but skip the tree below it."
160 :group 'org-export-general
161 :group 'org-archive
162 :type '(choice
163 (const :tag "not at all" nil)
164 (const :tag "headline only" 'headline)
165 (const :tag "entirely" t)))
167 (defcustom org-export-author-info t
168 "Non-nil means, insert author name and email into the exported file.
170 This option can also be set with the +OPTIONS line,
171 e.g. \"author-info:nil\"."
172 :group 'org-export-general
173 :type 'boolean)
175 (defcustom org-export-time-stamp-file t
176 "Non-nil means, insert a time stamp into the exported file.
177 The time stamp shows when the file was created.
179 This option can also be set with the +OPTIONS line,
180 e.g. \"timestamp:nil\"."
181 :group 'org-export-general
182 :type 'boolean)
184 (defcustom org-export-with-timestamps t
185 "If nil, do not export time stamps and associated keywords."
186 :group 'org-export-general
187 :type 'boolean)
189 (defcustom org-export-remove-timestamps-from-toc t
190 "If nil, remove timestamps from the table of contents entries."
191 :group 'org-export-general
192 :type 'boolean)
194 (defcustom org-export-with-tags 'not-in-toc
195 "If nil, do not export tags, just remove them from headlines.
196 If this is the symbol `not-in-toc', tags will be removed from table of
197 contents entries, but still be shown in the headlines of the document.
199 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
200 :group 'org-export-general
201 :type '(choice
202 (const :tag "Off" nil)
203 (const :tag "Not in TOC" not-in-toc)
204 (const :tag "On" t)))
206 (defcustom org-export-with-drawers nil
207 "Non-nil means, export with drawers like the property drawer.
208 When t, all drawers are exported. This may also be a list of
209 drawer names to export."
210 :group 'org-export-general
211 :type '(choice
212 (const :tag "All drawers" t)
213 (const :tag "None" nil)
214 (repeat :tag "Selected drawers"
215 (string :tag "Drawer name"))))
217 (defgroup org-export-translation nil
218 "Options for translating special ascii sequences for the export backends."
219 :tag "Org Export Translation"
220 :group 'org-export)
222 (defcustom org-export-with-emphasize t
223 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
224 If the export target supports emphasizing text, the word will be
225 typeset in bold, italic, or underlined, respectively. Works only for
226 single words, but you can say: I *really* *mean* *this*.
227 Not all export backends support this.
229 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
230 :group 'org-export-translation
231 :type 'boolean)
233 (defcustom org-export-with-footnotes t
234 "If nil, export [1] as a footnote marker.
235 Lines starting with [1] will be formatted as footnotes.
237 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
238 :group 'org-export-translation
239 :type 'boolean)
241 (defcustom org-export-with-sub-superscripts t
242 "Non-nil means, interpret \"_\" and \"^\" for export.
243 When this option is turned on, you can use TeX-like syntax for sub- and
244 superscripts. Several characters after \"_\" or \"^\" will be
245 considered as a single item - so grouping with {} is normally not
246 needed. For example, the following things will be parsed as single
247 sub- or superscripts.
249 10^24 or 10^tau several digits will be considered 1 item.
250 10^-12 or 10^-tau a leading sign with digits or a word
251 x^2-y^3 will be read as x^2 - y^3, because items are
252 terminated by almost any nonword/nondigit char.
253 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
255 Still, ambiguity is possible - so when in doubt use {} to enclose the
256 sub/superscript. If you set this variable to the symbol `{}',
257 the braces are *required* in order to trigger interpretations as
258 sub/superscript. This can be helpful in documents that need \"_\"
259 frequently in plain text.
261 Not all export backends support this, but HTML does.
263 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
264 :group 'org-export-translation
265 :type '(choice
266 (const :tag "Always interpret" t)
267 (const :tag "Only with braces" {})
268 (const :tag "Never interpret" nil)))
270 (defcustom org-export-with-special-strings t
271 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
272 When this option is turned on, these strings will be exported as:
274 \\- : &shy;
275 -- : &ndash;
276 --- : &mdash;
278 Not all export backends support this, but HTML does.
280 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
281 :group 'org-export-translation
282 :type 'boolean)
284 (defcustom org-export-with-TeX-macros t
285 "Non-nil means, interpret simple TeX-like macros when exporting.
286 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
287 No only real TeX macros will work here, but the standard HTML entities
288 for math can be used as macro names as well. For a list of supported
289 names in HTML export, see the constant `org-html-entities'.
290 Not all export backends support this.
292 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
293 :group 'org-export-translation
294 :group 'org-export-latex
295 :type 'boolean)
297 (defcustom org-export-with-LaTeX-fragments nil
298 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
299 When set, the exporter will find LaTeX environments if the \\begin line is
300 the first non-white thing on a line. It will also find the math delimiters
301 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
302 display math.
304 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
305 :group 'org-export-translation
306 :group 'org-export-latex
307 :type 'boolean)
309 (defcustom org-export-with-fixed-width t
310 "Non-nil means, lines starting with \":\" will be in fixed width font.
311 This can be used to have pre-formatted text, fragments of code etc. For
312 example:
313 : ;; Some Lisp examples
314 : (while (defc cnt)
315 : (ding))
316 will be looking just like this in also HTML. See also the QUOTE keyword.
317 Not all export backends support this.
319 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
320 :group 'org-export-translation
321 :type 'boolean)
323 (defcustom org-match-sexp-depth 3
324 "Number of stacked braces for sub/superscript matching.
325 This has to be set before loading org.el to be effective."
326 :group 'org-export-translation
327 :type 'integer)
329 (defgroup org-export-tables nil
330 "Options for exporting tables in Org-mode."
331 :tag "Org Export Tables"
332 :group 'org-export)
334 (defcustom org-export-with-tables t
335 "If non-nil, lines starting with \"|\" define a table.
336 For example:
338 | Name | Address | Birthday |
339 |-------------+----------+-----------|
340 | Arthur Dent | England | 29.2.2100 |
342 Not all export backends support this.
344 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
345 :group 'org-export-tables
346 :type 'boolean)
348 (defcustom org-export-highlight-first-table-line t
349 "Non-nil means, highlight the first table line.
350 In HTML export, this means use <th> instead of <td>.
351 In tables created with table.el, this applies to the first table line.
352 In Org-mode tables, all lines before the first horizontal separator
353 line will be formatted with <th> tags."
354 :group 'org-export-tables
355 :type 'boolean)
357 (defcustom org-export-table-remove-special-lines t
358 "Remove special lines and marking characters in calculating tables.
359 This removes the special marking character column from tables that are set
360 up for spreadsheet calculations. It also removes the entire lines
361 marked with `!', `_', or `^'. The lines with `$' are kept, because
362 the values of constants may be useful to have."
363 :group 'org-export-tables
364 :type 'boolean)
366 (defcustom org-export-prefer-native-exporter-for-tables nil
367 "Non-nil means, always export tables created with table.el natively.
368 Natively means, use the HTML code generator in table.el.
369 When nil, Org-mode's own HTML generator is used when possible (i.e. if
370 the table does not use row- or column-spanning). This has the
371 advantage, that the automatic HTML conversions for math symbols and
372 sub/superscripts can be applied. Org-mode's HTML generator is also
373 much faster."
374 :group 'org-export-tables
375 :type 'boolean)
377 (defgroup org-export-ascii nil
378 "Options specific for ASCII export of Org-mode files."
379 :tag "Org Export ASCII"
380 :group 'org-export)
382 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
383 "Characters for underlining headings in ASCII export.
384 In the given sequence, these characters will be used for level 1, 2, ..."
385 :group 'org-export-ascii
386 :type '(repeat character))
388 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
389 "Bullet characters for headlines converted to lists in ASCII export.
390 The first character is used for the first lest level generated in this
391 way, and so on. If there are more levels than characters given here,
392 the list will be repeated.
393 Note that plain lists will keep the same bullets as the have in the
394 Org-mode file."
395 :group 'org-export-ascii
396 :type '(repeat character))
398 (defgroup org-export-xml nil
399 "Options specific for XML export of Org-mode files."
400 :tag "Org Export XML"
401 :group 'org-export)
403 (defgroup org-export-html nil
404 "Options specific for HTML export of Org-mode files."
405 :tag "Org Export HTML"
406 :group 'org-export)
408 (defcustom org-export-html-coding-system nil
409 "Coding system for HTML export, defaults to buffer-file-coding-system."
410 :group 'org-export-html
411 :type 'coding-system)
413 (defcustom org-export-html-extension "html"
414 "The extension for exported HTML files."
415 :group 'org-export-html
416 :type 'string)
418 (defcustom org-export-html-link-up ""
419 "Where should the \"UP\" link of exported HTML pages lead?"
420 :group 'org-export-html
421 :type '(string :tag "File or URL"))
423 (defcustom org-export-html-link-home ""
424 "Where should the \"HOME\" link of exported HTML pages lead?"
425 :group 'org-export-html
426 :type '(string :tag "File or URL"))
428 (defcustom org-export-html-style
429 "<style type=\"text/css\">
430 html {
431 font-family: Times, serif;
432 font-size: 12pt;
434 .title { text-align: center; }
435 .todo { color: red; }
436 .done { color: green; }
437 .timestamp { color: grey }
438 .timestamp-kwd { color: CadetBlue }
439 .tag { background-color:lightblue; font-weight:normal }
440 .target { }
441 pre {
442 border: 1pt solid #AEBDCC;
443 background-color: #F3F5F7;
444 padding: 5pt;
445 font-family: courier, monospace;
447 table { border-collapse: collapse; }
448 td, th {
449 vertical-align: top;
450 <!--border: 1pt solid #ADB9CC;-->
452 </style>"
453 "The default style specification for exported HTML files.
454 Since there are different ways of setting style information, this variable
455 needs to contain the full HTML structure to provide a style, including the
456 surrounding HTML tags. The style specifications should include definitions
457 for new classes todo, done, title, and deadline. For example, valid values
458 would be:
460 <style type=\"text/css\">
461 p { font-weight: normal; color: gray; }
462 h1 { color: black; }
463 .title { text-align: center; }
464 .todo, .deadline { color: red; }
465 .done { color: green; }
466 </style>
468 or, if you want to keep the style in a file,
470 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
472 As the value of this option simply gets inserted into the HTML <head> header,
473 you can \"misuse\" it to add arbitrary text to the header."
474 :group 'org-export-html
475 :type 'string)
478 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
479 "Format for typesetting the document title in HTML export."
480 :group 'org-export-html
481 :type 'string)
483 (defcustom org-export-html-toplevel-hlevel 2
484 "The <H> level for level 1 headings in HTML export."
485 :group 'org-export-html
486 :type 'string)
488 (defcustom org-export-html-link-org-files-as-html t
489 "Non-nil means, make file links to `file.org' point to `file.html'.
490 When org-mode is exporting an org-mode file to HTML, links to
491 non-html files are directly put into a href tag in HTML.
492 However, links to other Org-mode files (recognized by the
493 extension `.org.) should become links to the corresponding html
494 file, assuming that the linked org-mode file will also be
495 converted to HTML.
496 When nil, the links still point to the plain `.org' file."
497 :group 'org-export-html
498 :type 'boolean)
500 (defcustom org-export-html-inline-images 'maybe
501 "Non-nil means, inline images into exported HTML pages.
502 This is done using an <img> tag. When nil, an anchor with href is used to
503 link to the image. If this option is `maybe', then images in links with
504 an empty description will be inlined, while images with a description will
505 be linked only."
506 :group 'org-export-html
507 :type '(choice (const :tag "Never" nil)
508 (const :tag "Always" t)
509 (const :tag "When there is no description" maybe)))
511 ;; FIXME: rename
512 (defcustom org-export-html-expand t
513 "Non-nil means, for HTML export, treat @<...> as HTML tag.
514 When nil, these tags will be exported as plain text and therefore
515 not be interpreted by a browser.
517 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
518 :group 'org-export-html
519 :type 'boolean)
521 (defcustom org-export-html-table-tag
522 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
523 "The HTML tag that is used to start a table.
524 This must be a <table> tag, but you may change the options like
525 borders and spacing."
526 :group 'org-export-html
527 :type 'string)
529 (defcustom org-export-table-header-tags '("<th>" . "</th>")
530 "The opening tag for table header fields.
531 This is customizable so that alignment options can be specified."
532 :group 'org-export-tables
533 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
535 (defcustom org-export-table-data-tags '("<td>" . "</td>")
536 "The opening tag for table data fields.
537 This is customizable so that alignment options can be specified."
538 :group 'org-export-tables
539 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
541 (defcustom org-export-html-with-timestamp nil
542 "If non-nil, write `org-export-html-html-helper-timestamp'
543 into the exported HTML text. Otherwise, the buffer will just be saved
544 to a file."
545 :group 'org-export-html
546 :type 'boolean)
548 (defcustom org-export-html-html-helper-timestamp
549 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
550 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
551 :group 'org-export-html
552 :type 'string)
554 (defgroup org-export-icalendar nil
555 "Options specific for iCalendar export of Org-mode files."
556 :tag "Org Export iCalendar"
557 :group 'org-export)
559 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
560 "The file name for the iCalendar file covering all agenda files.
561 This file is created with the command \\[org-export-icalendar-all-agenda-files].
562 The file name should be absolute, the file will be overwritten without warning."
563 :group 'org-export-icalendar
564 :type 'file)
566 (defcustom org-icalendar-include-todo nil
567 "Non-nil means, export to iCalendar files should also cover TODO items."
568 :group 'org-export-icalendar
569 :type '(choice
570 (const :tag "None" nil)
571 (const :tag "Unfinished" t)
572 (const :tag "All" all)))
574 (defcustom org-icalendar-include-sexps t
575 "Non-nil means, export to iCalendar files should also cover sexp entries.
576 These are entries like in the diary, but directly in an Org-mode file."
577 :group 'org-export-icalendar
578 :type 'boolean)
580 (defcustom org-icalendar-include-body 100
581 "Amount of text below headline to be included in iCalendar export.
582 This is a number of characters that should maximally be included.
583 Properties, scheduling and clocking lines will always be removed.
584 The text will be inserted into the DESCRIPTION field."
585 :group 'org-export-icalendar
586 :type '(choice
587 (const :tag "Nothing" nil)
588 (const :tag "Everything" t)
589 (integer :tag "Max characters")))
591 (defcustom org-icalendar-combined-name "OrgMode"
592 "Calendar name for the combined iCalendar representing all agenda files."
593 :group 'org-export-icalendar
594 :type 'string)
596 ;;;; Exporting
598 ;;; Variables, constants, and parameter plists
600 (defconst org-level-max 20)
602 (defvar org-export-html-preamble nil
603 "Preamble, to be inserted just after <body>. Set by publishing functions.")
604 (defvar org-export-html-postamble nil
605 "Preamble, to be inserted just before </body>. Set by publishing functions.")
606 (defvar org-export-html-auto-preamble t
607 "Should default preamble be inserted? Set by publishing functions.")
608 (defvar org-export-html-auto-postamble t
609 "Should default postamble be inserted? Set by publishing functions.")
610 (defvar org-current-export-file nil) ; dynamically scoped parameter
611 (defvar org-current-export-dir nil) ; dynamically scoped parameter
613 (defconst org-export-plist-vars
614 '((:link-up . org-export-html-link-up)
615 (:link-home . org-export-html-link-home)
616 (:language . org-export-default-language)
617 (:customtime . org-display-custom-times)
618 (:headline-levels . org-export-headline-levels)
619 (:section-numbers . org-export-with-section-numbers)
620 (:table-of-contents . org-export-with-toc)
621 (:preserve-breaks . org-export-preserve-breaks)
622 (:archived-trees . org-export-with-archived-trees)
623 (:emphasize . org-export-with-emphasize)
624 (:sub-superscript . org-export-with-sub-superscripts)
625 (:special-strings . org-export-with-special-strings)
626 (:footnotes . org-export-with-footnotes)
627 (:drawers . org-export-with-drawers)
628 (:tags . org-export-with-tags)
629 (:TeX-macros . org-export-with-TeX-macros)
630 (:LaTeX-fragments . org-export-with-LaTeX-fragments)
631 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
632 (:fixed-width . org-export-with-fixed-width)
633 (:timestamps . org-export-with-timestamps)
634 (:author-info . org-export-author-info)
635 (:time-stamp-file . org-export-time-stamp-file)
636 (:tables . org-export-with-tables)
637 (:table-auto-headline . org-export-highlight-first-table-line)
638 (:style . org-export-html-style)
639 (:agenda-style . org-agenda-export-html-style)
640 (:convert-org-links . org-export-html-link-org-files-as-html)
641 (:inline-images . org-export-html-inline-images)
642 (:html-extension . org-export-html-extension)
643 (:html-table-tag . org-export-html-table-tag)
644 (:expand-quoted-html . org-export-html-expand)
645 (:timestamp . org-export-html-with-timestamp)
646 (:publishing-directory . org-export-publishing-directory)
647 (:preamble . org-export-html-preamble)
648 (:postamble . org-export-html-postamble)
649 (:auto-preamble . org-export-html-auto-preamble)
650 (:auto-postamble . org-export-html-auto-postamble)
651 (:author . user-full-name)
652 (:email . user-mail-address)))
654 (defun org-default-export-plist ()
655 "Return the property list with default settings for the export variables."
656 (let ((l org-export-plist-vars) rtn e)
657 (while (setq e (pop l))
658 (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
659 rtn))
661 (defvar org-export-inbuffer-options-extra nil
662 "List of additional in-buffer options that should be detected.
663 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
664 etc. Extensions can add to this list to get their options detected, and they
665 can then add a function to `org-export-options-filters' to process these
666 options.
667 Each element in this list must be a list, with the in-buffer keyword as car,
668 and a property (a symbol) as the next element. All occurences of the
669 keyword will be found, the values concatenated with a space character
670 in between, and the result stored in the export options property list.")
672 (defvar org-export-options-filters nil
673 "Functions to be called to finalize the export/publishing options.
674 All these options are stored in a property list, and each of the functions
675 in this hook gets a chance to modify this property list. Each function
676 must accept the property list as an argument, and must return the (possibly
677 modified) list.")
679 (defun org-infile-export-plist ()
680 "Return the property list with file-local settings for export."
681 (save-excursion
682 (save-restriction
683 (widen)
684 (goto-char 0)
685 (let ((re (org-make-options-regexp
686 (append
687 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
688 "LINK_UP" "LINK_HOME")
689 (mapcar 'car org-export-inbuffer-options-extra))))
690 p key val text options js-up js-main js-css js-opt a pr)
691 (while (re-search-forward re nil t)
692 (setq key (org-match-string-no-properties 1)
693 val (org-match-string-no-properties 2))
694 (cond
695 ((setq a (assoc key org-export-inbuffer-options-extra))
696 (setq pr (nth 1 a))
697 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
698 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
699 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
700 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
701 ((string-equal key "DATE") (setq p (plist-put p :date val)))
702 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
703 ((string-equal key "TEXT")
704 (setq text (if text (concat text "\n" val) val)))
705 ((string-equal key "OPTIONS")
706 (setq options (concat options " " val)))
707 ((string-equal key "LINK_UP")
708 (setq p (plist-put p :link-up val)))
709 ((string-equal key "LINK_HOME")
710 (setq p (plist-put p :link-home val)))))
711 (setq p (plist-put p :text text))
712 (when options
713 (let ((op '(("H" . :headline-levels)
714 ("num" . :section-numbers)
715 ("toc" . :table-of-contents)
716 ("\\n" . :preserve-breaks)
717 ("@" . :expand-quoted-html)
718 (":" . :fixed-width)
719 ("|" . :tables)
720 ("^" . :sub-superscript)
721 ("-" . :special-strings)
722 ("f" . :footnotes)
723 ("d" . :drawers)
724 ("tags" . :tags)
725 ("*" . :emphasize)
726 ("TeX" . :TeX-macros)
727 ("LaTeX" . :LaTeX-fragments)
728 ("skip" . :skip-before-1st-heading)
729 ("author" . :author-info)
730 ("timestamp" . :time-stamp-file)))
732 (while (setq o (pop op))
733 (if (string-match (concat (regexp-quote (car o))
734 ":\\([^ \t\n\r;,.]*\\)")
735 options)
736 (setq p (plist-put p (cdr o)
737 (car (read-from-string
738 (match-string 1 options)))))))))
739 p))))
741 (defun org-export-directory (type plist)
742 (let* ((val (plist-get plist :publishing-directory))
743 (dir (if (listp val)
744 (or (cdr (assoc type val)) ".")
745 val)))
746 dir))
748 ;;;###autoload
749 (defun org-export (&optional arg)
750 "Export dispatcher for Org-mode."
751 (interactive)
752 (let ((help "[t] insert the export option template
753 \[v] limit export to visible part of outline tree
755 \[a] export as ASCII
757 \[h] export as HTML
758 \[H] export as HTML to temporary buffer
759 \[R] export region as HTML
760 \[b] export as HTML and browse immediately
761 \[x] export as XOXO
763 \[l] export as LaTeX
764 \[L] export as LaTeX to temporary buffer
766 \[i] export current file as iCalendar file
767 \[I] export all agenda files as iCalendar files
768 \[c] export agenda files into combined iCalendar file
770 \[F] publish current file
771 \[P] publish current project
772 \[X] publish... (project will be prompted for)
773 \[A] publish all projects")
774 (cmds
775 '((?t . org-insert-export-options-template)
776 (?v . org-export-visible)
777 (?a . org-export-as-ascii)
778 (?h . org-export-as-html)
779 (?b . org-export-as-html-and-open)
780 (?H . org-export-as-html-to-buffer)
781 (?R . org-export-region-as-html)
782 (?x . org-export-as-xoxo)
783 (?l . org-export-as-latex)
784 (?L . org-export-as-latex-to-buffer)
785 (?i . org-export-icalendar-this-file)
786 (?I . org-export-icalendar-all-agenda-files)
787 (?c . org-export-icalendar-combine-agenda-files)
788 (?F . org-publish-current-file)
789 (?P . org-publish-current-project)
790 (?X . org-publish)
791 (?A . org-publish-all)))
792 r1 r2 ass)
793 (save-window-excursion
794 (delete-other-windows)
795 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
796 (princ help))
797 (message "Select command: ")
798 (setq r1 (read-char-exclusive)))
799 (setq r2 (if (< r1 27) (+ r1 96) r1))
800 (if (setq ass (assq r2 cmds))
801 (call-interactively (cdr ass))
802 (error "No command associated with key %c" r1))))
804 (defconst org-html-entities
805 '(("nbsp")
806 ("iexcl")
807 ("cent")
808 ("pound")
809 ("curren")
810 ("yen")
811 ("brvbar")
812 ("vert" . "&#124;")
813 ("sect")
814 ("uml")
815 ("copy")
816 ("ordf")
817 ("laquo")
818 ("not")
819 ("shy")
820 ("reg")
821 ("macr")
822 ("deg")
823 ("plusmn")
824 ("sup2")
825 ("sup3")
826 ("acute")
827 ("micro")
828 ("para")
829 ("middot")
830 ("odot"."o")
831 ("star"."*")
832 ("cedil")
833 ("sup1")
834 ("ordm")
835 ("raquo")
836 ("frac14")
837 ("frac12")
838 ("frac34")
839 ("iquest")
840 ("Agrave")
841 ("Aacute")
842 ("Acirc")
843 ("Atilde")
844 ("Auml")
845 ("Aring") ("AA"."&Aring;")
846 ("AElig")
847 ("Ccedil")
848 ("Egrave")
849 ("Eacute")
850 ("Ecirc")
851 ("Euml")
852 ("Igrave")
853 ("Iacute")
854 ("Icirc")
855 ("Iuml")
856 ("ETH")
857 ("Ntilde")
858 ("Ograve")
859 ("Oacute")
860 ("Ocirc")
861 ("Otilde")
862 ("Ouml")
863 ("times")
864 ("Oslash")
865 ("Ugrave")
866 ("Uacute")
867 ("Ucirc")
868 ("Uuml")
869 ("Yacute")
870 ("THORN")
871 ("szlig")
872 ("agrave")
873 ("aacute")
874 ("acirc")
875 ("atilde")
876 ("auml")
877 ("aring")
878 ("aelig")
879 ("ccedil")
880 ("egrave")
881 ("eacute")
882 ("ecirc")
883 ("euml")
884 ("igrave")
885 ("iacute")
886 ("icirc")
887 ("iuml")
888 ("eth")
889 ("ntilde")
890 ("ograve")
891 ("oacute")
892 ("ocirc")
893 ("otilde")
894 ("ouml")
895 ("divide")
896 ("oslash")
897 ("ugrave")
898 ("uacute")
899 ("ucirc")
900 ("uuml")
901 ("yacute")
902 ("thorn")
903 ("yuml")
904 ("fnof")
905 ("Alpha")
906 ("Beta")
907 ("Gamma")
908 ("Delta")
909 ("Epsilon")
910 ("Zeta")
911 ("Eta")
912 ("Theta")
913 ("Iota")
914 ("Kappa")
915 ("Lambda")
916 ("Mu")
917 ("Nu")
918 ("Xi")
919 ("Omicron")
920 ("Pi")
921 ("Rho")
922 ("Sigma")
923 ("Tau")
924 ("Upsilon")
925 ("Phi")
926 ("Chi")
927 ("Psi")
928 ("Omega")
929 ("alpha")
930 ("beta")
931 ("gamma")
932 ("delta")
933 ("epsilon")
934 ("varepsilon"."&epsilon;")
935 ("zeta")
936 ("eta")
937 ("theta")
938 ("iota")
939 ("kappa")
940 ("lambda")
941 ("mu")
942 ("nu")
943 ("xi")
944 ("omicron")
945 ("pi")
946 ("rho")
947 ("sigmaf") ("varsigma"."&sigmaf;")
948 ("sigma")
949 ("tau")
950 ("upsilon")
951 ("phi")
952 ("chi")
953 ("psi")
954 ("omega")
955 ("thetasym") ("vartheta"."&thetasym;")
956 ("upsih")
957 ("piv")
958 ("bull") ("bullet"."&bull;")
959 ("hellip") ("dots"."&hellip;")
960 ("prime")
961 ("Prime")
962 ("oline")
963 ("frasl")
964 ("weierp")
965 ("image")
966 ("real")
967 ("trade")
968 ("alefsym")
969 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
970 ("uarr") ("uparrow"."&uarr;")
971 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
972 ("darr")("downarrow"."&darr;")
973 ("harr") ("leftrightarrow"."&harr;")
974 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
975 ("lArr") ("Leftarrow"."&lArr;")
976 ("uArr") ("Uparrow"."&uArr;")
977 ("rArr") ("Rightarrow"."&rArr;")
978 ("dArr") ("Downarrow"."&dArr;")
979 ("hArr") ("Leftrightarrow"."&hArr;")
980 ("forall")
981 ("part") ("partial"."&part;")
982 ("exist") ("exists"."&exist;")
983 ("empty") ("emptyset"."&empty;")
984 ("nabla")
985 ("isin") ("in"."&isin;")
986 ("notin")
987 ("ni")
988 ("prod")
989 ("sum")
990 ("minus")
991 ("lowast") ("ast"."&lowast;")
992 ("radic")
993 ("prop") ("proptp"."&prop;")
994 ("infin") ("infty"."&infin;")
995 ("ang") ("angle"."&ang;")
996 ("and") ("wedge"."&and;")
997 ("or") ("vee"."&or;")
998 ("cap")
999 ("cup")
1000 ("int")
1001 ("there4")
1002 ("sim")
1003 ("cong") ("simeq"."&cong;")
1004 ("asymp")("approx"."&asymp;")
1005 ("ne") ("neq"."&ne;")
1006 ("equiv")
1007 ("le")
1008 ("ge")
1009 ("sub") ("subset"."&sub;")
1010 ("sup") ("supset"."&sup;")
1011 ("nsub")
1012 ("sube")
1013 ("supe")
1014 ("oplus")
1015 ("otimes")
1016 ("perp")
1017 ("sdot") ("cdot"."&sdot;")
1018 ("lceil")
1019 ("rceil")
1020 ("lfloor")
1021 ("rfloor")
1022 ("lang")
1023 ("rang")
1024 ("loz") ("Diamond"."&loz;")
1025 ("spades") ("spadesuit"."&spades;")
1026 ("clubs") ("clubsuit"."&clubs;")
1027 ("hearts") ("diamondsuit"."&hearts;")
1028 ("diams") ("diamondsuit"."&diams;")
1029 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1030 ("quot")
1031 ("amp")
1032 ("lt")
1033 ("gt")
1034 ("OElig")
1035 ("oelig")
1036 ("Scaron")
1037 ("scaron")
1038 ("Yuml")
1039 ("circ")
1040 ("tilde")
1041 ("ensp")
1042 ("emsp")
1043 ("thinsp")
1044 ("zwnj")
1045 ("zwj")
1046 ("lrm")
1047 ("rlm")
1048 ("ndash")
1049 ("mdash")
1050 ("lsquo")
1051 ("rsquo")
1052 ("sbquo")
1053 ("ldquo")
1054 ("rdquo")
1055 ("bdquo")
1056 ("dagger")
1057 ("Dagger")
1058 ("permil")
1059 ("lsaquo")
1060 ("rsaquo")
1061 ("euro")
1063 ("arccos"."arccos")
1064 ("arcsin"."arcsin")
1065 ("arctan"."arctan")
1066 ("arg"."arg")
1067 ("cos"."cos")
1068 ("cosh"."cosh")
1069 ("cot"."cot")
1070 ("coth"."coth")
1071 ("csc"."csc")
1072 ("deg"."deg")
1073 ("det"."det")
1074 ("dim"."dim")
1075 ("exp"."exp")
1076 ("gcd"."gcd")
1077 ("hom"."hom")
1078 ("inf"."inf")
1079 ("ker"."ker")
1080 ("lg"."lg")
1081 ("lim"."lim")
1082 ("liminf"."liminf")
1083 ("limsup"."limsup")
1084 ("ln"."ln")
1085 ("log"."log")
1086 ("max"."max")
1087 ("min"."min")
1088 ("Pr"."Pr")
1089 ("sec"."sec")
1090 ("sin"."sin")
1091 ("sinh"."sinh")
1092 ("sup"."sup")
1093 ("tan"."tan")
1094 ("tanh"."tanh")
1096 "Entities for TeX->HTML translation.
1097 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1098 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1099 In that case, \"\\ent\" will be translated to \"&other;\".
1100 The list contains HTML entities for Latin-1, Greek and other symbols.
1101 It is supplemented by a number of commonly used TeX macros with appropriate
1102 translations. There is currently no way for users to extend this.")
1104 ;;; General functions for all backends
1106 (defun org-export-preprocess-string (string &rest parameters)
1107 "Cleanup STRING so that that the true exported has a more consistent source.
1108 This function takes STRING, which should be a buffer-string of an org-file
1109 to export. It then creates a temporary buffer where it does its job.
1110 The result is then again returned as a string, and the exporter works
1111 on this string to produce the exported version."
1112 (interactive)
1113 (let* ((re-radio (and org-target-link-regexp
1114 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
1115 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1116 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1117 (re-archive (concat ":" org-archive-tag ":"))
1118 (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
1119 (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1120 (htmlp (plist-get parameters :for-html))
1121 (asciip (plist-get parameters :for-ascii))
1122 (latexp (plist-get parameters :for-LaTeX))
1123 (commentsp (plist-get parameters :comments))
1124 (archived-trees (plist-get parameters :archived-trees))
1125 (inhibit-read-only t)
1126 (drawers org-drawers)
1127 (exp-drawers (plist-get parameters :drawers))
1128 (outline-regexp "\\*+ ")
1129 target-alist tmp target level
1130 a b xx rtn p)
1132 (with-current-buffer (get-buffer-create " org-mode-tmp")
1133 (erase-buffer)
1134 (insert string)
1135 ;; Remove license-to-kill stuff
1136 ;; The caller markes some stuff fo killing, stuff that has been
1137 ;; used to create the page title, for example.
1138 (while (setq p (text-property-any (point-min) (point-max)
1139 :org-license-to-kill t))
1140 (delete-region p (next-single-property-change p :org-license-to-kill)))
1142 (let ((org-inhibit-startup t)) (org-mode))
1143 (untabify (point-min) (point-max))
1145 ;; Get rid of drawers
1146 (unless (eq t exp-drawers)
1147 (goto-char (point-min))
1148 (let ((re (concat "^[ \t]*:\\("
1149 (mapconcat
1150 'identity
1151 (org-delete-all exp-drawers
1152 (copy-sequence drawers))
1153 "\\|")
1154 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1155 (while (re-search-forward re nil t)
1156 (replace-match ""))))
1158 ;; Get the correct stuff before the first headline
1159 (when (plist-get parameters :skip-before-1st-heading)
1160 (goto-char (point-min))
1161 (when (re-search-forward "^\\*+[ \t]" nil t)
1162 (delete-region (point-min) (match-beginning 0))
1163 (goto-char (point-min))
1164 (insert "\n")))
1165 (when (plist-get parameters :add-text)
1166 (goto-char (point-min))
1167 (insert (plist-get parameters :add-text) "\n"))
1169 ;; Get rid of archived trees
1170 (when (not (eq archived-trees t))
1171 (goto-char (point-min))
1172 (while (re-search-forward re-archive nil t)
1173 (if (not (org-on-heading-p t))
1174 (org-end-of-subtree t)
1175 (beginning-of-line 1)
1176 (setq a (if archived-trees
1177 (1+ (point-at-eol)) (point))
1178 b (org-end-of-subtree t))
1179 (if (> b a) (delete-region a b)))))
1181 ;; Find all headings and compute the targets for them
1182 (goto-char (point-min))
1183 (org-init-section-numbers)
1184 (let ((re (concat "^" org-outline-regexp)))
1185 (while (re-search-forward re nil t)
1186 (setq level (org-reduced-level
1187 (save-excursion (goto-char (point-at-bol))
1188 (org-outline-level))))
1189 (setq target (org-solidify-link-text
1190 (format "sec-%s" (org-section-number level))))
1191 (push (cons target target) target-alist)
1192 (add-text-properties
1193 (point-at-bol) (point-at-eol)
1194 (list 'target target))))
1196 ;; Find targets in comments and move them out of comments,
1197 ;; but mark them as targets that should be invisible
1198 (goto-char (point-min))
1199 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1200 ;; Check if the line before or after is a headline with a target
1201 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1202 (get-text-property (point-at-bol 2) 'target)))
1203 (progn
1204 ;; use the existing target in a neighboring line
1205 (setq tmp (match-string 2))
1206 (replace-match "")
1207 (and (looking-at "\n") (delete-char 1))
1208 (push (cons (org-solidify-link-text tmp) target)
1209 target-alist))
1210 ;; Make an invisible target
1211 (replace-match "\\1(INVISIBLE)")))
1213 ;; Protect backend specific stuff, throw away the others.
1214 (let ((formatters
1215 `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
1216 (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
1217 (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1218 fmt)
1219 (goto-char (point-min))
1220 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1221 (goto-char (match-end 0))
1222 (while (not (looking-at "#\\+END_EXAMPLE"))
1223 (insert ": ")
1224 (beginning-of-line 2)))
1225 (goto-char (point-min))
1226 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1227 (add-text-properties (match-beginning 0) (match-end 0)
1228 '(org-protected t)))
1229 (while formatters
1230 (setq fmt (pop formatters))
1231 (when (car fmt)
1232 (goto-char (point-min))
1233 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1234 ":[ \t]*\\(.*\\)") nil t)
1235 (replace-match "\\1" t)
1236 (add-text-properties
1237 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1238 '(org-protected t))))
1239 (goto-char (point-min))
1240 (while (re-search-forward
1241 (concat "^#\\+"
1242 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1243 (cadddr fmt) "\\>.*\n?") nil t)
1244 (if (car fmt)
1245 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1246 '(org-protected t))
1247 (delete-region (match-beginning 0) (match-end 0))))))
1249 ;; Protect quoted subtrees
1250 (goto-char (point-min))
1251 (while (re-search-forward re-quote nil t)
1252 (goto-char (match-beginning 0))
1253 (end-of-line 1)
1254 (add-text-properties (point) (org-end-of-subtree t)
1255 '(org-protected t)))
1257 ;; Protect verbatim elements
1258 (goto-char (point-min))
1259 (while (re-search-forward org-verbatim-re nil t)
1260 (add-text-properties (match-beginning 4) (match-end 4)
1261 '(org-protected t))
1262 (goto-char (1+ (match-end 4))))
1264 ;; Remove subtrees that are commented
1265 (goto-char (point-min))
1266 (while (re-search-forward re-commented nil t)
1267 (goto-char (match-beginning 0))
1268 (delete-region (point) (org-end-of-subtree t)))
1270 ;; Remove special table lines
1271 (when org-export-table-remove-special-lines
1272 (goto-char (point-min))
1273 (while (re-search-forward "^[ \t]*|" nil t)
1274 (beginning-of-line 1)
1275 (if (or (looking-at "[ \t]*| *[!_^] *|")
1276 (and (looking-at ".*?| *<[0-9]+> *|")
1277 (not (looking-at ".*?| *[^ <|]"))))
1278 (delete-region (max (point-min) (1- (point-at-bol)))
1279 (point-at-eol))
1280 (end-of-line 1))))
1282 ;; Specific LaTeX stuff
1283 (when latexp
1284 (require 'org-export-latex nil)
1285 (org-export-latex-preprocess))
1287 (when asciip
1288 (org-export-ascii-clean-string))
1290 ;; Specific HTML stuff
1291 (when htmlp
1292 ;; Convert LaTeX fragments to images
1293 (when (plist-get parameters :LaTeX-fragments)
1294 (org-format-latex
1295 (concat "ltxpng/" (file-name-sans-extension
1296 (file-name-nondirectory
1297 org-current-export-file)))
1298 org-current-export-dir nil "Creating LaTeX image %s"))
1299 (message "Exporting..."))
1301 ;; Remove or replace comments
1302 (goto-char (point-min))
1303 (while (re-search-forward "^#\\(.*\n?\\)" nil t)
1304 (if commentsp
1305 (progn (add-text-properties
1306 (match-beginning 0) (match-end 0) '(org-protected t))
1307 (replace-match (format commentsp (match-string 1)) t t))
1308 (replace-match "")))
1310 ;; Find matches for radio targets and turn them into internal links
1311 (goto-char (point-min))
1312 (when re-radio
1313 (while (re-search-forward re-radio nil t)
1314 (org-if-unprotected
1315 (replace-match "\\1[[\\2]]"))))
1317 ;; Find all links that contain a newline and put them into a single line
1318 (goto-char (point-min))
1319 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1320 (org-if-unprotected
1321 (replace-match "\\1 \\3")
1322 (goto-char (match-beginning 0))))
1324 ;; Find all internal links. If they have a fuzzy match (i.e. not
1325 ;; a *dedicated* target match, let the link point to the
1326 ;; correspinding section.
1328 (goto-char (point-min))
1329 (while (re-search-forward org-bracket-link-regexp nil t)
1330 (org-if-unprotected
1331 (let* ((md (match-data))
1332 (desc (match-end 2))
1333 (link (org-link-unescape (match-string 1)))
1334 (slink (org-solidify-link-text link))
1335 found props pos
1336 (target
1337 (or (cdr (assoc slink target-alist))
1338 (save-excursion
1339 (unless (string-match org-link-types-re link)
1340 (setq found (condition-case nil (org-link-search link)
1341 (error nil)))
1342 (when (and found
1343 (or (org-on-heading-p)
1344 (not (eq found 'dedicated))))
1345 (or (get-text-property (point) 'target)
1346 (get-text-property
1347 (max (point-min)
1348 (1- (previous-single-property-change
1349 (point) 'target)))
1350 'target))))))))
1351 (when target
1352 (set-match-data md)
1353 (goto-char (match-beginning 1))
1354 (setq props (text-properties-at (point)))
1355 (delete-region (match-beginning 1) (match-end 1))
1356 (setq pos (point))
1357 (insert target)
1358 (unless desc (insert "][" link))
1359 (add-text-properties pos (point) props)))))
1361 ;; Normalize links: Convert angle and plain links into bracket links
1362 ;; Expand link abbreviations
1363 (goto-char (point-min))
1364 (while (re-search-forward re-plain-link nil t)
1365 (goto-char (1- (match-end 0)))
1366 (org-if-unprotected
1367 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1368 ":" (match-string 3) "]]")))
1369 ;; added 'org-link face to links
1370 (put-text-property 0 (length s) 'face 'org-link s)
1371 (replace-match s t t))))
1372 (goto-char (point-min))
1373 (while (re-search-forward re-angle-link nil t)
1374 (goto-char (1- (match-end 0)))
1375 (org-if-unprotected
1376 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1377 ":" (match-string 3) "]]")))
1378 (put-text-property 0 (length s) 'face 'org-link s)
1379 (replace-match s t t))))
1380 (goto-char (point-min))
1381 (while (re-search-forward org-bracket-link-regexp nil t)
1382 (org-if-unprotected
1383 (let* ((s (concat "[[" (setq xx (save-match-data
1384 (org-link-expand-abbrev (match-string 1))))
1386 (if (match-end 3)
1387 (match-string 2)
1388 (concat "[" xx "]"))
1389 "]")))
1390 (put-text-property 0 (length s) 'face 'org-link s)
1391 (replace-match s t t))))
1393 ;; Find multiline emphasis and put them into single line
1394 (when (plist-get parameters :emph-multiline)
1395 (goto-char (point-min))
1396 (while (re-search-forward org-emph-re nil t)
1397 (if (not (= (char-after (match-beginning 3))
1398 (char-after (match-beginning 4))))
1399 (org-if-unprotected
1400 (subst-char-in-region (match-beginning 0) (match-end 0)
1401 ?\n ?\ t)
1402 (goto-char (1- (match-end 0))))
1403 (goto-char (1+ (match-beginning 0))))))
1405 (setq rtn (buffer-string)))
1406 (kill-buffer " org-mode-tmp")
1407 rtn))
1409 (defun org-export-grab-title-from-buffer ()
1410 "Get a title for the current document, from looking at the buffer."
1411 (let ((inhibit-read-only t))
1412 (save-excursion
1413 (goto-char (point-min))
1414 (let ((end (save-excursion (outline-next-heading) (point))))
1415 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1416 ;; Mark the line so that it will not be exported as normal text.
1417 (org-unmodified
1418 (add-text-properties (match-beginning 0) (match-end 0)
1419 (list :org-license-to-kill t)))
1420 ;; Return the title string
1421 (org-trim (match-string 0)))))))
1423 (defun org-export-get-title-from-subtree ()
1424 "Return subtree title and exclude it from export."
1425 (let (title (m (mark)))
1426 (save-excursion
1427 (goto-char (region-beginning))
1428 (when (and (org-at-heading-p)
1429 (>= (org-end-of-subtree t t) (region-end)))
1430 ;; This is a subtree, we take the title from the first heading
1431 (goto-char (region-beginning))
1432 (looking-at org-todo-line-regexp)
1433 (setq title (match-string 3))
1434 (org-unmodified
1435 (add-text-properties (point) (1+ (point-at-eol))
1436 (list :org-license-to-kill t)))))
1437 title))
1439 (defun org-solidify-link-text (s &optional alist)
1440 "Take link text and make a safe target out of it."
1441 (save-match-data
1442 (let* ((rtn
1443 (mapconcat
1444 'identity
1445 (org-split-string s "[ \t\r\n]+") "=="))
1446 (a (assoc rtn alist)))
1447 (or (cdr a) rtn))))
1449 (defun org-get-min-level (lines)
1450 "Get the minimum level in LINES."
1451 (let ((re "^\\(\\*+\\) ") l min)
1452 (catch 'exit
1453 (while (setq l (pop lines))
1454 (if (string-match re l)
1455 (throw 'exit (org-tr-level (length (match-string 1 l))))))
1456 1)))
1458 ;; Variable holding the vector with section numbers
1459 (defvar org-section-numbers (make-vector org-level-max 0))
1461 (defun org-init-section-numbers ()
1462 "Initialize the vector for the section numbers."
1463 (let* ((level -1)
1464 (numbers (nreverse (org-split-string "" "\\.")))
1465 (depth (1- (length org-section-numbers)))
1466 (i depth) number-string)
1467 (while (>= i 0)
1468 (if (> i level)
1469 (aset org-section-numbers i 0)
1470 (setq number-string (or (car numbers) "0"))
1471 (if (string-match "\\`[A-Z]\\'" number-string)
1472 (aset org-section-numbers i
1473 (- (string-to-char number-string) ?A -1))
1474 (aset org-section-numbers i (string-to-number number-string)))
1475 (pop numbers))
1476 (setq i (1- i)))))
1478 (defun org-section-number (&optional level)
1479 "Return a string with the current section number.
1480 When LEVEL is non-nil, increase section numbers on that level."
1481 (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
1482 (when level
1483 (when (> level -1)
1484 (aset org-section-numbers
1485 level (1+ (aref org-section-numbers level))))
1486 (setq idx (1+ level))
1487 (while (<= idx depth)
1488 (if (not (= idx 1))
1489 (aset org-section-numbers idx 0))
1490 (setq idx (1+ idx))))
1491 (setq idx 0)
1492 (while (<= idx depth)
1493 (setq n (aref org-section-numbers idx))
1494 (setq string (concat string (if (not (string= string "")) "." "")
1495 (int-to-string n)))
1496 (setq idx (1+ idx)))
1497 (save-match-data
1498 (if (string-match "\\`\\([@0]\\.\\)+" string)
1499 (setq string (replace-match "" t nil string)))
1500 (if (string-match "\\(\\.0\\)+\\'" string)
1501 (setq string (replace-match "" t nil string))))
1502 string))
1504 ;;; ASCII export
1506 (defvar org-last-level nil) ; dynamically scoped variable
1507 (defvar org-min-level nil) ; dynamically scoped variable
1508 (defvar org-levels-open nil) ; dynamically scoped parameter
1509 (defvar org-ascii-current-indentation nil) ; For communication
1511 ;;;###autoload
1512 (defun org-export-as-ascii (arg)
1513 "Export the outline as a pretty ASCII file.
1514 If there is an active region, export only the region.
1515 The prefix ARG specifies how many levels of the outline should become
1516 underlined headlines. The default is 3."
1517 (interactive "P")
1518 (setq-default org-todo-line-regexp org-todo-line-regexp)
1519 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1520 (org-infile-export-plist)))
1521 (region-p (org-region-active-p))
1522 (subtree-p
1523 (when region-p
1524 (save-excursion
1525 (goto-char (region-beginning))
1526 (and (org-at-heading-p)
1527 (>= (org-end-of-subtree t t) (region-end))))))
1528 (custom-times org-display-custom-times)
1529 (org-ascii-current-indentation '(0 . 0))
1530 (level 0) line txt
1531 (umax nil)
1532 (umax-toc nil)
1533 (case-fold-search nil)
1534 (filename (concat (file-name-as-directory
1535 (org-export-directory :ascii opt-plist))
1536 (file-name-sans-extension
1537 (or (and subtree-p
1538 (org-entry-get (region-beginning)
1539 "EXPORT_FILE_NAME" t))
1540 (file-name-nondirectory buffer-file-name)))
1541 ".txt"))
1542 (filename (if (equal (file-truename filename)
1543 (file-truename buffer-file-name))
1544 (concat filename ".txt")
1545 filename))
1546 (buffer (find-file-noselect filename))
1547 (org-levels-open (make-vector org-level-max nil))
1548 (odd org-odd-levels-only)
1549 (date (plist-get opt-plist :date))
1550 (author (plist-get opt-plist :author))
1551 (title (or (and subtree-p (org-export-get-title-from-subtree))
1552 (plist-get opt-plist :title)
1553 (and (not
1554 (plist-get opt-plist :skip-before-1st-heading))
1555 (org-export-grab-title-from-buffer))
1556 (file-name-sans-extension
1557 (file-name-nondirectory buffer-file-name))))
1558 (email (plist-get opt-plist :email))
1559 (language (plist-get opt-plist :language))
1560 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1561 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1562 (todo nil)
1563 (lang-words nil)
1564 (region
1565 (buffer-substring
1566 (if (org-region-active-p) (region-beginning) (point-min))
1567 (if (org-region-active-p) (region-end) (point-max))))
1568 (lines (org-split-string
1569 (org-export-preprocess-string
1570 region
1571 :for-ascii t
1572 :skip-before-1st-heading
1573 (plist-get opt-plist :skip-before-1st-heading)
1574 :drawers (plist-get opt-plist :drawers)
1575 :verbatim-multiline t
1576 :archived-trees
1577 (plist-get opt-plist :archived-trees)
1578 :add-text (plist-get opt-plist :text))
1579 "\n"))
1580 thetoc have-headings first-heading-pos
1581 table-open table-buffer)
1583 (let ((inhibit-read-only t))
1584 (org-unmodified
1585 (remove-text-properties (point-min) (point-max)
1586 '(:org-license-to-kill t))))
1588 (setq org-min-level (org-get-min-level lines))
1589 (setq org-last-level org-min-level)
1590 (org-init-section-numbers)
1592 (find-file-noselect filename)
1594 (setq lang-words (or (assoc language org-export-language-setup)
1595 (assoc "en" org-export-language-setup)))
1596 (switch-to-buffer-other-window buffer)
1597 (erase-buffer)
1598 (fundamental-mode)
1599 ;; create local variables for all options, to make sure all called
1600 ;; functions get the correct information
1601 (mapc (lambda (x)
1602 (set (make-local-variable (cdr x))
1603 (plist-get opt-plist (car x))))
1604 org-export-plist-vars)
1605 (org-set-local 'org-odd-levels-only odd)
1606 (setq umax (if arg (prefix-numeric-value arg)
1607 org-export-headline-levels))
1608 (setq umax-toc (if (integerp org-export-with-toc)
1609 (min org-export-with-toc umax)
1610 umax))
1612 ;; File header
1613 (if title (org-insert-centered title ?=))
1614 (insert "\n")
1615 (if (and (or author email)
1616 org-export-author-info)
1617 (insert (concat (nth 1 lang-words) ": " (or author "")
1618 (if email (concat " <" email ">") "")
1619 "\n")))
1621 (cond
1622 ((and date (string-match "%" date))
1623 (setq date (format-time-string date)))
1624 (date)
1625 (t (setq date (format-time-string "%Y/%m/%d %X"))))
1627 (if (and date org-export-time-stamp-file)
1628 (insert (concat (nth 2 lang-words) ": " date"\n")))
1630 (insert "\n\n")
1632 (if org-export-with-toc
1633 (progn
1634 (push (concat (nth 3 lang-words) "\n") thetoc)
1635 (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
1636 (mapc '(lambda (line)
1637 (if (string-match org-todo-line-regexp
1638 line)
1639 ;; This is a headline
1640 (progn
1641 (setq have-headings t)
1642 (setq level (- (match-end 1) (match-beginning 1))
1643 level (org-tr-level level)
1644 txt (match-string 3 line)
1645 todo
1646 (or (and org-export-mark-todo-in-toc
1647 (match-beginning 2)
1648 (not (member (match-string 2 line)
1649 org-done-keywords)))
1650 ; TODO, not DONE
1651 (and org-export-mark-todo-in-toc
1652 (= level umax-toc)
1653 (org-search-todo-below
1654 line lines level))))
1655 (setq txt (org-html-expand-for-ascii txt))
1657 (while (string-match org-bracket-link-regexp txt)
1658 (setq txt
1659 (replace-match
1660 (match-string (if (match-end 2) 3 1) txt)
1661 t t txt)))
1663 (if (and (memq org-export-with-tags '(not-in-toc nil))
1664 (string-match
1665 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1666 txt))
1667 (setq txt (replace-match "" t t txt)))
1668 (if (string-match quote-re0 txt)
1669 (setq txt (replace-match "" t t txt)))
1671 (if org-export-with-section-numbers
1672 (setq txt (concat (org-section-number level)
1673 " " txt)))
1674 (if (<= level umax-toc)
1675 (progn
1676 (push
1677 (concat
1678 (make-string
1679 (* (max 0 (- level org-min-level)) 4) ?\ )
1680 (format (if todo "%s (*)\n" "%s\n") txt))
1681 thetoc)
1682 (setq org-last-level level))
1683 ))))
1684 lines)
1685 (setq thetoc (if have-headings (nreverse thetoc) nil))))
1687 (org-init-section-numbers)
1688 (while (setq line (pop lines))
1689 ;; Remove the quoted HTML tags.
1690 (setq line (org-html-expand-for-ascii line))
1691 ;; Remove targets
1692 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
1693 (setq line (replace-match "" t t line)))
1694 ;; Replace internal links
1695 (while (string-match org-bracket-link-regexp line)
1696 (setq line (replace-match
1697 (if (match-end 3) "[\\3]" "[\\1]")
1698 t nil line)))
1699 (when custom-times
1700 (setq line (org-translate-time line)))
1701 (cond
1702 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1703 ;; a Headline
1704 (setq first-heading-pos (or first-heading-pos (point)))
1705 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
1706 txt (match-string 2 line))
1707 (org-ascii-level-start level txt umax lines))
1709 ((and org-export-with-tables
1710 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1711 (if (not table-open)
1712 ;; New table starts
1713 (setq table-open t table-buffer nil))
1714 ;; Accumulate lines
1715 (setq table-buffer (cons line table-buffer))
1716 (when (or (not lines)
1717 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1718 (car lines))))
1719 (setq table-open nil
1720 table-buffer (nreverse table-buffer))
1721 (insert (mapconcat
1722 (lambda (x)
1723 (org-fix-indentation x org-ascii-current-indentation))
1724 (org-format-table-ascii table-buffer)
1725 "\n") "\n")))
1727 (setq line (org-fix-indentation line org-ascii-current-indentation))
1728 (if (and org-export-with-fixed-width
1729 (string-match "^\\([ \t]*\\)\\(:\\)" line))
1730 (setq line (replace-match "\\1" nil nil line)))
1731 (insert line "\n"))))
1733 (normal-mode)
1735 ;; insert the table of contents
1736 (when thetoc
1737 (goto-char (point-min))
1738 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
1739 (progn
1740 (goto-char (match-beginning 0))
1741 (replace-match ""))
1742 (goto-char first-heading-pos))
1743 (mapc 'insert thetoc)
1744 (or (looking-at "[ \t]*\n[ \t]*\n")
1745 (insert "\n\n")))
1747 ;; Convert whitespace place holders
1748 (goto-char (point-min))
1749 (let (beg end)
1750 (while (setq beg (next-single-property-change (point) 'org-whitespace))
1751 (setq end (next-single-property-change beg 'org-whitespace))
1752 (goto-char beg)
1753 (delete-region beg end)
1754 (insert (make-string (- end beg) ?\ ))))
1756 (save-buffer)
1757 ;; remove display and invisible chars
1758 (let (beg end)
1759 (goto-char (point-min))
1760 (while (setq beg (next-single-property-change (point) 'display))
1761 (setq end (next-single-property-change beg 'display))
1762 (delete-region beg end)
1763 (goto-char beg)
1764 (insert "=>"))
1765 (goto-char (point-min))
1766 (while (setq beg (next-single-property-change (point) 'org-cwidth))
1767 (setq end (next-single-property-change beg 'org-cwidth))
1768 (delete-region beg end)
1769 (goto-char beg)))
1770 (goto-char (point-min))))
1772 (defun org-export-ascii-clean-string ()
1773 "Do extra work for ASCII export"
1774 (goto-char (point-min))
1775 (while (re-search-forward org-verbatim-re nil t)
1776 (goto-char (match-end 2))
1777 (backward-delete-char 1) (insert "'")
1778 (goto-char (match-beginning 2))
1779 (delete-char 1) (insert "`")
1780 (goto-char (match-end 2))))
1782 (defun org-search-todo-below (line lines level)
1783 "Search the subtree below LINE for any TODO entries."
1784 (let ((rest (cdr (memq line lines)))
1785 (re org-todo-line-regexp)
1786 line lv todo)
1787 (catch 'exit
1788 (while (setq line (pop rest))
1789 (if (string-match re line)
1790 (progn
1791 (setq lv (- (match-end 1) (match-beginning 1))
1792 todo (and (match-beginning 2)
1793 (not (member (match-string 2 line)
1794 org-done-keywords))))
1795 ; TODO, not DONE
1796 (if (<= lv level) (throw 'exit nil))
1797 (if todo (throw 'exit t))))))))
1799 (defun org-html-expand-for-ascii (line)
1800 "Handle quoted HTML for ASCII export."
1801 (if org-export-html-expand
1802 (while (string-match "@<[^<>\n]*>" line)
1803 ;; We just remove the tags for now.
1804 (setq line (replace-match "" nil nil line))))
1805 line)
1807 (defun org-insert-centered (s &optional underline)
1808 "Insert the string S centered and underline it with character UNDERLINE."
1809 (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
1810 (insert (make-string ind ?\ ) s "\n")
1811 (if underline
1812 (insert (make-string ind ?\ )
1813 (make-string (string-width s) underline)
1814 "\n"))))
1816 (defun org-ascii-level-start (level title umax &optional lines)
1817 "Insert a new level in ASCII export."
1818 (let (char (n (- level umax 1)) (ind 0))
1819 (if (> level umax)
1820 (progn
1821 (insert (make-string (* 2 n) ?\ )
1822 (char-to-string (nth (% n (length org-export-ascii-bullets))
1823 org-export-ascii-bullets))
1824 " " title "\n")
1825 ;; find the indentation of the next non-empty line
1826 (catch 'stop
1827 (while lines
1828 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
1829 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
1830 (throw 'stop (setq ind (org-get-indentation (car lines)))))
1831 (pop lines)))
1832 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
1833 (if (or (not (equal (char-before) ?\n))
1834 (not (equal (char-before (1- (point))) ?\n)))
1835 (insert "\n"))
1836 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
1837 (unless org-export-with-tags
1838 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
1839 (setq title (replace-match "" t t title))))
1840 (if org-export-with-section-numbers
1841 (setq title (concat (org-section-number level) " " title)))
1842 (insert title "\n" (make-string (string-width title) char) "\n")
1843 (setq org-ascii-current-indentation '(0 . 0)))))
1845 ;;;###autoload
1846 (defun org-export-visible (type arg)
1847 "Create a copy of the visible part of the current buffer, and export it.
1848 The copy is created in a temporary buffer and removed after use.
1849 TYPE is the final key (as a string) that also select the export command in
1850 the `C-c C-e' export dispatcher.
1851 As a special case, if the you type SPC at the prompt, the temporary
1852 org-mode file will not be removed but presented to you so that you can
1853 continue to use it. The prefix arg ARG is passed through to the exporting
1854 command."
1855 (interactive
1856 (list (progn
1857 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
1858 (read-char-exclusive))
1859 current-prefix-arg))
1860 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
1861 (error "Invalid export key"))
1862 (let* ((binding (cdr (assoc type
1863 '((?a . org-export-as-ascii)
1864 (?\C-a . org-export-as-ascii)
1865 (?b . org-export-as-html-and-open)
1866 (?\C-b . org-export-as-html-and-open)
1867 (?h . org-export-as-html)
1868 (?H . org-export-as-html-to-buffer)
1869 (?R . org-export-region-as-html)
1870 (?x . org-export-as-xoxo)))))
1871 (keepp (equal type ?\ ))
1872 (file buffer-file-name)
1873 (buffer (get-buffer-create "*Org Export Visible*"))
1874 s e)
1875 ;; Need to hack the drawers here.
1876 (save-excursion
1877 (goto-char (point-min))
1878 (while (re-search-forward org-drawer-regexp nil t)
1879 (goto-char (match-beginning 1))
1880 (or (org-invisible-p) (org-flag-drawer nil))))
1881 (with-current-buffer buffer (erase-buffer))
1882 (save-excursion
1883 (setq s (goto-char (point-min)))
1884 (while (not (= (point) (point-max)))
1885 (goto-char (org-find-invisible))
1886 (append-to-buffer buffer s (point))
1887 (setq s (goto-char (org-find-visible))))
1888 (org-cycle-hide-drawers 'all)
1889 (goto-char (point-min))
1890 (unless keepp
1891 ;; Copy all comment lines to the end, to make sure #+ settings are
1892 ;; still available for the second export step. Kind of a hack, but
1893 ;; does do the trick.
1894 (if (looking-at "#[^\r\n]*")
1895 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
1896 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
1897 (append-to-buffer buffer (1+ (match-beginning 0))
1898 (min (point-max) (1+ (match-end 0))))))
1899 (set-buffer buffer)
1900 (let ((buffer-file-name file)
1901 (org-inhibit-startup t))
1902 (org-mode)
1903 (show-all)
1904 (unless keepp (funcall binding arg))))
1905 (if (not keepp)
1906 (kill-buffer buffer)
1907 (switch-to-buffer-other-window buffer)
1908 (goto-char (point-min)))))
1910 (defun org-find-visible ()
1911 (let ((s (point)))
1912 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
1913 (get-char-property s 'invisible)))
1915 (defun org-find-invisible ()
1916 (let ((s (point)))
1917 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
1918 (not (get-char-property s 'invisible))))
1921 ;;; HTML export
1923 (defvar org-archive-location) ;; gets loades with the org-archive require.
1924 (defun org-get-current-options ()
1925 "Return a string with current options as keyword options.
1926 Does include HTML export options as well as TODO and CATEGORY stuff."
1927 (require 'org-archive)
1928 (format
1929 "#+TITLE: %s
1930 #+AUTHOR: %s
1931 #+EMAIL: %s
1932 #+DATE: %s
1933 #+LANGUAGE: %s
1934 #+TEXT: Some descriptive text to be emitted. Several lines OK.
1935 #+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
1937 #+LINK_UP: %s
1938 #+LINK_HOME: %s
1939 #+CATEGORY: %s
1940 #+SEQ_TODO: %s
1941 #+TYP_TODO: %s
1942 #+PRIORITIES: %c %c %c
1943 #+DRAWERS: %s
1944 #+STARTUP: %s %s %s %s %s
1945 #+TAGS: %s
1946 #+ARCHIVE: %s
1947 #+LINK: %s
1949 (buffer-name) (user-full-name) user-mail-address
1950 (format-time-string (car org-time-stamp-formats))
1951 org-export-default-language
1952 org-export-headline-levels
1953 org-export-with-section-numbers
1954 org-export-with-toc
1955 org-export-preserve-breaks
1956 org-export-html-expand
1957 org-export-with-fixed-width
1958 org-export-with-tables
1959 org-export-with-sub-superscripts
1960 org-export-with-special-strings
1961 org-export-with-footnotes
1962 org-export-with-emphasize
1963 org-export-with-TeX-macros
1964 org-export-with-LaTeX-fragments
1965 org-export-skip-text-before-1st-heading
1966 org-export-with-drawers
1967 org-export-with-tags
1968 (if (featurep 'org-infojs) (org-infojs-options-inbuffer-template) "")
1969 org-export-html-link-up
1970 org-export-html-link-home
1971 (file-name-nondirectory buffer-file-name)
1972 "TODO FEEDBACK VERIFY DONE"
1973 "Me Jason Marie DONE"
1974 org-highest-priority org-lowest-priority org-default-priority
1975 (mapconcat 'identity org-drawers " ")
1976 (cdr (assoc org-startup-folded
1977 '((nil . "showall") (t . "overview") (content . "content"))))
1978 (if org-odd-levels-only "odd" "oddeven")
1979 (if org-hide-leading-stars "hidestars" "showstars")
1980 (if org-startup-align-all-tables "align" "noalign")
1981 (cond ((eq org-log-done t) "logdone")
1982 ((equal org-log-done 'note) "lognotedone")
1983 ((not org-log-done) "nologdone"))
1984 (or (mapconcat (lambda (x)
1985 (cond
1986 ((equal '(:startgroup) x) "{")
1987 ((equal '(:endgroup) x) "}")
1988 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
1989 (t (car x))))
1990 (or org-tag-alist (org-get-buffer-tags)) " ") "")
1991 org-archive-location
1992 "org file:~/org/%s.org"
1995 ;;;###autoload
1996 (defun org-insert-export-options-template ()
1997 "Insert into the buffer a template with information for exporting."
1998 (interactive)
1999 (if (not (bolp)) (newline))
2000 (let ((s (org-get-current-options)))
2001 (and (string-match "#\\+CATEGORY" s)
2002 (setq s (substring s 0 (match-beginning 0))))
2003 (insert s)))
2005 ;;;###autoload
2006 (defun org-export-as-html-and-open (arg)
2007 "Export the outline as HTML and immediately open it with a browser.
2008 If there is an active region, export only the region.
2009 The prefix ARG specifies how many levels of the outline should become
2010 headlines. The default is 3. Lower levels will become bulleted lists."
2011 (interactive "P")
2012 (org-export-as-html arg 'hidden)
2013 (org-open-file buffer-file-name))
2015 ;;;###autoload
2016 (defun org-export-as-html-batch ()
2017 "Call `org-export-as-html', may be used in batch processing as
2018 emacs --batch
2019 --load=$HOME/lib/emacs/org.el
2020 --eval \"(setq org-export-headline-levels 2)\"
2021 --visit=MyFile --funcall org-export-as-html-batch"
2022 (org-export-as-html org-export-headline-levels 'hidden))
2024 ;;;###autoload
2025 (defun org-export-as-html-to-buffer (arg)
2026 "Call `org-exort-as-html` with output to a temporary buffer.
2027 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2028 (interactive "P")
2029 (org-export-as-html arg nil nil "*Org HTML Export*")
2030 (switch-to-buffer-other-window "*Org HTML Export*"))
2032 ;;;###autoload
2033 (defun org-replace-region-by-html (beg end)
2034 "Assume the current region has org-mode syntax, and convert it to HTML.
2035 This can be used in any buffer. For example, you could write an
2036 itemized list in org-mode syntax in an HTML buffer and then use this
2037 command to convert it."
2038 (interactive "r")
2039 (let (reg html buf pop-up-frames)
2040 (save-window-excursion
2041 (if (org-mode-p)
2042 (setq html (org-export-region-as-html
2043 beg end t 'string))
2044 (setq reg (buffer-substring beg end)
2045 buf (get-buffer-create "*Org tmp*"))
2046 (with-current-buffer buf
2047 (erase-buffer)
2048 (insert reg)
2049 (org-mode)
2050 (setq html (org-export-region-as-html
2051 (point-min) (point-max) t 'string)))
2052 (kill-buffer buf)))
2053 (delete-region beg end)
2054 (insert html)))
2056 ;;;###autoload
2057 (defun org-export-region-as-html (beg end &optional body-only buffer)
2058 "Convert region from BEG to END in org-mode buffer to HTML.
2059 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2060 contents, and only produce the region of converted text, useful for
2061 cut-and-paste operations.
2062 If BUFFER is a buffer or a string, use/create that buffer as a target
2063 of the converted HTML. If BUFFER is the symbol `string', return the
2064 produced HTML as a string and leave not buffer behind. For example,
2065 a Lisp program could call this function in the following way:
2067 (setq html (org-export-region-as-html beg end t 'string))
2069 When called interactively, the output buffer is selected, and shown
2070 in a window. A non-interactive call will only retunr the buffer."
2071 (interactive "r\nP")
2072 (when (interactive-p)
2073 (setq buffer "*Org HTML Export*"))
2074 (let ((transient-mark-mode t) (zmacs-regions t)
2075 rtn)
2076 (goto-char end)
2077 (set-mark (point)) ;; to activate the region
2078 (goto-char beg)
2079 (setq rtn (org-export-as-html
2080 nil nil nil
2081 buffer body-only))
2082 (if (fboundp 'deactivate-mark) (deactivate-mark))
2083 (if (and (interactive-p) (bufferp rtn))
2084 (switch-to-buffer-other-window rtn)
2085 rtn)))
2087 (defvar html-table-tag nil) ; dynamically scoped into this.
2088 ;;;###autoload
2089 (defun org-export-as-html (arg &optional hidden ext-plist
2090 to-buffer body-only pub-dir)
2091 "Export the outline as a pretty HTML file.
2092 If there is an active region, export only the region. The prefix
2093 ARG specifies how many levels of the outline should become
2094 headlines. The default is 3. Lower levels will become bulleted
2095 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2096 EXT-PLIST is a property list with external parameters overriding
2097 org-mode's default settings, but still inferior to file-local
2098 settings. When TO-BUFFER is non-nil, create a buffer with that
2099 name and export to that buffer. If TO-BUFFER is the symbol
2100 `string', don't leave any buffer behind but just return the
2101 resulting HTML as a string. When BODY-ONLY is set, don't produce
2102 the file header and footer, simply return the content of
2103 <body>...</body>, without even the body tags themselves. When
2104 PUB-DIR is set, use this as the publishing directory."
2105 (interactive "P")
2107 ;; Make sure we have a file name when we need it.
2108 (when (and (not (or to-buffer body-only))
2109 (not buffer-file-name))
2110 (if (buffer-base-buffer)
2111 (org-set-local 'buffer-file-name
2112 (with-current-buffer (buffer-base-buffer)
2113 buffer-file-name))
2114 (error "Need a file name to be able to export.")))
2116 (message "Exporting...")
2117 (setq-default org-todo-line-regexp org-todo-line-regexp)
2118 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2119 (setq-default org-done-keywords org-done-keywords)
2120 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2121 (let* ((opt-plist
2122 (org-export-process-option-filters
2123 (org-combine-plists (org-default-export-plist)
2124 ext-plist
2125 (org-infile-export-plist))))
2127 (style (plist-get opt-plist :style))
2128 (html-extension (plist-get opt-plist :html-extension))
2129 (link-validate (plist-get opt-plist :link-validation-function))
2130 valid thetoc have-headings first-heading-pos
2131 (odd org-odd-levels-only)
2132 (region-p (org-region-active-p))
2133 (subtree-p
2134 (when region-p
2135 (save-excursion
2136 (goto-char (region-beginning))
2137 (and (org-at-heading-p)
2138 (>= (org-end-of-subtree t t) (region-end))))))
2139 ;; The following two are dynamically scoped into other
2140 ;; routines below.
2141 (org-current-export-dir
2142 (or pub-dir (org-export-directory :html opt-plist)))
2143 (org-current-export-file buffer-file-name)
2144 (level 0) (line "") (origline "") txt todo
2145 (umax nil)
2146 (umax-toc nil)
2147 (filename (if to-buffer nil
2148 (expand-file-name
2149 (concat
2150 (file-name-sans-extension
2151 (or (and subtree-p
2152 (org-entry-get (region-beginning)
2153 "EXPORT_FILE_NAME" t))
2154 (file-name-nondirectory buffer-file-name)))
2155 "." html-extension)
2156 (file-name-as-directory
2157 (or pub-dir (org-export-directory :html opt-plist))))))
2158 (current-dir (if buffer-file-name
2159 (file-name-directory buffer-file-name)
2160 default-directory))
2161 (buffer (if to-buffer
2162 (cond
2163 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2164 (t (get-buffer-create to-buffer)))
2165 (find-file-noselect filename)))
2166 (org-levels-open (make-vector org-level-max nil))
2167 (date (plist-get opt-plist :date))
2168 (author (plist-get opt-plist :author))
2169 (title (or (and subtree-p (org-export-get-title-from-subtree))
2170 (plist-get opt-plist :title)
2171 (and (not
2172 (plist-get opt-plist :skip-before-1st-heading))
2173 (org-export-grab-title-from-buffer))
2174 (and buffer-file-name
2175 (file-name-sans-extension
2176 (file-name-nondirectory buffer-file-name)))
2177 "UNTITLED"))
2178 (html-table-tag (plist-get opt-plist :html-table-tag))
2179 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2180 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2181 (inquote nil)
2182 (infixed nil)
2183 (in-local-list nil)
2184 (local-list-num nil)
2185 (local-list-indent nil)
2186 (llt org-plain-list-ordered-item-terminator)
2187 (email (plist-get opt-plist :email))
2188 (language (plist-get opt-plist :language))
2189 (lang-words nil)
2190 (head-count 0) cnt
2191 (start 0)
2192 (coding-system (and (boundp 'buffer-file-coding-system)
2193 buffer-file-coding-system))
2194 (coding-system-for-write (or org-export-html-coding-system
2195 coding-system))
2196 (save-buffer-coding-system (or org-export-html-coding-system
2197 coding-system))
2198 (charset (and coding-system-for-write
2199 (fboundp 'coding-system-get)
2200 (coding-system-get coding-system-for-write
2201 'mime-charset)))
2202 (region
2203 (buffer-substring
2204 (if region-p (region-beginning) (point-min))
2205 (if region-p (region-end) (point-max))))
2206 (lines
2207 (org-split-string
2208 (org-export-preprocess-string
2209 region
2210 :emph-multiline t
2211 :for-html t
2212 :skip-before-1st-heading
2213 (plist-get opt-plist :skip-before-1st-heading)
2214 :drawers (plist-get opt-plist :drawers)
2215 :archived-trees
2216 (plist-get opt-plist :archived-trees)
2217 :add-text
2218 (plist-get opt-plist :text)
2219 :LaTeX-fragments
2220 (plist-get opt-plist :LaTeX-fragments))
2221 "[\r\n]"))
2222 table-open type
2223 table-buffer table-orig-buffer
2224 ind start-is-num starter didclose
2225 rpl path desc descp desc1 desc2 link
2226 snumber fnc
2229 (let ((inhibit-read-only t))
2230 (org-unmodified
2231 (remove-text-properties (point-min) (point-max)
2232 '(:org-license-to-kill t))))
2234 (message "Exporting...")
2236 (setq org-min-level (org-get-min-level lines))
2237 (setq org-last-level org-min-level)
2238 (org-init-section-numbers)
2240 (cond
2241 ((and date (string-match "%" date))
2242 (setq date (format-time-string date)))
2243 (date)
2244 (t (setq date (format-time-string "%Y/%m/%d %X"))))
2246 ;; Get the language-dependent settings
2247 (setq lang-words (or (assoc language org-export-language-setup)
2248 (assoc "en" org-export-language-setup)))
2250 ;; Switch to the output buffer
2251 (set-buffer buffer)
2252 (let ((inhibit-read-only t)) (erase-buffer))
2253 (fundamental-mode)
2255 (and (fboundp 'set-buffer-file-coding-system)
2256 (set-buffer-file-coding-system coding-system-for-write))
2258 (let ((case-fold-search nil)
2259 (org-odd-levels-only odd))
2260 ;; create local variables for all options, to make sure all called
2261 ;; functions get the correct information
2262 (mapc (lambda (x)
2263 (set (make-local-variable (cdr x))
2264 (plist-get opt-plist (car x))))
2265 org-export-plist-vars)
2266 (setq umax (if arg (prefix-numeric-value arg)
2267 org-export-headline-levels))
2268 (setq umax-toc (if (integerp org-export-with-toc)
2269 (min org-export-with-toc umax)
2270 umax))
2271 (unless body-only
2272 ;; File header
2273 (insert (format
2274 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2275 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2276 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2277 lang=\"%s\" xml:lang=\"%s\">
2278 <head>
2279 <title>%s</title>
2280 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2281 <meta name=\"generator\" content=\"Org-mode\"/>
2282 <meta name=\"generated\" content=\"%s\"/>
2283 <meta name=\"author\" content=\"%s\"/>
2285 </head><body>
2287 language language (org-html-expand title)
2288 (or charset "iso-8859-1") date author style))
2290 (insert (or (plist-get opt-plist :preamble) ""))
2292 (when (plist-get opt-plist :auto-preamble)
2293 (if title (insert (format org-export-html-title-format
2294 (org-html-expand title))))))
2296 (if (and org-export-with-toc (not body-only))
2297 (progn
2298 (push (format "<h%d>%s</h%d>\n"
2299 org-export-html-toplevel-hlevel
2300 (nth 3 lang-words)
2301 org-export-html-toplevel-hlevel)
2302 thetoc)
2303 (push "<div id=\"text-table-of-contents\">\n" thetoc)
2304 (push "<ul>\n<li>" thetoc)
2305 (setq lines
2306 (mapcar '(lambda (line)
2307 (if (string-match org-todo-line-regexp line)
2308 ;; This is a headline
2309 (progn
2310 (setq have-headings t)
2311 (setq level (- (match-end 1) (match-beginning 1))
2312 level (org-tr-level level)
2313 txt (save-match-data
2314 (org-html-expand
2315 (org-export-cleanup-toc-line
2316 (match-string 3 line))))
2317 todo
2318 (or (and org-export-mark-todo-in-toc
2319 (match-beginning 2)
2320 (not (member (match-string 2 line)
2321 org-done-keywords)))
2322 ; TODO, not DONE
2323 (and org-export-mark-todo-in-toc
2324 (= level umax-toc)
2325 (org-search-todo-below
2326 line lines level))))
2327 (if (string-match
2328 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2329 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
2330 (if (string-match quote-re0 txt)
2331 (setq txt (replace-match "" t t txt)))
2332 (setq snumber (org-section-number level))
2333 (if org-export-with-section-numbers
2334 (setq txt (concat snumber " " txt)))
2335 (if (<= level (max umax umax-toc))
2336 (setq head-count (+ head-count 1)))
2337 (if (<= level umax-toc)
2338 (progn
2339 (if (> level org-last-level)
2340 (progn
2341 (setq cnt (- level org-last-level))
2342 (while (>= (setq cnt (1- cnt)) 0)
2343 (push "\n<ul>\n<li>" thetoc))
2344 (push "\n" thetoc)))
2345 (if (< level org-last-level)
2346 (progn
2347 (setq cnt (- org-last-level level))
2348 (while (>= (setq cnt (1- cnt)) 0)
2349 (push "</li>\n</ul>" thetoc))
2350 (push "\n" thetoc)))
2351 ;; Check for targets
2352 (while (string-match org-any-target-regexp line)
2353 (setq line (replace-match
2354 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2355 t t line)))
2356 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2357 (setq txt (replace-match "" t t txt)))
2358 (push
2359 (format
2360 (if todo
2361 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2362 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2363 snumber txt) thetoc)
2365 (setq org-last-level level))
2367 line)
2368 lines))
2369 (while (> org-last-level (1- org-min-level))
2370 (setq org-last-level (1- org-last-level))
2371 (push "</li>\n</ul>\n" thetoc))
2372 (push "</div>\n" thetoc)
2373 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2375 (setq head-count 0)
2376 (org-init-section-numbers)
2378 (while (setq line (pop lines) origline line)
2379 (catch 'nextline
2381 ;; end of quote section?
2382 (when (and inquote (string-match "^\\*+ " line))
2383 (insert "</pre>\n")
2384 (setq inquote nil))
2385 ;; inside a quote section?
2386 (when inquote
2387 (insert (org-html-protect line) "\n")
2388 (throw 'nextline nil))
2390 ;; verbatim lines
2391 (when (and org-export-with-fixed-width
2392 (string-match "^[ \t]*:\\(.*\\)" line))
2393 (when (not infixed)
2394 (setq infixed t)
2395 (insert "<pre>\n"))
2396 (insert (org-html-protect (match-string 1 line)) "\n")
2397 (when (and lines
2398 (not (string-match "^[ \t]*\\(:.*\\)"
2399 (car lines))))
2400 (setq infixed nil)
2401 (insert "</pre>\n"))
2402 (throw 'nextline nil))
2404 ;; Protected HTML
2405 (when (get-text-property 0 'org-protected line)
2406 (let (par)
2407 (when (re-search-backward
2408 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
2409 (setq par (match-string 1))
2410 (replace-match "\\2\n"))
2411 (insert line "\n")
2412 (while (and lines
2413 (or (= (length (car lines)) 0)
2414 (get-text-property 0 'org-protected (car lines))))
2415 (insert (pop lines) "\n"))
2416 (and par (insert "<p>\n")))
2417 (throw 'nextline nil))
2419 ;; Horizontal line
2420 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
2421 (insert "\n<hr/>\n")
2422 (throw 'nextline nil))
2424 ;; make targets to anchors
2425 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
2426 (cond
2427 ((match-end 2)
2428 (setq line (replace-match
2429 (concat "@<a name=\""
2430 (org-solidify-link-text (match-string 1 line))
2431 "\">\\nbsp@</a>")
2432 t t line)))
2433 ((and org-export-with-toc (equal (string-to-char line) ?*))
2434 (setq line (replace-match
2435 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
2436 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2437 t t line)))
2439 (setq line (replace-match
2440 (concat "@<a name=\""
2441 (org-solidify-link-text (match-string 1 line))
2442 "\" class=\"target\">" (match-string 1 line) "@</a> ")
2443 t t line)))))
2445 (setq line (org-html-handle-time-stamps line))
2447 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
2448 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
2449 ;; Also handle sub_superscripts and checkboxes
2450 (or (string-match org-table-hline-regexp line)
2451 (setq line (org-html-expand line)))
2453 ;; Format the links
2454 (setq start 0)
2455 (while (string-match org-bracket-link-analytic-regexp line start)
2456 (setq start (match-beginning 0))
2457 (setq type (if (match-end 2) (match-string 2 line) "internal"))
2458 (setq path (match-string 3 line))
2459 (setq desc1 (if (match-end 5) (match-string 5 line))
2460 desc2 (if (match-end 2) (concat type ":" path) path)
2461 descp (and desc1 (not (equal desc1 desc2)))
2462 desc (or desc1 desc2))
2463 ;; Make an image out of the description if that is so wanted
2464 (when (and descp (org-file-image-p desc))
2465 (save-match-data
2466 (if (string-match "^file:" desc)
2467 (setq desc (substring desc (match-end 0)))))
2468 (setq desc (concat "<img src=\"" desc "\"/>")))
2469 ;; FIXME: do we need to unescape here somewhere?
2470 (cond
2471 ((equal type "internal")
2472 (setq rpl
2473 (concat
2474 "<a href=\"#"
2475 (org-solidify-link-text
2476 (save-match-data (org-link-unescape path)) nil)
2477 "\">" desc "</a>")))
2478 ((member type '("http" "https"))
2479 ;; standard URL, just check if we need to inline an image
2480 (if (and (or (eq t org-export-html-inline-images)
2481 (and org-export-html-inline-images (not descp)))
2482 (org-file-image-p path))
2483 (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
2484 (setq link (concat type ":" path))
2485 (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
2486 ((member type '("ftp" "mailto" "news"))
2487 ;; standard URL
2488 (setq link (concat type ":" path))
2489 (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
2490 ((string= type "file")
2491 ;; FILE link
2492 (let* ((filename path)
2493 (abs-p (file-name-absolute-p filename))
2494 thefile file-is-image-p search)
2495 (save-match-data
2496 (if (string-match "::\\(.*\\)" filename)
2497 (setq search (match-string 1 filename)
2498 filename (replace-match "" t nil filename)))
2499 (setq valid
2500 (if (functionp link-validate)
2501 (funcall link-validate filename current-dir)
2503 (setq file-is-image-p (org-file-image-p filename))
2504 (setq thefile (if abs-p (expand-file-name filename) filename))
2505 (when (and org-export-html-link-org-files-as-html
2506 (string-match "\\.org$" thefile))
2507 (setq thefile (concat (substring thefile 0
2508 (match-beginning 0))
2509 "." html-extension))
2510 (if (and search
2511 ;; make sure this is can be used as target search
2512 (not (string-match "^[0-9]*$" search))
2513 (not (string-match "^\\*" search))
2514 (not (string-match "^/.*/$" search)))
2515 (setq thefile (concat thefile "#"
2516 (org-solidify-link-text
2517 (org-link-unescape search)))))
2518 (when (string-match "^file:" desc)
2519 (setq desc (replace-match "" t t desc))
2520 (if (string-match "\\.org$" desc)
2521 (setq desc (replace-match "" t t desc))))))
2522 (setq rpl (if (and file-is-image-p
2523 (or (eq t org-export-html-inline-images)
2524 (and org-export-html-inline-images
2525 (not descp))))
2526 (concat "<img src=\"" thefile "\"/>")
2527 (concat "<a href=\"" thefile "\">" desc "</a>")))
2528 (if (not valid) (setq rpl desc))))
2530 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2531 (setq rpl
2532 (save-match-data
2533 (funcall fnc (org-link-unescape path) desc1 'html))))
2536 ;; just publish the path, as default
2537 (setq rpl (concat "<i>&lt;" type ":"
2538 (save-match-data (org-link-unescape path))
2539 "&gt;</i>"))))
2540 (setq line (replace-match rpl t t line)
2541 start (+ start (length rpl))))
2543 ;; TODO items
2544 (if (and (string-match org-todo-line-regexp line)
2545 (match-beginning 2))
2547 (setq line
2548 (concat (substring line 0 (match-beginning 2))
2549 "<span class=\""
2550 (if (member (match-string 2 line)
2551 org-done-keywords)
2552 "done" "todo")
2553 "\">" (match-string 2 line)
2554 "</span>" (substring line (match-end 2)))))
2556 ;; Does this contain a reference to a footnote?
2557 (when org-export-with-footnotes
2558 (setq start 0)
2559 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
2560 (if (get-text-property (match-beginning 2) 'org-protected line)
2561 (setq start (match-end 2))
2562 (let ((n (match-string 2 line)))
2563 (setq line
2564 (replace-match
2565 (format
2566 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2567 (match-string 1 line) n n n)
2568 t t line))))))
2570 (cond
2571 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2572 ;; This is a headline
2573 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2574 txt (match-string 2 line))
2575 (if (string-match quote-re0 txt)
2576 (setq txt (replace-match "" t t txt)))
2577 (if (<= level (max umax umax-toc))
2578 (setq head-count (+ head-count 1)))
2579 (when in-local-list
2580 ;; Close any local lists before inserting a new header line
2581 (while local-list-num
2582 (org-close-li)
2583 (insert (if (car local-list-num) "</ol>\n" "</ul>"))
2584 (pop local-list-num))
2585 (setq local-list-indent nil
2586 in-local-list nil))
2587 (setq first-heading-pos (or first-heading-pos (point)))
2588 (org-html-level-start level txt umax
2589 (and org-export-with-toc (<= level umax))
2590 head-count)
2591 ;; QUOTES
2592 (when (string-match quote-re line)
2593 (insert "<pre>")
2594 (setq inquote t)))
2596 ((and org-export-with-tables
2597 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2598 (if (not table-open)
2599 ;; New table starts
2600 (setq table-open t table-buffer nil table-orig-buffer nil))
2601 ;; Accumulate lines
2602 (setq table-buffer (cons line table-buffer)
2603 table-orig-buffer (cons origline table-orig-buffer))
2604 (when (or (not lines)
2605 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2606 (car lines))))
2607 (setq table-open nil
2608 table-buffer (nreverse table-buffer)
2609 table-orig-buffer (nreverse table-orig-buffer))
2610 (org-close-par-maybe)
2611 (insert (org-format-table-html table-buffer table-orig-buffer))))
2613 ;; Normal lines
2614 (when (string-match
2615 (cond
2616 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2617 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2618 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2619 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2620 line)
2621 (setq ind (org-get-string-indentation line)
2622 start-is-num (match-beginning 4)
2623 starter (if (match-beginning 2)
2624 (substring (match-string 2 line) 0 -1))
2625 line (substring line (match-beginning 5)))
2626 (unless (string-match "[^ \t]" line)
2627 ;; empty line. Pretend indentation is large.
2628 (setq ind (if org-empty-line-terminates-plain-lists
2630 (1+ (or (car local-list-indent) 1)))))
2631 (setq didclose nil)
2632 (while (and in-local-list
2633 (or (and (= ind (car local-list-indent))
2634 (not starter))
2635 (< ind (car local-list-indent))))
2636 (setq didclose t)
2637 (org-close-li)
2638 (insert (if (car local-list-num) "</ol>\n" "</ul>"))
2639 (pop local-list-num) (pop local-list-indent)
2640 (setq in-local-list local-list-indent))
2641 (cond
2642 ((and starter
2643 (or (not in-local-list)
2644 (> ind (car local-list-indent))))
2645 ;; Start new (level of) list
2646 (org-close-par-maybe)
2647 (insert (if start-is-num "<ol>\n<li>\n" "<ul>\n<li>\n"))
2648 (push start-is-num local-list-num)
2649 (push ind local-list-indent)
2650 (setq in-local-list t))
2651 (starter
2652 ;; continue current list
2653 (org-close-li)
2654 (insert "<li>\n"))
2655 (didclose
2656 ;; we did close a list, normal text follows: need <p>
2657 (org-open-par)))
2658 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
2659 (setq line
2660 (replace-match
2661 (if (equal (match-string 1 line) "X")
2662 "<b>[X]</b>"
2663 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2664 t t line))))
2666 ;; Empty lines start a new paragraph. If hand-formatted lists
2667 ;; are not fully interpreted, lines starting with "-", "+", "*"
2668 ;; also start a new paragraph.
2669 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
2671 ;; Is this the start of a footnote?
2672 (when org-export-with-footnotes
2673 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
2674 (org-close-par-maybe)
2675 (let ((n (match-string 1 line)))
2676 (setq line (replace-match
2677 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
2679 ;; Check if the line break needs to be conserved
2680 (cond
2681 ((string-match "\\\\\\\\[ \t]*$" line)
2682 (setq line (replace-match "<br/>" t t line)))
2683 (org-export-preserve-breaks
2684 (setq line (concat line "<br/>"))))
2686 (insert line "\n")))))
2688 ;; Properly close all local lists and other lists
2689 (when inquote (insert "</pre>\n"))
2690 (when in-local-list
2691 ;; Close any local lists before inserting a new header line
2692 (while local-list-num
2693 (org-close-li)
2694 (insert (if (car local-list-num) "</ol>\n" "</ul>\n"))
2695 (pop local-list-num))
2696 (setq local-list-indent nil
2697 in-local-list nil))
2698 (org-html-level-start 1 nil umax
2699 (and org-export-with-toc (<= level umax))
2700 head-count)
2701 ;; the </div> to lose the last text-... div.
2702 (insert "</div>\n")
2704 (unless body-only
2705 (when (plist-get opt-plist :auto-postamble)
2706 (insert "<div id=\"postamble\">")
2707 (when (and org-export-author-info author)
2708 (insert "<p class=\"author\"> "
2709 (nth 1 lang-words) ": " author "\n")
2710 (when email
2711 (if (listp (split-string email ",+ *"))
2712 (mapc (lambda(e)
2713 (insert "<a href=\"mailto:" e "\">&lt;"
2714 e "&gt;</a>\n"))
2715 (split-string email ",+ *"))
2716 (insert "<a href=\"mailto:" email "\">&lt;"
2717 email "&gt;</a>\n")))
2718 (insert "</p>\n"))
2719 (when (and date org-export-time-stamp-file)
2720 (insert "<p class=\"date\"> "
2721 (nth 2 lang-words) ": "
2722 date "</p>\n"))
2723 (insert "</div>"))
2725 (if org-export-html-with-timestamp
2726 (insert org-export-html-html-helper-timestamp))
2727 (insert (or (plist-get opt-plist :postamble) ""))
2728 (insert "</body>\n</html>\n"))
2730 (normal-mode)
2731 (if (eq major-mode default-major-mode) (html-mode))
2733 ;; insert the table of contents
2734 (goto-char (point-min))
2735 (when thetoc
2736 (if (or (re-search-forward
2737 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
2738 (re-search-forward
2739 "\\[TABLE-OF-CONTENTS\\]" nil t))
2740 (progn
2741 (goto-char (match-beginning 0))
2742 (replace-match ""))
2743 (goto-char first-heading-pos)
2744 (when (looking-at "\\s-*</p>")
2745 (goto-char (match-end 0))
2746 (insert "\n")))
2747 (insert "<div id=\"table-of-contents\">\n")
2748 (mapc 'insert thetoc)
2749 (insert "</div>\n"))
2750 ;; remove empty paragraphs and lists
2751 (goto-char (point-min))
2752 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2753 (replace-match ""))
2754 (goto-char (point-min))
2755 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
2756 (replace-match ""))
2757 (goto-char (point-min))
2758 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
2759 (replace-match ""))
2760 ;; Convert whitespace place holders
2761 (goto-char (point-min))
2762 (let (beg end n)
2763 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2764 (setq n (get-text-property beg 'org-whitespace)
2765 end (next-single-property-change beg 'org-whitespace))
2766 (goto-char beg)
2767 (delete-region beg end)
2768 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2769 (make-string n ?x)))))
2770 (or to-buffer (save-buffer))
2771 (goto-char (point-min))
2772 (message "Exporting... done")
2773 (if (eq to-buffer 'string)
2774 (prog1 (buffer-substring (point-min) (point-max))
2775 (kill-buffer (current-buffer)))
2776 (current-buffer)))))
2778 (defvar org-table-colgroup-info nil)
2779 (defun org-format-table-ascii (lines)
2780 "Format a table for ascii export."
2781 (if (stringp lines)
2782 (setq lines (org-split-string lines "\n")))
2783 (if (not (string-match "^[ \t]*|" (car lines)))
2784 ;; Table made by table.el - test for spanning
2785 lines
2787 ;; A normal org table
2788 ;; Get rid of hlines at beginning and end
2789 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2790 (setq lines (nreverse lines))
2791 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2792 (setq lines (nreverse lines))
2793 (when org-export-table-remove-special-lines
2794 ;; Check if the table has a marking column. If yes remove the
2795 ;; column and the special lines
2796 (setq lines (org-table-clean-before-export lines)))
2797 ;; Get rid of the vertical lines except for grouping
2798 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
2799 rtn line vl1 start)
2800 (while (setq line (pop lines))
2801 (if (string-match org-table-hline-regexp line)
2802 (and (string-match "|\\(.*\\)|" line)
2803 (setq line (replace-match " \\1" t nil line)))
2804 (setq start 0 vl1 vl)
2805 (while (string-match "|" line start)
2806 (setq start (match-end 0))
2807 (or (pop vl1) (setq line (replace-match " " t t line)))))
2808 (push line rtn))
2809 (nreverse rtn))))
2811 (defun org-colgroup-info-to-vline-list (info)
2812 (let (vl new last)
2813 (while info
2814 (setq last new new (pop info))
2815 (if (or (memq last '(:end :startend))
2816 (memq new '(:start :startend)))
2817 (push t vl)
2818 (push nil vl)))
2819 (setq vl (nreverse vl))
2820 (and vl (setcar vl nil))
2821 vl))
2823 (defvar org-table-number-regexp) ; defined in org-table.el
2824 (defun org-format-table-html (lines olines)
2825 "Find out which HTML converter to use and return the HTML code."
2826 (if (stringp lines)
2827 (setq lines (org-split-string lines "\n")))
2828 (if (string-match "^[ \t]*|" (car lines))
2829 ;; A normal org table
2830 (org-format-org-table-html lines)
2831 ;; Table made by table.el - test for spanning
2832 (let* ((hlines (delq nil (mapcar
2833 (lambda (x)
2834 (if (string-match "^[ \t]*\\+-" x) x
2835 nil))
2836 lines)))
2837 (first (car hlines))
2838 (ll (and (string-match "\\S-+" first)
2839 (match-string 0 first)))
2840 (re (concat "^[ \t]*" (regexp-quote ll)))
2841 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
2842 hlines))))
2843 (if (and (not spanning)
2844 (not org-export-prefer-native-exporter-for-tables))
2845 ;; We can use my own converter with HTML conversions
2846 (org-format-table-table-html lines)
2847 ;; Need to use the code generator in table.el, with the original text.
2848 (org-format-table-table-html-using-table-generate-source olines)))))
2850 (defvar org-table-number-fraction) ; defined in org-table.el
2851 (defun org-format-org-table-html (lines &optional splice)
2852 "Format a table into HTML."
2853 (require 'org-table)
2854 ;; Get rid of hlines at beginning and end
2855 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2856 (setq lines (nreverse lines))
2857 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
2858 (setq lines (nreverse lines))
2859 (when org-export-table-remove-special-lines
2860 ;; Check if the table has a marking column. If yes remove the
2861 ;; column and the special lines
2862 (setq lines (org-table-clean-before-export lines)))
2864 (let ((head (and org-export-highlight-first-table-line
2865 (delq nil (mapcar
2866 (lambda (x) (string-match "^[ \t]*|-" x))
2867 (cdr lines)))))
2868 (nlines 0) fnum i
2869 tbopen line fields html gr colgropen)
2870 (if splice (setq head nil))
2871 (unless splice (push (if head "<thead>" "<tbody>") html))
2872 (setq tbopen t)
2873 (while (setq line (pop lines))
2874 (catch 'next-line
2875 (if (string-match "^[ \t]*|-" line)
2876 (progn
2877 (unless splice
2878 (push (if head "</thead>" "</tbody>") html)
2879 (if lines (push "<tbody>" html) (setq tbopen nil)))
2880 (setq head nil) ;; head ends here, first time around
2881 ;; ignore this line
2882 (throw 'next-line t)))
2883 ;; Break the line into fields
2884 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2885 (unless fnum (setq fnum (make-vector (length fields) 0)))
2886 (setq nlines (1+ nlines) i -1)
2887 (push (concat "<tr>"
2888 (mapconcat
2889 (lambda (x)
2890 (setq i (1+ i))
2891 (if (and (< i nlines)
2892 (string-match org-table-number-regexp x))
2893 (incf (aref fnum i)))
2894 (if head
2895 (concat (car org-export-table-header-tags) x
2896 (cdr org-export-table-header-tags))
2897 (concat (car org-export-table-data-tags) x
2898 (cdr org-export-table-data-tags))))
2899 fields "")
2900 "</tr>")
2901 html)))
2902 (unless splice (if tbopen (push "</tbody>" html)))
2903 (unless splice (push "</table>\n" html))
2904 (setq html (nreverse html))
2905 (unless splice
2906 ;; Put in col tags with the alignment (unfortuntely often ignored...)
2907 (push (mapconcat
2908 (lambda (x)
2909 (setq gr (pop org-table-colgroup-info))
2910 (format "%s<col align=\"%s\"></col>%s"
2911 (if (memq gr '(:start :startend))
2912 (prog1
2913 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
2914 (setq colgropen t))
2916 (if (> (/ (float x) nlines) org-table-number-fraction)
2917 "right" "left")
2918 (if (memq gr '(:end :startend))
2919 (progn (setq colgropen nil) "</colgroup>")
2920 "")))
2921 fnum "")
2922 html)
2923 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
2924 (push html-table-tag html))
2925 (concat (mapconcat 'identity html "\n") "\n")))
2927 (defun org-table-clean-before-export (lines)
2928 "Check if the table has a marking column.
2929 If yes remove the column and the special lines."
2930 (setq org-table-colgroup-info nil)
2931 (if (memq nil
2932 (mapcar
2933 (lambda (x) (or (string-match "^[ \t]*|-" x)
2934 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
2935 lines))
2936 (progn
2937 (setq org-table-clean-did-remove-column nil)
2938 (delq nil
2939 (mapcar
2940 (lambda (x)
2941 (cond
2942 ((string-match "^[ \t]*| */ *|" x)
2943 (setq org-table-colgroup-info
2944 (mapcar (lambda (x)
2945 (cond ((member x '("<" "&lt;")) :start)
2946 ((member x '(">" "&gt;")) :end)
2947 ((member x '("<>" "&lt;&gt;")) :startend)
2948 (t nil)))
2949 (org-split-string x "[ \t]*|[ \t]*")))
2950 nil)
2951 (t x)))
2952 lines)))
2953 (setq org-table-clean-did-remove-column t)
2954 (delq nil
2955 (mapcar
2956 (lambda (x)
2957 (cond
2958 ((string-match "^[ \t]*| */ *|" x)
2959 (setq org-table-colgroup-info
2960 (mapcar (lambda (x)
2961 (cond ((member x '("<" "&lt;")) :start)
2962 ((member x '(">" "&gt;")) :end)
2963 ((member x '("<>" "&lt;&gt;")) :startend)
2964 (t nil)))
2965 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2966 nil)
2967 ((string-match "^[ \t]*| *[!_^/] *|" x)
2968 nil) ; ignore this line
2969 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2970 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2971 ;; remove the first column
2972 (replace-match "\\1|" t nil x))))
2973 lines))))
2975 (defun org-format-table-table-html (lines)
2976 "Format a table generated by table.el into HTML.
2977 This conversion does *not* use `table-generate-source' from table.el.
2978 This has the advantage that Org-mode's HTML conversions can be used.
2979 But it has the disadvantage, that no cell- or row-spanning is allowed."
2980 (let (line field-buffer
2981 (head org-export-highlight-first-table-line)
2982 fields html empty)
2983 (setq html (concat html-table-tag "\n"))
2984 (while (setq line (pop lines))
2985 (setq empty "&nbsp;")
2986 (catch 'next-line
2987 (if (string-match "^[ \t]*\\+-" line)
2988 (progn
2989 (if field-buffer
2990 (progn
2991 (setq
2992 html
2993 (concat
2994 html
2995 "<tr>"
2996 (mapconcat
2997 (lambda (x)
2998 (if (equal x "") (setq x empty))
2999 (if head
3000 (concat (car org-export-table-header-tags) x
3001 (cdr org-export-table-header-tags))
3002 (concat (car org-export-table-data-tags) x
3003 (cdr org-export-table-data-tags))))
3004 field-buffer "\n")
3005 "</tr>\n"))
3006 (setq head nil)
3007 (setq field-buffer nil)))
3008 ;; Ignore this line
3009 (throw 'next-line t)))
3010 ;; Break the line into fields and store the fields
3011 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3012 (if field-buffer
3013 (setq field-buffer (mapcar
3014 (lambda (x)
3015 (concat x "<br/>" (pop fields)))
3016 field-buffer))
3017 (setq field-buffer fields))))
3018 (setq html (concat html "</table>\n"))
3019 html))
3021 (defun org-format-table-table-html-using-table-generate-source (lines)
3022 "Format a table into html, using `table-generate-source' from table.el.
3023 This has the advantage that cell- or row-spanning is allowed.
3024 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3025 (require 'table)
3026 (with-current-buffer (get-buffer-create " org-tmp1 ")
3027 (erase-buffer)
3028 (insert (mapconcat 'identity lines "\n"))
3029 (goto-char (point-min))
3030 (if (not (re-search-forward "|[^+]" nil t))
3031 (error "Error processing table"))
3032 (table-recognize-table)
3033 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3034 (table-generate-source 'html " org-tmp2 ")
3035 (set-buffer " org-tmp2 ")
3036 (buffer-substring (point-min) (point-max))))
3038 (defun org-html-handle-time-stamps (s)
3039 "Format time stamps in string S, or remove them."
3040 (catch 'exit
3041 (let (r b)
3042 (while (string-match org-maybe-keyword-time-regexp s)
3043 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3044 ;; never export CLOCK
3045 (throw 'exit ""))
3046 (or b (setq b (substring s 0 (match-beginning 0))))
3047 (if (not org-export-with-timestamps)
3048 (setq r (concat r (substring s 0 (match-beginning 0)))
3049 s (substring s (match-end 0)))
3050 (setq r (concat
3051 r (substring s 0 (match-beginning 0))
3052 (if (match-end 1)
3053 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3054 (match-string 1 s)))
3055 (format " @<span class=\"timestamp\">%s@</span>"
3056 (substring
3057 (org-translate-time (match-string 3 s)) 1 -1)))
3058 s (substring s (match-end 0)))))
3059 ;; Line break if line started and ended with time stamp stuff
3060 (if (not r)
3062 (setq r (concat r s))
3063 (unless (string-match "\\S-" (concat b s))
3064 (setq r (concat r "@<br/>")))
3065 r))))
3067 (defun org-html-protect (s)
3068 ;; convert & to &amp;, < to &lt; and > to &gt;
3069 (let ((start 0))
3070 (while (string-match "&" s start)
3071 (setq s (replace-match "&amp;" t t s)
3072 start (1+ (match-beginning 0))))
3073 (while (string-match "<" s)
3074 (setq s (replace-match "&lt;" t t s)))
3075 (while (string-match ">" s)
3076 (setq s (replace-match "&gt;" t t s))))
3079 (defun org-export-cleanup-toc-line (s)
3080 "Remove tags and time staps from lines going into the toc."
3081 (when (memq org-export-with-tags '(not-in-toc nil))
3082 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
3083 (setq s (replace-match "" t t s))))
3084 (when org-export-remove-timestamps-from-toc
3085 (while (string-match org-maybe-keyword-time-regexp s)
3086 (setq s (replace-match "" t t s))))
3087 (while (string-match org-bracket-link-regexp s)
3088 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3089 t t s)))
3092 (defun org-html-expand (string)
3093 "Prepare STRING for HTML export. Applies all active conversions.
3094 If there are links in the string, don't modify these."
3095 (let* ((re (concat org-bracket-link-regexp "\\|"
3096 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3097 m s l res)
3098 (while (setq m (string-match re string))
3099 (setq s (substring string 0 m)
3100 l (match-string 0 string)
3101 string (substring string (match-end 0)))
3102 (push (org-html-do-expand s) res)
3103 (push l res))
3104 (push (org-html-do-expand string) res)
3105 (apply 'concat (nreverse res))))
3107 (defun org-html-do-expand (s)
3108 "Apply all active conversions to translate special ASCII to HTML."
3109 (setq s (org-html-protect s))
3110 (if org-export-html-expand
3111 (let ((start 0))
3112 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
3113 (setq s (replace-match "<\\1>" t nil s)))))
3114 (if org-export-with-emphasize
3115 (setq s (org-export-html-convert-emphasize s)))
3116 (if org-export-with-special-strings
3117 (setq s (org-export-html-convert-special-strings s)))
3118 (if org-export-with-sub-superscripts
3119 (setq s (org-export-html-convert-sub-super s)))
3120 (if org-export-with-TeX-macros
3121 (let ((start 0) wd ass)
3122 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
3123 (if (get-text-property (match-beginning 0) 'org-protected s)
3124 (setq start (match-end 0))
3125 (setq wd (match-string 1 s))
3126 (if (setq ass (assoc wd org-html-entities))
3127 (setq s (replace-match (or (cdr ass)
3128 (concat "&" (car ass) ";"))
3129 t t s))
3130 (setq start (+ start (length wd))))))))
3133 (defun org-create-multibrace-regexp (left right n)
3134 "Create a regular expression which will match a balanced sexp.
3135 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3136 as single character strings.
3137 The regexp returned will match the entire expression including the
3138 delimiters. It will also define a single group which contains the
3139 match except for the outermost delimiters. The maximum depth of
3140 stacked delimiters is N. Escaping delimiters is not possible."
3141 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
3142 (or "\\|")
3143 (re nothing)
3144 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
3145 (while (> n 1)
3146 (setq n (1- n)
3147 re (concat re or next)
3148 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
3149 (concat left "\\(" re "\\)" right)))
3151 (defvar org-match-substring-regexp
3152 (concat
3153 "\\([^\\]\\)\\([_^]\\)\\("
3154 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3155 "\\|"
3156 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
3157 "\\|"
3158 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3159 "The regular expression matching a sub- or superscript.")
3161 (defvar org-match-substring-with-braces-regexp
3162 (concat
3163 "\\([^\\]\\)\\([_^]\\)\\("
3164 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
3165 "\\)")
3166 "The regular expression matching a sub- or superscript, forcing braces.")
3168 (defconst org-export-html-special-string-regexps
3169 '(("\\\\-" . "&shy;")
3170 ("---\\([^-]\\)" . "&mdash;\\1")
3171 ("--\\([^-]\\)" . "&ndash;\\1")
3172 ("\\.\\.\\." . "&hellip;"))
3173 "Regular expressions for special string conversion.")
3175 (defun org-export-html-convert-special-strings (string)
3176 "Convert special characters in STRING to HTML."
3177 (let ((all org-export-html-special-string-regexps)
3178 e a re rpl start)
3179 (while (setq a (pop all))
3180 (setq re (car a) rpl (cdr a) start 0)
3181 (while (string-match re string start)
3182 (if (get-text-property (match-beginning 0) 'org-protected string)
3183 (setq start (match-end 0))
3184 (setq string (replace-match rpl t nil string)))))
3185 string))
3187 (defun org-export-html-convert-sub-super (string)
3188 "Convert sub- and superscripts in STRING to HTML."
3189 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
3190 (while (string-match org-match-substring-regexp string s)
3191 (cond
3192 ((and requireb (match-end 8)) (setq s (match-end 2)))
3193 ((get-text-property (match-beginning 2) 'org-protected string)
3194 (setq s (match-end 2)))
3196 (setq s (match-end 1)
3197 key (if (string= (match-string 2 string) "_") "sub" "sup")
3198 c (or (match-string 8 string)
3199 (match-string 6 string)
3200 (match-string 5 string))
3201 string (replace-match
3202 (concat (match-string 1 string)
3203 "<" key ">" c "</" key ">")
3204 t t string)))))
3205 (while (string-match "\\\\\\([_^]\\)" string)
3206 (setq string (replace-match (match-string 1 string) t t string)))
3207 string))
3209 (defun org-export-html-convert-emphasize (string)
3210 "Apply emphasis."
3211 (let ((s 0) rpl)
3212 (while (string-match org-emph-re string s)
3213 (if (not (equal
3214 (substring string (match-beginning 3) (1+ (match-beginning 3)))
3215 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
3216 (setq s (match-beginning 0)
3218 (concat
3219 (match-string 1 string)
3220 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
3221 (match-string 4 string)
3222 (nth 3 (assoc (match-string 3 string)
3223 org-emphasis-alist))
3224 (match-string 5 string))
3225 string (replace-match rpl t t string)
3226 s (+ s (- (length rpl) 2)))
3227 (setq s (1+ s))))
3228 string))
3230 (defvar org-par-open nil)
3231 (defun org-open-par ()
3232 "Insert <p>, but first close previous paragraph if any."
3233 (org-close-par-maybe)
3234 (insert "\n<p>")
3235 (setq org-par-open t))
3236 (defun org-close-par-maybe ()
3237 "Close paragraph if there is one open."
3238 (when org-par-open
3239 (insert "</p>")
3240 (setq org-par-open nil)))
3241 (defun org-close-li ()
3242 "Close <li> if necessary."
3243 (org-close-par-maybe)
3244 (insert "</li>\n"))
3246 (defvar body-only) ; dynamically scoped into this.
3247 (defun org-html-level-start (level title umax with-toc head-count)
3248 "Insert a new level in HTML export.
3249 When TITLE is nil, just close all open levels."
3250 (org-close-par-maybe)
3251 (let ((target (and title (org-get-text-property-any 0 'target title)))
3252 (l org-level-max)
3253 snumber)
3254 (while (>= l level)
3255 (if (aref org-levels-open (1- l))
3256 (progn
3257 (org-html-level-close l umax)
3258 (aset org-levels-open (1- l) nil)))
3259 (setq l (1- l)))
3260 (when title
3261 ;; If title is nil, this means this function is called to close
3262 ;; all levels, so the rest is done only if title is given
3263 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3264 (setq title (replace-match
3265 (if org-export-with-tags
3266 (save-match-data
3267 (concat
3268 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
3269 (mapconcat 'identity (org-split-string
3270 (match-string 1 title) ":")
3271 "&nbsp;")
3272 "</span>"))
3274 t t title)))
3275 (if (> level umax)
3276 (progn
3277 (if (aref org-levels-open (1- level))
3278 (progn
3279 (org-close-li)
3280 (if target
3281 (insert (format "<li id=\"%s\">" target) title "<br/>\n")
3282 (insert "<li>" title "<br/>\n")))
3283 (aset org-levels-open (1- level) t)
3284 (org-close-par-maybe)
3285 (if target
3286 (insert (format "<ul>\n<li id=\"%s\">" target)
3287 title "<br/>\n")
3288 (insert "<ul>\n<li>" title "<br/>\n"))))
3289 (aset org-levels-open (1- level) t)
3290 (setq snumber (org-section-number level))
3291 (if (and org-export-with-section-numbers (not body-only))
3292 (setq title (concat snumber " " title)))
3293 (setq level (+ level org-export-html-toplevel-hlevel -1))
3294 (unless (= head-count 1) (insert "\n</div>\n"))
3295 (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"
3296 snumber level level snumber title level snumber))
3297 (org-open-par)))))
3299 (defun org-get-text-property-any (pos prop &optional object)
3300 (or (get-text-property pos prop object)
3301 (and (setq pos (next-single-property-change pos prop object))
3302 (get-text-property pos prop object))))
3304 (defun org-html-level-close (level max-outline-level)
3305 "Terminate one level in HTML export."
3306 (if (<= level max-outline-level)
3307 (insert "</div>\n")
3308 (org-close-li)
3309 (insert "</ul>\n")))
3311 ;;; iCalendar export
3313 ;;;###autoload
3314 (defun org-export-icalendar-this-file ()
3315 "Export current file as an iCalendar file.
3316 The iCalendar file will be located in the same directory as the Org-mode
3317 file, but with extension `.ics'."
3318 (interactive)
3319 (org-export-icalendar nil buffer-file-name))
3321 ;;;###autoload
3322 (defun org-export-icalendar-all-agenda-files ()
3323 "Export all files in `org-agenda-files' to iCalendar .ics files.
3324 Each iCalendar file will be located in the same directory as the Org-mode
3325 file, but with extension `.ics'."
3326 (interactive)
3327 (apply 'org-export-icalendar nil (org-agenda-files t)))
3329 ;;;###autoload
3330 (defun org-export-icalendar-combine-agenda-files ()
3331 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3332 The file is stored under the name `org-combined-agenda-icalendar-file'."
3333 (interactive)
3334 (apply 'org-export-icalendar t (org-agenda-files t)))
3336 (defun org-export-icalendar (combine &rest files)
3337 "Create iCalendar files for all elements of FILES.
3338 If COMBINE is non-nil, combine all calendar entries into a single large
3339 file and store it under the name `org-combined-agenda-icalendar-file'."
3340 (save-excursion
3341 (org-prepare-agenda-buffers files)
3342 (let* ((dir (org-export-directory
3343 :ical (list :publishing-directory
3344 org-export-publishing-directory)))
3345 file ical-file ical-buffer category started org-agenda-new-buffers)
3346 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3347 (when combine
3348 (setq ical-file
3349 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
3350 org-combined-agenda-icalendar-file
3351 (expand-file-name org-combined-agenda-icalendar-file dir))
3352 ical-buffer (org-get-agenda-file-buffer ical-file))
3353 (set-buffer ical-buffer) (erase-buffer))
3354 (while (setq file (pop files))
3355 (catch 'nextfile
3356 (org-check-agenda-file file)
3357 (set-buffer (org-get-agenda-file-buffer file))
3358 (unless combine
3359 (setq ical-file (concat (file-name-as-directory dir)
3360 (file-name-sans-extension
3361 (file-name-nondirectory buffer-file-name))
3362 ".ics"))
3363 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
3364 (with-current-buffer ical-buffer (erase-buffer)))
3365 (setq category (or org-category
3366 (file-name-sans-extension
3367 (file-name-nondirectory buffer-file-name))))
3368 (if (symbolp category) (setq category (symbol-name category)))
3369 (let ((standard-output ical-buffer))
3370 (if combine
3371 (and (not started) (setq started t)
3372 (org-start-icalendar-file org-icalendar-combined-name))
3373 (org-start-icalendar-file category))
3374 (org-print-icalendar-entries combine)
3375 (when (or (and combine (not files)) (not combine))
3376 (org-finish-icalendar-file)
3377 (set-buffer ical-buffer)
3378 (save-buffer)
3379 (run-hooks 'org-after-save-iCalendar-file-hook)))))
3380 (org-release-buffers org-agenda-new-buffers))))
3382 (defvar org-after-save-iCalendar-file-hook nil
3383 "Hook run after an iCalendar file has been saved.
3384 The iCalendar buffer is still current when this hook is run.
3385 A good way to use this is to tell a desktop calenndar application to re-read
3386 the iCalendar file.")
3388 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
3389 (defun org-print-icalendar-entries (&optional combine)
3390 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3391 When COMBINE is non nil, add the category to each line."
3392 (require 'org-agenda)
3393 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
3394 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
3395 (dts (org-ical-ts-to-string
3396 (format-time-string (cdr org-time-stamp-formats) (current-time))
3397 "DTSTART"))
3398 hd ts ts2 state status (inc t) pos b sexp rrule
3399 scheduledp deadlinep tmp pri category entry location summary desc
3400 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3401 (org-refresh-category-properties)
3402 (save-excursion
3403 (goto-char (point-min))
3404 (while (re-search-forward re1 nil t)
3405 (catch :skip
3406 (org-agenda-skip)
3407 (when (boundp 'org-icalendar-verify-function)
3408 (unless (funcall org-icalendar-verify-function)
3409 (outline-next-heading)
3410 (backward-char 1)
3411 (throw :skip nil)))
3412 (setq pos (match-beginning 0)
3413 ts (match-string 0)
3414 inc t
3415 hd (condition-case nil (org-get-heading)
3416 (error (throw :skip nil)))
3417 summary (org-icalendar-cleanup-string
3418 (org-entry-get nil "SUMMARY"))
3419 desc (org-icalendar-cleanup-string
3420 (or (org-entry-get nil "DESCRIPTION")
3421 (and org-icalendar-include-body (org-get-entry)))
3422 t org-icalendar-include-body)
3423 location (org-icalendar-cleanup-string
3424 (org-entry-get nil "LOCATION"))
3425 category (org-get-category))
3426 (if (looking-at re2)
3427 (progn
3428 (goto-char (match-end 0))
3429 (setq ts2 (match-string 1) inc nil))
3430 (setq tmp (buffer-substring (max (point-min)
3431 (- pos org-ds-keyword-length))
3432 pos)
3433 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
3434 (progn
3435 (setq inc nil)
3436 (replace-match "\\1" t nil ts))
3438 deadlinep (string-match org-deadline-regexp tmp)
3439 scheduledp (string-match org-scheduled-regexp tmp)
3440 ;; donep (org-entry-is-done-p)
3442 (if (or (string-match org-tr-regexp hd)
3443 (string-match org-ts-regexp hd))
3444 (setq hd (replace-match "" t t hd)))
3445 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
3446 (setq rrule
3447 (concat "\nRRULE:FREQ="
3448 (cdr (assoc
3449 (match-string 2 ts)
3450 '(("d" . "DAILY")("w" . "WEEKLY")
3451 ("m" . "MONTHLY")("y" . "YEARLY"))))
3452 ";INTERVAL=" (match-string 1 ts)))
3453 (setq rrule ""))
3454 (setq summary (or summary hd))
3455 (if (string-match org-bracket-link-regexp summary)
3456 (setq summary
3457 (replace-match (if (match-end 3)
3458 (match-string 3 summary)
3459 (match-string 1 summary))
3460 t t summary)))
3461 (if deadlinep (setq summary (concat "DL: " summary)))
3462 (if scheduledp (setq summary (concat "S: " summary)))
3463 (if (string-match "\\`<%%" ts)
3464 (with-current-buffer sexp-buffer
3465 (insert (substring ts 1 -1) " " summary "\n"))
3466 (princ (format "BEGIN:VEVENT
3468 %s%s
3469 SUMMARY:%s%s%s
3470 CATEGORIES:%s
3471 END:VEVENT\n"
3472 (org-ical-ts-to-string ts "DTSTART")
3473 (org-ical-ts-to-string ts2 "DTEND" inc)
3474 rrule summary
3475 (if (and desc (string-match "\\S-" desc))
3476 (concat "\nDESCRIPTION: " desc) "")
3477 (if (and location (string-match "\\S-" location))
3478 (concat "\nLOCATION: " location) "")
3479 category)))))
3481 (when (and org-icalendar-include-sexps
3482 (condition-case nil (require 'icalendar) (error nil))
3483 (fboundp 'icalendar-export-region))
3484 ;; Get all the literal sexps
3485 (goto-char (point-min))
3486 (while (re-search-forward "^&?%%(" nil t)
3487 (catch :skip
3488 (org-agenda-skip)
3489 (setq b (match-beginning 0))
3490 (goto-char (1- (match-end 0)))
3491 (forward-sexp 1)
3492 (end-of-line 1)
3493 (setq sexp (buffer-substring b (point)))
3494 (with-current-buffer sexp-buffer
3495 (insert sexp "\n"))
3496 (princ (org-diary-to-ical-string sexp-buffer)))))
3498 (when org-icalendar-include-todo
3499 (goto-char (point-min))
3500 (while (re-search-forward org-todo-line-regexp nil t)
3501 (catch :skip
3502 (org-agenda-skip)
3503 (when (boundp 'org-icalendar-verify-function)
3504 (unless (funcall org-icalendar-verify-function)
3505 (outline-next-heading)
3506 (backward-char 1)
3507 (throw :skip nil)))
3508 (setq state (match-string 2))
3509 (setq status (if (member state org-done-keywords)
3510 "COMPLETED" "NEEDS-ACTION"))
3511 (when (and state
3512 (or (not (member state org-done-keywords))
3513 (eq org-icalendar-include-todo 'all))
3514 (not (member org-archive-tag (org-get-tags-at)))
3516 (setq hd (match-string 3)
3517 summary (org-icalendar-cleanup-string
3518 (org-entry-get nil "SUMMARY"))
3519 desc (org-icalendar-cleanup-string
3520 (or (org-entry-get nil "DESCRIPTION")
3521 (and org-icalendar-include-body (org-get-entry)))
3522 t org-icalendar-include-body)
3523 location (org-icalendar-cleanup-string
3524 (org-entry-get nil "LOCATION")))
3525 (if (string-match org-bracket-link-regexp hd)
3526 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
3527 (match-string 1 hd))
3528 t t hd)))
3529 (if (string-match org-priority-regexp hd)
3530 (setq pri (string-to-char (match-string 2 hd))
3531 hd (concat (substring hd 0 (match-beginning 1))
3532 (substring hd (match-end 1))))
3533 (setq pri org-default-priority))
3534 (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
3535 (- org-lowest-priority org-highest-priority))))))
3537 (princ (format "BEGIN:VTODO
3539 SUMMARY:%s%s%s
3540 CATEGORIES:%s
3541 SEQUENCE:1
3542 PRIORITY:%d
3543 STATUS:%s
3544 END:VTODO\n"
3546 (or summary hd)
3547 (if (and location (string-match "\\S-" location))
3548 (concat "\nLOCATION: " location) "")
3549 (if (and desc (string-match "\\S-" desc))
3550 (concat "\nDESCRIPTION: " desc) "")
3551 category pri status)))))))))
3553 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
3554 "Take out stuff and quote what needs to be quoted.
3555 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3556 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3557 characters."
3558 (if (not s)
3560 (when is-body
3561 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
3562 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
3563 (while (string-match re s) (setq s (replace-match "" t t s)))
3564 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
3565 (let ((start 0))
3566 (while (string-match "\\([,;\\]\\)" s start)
3567 (setq start (+ (match-beginning 0) 2)
3568 s (replace-match "\\\\\\1" nil nil s))))
3569 (when is-body
3570 (while (string-match "[ \t]*\n[ \t]*" s)
3571 (setq s (replace-match "\\n" t t s))))
3572 (setq s (org-trim s))
3573 (if is-body
3574 (if maxlength
3575 (if (and (numberp maxlength)
3576 (> (length s) maxlength))
3577 (setq s (substring s 0 maxlength)))))
3580 (defun org-get-entry ()
3581 "Clean-up description string."
3582 (save-excursion
3583 (org-back-to-heading t)
3584 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
3586 (defun org-start-icalendar-file (name)
3587 "Start an iCalendar file by inserting the header."
3588 (let ((user user-full-name)
3589 (name (or name "unknown"))
3590 (timezone (cadr (current-time-zone))))
3591 (princ
3592 (format "BEGIN:VCALENDAR
3593 VERSION:2.0
3594 X-WR-CALNAME:%s
3595 PRODID:-//%s//Emacs with Org-mode//EN
3596 X-WR-TIMEZONE:%s
3597 CALSCALE:GREGORIAN\n" name user timezone))))
3599 (defun org-finish-icalendar-file ()
3600 "Finish an iCalendar file by inserting the END statement."
3601 (princ "END:VCALENDAR\n"))
3603 (defun org-ical-ts-to-string (s keyword &optional inc)
3604 "Take a time string S and convert it to iCalendar format.
3605 KEYWORD is added in front, to make a complete line like DTSTART....
3606 When INC is non-nil, increase the hour by two (if time string contains
3607 a time), or the day by one (if it does not contain a time)."
3608 (let ((t1 (org-parse-time-string s 'nodefault))
3609 t2 fmt have-time time)
3610 (if (and (car t1) (nth 1 t1) (nth 2 t1))
3611 (setq t2 t1 have-time t)
3612 (setq t2 (org-parse-time-string s)))
3613 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
3614 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
3615 (when inc
3616 (if have-time
3617 (if org-agenda-default-appointment-duration
3618 (setq mi (+ org-agenda-default-appointment-duration mi))
3619 (setq h (+ 2 h)))
3620 (setq d (1+ d))))
3621 (setq time (encode-time s mi h d m y)))
3622 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3623 (concat keyword (format-time-string fmt time))))
3625 ;;; XOXO export
3627 (defun org-export-as-xoxo-insert-into (buffer &rest output)
3628 (with-current-buffer buffer
3629 (apply 'insert output)))
3630 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
3632 ;;;###autoload
3633 (defun org-export-as-xoxo (&optional buffer)
3634 "Export the org buffer as XOXO.
3635 The XOXO buffer is named *xoxo-<source buffer name>*"
3636 (interactive (list (current-buffer)))
3637 ;; A quickie abstraction
3639 ;; Output everything as XOXO
3640 (with-current-buffer (get-buffer buffer)
3641 (let* ((pos (point))
3642 (opt-plist (org-combine-plists (org-default-export-plist)
3643 (org-infile-export-plist)))
3644 (filename (concat (file-name-as-directory
3645 (org-export-directory :xoxo opt-plist))
3646 (file-name-sans-extension
3647 (file-name-nondirectory buffer-file-name))
3648 ".html"))
3649 (out (find-file-noselect filename))
3650 (last-level 1)
3651 (hanging-li nil))
3652 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3653 ;; Check the output buffer is empty.
3654 (with-current-buffer out (erase-buffer))
3655 ;; Kick off the output
3656 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
3657 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
3658 (let* ((hd (match-string-no-properties 1))
3659 (level (length hd))
3660 (text (concat
3661 (match-string-no-properties 2)
3662 (save-excursion
3663 (goto-char (match-end 0))
3664 (let ((str ""))
3665 (catch 'loop
3666 (while 't
3667 (forward-line)
3668 (if (looking-at "^[ \t]\\(.*\\)")
3669 (setq str (concat str (match-string-no-properties 1)))
3670 (throw 'loop str)))))))))
3672 ;; Handle level rendering
3673 (cond
3674 ((> level last-level)
3675 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
3677 ((< level last-level)
3678 (dotimes (- (- last-level level) 1)
3679 (if hanging-li
3680 (org-export-as-xoxo-insert-into out "</li>\n"))
3681 (org-export-as-xoxo-insert-into out "</ol>\n"))
3682 (when hanging-li
3683 (org-export-as-xoxo-insert-into out "</li>\n")
3684 (setq hanging-li nil)))
3686 ((equal level last-level)
3687 (if hanging-li
3688 (org-export-as-xoxo-insert-into out "</li>\n")))
3691 (setq last-level level)
3693 ;; And output the new li
3694 (setq hanging-li 't)
3695 (if (equal ?+ (elt text 0))
3696 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
3697 (org-export-as-xoxo-insert-into out "<li>" text))))
3699 ;; Finally finish off the ol
3700 (dotimes (- last-level 1)
3701 (if hanging-li
3702 (org-export-as-xoxo-insert-into out "</li>\n"))
3703 (org-export-as-xoxo-insert-into out "</ol>\n"))
3705 (goto-char pos)
3706 ;; Finish the buffer off and clean it up.
3707 (switch-to-buffer-other-window out)
3708 (indent-region (point-min) (point-max) nil)
3709 (save-buffer)
3710 (goto-char (point-min))
3713 (provide 'org-exp)
3715 ;;; org-exp.el ends here
3718 (defun org-export-process-option-filters (plist)
3719 (let ((functions org-export-options-filters) f)
3720 (while (setq f (pop functions))
3721 (setq plist (funcall f plist))))
3722 plist)