Captions and attributes for images and tables during export
[org-mode/org-tableheadings.git] / lisp / org-exp.el
bloba24b439138866e5238b2803019603429cff5cce5
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.14
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
29 (require 'org-agenda)
30 (eval-and-compile
31 (require 'cl))
33 (declare-function org-export-latex-preprocess "org-export-latex" ())
34 (declare-function org-agenda-skip "org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
36 (declare-function htmlize-region "ext:htmlize" (beg end))
37 (defvar htmlize-buffer-places) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
41 :tag "Org Export"
42 :group 'org)
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag "Org Export General"
47 :group 'org-export)
49 ;; FIXME
50 (defvar org-export-publishing-directory nil)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group 'org-export-general
65 :type 'boolean)
68 (defcustom org-export-select-tags '("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-exclude-tags'."
74 :group 'org-export-general
75 :type '(repeat (string :tag "Tag")))
77 (defcustom org-export-exclude-tags '("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without contition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group 'org-export-general
83 :type '(repeat (string :tag "Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
89 Org HTML LaTeX
90 -----+----------+--------
91 \\- &shy; \\-
92 -- &ndash; --
93 --- &mdash; ---
94 ... &hellip; \ldots
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group 'org-export-translation
98 :type 'boolean)
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
102 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
103 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
104 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
105 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
106 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
107 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
108 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
109 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
110 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
111 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
112 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
113 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
114 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
115 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
116 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
117 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
118 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
119 "Terms used in export text, translated to different languages.
120 Use the variable `org-export-default-language' to set the language,
121 or use the +OPTION lines for a per-file setting."
122 :group 'org-export-general
123 :type '(repeat
124 (list
125 (string :tag "HTML language tag")
126 (string :tag "Author")
127 (string :tag "Date")
128 (string :tag "Table of Contents")
129 (string :tag "Footnotes"))))
131 (defcustom org-export-default-language "en"
132 "The default language of HTML export, as a string.
133 This should have an association in `org-export-language-setup'."
134 :group 'org-export-general
135 :type 'string)
137 (defcustom org-export-skip-text-before-1st-heading nil
138 "Non-nil means, skip all text before the first headline when exporting.
139 When nil, that text is exported as well."
140 :group 'org-export-general
141 :type 'boolean)
143 (defcustom org-export-headline-levels 3
144 "The last level which is still exported as a headline.
145 Inferior levels will produce itemize lists when exported.
146 Note that a numeric prefix argument to an exporter function overrides
147 this setting.
149 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
150 :group 'org-export-general
151 :type 'number)
153 (defcustom org-export-with-section-numbers t
154 "Non-nil means, add section numbers to headlines when exporting.
156 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
157 :group 'org-export-general
158 :type 'boolean)
160 (defcustom org-export-section-number-format '((("1" ".")) . "")
161 "Format of section numbers for export.
162 The variable has two components.
163 1. A list of lists, each indicating a counter type and a separator.
164 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
165 It causes causes numeric, alphabetic, or roman counters, respectively.
166 The separator is only used if another counter for a subsection is being
167 added.
168 If there are more numbered section levels than entries in this lists,
169 then the last entry will be reused.
170 2. A terminator string that will be added after the entire
171 section number."
172 :group 'org-export-general
173 :type '(cons
174 (repeat
175 (list
176 (string :tag "Counter Type")
177 (string :tag "Separator ")))
178 (string :tag "Terminator")))
180 (defcustom org-export-with-toc t
181 "Non-nil means, create a table of contents in exported files.
182 The TOC contains headlines with levels up to`org-export-headline-levels'.
183 When an integer, include levels up to N in the toc, this may then be
184 different from `org-export-headline-levels', but it will not be allowed
185 to be larger than the number of headline levels.
186 When nil, no table of contents is made.
188 Headlines which contain any TODO items will be marked with \"(*)\" in
189 ASCII export, and with red color in HTML output, if the option
190 `org-export-mark-todo-in-toc' is set.
192 In HTML output, the TOC will be clickable.
194 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
195 or \"toc:3\"."
196 :group 'org-export-general
197 :type '(choice
198 (const :tag "No Table of Contents" nil)
199 (const :tag "Full Table of Contents" t)
200 (integer :tag "TOC to level")))
202 (defcustom org-export-mark-todo-in-toc nil
203 "Non-nil means, mark TOC lines that contain any open TODO items."
204 :group 'org-export-general
205 :type 'boolean)
207 (defcustom org-export-with-todo-keywords t
208 "Non-nil means, include TODO keywords in export.
209 When nil, remove all these keywords from the export."
210 :group 'org-export-general
211 :type 'boolean)
213 (defcustom org-export-with-priority nil
214 "Non-nil means, include priority cookies in export.
215 When nil, remove priority cookies for export."
216 :group 'org-export-general
217 :type 'boolean)
219 (defcustom org-export-preserve-breaks nil
220 "Non-nil means, preserve all line breaks when exporting.
221 Normally, in HTML output paragraphs will be reformatted. In ASCII
222 export, line breaks will always be preserved, regardless of this variable.
224 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
225 :group 'org-export-general
226 :type 'boolean)
228 (defcustom org-export-with-archived-trees 'headline
229 "Whether subtrees with the ARCHIVE tag should be exported.
230 This can have three different values
231 nil Do not export, pretend this tree is not present
232 t Do export the entire tree
233 headline Only export the headline, but skip the tree below it."
234 :group 'org-export-general
235 :group 'org-archive
236 :type '(choice
237 (const :tag "not at all" nil)
238 (const :tag "headline only" 'headline)
239 (const :tag "entirely" t)))
241 (defcustom org-export-author-info t
242 "Non-nil means, insert author name and email into the exported file.
244 This option can also be set with the +OPTIONS line,
245 e.g. \"author-info:nil\"."
246 :group 'org-export-general
247 :type 'boolean)
249 (defcustom org-export-creator-info t
250 "Non-nil means, the postamle should contain a creator sentence.
251 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
252 :group 'org-export-general
253 :type 'boolean)
255 (defcustom org-export-time-stamp-file t
256 "Non-nil means, insert a time stamp into the exported file.
257 The time stamp shows when the file was created.
259 This option can also be set with the +OPTIONS line,
260 e.g. \"timestamp:nil\"."
261 :group 'org-export-general
262 :type 'boolean)
264 (defcustom org-export-with-timestamps t
265 "If nil, do not export time stamps and associated keywords."
266 :group 'org-export-general
267 :type 'boolean)
269 (defcustom org-export-remove-timestamps-from-toc t
270 "If nil, remove timestamps from the table of contents entries."
271 :group 'org-export-general
272 :type 'boolean)
274 (defcustom org-export-with-tags 'not-in-toc
275 "If nil, do not export tags, just remove them from headlines.
276 If this is the symbol `not-in-toc', tags will be removed from table of
277 contents entries, but still be shown in the headlines of the document.
279 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
280 :group 'org-export-general
281 :type '(choice
282 (const :tag "Off" nil)
283 (const :tag "Not in TOC" not-in-toc)
284 (const :tag "On" t)))
286 (defcustom org-export-with-drawers nil
287 "Non-nil means, export with drawers like the property drawer.
288 When t, all drawers are exported. This may also be a list of
289 drawer names to export."
290 :group 'org-export-general
291 :type '(choice
292 (const :tag "All drawers" t)
293 (const :tag "None" nil)
294 (repeat :tag "Selected drawers"
295 (string :tag "Drawer name"))))
297 (defvar org-export-preprocess-hook nil
298 "Hook for preprocessing an export buffer.
299 Pretty much the first thing when exporting is running this hook.")
301 (defgroup org-export-translation nil
302 "Options for translating special ascii sequences for the export backends."
303 :tag "Org Export Translation"
304 :group 'org-export)
306 (defcustom org-export-with-emphasize t
307 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
308 If the export target supports emphasizing text, the word will be
309 typeset in bold, italic, or underlined, respectively. Works only for
310 single words, but you can say: I *really* *mean* *this*.
311 Not all export backends support this.
313 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
314 :group 'org-export-translation
315 :type 'boolean)
317 (defcustom org-export-with-footnotes t
318 "If nil, export [1] as a footnote marker.
319 Lines starting with [1] will be formatted as footnotes.
321 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
322 :group 'org-export-translation
323 :type 'boolean)
325 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
326 <h2 class=\"footnotes\">%s: </h2>
327 <div id=\"footnotes-text\">
329 </div>
330 </div>"
331 "Format for the footnotes section.
332 Should contain a two instances of %s. The first will be replaced with the
333 language-specific word for \"Footnotes\", the second one will be replaced
334 by the footnotes themselves."
335 :group 'org-export-html
336 :type 'string)
338 (defcustom org-export-with-sub-superscripts t
339 "Non-nil means, interpret \"_\" and \"^\" for export.
340 When this option is turned on, you can use TeX-like syntax for sub- and
341 superscripts. Several characters after \"_\" or \"^\" will be
342 considered as a single item - so grouping with {} is normally not
343 needed. For example, the following things will be parsed as single
344 sub- or superscripts.
346 10^24 or 10^tau several digits will be considered 1 item.
347 10^-12 or 10^-tau a leading sign with digits or a word
348 x^2-y^3 will be read as x^2 - y^3, because items are
349 terminated by almost any nonword/nondigit char.
350 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
352 Still, ambiguity is possible - so when in doubt use {} to enclose the
353 sub/superscript. If you set this variable to the symbol `{}',
354 the braces are *required* in order to trigger interpretations as
355 sub/superscript. This can be helpful in documents that need \"_\"
356 frequently in plain text.
358 Not all export backends support this, but HTML does.
360 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
361 :group 'org-export-translation
362 :type '(choice
363 (const :tag "Always interpret" t)
364 (const :tag "Only with braces" {})
365 (const :tag "Never interpret" nil)))
367 (defcustom org-export-with-special-strings t
368 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
369 When this option is turned on, these strings will be exported as:
371 \\- : &shy;
372 -- : &ndash;
373 --- : &mdash;
375 Not all export backends support this, but HTML does.
377 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
378 :group 'org-export-translation
379 :type 'boolean)
381 (defcustom org-export-with-TeX-macros t
382 "Non-nil means, interpret simple TeX-like macros when exporting.
383 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
384 No only real TeX macros will work here, but the standard HTML entities
385 for math can be used as macro names as well. For a list of supported
386 names in HTML export, see the constant `org-html-entities'.
387 Not all export backends support this.
389 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
390 :group 'org-export-translation
391 :group 'org-export-latex
392 :type 'boolean)
394 (defcustom org-export-with-LaTeX-fragments nil
395 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
396 When set, the exporter will find LaTeX environments if the \\begin line is
397 the first non-white thing on a line. It will also find the math delimiters
398 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
399 display math.
401 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
402 :group 'org-export-translation
403 :group 'org-export-latex
404 :type 'boolean)
406 (defcustom org-export-with-fixed-width t
407 "Non-nil means, lines starting with \":\" will be in fixed width font.
408 This can be used to have pre-formatted text, fragments of code etc. For
409 example:
410 : ;; Some Lisp examples
411 : (while (defc cnt)
412 : (ding))
413 will be looking just like this in also HTML. See also the QUOTE keyword.
414 Not all export backends support this.
416 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
417 :group 'org-export-translation
418 :type 'boolean)
420 (defcustom org-match-sexp-depth 3
421 "Number of stacked braces for sub/superscript matching.
422 This has to be set before loading org.el to be effective."
423 :group 'org-export-translation
424 :type 'integer)
426 (defgroup org-export-tables nil
427 "Options for exporting tables in Org-mode."
428 :tag "Org Export Tables"
429 :group 'org-export)
431 (defcustom org-export-with-tables t
432 "If non-nil, lines starting with \"|\" define a table.
433 For example:
435 | Name | Address | Birthday |
436 |-------------+----------+-----------|
437 | Arthur Dent | England | 29.2.2100 |
439 Not all export backends support this.
441 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
442 :group 'org-export-tables
443 :type 'boolean)
445 (defcustom org-export-highlight-first-table-line t
446 "Non-nil means, highlight the first table line.
447 In HTML export, this means use <th> instead of <td>.
448 In tables created with table.el, this applies to the first table line.
449 In Org-mode tables, all lines before the first horizontal separator
450 line will be formatted with <th> tags."
451 :group 'org-export-tables
452 :type 'boolean)
454 (defcustom org-export-table-remove-special-lines t
455 "Remove special lines and marking characters in calculating tables.
456 This removes the special marking character column from tables that are set
457 up for spreadsheet calculations. It also removes the entire lines
458 marked with `!', `_', or `^'. The lines with `$' are kept, because
459 the values of constants may be useful to have."
460 :group 'org-export-tables
461 :type 'boolean)
463 (defcustom org-export-prefer-native-exporter-for-tables nil
464 "Non-nil means, always export tables created with table.el natively.
465 Natively means, use the HTML code generator in table.el.
466 When nil, Org-mode's own HTML generator is used when possible (i.e. if
467 the table does not use row- or column-spanning). This has the
468 advantage, that the automatic HTML conversions for math symbols and
469 sub/superscripts can be applied. Org-mode's HTML generator is also
470 much faster."
471 :group 'org-export-tables
472 :type 'boolean)
474 (defgroup org-export-ascii nil
475 "Options specific for ASCII export of Org-mode files."
476 :tag "Org Export ASCII"
477 :group 'org-export)
479 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
480 "Characters for underlining headings in ASCII export.
481 In the given sequence, these characters will be used for level 1, 2, ..."
482 :group 'org-export-ascii
483 :type '(repeat character))
485 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
486 "Bullet characters for headlines converted to lists in ASCII export.
487 The first character is used for the first lest level generated in this
488 way, and so on. If there are more levels than characters given here,
489 the list will be repeated.
490 Note that plain lists will keep the same bullets as the have in the
491 Org-mode file."
492 :group 'org-export-ascii
493 :type '(repeat character))
495 (defgroup org-export-xml nil
496 "Options specific for XML export of Org-mode files."
497 :tag "Org Export XML"
498 :group 'org-export)
500 (defgroup org-export-html nil
501 "Options specific for HTML export of Org-mode files."
502 :tag "Org Export HTML"
503 :group 'org-export)
505 (defcustom org-export-html-coding-system nil
506 "Coding system for HTML export, defaults to buffer-file-coding-system."
507 :group 'org-export-html
508 :type 'coding-system)
510 (defcustom org-export-html-extension "html"
511 "The extension for exported HTML files."
512 :group 'org-export-html
513 :type 'string)
515 (defcustom org-export-html-link-up ""
516 "Where should the \"UP\" link of exported HTML pages lead?"
517 :group 'org-export-html
518 :type '(string :tag "File or URL"))
520 (defcustom org-export-html-link-home ""
521 "Where should the \"HOME\" link of exported HTML pages lead?"
522 :group 'org-export-html
523 :type '(string :tag "File or URL"))
525 (defconst org-export-html-style-default
526 "<style type=\"text/css\">
527 <!--/*--><![CDATA[/*><!--*/
528 html { font-family: Times, serif; font-size: 12pt; }
529 .title { text-align: center; }
530 .todo { color: red; }
531 .done { color: green; }
532 .tag { background-color:lightblue; font-weight:normal }
533 .target { }
534 .timestamp { color: grey }
535 .timestamp-kwd { color: CadetBlue }
536 p.verse { margin-left: 3% }
537 pre {
538 border: 1pt solid #AEBDCC;
539 background-color: #F3F5F7;
540 padding: 5pt;
541 font-family: courier, monospace;
542 font-size: 90%;
543 overflow:auto;
545 table { border-collapse: collapse; }
546 td, th { vertical-align: top; }
547 dt { font-weight: bold; }
548 div.figure { padding: 0.5em; }
549 div.figure p { text-align: center; }
550 .org-info-js_info-navigation { border-style:none; }
551 #org-info-js_console-label { font-size:10px; font-weight:bold;
552 white-space:nowrap; }
553 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
554 font-weight:bold; }
555 /*]]>*/-->
556 </style>"
557 "The default style specification for exported HTML files.
558 Please use the variables `org-export-html-style' and
559 `org-export-html-style-extra' to add to this style. If you wish to not
560 have the default style included, customize the variable
561 `org-export-html-style-include-default'.")
563 (defcustom org-export-html-style-include-default t
564 "Non-nil means, include the default style in exported HTML files.
565 The actualy style is defined in `org-export-html-style-default' and should
566 not be modified. Use the variables `org-export-html-style' to add
567 your own style information."
568 :group 'org-export-html
569 :type 'boolean)
570 ;;;###autoload
571 (put 'org-export-html-style 'safe-local-variable 'booleanp)
573 (defcustom org-export-html-style ""
574 "Org-wide style definitions for exported HTML files.
576 This variable needs to contain the full HTML structure to provide a style,
577 including the surrounding HTML tags. If you set the value of this variable,
578 you should consider to include definitions for the following classes:
579 title, todo, done, timestamp, timestamp-kwd, tag, target.
581 For example, a valid value would be:
583 <style type=\"text/css\">
584 <![CDATA[
585 p { font-weight: normal; color: gray; }
586 h1 { color: black; }
587 .title { text-align: center; }
588 .todo, .timestamp-kwd { color: red; }
589 .done { color: green; }
591 </style>
593 If you'd like to refer to en external style file, use something like
595 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
597 As the value of this option simply gets inserted into the HTML <head> header,
598 you can \"misuse\" it to add arbitrary text to the header.
599 See also the variable `org-export-html-style-extra'."
600 :group 'org-export-html
601 :type 'string)
602 ;;;###autoload
603 (put 'org-export-html-style 'safe-local-variable 'stringp)
605 (defcustom org-export-html-style-extra ""
606 "Additional style information for HTML export.
607 The value of this variable is inserted into the HTML buffer right after
608 the value of `org-export-html-style'. Use this variable for per-file
609 settings of style information, and do not forget to surround the style
610 settings with <style>...</style> tags."
611 :group 'org-export-html
612 :type 'string)
613 ;;;###autoload
614 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
617 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
618 "Format for typesetting the document title in HTML export."
619 :group 'org-export-html
620 :type 'string)
622 (defcustom org-export-html-toplevel-hlevel 2
623 "The <H> level for level 1 headings in HTML export."
624 :group 'org-export-html
625 :type 'string)
627 (defcustom org-export-html-link-org-files-as-html t
628 "Non-nil means, make file links to `file.org' point to `file.html'.
629 When org-mode is exporting an org-mode file to HTML, links to
630 non-html files are directly put into a href tag in HTML.
631 However, links to other Org-mode files (recognized by the
632 extension `.org.) should become links to the corresponding html
633 file, assuming that the linked org-mode file will also be
634 converted to HTML.
635 When nil, the links still point to the plain `.org' file."
636 :group 'org-export-html
637 :type 'boolean)
639 (defcustom org-export-html-inline-images 'maybe
640 "Non-nil means, inline images into exported HTML pages.
641 This is done using an <img> tag. When nil, an anchor with href is used to
642 link to the image. If this option is `maybe', then images in links with
643 an empty description will be inlined, while images with a description will
644 be linked only."
645 :group 'org-export-html
646 :type '(choice (const :tag "Never" nil)
647 (const :tag "Always" t)
648 (const :tag "When there is no description" maybe)))
650 ;; FIXME: rename
651 (defcustom org-export-html-expand t
652 "Non-nil means, for HTML export, treat @<...> as HTML tag.
653 When nil, these tags will be exported as plain text and therefore
654 not be interpreted by a browser.
656 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
657 :group 'org-export-html
658 :type 'boolean)
660 (defcustom org-export-html-table-tag
661 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
662 "The HTML tag that is used to start a table.
663 This must be a <table> tag, but you may change the options like
664 borders and spacing."
665 :group 'org-export-html
666 :type 'string)
668 (defcustom org-export-table-header-tags '("<th>" . "</th>")
669 "The opening tag for table header fields.
670 This is customizable so that alignment options can be specified."
671 :group 'org-export-tables
672 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
674 (defcustom org-export-table-data-tags '("<td>" . "</td>")
675 "The opening tag for table data fields.
676 This is customizable so that alignment options can be specified."
677 :group 'org-export-tables
678 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
680 (defcustom org-export-html-with-timestamp nil
681 "If non-nil, write `org-export-html-html-helper-timestamp'
682 into the exported HTML text. Otherwise, the buffer will just be saved
683 to a file."
684 :group 'org-export-html
685 :type 'boolean)
687 (defcustom org-export-html-html-helper-timestamp
688 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
689 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
690 :group 'org-export-html
691 :type 'string)
693 (defgroup org-export-htmlize nil
694 "Options for processing examples with htmlize.el."
695 :tag "Org Export Htmlize"
696 :group 'org-export-html)
698 (defcustom org-export-htmlize-output-type 'inline-css
699 "Output type to be used by htmlize when formatting code snippets.
700 Normally this is `inline-css', but if you have defined to appropriate
701 classes in your css style file, setting this to `css' means that the
702 fontification will use the class names.
703 See also the function `org-export-htmlize-generate-css'."
704 :group 'org-export-htmlize
705 :type '(choice (const css) (const inline-css)))
707 (defcustom org-export-htmlize-css-font-prefix "org-"
708 "The prefix for CSS class names for htmlize font specifications."
709 :group 'org-export-htmlize
710 :type 'string)
712 (defgroup org-export-icalendar nil
713 "Options specific for iCalendar export of Org-mode files."
714 :tag "Org Export iCalendar"
715 :group 'org-export)
717 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
718 "The file name for the iCalendar file covering all agenda files.
719 This file is created with the command \\[org-export-icalendar-all-agenda-files].
720 The file name should be absolute, the file will be overwritten without warning."
721 :group 'org-export-icalendar
722 :type 'file)
724 (defcustom org-icalendar-combined-name "OrgMode"
725 "Calendar name for the combined iCalendar representing all agenda files."
726 :group 'org-export-icalendar
727 :type 'string)
729 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
730 "Contexts where iCalendar export should use a deadline time stamp.
731 This is a list with several symbols in it. Valid symbol are:
733 event-if-todo Deadlines in TODO entries become calendar events.
734 event-if-not-todo Deadlines in non-TODO entries become calendar events.
735 todo-due Use deadlines in TODO entries as due-dates"
736 :group 'org-export-icalendar
737 :type '(set :greedy t
738 (const :tag "Deadlines in non-TODO entries become events"
739 event-if-not-todo)
740 (const :tag "Deadline in TODO entries become events"
741 event-if-todo)
742 (const :tag "Deadlines in TODO entries become due-dates"
743 todo-due)))
745 (defcustom org-icalendar-use-scheduled '(todo-start)
746 "Contexts where iCalendar export should use a scheduling time stamp.
747 This is a list with several symbols in it. Valid symbol are:
749 event-if-todo Scheduling time stamps in TODO entries become an event.
750 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
751 todo-start Scheduling time stamps in TODO entries become start date.
752 Some calendar applications show TODO entries only after
753 that date."
754 :group 'org-export-icalendar
755 :type '(set :greedy t
756 (const :tag
757 "SCHEDULED timestamps in non-TODO entries become events"
758 event-if-not-todo)
759 (const :tag "SCHEDULED timestamps in TODO entries become events"
760 event-if-todo)
761 (const :tag "SCHEDULED in TODO entries become start date"
762 todo-start)))
764 (defcustom org-icalendar-categories '(local-tags category)
765 "Items that should be entered into the categories field.
766 This is a list of symbols, the following are valid:
768 category The Org-mode category of the current file or tree
769 todo-state The todo state, if any
770 local-tags The tags, defined in the current line
771 all-tags All tags, including inherited ones."
772 :group 'org-export-icalendar
773 :type '(repeat
774 (choice
775 (const :tag "The file or tree category" category)
776 (const :tag "The TODO state" todo-state)
777 (const :tag "Tags defined in current line" local-tags)
778 (const :tag "All tags, including inherited ones" all-tags))))
780 (defcustom org-icalendar-include-todo nil
781 "Non-nil means, export to iCalendar files should also cover TODO items."
782 :group 'org-export-icalendar
783 :type '(choice
784 (const :tag "None" nil)
785 (const :tag "Unfinished" t)
786 (const :tag "All" all)))
788 (defcustom org-icalendar-include-sexps t
789 "Non-nil means, export to iCalendar files should also cover sexp entries.
790 These are entries like in the diary, but directly in an Org-mode file."
791 :group 'org-export-icalendar
792 :type 'boolean)
794 (defcustom org-icalendar-include-body 100
795 "Amount of text below headline to be included in iCalendar export.
796 This is a number of characters that should maximally be included.
797 Properties, scheduling and clocking lines will always be removed.
798 The text will be inserted into the DESCRIPTION field."
799 :group 'org-export-icalendar
800 :type '(choice
801 (const :tag "Nothing" nil)
802 (const :tag "Everything" t)
803 (integer :tag "Max characters")))
805 (defcustom org-icalendar-store-UID nil
806 "Non-nil means, store any created UIDs in properties.
807 The iCalendar standard requires that all entries have a unique identifyer.
808 Org will create these identifiers as needed. When this variable is non-nil,
809 the created UIDs will be stored in the ID property of the entry. Then the
810 next time this entry is exported, it will be exported with the same UID,
811 superceeding the previous form of it. This is essential for
812 synchronization services.
813 This variable is not turned on by default because we want to avoid creating
814 a property drawer in every entry if people are only playing with this feature,
815 or if they are only using it locally."
816 :group 'org-export-icalendar
817 :type 'boolean)
819 ;;;; Exporting
821 ;;; Variables, constants, and parameter plists
823 (defconst org-level-max 20)
825 (defvar org-export-html-preamble nil
826 "Preamble, to be inserted just before <body>. Set by publishing functions.")
827 (defvar org-export-html-postamble nil
828 "Preamble, to be inserted just after </body>. Set by publishing functions.")
829 (defvar org-export-html-auto-preamble t
830 "Should default preamble be inserted? Set by publishing functions.")
831 (defvar org-export-html-auto-postamble t
832 "Should default postamble be inserted? Set by publishing functions.")
833 (defvar org-current-export-file nil) ; dynamically scoped parameter
834 (defvar org-current-export-dir nil) ; dynamically scoped parameter
836 (defconst org-export-plist-vars
837 '((:link-up nil org-export-html-link-up)
838 (:link-home nil org-export-html-link-home)
839 (:language nil org-export-default-language)
840 (:customtime nil org-display-custom-times)
841 (:headline-levels "H" org-export-headline-levels)
842 (:section-numbers "num" org-export-with-section-numbers)
843 (:section-number-format nil org-export-section-number-format)
844 (:table-of-contents "toc" org-export-with-toc)
845 (:preserve-breaks "\\n" org-export-preserve-breaks)
846 (:archived-trees nil org-export-with-archived-trees)
847 (:emphasize "*" org-export-with-emphasize)
848 (:sub-superscript "^" org-export-with-sub-superscripts)
849 (:special-strings "-" org-export-with-special-strings)
850 (:footnotes "f" org-export-with-footnotes)
851 (:drawers "d" org-export-with-drawers)
852 (:tags "tags" org-export-with-tags)
853 (:todo-keywords "todo" org-export-with-todo-keywords)
854 (:priority "pri" org-export-with-priority)
855 (:TeX-macros "TeX" org-export-with-TeX-macros)
856 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
857 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
858 (:fixed-width ":" org-export-with-fixed-width)
859 (:timestamps "<" org-export-with-timestamps)
860 (:author-info "author" org-export-author-info)
861 (:creator-info "creator" org-export-creator-info)
862 (:time-stamp-file "timestamp" org-export-time-stamp-file)
863 (:tables "|" org-export-with-tables)
864 (:table-auto-headline nil org-export-highlight-first-table-line)
865 (:style-include-default nil org-export-html-style-include-default)
866 (:style nil org-export-html-style)
867 (:style-extra nil org-export-html-style-extra)
868 (:agenda-style nil org-agenda-export-html-style)
869 (:convert-org-links nil org-export-html-link-org-files-as-html)
870 (:inline-images nil org-export-html-inline-images)
871 (:html-extension nil org-export-html-extension)
872 (:html-table-tag nil org-export-html-table-tag)
873 (:expand-quoted-html "@" org-export-html-expand)
874 (:timestamp nil org-export-html-with-timestamp)
875 (:publishing-directory nil org-export-publishing-directory)
876 (:preamble nil org-export-html-preamble)
877 (:postamble nil org-export-html-postamble)
878 (:auto-preamble nil org-export-html-auto-preamble)
879 (:auto-postamble nil org-export-html-auto-postamble)
880 (:author nil user-full-name)
881 (:email nil user-mail-address)
882 (:select-tags nil org-export-select-tags)
883 (:exclude-tags nil org-export-exclude-tags))
884 "List of properties that represent export/publishing variables.
885 Each element is a list of 3 items:
886 1. The property that is used internally, and also for org-publish-project-alist
887 2. The string that can be used in the OPTION lines to set this option,
888 or nil if this option cannot be changed in this way
889 3. The customization variable that sets the default for this option."
893 (defun org-default-export-plist ()
894 "Return the property list with default settings for the export variables."
895 (let ((l org-export-plist-vars) rtn e)
896 (while (setq e (pop l))
897 (setq rtn (cons (car e) (cons (symbol-value (nth 2 e)) rtn))))
898 rtn))
900 (defvar org-export-inbuffer-options-extra nil
901 "List of additional in-buffer options that should be detected.
902 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
903 etc. Extensions can add to this list to get their options detected, and they
904 can then add a function to `org-export-options-filters' to process these
905 options.
906 Each element in this list must be a list, with the in-buffer keyword as car,
907 and a property (a symbol) as the next element. All occurences of the
908 keyword will be found, the values concatenated with a space character
909 in between, and the result stored in the export options property list.")
911 (defvar org-export-options-filters nil
912 "Functions to be called to finalize the export/publishing options.
913 All these options are stored in a property list, and each of the functions
914 in this hook gets a chance to modify this property list. Each function
915 must accept the property list as an argument, and must return the (possibly
916 modified) list.")
918 ;; FIXME: should we fold case here?
919 (defun org-infile-export-plist ()
920 "Return the property list with file-local settings for export."
921 (save-excursion
922 (save-restriction
923 (widen)
924 (goto-char (point-min))
925 (let ((re (org-make-options-regexp
926 (append
927 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
928 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
929 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
930 (mapcar 'car org-export-inbuffer-options-extra))))
931 p key val text options js-up js-main js-css js-opt a pr style
932 latex-header
933 ext-setup-or-nil setup-contents (start 0))
934 (while (or (and ext-setup-or-nil
935 (string-match re ext-setup-or-nil start)
936 (setq start (match-end 0)))
937 (and (setq ext-setup-or-nil nil start 0)
938 (re-search-forward re nil t)))
939 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
940 val (org-match-string-no-properties 2 ext-setup-or-nil))
941 (cond
942 ((setq a (assoc key org-export-inbuffer-options-extra))
943 (setq pr (nth 1 a))
944 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
945 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
946 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
947 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
948 ((string-equal key "DATE") (setq p (plist-put p :date val)))
949 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
950 ((string-equal key "STYLE")
951 (setq style (concat style "\n" val)))
952 ((string-equal key "LATEX_HEADER")
953 (setq latex-header (concat latex-header "\n" val)))
954 ((string-equal key "TEXT")
955 (setq text (if text (concat text "\n" val) val)))
956 ((string-equal key "OPTIONS")
957 (setq options (concat val " " options)))
958 ((string-equal key "LINK_UP")
959 (setq p (plist-put p :link-up val)))
960 ((string-equal key "LINK_HOME")
961 (setq p (plist-put p :link-home val)))
962 ((string-equal key "EXPORT_SELECT_TAGS")
963 (setq p (plist-put p :select-tags (org-split-string val))))
964 ((string-equal key "EXPORT_EXCLUDE_TAGS")
965 (setq p (plist-put p :exclude-tags (org-split-string val))))
966 ((equal key "SETUPFILE")
967 (setq setup-contents (org-file-contents
968 (expand-file-name
969 (org-remove-double-quotes
970 (org-trim val)))
971 'noerror))
972 (if (not ext-setup-or-nil)
973 (setq ext-setup-or-nil setup-contents start 0)
974 (setq ext-setup-or-nil
975 (concat (substring ext-setup-or-nil 0 start)
976 "\n" setup-contents "\n"
977 (substring ext-setup-or-nil start)))))))
978 (setq p (plist-put p :text text))
979 (when style (setq p (plist-put p :style-extra style)))
980 (when latex-header
981 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
982 (when options
983 (setq p (org-export-add-options-to-plist p options)))
984 p))))
986 (defun org-export-add-options-to-plist (p options)
987 "Parse an OPTONS line and set values in the property list P."
988 (let (o)
989 (when options
990 (let ((op org-export-plist-vars) a)
991 (while (setq o (pop op))
992 (if (and (nth 1 o)
993 (string-match (concat (regexp-quote (nth 1 o))
994 ":\\([^ \t\n\r;,.]*\\)")
995 options))
996 (setq p (plist-put p (car o)
997 (car (read-from-string
998 (match-string 1 options))))))))))
1001 (defun org-export-add-subtree-options (p pos)
1002 "Add options in subtree at position POS to property list P."
1003 (save-excursion
1004 (goto-char pos)
1005 (when (org-at-heading-p)
1006 (let (a)
1007 ;; This is actually read in `org-export-get-title-from-subtree'
1008 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1009 ;; (setq p (plist-put p :title a)))
1010 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
1011 (setq p (plist-put p :text a)))
1012 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
1013 (setq p (org-export-add-options-to-plist p a)))))
1016 (defun org-export-directory (type plist)
1017 (let* ((val (plist-get plist :publishing-directory))
1018 (dir (if (listp val)
1019 (or (cdr (assoc type val)) ".")
1020 val)))
1021 dir))
1023 (defun org-export-process-option-filters (plist)
1024 (let ((functions org-export-options-filters) f)
1025 (while (setq f (pop functions))
1026 (setq plist (funcall f plist))))
1027 plist)
1029 ;;;###autoload
1030 (defun org-export (&optional arg)
1031 "Export dispatcher for Org-mode.
1032 When `org-export-run-in-background' is non-nil, try to run the command
1033 in the background. This will be done only for commands that write
1034 to a file. For details see the docstring of `org-export-run-in-background'.
1036 The prefix argument ARG will be passed to the exporter. However, if
1037 ARG is a double universal prefix `C-u C-u', that means to inverse the
1038 value of `org-export-run-in-background'."
1039 (interactive "P")
1040 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
1041 (help "[t] insert the export option template
1042 \[v] limit export to visible part of outline tree
1044 \[a] export as ASCII
1046 \[h] export as HTML
1047 \[H] export as HTML to temporary buffer
1048 \[R] export region as HTML
1049 \[b] export as HTML and browse immediately
1050 \[x] export as XOXO
1052 \[l] export as LaTeX
1053 \[p] export as LaTeX and process to PDF
1054 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1055 \[L] export as LaTeX to temporary buffer
1057 \[i] export current file as iCalendar file
1058 \[I] export all agenda files as iCalendar files
1059 \[c] export agenda files into combined iCalendar file
1061 \[F] publish current file
1062 \[P] publish current project
1063 \[X] publish... (project will be prompted for)
1064 \[A] publish all projects")
1065 (cmds
1066 '((?t org-insert-export-options-template nil)
1067 (?v org-export-visible nil)
1068 (?a org-export-as-ascii t)
1069 (?h org-export-as-html t)
1070 (?b org-export-as-html-and-open t)
1071 (?H org-export-as-html-to-buffer nil)
1072 (?R org-export-region-as-html nil)
1073 (?x org-export-as-xoxo t)
1074 (?l org-export-as-latex t)
1075 (?p org-export-as-pdf t)
1076 (?d org-export-as-pdf-and-open t)
1077 (?L org-export-as-latex-to-buffer nil)
1078 (?i org-export-icalendar-this-file t)
1079 (?I org-export-icalendar-all-agenda-files t)
1080 (?c org-export-icalendar-combine-agenda-files t)
1081 (?F org-publish-current-file t)
1082 (?P org-publish-current-project t)
1083 (?X org-publish t)
1084 (?A org-publish-all t)))
1085 r1 r2 ass)
1086 (save-window-excursion
1087 (delete-other-windows)
1088 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1089 (princ help))
1090 (org-fit-window-to-buffer (get-buffer-window
1091 "*Org Export/Publishing Help*"))
1092 (message "Select command: ")
1093 (setq r1 (read-char-exclusive)))
1094 (setq r2 (if (< r1 27) (+ r1 96) r1))
1095 (unless (setq ass (assq r2 cmds))
1096 (error "No command associated with key %c" r1))
1097 (if (and bg (nth 2 ass)
1098 (not (buffer-base-buffer))
1099 (not (org-region-active-p)))
1100 ;; execute in background
1101 (let ((p (start-process
1102 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1103 "*Org Processes*"
1104 (expand-file-name invocation-name invocation-directory)
1105 "-batch"
1106 "-l" user-init-file
1107 "--eval" "(require 'org-exp)"
1108 "--eval" "(setq org-wait .2)"
1109 (buffer-file-name)
1110 "-f" (symbol-name (nth 1 ass)))))
1111 (set-process-sentinel p 'org-export-process-sentinel)
1112 (message "Background process \"%s\": started" p))
1113 ;; background processing not requested, or not possible
1114 (call-interactively (nth 1 ass)))))
1116 (defun org-export-process-sentinel (process status)
1117 (if (string-match "\n+\\'" status)
1118 (setq status (substring status 0 -1)))
1119 (message "Background process \"%s\": %s" process status))
1121 (defconst org-html-entities
1122 '(("nbsp")
1123 ("iexcl")
1124 ("cent")
1125 ("pound")
1126 ("curren")
1127 ("yen")
1128 ("brvbar")
1129 ("vert" . "&#124;")
1130 ("sect")
1131 ("uml")
1132 ("copy")
1133 ("ordf")
1134 ("laquo")
1135 ("not")
1136 ("shy")
1137 ("reg")
1138 ("macr")
1139 ("deg")
1140 ("plusmn")
1141 ("sup2")
1142 ("sup3")
1143 ("acute")
1144 ("micro")
1145 ("para")
1146 ("middot")
1147 ("odot"."o")
1148 ("star"."*")
1149 ("cedil")
1150 ("sup1")
1151 ("ordm")
1152 ("raquo")
1153 ("frac14")
1154 ("frac12")
1155 ("frac34")
1156 ("iquest")
1157 ("Agrave")
1158 ("Aacute")
1159 ("Acirc")
1160 ("Atilde")
1161 ("Auml")
1162 ("Aring") ("AA"."&Aring;")
1163 ("AElig")
1164 ("Ccedil")
1165 ("Egrave")
1166 ("Eacute")
1167 ("Ecirc")
1168 ("Euml")
1169 ("Igrave")
1170 ("Iacute")
1171 ("Icirc")
1172 ("Iuml")
1173 ("ETH")
1174 ("Ntilde")
1175 ("Ograve")
1176 ("Oacute")
1177 ("Ocirc")
1178 ("Otilde")
1179 ("Ouml")
1180 ("times")
1181 ("Oslash")
1182 ("Ugrave")
1183 ("Uacute")
1184 ("Ucirc")
1185 ("Uuml")
1186 ("Yacute")
1187 ("THORN")
1188 ("szlig")
1189 ("agrave")
1190 ("aacute")
1191 ("acirc")
1192 ("atilde")
1193 ("auml")
1194 ("aring")
1195 ("aelig")
1196 ("ccedil")
1197 ("egrave")
1198 ("eacute")
1199 ("ecirc")
1200 ("euml")
1201 ("igrave")
1202 ("iacute")
1203 ("icirc")
1204 ("iuml")
1205 ("eth")
1206 ("ntilde")
1207 ("ograve")
1208 ("oacute")
1209 ("ocirc")
1210 ("otilde")
1211 ("ouml")
1212 ("divide")
1213 ("oslash")
1214 ("ugrave")
1215 ("uacute")
1216 ("ucirc")
1217 ("uuml")
1218 ("yacute")
1219 ("thorn")
1220 ("yuml")
1221 ("fnof")
1222 ("Alpha")
1223 ("Beta")
1224 ("Gamma")
1225 ("Delta")
1226 ("Epsilon")
1227 ("Zeta")
1228 ("Eta")
1229 ("Theta")
1230 ("Iota")
1231 ("Kappa")
1232 ("Lambda")
1233 ("Mu")
1234 ("Nu")
1235 ("Xi")
1236 ("Omicron")
1237 ("Pi")
1238 ("Rho")
1239 ("Sigma")
1240 ("Tau")
1241 ("Upsilon")
1242 ("Phi")
1243 ("Chi")
1244 ("Psi")
1245 ("Omega")
1246 ("alpha")
1247 ("beta")
1248 ("gamma")
1249 ("delta")
1250 ("epsilon")
1251 ("varepsilon"."&epsilon;")
1252 ("zeta")
1253 ("eta")
1254 ("theta")
1255 ("iota")
1256 ("kappa")
1257 ("lambda")
1258 ("mu")
1259 ("nu")
1260 ("xi")
1261 ("omicron")
1262 ("pi")
1263 ("rho")
1264 ("sigmaf") ("varsigma"."&sigmaf;")
1265 ("sigma")
1266 ("tau")
1267 ("upsilon")
1268 ("phi")
1269 ("chi")
1270 ("psi")
1271 ("omega")
1272 ("thetasym") ("vartheta"."&thetasym;")
1273 ("upsih")
1274 ("piv")
1275 ("bull") ("bullet"."&bull;")
1276 ("hellip") ("dots"."&hellip;")
1277 ("prime")
1278 ("Prime")
1279 ("oline")
1280 ("frasl")
1281 ("weierp")
1282 ("image")
1283 ("real")
1284 ("trade")
1285 ("alefsym")
1286 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1287 ("uarr") ("uparrow"."&uarr;")
1288 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1289 ("darr")("downarrow"."&darr;")
1290 ("harr") ("leftrightarrow"."&harr;")
1291 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1292 ("lArr") ("Leftarrow"."&lArr;")
1293 ("uArr") ("Uparrow"."&uArr;")
1294 ("rArr") ("Rightarrow"."&rArr;")
1295 ("dArr") ("Downarrow"."&dArr;")
1296 ("hArr") ("Leftrightarrow"."&hArr;")
1297 ("forall")
1298 ("part") ("partial"."&part;")
1299 ("exist") ("exists"."&exist;")
1300 ("empty") ("emptyset"."&empty;")
1301 ("nabla")
1302 ("isin") ("in"."&isin;")
1303 ("notin")
1304 ("ni")
1305 ("prod")
1306 ("sum")
1307 ("minus")
1308 ("lowast") ("ast"."&lowast;")
1309 ("radic")
1310 ("prop") ("proptp"."&prop;")
1311 ("infin") ("infty"."&infin;")
1312 ("ang") ("angle"."&ang;")
1313 ("and") ("wedge"."&and;")
1314 ("or") ("vee"."&or;")
1315 ("cap")
1316 ("cup")
1317 ("int")
1318 ("there4")
1319 ("sim")
1320 ("cong") ("simeq"."&cong;")
1321 ("asymp")("approx"."&asymp;")
1322 ("ne") ("neq"."&ne;")
1323 ("equiv")
1324 ("le")
1325 ("ge")
1326 ("sub") ("subset"."&sub;")
1327 ("sup") ("supset"."&sup;")
1328 ("nsub")
1329 ("sube")
1330 ("supe")
1331 ("oplus")
1332 ("otimes")
1333 ("perp")
1334 ("sdot") ("cdot"."&sdot;")
1335 ("lceil")
1336 ("rceil")
1337 ("lfloor")
1338 ("rfloor")
1339 ("lang")
1340 ("rang")
1341 ("loz") ("Diamond"."&loz;")
1342 ("spades") ("spadesuit"."&spades;")
1343 ("clubs") ("clubsuit"."&clubs;")
1344 ("hearts") ("diamondsuit"."&hearts;")
1345 ("diams") ("diamondsuit"."&diams;")
1346 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1347 ("quot")
1348 ("amp")
1349 ("lt")
1350 ("gt")
1351 ("OElig")
1352 ("oelig")
1353 ("Scaron")
1354 ("scaron")
1355 ("Yuml")
1356 ("circ")
1357 ("tilde")
1358 ("ensp")
1359 ("emsp")
1360 ("thinsp")
1361 ("zwnj")
1362 ("zwj")
1363 ("lrm")
1364 ("rlm")
1365 ("ndash")
1366 ("mdash")
1367 ("lsquo")
1368 ("rsquo")
1369 ("sbquo")
1370 ("ldquo")
1371 ("rdquo")
1372 ("bdquo")
1373 ("dagger")
1374 ("Dagger")
1375 ("permil")
1376 ("lsaquo")
1377 ("rsaquo")
1378 ("euro")
1380 ("arccos"."arccos")
1381 ("arcsin"."arcsin")
1382 ("arctan"."arctan")
1383 ("arg"."arg")
1384 ("cos"."cos")
1385 ("cosh"."cosh")
1386 ("cot"."cot")
1387 ("coth"."coth")
1388 ("csc"."csc")
1389 ("deg"."deg")
1390 ("det"."det")
1391 ("dim"."dim")
1392 ("exp"."exp")
1393 ("gcd"."gcd")
1394 ("hom"."hom")
1395 ("inf"."inf")
1396 ("ker"."ker")
1397 ("lg"."lg")
1398 ("lim"."lim")
1399 ("liminf"."liminf")
1400 ("limsup"."limsup")
1401 ("ln"."ln")
1402 ("log"."log")
1403 ("max"."max")
1404 ("min"."min")
1405 ("Pr"."Pr")
1406 ("sec"."sec")
1407 ("sin"."sin")
1408 ("sinh"."sinh")
1409 ("sup"."sup")
1410 ("tan"."tan")
1411 ("tanh"."tanh")
1413 "Entities for TeX->HTML translation.
1414 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1415 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1416 In that case, \"\\ent\" will be translated to \"&other;\".
1417 The list contains HTML entities for Latin-1, Greek and other symbols.
1418 It is supplemented by a number of commonly used TeX macros with appropriate
1419 translations. There is currently no way for users to extend this.")
1421 ;;; General functions for all backends
1423 (defvar org-export-target-aliases nil
1424 "Alist of targets with invisible aliases.")
1426 (defun org-export-preprocess-string (string &rest parameters)
1427 "Cleanup STRING so that that the true exported has a more consistent source.
1428 This function takes STRING, which should be a buffer-string of an org-file
1429 to export. It then creates a temporary buffer where it does its job.
1430 The result is then again returned as a string, and the exporter works
1431 on this string to produce the exported version."
1432 (interactive)
1433 (let* ((htmlp (plist-get parameters :for-html))
1434 (asciip (plist-get parameters :for-ascii))
1435 (latexp (plist-get parameters :for-LaTeX))
1436 (backend (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1438 (archived-trees (plist-get parameters :archived-trees))
1439 (inhibit-read-only t)
1440 (drawers org-drawers)
1441 (outline-regexp "\\*+ ")
1442 target-alist rtn)
1444 (setq org-export-target-aliases nil)
1446 (with-current-buffer (get-buffer-create " org-mode-tmp")
1447 (erase-buffer)
1448 (insert string)
1449 (setq case-fold-search t)
1450 ;; Call the hook
1451 (run-hooks 'org-export-preprocess-hook)
1453 ;; Remove license-to-kill stuff
1454 ;; The caller markes some stuff fo killing, stuff that has been
1455 ;; used to create the page title, for example.
1456 (org-export-kill-licensed-text)
1458 (let ((org-inhibit-startup t)) (org-mode))
1459 (setq case-fold-search t)
1460 (untabify (point-min) (point-max))
1462 ;; Handle include files
1463 (org-export-handle-include-files)
1465 ;; Get rid of excluded trees
1466 (org-export-handle-export-tags (plist-get parameters :select-tags)
1467 (plist-get parameters :exclude-tags))
1469 ;; Handle source code snippets
1470 (org-export-replace-src-segments)
1472 ;; Get rid of drawers
1473 (org-export-remove-or-extract-drawers drawers
1474 (plist-get parameters :drawers))
1476 ;; Get the correct stuff before the first headline
1477 (when (plist-get parameters :skip-before-1st-heading)
1478 (goto-char (point-min))
1479 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t)
1480 (delete-region (point-min) (match-beginning 0))
1481 (goto-char (point-min))
1482 (insert "\n")))
1483 (when (plist-get parameters :add-text)
1484 (goto-char (point-min))
1485 (insert (plist-get parameters :add-text) "\n"))
1487 ;; Get rid of archived trees
1488 (org-export-remove-archived-trees archived-trees)
1490 ;; Remove todo-keywords before exporting, if the user has requested so
1491 (org-export-remove-headline-metadata parameters)
1493 ;; Find all headings and compute the targets for them
1494 (setq target-alist (org-export-define-heading-targets target-alist))
1496 ;; Find targets in comments and move them out of comments,
1497 ;; but mark them as targets that should be invisible
1498 (setq target-alist (org-export-handle-invisible-targets target-alist))
1500 ;; Protect examples
1501 (org-export-protect-examples (if asciip 'indent nil))
1503 ;; Protect backend specific stuff, throw away the others.
1504 (org-export-select-backend-specific-text backend)
1506 ;; Protect quoted subtrees
1507 (org-export-protect-quoted-subtrees)
1509 ;; Protect verbatim elements
1510 (org-export-protect-verbatim)
1512 ;; Blockquotes and verse
1513 (org-export-mark-blockquote-and-verse)
1515 ;; Attach captions to the correct opject
1516 (setq target-alist (org-export-attach-captions-and-attributes
1517 backend target-alist))
1519 ;; Remove comment environment and comment subtrees
1520 (org-export-remove-comment-blocks-and-subtrees)
1523 ;; Find matches for radio targets and turn them into internal links
1524 (org-export-mark-radio-links)
1526 ;; Find all links that contain a newline and put them into a single line
1527 (org-export-concatenate-multiline-links)
1529 ;; Normalize links: Convert angle and plain links into bracket links
1530 ;; and expand link abbreviations
1531 (org-export-normalize-links)
1533 ;; Find all internal links. If they have a fuzzy match (i.e. not
1534 ;; a *dedicated* target match, let the link point to the
1535 ;; corresponding section.
1536 (org-export-target-internal-links target-alist)
1538 ;; Find multiline emphasis and put them into single line
1539 (when (plist-get parameters :emph-multiline)
1540 (org-export-concatenate-multiline-emphasis))
1542 ;; Remove special table lines
1543 (when org-export-table-remove-special-lines
1544 (org-export-remove-special-table-lines))
1546 ;; Specific LaTeX stuff
1547 (when latexp
1548 (require 'org-export-latex nil)
1549 (org-export-latex-preprocess))
1551 ;; Specific ASCII stuff
1552 (when asciip
1553 (org-export-ascii-preprocess))
1555 ;; Specific HTML stuff
1556 (when htmlp
1557 (org-export-html-preprocess parameters))
1559 ;; Remove or replace comments
1560 (org-export-handle-comments (plist-get parameters :comments))
1562 (setq rtn (buffer-string)))
1563 (kill-buffer " org-mode-tmp")
1564 rtn))
1566 (defun org-export-kill-licensed-text ()
1567 "Remove all text that is marked with a :org-license-to-kill property."
1568 (let (p q)
1569 (while (setq p (text-property-any (point-min) (point-max)
1570 :org-license-to-kill t))
1571 (delete-region
1572 p (or (next-single-property-change p :org-license-to-kill)
1573 (point-max))))))
1575 (defun org-export-define-heading-targets (target-alist)
1576 "Find all headings and define the targets for them.
1577 The new targets are added to TARGET-ALIST, which is also returned."
1578 (goto-char (point-min))
1579 (org-init-section-numbers)
1580 (let ((re (concat "^" org-outline-regexp))
1581 level target)
1582 (while (re-search-forward re nil t)
1583 (setq level (org-reduced-level
1584 (save-excursion (goto-char (point-at-bol))
1585 (org-outline-level))))
1586 (setq target (org-solidify-link-text
1587 (format "sec-%s" (org-section-number level))))
1588 (push (cons target target) target-alist)
1589 (add-text-properties
1590 (point-at-bol) (point-at-eol)
1591 (list 'target target))))
1592 target-alist)
1594 (defun org-export-handle-invisible-targets (target-alist)
1595 "Find targets in comments and move them out of comments.
1596 Mark them as invisible targets."
1597 (let (target tmp a)
1598 (goto-char (point-min))
1599 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1600 ;; Check if the line before or after is a headline with a target
1601 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1602 (get-text-property (point-at-bol 2) 'target)))
1603 (progn
1604 ;; use the existing target in a neighboring line
1605 (setq tmp (match-string 2))
1606 (replace-match "")
1607 (and (looking-at "\n") (delete-char 1))
1608 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1609 target-alist)
1610 (setq a (or (assoc target org-export-target-aliases)
1611 (progn
1612 (push (list target) org-export-target-aliases)
1613 (car org-export-target-aliases))))
1614 (push tmp (cdr a)))
1615 ;; Make an invisible target
1616 (replace-match "\\1(INVISIBLE)"))))
1617 target-alist)
1619 (defun org-export-target-internal-links (target-alist)
1620 "Find all internal links and assign target to them.
1621 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1622 let the link point to the corresponding section."
1623 (goto-char (point-min))
1624 (while (re-search-forward org-bracket-link-regexp nil t)
1625 (org-if-unprotected
1626 (let* ((md (match-data))
1627 (desc (match-end 2))
1628 (link (org-link-unescape (match-string 1)))
1629 (slink (org-solidify-link-text link))
1630 found props pos
1631 (target
1632 (cond
1633 ((cdr (assoc slink target-alist)))
1634 ((string-match org-link-types-re link) nil)
1635 ((or (file-name-absolute-p link)
1636 (string-match "^\\." link))
1637 nil)
1639 (save-excursion
1640 (setq found (condition-case nil (org-link-search link)
1641 (error nil)))
1642 (when (and found
1643 (or (org-on-heading-p)
1644 (not (eq found 'dedicated))))
1645 (or (get-text-property (point) 'target)
1646 (get-text-property
1647 (max (point-min)
1648 (1- (or (previous-single-property-change
1649 (point) 'target) 0)))
1650 'target))))))))
1651 (when target
1652 (set-match-data md)
1653 (goto-char (match-beginning 1))
1654 (setq props (text-properties-at (point)))
1655 (delete-region (match-beginning 1) (match-end 1))
1656 (setq pos (point))
1657 (insert target)
1658 (unless desc (insert "][" link))
1659 (add-text-properties pos (point) props))))))
1661 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1662 "Remove drawers, or extract the content.
1663 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1664 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1665 whose content to keep."
1666 (unless (eq t exp-drawers)
1667 (goto-char (point-min))
1668 (let ((re (concat "^[ \t]*:\\("
1669 (mapconcat
1670 'identity
1671 (org-delete-all exp-drawers
1672 (copy-sequence all-drawers))
1673 "\\|")
1674 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1675 (while (re-search-forward re nil t)
1676 (replace-match "")))))
1678 (defun org-export-handle-export-tags (select-tags exclude-tags)
1679 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1680 Both arguments are lists of tags.
1681 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1682 will be removed.
1683 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1684 removed as well."
1685 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1686 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1687 select-tags "\\|")
1688 "\\):"))
1689 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1690 exclude-tags "\\|")
1691 "\\):"))
1692 beg end cont)
1693 (goto-char (point-min))
1694 (when (and select-tags
1695 (re-search-forward
1696 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1697 ;; At least one tree is marked for export, this means
1698 ;; all the unmarked stuff needs to go.
1699 ;; Dig out the trees that should be exported
1700 (goto-char (point-min))
1701 (outline-next-heading)
1702 (setq beg (point))
1703 (put-text-property beg (point-max) :org-delete t)
1704 (while (re-search-forward re-sel nil t)
1705 (when (org-on-heading-p)
1706 (org-back-to-heading)
1707 (remove-text-properties
1708 (max (1- (point)) (point-min))
1709 (setq cont (save-excursion (org-end-of-subtree t t)))
1710 '(:org-delete t))
1711 (while (and (org-up-heading-safe)
1712 (get-text-property (point) :org-delete))
1713 (remove-text-properties (max (1- (point)) (point-min))
1714 (point-at-eol) '(:org-delete t)))
1715 (goto-char cont))))
1716 ;; Remove the trees explicitly marked for noexport
1717 (when exclude-tags
1718 (goto-char (point-min))
1719 (while (re-search-forward re-excl nil t)
1720 (when (org-at-heading-p)
1721 (org-back-to-heading t)
1722 (setq beg (point))
1723 (org-end-of-subtree t)
1724 (delete-region beg (point)))))
1725 ;; Remove everything that is now still marked for deletion
1726 (goto-char (point-min))
1727 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1728 (setq end (or (next-single-property-change beg :org-delete)
1729 (point-max)))
1730 (delete-region beg end))))
1732 (defun org-export-remove-archived-trees (export-archived-trees)
1733 "Remove archived trees.
1734 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1735 When it is t, the entire archived tree will be exported.
1736 When it is nil the entire tree including the headline will be removed
1737 from the buffer."
1738 (let ((re-archive (concat ":" org-archive-tag ":"))
1739 a b)
1740 (when (not (eq export-archived-trees t))
1741 (goto-char (point-min))
1742 (while (re-search-forward re-archive nil t)
1743 (if (not (org-on-heading-p t))
1744 (org-end-of-subtree t)
1745 (beginning-of-line 1)
1746 (setq a (if export-archived-trees
1747 (1+ (point-at-eol)) (point))
1748 b (org-end-of-subtree t))
1749 (if (> b a) (delete-region a b)))))))
1751 (defun org-export-remove-headline-metadata (opts)
1752 "Remove meta data from the headline, according to user options."
1753 (let ((re org-complex-heading-regexp)
1754 (todo (plist-get opts :todo-keywords))
1755 (tags (plist-get opts :tags))
1756 (pri (plist-get opts :priority))
1757 rpl)
1758 (when (or (not todo) (not tags) (not pri))
1759 ;; OK, something needs to be removed
1760 (setq rpl (concat "\\1"
1761 (if todo " \\2" "")
1762 (if pri " \\3" "")
1763 " \\4"
1764 (if tags " \\5" "")))
1765 (goto-char (point-min))
1766 (while (re-search-forward re nil t)
1767 (replace-match rpl t nil)))))
1769 (defun org-export-protect-quoted-subtrees ()
1770 "Mark quoted subtrees with the protection property."
1771 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1772 (goto-char (point-min))
1773 (while (re-search-forward re-quote nil t)
1774 (goto-char (match-beginning 0))
1775 (end-of-line 1)
1776 (add-text-properties (point) (org-end-of-subtree t)
1777 '(org-protected t)))))
1779 (defun org-export-protect-verbatim ()
1780 "Mark verbatim snippets with the protection property."
1781 (goto-char (point-min))
1782 (while (re-search-forward org-verbatim-re nil t)
1783 (add-text-properties (match-beginning 4) (match-end 4)
1784 '(org-protected t))
1785 (goto-char (1+ (match-end 4)))))
1787 (defun org-export-protect-examples (&optional indent)
1788 "Protect code that should be exported as monospaced examples."
1789 (goto-char (point-min))
1790 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1791 (goto-char (match-end 0))
1792 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1793 (insert (if indent ": " ":"))
1794 (beginning-of-line 2)))
1795 (goto-char (point-min))
1796 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1797 (add-text-properties (match-beginning 0) (match-end 0)
1798 '(org-protected t))))
1800 (defun org-export-select-backend-specific-text (backend)
1801 (let ((formatters
1802 '((html "HTML" "BEGIN_HTML" "END_HTML")
1803 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1804 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1805 fmt)
1807 (while formatters
1808 (setq fmt (pop formatters))
1809 (when (eq (car fmt) backend)
1810 ;; This is selected code, put it into the file for real
1811 (goto-char (point-min))
1812 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1813 ":[ \t]*\\(.*\\)") nil t)
1814 (replace-match "\\1" t)
1815 (add-text-properties
1816 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1817 '(org-protected t))))
1818 (goto-char (point-min))
1819 (while (re-search-forward
1820 (concat "^#\\+"
1821 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1822 (cadddr fmt) "\\>.*\n?") nil t)
1823 (if (eq (car fmt) backend)
1824 ;; yes, keep this
1825 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1826 '(org-protected t))
1827 ;; No, this is for a different backend, kill it
1828 (delete-region (match-beginning 0) (match-end 0)))))))
1830 (defun org-export-mark-blockquote-and-verse ()
1831 "Mark block quote and verse environments with special cookies.
1832 These special cookies will later be interpreted by the backend."
1833 ;; Blockquotes
1834 (goto-char (point-min))
1835 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1836 nil t)
1837 (replace-match (if (equal (downcase (match-string 1)) "end")
1838 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1839 t t))
1840 ;; Verse
1841 (goto-char (point-min))
1842 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1843 (replace-match (if (equal (downcase (match-string 1)) "end")
1844 "ORG-VERSE-END" "ORG-VERSE-START")
1845 t t)))
1847 (defun org-export-attach-captions-and-attributes (backend target-alist)
1848 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1849 If the next thing following is a table, add the text properties to the first
1850 table line. If it is a link, add it to the line containing the link."
1851 (goto-char (point-min))
1852 (remove-text-properties (point-min) (point-max)
1853 '(org-caption nil org-attributes nil))
1854 (let ((case-fold-search t)
1855 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1856 "\\|"
1857 "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1858 "\\|"
1859 "^#\\+label:[ \t]+\\(.*\\)"
1860 "\\|"
1861 "^[ \t]*|[^-]"
1862 "\\|"
1863 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1864 cap attr label)
1865 (while (re-search-forward re nil t)
1866 (cond
1867 ((match-end 1)
1868 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1869 ((match-end 2)
1870 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1871 ((match-end 3)
1872 (setq label (org-trim (match-string 3))))
1874 (add-text-properties (point-at-bol) (point-at-eol)
1875 (list 'org-caption cap
1876 'org-attributes attr
1877 'org-label label))
1878 (if label (push (cons label label) target-alist))
1879 (setq cap nil attr nil label nil)))))
1880 target-alist)
1882 (defun org-export-remove-comment-blocks-and-subtrees ()
1883 "Remove the comment environment, and also commented subtrees."
1884 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1885 (case-fold-search nil))
1886 ;; Remove comment environment
1887 (goto-char (point-min))
1888 (while (re-search-forward
1889 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1890 (replace-match "" t t))
1891 ;; Remove subtrees that are commented
1892 (goto-char (point-min))
1893 (while (re-search-forward re-commented nil t)
1894 (goto-char (match-beginning 0))
1895 (delete-region (point) (org-end-of-subtree t)))))
1897 (defun org-export-handle-comments (commentsp)
1898 "Remove comments, or convert to backend-specific format.
1899 COMMENTSP can be a format string for publishing comments.
1900 When it is nil, all comments will be removed."
1901 (let ((re "^#\\(.*\n?\\)")
1902 pos)
1903 (goto-char (point-min))
1904 (while (or (looking-at re)
1905 (re-search-forward re nil t))
1906 (setq pos (match-beginning 0))
1907 (if commentsp
1908 (progn (add-text-properties
1909 (match-beginning 0) (match-end 0) '(org-protected t))
1910 (replace-match (format commentsp (match-string 1)) t t))
1911 (goto-char (1+ pos))
1912 (org-if-unprotected
1913 (replace-match "")
1914 (goto-char (max (point-min) (1- pos))))))))
1916 (defun org-export-mark-radio-links ()
1917 "Find all matches for radio targets and turn them into internal links."
1918 (let ((re-radio (and org-target-link-regexp
1919 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1920 (goto-char (point-min))
1921 (when re-radio
1922 (while (re-search-forward re-radio nil t)
1923 (org-if-unprotected
1924 (replace-match "\\1[[\\2]]"))))))
1926 (defun org-export-remove-special-table-lines ()
1927 "Remove tables lines that are used for internal purposes."
1928 (goto-char (point-min))
1929 (while (re-search-forward "^[ \t]*|" nil t)
1930 (beginning-of-line 1)
1931 (if (or (looking-at "[ \t]*| *[!_^] *|")
1932 (and (looking-at ".*?| *<[0-9]+> *|")
1933 (not (looking-at ".*?| *[^ <|]"))))
1934 (delete-region (max (point-min) (1- (point-at-bol)))
1935 (point-at-eol))
1936 (end-of-line 1))))
1938 (defun org-export-normalize-links ()
1939 "Convert all links to bracket links, and expand link abbreviations."
1940 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1941 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1942 (goto-char (point-min))
1943 (while (re-search-forward re-plain-link nil t)
1944 (goto-char (1- (match-end 0)))
1945 (org-if-unprotected
1946 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1947 ":" (match-string 3) "]]")))
1948 ;; added 'org-link face to links
1949 (put-text-property 0 (length s) 'face 'org-link s)
1950 (replace-match s t t))))
1951 (goto-char (point-min))
1952 (while (re-search-forward re-angle-link nil t)
1953 (goto-char (1- (match-end 0)))
1954 (org-if-unprotected
1955 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1956 ":" (match-string 3) "]]")))
1957 (put-text-property 0 (length s) 'face 'org-link s)
1958 (replace-match s t t))))
1959 (goto-char (point-min))
1960 (while (re-search-forward org-bracket-link-regexp nil t)
1961 (goto-char (1- (match-end 0)))
1962 (org-if-unprotected
1963 (let* ((xx (save-match-data
1964 (org-translate-link
1965 (org-link-expand-abbrev (match-string 1)))))
1966 (s (concat
1967 "[[" xx "]"
1968 (if (match-end 3)
1969 (match-string 2)
1970 (concat "[" xx "]"))
1971 "]")))
1972 (put-text-property 0 (length s) 'face 'org-link s)
1973 (replace-match s t t))))))
1975 (defun org-export-concatenate-multiline-links ()
1976 "Find multi-line links and put it all into a single line.
1977 This is to make sure that the line-processing export backends
1978 can work correctly."
1979 (goto-char (point-min))
1980 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1981 (org-if-unprotected
1982 (replace-match "\\1 \\3")
1983 (goto-char (match-beginning 0)))))
1985 (defun org-export-concatenate-multiline-emphasis ()
1986 "Find multi-line emphasis and put it all into a single line.
1987 This is to make sure that the line-processing export backends
1988 can work correctly."
1989 (goto-char (point-min))
1990 (while (re-search-forward org-emph-re nil t)
1991 (if (not (= (char-after (match-beginning 3))
1992 (char-after (match-beginning 4))))
1993 (org-if-unprotected
1994 (subst-char-in-region (match-beginning 0) (match-end 0)
1995 ?\n ?\ t)
1996 (goto-char (1- (match-end 0))))
1997 (goto-char (1+ (match-beginning 0))))))
1999 (defun org-export-grab-title-from-buffer ()
2000 "Get a title for the current document, from looking at the buffer."
2001 (let ((inhibit-read-only t))
2002 (save-excursion
2003 (goto-char (point-min))
2004 (let ((end (if (looking-at org-outline-regexp)
2005 (point)
2006 (save-excursion (outline-next-heading) (point)))))
2007 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2008 ;; Mark the line so that it will not be exported as normal text.
2009 (org-unmodified
2010 (add-text-properties (match-beginning 0) (match-end 0)
2011 (list :org-license-to-kill t)))
2012 ;; Return the title string
2013 (org-trim (match-string 0)))))))
2015 (defun org-export-get-title-from-subtree ()
2016 "Return subtree title and exclude it from export."
2017 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
2018 (save-excursion
2019 (goto-char rbeg)
2020 (when (and (org-at-heading-p)
2021 (>= (org-end-of-subtree t t) rend))
2022 ;; This is a subtree, we take the title from the first heading
2023 (goto-char rbeg)
2024 (looking-at org-todo-line-regexp)
2025 (setq title (match-string 3))
2026 (org-unmodified
2027 (add-text-properties (point) (1+ (point-at-eol))
2028 (list :org-license-to-kill t)))
2029 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2030 title))
2032 (defun org-solidify-link-text (s &optional alist)
2033 "Take link text and make a safe target out of it."
2034 (save-match-data
2035 (let* ((rtn
2036 (mapconcat
2037 'identity
2038 (org-split-string s "[ \t\r\n]+") "=="))
2039 (a (assoc rtn alist)))
2040 (or (cdr a) rtn))))
2042 (defun org-get-min-level (lines)
2043 "Get the minimum level in LINES."
2044 (let ((re "^\\(\\*+\\) ") l min)
2045 (catch 'exit
2046 (while (setq l (pop lines))
2047 (if (string-match re l)
2048 (throw 'exit (org-tr-level (length (match-string 1 l))))))
2049 1)))
2051 ;; Variable holding the vector with section numbers
2052 (defvar org-section-numbers (make-vector org-level-max 0))
2054 (defun org-init-section-numbers ()
2055 "Initialize the vector for the section numbers."
2056 (let* ((level -1)
2057 (numbers (nreverse (org-split-string "" "\\.")))
2058 (depth (1- (length org-section-numbers)))
2059 (i depth) number-string)
2060 (while (>= i 0)
2061 (if (> i level)
2062 (aset org-section-numbers i 0)
2063 (setq number-string (or (car numbers) "0"))
2064 (if (string-match "\\`[A-Z]\\'" number-string)
2065 (aset org-section-numbers i
2066 (- (string-to-char number-string) ?A -1))
2067 (aset org-section-numbers i (string-to-number number-string)))
2068 (pop numbers))
2069 (setq i (1- i)))))
2071 (defun org-section-number (&optional level)
2072 "Return a string with the current section number.
2073 When LEVEL is non-nil, increase section numbers on that level."
2074 (let* ((depth (1- (length org-section-numbers)))
2075 (string "")
2076 (fmts (car org-export-section-number-format))
2077 (term (cdr org-export-section-number-format))
2078 (sep "")
2079 ctype fmt idx n)
2080 (when level
2081 (when (> level -1)
2082 (aset org-section-numbers
2083 level (1+ (aref org-section-numbers level))))
2084 (setq idx (1+ level))
2085 (while (<= idx depth)
2086 (if (not (= idx 1))
2087 (aset org-section-numbers idx 0))
2088 (setq idx (1+ idx))))
2089 (setq idx 0)
2090 (while (<= idx depth)
2091 (when (> (aref org-section-numbers idx) 0)
2092 (setq fmt (or (pop fmts) fmt)
2093 ctype (car fmt)
2094 n (aref org-section-numbers idx)
2095 string (if (> n 0)
2096 (concat string sep (org-number-to-counter n ctype))
2097 (concat string ".0"))
2098 sep (nth 1 fmt)))
2099 (setq idx (1+ idx)))
2100 (save-match-data
2101 (if (string-match "\\`\\([@0]\\.\\)+" string)
2102 (setq string (replace-match "" t nil string)))
2103 (if (string-match "\\(\\.0\\)+\\'" string)
2104 (setq string (replace-match "" t nil string))))
2105 (concat string term)))
2107 (defun org-number-to-counter (n type)
2108 "Concert number N to a string counter, according to TYPE.
2109 TYPE must be a string, any of:
2110 1 number
2111 A A,B,....
2112 a a,b,....
2113 I uppper case roman numeral
2114 i lower case roman numeral"
2115 (cond
2116 ((equal type "1") (number-to-string n))
2117 ((equal type "A") (char-to-string (+ ?A n -1)))
2118 ((equal type "a") (char-to-string (+ ?a n -1)))
2119 ((equal type "I") (org-number-to-roman n))
2120 ((equal type "i") (downcase (org-number-to-roman n)))
2121 (t (error "Invalid counter type `%s'" type))))
2123 (defun org-number-to-roman (n)
2124 "Convert integer N into a roman numeral."
2125 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2126 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2127 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2128 ( 1 . "I")))
2129 (res ""))
2130 (if (<= n 0)
2131 (number-to-string n)
2132 (while roman
2133 (if (>= n (caar roman))
2134 (setq n (- n (caar roman))
2135 res (concat res (cdar roman)))
2136 (pop roman)))
2137 res)))
2139 (org-number-to-roman 1961)
2142 ;;; Include files
2144 (defun org-export-handle-include-files ()
2145 "Include the contents of include files, with proper formatting."
2146 (let ((case-fold-search t)
2147 params file markup lang start end prefix prefix1)
2148 (goto-char (point-min))
2149 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2150 (setq params (read (concat "(" (match-string 1) ")"))
2151 prefix (org-get-and-remove-property 'params :prefix)
2152 prefix1 (org-get-and-remove-property 'params :prefix1)
2153 file (org-symname-or-string (pop params))
2154 markup (org-symname-or-string (pop params))
2155 lang (org-symname-or-string (pop params)))
2156 (delete-region (match-beginning 0) (match-end 0))
2157 (if (or (not file)
2158 (not (file-exists-p file))
2159 (not (file-readable-p file)))
2160 (insert (format "CANNOT INCLUDE FILE %s" file))
2161 (when markup
2162 (if (equal (downcase markup) "src")
2163 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2164 end "#+end_src")
2165 (setq start (format "#+begin_%s\n" markup)
2166 end (format "#+end_%s" markup))))
2167 (insert (or start ""))
2168 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2169 (or (bolp) (newline))
2170 (insert (or end ""))))))
2172 (defun org-get-file-contents (file &optional prefix prefix1)
2173 "Get the contents of FILE and return them as a string.
2174 If PREFIX is a string, prepend it to each line. If PREFIX1
2175 is a string, prepend it to the first line instead of PREFIX."
2176 (with-temp-buffer
2177 (insert-file-contents file)
2178 (when (or prefix prefix1)
2179 (goto-char (point-min))
2180 (while (not (eobp))
2181 (insert (or prefix1 prefix))
2182 (setq prefix1 nil)
2183 (beginning-of-line 2)))
2184 (buffer-string)))
2186 (defun org-get-and-remove-property (listvar prop)
2187 "Check if the value of LISTVAR contains PROP as a property.
2188 If yes, return the value of that property (i.e. the element following
2189 in the list) and remove property and value from the list in LISTVAR."
2190 (let ((list (symbol-value listvar)) m v)
2191 (when (setq m (member prop list))
2192 (setq v (nth 1 m))
2193 (if (equal (car list) prop)
2194 (set listvar (cddr list))
2195 (setcdr (nthcdr (- (length list) (length m) 1) list)
2196 (cddr m))
2197 (set listvar list)))
2200 (defun org-symname-or-string (s)
2201 (if (symbolp s)
2202 (if s (symbol-name s) s)
2205 ;;; Fontification of code
2206 ;; Currently only for the HTML backend, but who knows....
2207 (defun org-export-replace-src-segments ()
2208 "Replace source code segments with special code for export."
2209 (let ((case-fold-search t)
2210 lang code trans)
2211 (goto-char (point-min))
2212 (while (re-search-forward
2213 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2214 nil t)
2215 (setq lang (match-string 1) code (match-string 2)
2216 trans (org-export-format-source-code lang code))
2217 (replace-match trans t t))))
2219 (defvar htmlp) ;; dynamically scoped from org-exp.el
2221 (defun org-export-format-source-code (lang code)
2222 "Format CODE from language LANG and return it formatted for export.
2223 Currently, this only does something for HTML export, for all other
2224 backends, it converts the segment into an EXAMPLE segment."
2225 (save-match-data
2226 (cond
2227 (htmlp
2228 ;; We are exporting to HTML
2229 (require 'htmlize nil t)
2230 (if (not (fboundp 'htmlize-region-for-paste))
2231 (progn
2232 ;; we do not have htmlize.el, or an old version of it
2233 (message
2234 "htmlize.el 1.34 or later is needed for source code formatting")
2235 (concat "#+BEGIN_EXAMPLE\n" code
2236 (if (string-match "\n\\'" code) "" "\n")
2237 "#+END_EXAMPLE\n"))
2238 ;; ok, we are good to go
2239 (let* ((mode (and lang (intern (concat lang "-mode"))))
2240 (org-inhibit-startup t)
2241 (org-startup-folded nil)
2242 (htmltext
2243 (with-temp-buffer
2244 (insert code)
2245 ;; Free up the protected stuff
2246 (goto-char (point-min))
2247 (while (re-search-forward "^," nil t)
2248 (replace-match "")
2249 (end-of-line 1))
2250 (if (functionp mode)
2251 (funcall mode)
2252 (fundamental-mode))
2253 (font-lock-fontify-buffer)
2254 (org-export-htmlize-region-for-paste
2255 (point-min) (point-max)))))
2256 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2257 (setq htmltext (replace-match
2258 (format "<pre class=\"src src-%s\">" lang)
2259 t t htmltext)))
2260 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2262 ;; This is not HTML, so just make it an example.
2263 (when (equal lang "org")
2264 (while (string-match "^," code)
2265 (setq code (replace-match "" t t code))))
2266 (concat "#+BEGIN_EXAMPLE\n" code
2267 (if (string-match "\n\\'" code) "" "\n")
2268 "#+END_EXAMPLE\n")))))
2270 ;;; ASCII export
2272 (defvar org-last-level nil) ; dynamically scoped variable
2273 (defvar org-min-level nil) ; dynamically scoped variable
2274 (defvar org-levels-open nil) ; dynamically scoped parameter
2275 (defvar org-ascii-current-indentation nil) ; For communication
2277 ;;;###autoload
2278 (defun org-export-as-ascii (arg)
2279 "Export the outline as a pretty ASCII file.
2280 If there is an active region, export only the region.
2281 The prefix ARG specifies how many levels of the outline should become
2282 underlined headlines. The default is 3."
2283 (interactive "P")
2284 (setq-default org-todo-line-regexp org-todo-line-regexp)
2285 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2286 (org-infile-export-plist)))
2287 (region-p (org-region-active-p))
2288 (rbeg (and region-p (region-beginning)))
2289 (rend (and region-p (region-end)))
2290 (subtree-p
2291 (when region-p
2292 (save-excursion
2293 (goto-char rbeg)
2294 (and (org-at-heading-p)
2295 (>= (org-end-of-subtree t t) rend)))))
2296 (opt-plist (if subtree-p
2297 (org-export-add-subtree-options opt-plist rbeg)
2298 opt-plist))
2299 (custom-times org-display-custom-times)
2300 (org-ascii-current-indentation '(0 . 0))
2301 (level 0) line txt
2302 (umax nil)
2303 (umax-toc nil)
2304 (case-fold-search nil)
2305 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2306 (filename (concat (file-name-as-directory
2307 (org-export-directory :ascii opt-plist))
2308 (file-name-sans-extension
2309 (or (and subtree-p
2310 (org-entry-get (region-beginning)
2311 "EXPORT_FILE_NAME" t))
2312 (file-name-nondirectory bfname)))
2313 ".txt"))
2314 (filename (if (equal (file-truename filename)
2315 (file-truename bfname))
2316 (concat filename ".txt")
2317 filename))
2318 (buffer (find-file-noselect filename))
2319 (org-levels-open (make-vector org-level-max nil))
2320 (odd org-odd-levels-only)
2321 (date (plist-get opt-plist :date))
2322 (author (plist-get opt-plist :author))
2323 (title (or (and subtree-p (org-export-get-title-from-subtree))
2324 (plist-get opt-plist :title)
2325 (and (not
2326 (plist-get opt-plist :skip-before-1st-heading))
2327 (org-export-grab-title-from-buffer))
2328 (file-name-sans-extension
2329 (file-name-nondirectory bfname))))
2330 (email (plist-get opt-plist :email))
2331 (language (plist-get opt-plist :language))
2332 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2333 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2334 (todo nil)
2335 (lang-words nil)
2336 (region
2337 (buffer-substring
2338 (if (org-region-active-p) (region-beginning) (point-min))
2339 (if (org-region-active-p) (region-end) (point-max))))
2340 (lines (org-split-string
2341 (org-export-preprocess-string
2342 region
2343 :for-ascii t
2344 :skip-before-1st-heading
2345 (plist-get opt-plist :skip-before-1st-heading)
2346 :drawers (plist-get opt-plist :drawers)
2347 :tags (plist-get opt-plist :tags)
2348 :priority (plist-get opt-plist :priority)
2349 :todo-keywords (plist-get opt-plist :todo-keywords)
2350 :verbatim-multiline t
2351 :select-tags (plist-get opt-plist :select-tags)
2352 :exclude-tags (plist-get opt-plist :exclude-tags)
2353 :archived-trees
2354 (plist-get opt-plist :archived-trees)
2355 :add-text (plist-get opt-plist :text))
2356 "\n"))
2357 thetoc have-headings first-heading-pos
2358 table-open table-buffer)
2360 (let ((inhibit-read-only t))
2361 (org-unmodified
2362 (remove-text-properties (point-min) (point-max)
2363 '(:org-license-to-kill t))))
2365 (setq org-min-level (org-get-min-level lines))
2366 (setq org-last-level org-min-level)
2367 (org-init-section-numbers)
2369 (find-file-noselect filename)
2371 (setq lang-words (or (assoc language org-export-language-setup)
2372 (assoc "en" org-export-language-setup)))
2373 (switch-to-buffer-other-window buffer)
2374 (erase-buffer)
2375 (fundamental-mode)
2376 ;; create local variables for all options, to make sure all called
2377 ;; functions get the correct information
2378 (mapc (lambda (x)
2379 (set (make-local-variable (nth 2 x))
2380 (plist-get opt-plist (car x))))
2381 org-export-plist-vars)
2382 (org-set-local 'org-odd-levels-only odd)
2383 (setq umax (if arg (prefix-numeric-value arg)
2384 org-export-headline-levels))
2385 (setq umax-toc (if (integerp org-export-with-toc)
2386 (min org-export-with-toc umax)
2387 umax))
2389 ;; File header
2390 (if title (org-insert-centered title ?=))
2391 (insert "\n")
2392 (if (and (or author email)
2393 org-export-author-info)
2394 (insert (concat (nth 1 lang-words) ": " (or author "")
2395 (if email (concat " <" email ">") "")
2396 "\n")))
2398 (cond
2399 ((and date (string-match "%" date))
2400 (setq date (format-time-string date)))
2401 (date)
2402 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2404 (if (and date org-export-time-stamp-file)
2405 (insert (concat (nth 2 lang-words) ": " date"\n")))
2407 (insert "\n\n")
2409 (if org-export-with-toc
2410 (progn
2411 (push (concat (nth 3 lang-words) "\n") thetoc)
2412 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2413 "\n") thetoc)
2414 (mapc '(lambda (line)
2415 (if (string-match org-todo-line-regexp
2416 line)
2417 ;; This is a headline
2418 (progn
2419 (setq have-headings t)
2420 (setq level (- (match-end 1) (match-beginning 1))
2421 level (org-tr-level level)
2422 txt (match-string 3 line)
2423 todo
2424 (or (and org-export-mark-todo-in-toc
2425 (match-beginning 2)
2426 (not (member (match-string 2 line)
2427 org-done-keywords)))
2428 ; TODO, not DONE
2429 (and org-export-mark-todo-in-toc
2430 (= level umax-toc)
2431 (org-search-todo-below
2432 line lines level))))
2433 (setq txt (org-html-expand-for-ascii txt))
2435 (while (string-match org-bracket-link-regexp txt)
2436 (setq txt
2437 (replace-match
2438 (match-string (if (match-end 2) 3 1) txt)
2439 t t txt)))
2441 (if (and (memq org-export-with-tags '(not-in-toc nil))
2442 (string-match
2443 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2444 txt))
2445 (setq txt (replace-match "" t t txt)))
2446 (if (string-match quote-re0 txt)
2447 (setq txt (replace-match "" t t txt)))
2449 (if org-export-with-section-numbers
2450 (setq txt (concat (org-section-number level)
2451 " " txt)))
2452 (if (<= level umax-toc)
2453 (progn
2454 (push
2455 (concat
2456 (make-string
2457 (* (max 0 (- level org-min-level)) 4) ?\ )
2458 (format (if todo "%s (*)\n" "%s\n") txt))
2459 thetoc)
2460 (setq org-last-level level))
2461 ))))
2462 lines)
2463 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2465 (org-init-section-numbers)
2466 (while (setq line (pop lines))
2467 ;; Remove the quoted HTML tags.
2468 (setq line (org-html-expand-for-ascii line))
2469 ;; Replace links with the description when possible
2470 (while (string-match org-bracket-link-regexp line)
2471 (setq line (replace-match
2472 (if (match-end 3) "[\\3]" "[\\1]")
2473 t nil line)))
2474 (when custom-times
2475 (setq line (org-translate-time line)))
2476 (cond
2477 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2478 ;; a Headline
2479 (setq first-heading-pos (or first-heading-pos (point)))
2480 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2481 txt (match-string 2 line))
2482 (org-ascii-level-start level txt umax lines))
2484 ((and org-export-with-tables
2485 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2486 (if (not table-open)
2487 ;; New table starts
2488 (setq table-open t table-buffer nil))
2489 ;; Accumulate lines
2490 (setq table-buffer (cons line table-buffer))
2491 (when (or (not lines)
2492 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2493 (car lines))))
2494 (setq table-open nil
2495 table-buffer (nreverse table-buffer))
2496 (insert (mapconcat
2497 (lambda (x)
2498 (org-fix-indentation x org-ascii-current-indentation))
2499 (org-format-table-ascii table-buffer)
2500 "\n") "\n")))
2502 (setq line (org-fix-indentation line org-ascii-current-indentation))
2503 ;; Remove forced line breaks
2504 (if (string-match "\\\\\\\\[ \t]*$" line)
2505 (setq line (replace-match "" t t line)))
2506 (if (and org-export-with-fixed-width
2507 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2508 (setq line (replace-match "\\1" nil nil line)))
2509 (insert line "\n"))))
2511 (normal-mode)
2513 ;; insert the table of contents
2514 (when thetoc
2515 (goto-char (point-min))
2516 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2517 (progn
2518 (goto-char (match-beginning 0))
2519 (replace-match ""))
2520 (goto-char first-heading-pos))
2521 (mapc 'insert thetoc)
2522 (or (looking-at "[ \t]*\n[ \t]*\n")
2523 (insert "\n\n")))
2525 ;; Convert whitespace place holders
2526 (goto-char (point-min))
2527 (let (beg end)
2528 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2529 (setq end (next-single-property-change beg 'org-whitespace))
2530 (goto-char beg)
2531 (delete-region beg end)
2532 (insert (make-string (- end beg) ?\ ))))
2534 (save-buffer)
2535 ;; remove display and invisible chars
2536 (let (beg end)
2537 (goto-char (point-min))
2538 (while (setq beg (next-single-property-change (point) 'display))
2539 (setq end (next-single-property-change beg 'display))
2540 (delete-region beg end)
2541 (goto-char beg)
2542 (insert "=>"))
2543 (goto-char (point-min))
2544 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2545 (setq end (next-single-property-change beg 'org-cwidth))
2546 (delete-region beg end)
2547 (goto-char beg)))
2548 (goto-char (point-min))))
2550 (defun org-export-ascii-preprocess ()
2551 "Do extra work for ASCII export"
2552 ;; Put quotes around verbatim text
2553 (goto-char (point-min))
2554 (while (re-search-forward org-verbatim-re nil t)
2555 (goto-char (match-end 2))
2556 (backward-delete-char 1) (insert "'")
2557 (goto-char (match-beginning 2))
2558 (delete-char 1) (insert "`")
2559 (goto-char (match-end 2)))
2560 (goto-char (point-min))
2561 ;; Remove target markers
2562 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
2563 (replace-match "\\1\\2")))
2565 (defun org-search-todo-below (line lines level)
2566 "Search the subtree below LINE for any TODO entries."
2567 (let ((rest (cdr (memq line lines)))
2568 (re org-todo-line-regexp)
2569 line lv todo)
2570 (catch 'exit
2571 (while (setq line (pop rest))
2572 (if (string-match re line)
2573 (progn
2574 (setq lv (- (match-end 1) (match-beginning 1))
2575 todo (and (match-beginning 2)
2576 (not (member (match-string 2 line)
2577 org-done-keywords))))
2578 ; TODO, not DONE
2579 (if (<= lv level) (throw 'exit nil))
2580 (if todo (throw 'exit t))))))))
2582 (defun org-html-expand-for-ascii (line)
2583 "Handle quoted HTML for ASCII export."
2584 (if org-export-html-expand
2585 (while (string-match "@<[^<>\n]*>" line)
2586 ;; We just remove the tags for now.
2587 (setq line (replace-match "" nil nil line))))
2588 line)
2590 (defun org-insert-centered (s &optional underline)
2591 "Insert the string S centered and underline it with character UNDERLINE."
2592 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2593 (insert (make-string ind ?\ ) s "\n")
2594 (if underline
2595 (insert (make-string ind ?\ )
2596 (make-string (string-width s) underline)
2597 "\n"))))
2599 (defun org-ascii-level-start (level title umax &optional lines)
2600 "Insert a new level in ASCII export."
2601 (let (char (n (- level umax 1)) (ind 0))
2602 (if (> level umax)
2603 (progn
2604 (insert (make-string (* 2 n) ?\ )
2605 (char-to-string (nth (% n (length org-export-ascii-bullets))
2606 org-export-ascii-bullets))
2607 " " title "\n")
2608 ;; find the indentation of the next non-empty line
2609 (catch 'stop
2610 (while lines
2611 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2612 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2613 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2614 (pop lines)))
2615 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2616 (if (or (not (equal (char-before) ?\n))
2617 (not (equal (char-before (1- (point))) ?\n)))
2618 (insert "\n"))
2619 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2620 (unless org-export-with-tags
2621 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2622 (setq title (replace-match "" t t title))))
2623 (if org-export-with-section-numbers
2624 (setq title (concat (org-section-number level) " " title)))
2625 (insert title "\n" (make-string (string-width title) char) "\n")
2626 (setq org-ascii-current-indentation '(0 . 0)))))
2628 ;;;###autoload
2629 (defun org-export-visible (type arg)
2630 "Create a copy of the visible part of the current buffer, and export it.
2631 The copy is created in a temporary buffer and removed after use.
2632 TYPE is the final key (as a string) that also select the export command in
2633 the `C-c C-e' export dispatcher.
2634 As a special case, if the you type SPC at the prompt, the temporary
2635 org-mode file will not be removed but presented to you so that you can
2636 continue to use it. The prefix arg ARG is passed through to the exporting
2637 command."
2638 (interactive
2639 (list (progn
2640 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2641 (read-char-exclusive))
2642 current-prefix-arg))
2643 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2644 (error "Invalid export key"))
2645 (let* ((binding (cdr (assoc type
2646 '((?a . org-export-as-ascii)
2647 (?\C-a . org-export-as-ascii)
2648 (?b . org-export-as-html-and-open)
2649 (?\C-b . org-export-as-html-and-open)
2650 (?h . org-export-as-html)
2651 (?H . org-export-as-html-to-buffer)
2652 (?R . org-export-region-as-html)
2653 (?x . org-export-as-xoxo)))))
2654 (keepp (equal type ?\ ))
2655 (file buffer-file-name)
2656 (buffer (get-buffer-create "*Org Export Visible*"))
2657 s e)
2658 ;; Need to hack the drawers here.
2659 (save-excursion
2660 (goto-char (point-min))
2661 (while (re-search-forward org-drawer-regexp nil t)
2662 (goto-char (match-beginning 1))
2663 (or (org-invisible-p) (org-flag-drawer nil))))
2664 (with-current-buffer buffer (erase-buffer))
2665 (save-excursion
2666 (setq s (goto-char (point-min)))
2667 (while (not (= (point) (point-max)))
2668 (goto-char (org-find-invisible))
2669 (append-to-buffer buffer s (point))
2670 (setq s (goto-char (org-find-visible))))
2671 (org-cycle-hide-drawers 'all)
2672 (goto-char (point-min))
2673 (unless keepp
2674 ;; Copy all comment lines to the end, to make sure #+ settings are
2675 ;; still available for the second export step. Kind of a hack, but
2676 ;; does do the trick.
2677 (if (looking-at "#[^\r\n]*")
2678 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2679 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2680 (append-to-buffer buffer (1+ (match-beginning 0))
2681 (min (point-max) (1+ (match-end 0))))))
2682 (set-buffer buffer)
2683 (let ((buffer-file-name file)
2684 (org-inhibit-startup t))
2685 (org-mode)
2686 (show-all)
2687 (unless keepp (funcall binding arg))))
2688 (if (not keepp)
2689 (kill-buffer buffer)
2690 (switch-to-buffer-other-window buffer)
2691 (goto-char (point-min)))))
2693 (defun org-find-visible ()
2694 (let ((s (point)))
2695 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2696 (get-char-property s 'invisible)))
2698 (defun org-find-invisible ()
2699 (let ((s (point)))
2700 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2701 (not (get-char-property s 'invisible))))
2704 ;;; HTML export
2706 (defvar org-archive-location) ;; gets loades with the org-archive require.
2707 (defun org-get-current-options ()
2708 "Return a string with current options as keyword options.
2709 Does include HTML export options as well as TODO and CATEGORY stuff."
2710 (require 'org-archive)
2711 (format
2712 "#+TITLE: %s
2713 #+AUTHOR: %s
2714 #+EMAIL: %s
2715 #+DATE: %s
2716 #+LANGUAGE: %s
2717 #+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 todo:%s pri:%s tags:%s
2719 #+EXPORT_SELECT_TAGS: %s
2720 #+EXPORT_EXCLUDE_TAGS: %s
2721 #+LINK_UP: %s
2722 #+LINK_HOME: %s
2723 #+CATEGORY: %s
2724 #+SEQ_TODO: %s
2725 #+TYP_TODO: %s
2726 #+PRIORITIES: %c %c %c
2727 #+DRAWERS: %s
2728 #+STARTUP: %s %s %s %s %s
2729 #+TAGS: %s
2730 #+FILETAGS: %s
2731 #+ARCHIVE: %s
2732 #+LINK: %s
2734 (buffer-name) (user-full-name) user-mail-address
2735 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2736 org-export-default-language
2737 org-export-headline-levels
2738 org-export-with-section-numbers
2739 org-export-with-toc
2740 org-export-preserve-breaks
2741 org-export-html-expand
2742 org-export-with-fixed-width
2743 org-export-with-tables
2744 org-export-with-sub-superscripts
2745 org-export-with-special-strings
2746 org-export-with-footnotes
2747 org-export-with-emphasize
2748 org-export-with-TeX-macros
2749 org-export-with-LaTeX-fragments
2750 org-export-skip-text-before-1st-heading
2751 org-export-with-drawers
2752 org-export-with-todo-keywords
2753 org-export-with-priority
2754 org-export-with-tags
2755 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2756 (mapconcat 'identity org-export-select-tags " ")
2757 (mapconcat 'identity org-export-exclude-tags " ")
2758 org-export-html-link-up
2759 org-export-html-link-home
2760 (file-name-nondirectory buffer-file-name)
2761 "TODO FEEDBACK VERIFY DONE"
2762 "Me Jason Marie DONE"
2763 org-highest-priority org-lowest-priority org-default-priority
2764 (mapconcat 'identity org-drawers " ")
2765 (cdr (assoc org-startup-folded
2766 '((nil . "showall") (t . "overview") (content . "content"))))
2767 (if org-odd-levels-only "odd" "oddeven")
2768 (if org-hide-leading-stars "hidestars" "showstars")
2769 (if org-startup-align-all-tables "align" "noalign")
2770 (cond ((eq org-log-done t) "logdone")
2771 ((equal org-log-done 'note) "lognotedone")
2772 ((not org-log-done) "nologdone"))
2773 (or (mapconcat (lambda (x)
2774 (cond
2775 ((equal '(:startgroup) x) "{")
2776 ((equal '(:endgroup) x) "}")
2777 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2778 (t (car x))))
2779 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2780 (mapconcat 'identity org-file-tags " ")
2781 org-archive-location
2782 "org file:~/org/%s.org"
2785 (defun org-export-html-preprocess (parameters)
2786 ;; Convert LaTeX fragments to images
2787 (when (plist-get parameters :LaTeX-fragments)
2788 (org-format-latex
2789 (concat "ltxpng/" (file-name-sans-extension
2790 (file-name-nondirectory
2791 org-current-export-file)))
2792 org-current-export-dir nil "Creating LaTeX image %s"))
2793 (message "Exporting..."))
2795 ;;;###autoload
2796 (defun org-insert-export-options-template ()
2797 "Insert into the buffer a template with information for exporting."
2798 (interactive)
2799 (if (not (bolp)) (newline))
2800 (let ((s (org-get-current-options)))
2801 (and (string-match "#\\+CATEGORY" s)
2802 (setq s (substring s 0 (match-beginning 0))))
2803 (insert s)))
2805 ;;;###autoload
2806 (defun org-export-as-html-and-open (arg)
2807 "Export the outline as HTML and immediately open it with a browser.
2808 If there is an active region, export only the region.
2809 The prefix ARG specifies how many levels of the outline should become
2810 headlines. The default is 3. Lower levels will become bulleted lists."
2811 (interactive "P")
2812 (org-export-as-html arg 'hidden)
2813 (org-open-file buffer-file-name))
2815 ;;;###autoload
2816 (defun org-export-as-html-batch ()
2817 "Call `org-export-as-html', may be used in batch processing as
2818 emacs --batch
2819 --load=$HOME/lib/emacs/org.el
2820 --eval \"(setq org-export-headline-levels 2)\"
2821 --visit=MyFile --funcall org-export-as-html-batch"
2822 (org-export-as-html org-export-headline-levels 'hidden))
2824 ;;;###autoload
2825 (defun org-export-as-html-to-buffer (arg)
2826 "Call `org-exort-as-html` with output to a temporary buffer.
2827 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2828 (interactive "P")
2829 (org-export-as-html arg nil nil "*Org HTML Export*")
2830 (switch-to-buffer-other-window "*Org HTML Export*"))
2832 ;;;###autoload
2833 (defun org-replace-region-by-html (beg end)
2834 "Assume the current region has org-mode syntax, and convert it to HTML.
2835 This can be used in any buffer. For example, you could write an
2836 itemized list in org-mode syntax in an HTML buffer and then use this
2837 command to convert it."
2838 (interactive "r")
2839 (let (reg html buf pop-up-frames)
2840 (save-window-excursion
2841 (if (org-mode-p)
2842 (setq html (org-export-region-as-html
2843 beg end t 'string))
2844 (setq reg (buffer-substring beg end)
2845 buf (get-buffer-create "*Org tmp*"))
2846 (with-current-buffer buf
2847 (erase-buffer)
2848 (insert reg)
2849 (org-mode)
2850 (setq html (org-export-region-as-html
2851 (point-min) (point-max) t 'string)))
2852 (kill-buffer buf)))
2853 (delete-region beg end)
2854 (insert html)))
2856 ;;;###autoload
2857 (defun org-export-region-as-html (beg end &optional body-only buffer)
2858 "Convert region from BEG to END in org-mode buffer to HTML.
2859 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2860 contents, and only produce the region of converted text, useful for
2861 cut-and-paste operations.
2862 If BUFFER is a buffer or a string, use/create that buffer as a target
2863 of the converted HTML. If BUFFER is the symbol `string', return the
2864 produced HTML as a string and leave not buffer behind. For example,
2865 a Lisp program could call this function in the following way:
2867 (setq html (org-export-region-as-html beg end t 'string))
2869 When called interactively, the output buffer is selected, and shown
2870 in a window. A non-interactive call will only return the buffer."
2871 (interactive "r\nP")
2872 (when (interactive-p)
2873 (setq buffer "*Org HTML Export*"))
2874 (let ((transient-mark-mode t) (zmacs-regions t)
2875 ext-plist rtn)
2876 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2877 (goto-char end)
2878 (set-mark (point)) ;; to activate the region
2879 (goto-char beg)
2880 (setq rtn (org-export-as-html
2881 nil nil ext-plist
2882 buffer body-only))
2883 (if (fboundp 'deactivate-mark) (deactivate-mark))
2884 (if (and (interactive-p) (bufferp rtn))
2885 (switch-to-buffer-other-window rtn)
2886 rtn)))
2888 (defvar html-table-tag nil) ; dynamically scoped into this.
2889 (defvar org-par-open nil)
2890 ;;;###autoload
2891 (defun org-export-as-html (arg &optional hidden ext-plist
2892 to-buffer body-only pub-dir)
2893 "Export the outline as a pretty HTML file.
2894 If there is an active region, export only the region. The prefix
2895 ARG specifies how many levels of the outline should become
2896 headlines. The default is 3. Lower levels will become bulleted
2897 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2898 EXT-PLIST is a property list with external parameters overriding
2899 org-mode's default settings, but still inferior to file-local
2900 settings. When TO-BUFFER is non-nil, create a buffer with that
2901 name and export to that buffer. If TO-BUFFER is the symbol
2902 `string', don't leave any buffer behind but just return the
2903 resulting HTML as a string. When BODY-ONLY is set, don't produce
2904 the file header and footer, simply return the content of
2905 <body>...</body>, without even the body tags themselves. When
2906 PUB-DIR is set, use this as the publishing directory."
2907 (interactive "P")
2909 ;; Make sure we have a file name when we need it.
2910 (when (and (not (or to-buffer body-only))
2911 (not buffer-file-name))
2912 (if (buffer-base-buffer)
2913 (org-set-local 'buffer-file-name
2914 (with-current-buffer (buffer-base-buffer)
2915 buffer-file-name))
2916 (error "Need a file name to be able to export.")))
2918 (message "Exporting...")
2919 (setq-default org-todo-line-regexp org-todo-line-regexp)
2920 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2921 (setq-default org-done-keywords org-done-keywords)
2922 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2923 (let* ((opt-plist
2924 (org-export-process-option-filters
2925 (org-combine-plists (org-default-export-plist)
2926 ext-plist
2927 (org-infile-export-plist))))
2928 (style (concat (if (plist-get opt-plist :style-include-default)
2929 org-export-html-style-default)
2930 (plist-get opt-plist :style)
2931 (plist-get opt-plist :style-extra)))
2932 (html-extension (plist-get opt-plist :html-extension))
2933 (link-validate (plist-get opt-plist :link-validation-function))
2934 valid thetoc have-headings first-heading-pos
2935 (odd org-odd-levels-only)
2936 (region-p (org-region-active-p))
2937 (rbeg (and region-p (region-beginning)))
2938 (rend (and region-p (region-end)))
2939 (subtree-p
2940 (if (plist-get opt-plist :ignore-subree-p)
2942 (when region-p
2943 (save-excursion
2944 (goto-char rbeg)
2945 (and (org-at-heading-p)
2946 (>= (org-end-of-subtree t t) rend))))))
2947 (opt-plist (if subtree-p
2948 (org-export-add-subtree-options opt-plist rbeg)
2949 opt-plist))
2950 ;; The following two are dynamically scoped into other
2951 ;; routines below.
2952 (org-current-export-dir
2953 (or pub-dir (org-export-directory :html opt-plist)))
2954 (org-current-export-file buffer-file-name)
2955 (level 0) (line "") (origline "") txt todo
2956 (umax nil)
2957 (umax-toc nil)
2958 (filename (if to-buffer nil
2959 (expand-file-name
2960 (concat
2961 (file-name-sans-extension
2962 (or (and subtree-p
2963 (org-entry-get (region-beginning)
2964 "EXPORT_FILE_NAME" t))
2965 (file-name-nondirectory buffer-file-name)))
2966 "." html-extension)
2967 (file-name-as-directory
2968 (or pub-dir (org-export-directory :html opt-plist))))))
2969 (current-dir (if buffer-file-name
2970 (file-name-directory buffer-file-name)
2971 default-directory))
2972 (buffer (if to-buffer
2973 (cond
2974 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2975 (t (get-buffer-create to-buffer)))
2976 (find-file-noselect filename)))
2977 (org-levels-open (make-vector org-level-max nil))
2978 (date (plist-get opt-plist :date))
2979 (author (plist-get opt-plist :author))
2980 (title (or (and subtree-p (org-export-get-title-from-subtree))
2981 (plist-get opt-plist :title)
2982 (and (not
2983 (plist-get opt-plist :skip-before-1st-heading))
2984 (org-export-grab-title-from-buffer))
2985 (and buffer-file-name
2986 (file-name-sans-extension
2987 (file-name-nondirectory buffer-file-name)))
2988 "UNTITLED"))
2989 (html-table-tag (plist-get opt-plist :html-table-tag))
2990 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2991 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2992 (inquote nil)
2993 (infixed nil)
2994 (inverse nil)
2995 (in-local-list nil)
2996 (local-list-type nil)
2997 (local-list-indent nil)
2998 (llt org-plain-list-ordered-item-terminator)
2999 (email (plist-get opt-plist :email))
3000 (language (plist-get opt-plist :language))
3001 (lang-words nil)
3002 (head-count 0) cnt
3003 (start 0)
3004 (coding-system (and (boundp 'buffer-file-coding-system)
3005 buffer-file-coding-system))
3006 (coding-system-for-write (or org-export-html-coding-system
3007 coding-system))
3008 (save-buffer-coding-system (or org-export-html-coding-system
3009 coding-system))
3010 (charset (and coding-system-for-write
3011 (fboundp 'coding-system-get)
3012 (coding-system-get coding-system-for-write
3013 'mime-charset)))
3014 (region
3015 (buffer-substring
3016 (if region-p (region-beginning) (point-min))
3017 (if region-p (region-end) (point-max))))
3018 (lines
3019 (org-split-string
3020 (org-export-preprocess-string
3021 region
3022 :emph-multiline t
3023 :for-html t
3024 :skip-before-1st-heading
3025 (plist-get opt-plist :skip-before-1st-heading)
3026 :drawers (plist-get opt-plist :drawers)
3027 :todo-keywords (plist-get opt-plist :todo-keywords)
3028 :tags (plist-get opt-plist :tags)
3029 :priority (plist-get opt-plist :priority)
3030 :archived-trees
3031 (plist-get opt-plist :archived-trees)
3032 :select-tags (plist-get opt-plist :select-tags)
3033 :exclude-tags (plist-get opt-plist :exclude-tags)
3034 :add-text
3035 (plist-get opt-plist :text)
3036 :LaTeX-fragments
3037 (plist-get opt-plist :LaTeX-fragments))
3038 "[\r\n]"))
3039 table-open type
3040 table-buffer table-orig-buffer
3041 ind item-type starter didclose
3042 rpl path attr desc descp desc1 desc2 link
3043 snumber fnc item-tag
3044 footnotes
3047 (let ((inhibit-read-only t))
3048 (org-unmodified
3049 (remove-text-properties (point-min) (point-max)
3050 '(:org-license-to-kill t))))
3052 (message "Exporting...")
3054 (setq org-min-level (org-get-min-level lines))
3055 (setq org-last-level org-min-level)
3056 (org-init-section-numbers)
3058 (cond
3059 ((and date (string-match "%" date))
3060 (setq date (format-time-string date)))
3061 (date)
3062 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3064 ;; Get the language-dependent settings
3065 (setq lang-words (or (assoc language org-export-language-setup)
3066 (assoc "en" org-export-language-setup)))
3068 ;; Switch to the output buffer
3069 (set-buffer buffer)
3070 (let ((inhibit-read-only t)) (erase-buffer))
3071 (fundamental-mode)
3073 (and (fboundp 'set-buffer-file-coding-system)
3074 (set-buffer-file-coding-system coding-system-for-write))
3076 (let ((case-fold-search nil)
3077 (org-odd-levels-only odd))
3078 ;; create local variables for all options, to make sure all called
3079 ;; functions get the correct information
3080 (mapc (lambda (x)
3081 (set (make-local-variable (nth 2 x))
3082 (plist-get opt-plist (car x))))
3083 org-export-plist-vars)
3084 (setq umax (if arg (prefix-numeric-value arg)
3085 org-export-headline-levels))
3086 (setq umax-toc (if (integerp org-export-with-toc)
3087 (min org-export-with-toc umax)
3088 umax))
3089 (unless body-only
3090 ;; File header
3091 (insert (format
3092 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3093 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3094 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3095 lang=\"%s\" xml:lang=\"%s\">
3096 <head>
3097 <title>%s</title>
3098 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3099 <meta name=\"generator\" content=\"Org-mode\"/>
3100 <meta name=\"generated\" content=\"%s\"/>
3101 <meta name=\"author\" content=\"%s\"/>
3103 </head><body>
3105 language language (org-html-expand title)
3106 (or charset "iso-8859-1") date author style))
3108 (insert (or (plist-get opt-plist :preamble) ""))
3110 (when (plist-get opt-plist :auto-preamble)
3111 (if title (insert (format org-export-html-title-format
3112 (org-html-expand title))))))
3114 (if (and org-export-with-toc (not body-only))
3115 (progn
3116 (push (format "<h%d>%s</h%d>\n"
3117 org-export-html-toplevel-hlevel
3118 (nth 3 lang-words)
3119 org-export-html-toplevel-hlevel)
3120 thetoc)
3121 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3122 (push "<ul>\n<li>" thetoc)
3123 (setq lines
3124 (mapcar '(lambda (line)
3125 (if (string-match org-todo-line-regexp line)
3126 ;; This is a headline
3127 (progn
3128 (setq have-headings t)
3129 (setq level (- (match-end 1) (match-beginning 1))
3130 level (org-tr-level level)
3131 txt (save-match-data
3132 (org-html-expand
3133 (org-export-cleanup-toc-line
3134 (match-string 3 line))))
3135 todo
3136 (or (and org-export-mark-todo-in-toc
3137 (match-beginning 2)
3138 (not (member (match-string 2 line)
3139 org-done-keywords)))
3140 ; TODO, not DONE
3141 (and org-export-mark-todo-in-toc
3142 (= level umax-toc)
3143 (org-search-todo-below
3144 line lines level))))
3145 (if (string-match
3146 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3147 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3148 (if (string-match quote-re0 txt)
3149 (setq txt (replace-match "" t t txt)))
3150 (setq snumber (org-section-number level))
3151 (if org-export-with-section-numbers
3152 (setq txt (concat snumber " " txt)))
3153 (if (<= level (max umax umax-toc))
3154 (setq head-count (+ head-count 1)))
3155 (if (<= level umax-toc)
3156 (progn
3157 (if (> level org-last-level)
3158 (progn
3159 (setq cnt (- level org-last-level))
3160 (while (>= (setq cnt (1- cnt)) 0)
3161 (push "\n<ul>\n<li>" thetoc))
3162 (push "\n" thetoc)))
3163 (if (< level org-last-level)
3164 (progn
3165 (setq cnt (- org-last-level level))
3166 (while (>= (setq cnt (1- cnt)) 0)
3167 (push "</li>\n</ul>" thetoc))
3168 (push "\n" thetoc)))
3169 ;; Check for targets
3170 (while (string-match org-any-target-regexp line)
3171 (setq line (replace-match
3172 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3173 t t line)))
3174 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3175 (setq txt (replace-match "" t t txt)))
3176 (push
3177 (format
3178 (if todo
3179 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3180 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3181 snumber txt) thetoc)
3183 (setq org-last-level level))
3185 line)
3186 lines))
3187 (while (> org-last-level (1- org-min-level))
3188 (setq org-last-level (1- org-last-level))
3189 (push "</li>\n</ul>\n" thetoc))
3190 (push "</div>\n" thetoc)
3191 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3193 (setq head-count 0)
3194 (org-init-section-numbers)
3196 (org-open-par)
3198 (while (setq line (pop lines) origline line)
3199 (catch 'nextline
3201 ;; end of quote section?
3202 (when (and inquote (string-match "^\\*+ " line))
3203 (insert "</pre>\n")
3204 (setq inquote nil))
3205 ;; inside a quote section?
3206 (when inquote
3207 (insert (org-html-protect line) "\n")
3208 (throw 'nextline nil))
3210 ;; Fixed-width, verbatim lines (examples)
3211 (when (and org-export-with-fixed-width
3212 (string-match "^[ \t]*:\\(.*\\)" line))
3213 (when (not infixed)
3214 (setq infixed t)
3215 (org-close-par-maybe)
3216 (insert "<pre class=\"example\">\n"))
3217 (insert (org-html-protect (match-string 1 line)) "\n")
3218 (when (or (not lines)
3219 (not (string-match "^[ \t]*\\(:.*\\)"
3220 (car lines))))
3221 (setq infixed nil)
3222 (insert "</pre>\n"))
3223 (throw 'nextline nil))
3225 ;; Protected HTML
3226 (when (get-text-property 0 'org-protected line)
3227 (let (par)
3228 (when (re-search-backward
3229 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3230 (setq par (match-string 1))
3231 (replace-match "\\2\n"))
3232 (insert line "\n")
3233 (while (and lines
3234 (not (string-match "^[ \t]*:" (car lines)))
3235 (or (= (length (car lines)) 0)
3236 (get-text-property 0 'org-protected (car lines))))
3237 (insert (pop lines) "\n"))
3238 (and par (insert "<p>\n")))
3239 (throw 'nextline nil))
3241 ;; Horizontal line
3242 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3243 (if org-par-open
3244 (insert "\n</p>\n<hr/>\n<p>\n")
3245 (insert "\n<hr/>\n"))
3246 (throw 'nextline nil))
3248 ;; Blockquotes and verse
3249 (when (equal "ORG-BLOCKQUOTE-START" line)
3250 (org-close-par-maybe)
3251 (insert "<blockquote>\n<p>\n")
3252 (throw 'nextline nil))
3253 (when (equal "ORG-BLOCKQUOTE-END" line)
3254 (insert "</p>\n</blockquote>\n")
3255 (throw 'nextline nil))
3256 (when (equal "ORG-VERSE-START" line)
3257 (org-close-par-maybe)
3258 (insert "\n<p class=\"verse\">\n")
3259 (setq inverse t)
3260 (throw 'nextline nil))
3261 (when (equal "ORG-VERSE-END" line)
3262 (insert "</p>\n")
3263 (setq inverse nil)
3264 (throw 'nextline nil))
3265 (when inverse
3266 (let ((i (org-get-string-indentation line)))
3267 (if (> i 0)
3268 (setq line (concat (mapconcat 'identity
3269 (make-list (* 2 i) "\\nbsp") "")
3270 " " (org-trim line))))
3271 (setq line (concat line "\\\\"))))
3273 ;; make targets to anchors
3274 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3275 (cond
3276 ((match-end 2)
3277 (setq line (replace-match
3278 (format
3279 "@<a name=\"%s\" id=\"%s\">@</a>"
3280 (org-solidify-link-text (match-string 1 line))
3281 (org-solidify-link-text (match-string 1 line)))
3282 t t line)))
3283 ((and org-export-with-toc (equal (string-to-char line) ?*))
3284 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3285 (setq line (replace-match
3286 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3287 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3288 t t line)))
3290 (setq line (replace-match
3291 (concat "@<a name=\""
3292 (org-solidify-link-text (match-string 1 line))
3293 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3294 t t line)))))
3296 (setq line (org-html-handle-time-stamps line))
3298 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3299 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3300 ;; Also handle sub_superscripts and checkboxes
3301 (or (string-match org-table-hline-regexp line)
3302 (setq line (org-html-expand line)))
3304 ;; Format the links
3305 (setq start 0)
3306 (while (string-match org-bracket-link-analytic-regexp line start)
3307 (setq start (match-beginning 0))
3308 (setq path (save-match-data (org-link-unescape
3309 (match-string 3 line))))
3310 (setq type (cond
3311 ((match-end 2) (match-string 2 line))
3312 ((save-match-data
3313 (or (file-name-absolute-p path)
3314 (string-match "^\\.\\.?/" path)))
3315 "file")
3316 (t "internal")))
3317 (setq path (org-extract-attributes (org-link-unescape path)))
3318 (setq attr (get-text-property 0 'org-attributes path))
3319 (setq desc1 (if (match-end 5) (match-string 5 line))
3320 desc2 (if (match-end 2) (concat type ":" path) path)
3321 descp (and desc1 (not (equal desc1 desc2)))
3322 desc (or desc1 desc2))
3323 ;; Make an image out of the description if that is so wanted
3324 (when (and descp (org-file-image-p desc))
3325 (save-match-data
3326 (if (string-match "^file:" desc)
3327 (setq desc (substring desc (match-end 0)))))
3328 (setq desc (org-add-props
3329 (concat "<img src=\"" desc "\"/>")
3330 '(org-protected t))))
3331 ;; FIXME: do we need to unescape here somewhere?
3332 (cond
3333 ((equal type "internal")
3334 (setq rpl
3335 (concat
3336 "<a href=\"#"
3337 (org-solidify-link-text
3338 (save-match-data (org-link-unescape path)) nil)
3339 "\"" attr ">"
3340 (org-export-html-format-desc desc)
3341 "</a>")))
3342 ((member type '("http" "https"))
3343 ;; standard URL, just check if we need to inline an image
3344 (if (and (or (eq t org-export-html-inline-images)
3345 (and org-export-html-inline-images (not descp)))
3346 (org-file-image-p path))
3347 (setq rpl (org-export-html-format-image
3348 (concat type ":" path)))
3349 (setq link (concat type ":" path))
3350 (setq rpl (concat "<a href=\""
3351 (org-export-html-format-href link)
3352 "\"" attr ">"
3353 (org-export-html-format-desc desc)
3354 "</a>"))))
3355 ((member type '("ftp" "mailto" "news"))
3356 ;; standard URL
3357 (setq link (concat type ":" path))
3358 (setq rpl (concat "<a href=\""
3359 (org-export-html-format-href link)
3360 "\"" attr ">"
3361 (org-export-html-format-desc desc)
3362 "</a>")))
3364 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3365 ;; The link protocol has a function for format the link
3366 (setq rpl
3367 (save-match-data
3368 (funcall fnc (org-link-unescape path) desc1 'html))))
3370 ((string= type "file")
3371 ;; FILE link
3372 (let* ((filename path)
3373 (abs-p (file-name-absolute-p filename))
3374 thefile file-is-image-p search)
3375 (save-match-data
3376 (if (string-match "::\\(.*\\)" filename)
3377 (setq search (match-string 1 filename)
3378 filename (replace-match "" t nil filename)))
3379 (setq valid
3380 (if (functionp link-validate)
3381 (funcall link-validate filename current-dir)
3383 (setq file-is-image-p (org-file-image-p filename))
3384 (setq thefile (if abs-p (expand-file-name filename) filename))
3385 (when (and org-export-html-link-org-files-as-html
3386 (string-match "\\.org$" thefile))
3387 (setq thefile (concat (substring thefile 0
3388 (match-beginning 0))
3389 "." html-extension))
3390 (if (and search
3391 ;; make sure this is can be used as target search
3392 (not (string-match "^[0-9]*$" search))
3393 (not (string-match "^\\*" search))
3394 (not (string-match "^/.*/$" search)))
3395 (setq thefile (concat thefile "#"
3396 (org-solidify-link-text
3397 (org-link-unescape search)))))
3398 (when (string-match "^file:" desc)
3399 (setq desc (replace-match "" t t desc))
3400 (if (string-match "\\.org$" desc)
3401 (setq desc (replace-match "" t t desc))))))
3402 (setq rpl (if (and file-is-image-p
3403 (or (eq t org-export-html-inline-images)
3404 (and org-export-html-inline-images
3405 (not descp))))
3406 (org-export-html-format-image thefile)
3407 (concat "<a href=\"" thefile "\"" attr ">"
3408 (org-export-html-format-desc desc)
3409 "</a>")))
3410 (if (not valid) (setq rpl desc))))
3413 ;; just publish the path, as default
3414 (setq rpl (concat "<i>&lt;" type ":"
3415 (save-match-data (org-link-unescape path))
3416 "&gt;</i>"))))
3417 (setq line (replace-match rpl t t line)
3418 start (+ start (length rpl))))
3420 ;; TODO items
3421 (if (and (string-match org-todo-line-regexp line)
3422 (match-beginning 2))
3424 (setq line
3425 (concat (substring line 0 (match-beginning 2))
3426 "<span class=\""
3427 (if (member (match-string 2 line)
3428 org-done-keywords)
3429 "done" "todo")
3430 "\">" (match-string 2 line)
3431 "</span>" (substring line (match-end 2)))))
3433 ;; Does this contain a reference to a footnote?
3434 (when org-export-with-footnotes
3435 (setq start 0)
3436 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3437 (if (get-text-property (match-beginning 2) 'org-protected line)
3438 (setq start (match-end 2))
3439 (let ((n (match-string 2 line)))
3440 (setq line
3441 (replace-match
3442 (format
3443 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3444 (match-string 1 line) n n n)
3445 t t line))))))
3447 (cond
3448 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3449 ;; This is a headline
3450 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3451 txt (match-string 2 line))
3452 (if (string-match quote-re0 txt)
3453 (setq txt (replace-match "" t t txt)))
3454 (if (<= level (max umax umax-toc))
3455 (setq head-count (+ head-count 1)))
3456 (when in-local-list
3457 ;; Close any local lists before inserting a new header line
3458 (while local-list-type
3459 (org-close-li (car local-list-type))
3460 (insert (format "</%sl>\n" (car local-list-type)))
3461 (pop local-list-type))
3462 (setq local-list-indent nil
3463 in-local-list nil))
3464 (setq first-heading-pos (or first-heading-pos (point)))
3465 (org-html-level-start level txt umax
3466 (and org-export-with-toc (<= level umax))
3467 head-count)
3468 ;; QUOTES
3469 (when (string-match quote-re line)
3470 (org-close-par-maybe)
3471 (insert "<pre>")
3472 (setq inquote t)))
3474 ((and org-export-with-tables
3475 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3476 (if (not table-open)
3477 ;; New table starts
3478 (setq table-open t table-buffer nil table-orig-buffer nil))
3479 ;; Accumulate lines
3480 (setq table-buffer (cons line table-buffer)
3481 table-orig-buffer (cons origline table-orig-buffer))
3482 (when (or (not lines)
3483 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3484 (car lines))))
3485 (setq table-open nil
3486 table-buffer (nreverse table-buffer)
3487 table-orig-buffer (nreverse table-orig-buffer))
3488 (org-close-par-maybe)
3489 (insert (org-format-table-html table-buffer table-orig-buffer))))
3491 ;; Normal lines
3492 (when (string-match
3493 (cond
3494 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3495 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3496 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3497 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3498 line)
3499 (setq ind (org-get-string-indentation line)
3500 item-type (if (match-beginning 4) "o" "u")
3501 starter (if (match-beginning 2)
3502 (substring (match-string 2 line) 0 -1))
3503 line (substring line (match-beginning 5))
3504 item-tag nil)
3505 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3506 (setq item-type "d"
3507 item-tag (match-string 1 line)
3508 line (substring line (match-end 0))))
3509 (when (and (not (equal item-type "d"))
3510 (not (string-match "[^ \t]" line)))
3511 ;; empty line. Pretend indentation is large.
3512 (setq ind (if org-empty-line-terminates-plain-lists
3514 (1+ (or (car local-list-indent) 1)))))
3515 (setq didclose nil)
3516 (while (and in-local-list
3517 (or (and (= ind (car local-list-indent))
3518 (not starter))
3519 (< ind (car local-list-indent))))
3520 (setq didclose t)
3521 (org-close-li (car local-list-type))
3522 (insert (format "</%sl>\n" (car local-list-type)))
3523 (pop local-list-type) (pop local-list-indent)
3524 (setq in-local-list local-list-indent))
3525 (cond
3526 ((and starter
3527 (or (not in-local-list)
3528 (> ind (car local-list-indent))))
3529 ;; Start new (level of) list
3530 (org-close-par-maybe)
3531 (insert (cond
3532 ((equal item-type "u") "<ul>\n<li>\n")
3533 ((equal item-type "o") "<ol>\n<li>\n")
3534 ((equal item-type "d")
3535 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3536 (push item-type local-list-type)
3537 (push ind local-list-indent)
3538 (setq in-local-list t))
3539 (starter
3540 ;; continue current list
3541 (org-close-li (car local-list-type))
3542 (insert (cond
3543 ((equal (car local-list-type) "d")
3544 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3545 (t "<li>\n"))))
3546 (didclose
3547 ;; we did close a list, normal text follows: need <p>
3548 (org-open-par)))
3549 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3550 (setq line
3551 (replace-match
3552 (if (equal (match-string 1 line) "X")
3553 "<b>[X]</b>"
3554 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3555 t t line))))
3557 ;; Empty lines start a new paragraph. If hand-formatted lists
3558 ;; are not fully interpreted, lines starting with "-", "+", "*"
3559 ;; also start a new paragraph.
3560 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3562 ;; Is this the start of a footnote?
3563 (when org-export-with-footnotes
3564 (when (and (boundp 'footnote-section-tag-regexp)
3565 (string-match (concat "^" footnote-section-tag-regexp)
3566 line))
3567 ;; ignore this line
3568 (throw 'nextline nil))
3569 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3570 (org-close-par-maybe)
3571 (let ((n (match-string 1 line)))
3572 (setq org-par-open t
3573 line (replace-match
3574 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
3576 ;; Check if the line break needs to be conserved
3577 (cond
3578 ((string-match "\\\\\\\\[ \t]*$" line)
3579 (setq line (replace-match "<br/>" t t line)))
3580 (org-export-preserve-breaks
3581 (setq line (concat line "<br/>"))))
3583 (insert line "\n")))))
3585 ;; Properly close all local lists and other lists
3586 (when inquote
3587 (insert "</pre>\n")
3588 (org-open-par))
3589 (when in-local-list
3590 ;; Close any local lists before inserting a new header line
3591 (while local-list-type
3592 (org-close-li (car local-list-type))
3593 (insert (format "</%sl>\n" (car local-list-type)))
3594 (pop local-list-type))
3595 (setq local-list-indent nil
3596 in-local-list nil))
3597 (org-html-level-start 1 nil umax
3598 (and org-export-with-toc (<= level umax))
3599 head-count)
3600 ;; the </div> to close the last text-... div.
3601 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
3603 (save-excursion
3604 (goto-char (point-min))
3605 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
3606 (push (match-string 0) footnotes)
3607 (replace-match "" t t)))
3608 (when footnotes
3609 (insert (format org-export-html-footnotes-section
3610 (or (nth 4 lang-words) "Footnotes")
3611 (mapconcat 'identity (nreverse footnotes) "\n"))
3612 "\n"))
3613 (unless body-only
3614 (when (plist-get opt-plist :auto-postamble)
3615 (insert "<div id=\"postamble\">")
3616 (when (and org-export-author-info author)
3617 (insert "<p class=\"author\"> "
3618 (nth 1 lang-words) ": " author "\n")
3619 (when email
3620 (if (listp (split-string email ",+ *"))
3621 (mapc (lambda(e)
3622 (insert "<a href=\"mailto:" e "\">&lt;"
3623 e "&gt;</a>\n"))
3624 (split-string email ",+ *"))
3625 (insert "<a href=\"mailto:" email "\">&lt;"
3626 email "&gt;</a>\n")))
3627 (insert "</p>\n"))
3628 (when (and date org-export-time-stamp-file)
3629 (insert "<p class=\"date\"> "
3630 (nth 2 lang-words) ": "
3631 date "</p>\n"))
3632 (when org-export-creator-info
3633 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3634 org-version emacs-major-version)))
3635 (insert "</div>"))
3637 (if org-export-html-with-timestamp
3638 (insert org-export-html-html-helper-timestamp))
3639 (insert (or (plist-get opt-plist :postamble) ""))
3640 (insert "</body>\n</html>\n"))
3642 (unless (plist-get opt-plist :buffer-will-be-killed)
3643 (normal-mode)
3644 (if (eq major-mode default-major-mode) (html-mode)))
3646 ;; insert the table of contents
3647 (goto-char (point-min))
3648 (when thetoc
3649 (if (or (re-search-forward
3650 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3651 (re-search-forward
3652 "\\[TABLE-OF-CONTENTS\\]" nil t))
3653 (progn
3654 (goto-char (match-beginning 0))
3655 (replace-match ""))
3656 (goto-char first-heading-pos)
3657 (when (looking-at "\\s-*</p>")
3658 (goto-char (match-end 0))
3659 (insert "\n")))
3660 (insert "<div id=\"table-of-contents\">\n")
3661 (mapc 'insert thetoc)
3662 (insert "</div>\n"))
3663 ;; remove empty paragraphs and lists
3664 (goto-char (point-min))
3665 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3666 (replace-match ""))
3667 (goto-char (point-min))
3668 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3669 (replace-match ""))
3670 (goto-char (point-min))
3671 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3672 (replace-match ""))
3673 ;; Convert whitespace place holders
3674 (goto-char (point-min))
3675 (let (beg end n)
3676 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3677 (setq n (get-text-property beg 'org-whitespace)
3678 end (next-single-property-change beg 'org-whitespace))
3679 (goto-char beg)
3680 (delete-region beg end)
3681 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3682 (make-string n ?x)))))
3683 (or to-buffer (save-buffer))
3684 (goto-char (point-min))
3685 (message "Exporting... done")
3686 (if (eq to-buffer 'string)
3687 (prog1 (buffer-substring (point-min) (point-max))
3688 (kill-buffer (current-buffer)))
3689 (current-buffer)))))
3691 (defun org-export-html-format-href (s)
3692 "Make sure the S is valid as a href reference in an XHTML document."
3693 (save-match-data
3694 (let ((start 0))
3695 (while (string-match "&" s start)
3696 (setq start (+ (match-beginning 0) 3)
3697 s (replace-match "&amp;" t t s)))))
3700 (defun org-export-html-format-desc (s)
3701 "Make sure the S is valid as a description in a link."
3702 (if (and s (not (get-text-property 1 'org-protected s)))
3703 (save-match-data
3704 (org-html-do-expand s))
3707 (defun org-export-html-format-image (src)
3708 "Create image tag with source and attributes."
3709 (save-match-data
3710 (let* ((caption (org-find-text-property-in-string 'org-caption src))
3711 (attr (org-find-text-property-in-string 'org-attributes src))
3712 (label (org-find-text-property-in-string 'org-label src)))
3713 (format "<div %sclass=\"figure\">
3714 <p><img src=\"%s\"%s>
3716 </div>"
3717 (if label (format "id=\"%s\" " label) "")
3719 (if (string-match "\\<alt=" (or attr ""))
3720 (concat " " attr )
3721 (concat " " attr " alt=\"" src "\""))
3722 (if caption (concat "<p>" caption))))))
3724 (defvar org-table-colgroup-info nil)
3725 (defun org-format-table-ascii (lines)
3726 "Format a table for ascii export."
3727 (if (stringp lines)
3728 (setq lines (org-split-string lines "\n")))
3729 (if (not (string-match "^[ \t]*|" (car lines)))
3730 ;; Table made by table.el - test for spanning
3731 lines
3733 ;; A normal org table
3734 ;; Get rid of hlines at beginning and end
3735 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3736 (setq lines (nreverse lines))
3737 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3738 (setq lines (nreverse lines))
3739 (when org-export-table-remove-special-lines
3740 ;; Check if the table has a marking column. If yes remove the
3741 ;; column and the special lines
3742 (setq lines (org-table-clean-before-export lines)))
3743 ;; Get rid of the vertical lines except for grouping
3744 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3745 rtn line vl1 start)
3746 (while (setq line (pop lines))
3747 (if (string-match org-table-hline-regexp line)
3748 (and (string-match "|\\(.*\\)|" line)
3749 (setq line (replace-match " \\1" t nil line)))
3750 (setq start 0 vl1 vl)
3751 (while (string-match "|" line start)
3752 (setq start (match-end 0))
3753 (or (pop vl1) (setq line (replace-match " " t t line)))))
3754 (push line rtn))
3755 (nreverse rtn))))
3757 (defun org-colgroup-info-to-vline-list (info)
3758 (let (vl new last)
3759 (while info
3760 (setq last new new (pop info))
3761 (if (or (memq last '(:end :startend))
3762 (memq new '(:start :startend)))
3763 (push t vl)
3764 (push nil vl)))
3765 (setq vl (nreverse vl))
3766 (and vl (setcar vl nil))
3767 vl))
3769 (defvar org-table-number-regexp) ; defined in org-table.el
3770 (defun org-format-table-html (lines olines)
3771 "Find out which HTML converter to use and return the HTML code."
3772 (if (stringp lines)
3773 (setq lines (org-split-string lines "\n")))
3774 (if (string-match "^[ \t]*|" (car lines))
3775 ;; A normal org table
3776 (org-format-org-table-html lines)
3777 ;; Table made by table.el - test for spanning
3778 (let* ((hlines (delq nil (mapcar
3779 (lambda (x)
3780 (if (string-match "^[ \t]*\\+-" x) x
3781 nil))
3782 lines)))
3783 (first (car hlines))
3784 (ll (and (string-match "\\S-+" first)
3785 (match-string 0 first)))
3786 (re (concat "^[ \t]*" (regexp-quote ll)))
3787 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3788 hlines))))
3789 (if (and (not spanning)
3790 (not org-export-prefer-native-exporter-for-tables))
3791 ;; We can use my own converter with HTML conversions
3792 (org-format-table-table-html lines)
3793 ;; Need to use the code generator in table.el, with the original text.
3794 (org-format-table-table-html-using-table-generate-source olines)))))
3796 (defvar org-table-number-fraction) ; defined in org-table.el
3797 (defun org-format-org-table-html (lines &optional splice)
3798 "Format a table into HTML."
3799 (require 'org-table)
3800 ;; Get rid of hlines at beginning and end
3801 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3802 (setq lines (nreverse lines))
3803 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3804 (setq lines (nreverse lines))
3805 (when org-export-table-remove-special-lines
3806 ;; Check if the table has a marking column. If yes remove the
3807 ;; column and the special lines
3808 (setq lines (org-table-clean-before-export lines)))
3810 (let ((caption (or (get-text-property 0 'org-caption (car lines))
3811 (get-text-property (or (next-single-property-change
3812 0 'org-caption (car lines))
3814 'org-caption (car lines))))
3815 (head (and org-export-highlight-first-table-line
3816 (delq nil (mapcar
3817 (lambda (x) (string-match "^[ \t]*|-" x))
3818 (cdr lines)))))
3820 (nlines 0) fnum i
3821 tbopen line fields html gr colgropen)
3822 (if splice (setq head nil))
3823 (unless splice (push (if head "<thead>" "<tbody>") html))
3824 (setq tbopen t)
3825 (while (setq line (pop lines))
3826 (catch 'next-line
3827 (if (string-match "^[ \t]*|-" line)
3828 (progn
3829 (unless splice
3830 (push (if head "</thead>" "</tbody>") html)
3831 (if lines (push "<tbody>" html) (setq tbopen nil)))
3832 (setq head nil) ;; head ends here, first time around
3833 ;; ignore this line
3834 (throw 'next-line t)))
3835 ;; Break the line into fields
3836 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3837 (unless fnum (setq fnum (make-vector (length fields) 0)))
3838 (setq nlines (1+ nlines) i -1)
3839 (push (concat "<tr>"
3840 (mapconcat
3841 (lambda (x)
3842 (setq i (1+ i))
3843 (if (and (< i nlines)
3844 (string-match org-table-number-regexp x))
3845 (incf (aref fnum i)))
3846 (if head
3847 (concat (car org-export-table-header-tags) x
3848 (cdr org-export-table-header-tags))
3849 (concat (car org-export-table-data-tags) x
3850 (cdr org-export-table-data-tags))))
3851 fields "")
3852 "</tr>")
3853 html)))
3854 (unless splice (if tbopen (push "</tbody>" html)))
3855 (unless splice (push "</table>\n" html))
3856 (setq html (nreverse html))
3857 (unless splice
3858 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3859 (push (mapconcat
3860 (lambda (x)
3861 (setq gr (pop org-table-colgroup-info))
3862 (format "%s<col align=\"%s\"></col>%s"
3863 (if (memq gr '(:start :startend))
3864 (prog1
3865 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3866 (setq colgropen t))
3868 (if (> (/ (float x) nlines) org-table-number-fraction)
3869 "right" "left")
3870 (if (memq gr '(:end :startend))
3871 (progn (setq colgropen nil) "</colgroup>")
3872 "")))
3873 fnum "")
3874 html)
3875 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3876 (if caption (push (format "<caption>%s</caption>" caption) html))
3877 (push html-table-tag html))
3878 (concat (mapconcat 'identity html "\n") "\n")))
3880 (defun org-table-clean-before-export (lines)
3881 "Check if the table has a marking column.
3882 If yes remove the column and the special lines."
3883 (setq org-table-colgroup-info nil)
3884 (if (memq nil
3885 (mapcar
3886 (lambda (x) (or (string-match "^[ \t]*|-" x)
3887 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3888 lines))
3889 (progn
3890 (setq org-table-clean-did-remove-column nil)
3891 (delq nil
3892 (mapcar
3893 (lambda (x)
3894 (cond
3895 ((string-match "^[ \t]*| */ *|" x)
3896 (setq org-table-colgroup-info
3897 (mapcar (lambda (x)
3898 (cond ((member x '("<" "&lt;")) :start)
3899 ((member x '(">" "&gt;")) :end)
3900 ((member x '("<>" "&lt;&gt;")) :startend)
3901 (t nil)))
3902 (org-split-string x "[ \t]*|[ \t]*")))
3903 nil)
3904 (t x)))
3905 lines)))
3906 (setq org-table-clean-did-remove-column t)
3907 (delq nil
3908 (mapcar
3909 (lambda (x)
3910 (cond
3911 ((string-match "^[ \t]*| */ *|" x)
3912 (setq org-table-colgroup-info
3913 (mapcar (lambda (x)
3914 (cond ((member x '("<" "&lt;")) :start)
3915 ((member x '(">" "&gt;")) :end)
3916 ((member x '("<>" "&lt;&gt;")) :startend)
3917 (t nil)))
3918 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3919 nil)
3920 ((string-match "^[ \t]*| *[!_^/] *|" x)
3921 nil) ; ignore this line
3922 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3923 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3924 ;; remove the first column
3925 (replace-match "\\1|" t nil x))))
3926 lines))))
3928 (defun org-format-table-table-html (lines)
3929 "Format a table generated by table.el into HTML.
3930 This conversion does *not* use `table-generate-source' from table.el.
3931 This has the advantage that Org-mode's HTML conversions can be used.
3932 But it has the disadvantage, that no cell- or row-spanning is allowed."
3933 (let (line field-buffer
3934 (head org-export-highlight-first-table-line)
3935 fields html empty)
3936 (setq html (concat html-table-tag "\n"))
3937 (while (setq line (pop lines))
3938 (setq empty "&nbsp;")
3939 (catch 'next-line
3940 (if (string-match "^[ \t]*\\+-" line)
3941 (progn
3942 (if field-buffer
3943 (progn
3944 (setq
3945 html
3946 (concat
3947 html
3948 "<tr>"
3949 (mapconcat
3950 (lambda (x)
3951 (if (equal x "") (setq x empty))
3952 (if head
3953 (concat (car org-export-table-header-tags) x
3954 (cdr org-export-table-header-tags))
3955 (concat (car org-export-table-data-tags) x
3956 (cdr org-export-table-data-tags))))
3957 field-buffer "\n")
3958 "</tr>\n"))
3959 (setq head nil)
3960 (setq field-buffer nil)))
3961 ;; Ignore this line
3962 (throw 'next-line t)))
3963 ;; Break the line into fields and store the fields
3964 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3965 (if field-buffer
3966 (setq field-buffer (mapcar
3967 (lambda (x)
3968 (concat x "<br/>" (pop fields)))
3969 field-buffer))
3970 (setq field-buffer fields))))
3971 (setq html (concat html "</table>\n"))
3972 html))
3974 (defun org-format-table-table-html-using-table-generate-source (lines)
3975 "Format a table into html, using `table-generate-source' from table.el.
3976 This has the advantage that cell- or row-spanning is allowed.
3977 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3978 (require 'table)
3979 (with-current-buffer (get-buffer-create " org-tmp1 ")
3980 (erase-buffer)
3981 (insert (mapconcat 'identity lines "\n"))
3982 (goto-char (point-min))
3983 (if (not (re-search-forward "|[^+]" nil t))
3984 (error "Error processing table"))
3985 (table-recognize-table)
3986 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3987 (table-generate-source 'html " org-tmp2 ")
3988 (set-buffer " org-tmp2 ")
3989 (buffer-substring (point-min) (point-max))))
3991 (defun org-export-splice-style (style extra)
3992 "Splice EXTRA into STYLE, just before \"</style>\"."
3993 (if (and (stringp extra)
3994 (string-match "\\S-" extra)
3995 (string-match "</style>" style))
3996 (concat (substring style 0 (match-beginning 0))
3997 "\n" extra "\n"
3998 (substring style (match-beginning 0)))
3999 style))
4001 (defun org-html-handle-time-stamps (s)
4002 "Format time stamps in string S, or remove them."
4003 (catch 'exit
4004 (let (r b)
4005 (while (string-match org-maybe-keyword-time-regexp s)
4006 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
4007 ;; never export CLOCK
4008 (throw 'exit ""))
4009 (or b (setq b (substring s 0 (match-beginning 0))))
4010 (if (not org-export-with-timestamps)
4011 (setq r (concat r (substring s 0 (match-beginning 0)))
4012 s (substring s (match-end 0)))
4013 (setq r (concat
4014 r (substring s 0 (match-beginning 0))
4015 (if (match-end 1)
4016 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4017 (match-string 1 s)))
4018 (format " @<span class=\"timestamp\">%s@</span>"
4019 (substring
4020 (org-translate-time (match-string 3 s)) 1 -1)))
4021 s (substring s (match-end 0)))))
4022 ;; Line break if line started and ended with time stamp stuff
4023 (if (not r)
4025 (setq r (concat r s))
4026 (unless (string-match "\\S-" (concat b s))
4027 (setq r (concat r "@<br/>")))
4028 r))))
4030 (defun org-export-htmlize-region-for-paste (beg end)
4031 "Convert the region to HTML, using htmlize.el.
4032 This is much like `htmlize-region-for-paste', only that it uses
4033 the settings define in the org-... variables."
4034 (let* ((htmlize-output-type org-export-htmlize-output-type)
4035 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
4036 (htmlbuf (htmlize-region beg end)))
4037 (unwind-protect
4038 (with-current-buffer htmlbuf
4039 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
4040 (plist-get htmlize-buffer-places 'content-end)))
4041 (kill-buffer htmlbuf))))
4043 ;;;###autoload
4044 (defun org-export-htmlize-generate-css ()
4045 "Create the CSS for all font definitions in the current Emacs session.
4046 Use this to create face definitions in your CSS style file that can then
4047 be used by code snippets transformed by htmlize.
4048 This command just produces a buffer that contains class definitions for all
4049 faces used in the current Emacs session. You can copy and paste the ones you
4050 need into your CSS file.
4052 If you then set `org-export-htmlize-output-type' to `css', calls to
4053 the function `org-export-htmlize-region-for-paste' will produce code
4054 that uses these same face definitions."
4055 (interactive)
4056 (require 'htmlize)
4057 (and (get-buffer "*html*") (kill-buffer "*html*"))
4058 (with-temp-buffer
4059 (let ((fl (face-list))
4060 (htmlize-css-name-prefix "org-")
4061 (htmlize-output-type 'css)
4062 f i)
4063 (while (setq f (pop fl)
4064 i (and f (face-attribute f :inherit)))
4065 (when (and (symbolp f) (or (not i) (not (listp i))))
4066 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4067 (htmlize-region (point-min) (point-max))))
4068 (switch-to-buffer "*html*")
4069 (goto-char (point-min))
4070 (if (re-search-forward "<style" nil t)
4071 (delete-region (point-min) (match-beginning 0)))
4072 (if (re-search-forward "</style>" nil t)
4073 (delete-region (1+ (match-end 0)) (point-max)))
4074 (beginning-of-line 1)
4075 (if (looking-at " +") (replace-match ""))
4076 (goto-char (point-min)))
4078 (defun org-html-protect (s)
4079 ;; convert & to &amp;, < to &lt; and > to &gt;
4080 (let ((start 0))
4081 (while (string-match "&" s start)
4082 (setq s (replace-match "&amp;" t t s)
4083 start (1+ (match-beginning 0))))
4084 (while (string-match "<" s)
4085 (setq s (replace-match "&lt;" t t s)))
4086 (while (string-match ">" s)
4087 (setq s (replace-match "&gt;" t t s)))
4088 ; (while (string-match "\"" s)
4089 ; (setq s (replace-match "&quot;" t t s)))
4093 (defun org-export-cleanup-toc-line (s)
4094 "Remove tags and time staps from lines going into the toc."
4095 (when (memq org-export-with-tags '(not-in-toc nil))
4096 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4097 (setq s (replace-match "" t t s))))
4098 (when org-export-remove-timestamps-from-toc
4099 (while (string-match org-maybe-keyword-time-regexp s)
4100 (setq s (replace-match "" t t s))))
4101 (while (string-match org-bracket-link-regexp s)
4102 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4103 t t s)))
4106 (defun org-html-expand (string)
4107 "Prepare STRING for HTML export. Applies all active conversions.
4108 If there are links in the string, don't modify these."
4109 (let* ((re (concat org-bracket-link-regexp "\\|"
4110 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4111 m s l res)
4112 (while (setq m (string-match re string))
4113 (setq s (substring string 0 m)
4114 l (match-string 0 string)
4115 string (substring string (match-end 0)))
4116 (push (org-html-do-expand s) res)
4117 (push l res))
4118 (push (org-html-do-expand string) res)
4119 (apply 'concat (nreverse res))))
4121 (defun org-html-do-expand (s)
4122 "Apply all active conversions to translate special ASCII to HTML."
4123 (setq s (org-html-protect s))
4124 (if org-export-html-expand
4125 (let ((start 0))
4126 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
4127 (setq s (replace-match "<\\1>" t nil s)))))
4128 (if org-export-with-emphasize
4129 (setq s (org-export-html-convert-emphasize s)))
4130 (if org-export-with-special-strings
4131 (setq s (org-export-html-convert-special-strings s)))
4132 (if org-export-with-sub-superscripts
4133 (setq s (org-export-html-convert-sub-super s)))
4134 (if org-export-with-TeX-macros
4135 (let ((start 0) wd ass)
4136 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4137 s start))
4138 (if (get-text-property (match-beginning 0) 'org-protected s)
4139 (setq start (match-end 0))
4140 (setq wd (match-string 1 s))
4141 (if (setq ass (assoc wd org-html-entities))
4142 (setq s (replace-match (or (cdr ass)
4143 (concat "&" (car ass) ";"))
4144 t t s))
4145 (setq start (+ start (length wd))))))))
4148 (defun org-create-multibrace-regexp (left right n)
4149 "Create a regular expression which will match a balanced sexp.
4150 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4151 as single character strings.
4152 The regexp returned will match the entire expression including the
4153 delimiters. It will also define a single group which contains the
4154 match except for the outermost delimiters. The maximum depth of
4155 stacked delimiters is N. Escaping delimiters is not possible."
4156 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
4157 (or "\\|")
4158 (re nothing)
4159 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4160 (while (> n 1)
4161 (setq n (1- n)
4162 re (concat re or next)
4163 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4164 (concat left "\\(" re "\\)" right)))
4166 (defvar org-match-substring-regexp
4167 (concat
4168 "\\([^\\]\\)\\([_^]\\)\\("
4169 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4170 "\\|"
4171 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4172 "\\|"
4173 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4174 "The regular expression matching a sub- or superscript.")
4176 (defvar org-match-substring-with-braces-regexp
4177 (concat
4178 "\\([^\\]\\)\\([_^]\\)\\("
4179 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4180 "\\)")
4181 "The regular expression matching a sub- or superscript, forcing braces.")
4183 (defconst org-export-html-special-string-regexps
4184 '(("\\\\-" . "&shy;")
4185 ("---\\([^-]\\)" . "&mdash;\\1")
4186 ("--\\([^-]\\)" . "&ndash;\\1")
4187 ("\\.\\.\\." . "&hellip;"))
4188 "Regular expressions for special string conversion.")
4190 (defun org-export-html-convert-special-strings (string)
4191 "Convert special characters in STRING to HTML."
4192 (let ((all org-export-html-special-string-regexps)
4193 e a re rpl start)
4194 (while (setq a (pop all))
4195 (setq re (car a) rpl (cdr a) start 0)
4196 (while (string-match re string start)
4197 (if (get-text-property (match-beginning 0) 'org-protected string)
4198 (setq start (match-end 0))
4199 (setq string (replace-match rpl t nil string)))))
4200 string))
4202 (defun org-export-html-convert-sub-super (string)
4203 "Convert sub- and superscripts in STRING to HTML."
4204 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4205 (while (string-match org-match-substring-regexp string s)
4206 (cond
4207 ((and requireb (match-end 8)) (setq s (match-end 2)))
4208 ((get-text-property (match-beginning 2) 'org-protected string)
4209 (setq s (match-end 2)))
4211 (setq s (match-end 1)
4212 key (if (string= (match-string 2 string) "_") "sub" "sup")
4213 c (or (match-string 8 string)
4214 (match-string 6 string)
4215 (match-string 5 string))
4216 string (replace-match
4217 (concat (match-string 1 string)
4218 "<" key ">" c "</" key ">")
4219 t t string)))))
4220 (while (string-match "\\\\\\([_^]\\)" string)
4221 (setq string (replace-match (match-string 1 string) t t string)))
4222 string))
4224 (defun org-export-html-convert-emphasize (string)
4225 "Apply emphasis."
4226 (let ((s 0) rpl)
4227 (while (string-match org-emph-re string s)
4228 (if (not (equal
4229 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4230 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4231 (setq s (match-beginning 0)
4233 (concat
4234 (match-string 1 string)
4235 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4236 (match-string 4 string)
4237 (nth 3 (assoc (match-string 3 string)
4238 org-emphasis-alist))
4239 (match-string 5 string))
4240 string (replace-match rpl t t string)
4241 s (+ s (- (length rpl) 2)))
4242 (setq s (1+ s))))
4243 string))
4245 (defun org-open-par ()
4246 "Insert <p>, but first close previous paragraph if any."
4247 (org-close-par-maybe)
4248 (insert "\n<p>")
4249 (setq org-par-open t))
4250 (defun org-close-par-maybe ()
4251 "Close paragraph if there is one open."
4252 (when org-par-open
4253 (insert "</p>")
4254 (setq org-par-open nil)))
4255 (defun org-close-li (&optional type)
4256 "Close <li> if necessary."
4257 (org-close-par-maybe)
4258 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4260 (defvar body-only) ; dynamically scoped into this.
4261 (defun org-html-level-start (level title umax with-toc head-count)
4262 "Insert a new level in HTML export.
4263 When TITLE is nil, just close all open levels."
4264 (org-close-par-maybe)
4265 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4266 (extra-targets
4267 (mapconcat (lambda (x)
4268 (format "<a name=\"%s\" id=\"%s\"></a>"
4269 x x))
4270 (cdr (assoc target org-export-target-aliases))
4271 ""))
4272 (l org-level-max)
4273 snumber)
4274 (while (>= l level)
4275 (if (aref org-levels-open (1- l))
4276 (progn
4277 (org-html-level-close l umax)
4278 (aset org-levels-open (1- l) nil)))
4279 (setq l (1- l)))
4280 (when title
4281 ;; If title is nil, this means this function is called to close
4282 ;; all levels, so the rest is done only if title is given
4283 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4284 (setq title (replace-match
4285 (if org-export-with-tags
4286 (save-match-data
4287 (concat
4288 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4289 (mapconcat 'identity (org-split-string
4290 (match-string 1 title) ":")
4291 "&nbsp;")
4292 "</span>"))
4294 t t title)))
4295 (if (> level umax)
4296 (progn
4297 (if (aref org-levels-open (1- level))
4298 (progn
4299 (org-close-li)
4300 (if target
4301 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4302 (insert "<li>" title "<br/>\n")))
4303 (aset org-levels-open (1- level) t)
4304 (org-close-par-maybe)
4305 (if target
4306 (insert (format "<ul>\n<li id=\"%s\">" target)
4307 extra-targets title "<br/>\n")
4308 (insert "<ul>\n<li>" title "<br/>\n"))))
4309 (aset org-levels-open (1- level) t)
4310 (setq snumber (org-section-number level))
4311 (if (and org-export-with-section-numbers (not body-only))
4312 (setq title (concat snumber " " title)))
4313 (setq level (+ level org-export-html-toplevel-hlevel -1))
4314 (unless (= head-count 1) (insert "\n</div>\n"))
4315 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div id=\"text-%s\">\n"
4316 snumber level level snumber extra-targets title level snumber))
4317 (org-open-par)))))
4319 (defun org-get-text-property-any (pos prop &optional object)
4320 (or (get-text-property pos prop object)
4321 (and (setq pos (next-single-property-change pos prop object))
4322 (get-text-property pos prop object))))
4324 (defun org-html-level-close (level max-outline-level)
4325 "Terminate one level in HTML export."
4326 (if (<= level max-outline-level)
4327 (insert "</div>\n")
4328 (org-close-li)
4329 (insert "</ul>\n")))
4331 ;;; iCalendar export
4333 ;;;###autoload
4334 (defun org-export-icalendar-this-file ()
4335 "Export current file as an iCalendar file.
4336 The iCalendar file will be located in the same directory as the Org-mode
4337 file, but with extension `.ics'."
4338 (interactive)
4339 (org-export-icalendar nil buffer-file-name))
4341 ;;;###autoload
4342 (defun org-export-icalendar-all-agenda-files ()
4343 "Export all files in `org-agenda-files' to iCalendar .ics files.
4344 Each iCalendar file will be located in the same directory as the Org-mode
4345 file, but with extension `.ics'."
4346 (interactive)
4347 (apply 'org-export-icalendar nil (org-agenda-files t)))
4349 ;;;###autoload
4350 (defun org-export-icalendar-combine-agenda-files ()
4351 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4352 The file is stored under the name `org-combined-agenda-icalendar-file'."
4353 (interactive)
4354 (apply 'org-export-icalendar t (org-agenda-files t)))
4356 (defun org-export-icalendar (combine &rest files)
4357 "Create iCalendar files for all elements of FILES.
4358 If COMBINE is non-nil, combine all calendar entries into a single large
4359 file and store it under the name `org-combined-agenda-icalendar-file'."
4360 (save-excursion
4361 (org-prepare-agenda-buffers files)
4362 (let* ((dir (org-export-directory
4363 :ical (list :publishing-directory
4364 org-export-publishing-directory)))
4365 file ical-file ical-buffer category started org-agenda-new-buffers)
4366 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4367 (when combine
4368 (setq ical-file
4369 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4370 org-combined-agenda-icalendar-file
4371 (expand-file-name org-combined-agenda-icalendar-file dir))
4372 ical-buffer (org-get-agenda-file-buffer ical-file))
4373 (set-buffer ical-buffer) (erase-buffer))
4374 (while (setq file (pop files))
4375 (catch 'nextfile
4376 (org-check-agenda-file file)
4377 (set-buffer (org-get-agenda-file-buffer file))
4378 (unless combine
4379 (setq ical-file (concat (file-name-as-directory dir)
4380 (file-name-sans-extension
4381 (file-name-nondirectory buffer-file-name))
4382 ".ics"))
4383 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4384 (with-current-buffer ical-buffer (erase-buffer)))
4385 (setq category (or org-category
4386 (file-name-sans-extension
4387 (file-name-nondirectory buffer-file-name))))
4388 (if (symbolp category) (setq category (symbol-name category)))
4389 (let ((standard-output ical-buffer))
4390 (if combine
4391 (and (not started) (setq started t)
4392 (org-start-icalendar-file org-icalendar-combined-name))
4393 (org-start-icalendar-file category))
4394 (org-print-icalendar-entries combine)
4395 (when (or (and combine (not files)) (not combine))
4396 (org-finish-icalendar-file)
4397 (set-buffer ical-buffer)
4398 (run-hooks 'org-before-save-iCalendar-file-hook)
4399 (save-buffer)
4400 (run-hooks 'org-after-save-iCalendar-file-hook)
4401 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4402 ))))
4403 (org-release-buffers org-agenda-new-buffers))))
4405 (defvar org-before-save-iCalendar-file-hook nil
4406 "Hook run before an iCalendar file has been saved.
4407 This can be used to modify the result of the export.")
4409 (defvar org-after-save-iCalendar-file-hook nil
4410 "Hook run after an iCalendar file has been saved.
4411 The iCalendar buffer is still current when this hook is run.
4412 A good way to use this is to tell a desktop calenndar application to re-read
4413 the iCalendar file.")
4415 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4416 (defun org-print-icalendar-entries (&optional combine)
4417 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4418 When COMBINE is non nil, add the category to each line."
4419 (require 'org-agenda)
4420 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4421 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4422 (dts (org-ical-ts-to-string
4423 (format-time-string (cdr org-time-stamp-formats) (current-time))
4424 "DTSTART"))
4425 hd ts ts2 state status (inc t) pos b sexp rrule
4426 scheduledp deadlinep todo prefix due start
4427 tmp pri categories entry location summary desc uid
4428 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4429 (org-refresh-category-properties)
4430 (save-excursion
4431 (goto-char (point-min))
4432 (while (re-search-forward re1 nil t)
4433 (catch :skip
4434 (org-agenda-skip)
4435 (when (boundp 'org-icalendar-verify-function)
4436 (unless (funcall org-icalendar-verify-function)
4437 (outline-next-heading)
4438 (backward-char 1)
4439 (throw :skip nil)))
4440 (setq pos (match-beginning 0)
4441 ts (match-string 0)
4442 inc t
4443 hd (condition-case nil
4444 (org-icalendar-cleanup-string
4445 (org-get-heading))
4446 (error (throw :skip nil)))
4447 summary (org-icalendar-cleanup-string
4448 (org-entry-get nil "SUMMARY"))
4449 desc (org-icalendar-cleanup-string
4450 (or (org-entry-get nil "DESCRIPTION")
4451 (and org-icalendar-include-body (org-get-entry)))
4452 t org-icalendar-include-body)
4453 location (org-icalendar-cleanup-string
4454 (org-entry-get nil "LOCATION" 'selective))
4455 uid (if org-icalendar-store-UID
4456 (org-id-get-create)
4457 (or (org-id-get) (org-id-new)))
4458 categories (org-export-get-categories)
4459 deadlinep nil scheduledp nil)
4460 (if (looking-at re2)
4461 (progn
4462 (goto-char (match-end 0))
4463 (setq ts2 (match-string 1)
4464 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4465 (setq tmp (buffer-substring (max (point-min)
4466 (- pos org-ds-keyword-length))
4467 pos)
4468 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4469 (progn
4470 (setq inc nil)
4471 (replace-match "\\1" t nil ts))
4473 deadlinep (string-match org-deadline-regexp tmp)
4474 scheduledp (string-match org-scheduled-regexp tmp)
4475 todo (org-get-todo-state)
4476 ;; donep (org-entry-is-done-p)
4478 (when (and
4479 deadlinep
4480 (if todo
4481 (not (memq 'event-if-todo org-icalendar-use-deadline))
4482 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4483 (throw :skip t))
4484 (when (and
4485 scheduledp
4486 (if todo
4487 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4488 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4489 (throw :skip t))
4490 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4491 (if (or (string-match org-tr-regexp hd)
4492 (string-match org-ts-regexp hd))
4493 (setq hd (replace-match "" t t hd)))
4494 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4495 (setq rrule
4496 (concat "\nRRULE:FREQ="
4497 (cdr (assoc
4498 (match-string 2 ts)
4499 '(("d" . "DAILY")("w" . "WEEKLY")
4500 ("m" . "MONTHLY")("y" . "YEARLY"))))
4501 ";INTERVAL=" (match-string 1 ts)))
4502 (setq rrule ""))
4503 (setq summary (or summary hd))
4504 (if (string-match org-bracket-link-regexp summary)
4505 (setq summary
4506 (replace-match (if (match-end 3)
4507 (match-string 3 summary)
4508 (match-string 1 summary))
4509 t t summary)))
4510 (if deadlinep (setq summary (concat "DL: " summary)))
4511 (if scheduledp (setq summary (concat "S: " summary)))
4512 (if (string-match "\\`<%%" ts)
4513 (with-current-buffer sexp-buffer
4514 (insert (substring ts 1 -1) " " summary "\n"))
4515 (princ (format "BEGIN:VEVENT
4516 UID: %s
4518 %s%s
4519 SUMMARY:%s%s%s
4520 CATEGORIES:%s
4521 END:VEVENT\n"
4522 (concat prefix uid)
4523 (org-ical-ts-to-string ts "DTSTART")
4524 (org-ical-ts-to-string ts2 "DTEND" inc)
4525 rrule summary
4526 (if (and desc (string-match "\\S-" desc))
4527 (concat "\nDESCRIPTION: " desc) "")
4528 (if (and location (string-match "\\S-" location))
4529 (concat "\nLOCATION: " location) "")
4530 categories)))))
4531 (when (and org-icalendar-include-sexps
4532 (condition-case nil (require 'icalendar) (error nil))
4533 (fboundp 'icalendar-export-region))
4534 ;; Get all the literal sexps
4535 (goto-char (point-min))
4536 (while (re-search-forward "^&?%%(" nil t)
4537 (catch :skip
4538 (org-agenda-skip)
4539 (setq b (match-beginning 0))
4540 (goto-char (1- (match-end 0)))
4541 (forward-sexp 1)
4542 (end-of-line 1)
4543 (setq sexp (buffer-substring b (point)))
4544 (with-current-buffer sexp-buffer
4545 (insert sexp "\n"))))
4546 (princ (org-diary-to-ical-string sexp-buffer))
4547 (kill-buffer sexp-buffer))
4549 (when org-icalendar-include-todo
4550 (setq prefix "TODO-")
4551 (goto-char (point-min))
4552 (while (re-search-forward org-todo-line-regexp nil t)
4553 (catch :skip
4554 (org-agenda-skip)
4555 (when (boundp 'org-icalendar-verify-function)
4556 (unless (funcall org-icalendar-verify-function)
4557 (outline-next-heading)
4558 (backward-char 1)
4559 (throw :skip nil)))
4560 (setq state (match-string 2))
4561 (setq status (if (member state org-done-keywords)
4562 "COMPLETED" "NEEDS-ACTION"))
4563 (when (and state
4564 (or (not (member state org-done-keywords))
4565 (eq org-icalendar-include-todo 'all))
4566 (not (member org-archive-tag (org-get-tags-at)))
4568 (setq hd (match-string 3)
4569 summary (org-icalendar-cleanup-string
4570 (org-entry-get nil "SUMMARY"))
4571 desc (org-icalendar-cleanup-string
4572 (or (org-entry-get nil "DESCRIPTION")
4573 (and org-icalendar-include-body (org-get-entry)))
4574 t org-icalendar-include-body)
4575 location (org-icalendar-cleanup-string
4576 (org-entry-get nil "LOCATION" 'selective))
4577 due (and (member 'todo-due org-icalendar-use-deadline)
4578 (org-entry-get nil "DEADLINE"))
4579 start (and (member 'todo-start org-icalendar-use-scheduled)
4580 (org-entry-get nil "SCHEDULED"))
4581 categories (org-export-get-categories)
4582 uid (if org-icalendar-store-UID
4583 (org-id-get-create)
4584 (or (org-id-get) (org-id-new))))
4585 (and due (setq due (org-ical-ts-to-string due "DUE")))
4586 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4588 (if (string-match org-bracket-link-regexp hd)
4589 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4590 (match-string 1 hd))
4591 t t hd)))
4592 (if (string-match org-priority-regexp hd)
4593 (setq pri (string-to-char (match-string 2 hd))
4594 hd (concat (substring hd 0 (match-beginning 1))
4595 (substring hd (match-end 1))))
4596 (setq pri org-default-priority))
4597 (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
4598 (- org-lowest-priority org-highest-priority))))))
4600 (princ (format "BEGIN:VTODO
4601 UID: %s
4603 SUMMARY:%s%s%s%s
4604 CATEGORIES:%s
4605 SEQUENCE:1
4606 PRIORITY:%d
4607 STATUS:%s
4608 END:VTODO\n"
4609 (concat prefix uid)
4610 (or start dts)
4611 (or summary hd)
4612 (if (and location (string-match "\\S-" location))
4613 (concat "\nLOCATION: " location) "")
4614 (if (and desc (string-match "\\S-" desc))
4615 (concat "\nDESCRIPTION: " desc) "")
4616 (if due (concat "\n" due) "")
4617 categories
4618 pri status)))))))))
4620 (defun org-export-get-categories ()
4621 "Get categories according to `org-icalendar-categories'."
4622 (let ((cs org-icalendar-categories) c rtn tmp)
4623 (while (setq c (pop cs))
4624 (cond
4625 ((eq c 'category) (push (org-get-category) rtn))
4626 ((eq c 'todo-state)
4627 (setq tmp (org-get-todo-state))
4628 (and tmp (push tmp rtn)))
4629 ((eq c 'local-tags)
4630 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4631 ((eq c 'all-tags)
4632 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4633 (mapconcat 'identity (nreverse rtn) ",")))
4635 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4636 "Take out stuff and quote what needs to be quoted.
4637 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4638 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4639 characters."
4640 (if (not s)
4642 (when is-body
4643 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4644 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4645 (while (string-match re s) (setq s (replace-match "" t t s)))
4646 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4647 (let ((start 0))
4648 (while (string-match "\\([,;]\\)" s start)
4649 (setq start (+ (match-beginning 0) 2)
4650 s (replace-match "\\\\\\1" nil nil s))))
4651 (setq s (org-trim s))
4652 (when is-body
4653 (while (string-match "[ \t]*\n[ \t]*" s)
4654 (setq s (replace-match "\\n" t t s))))
4655 (if is-body
4656 (if maxlength
4657 (if (and (numberp maxlength)
4658 (> (length s) maxlength))
4659 (setq s (substring s 0 maxlength)))))
4662 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
4663 "Take out stuff and quote what needs to be quoted.
4664 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4665 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4666 characters.
4667 This seems to be more like RFC 2455, but it causes problems, so it is
4668 not used right now."
4669 (if (not s)
4671 (if is-body
4672 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4673 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4674 (while (string-match re s) (setq s (replace-match "" t t s)))
4675 (while (string-match re2 s) (setq s (replace-match "" t t s)))
4676 (setq s (org-trim s))
4677 (while (string-match "[ \t]*\n[ \t]*" s)
4678 (setq s (replace-match "\\n" t t s)))
4679 (if maxlength
4680 (if (and (numberp maxlength)
4681 (> (length s) maxlength))
4682 (setq s (substring s 0 maxlength)))))
4683 (setq s (org-trim s)))
4684 (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
4685 (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
4688 (defun org-get-entry ()
4689 "Clean-up description string."
4690 (save-excursion
4691 (org-back-to-heading t)
4692 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4694 (defun org-start-icalendar-file (name)
4695 "Start an iCalendar file by inserting the header."
4696 (let ((user user-full-name)
4697 (name (or name "unknown"))
4698 (timezone (cadr (current-time-zone))))
4699 (princ
4700 (format "BEGIN:VCALENDAR
4701 VERSION:2.0
4702 X-WR-CALNAME:%s
4703 PRODID:-//%s//Emacs with Org-mode//EN
4704 X-WR-TIMEZONE:%s
4705 CALSCALE:GREGORIAN\n" name user timezone))))
4707 (defun org-finish-icalendar-file ()
4708 "Finish an iCalendar file by inserting the END statement."
4709 (princ "END:VCALENDAR\n"))
4711 (defun org-ical-ts-to-string (s keyword &optional inc)
4712 "Take a time string S and convert it to iCalendar format.
4713 KEYWORD is added in front, to make a complete line like DTSTART....
4714 When INC is non-nil, increase the hour by two (if time string contains
4715 a time), or the day by one (if it does not contain a time)."
4716 (let ((t1 (org-parse-time-string s 'nodefault))
4717 t2 fmt have-time time)
4718 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4719 (setq t2 t1 have-time t)
4720 (setq t2 (org-parse-time-string s)))
4721 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4722 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4723 (when inc
4724 (if have-time
4725 (if org-agenda-default-appointment-duration
4726 (setq mi (+ org-agenda-default-appointment-duration mi))
4727 (setq h (+ 2 h)))
4728 (setq d (1+ d))))
4729 (setq time (encode-time s mi h d m y)))
4730 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4731 (concat keyword (format-time-string fmt time))))
4733 ;;; XOXO export
4735 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4736 (with-current-buffer buffer
4737 (apply 'insert output)))
4738 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4740 ;;;###autoload
4741 (defun org-export-as-xoxo (&optional buffer)
4742 "Export the org buffer as XOXO.
4743 The XOXO buffer is named *xoxo-<source buffer name>*"
4744 (interactive (list (current-buffer)))
4745 ;; A quickie abstraction
4747 ;; Output everything as XOXO
4748 (with-current-buffer (get-buffer buffer)
4749 (let* ((pos (point))
4750 (opt-plist (org-combine-plists (org-default-export-plist)
4751 (org-infile-export-plist)))
4752 (filename (concat (file-name-as-directory
4753 (org-export-directory :xoxo opt-plist))
4754 (file-name-sans-extension
4755 (file-name-nondirectory buffer-file-name))
4756 ".html"))
4757 (out (find-file-noselect filename))
4758 (last-level 1)
4759 (hanging-li nil))
4760 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4761 ;; Check the output buffer is empty.
4762 (with-current-buffer out (erase-buffer))
4763 ;; Kick off the output
4764 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4765 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4766 (let* ((hd (match-string-no-properties 1))
4767 (level (length hd))
4768 (text (concat
4769 (match-string-no-properties 2)
4770 (save-excursion
4771 (goto-char (match-end 0))
4772 (let ((str ""))
4773 (catch 'loop
4774 (while 't
4775 (forward-line)
4776 (if (looking-at "^[ \t]\\(.*\\)")
4777 (setq str (concat str (match-string-no-properties 1)))
4778 (throw 'loop str)))))))))
4780 ;; Handle level rendering
4781 (cond
4782 ((> level last-level)
4783 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4785 ((< level last-level)
4786 (dotimes (- (- last-level level) 1)
4787 (if hanging-li
4788 (org-export-as-xoxo-insert-into out "</li>\n"))
4789 (org-export-as-xoxo-insert-into out "</ol>\n"))
4790 (when hanging-li
4791 (org-export-as-xoxo-insert-into out "</li>\n")
4792 (setq hanging-li nil)))
4794 ((equal level last-level)
4795 (if hanging-li
4796 (org-export-as-xoxo-insert-into out "</li>\n")))
4799 (setq last-level level)
4801 ;; And output the new li
4802 (setq hanging-li 't)
4803 (if (equal ?+ (elt text 0))
4804 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4805 (org-export-as-xoxo-insert-into out "<li>" text))))
4807 ;; Finally finish off the ol
4808 (dotimes (- last-level 1)
4809 (if hanging-li
4810 (org-export-as-xoxo-insert-into out "</li>\n"))
4811 (org-export-as-xoxo-insert-into out "</ol>\n"))
4813 (goto-char pos)
4814 ;; Finish the buffer off and clean it up.
4815 (switch-to-buffer-other-window out)
4816 (indent-region (point-min) (point-max) nil)
4817 (save-buffer)
4818 (goto-char (point-min))
4821 (provide 'org-exp)
4823 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4825 ;;; org-exp.el ends here