Release 6.15b.
[org-mode/org-tableheadings.git] / lisp / org-exp.el
blob3188ed085bd799de1f023f7ff39020fdfc1daae2
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.15b
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 condition, 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 postamble 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 actual 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 identifier.
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 superceding 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 occurrences 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 OPTIONS 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 marks some stuff for 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 ;; Find all headings and compute the targets for them
1473 (setq target-alist (org-export-define-heading-targets target-alist))
1475 ;; Get rid of drawers
1476 (org-export-remove-or-extract-drawers drawers
1477 (plist-get parameters :drawers))
1479 ;; Get the correct stuff before the first headline
1480 (when (plist-get parameters :skip-before-1st-heading)
1481 (goto-char (point-min))
1482 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t)
1483 (delete-region (point-min) (match-beginning 0))
1484 (goto-char (point-min))
1485 (insert "\n")))
1486 (when (plist-get parameters :add-text)
1487 (goto-char (point-min))
1488 (insert (plist-get parameters :add-text) "\n"))
1490 ;; Get rid of archived trees
1491 (org-export-remove-archived-trees archived-trees)
1493 ;; Remove todo-keywords before exporting, if the user has requested so
1494 (org-export-remove-headline-metadata parameters)
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 object
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)
1522 ;; Find matches for radio targets and turn them into internal links
1523 (org-export-mark-radio-links)
1525 ;; Find all links that contain a newline and put them into a single line
1526 (org-export-concatenate-multiline-links)
1528 ;; Normalize links: Convert angle and plain links into bracket links
1529 ;; and expand link abbreviations
1530 (org-export-normalize-links)
1532 ;; Find all internal links. If they have a fuzzy match (i.e. not
1533 ;; a *dedicated* target match, let the link point to the
1534 ;; corresponding section.
1535 (org-export-target-internal-links target-alist)
1537 ;; Find multiline emphasis and put them into single line
1538 (when (plist-get parameters :emph-multiline)
1539 (org-export-concatenate-multiline-emphasis))
1541 ;; Remove special table lines
1542 (when org-export-table-remove-special-lines
1543 (org-export-remove-special-table-lines))
1545 ;; Specific LaTeX stuff
1546 (when latexp
1547 (require 'org-export-latex nil)
1548 (org-export-latex-preprocess))
1550 ;; Specific ASCII stuff
1551 (when asciip
1552 (org-export-ascii-preprocess))
1554 ;; Specific HTML stuff
1555 (when htmlp
1556 (org-export-html-preprocess parameters))
1558 ;; Remove or replace comments
1559 (org-export-handle-comments (plist-get parameters :comments))
1561 (setq rtn (buffer-string)))
1562 (kill-buffer " org-mode-tmp")
1563 rtn))
1565 (defun org-export-kill-licensed-text ()
1566 "Remove all text that is marked with a :org-license-to-kill property."
1567 (let (p q)
1568 (while (setq p (text-property-any (point-min) (point-max)
1569 :org-license-to-kill t))
1570 (delete-region
1571 p (or (next-single-property-change p :org-license-to-kill)
1572 (point-max))))))
1574 (defun org-export-define-heading-targets (target-alist)
1575 "Find all headings and define the targets for them.
1576 The new targets are added to TARGET-ALIST, which is also returned."
1577 (goto-char (point-min))
1578 (org-init-section-numbers)
1579 (let ((re (concat "^" org-outline-regexp
1580 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1581 level target)
1582 (while (re-search-forward re nil t)
1583 (if (match-end 1)
1584 (push (cons (org-match-string-no-properties 1)
1585 target) target-alist)
1586 (setq level (org-reduced-level
1587 (save-excursion (goto-char (point-at-bol))
1588 (org-outline-level))))
1589 (setq target (org-solidify-link-text
1590 (format "sec-%s" (org-section-number level))))
1591 (push (cons target target) target-alist)
1592 (add-text-properties
1593 (point-at-bol) (point-at-eol)
1594 (list 'target target)))))
1595 target-alist)
1597 (defun org-export-handle-invisible-targets (target-alist)
1598 "Find targets in comments and move them out of comments.
1599 Mark them as invisible targets."
1600 (let (target tmp a)
1601 (goto-char (point-min))
1602 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1603 ;; Check if the line before or after is a headline with a target
1604 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1605 (get-text-property (point-at-bol 2) 'target)))
1606 (progn
1607 ;; use the existing target in a neighboring line
1608 (setq tmp (match-string 2))
1609 (replace-match "")
1610 (and (looking-at "\n") (delete-char 1))
1611 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1612 target-alist)
1613 (setq a (or (assoc target org-export-target-aliases)
1614 (progn
1615 (push (list target) org-export-target-aliases)
1616 (car org-export-target-aliases))))
1617 (push tmp (cdr a)))
1618 ;; Make an invisible target
1619 (replace-match "\\1(INVISIBLE)"))))
1620 target-alist)
1622 (defun org-export-target-internal-links (target-alist)
1623 "Find all internal links and assign targets to them.
1624 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1625 let the link point to the corresponding section.
1626 This function also handles the id links, if they have a match in
1627 the current file."
1628 (goto-char (point-min))
1629 (while (re-search-forward org-bracket-link-regexp nil t)
1630 (org-if-unprotected
1631 (let* ((md (match-data))
1632 (desc (match-end 2))
1633 (link (org-link-unescape (match-string 1)))
1634 (slink (org-solidify-link-text link))
1635 found props pos
1636 (target
1637 (cond
1638 ((cdr (assoc slink target-alist)))
1639 ((and (string-match "^id:" link)
1640 (cdr (assoc (substring link 3) target-alist))))
1641 ((string-match org-link-types-re link) nil)
1642 ((or (file-name-absolute-p link)
1643 (string-match "^\\." link))
1644 nil)
1646 (save-excursion
1647 (setq found (condition-case nil (org-link-search link)
1648 (error nil)))
1649 (when (and found
1650 (or (org-on-heading-p)
1651 (not (eq found 'dedicated))))
1652 (or (get-text-property (point) 'target)
1653 (get-text-property
1654 (max (point-min)
1655 (1- (or (previous-single-property-change
1656 (point) 'target) 0)))
1657 'target))))))))
1658 (when target
1659 (set-match-data md)
1660 (goto-char (match-beginning 1))
1661 (setq props (text-properties-at (point)))
1662 (delete-region (match-beginning 1) (match-end 1))
1663 (setq pos (point))
1664 (insert target)
1665 (unless desc (insert "][" link))
1666 (add-text-properties pos (point) props))))))
1668 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1669 "Remove drawers, or extract the content.
1670 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1671 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1672 whose content to keep."
1673 (unless (eq t exp-drawers)
1674 (goto-char (point-min))
1675 (let ((re (concat "^[ \t]*:\\("
1676 (mapconcat
1677 'identity
1678 (org-delete-all exp-drawers
1679 (copy-sequence all-drawers))
1680 "\\|")
1681 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1682 (while (re-search-forward re nil t)
1683 (replace-match "")))))
1685 (defun org-export-handle-export-tags (select-tags exclude-tags)
1686 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1687 Both arguments are lists of tags.
1688 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1689 will be removed.
1690 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1691 removed as well."
1692 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1693 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1694 select-tags "\\|")
1695 "\\):"))
1696 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1697 exclude-tags "\\|")
1698 "\\):"))
1699 beg end cont)
1700 (goto-char (point-min))
1701 (when (and select-tags
1702 (re-search-forward
1703 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1704 ;; At least one tree is marked for export, this means
1705 ;; all the unmarked stuff needs to go.
1706 ;; Dig out the trees that should be exported
1707 (goto-char (point-min))
1708 (outline-next-heading)
1709 (setq beg (point))
1710 (put-text-property beg (point-max) :org-delete t)
1711 (while (re-search-forward re-sel nil t)
1712 (when (org-on-heading-p)
1713 (org-back-to-heading)
1714 (remove-text-properties
1715 (max (1- (point)) (point-min))
1716 (setq cont (save-excursion (org-end-of-subtree t t)))
1717 '(:org-delete t))
1718 (while (and (org-up-heading-safe)
1719 (get-text-property (point) :org-delete))
1720 (remove-text-properties (max (1- (point)) (point-min))
1721 (point-at-eol) '(:org-delete t)))
1722 (goto-char cont))))
1723 ;; Remove the trees explicitly marked for noexport
1724 (when exclude-tags
1725 (goto-char (point-min))
1726 (while (re-search-forward re-excl nil t)
1727 (when (org-at-heading-p)
1728 (org-back-to-heading t)
1729 (setq beg (point))
1730 (org-end-of-subtree t)
1731 (delete-region beg (point)))))
1732 ;; Remove everything that is now still marked for deletion
1733 (goto-char (point-min))
1734 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1735 (setq end (or (next-single-property-change beg :org-delete)
1736 (point-max)))
1737 (delete-region beg end))))
1739 (defun org-export-remove-archived-trees (export-archived-trees)
1740 "Remove archived trees.
1741 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1742 When it is t, the entire archived tree will be exported.
1743 When it is nil the entire tree including the headline will be removed
1744 from the buffer."
1745 (let ((re-archive (concat ":" org-archive-tag ":"))
1746 a b)
1747 (when (not (eq export-archived-trees t))
1748 (goto-char (point-min))
1749 (while (re-search-forward re-archive nil t)
1750 (if (not (org-on-heading-p t))
1751 (org-end-of-subtree t)
1752 (beginning-of-line 1)
1753 (setq a (if export-archived-trees
1754 (1+ (point-at-eol)) (point))
1755 b (org-end-of-subtree t))
1756 (if (> b a) (delete-region a b)))))))
1758 (defun org-export-remove-headline-metadata (opts)
1759 "Remove meta data from the headline, according to user options."
1760 (let ((re org-complex-heading-regexp)
1761 (todo (plist-get opts :todo-keywords))
1762 (tags (plist-get opts :tags))
1763 (pri (plist-get opts :priority))
1764 (elts '(1 2 3 4 5))
1765 rpl props)
1766 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1767 (when (or (not todo) (not tags) (not pri))
1768 (goto-char (point-min))
1769 (while (re-search-forward re nil t)
1770 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1771 elts " "))
1772 (replace-match rpl t t)))))
1774 (defun org-export-protect-quoted-subtrees ()
1775 "Mark quoted subtrees with the protection property."
1776 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1777 (goto-char (point-min))
1778 (while (re-search-forward re-quote nil t)
1779 (goto-char (match-beginning 0))
1780 (end-of-line 1)
1781 (add-text-properties (point) (org-end-of-subtree t)
1782 '(org-protected t)))))
1784 (defun org-export-protect-verbatim ()
1785 "Mark verbatim snippets with the protection property."
1786 (goto-char (point-min))
1787 (while (re-search-forward org-verbatim-re nil t)
1788 (add-text-properties (match-beginning 4) (match-end 4)
1789 '(org-protected t))
1790 (goto-char (1+ (match-end 4)))))
1792 (defun org-export-protect-examples (&optional indent)
1793 "Protect code that should be exported as monospaced examples."
1794 (goto-char (point-min))
1795 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1796 (goto-char (match-end 0))
1797 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1798 (insert (if indent ": " ":"))
1799 (beginning-of-line 2)))
1800 (goto-char (point-min))
1801 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1802 (add-text-properties (match-beginning 0) (match-end 0)
1803 '(org-protected t))))
1805 (defun org-export-select-backend-specific-text (backend)
1806 (let ((formatters
1807 '((html "HTML" "BEGIN_HTML" "END_HTML")
1808 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1809 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1810 fmt)
1812 (while formatters
1813 (setq fmt (pop formatters))
1814 (when (eq (car fmt) backend)
1815 ;; This is selected code, put it into the file for real
1816 (goto-char (point-min))
1817 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1818 ":[ \t]*\\(.*\\)") nil t)
1819 (replace-match "\\1" t)
1820 (add-text-properties
1821 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1822 '(org-protected t))))
1823 (goto-char (point-min))
1824 (while (re-search-forward
1825 (concat "^#\\+"
1826 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1827 (cadddr fmt) "\\>.*\n?") nil t)
1828 (if (eq (car fmt) backend)
1829 ;; yes, keep this
1830 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1831 '(org-protected t))
1832 ;; No, this is for a different backend, kill it
1833 (delete-region (match-beginning 0) (match-end 0)))))))
1835 (defun org-export-mark-blockquote-and-verse ()
1836 "Mark block quote and verse environments with special cookies.
1837 These special cookies will later be interpreted by the backend."
1838 ;; Blockquotes
1839 (goto-char (point-min))
1840 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1841 nil t)
1842 (replace-match (if (equal (downcase (match-string 1)) "end")
1843 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1844 t t))
1845 ;; Verse
1846 (goto-char (point-min))
1847 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1848 (replace-match (if (equal (downcase (match-string 1)) "end")
1849 "ORG-VERSE-END" "ORG-VERSE-START")
1850 t t)))
1852 (defun org-export-attach-captions-and-attributes (backend target-alist)
1853 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1854 If the next thing following is a table, add the text properties to the first
1855 table line. If it is a link, add it to the line containing the link."
1856 (goto-char (point-min))
1857 (remove-text-properties (point-min) (point-max)
1858 '(org-caption nil org-attributes nil))
1859 (let ((case-fold-search t)
1860 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1861 "\\|"
1862 "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1863 "\\|"
1864 "^#\\+label:[ \t]+\\(.*\\)"
1865 "\\|"
1866 "^[ \t]*|[^-]"
1867 "\\|"
1868 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1869 cap attr label)
1870 (while (re-search-forward re nil t)
1871 (cond
1872 ((match-end 1)
1873 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1874 ((match-end 2)
1875 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1876 ((match-end 3)
1877 (setq label (org-trim (match-string 3))))
1879 (add-text-properties (point-at-bol) (point-at-eol)
1880 (list 'org-caption cap
1881 'org-attributes attr
1882 'org-label label))
1883 (if label (push (cons label label) target-alist))
1884 (setq cap nil attr nil label nil)))))
1885 target-alist)
1887 (defun org-export-remove-comment-blocks-and-subtrees ()
1888 "Remove the comment environment, and also commented subtrees."
1889 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1890 (case-fold-search nil))
1891 ;; Remove comment environment
1892 (goto-char (point-min))
1893 (while (re-search-forward
1894 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1895 (replace-match "" t t))
1896 ;; Remove subtrees that are commented
1897 (goto-char (point-min))
1898 (while (re-search-forward re-commented nil t)
1899 (goto-char (match-beginning 0))
1900 (delete-region (point) (org-end-of-subtree t)))))
1902 (defun org-export-handle-comments (commentsp)
1903 "Remove comments, or convert to backend-specific format.
1904 COMMENTSP can be a format string for publishing comments.
1905 When it is nil, all comments will be removed."
1906 (let ((re "^#\\(.*\n?\\)")
1907 pos)
1908 (goto-char (point-min))
1909 (while (or (looking-at re)
1910 (re-search-forward re nil t))
1911 (setq pos (match-beginning 0))
1912 (if commentsp
1913 (progn (add-text-properties
1914 (match-beginning 0) (match-end 0) '(org-protected t))
1915 (replace-match (format commentsp (match-string 1)) t t))
1916 (goto-char (1+ pos))
1917 (org-if-unprotected
1918 (replace-match "")
1919 (goto-char (max (point-min) (1- pos))))))))
1921 (defun org-export-mark-radio-links ()
1922 "Find all matches for radio targets and turn them into internal links."
1923 (let ((re-radio (and org-target-link-regexp
1924 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1925 (goto-char (point-min))
1926 (when re-radio
1927 (while (re-search-forward re-radio nil t)
1928 (org-if-unprotected
1929 (replace-match "\\1[[\\2]]"))))))
1931 (defun org-export-remove-special-table-lines ()
1932 "Remove tables lines that are used for internal purposes."
1933 (goto-char (point-min))
1934 (while (re-search-forward "^[ \t]*|" nil t)
1935 (beginning-of-line 1)
1936 (if (or (looking-at "[ \t]*| *[!_^] *|")
1937 (and (looking-at ".*?| *<[0-9]+> *|")
1938 (not (looking-at ".*?| *[^ <|]"))))
1939 (delete-region (max (point-min) (1- (point-at-bol)))
1940 (point-at-eol))
1941 (end-of-line 1))))
1943 (defun org-export-normalize-links ()
1944 "Convert all links to bracket links, and expand link abbreviations."
1945 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1946 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1947 (goto-char (point-min))
1948 (while (re-search-forward re-plain-link nil t)
1949 (goto-char (1- (match-end 0)))
1950 (org-if-unprotected
1951 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1952 ":" (match-string 3) "]]")))
1953 ;; added 'org-link face to links
1954 (put-text-property 0 (length s) 'face 'org-link s)
1955 (replace-match s t t))))
1956 (goto-char (point-min))
1957 (while (re-search-forward re-angle-link nil t)
1958 (goto-char (1- (match-end 0)))
1959 (org-if-unprotected
1960 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1961 ":" (match-string 3) "]]")))
1962 (put-text-property 0 (length s) 'face 'org-link s)
1963 (replace-match s t t))))
1964 (goto-char (point-min))
1965 (while (re-search-forward org-bracket-link-regexp nil t)
1966 (goto-char (1- (match-end 0)))
1967 (org-if-unprotected
1968 (let* ((xx (save-match-data
1969 (org-translate-link
1970 (org-link-expand-abbrev (match-string 1)))))
1971 (s (concat
1972 "[[" xx "]"
1973 (if (match-end 3)
1974 (match-string 2)
1975 (concat "[" xx "]"))
1976 "]")))
1977 (put-text-property 0 (length s) 'face 'org-link s)
1978 (replace-match s t t))))))
1980 (defun org-export-concatenate-multiline-links ()
1981 "Find multi-line links and put it all into a single line.
1982 This is to make sure that the line-processing export backends
1983 can work correctly."
1984 (goto-char (point-min))
1985 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1986 (org-if-unprotected
1987 (replace-match "\\1 \\3")
1988 (goto-char (match-beginning 0)))))
1990 (defun org-export-concatenate-multiline-emphasis ()
1991 "Find multi-line emphasis and put it all into a single line.
1992 This is to make sure that the line-processing export backends
1993 can work correctly."
1994 (goto-char (point-min))
1995 (while (re-search-forward org-emph-re nil t)
1996 (if (not (= (char-after (match-beginning 3))
1997 (char-after (match-beginning 4))))
1998 (org-if-unprotected
1999 (subst-char-in-region (match-beginning 0) (match-end 0)
2000 ?\n ?\ t)
2001 (goto-char (1- (match-end 0))))
2002 (goto-char (1+ (match-beginning 0))))))
2004 (defun org-export-grab-title-from-buffer ()
2005 "Get a title for the current document, from looking at the buffer."
2006 (let ((inhibit-read-only t))
2007 (save-excursion
2008 (goto-char (point-min))
2009 (let ((end (if (looking-at org-outline-regexp)
2010 (point)
2011 (save-excursion (outline-next-heading) (point)))))
2012 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2013 ;; Mark the line so that it will not be exported as normal text.
2014 (org-unmodified
2015 (add-text-properties (match-beginning 0) (match-end 0)
2016 (list :org-license-to-kill t)))
2017 ;; Return the title string
2018 (org-trim (match-string 0)))))))
2020 (defun org-export-get-title-from-subtree ()
2021 "Return subtree title and exclude it from export."
2022 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
2023 (save-excursion
2024 (goto-char rbeg)
2025 (when (and (org-at-heading-p)
2026 (>= (org-end-of-subtree t t) rend))
2027 ;; This is a subtree, we take the title from the first heading
2028 (goto-char rbeg)
2029 (looking-at org-todo-line-regexp)
2030 (setq title (match-string 3))
2031 (org-unmodified
2032 (add-text-properties (point) (1+ (point-at-eol))
2033 (list :org-license-to-kill t)))
2034 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2035 title))
2037 (defun org-solidify-link-text (s &optional alist)
2038 "Take link text and make a safe target out of it."
2039 (save-match-data
2040 (let* ((rtn
2041 (mapconcat
2042 'identity
2043 (org-split-string s "[ \t\r\n]+") "=="))
2044 (a (assoc rtn alist)))
2045 (or (cdr a) rtn))))
2047 (defun org-get-min-level (lines)
2048 "Get the minimum level in LINES."
2049 (let ((re "^\\(\\*+\\) ") l min)
2050 (catch 'exit
2051 (while (setq l (pop lines))
2052 (if (string-match re l)
2053 (throw 'exit (org-tr-level (length (match-string 1 l))))))
2054 1)))
2056 ;; Variable holding the vector with section numbers
2057 (defvar org-section-numbers (make-vector org-level-max 0))
2059 (defun org-init-section-numbers ()
2060 "Initialize the vector for the section numbers."
2061 (let* ((level -1)
2062 (numbers (nreverse (org-split-string "" "\\.")))
2063 (depth (1- (length org-section-numbers)))
2064 (i depth) number-string)
2065 (while (>= i 0)
2066 (if (> i level)
2067 (aset org-section-numbers i 0)
2068 (setq number-string (or (car numbers) "0"))
2069 (if (string-match "\\`[A-Z]\\'" number-string)
2070 (aset org-section-numbers i
2071 (- (string-to-char number-string) ?A -1))
2072 (aset org-section-numbers i (string-to-number number-string)))
2073 (pop numbers))
2074 (setq i (1- i)))))
2076 (defun org-section-number (&optional level)
2077 "Return a string with the current section number.
2078 When LEVEL is non-nil, increase section numbers on that level."
2079 (let* ((depth (1- (length org-section-numbers)))
2080 (string "")
2081 (fmts (car org-export-section-number-format))
2082 (term (cdr org-export-section-number-format))
2083 (sep "")
2084 ctype fmt idx n)
2085 (when level
2086 (when (> level -1)
2087 (aset org-section-numbers
2088 level (1+ (aref org-section-numbers level))))
2089 (setq idx (1+ level))
2090 (while (<= idx depth)
2091 (if (not (= idx 1))
2092 (aset org-section-numbers idx 0))
2093 (setq idx (1+ idx))))
2094 (setq idx 0)
2095 (while (<= idx depth)
2096 (when (> (aref org-section-numbers idx) 0)
2097 (setq fmt (or (pop fmts) fmt)
2098 ctype (car fmt)
2099 n (aref org-section-numbers idx)
2100 string (if (> n 0)
2101 (concat string sep (org-number-to-counter n ctype))
2102 (concat string ".0"))
2103 sep (nth 1 fmt)))
2104 (setq idx (1+ idx)))
2105 (save-match-data
2106 (if (string-match "\\`\\([@0]\\.\\)+" string)
2107 (setq string (replace-match "" t nil string)))
2108 (if (string-match "\\(\\.0\\)+\\'" string)
2109 (setq string (replace-match "" t nil string))))
2110 (concat string term)))
2112 (defun org-number-to-counter (n type)
2113 "Concert number N to a string counter, according to TYPE.
2114 TYPE must be a string, any of:
2115 1 number
2116 A A,B,....
2117 a a,b,....
2118 I upper case roman numeral
2119 i lower case roman numeral"
2120 (cond
2121 ((equal type "1") (number-to-string n))
2122 ((equal type "A") (char-to-string (+ ?A n -1)))
2123 ((equal type "a") (char-to-string (+ ?a n -1)))
2124 ((equal type "I") (org-number-to-roman n))
2125 ((equal type "i") (downcase (org-number-to-roman n)))
2126 (t (error "Invalid counter type `%s'" type))))
2128 (defun org-number-to-roman (n)
2129 "Convert integer N into a roman numeral."
2130 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2131 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2132 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2133 ( 1 . "I")))
2134 (res ""))
2135 (if (<= n 0)
2136 (number-to-string n)
2137 (while roman
2138 (if (>= n (caar roman))
2139 (setq n (- n (caar roman))
2140 res (concat res (cdar roman)))
2141 (pop roman)))
2142 res)))
2144 (org-number-to-roman 1961)
2147 ;;; Include files
2149 (defun org-export-handle-include-files ()
2150 "Include the contents of include files, with proper formatting."
2151 (let ((case-fold-search t)
2152 params file markup lang start end prefix prefix1)
2153 (goto-char (point-min))
2154 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2155 (setq params (read (concat "(" (match-string 1) ")"))
2156 prefix (org-get-and-remove-property 'params :prefix)
2157 prefix1 (org-get-and-remove-property 'params :prefix1)
2158 file (org-symname-or-string (pop params))
2159 markup (org-symname-or-string (pop params))
2160 lang (org-symname-or-string (pop params)))
2161 (delete-region (match-beginning 0) (match-end 0))
2162 (if (or (not file)
2163 (not (file-exists-p file))
2164 (not (file-readable-p file)))
2165 (insert (format "CANNOT INCLUDE FILE %s" file))
2166 (when markup
2167 (if (equal (downcase markup) "src")
2168 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2169 end "#+end_src")
2170 (setq start (format "#+begin_%s\n" markup)
2171 end (format "#+end_%s" markup))))
2172 (insert (or start ""))
2173 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2174 (or (bolp) (newline))
2175 (insert (or end ""))))))
2177 (defun org-get-file-contents (file &optional prefix prefix1)
2178 "Get the contents of FILE and return them as a string.
2179 If PREFIX is a string, prepend it to each line. If PREFIX1
2180 is a string, prepend it to the first line instead of PREFIX."
2181 (with-temp-buffer
2182 (insert-file-contents file)
2183 (when (or prefix prefix1)
2184 (goto-char (point-min))
2185 (while (not (eobp))
2186 (insert (or prefix1 prefix))
2187 (setq prefix1 nil)
2188 (beginning-of-line 2)))
2189 (buffer-string)))
2191 (defun org-get-and-remove-property (listvar prop)
2192 "Check if the value of LISTVAR contains PROP as a property.
2193 If yes, return the value of that property (i.e. the element following
2194 in the list) and remove property and value from the list in LISTVAR."
2195 (let ((list (symbol-value listvar)) m v)
2196 (when (setq m (member prop list))
2197 (setq v (nth 1 m))
2198 (if (equal (car list) prop)
2199 (set listvar (cddr list))
2200 (setcdr (nthcdr (- (length list) (length m) 1) list)
2201 (cddr m))
2202 (set listvar list)))
2205 (defun org-symname-or-string (s)
2206 (if (symbolp s)
2207 (if s (symbol-name s) s)
2210 ;;; Fontification of code
2211 ;; Currently only for the HTML backend, but who knows....
2212 (defun org-export-replace-src-segments ()
2213 "Replace source code segments with special code for export."
2214 (let ((case-fold-search t)
2215 lang code trans)
2216 (goto-char (point-min))
2217 (while (re-search-forward
2218 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2219 nil t)
2220 (setq lang (match-string 1) code (match-string 2)
2221 trans (org-export-format-source-code lang code))
2222 (replace-match trans t t))))
2224 (defvar htmlp) ;; dynamically scoped from org-exp.el
2226 (defun org-export-format-source-code (lang code)
2227 "Format CODE from language LANG and return it formatted for export.
2228 Currently, this only does something for HTML export, for all other
2229 backends, it converts the segment into an EXAMPLE segment."
2230 (save-match-data
2231 (cond
2232 (htmlp
2233 ;; We are exporting to HTML
2234 (require 'htmlize nil t)
2235 (if (not (fboundp 'htmlize-region-for-paste))
2236 (progn
2237 ;; we do not have htmlize.el, or an old version of it
2238 (message
2239 "htmlize.el 1.34 or later is needed for source code formatting")
2240 (concat "#+BEGIN_EXAMPLE\n" code
2241 (if (string-match "\n\\'" code) "" "\n")
2242 "#+END_EXAMPLE\n"))
2243 ;; ok, we are good to go
2244 (let* ((mode (and lang (intern (concat lang "-mode"))))
2245 (org-inhibit-startup t)
2246 (org-startup-folded nil)
2247 (htmltext
2248 (with-temp-buffer
2249 (insert code)
2250 ;; Free up the protected stuff
2251 (goto-char (point-min))
2252 (while (re-search-forward "^," nil t)
2253 (replace-match "")
2254 (end-of-line 1))
2255 (if (functionp mode)
2256 (funcall mode)
2257 (fundamental-mode))
2258 (font-lock-fontify-buffer)
2259 (org-export-htmlize-region-for-paste
2260 (point-min) (point-max)))))
2261 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2262 (setq htmltext (replace-match
2263 (format "<pre class=\"src src-%s\">" lang)
2264 t t htmltext)))
2265 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2267 ;; This is not HTML, so just make it an example.
2268 (when (equal lang "org")
2269 (while (string-match "^," code)
2270 (setq code (replace-match "" t t code))))
2271 (concat "#+BEGIN_EXAMPLE\n" code
2272 (if (string-match "\n\\'" code) "" "\n")
2273 "#+END_EXAMPLE\n")))))
2275 ;;; ASCII export
2277 (defvar org-last-level nil) ; dynamically scoped variable
2278 (defvar org-min-level nil) ; dynamically scoped variable
2279 (defvar org-levels-open nil) ; dynamically scoped parameter
2280 (defvar org-ascii-current-indentation nil) ; For communication
2282 ;;;###autoload
2283 (defun org-export-as-ascii (arg)
2284 "Export the outline as a pretty ASCII file.
2285 If there is an active region, export only the region.
2286 The prefix ARG specifies how many levels of the outline should become
2287 underlined headlines. The default is 3."
2288 (interactive "P")
2289 (setq-default org-todo-line-regexp org-todo-line-regexp)
2290 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2291 (org-infile-export-plist)))
2292 (region-p (org-region-active-p))
2293 (rbeg (and region-p (region-beginning)))
2294 (rend (and region-p (region-end)))
2295 (subtree-p
2296 (when region-p
2297 (save-excursion
2298 (goto-char rbeg)
2299 (and (org-at-heading-p)
2300 (>= (org-end-of-subtree t t) rend)))))
2301 (opt-plist (if subtree-p
2302 (org-export-add-subtree-options opt-plist rbeg)
2303 opt-plist))
2304 (custom-times org-display-custom-times)
2305 (org-ascii-current-indentation '(0 . 0))
2306 (level 0) line txt
2307 (umax nil)
2308 (umax-toc nil)
2309 (case-fold-search nil)
2310 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2311 (filename (concat (file-name-as-directory
2312 (org-export-directory :ascii opt-plist))
2313 (file-name-sans-extension
2314 (or (and subtree-p
2315 (org-entry-get (region-beginning)
2316 "EXPORT_FILE_NAME" t))
2317 (file-name-nondirectory bfname)))
2318 ".txt"))
2319 (filename (if (equal (file-truename filename)
2320 (file-truename bfname))
2321 (concat filename ".txt")
2322 filename))
2323 (buffer (find-file-noselect filename))
2324 (org-levels-open (make-vector org-level-max nil))
2325 (odd org-odd-levels-only)
2326 (date (plist-get opt-plist :date))
2327 (author (plist-get opt-plist :author))
2328 (title (or (and subtree-p (org-export-get-title-from-subtree))
2329 (plist-get opt-plist :title)
2330 (and (not
2331 (plist-get opt-plist :skip-before-1st-heading))
2332 (org-export-grab-title-from-buffer))
2333 (file-name-sans-extension
2334 (file-name-nondirectory bfname))))
2335 (email (plist-get opt-plist :email))
2336 (language (plist-get opt-plist :language))
2337 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2338 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2339 (todo nil)
2340 (lang-words nil)
2341 (region
2342 (buffer-substring
2343 (if (org-region-active-p) (region-beginning) (point-min))
2344 (if (org-region-active-p) (region-end) (point-max))))
2345 (lines (org-split-string
2346 (org-export-preprocess-string
2347 region
2348 :for-ascii t
2349 :skip-before-1st-heading
2350 (plist-get opt-plist :skip-before-1st-heading)
2351 :drawers (plist-get opt-plist :drawers)
2352 :tags (plist-get opt-plist :tags)
2353 :priority (plist-get opt-plist :priority)
2354 :todo-keywords (plist-get opt-plist :todo-keywords)
2355 :verbatim-multiline t
2356 :select-tags (plist-get opt-plist :select-tags)
2357 :exclude-tags (plist-get opt-plist :exclude-tags)
2358 :archived-trees
2359 (plist-get opt-plist :archived-trees)
2360 :add-text (plist-get opt-plist :text))
2361 "\n"))
2362 thetoc have-headings first-heading-pos
2363 table-open table-buffer)
2365 (let ((inhibit-read-only t))
2366 (org-unmodified
2367 (remove-text-properties (point-min) (point-max)
2368 '(:org-license-to-kill t))))
2370 (setq org-min-level (org-get-min-level lines))
2371 (setq org-last-level org-min-level)
2372 (org-init-section-numbers)
2374 (find-file-noselect filename)
2376 (setq lang-words (or (assoc language org-export-language-setup)
2377 (assoc "en" org-export-language-setup)))
2378 (switch-to-buffer-other-window buffer)
2379 (erase-buffer)
2380 (fundamental-mode)
2381 ;; create local variables for all options, to make sure all called
2382 ;; functions get the correct information
2383 (mapc (lambda (x)
2384 (set (make-local-variable (nth 2 x))
2385 (plist-get opt-plist (car x))))
2386 org-export-plist-vars)
2387 (org-set-local 'org-odd-levels-only odd)
2388 (setq umax (if arg (prefix-numeric-value arg)
2389 org-export-headline-levels))
2390 (setq umax-toc (if (integerp org-export-with-toc)
2391 (min org-export-with-toc umax)
2392 umax))
2394 ;; File header
2395 (if title (org-insert-centered title ?=))
2396 (insert "\n")
2397 (if (and (or author email)
2398 org-export-author-info)
2399 (insert (concat (nth 1 lang-words) ": " (or author "")
2400 (if email (concat " <" email ">") "")
2401 "\n")))
2403 (cond
2404 ((and date (string-match "%" date))
2405 (setq date (format-time-string date)))
2406 (date)
2407 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2409 (if (and date org-export-time-stamp-file)
2410 (insert (concat (nth 2 lang-words) ": " date"\n")))
2412 (insert "\n\n")
2414 (if org-export-with-toc
2415 (progn
2416 (push (concat (nth 3 lang-words) "\n") thetoc)
2417 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2418 "\n") thetoc)
2419 (mapc '(lambda (line)
2420 (if (string-match org-todo-line-regexp
2421 line)
2422 ;; This is a headline
2423 (progn
2424 (setq have-headings t)
2425 (setq level (- (match-end 1) (match-beginning 1))
2426 level (org-tr-level level)
2427 txt (match-string 3 line)
2428 todo
2429 (or (and org-export-mark-todo-in-toc
2430 (match-beginning 2)
2431 (not (member (match-string 2 line)
2432 org-done-keywords)))
2433 ; TODO, not DONE
2434 (and org-export-mark-todo-in-toc
2435 (= level umax-toc)
2436 (org-search-todo-below
2437 line lines level))))
2438 (setq txt (org-html-expand-for-ascii txt))
2440 (while (string-match org-bracket-link-regexp txt)
2441 (setq txt
2442 (replace-match
2443 (match-string (if (match-end 2) 3 1) txt)
2444 t t txt)))
2446 (if (and (memq org-export-with-tags '(not-in-toc nil))
2447 (string-match
2448 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2449 txt))
2450 (setq txt (replace-match "" t t txt)))
2451 (if (string-match quote-re0 txt)
2452 (setq txt (replace-match "" t t txt)))
2454 (if org-export-with-section-numbers
2455 (setq txt (concat (org-section-number level)
2456 " " txt)))
2457 (if (<= level umax-toc)
2458 (progn
2459 (push
2460 (concat
2461 (make-string
2462 (* (max 0 (- level org-min-level)) 4) ?\ )
2463 (format (if todo "%s (*)\n" "%s\n") txt))
2464 thetoc)
2465 (setq org-last-level level))
2466 ))))
2467 lines)
2468 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2470 (org-init-section-numbers)
2471 (while (setq line (pop lines))
2472 ;; Remove the quoted HTML tags.
2473 (setq line (org-html-expand-for-ascii line))
2474 ;; Replace links with the description when possible
2475 (while (string-match org-bracket-link-regexp line)
2476 (setq line (replace-match
2477 (if (match-end 3) "[\\3]" "[\\1]")
2478 t nil line)))
2479 (when custom-times
2480 (setq line (org-translate-time line)))
2481 (cond
2482 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2483 ;; a Headline
2484 (setq first-heading-pos (or first-heading-pos (point)))
2485 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2486 txt (match-string 2 line))
2487 (org-ascii-level-start level txt umax lines))
2489 ((and org-export-with-tables
2490 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2491 (if (not table-open)
2492 ;; New table starts
2493 (setq table-open t table-buffer nil))
2494 ;; Accumulate lines
2495 (setq table-buffer (cons line table-buffer))
2496 (when (or (not lines)
2497 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2498 (car lines))))
2499 (setq table-open nil
2500 table-buffer (nreverse table-buffer))
2501 (insert (mapconcat
2502 (lambda (x)
2503 (org-fix-indentation x org-ascii-current-indentation))
2504 (org-format-table-ascii table-buffer)
2505 "\n") "\n")))
2507 (setq line (org-fix-indentation line org-ascii-current-indentation))
2508 ;; Remove forced line breaks
2509 (if (string-match "\\\\\\\\[ \t]*$" line)
2510 (setq line (replace-match "" t t line)))
2511 (if (and org-export-with-fixed-width
2512 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2513 (setq line (replace-match "\\1" nil nil line)))
2514 (insert line "\n"))))
2516 (normal-mode)
2518 ;; insert the table of contents
2519 (when thetoc
2520 (goto-char (point-min))
2521 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2522 (progn
2523 (goto-char (match-beginning 0))
2524 (replace-match ""))
2525 (goto-char first-heading-pos))
2526 (mapc 'insert thetoc)
2527 (or (looking-at "[ \t]*\n[ \t]*\n")
2528 (insert "\n\n")))
2530 ;; Convert whitespace place holders
2531 (goto-char (point-min))
2532 (let (beg end)
2533 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2534 (setq end (next-single-property-change beg 'org-whitespace))
2535 (goto-char beg)
2536 (delete-region beg end)
2537 (insert (make-string (- end beg) ?\ ))))
2539 (save-buffer)
2540 ;; remove display and invisible chars
2541 (let (beg end)
2542 (goto-char (point-min))
2543 (while (setq beg (next-single-property-change (point) 'display))
2544 (setq end (next-single-property-change beg 'display))
2545 (delete-region beg end)
2546 (goto-char beg)
2547 (insert "=>"))
2548 (goto-char (point-min))
2549 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2550 (setq end (next-single-property-change beg 'org-cwidth))
2551 (delete-region beg end)
2552 (goto-char beg)))
2553 (goto-char (point-min))))
2555 (defun org-export-ascii-preprocess ()
2556 "Do extra work for ASCII export"
2557 ;; Put quotes around verbatim text
2558 (goto-char (point-min))
2559 (while (re-search-forward org-verbatim-re nil t)
2560 (goto-char (match-end 2))
2561 (backward-delete-char 1) (insert "'")
2562 (goto-char (match-beginning 2))
2563 (delete-char 1) (insert "`")
2564 (goto-char (match-end 2)))
2565 (goto-char (point-min))
2566 ;; Remove target markers
2567 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
2568 (replace-match "\\1\\2")))
2570 (defun org-search-todo-below (line lines level)
2571 "Search the subtree below LINE for any TODO entries."
2572 (let ((rest (cdr (memq line lines)))
2573 (re org-todo-line-regexp)
2574 line lv todo)
2575 (catch 'exit
2576 (while (setq line (pop rest))
2577 (if (string-match re line)
2578 (progn
2579 (setq lv (- (match-end 1) (match-beginning 1))
2580 todo (and (match-beginning 2)
2581 (not (member (match-string 2 line)
2582 org-done-keywords))))
2583 ; TODO, not DONE
2584 (if (<= lv level) (throw 'exit nil))
2585 (if todo (throw 'exit t))))))))
2587 (defun org-html-expand-for-ascii (line)
2588 "Handle quoted HTML for ASCII export."
2589 (if org-export-html-expand
2590 (while (string-match "@<[^<>\n]*>" line)
2591 ;; We just remove the tags for now.
2592 (setq line (replace-match "" nil nil line))))
2593 line)
2595 (defun org-insert-centered (s &optional underline)
2596 "Insert the string S centered and underline it with character UNDERLINE."
2597 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2598 (insert (make-string ind ?\ ) s "\n")
2599 (if underline
2600 (insert (make-string ind ?\ )
2601 (make-string (string-width s) underline)
2602 "\n"))))
2604 (defun org-ascii-level-start (level title umax &optional lines)
2605 "Insert a new level in ASCII export."
2606 (let (char (n (- level umax 1)) (ind 0))
2607 (if (> level umax)
2608 (progn
2609 (insert (make-string (* 2 n) ?\ )
2610 (char-to-string (nth (% n (length org-export-ascii-bullets))
2611 org-export-ascii-bullets))
2612 " " title "\n")
2613 ;; find the indentation of the next non-empty line
2614 (catch 'stop
2615 (while lines
2616 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2617 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2618 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2619 (pop lines)))
2620 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2621 (if (or (not (equal (char-before) ?\n))
2622 (not (equal (char-before (1- (point))) ?\n)))
2623 (insert "\n"))
2624 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2625 (unless org-export-with-tags
2626 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2627 (setq title (replace-match "" t t title))))
2628 (if org-export-with-section-numbers
2629 (setq title (concat (org-section-number level) " " title)))
2630 (insert title "\n" (make-string (string-width title) char) "\n")
2631 (setq org-ascii-current-indentation '(0 . 0)))))
2633 ;;;###autoload
2634 (defun org-export-visible (type arg)
2635 "Create a copy of the visible part of the current buffer, and export it.
2636 The copy is created in a temporary buffer and removed after use.
2637 TYPE is the final key (as a string) that also select the export command in
2638 the `C-c C-e' export dispatcher.
2639 As a special case, if the you type SPC at the prompt, the temporary
2640 org-mode file will not be removed but presented to you so that you can
2641 continue to use it. The prefix arg ARG is passed through to the exporting
2642 command."
2643 (interactive
2644 (list (progn
2645 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2646 (read-char-exclusive))
2647 current-prefix-arg))
2648 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2649 (error "Invalid export key"))
2650 (let* ((binding (cdr (assoc type
2651 '((?a . org-export-as-ascii)
2652 (?\C-a . org-export-as-ascii)
2653 (?b . org-export-as-html-and-open)
2654 (?\C-b . org-export-as-html-and-open)
2655 (?h . org-export-as-html)
2656 (?H . org-export-as-html-to-buffer)
2657 (?R . org-export-region-as-html)
2658 (?x . org-export-as-xoxo)))))
2659 (keepp (equal type ?\ ))
2660 (file buffer-file-name)
2661 (buffer (get-buffer-create "*Org Export Visible*"))
2662 s e)
2663 ;; Need to hack the drawers here.
2664 (save-excursion
2665 (goto-char (point-min))
2666 (while (re-search-forward org-drawer-regexp nil t)
2667 (goto-char (match-beginning 1))
2668 (or (org-invisible-p) (org-flag-drawer nil))))
2669 (with-current-buffer buffer (erase-buffer))
2670 (save-excursion
2671 (setq s (goto-char (point-min)))
2672 (while (not (= (point) (point-max)))
2673 (goto-char (org-find-invisible))
2674 (append-to-buffer buffer s (point))
2675 (setq s (goto-char (org-find-visible))))
2676 (org-cycle-hide-drawers 'all)
2677 (goto-char (point-min))
2678 (unless keepp
2679 ;; Copy all comment lines to the end, to make sure #+ settings are
2680 ;; still available for the second export step. Kind of a hack, but
2681 ;; does do the trick.
2682 (if (looking-at "#[^\r\n]*")
2683 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2684 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2685 (append-to-buffer buffer (1+ (match-beginning 0))
2686 (min (point-max) (1+ (match-end 0))))))
2687 (set-buffer buffer)
2688 (let ((buffer-file-name file)
2689 (org-inhibit-startup t))
2690 (org-mode)
2691 (show-all)
2692 (unless keepp (funcall binding arg))))
2693 (if (not keepp)
2694 (kill-buffer buffer)
2695 (switch-to-buffer-other-window buffer)
2696 (goto-char (point-min)))))
2698 (defun org-find-visible ()
2699 (let ((s (point)))
2700 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2701 (get-char-property s 'invisible)))
2703 (defun org-find-invisible ()
2704 (let ((s (point)))
2705 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2706 (not (get-char-property s 'invisible))))
2709 ;;; HTML export
2711 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2712 (defun org-get-current-options ()
2713 "Return a string with current options as keyword options.
2714 Does include HTML export options as well as TODO and CATEGORY stuff."
2715 (require 'org-archive)
2716 (format
2717 "#+TITLE: %s
2718 #+AUTHOR: %s
2719 #+EMAIL: %s
2720 #+DATE: %s
2721 #+LANGUAGE: %s
2722 #+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
2724 #+EXPORT_SELECT_TAGS: %s
2725 #+EXPORT_EXCLUDE_TAGS: %s
2726 #+LINK_UP: %s
2727 #+LINK_HOME: %s
2728 #+CATEGORY: %s
2729 #+SEQ_TODO: %s
2730 #+TYP_TODO: %s
2731 #+PRIORITIES: %c %c %c
2732 #+DRAWERS: %s
2733 #+STARTUP: %s %s %s %s %s
2734 #+TAGS: %s
2735 #+FILETAGS: %s
2736 #+ARCHIVE: %s
2737 #+LINK: %s
2739 (buffer-name) (user-full-name) user-mail-address
2740 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2741 org-export-default-language
2742 org-export-headline-levels
2743 org-export-with-section-numbers
2744 org-export-with-toc
2745 org-export-preserve-breaks
2746 org-export-html-expand
2747 org-export-with-fixed-width
2748 org-export-with-tables
2749 org-export-with-sub-superscripts
2750 org-export-with-special-strings
2751 org-export-with-footnotes
2752 org-export-with-emphasize
2753 org-export-with-TeX-macros
2754 org-export-with-LaTeX-fragments
2755 org-export-skip-text-before-1st-heading
2756 org-export-with-drawers
2757 org-export-with-todo-keywords
2758 org-export-with-priority
2759 org-export-with-tags
2760 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2761 (mapconcat 'identity org-export-select-tags " ")
2762 (mapconcat 'identity org-export-exclude-tags " ")
2763 org-export-html-link-up
2764 org-export-html-link-home
2765 (file-name-nondirectory buffer-file-name)
2766 "TODO FEEDBACK VERIFY DONE"
2767 "Me Jason Marie DONE"
2768 org-highest-priority org-lowest-priority org-default-priority
2769 (mapconcat 'identity org-drawers " ")
2770 (cdr (assoc org-startup-folded
2771 '((nil . "showall") (t . "overview") (content . "content"))))
2772 (if org-odd-levels-only "odd" "oddeven")
2773 (if org-hide-leading-stars "hidestars" "showstars")
2774 (if org-startup-align-all-tables "align" "noalign")
2775 (cond ((eq org-log-done t) "logdone")
2776 ((equal org-log-done 'note) "lognotedone")
2777 ((not org-log-done) "nologdone"))
2778 (or (mapconcat (lambda (x)
2779 (cond
2780 ((equal '(:startgroup) x) "{")
2781 ((equal '(:endgroup) x) "}")
2782 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2783 (t (car x))))
2784 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2785 (mapconcat 'identity org-file-tags " ")
2786 org-archive-location
2787 "org file:~/org/%s.org"
2790 (defun org-export-html-preprocess (parameters)
2791 ;; Convert LaTeX fragments to images
2792 (when (plist-get parameters :LaTeX-fragments)
2793 (org-format-latex
2794 (concat "ltxpng/" (file-name-sans-extension
2795 (file-name-nondirectory
2796 org-current-export-file)))
2797 org-current-export-dir nil "Creating LaTeX image %s"))
2798 (message "Exporting..."))
2800 ;;;###autoload
2801 (defun org-insert-export-options-template ()
2802 "Insert into the buffer a template with information for exporting."
2803 (interactive)
2804 (if (not (bolp)) (newline))
2805 (let ((s (org-get-current-options)))
2806 (and (string-match "#\\+CATEGORY" s)
2807 (setq s (substring s 0 (match-beginning 0))))
2808 (insert s)))
2810 ;;;###autoload
2811 (defun org-export-as-html-and-open (arg)
2812 "Export the outline as HTML and immediately open it with a browser.
2813 If there is an active region, export only the region.
2814 The prefix ARG specifies how many levels of the outline should become
2815 headlines. The default is 3. Lower levels will become bulleted lists."
2816 (interactive "P")
2817 (org-export-as-html arg 'hidden)
2818 (org-open-file buffer-file-name))
2820 ;;;###autoload
2821 (defun org-export-as-html-batch ()
2822 "Call `org-export-as-html', may be used in batch processing as
2823 emacs --batch
2824 --load=$HOME/lib/emacs/org.el
2825 --eval \"(setq org-export-headline-levels 2)\"
2826 --visit=MyFile --funcall org-export-as-html-batch"
2827 (org-export-as-html org-export-headline-levels 'hidden))
2829 ;;;###autoload
2830 (defun org-export-as-html-to-buffer (arg)
2831 "Call `org-export-as-html` with output to a temporary buffer.
2832 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2833 (interactive "P")
2834 (org-export-as-html arg nil nil "*Org HTML Export*")
2835 (switch-to-buffer-other-window "*Org HTML Export*"))
2837 ;;;###autoload
2838 (defun org-replace-region-by-html (beg end)
2839 "Assume the current region has org-mode syntax, and convert it to HTML.
2840 This can be used in any buffer. For example, you could write an
2841 itemized list in org-mode syntax in an HTML buffer and then use this
2842 command to convert it."
2843 (interactive "r")
2844 (let (reg html buf pop-up-frames)
2845 (save-window-excursion
2846 (if (org-mode-p)
2847 (setq html (org-export-region-as-html
2848 beg end t 'string))
2849 (setq reg (buffer-substring beg end)
2850 buf (get-buffer-create "*Org tmp*"))
2851 (with-current-buffer buf
2852 (erase-buffer)
2853 (insert reg)
2854 (org-mode)
2855 (setq html (org-export-region-as-html
2856 (point-min) (point-max) t 'string)))
2857 (kill-buffer buf)))
2858 (delete-region beg end)
2859 (insert html)))
2861 ;;;###autoload
2862 (defun org-export-region-as-html (beg end &optional body-only buffer)
2863 "Convert region from BEG to END in org-mode buffer to HTML.
2864 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2865 contents, and only produce the region of converted text, useful for
2866 cut-and-paste operations.
2867 If BUFFER is a buffer or a string, use/create that buffer as a target
2868 of the converted HTML. If BUFFER is the symbol `string', return the
2869 produced HTML as a string and leave not buffer behind. For example,
2870 a Lisp program could call this function in the following way:
2872 (setq html (org-export-region-as-html beg end t 'string))
2874 When called interactively, the output buffer is selected, and shown
2875 in a window. A non-interactive call will only return the buffer."
2876 (interactive "r\nP")
2877 (when (interactive-p)
2878 (setq buffer "*Org HTML Export*"))
2879 (let ((transient-mark-mode t) (zmacs-regions t)
2880 ext-plist rtn)
2881 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2882 (goto-char end)
2883 (set-mark (point)) ;; to activate the region
2884 (goto-char beg)
2885 (setq rtn (org-export-as-html
2886 nil nil ext-plist
2887 buffer body-only))
2888 (if (fboundp 'deactivate-mark) (deactivate-mark))
2889 (if (and (interactive-p) (bufferp rtn))
2890 (switch-to-buffer-other-window rtn)
2891 rtn)))
2893 (defvar html-table-tag nil) ; dynamically scoped into this.
2894 (defvar org-par-open nil)
2895 ;;;###autoload
2896 (defun org-export-as-html (arg &optional hidden ext-plist
2897 to-buffer body-only pub-dir)
2898 "Export the outline as a pretty HTML file.
2899 If there is an active region, export only the region. The prefix
2900 ARG specifies how many levels of the outline should become
2901 headlines. The default is 3. Lower levels will become bulleted
2902 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2903 EXT-PLIST is a property list with external parameters overriding
2904 org-mode's default settings, but still inferior to file-local
2905 settings. When TO-BUFFER is non-nil, create a buffer with that
2906 name and export to that buffer. If TO-BUFFER is the symbol
2907 `string', don't leave any buffer behind but just return the
2908 resulting HTML as a string. When BODY-ONLY is set, don't produce
2909 the file header and footer, simply return the content of
2910 <body>...</body>, without even the body tags themselves. When
2911 PUB-DIR is set, use this as the publishing directory."
2912 (interactive "P")
2914 ;; Make sure we have a file name when we need it.
2915 (when (and (not (or to-buffer body-only))
2916 (not buffer-file-name))
2917 (if (buffer-base-buffer)
2918 (org-set-local 'buffer-file-name
2919 (with-current-buffer (buffer-base-buffer)
2920 buffer-file-name))
2921 (error "Need a file name to be able to export.")))
2923 (message "Exporting...")
2924 (setq-default org-todo-line-regexp org-todo-line-regexp)
2925 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2926 (setq-default org-done-keywords org-done-keywords)
2927 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2928 (let* ((opt-plist
2929 (org-export-process-option-filters
2930 (org-combine-plists (org-default-export-plist)
2931 ext-plist
2932 (org-infile-export-plist))))
2933 (style (concat (if (plist-get opt-plist :style-include-default)
2934 org-export-html-style-default)
2935 (plist-get opt-plist :style)
2936 (plist-get opt-plist :style-extra)))
2937 (html-extension (plist-get opt-plist :html-extension))
2938 (link-validate (plist-get opt-plist :link-validation-function))
2939 valid thetoc have-headings first-heading-pos
2940 (odd org-odd-levels-only)
2941 (region-p (org-region-active-p))
2942 (rbeg (and region-p (region-beginning)))
2943 (rend (and region-p (region-end)))
2944 (subtree-p
2945 (if (plist-get opt-plist :ignore-subree-p)
2947 (when region-p
2948 (save-excursion
2949 (goto-char rbeg)
2950 (and (org-at-heading-p)
2951 (>= (org-end-of-subtree t t) rend))))))
2952 (opt-plist (if subtree-p
2953 (org-export-add-subtree-options opt-plist rbeg)
2954 opt-plist))
2955 ;; The following two are dynamically scoped into other
2956 ;; routines below.
2957 (org-current-export-dir
2958 (or pub-dir (org-export-directory :html opt-plist)))
2959 (org-current-export-file buffer-file-name)
2960 (level 0) (line "") (origline "") txt todo
2961 (umax nil)
2962 (umax-toc nil)
2963 (filename (if to-buffer nil
2964 (expand-file-name
2965 (concat
2966 (file-name-sans-extension
2967 (or (and subtree-p
2968 (org-entry-get (region-beginning)
2969 "EXPORT_FILE_NAME" t))
2970 (file-name-nondirectory buffer-file-name)))
2971 "." html-extension)
2972 (file-name-as-directory
2973 (or pub-dir (org-export-directory :html opt-plist))))))
2974 (current-dir (if buffer-file-name
2975 (file-name-directory buffer-file-name)
2976 default-directory))
2977 (buffer (if to-buffer
2978 (cond
2979 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2980 (t (get-buffer-create to-buffer)))
2981 (find-file-noselect filename)))
2982 (org-levels-open (make-vector org-level-max nil))
2983 (date (plist-get opt-plist :date))
2984 (author (plist-get opt-plist :author))
2985 (title (or (and subtree-p (org-export-get-title-from-subtree))
2986 (plist-get opt-plist :title)
2987 (and (not
2988 (plist-get opt-plist :skip-before-1st-heading))
2989 (org-export-grab-title-from-buffer))
2990 (and buffer-file-name
2991 (file-name-sans-extension
2992 (file-name-nondirectory buffer-file-name)))
2993 "UNTITLED"))
2994 (html-table-tag (plist-get opt-plist :html-table-tag))
2995 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2996 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2997 (inquote nil)
2998 (infixed nil)
2999 (inverse nil)
3000 (in-local-list nil)
3001 (local-list-type nil)
3002 (local-list-indent nil)
3003 (llt org-plain-list-ordered-item-terminator)
3004 (email (plist-get opt-plist :email))
3005 (language (plist-get opt-plist :language))
3006 (lang-words nil)
3007 (head-count 0) cnt
3008 (start 0)
3009 (coding-system (and (boundp 'buffer-file-coding-system)
3010 buffer-file-coding-system))
3011 (coding-system-for-write (or org-export-html-coding-system
3012 coding-system))
3013 (save-buffer-coding-system (or org-export-html-coding-system
3014 coding-system))
3015 (charset (and coding-system-for-write
3016 (fboundp 'coding-system-get)
3017 (coding-system-get coding-system-for-write
3018 'mime-charset)))
3019 (region
3020 (buffer-substring
3021 (if region-p (region-beginning) (point-min))
3022 (if region-p (region-end) (point-max))))
3023 (lines
3024 (org-split-string
3025 (org-export-preprocess-string
3026 region
3027 :emph-multiline t
3028 :for-html t
3029 :skip-before-1st-heading
3030 (plist-get opt-plist :skip-before-1st-heading)
3031 :drawers (plist-get opt-plist :drawers)
3032 :todo-keywords (plist-get opt-plist :todo-keywords)
3033 :tags (plist-get opt-plist :tags)
3034 :priority (plist-get opt-plist :priority)
3035 :archived-trees
3036 (plist-get opt-plist :archived-trees)
3037 :select-tags (plist-get opt-plist :select-tags)
3038 :exclude-tags (plist-get opt-plist :exclude-tags)
3039 :add-text
3040 (plist-get opt-plist :text)
3041 :LaTeX-fragments
3042 (plist-get opt-plist :LaTeX-fragments))
3043 "[\r\n]"))
3044 table-open type
3045 table-buffer table-orig-buffer
3046 ind item-type starter didclose
3047 rpl path attr desc descp desc1 desc2 link
3048 snumber fnc item-tag
3049 footnotes
3052 (let ((inhibit-read-only t))
3053 (org-unmodified
3054 (remove-text-properties (point-min) (point-max)
3055 '(:org-license-to-kill t))))
3057 (message "Exporting...")
3059 (setq org-min-level (org-get-min-level lines))
3060 (setq org-last-level org-min-level)
3061 (org-init-section-numbers)
3063 (cond
3064 ((and date (string-match "%" date))
3065 (setq date (format-time-string date)))
3066 (date)
3067 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3069 ;; Get the language-dependent settings
3070 (setq lang-words (or (assoc language org-export-language-setup)
3071 (assoc "en" org-export-language-setup)))
3073 ;; Switch to the output buffer
3074 (set-buffer buffer)
3075 (let ((inhibit-read-only t)) (erase-buffer))
3076 (fundamental-mode)
3078 (and (fboundp 'set-buffer-file-coding-system)
3079 (set-buffer-file-coding-system coding-system-for-write))
3081 (let ((case-fold-search nil)
3082 (org-odd-levels-only odd))
3083 ;; create local variables for all options, to make sure all called
3084 ;; functions get the correct information
3085 (mapc (lambda (x)
3086 (set (make-local-variable (nth 2 x))
3087 (plist-get opt-plist (car x))))
3088 org-export-plist-vars)
3089 (setq umax (if arg (prefix-numeric-value arg)
3090 org-export-headline-levels))
3091 (setq umax-toc (if (integerp org-export-with-toc)
3092 (min org-export-with-toc umax)
3093 umax))
3094 (unless body-only
3095 ;; File header
3096 (insert (format
3097 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3098 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3099 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3100 lang=\"%s\" xml:lang=\"%s\">
3101 <head>
3102 <title>%s</title>
3103 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3104 <meta name=\"generator\" content=\"Org-mode\"/>
3105 <meta name=\"generated\" content=\"%s\"/>
3106 <meta name=\"author\" content=\"%s\"/>
3108 </head><body>
3110 language language (org-html-expand title)
3111 (or charset "iso-8859-1") date author style))
3113 (insert (or (plist-get opt-plist :preamble) ""))
3115 (when (plist-get opt-plist :auto-preamble)
3116 (if title (insert (format org-export-html-title-format
3117 (org-html-expand title))))))
3119 (if (and org-export-with-toc (not body-only))
3120 (progn
3121 (push (format "<h%d>%s</h%d>\n"
3122 org-export-html-toplevel-hlevel
3123 (nth 3 lang-words)
3124 org-export-html-toplevel-hlevel)
3125 thetoc)
3126 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3127 (push "<ul>\n<li>" thetoc)
3128 (setq lines
3129 (mapcar '(lambda (line)
3130 (if (string-match org-todo-line-regexp line)
3131 ;; This is a headline
3132 (progn
3133 (setq have-headings t)
3134 (setq level (- (match-end 1) (match-beginning 1))
3135 level (org-tr-level level)
3136 txt (save-match-data
3137 (org-html-expand
3138 (org-export-cleanup-toc-line
3139 (match-string 3 line))))
3140 todo
3141 (or (and org-export-mark-todo-in-toc
3142 (match-beginning 2)
3143 (not (member (match-string 2 line)
3144 org-done-keywords)))
3145 ; TODO, not DONE
3146 (and org-export-mark-todo-in-toc
3147 (= level umax-toc)
3148 (org-search-todo-below
3149 line lines level))))
3150 (if (string-match
3151 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3152 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3153 (if (string-match quote-re0 txt)
3154 (setq txt (replace-match "" t t txt)))
3155 (setq snumber (org-section-number level))
3156 (if org-export-with-section-numbers
3157 (setq txt (concat snumber " " txt)))
3158 (if (<= level (max umax umax-toc))
3159 (setq head-count (+ head-count 1)))
3160 (if (<= level umax-toc)
3161 (progn
3162 (if (> level org-last-level)
3163 (progn
3164 (setq cnt (- level org-last-level))
3165 (while (>= (setq cnt (1- cnt)) 0)
3166 (push "\n<ul>\n<li>" thetoc))
3167 (push "\n" thetoc)))
3168 (if (< level org-last-level)
3169 (progn
3170 (setq cnt (- org-last-level level))
3171 (while (>= (setq cnt (1- cnt)) 0)
3172 (push "</li>\n</ul>" thetoc))
3173 (push "\n" thetoc)))
3174 ;; Check for targets
3175 (while (string-match org-any-target-regexp line)
3176 (setq line (replace-match
3177 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3178 t t line)))
3179 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3180 (setq txt (replace-match "" t t txt)))
3181 (push
3182 (format
3183 (if todo
3184 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3185 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3186 snumber txt) thetoc)
3188 (setq org-last-level level))
3190 line)
3191 lines))
3192 (while (> org-last-level (1- org-min-level))
3193 (setq org-last-level (1- org-last-level))
3194 (push "</li>\n</ul>\n" thetoc))
3195 (push "</div>\n" thetoc)
3196 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3198 (setq head-count 0)
3199 (org-init-section-numbers)
3201 (org-open-par)
3203 (while (setq line (pop lines) origline line)
3204 (catch 'nextline
3206 ;; end of quote section?
3207 (when (and inquote (string-match "^\\*+ " line))
3208 (insert "</pre>\n")
3209 (setq inquote nil))
3210 ;; inside a quote section?
3211 (when inquote
3212 (insert (org-html-protect line) "\n")
3213 (throw 'nextline nil))
3215 ;; Fixed-width, verbatim lines (examples)
3216 (when (and org-export-with-fixed-width
3217 (string-match "^[ \t]*:\\(.*\\)" line))
3218 (when (not infixed)
3219 (setq infixed t)
3220 (org-close-par-maybe)
3221 (insert "<pre class=\"example\">\n"))
3222 (insert (org-html-protect (match-string 1 line)) "\n")
3223 (when (or (not lines)
3224 (not (string-match "^[ \t]*\\(:.*\\)"
3225 (car lines))))
3226 (setq infixed nil)
3227 (insert "</pre>\n"))
3228 (throw 'nextline nil))
3230 ;; Protected HTML
3231 (when (get-text-property 0 'org-protected line)
3232 (let (par)
3233 (when (re-search-backward
3234 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3235 (setq par (match-string 1))
3236 (replace-match "\\2\n"))
3237 (insert line "\n")
3238 (while (and lines
3239 (not (string-match "^[ \t]*:" (car lines)))
3240 (or (= (length (car lines)) 0)
3241 (get-text-property 0 'org-protected (car lines))))
3242 (insert (pop lines) "\n"))
3243 (and par (insert "<p>\n")))
3244 (throw 'nextline nil))
3246 ;; Horizontal line
3247 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3248 (if org-par-open
3249 (insert "\n</p>\n<hr/>\n<p>\n")
3250 (insert "\n<hr/>\n"))
3251 (throw 'nextline nil))
3253 ;; Blockquotes and verse
3254 (when (equal "ORG-BLOCKQUOTE-START" line)
3255 (org-close-par-maybe)
3256 (insert "<blockquote>\n<p>\n")
3257 (throw 'nextline nil))
3258 (when (equal "ORG-BLOCKQUOTE-END" line)
3259 (insert "</p>\n</blockquote>\n")
3260 (throw 'nextline nil))
3261 (when (equal "ORG-VERSE-START" line)
3262 (org-close-par-maybe)
3263 (insert "\n<p class=\"verse\">\n")
3264 (setq inverse t)
3265 (throw 'nextline nil))
3266 (when (equal "ORG-VERSE-END" line)
3267 (insert "</p>\n")
3268 (setq inverse nil)
3269 (throw 'nextline nil))
3270 (when inverse
3271 (let ((i (org-get-string-indentation line)))
3272 (if (> i 0)
3273 (setq line (concat (mapconcat 'identity
3274 (make-list (* 2 i) "\\nbsp") "")
3275 " " (org-trim line))))
3276 (setq line (concat line "\\\\"))))
3278 ;; make targets to anchors
3279 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3280 (cond
3281 ((match-end 2)
3282 (setq line (replace-match
3283 (format
3284 "@<a name=\"%s\" id=\"%s\">@</a>"
3285 (org-solidify-link-text (match-string 1 line))
3286 (org-solidify-link-text (match-string 1 line)))
3287 t t line)))
3288 ((and org-export-with-toc (equal (string-to-char line) ?*))
3289 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3290 (setq line (replace-match
3291 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3292 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3293 t t line)))
3295 (setq line (replace-match
3296 (concat "@<a name=\""
3297 (org-solidify-link-text (match-string 1 line))
3298 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3299 t t line)))))
3301 (setq line (org-html-handle-time-stamps line))
3303 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3304 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3305 ;; Also handle sub_superscripts and checkboxes
3306 (or (string-match org-table-hline-regexp line)
3307 (setq line (org-html-expand line)))
3309 ;; Format the links
3310 (setq start 0)
3311 (while (string-match org-bracket-link-analytic-regexp line start)
3312 (setq start (match-beginning 0))
3313 (setq path (save-match-data (org-link-unescape
3314 (match-string 3 line))))
3315 (setq type (cond
3316 ((match-end 2) (match-string 2 line))
3317 ((save-match-data
3318 (or (file-name-absolute-p path)
3319 (string-match "^\\.\\.?/" path)))
3320 "file")
3321 (t "internal")))
3322 (setq path (org-extract-attributes (org-link-unescape path)))
3323 (setq attr (get-text-property 0 'org-attributes path))
3324 (setq desc1 (if (match-end 5) (match-string 5 line))
3325 desc2 (if (match-end 2) (concat type ":" path) path)
3326 descp (and desc1 (not (equal desc1 desc2)))
3327 desc (or desc1 desc2))
3328 ;; Make an image out of the description if that is so wanted
3329 (when (and descp (org-file-image-p desc))
3330 (save-match-data
3331 (if (string-match "^file:" desc)
3332 (setq desc (substring desc (match-end 0)))))
3333 (setq desc (org-add-props
3334 (concat "<img src=\"" desc "\"/>")
3335 '(org-protected t))))
3336 ;; FIXME: do we need to unescape here somewhere?
3337 (cond
3338 ((equal type "internal")
3339 (setq rpl
3340 (concat
3341 "<a href=\"#"
3342 (org-solidify-link-text
3343 (save-match-data (org-link-unescape path)) nil)
3344 "\"" attr ">"
3345 (org-export-html-format-desc desc)
3346 "</a>")))
3347 ((member type '("http" "https"))
3348 ;; standard URL, just check if we need to inline an image
3349 (if (and (or (eq t org-export-html-inline-images)
3350 (and org-export-html-inline-images (not descp)))
3351 (org-file-image-p path))
3352 (setq rpl (org-export-html-format-image
3353 (concat type ":" path)))
3354 (setq link (concat type ":" path))
3355 (setq rpl (concat "<a href=\""
3356 (org-export-html-format-href link)
3357 "\"" attr ">"
3358 (org-export-html-format-desc desc)
3359 "</a>"))))
3360 ((member type '("ftp" "mailto" "news"))
3361 ;; standard URL
3362 (setq link (concat type ":" path))
3363 (setq rpl (concat "<a href=\""
3364 (org-export-html-format-href link)
3365 "\"" attr ">"
3366 (org-export-html-format-desc desc)
3367 "</a>")))
3369 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3370 ;; The link protocol has a function for format the link
3371 (setq rpl
3372 (save-match-data
3373 (funcall fnc (org-link-unescape path) desc1 'html))))
3375 ((string= type "file")
3376 ;; FILE link
3377 (let* ((filename path)
3378 (abs-p (file-name-absolute-p filename))
3379 thefile file-is-image-p search)
3380 (save-match-data
3381 (if (string-match "::\\(.*\\)" filename)
3382 (setq search (match-string 1 filename)
3383 filename (replace-match "" t nil filename)))
3384 (setq valid
3385 (if (functionp link-validate)
3386 (funcall link-validate filename current-dir)
3388 (setq file-is-image-p (org-file-image-p filename))
3389 (setq thefile (if abs-p (expand-file-name filename) filename))
3390 (when (and org-export-html-link-org-files-as-html
3391 (string-match "\\.org$" thefile))
3392 (setq thefile (concat (substring thefile 0
3393 (match-beginning 0))
3394 "." html-extension))
3395 (if (and search
3396 ;; make sure this is can be used as target search
3397 (not (string-match "^[0-9]*$" search))
3398 (not (string-match "^\\*" search))
3399 (not (string-match "^/.*/$" search)))
3400 (setq thefile (concat thefile "#"
3401 (org-solidify-link-text
3402 (org-link-unescape search)))))
3403 (when (string-match "^file:" desc)
3404 (setq desc (replace-match "" t t desc))
3405 (if (string-match "\\.org$" desc)
3406 (setq desc (replace-match "" t t desc))))))
3407 (setq rpl (if (and file-is-image-p
3408 (or (eq t org-export-html-inline-images)
3409 (and org-export-html-inline-images
3410 (not descp))))
3411 (org-export-html-format-image thefile)
3412 (concat "<a href=\"" thefile "\"" attr ">"
3413 (org-export-html-format-desc desc)
3414 "</a>")))
3415 (if (not valid) (setq rpl desc))))
3418 ;; just publish the path, as default
3419 (setq rpl (concat "<i>&lt;" type ":"
3420 (save-match-data (org-link-unescape path))
3421 "&gt;</i>"))))
3422 (setq line (replace-match rpl t t line)
3423 start (+ start (length rpl))))
3425 ;; TODO items
3426 (if (and (string-match org-todo-line-regexp line)
3427 (match-beginning 2))
3429 (setq line
3430 (concat (substring line 0 (match-beginning 2))
3431 "<span class=\""
3432 (if (member (match-string 2 line)
3433 org-done-keywords)
3434 "done" "todo")
3435 "\">" (match-string 2 line)
3436 "</span>" (substring line (match-end 2)))))
3438 ;; Does this contain a reference to a footnote?
3439 (when org-export-with-footnotes
3440 (setq start 0)
3441 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3442 (if (get-text-property (match-beginning 2) 'org-protected line)
3443 (setq start (match-end 2))
3444 (let ((n (match-string 2 line)))
3445 (setq line
3446 (replace-match
3447 (format
3448 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3449 (match-string 1 line) n n n)
3450 t t line))))))
3452 (cond
3453 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3454 ;; This is a headline
3455 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3456 txt (match-string 2 line))
3457 (if (string-match quote-re0 txt)
3458 (setq txt (replace-match "" t t txt)))
3459 (if (<= level (max umax umax-toc))
3460 (setq head-count (+ head-count 1)))
3461 (when in-local-list
3462 ;; Close any local lists before inserting a new header line
3463 (while local-list-type
3464 (org-close-li (car local-list-type))
3465 (insert (format "</%sl>\n" (car local-list-type)))
3466 (pop local-list-type))
3467 (setq local-list-indent nil
3468 in-local-list nil))
3469 (setq first-heading-pos (or first-heading-pos (point)))
3470 (org-html-level-start level txt umax
3471 (and org-export-with-toc (<= level umax))
3472 head-count)
3473 ;; QUOTES
3474 (when (string-match quote-re line)
3475 (org-close-par-maybe)
3476 (insert "<pre>")
3477 (setq inquote t)))
3479 ((and org-export-with-tables
3480 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3481 (if (not table-open)
3482 ;; New table starts
3483 (setq table-open t table-buffer nil table-orig-buffer nil))
3484 ;; Accumulate lines
3485 (setq table-buffer (cons line table-buffer)
3486 table-orig-buffer (cons origline table-orig-buffer))
3487 (when (or (not lines)
3488 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3489 (car lines))))
3490 (setq table-open nil
3491 table-buffer (nreverse table-buffer)
3492 table-orig-buffer (nreverse table-orig-buffer))
3493 (org-close-par-maybe)
3494 (insert (org-format-table-html table-buffer table-orig-buffer))))
3496 ;; Normal lines
3497 (when (string-match
3498 (cond
3499 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3500 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3501 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3502 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3503 line)
3504 (setq ind (org-get-string-indentation line)
3505 item-type (if (match-beginning 4) "o" "u")
3506 starter (if (match-beginning 2)
3507 (substring (match-string 2 line) 0 -1))
3508 line (substring line (match-beginning 5))
3509 item-tag nil)
3510 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3511 (setq item-type "d"
3512 item-tag (match-string 1 line)
3513 line (substring line (match-end 0))))
3514 (when (and (not (equal item-type "d"))
3515 (not (string-match "[^ \t]" line)))
3516 ;; empty line. Pretend indentation is large.
3517 (setq ind (if org-empty-line-terminates-plain-lists
3519 (1+ (or (car local-list-indent) 1)))))
3520 (setq didclose nil)
3521 (while (and in-local-list
3522 (or (and (= ind (car local-list-indent))
3523 (not starter))
3524 (< ind (car local-list-indent))))
3525 (setq didclose t)
3526 (org-close-li (car local-list-type))
3527 (insert (format "</%sl>\n" (car local-list-type)))
3528 (pop local-list-type) (pop local-list-indent)
3529 (setq in-local-list local-list-indent))
3530 (cond
3531 ((and starter
3532 (or (not in-local-list)
3533 (> ind (car local-list-indent))))
3534 ;; Start new (level of) list
3535 (org-close-par-maybe)
3536 (insert (cond
3537 ((equal item-type "u") "<ul>\n<li>\n")
3538 ((equal item-type "o") "<ol>\n<li>\n")
3539 ((equal item-type "d")
3540 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3541 (push item-type local-list-type)
3542 (push ind local-list-indent)
3543 (setq in-local-list t))
3544 (starter
3545 ;; continue current list
3546 (org-close-li (car local-list-type))
3547 (insert (cond
3548 ((equal (car local-list-type) "d")
3549 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3550 (t "<li>\n"))))
3551 (didclose
3552 ;; we did close a list, normal text follows: need <p>
3553 (org-open-par)))
3554 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3555 (setq line
3556 (replace-match
3557 (if (equal (match-string 1 line) "X")
3558 "<b>[X]</b>"
3559 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3560 t t line))))
3562 ;; Empty lines start a new paragraph. If hand-formatted lists
3563 ;; are not fully interpreted, lines starting with "-", "+", "*"
3564 ;; also start a new paragraph.
3565 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3567 ;; Is this the start of a footnote?
3568 (when org-export-with-footnotes
3569 (when (and (boundp 'footnote-section-tag-regexp)
3570 (string-match (concat "^" footnote-section-tag-regexp)
3571 line))
3572 ;; ignore this line
3573 (throw 'nextline nil))
3574 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3575 (org-close-par-maybe)
3576 (let ((n (match-string 1 line)))
3577 (setq org-par-open t
3578 line (replace-match
3579 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
3581 ;; Check if the line break needs to be conserved
3582 (cond
3583 ((string-match "\\\\\\\\[ \t]*$" line)
3584 (setq line (replace-match "<br/>" t t line)))
3585 (org-export-preserve-breaks
3586 (setq line (concat line "<br/>"))))
3588 (insert line "\n")))))
3590 ;; Properly close all local lists and other lists
3591 (when inquote
3592 (insert "</pre>\n")
3593 (org-open-par))
3594 (when in-local-list
3595 ;; Close any local lists before inserting a new header line
3596 (while local-list-type
3597 (org-close-li (car local-list-type))
3598 (insert (format "</%sl>\n" (car local-list-type)))
3599 (pop local-list-type))
3600 (setq local-list-indent nil
3601 in-local-list nil))
3602 (org-html-level-start 1 nil umax
3603 (and org-export-with-toc (<= level umax))
3604 head-count)
3605 ;; the </div> to close the last text-... div.
3606 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
3608 (save-excursion
3609 (goto-char (point-min))
3610 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
3611 (push (match-string 0) footnotes)
3612 (replace-match "" t t)))
3613 (when footnotes
3614 (insert (format org-export-html-footnotes-section
3615 (or (nth 4 lang-words) "Footnotes")
3616 (mapconcat 'identity (nreverse footnotes) "\n"))
3617 "\n"))
3618 (unless body-only
3619 (when (plist-get opt-plist :auto-postamble)
3620 (insert "<div id=\"postamble\">")
3621 (when (and org-export-author-info author)
3622 (insert "<p class=\"author\"> "
3623 (nth 1 lang-words) ": " author "\n")
3624 (when email
3625 (if (listp (split-string email ",+ *"))
3626 (mapc (lambda(e)
3627 (insert "<a href=\"mailto:" e "\">&lt;"
3628 e "&gt;</a>\n"))
3629 (split-string email ",+ *"))
3630 (insert "<a href=\"mailto:" email "\">&lt;"
3631 email "&gt;</a>\n")))
3632 (insert "</p>\n"))
3633 (when (and date org-export-time-stamp-file)
3634 (insert "<p class=\"date\"> "
3635 (nth 2 lang-words) ": "
3636 date "</p>\n"))
3637 (when org-export-creator-info
3638 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3639 org-version emacs-major-version)))
3640 (insert "</div>"))
3642 (if org-export-html-with-timestamp
3643 (insert org-export-html-html-helper-timestamp))
3644 (insert (or (plist-get opt-plist :postamble) ""))
3645 (insert "</body>\n</html>\n"))
3647 (unless (plist-get opt-plist :buffer-will-be-killed)
3648 (normal-mode)
3649 (if (eq major-mode default-major-mode) (html-mode)))
3651 ;; insert the table of contents
3652 (goto-char (point-min))
3653 (when thetoc
3654 (if (or (re-search-forward
3655 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3656 (re-search-forward
3657 "\\[TABLE-OF-CONTENTS\\]" nil t))
3658 (progn
3659 (goto-char (match-beginning 0))
3660 (replace-match ""))
3661 (goto-char first-heading-pos)
3662 (when (looking-at "\\s-*</p>")
3663 (goto-char (match-end 0))
3664 (insert "\n")))
3665 (insert "<div id=\"table-of-contents\">\n")
3666 (mapc 'insert thetoc)
3667 (insert "</div>\n"))
3668 ;; remove empty paragraphs and lists
3669 (goto-char (point-min))
3670 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3671 (replace-match ""))
3672 (goto-char (point-min))
3673 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3674 (replace-match ""))
3675 (goto-char (point-min))
3676 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3677 (replace-match ""))
3678 ;; Convert whitespace place holders
3679 (goto-char (point-min))
3680 (let (beg end n)
3681 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3682 (setq n (get-text-property beg 'org-whitespace)
3683 end (next-single-property-change beg 'org-whitespace))
3684 (goto-char beg)
3685 (delete-region beg end)
3686 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3687 (make-string n ?x)))))
3688 (or to-buffer (save-buffer))
3689 (goto-char (point-min))
3690 (message "Exporting... done")
3691 (if (eq to-buffer 'string)
3692 (prog1 (buffer-substring (point-min) (point-max))
3693 (kill-buffer (current-buffer)))
3694 (current-buffer)))))
3696 (defun org-export-html-format-href (s)
3697 "Make sure the S is valid as a href reference in an XHTML document."
3698 (save-match-data
3699 (let ((start 0))
3700 (while (string-match "&" s start)
3701 (setq start (+ (match-beginning 0) 3)
3702 s (replace-match "&amp;" t t s)))))
3705 (defun org-export-html-format-desc (s)
3706 "Make sure the S is valid as a description in a link."
3707 (if (and s (not (get-text-property 1 'org-protected s)))
3708 (save-match-data
3709 (org-html-do-expand s))
3712 (defun org-export-html-format-image (src)
3713 "Create image tag with source and attributes."
3714 (save-match-data
3715 (let* ((caption (org-find-text-property-in-string 'org-caption src))
3716 (attr (org-find-text-property-in-string 'org-attributes src))
3717 (label (org-find-text-property-in-string 'org-label src)))
3718 (format "<div %sclass=\"figure\">
3719 <p><img src=\"%s\"%s></p>%s
3720 </div>"
3721 (if label (format "id=\"%s\" " label) "")
3723 (if (string-match "\\<alt=" (or attr ""))
3724 (concat " " attr )
3725 (concat " " attr " alt=\"" src "\""))
3726 (if caption (concat "\n<p>" caption "</p>") "")))))
3728 (defvar org-table-colgroup-info nil)
3729 (defun org-format-table-ascii (lines)
3730 "Format a table for ascii export."
3731 (if (stringp lines)
3732 (setq lines (org-split-string lines "\n")))
3733 (if (not (string-match "^[ \t]*|" (car lines)))
3734 ;; Table made by table.el - test for spanning
3735 lines
3737 ;; A normal org table
3738 ;; Get rid of hlines at beginning and end
3739 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3740 (setq lines (nreverse lines))
3741 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3742 (setq lines (nreverse lines))
3743 (when org-export-table-remove-special-lines
3744 ;; Check if the table has a marking column. If yes remove the
3745 ;; column and the special lines
3746 (setq lines (org-table-clean-before-export lines)))
3747 ;; Get rid of the vertical lines except for grouping
3748 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3749 rtn line vl1 start)
3750 (while (setq line (pop lines))
3751 (if (string-match org-table-hline-regexp line)
3752 (and (string-match "|\\(.*\\)|" line)
3753 (setq line (replace-match " \\1" t nil line)))
3754 (setq start 0 vl1 vl)
3755 (while (string-match "|" line start)
3756 (setq start (match-end 0))
3757 (or (pop vl1) (setq line (replace-match " " t t line)))))
3758 (push line rtn))
3759 (nreverse rtn))))
3761 (defun org-colgroup-info-to-vline-list (info)
3762 (let (vl new last)
3763 (while info
3764 (setq last new new (pop info))
3765 (if (or (memq last '(:end :startend))
3766 (memq new '(:start :startend)))
3767 (push t vl)
3768 (push nil vl)))
3769 (setq vl (nreverse vl))
3770 (and vl (setcar vl nil))
3771 vl))
3773 (defvar org-table-number-regexp) ; defined in org-table.el
3774 (defun org-format-table-html (lines olines)
3775 "Find out which HTML converter to use and return the HTML code."
3776 (if (stringp lines)
3777 (setq lines (org-split-string lines "\n")))
3778 (if (string-match "^[ \t]*|" (car lines))
3779 ;; A normal org table
3780 (org-format-org-table-html lines)
3781 ;; Table made by table.el - test for spanning
3782 (let* ((hlines (delq nil (mapcar
3783 (lambda (x)
3784 (if (string-match "^[ \t]*\\+-" x) x
3785 nil))
3786 lines)))
3787 (first (car hlines))
3788 (ll (and (string-match "\\S-+" first)
3789 (match-string 0 first)))
3790 (re (concat "^[ \t]*" (regexp-quote ll)))
3791 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3792 hlines))))
3793 (if (and (not spanning)
3794 (not org-export-prefer-native-exporter-for-tables))
3795 ;; We can use my own converter with HTML conversions
3796 (org-format-table-table-html lines)
3797 ;; Need to use the code generator in table.el, with the original text.
3798 (org-format-table-table-html-using-table-generate-source olines)))))
3800 (defvar org-table-number-fraction) ; defined in org-table.el
3801 (defun org-format-org-table-html (lines &optional splice)
3802 "Format a table into HTML."
3803 (require 'org-table)
3804 ;; Get rid of hlines at beginning and end
3805 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3806 (setq lines (nreverse lines))
3807 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3808 (setq lines (nreverse lines))
3809 (when org-export-table-remove-special-lines
3810 ;; Check if the table has a marking column. If yes remove the
3811 ;; column and the special lines
3812 (setq lines (org-table-clean-before-export lines)))
3814 (let ((caption (or (get-text-property 0 'org-caption (car lines))
3815 (get-text-property (or (next-single-property-change
3816 0 'org-caption (car lines))
3818 'org-caption (car lines))))
3819 (head (and org-export-highlight-first-table-line
3820 (delq nil (mapcar
3821 (lambda (x) (string-match "^[ \t]*|-" x))
3822 (cdr lines)))))
3824 (nlines 0) fnum i
3825 tbopen line fields html gr colgropen)
3826 (if splice (setq head nil))
3827 (unless splice (push (if head "<thead>" "<tbody>") html))
3828 (setq tbopen t)
3829 (while (setq line (pop lines))
3830 (catch 'next-line
3831 (if (string-match "^[ \t]*|-" line)
3832 (progn
3833 (unless splice
3834 (push (if head "</thead>" "</tbody>") html)
3835 (if lines (push "<tbody>" html) (setq tbopen nil)))
3836 (setq head nil) ;; head ends here, first time around
3837 ;; ignore this line
3838 (throw 'next-line t)))
3839 ;; Break the line into fields
3840 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3841 (unless fnum (setq fnum (make-vector (length fields) 0)))
3842 (setq nlines (1+ nlines) i -1)
3843 (push (concat "<tr>"
3844 (mapconcat
3845 (lambda (x)
3846 (setq i (1+ i))
3847 (if (and (< i nlines)
3848 (string-match org-table-number-regexp x))
3849 (incf (aref fnum i)))
3850 (if head
3851 (concat (car org-export-table-header-tags) x
3852 (cdr org-export-table-header-tags))
3853 (concat (car org-export-table-data-tags) x
3854 (cdr org-export-table-data-tags))))
3855 fields "")
3856 "</tr>")
3857 html)))
3858 (unless splice (if tbopen (push "</tbody>" html)))
3859 (unless splice (push "</table>\n" html))
3860 (setq html (nreverse html))
3861 (unless splice
3862 ;; Put in col tags with the alignment (unfortunately often ignored...)
3863 (push (mapconcat
3864 (lambda (x)
3865 (setq gr (pop org-table-colgroup-info))
3866 (format "%s<col align=\"%s\"></col>%s"
3867 (if (memq gr '(:start :startend))
3868 (prog1
3869 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3870 (setq colgropen t))
3872 (if (> (/ (float x) nlines) org-table-number-fraction)
3873 "right" "left")
3874 (if (memq gr '(:end :startend))
3875 (progn (setq colgropen nil) "</colgroup>")
3876 "")))
3877 fnum "")
3878 html)
3879 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3880 (if caption (push (format "<caption>%s</caption>" caption) html))
3881 (push html-table-tag html))
3882 (concat (mapconcat 'identity html "\n") "\n")))
3884 (defun org-table-clean-before-export (lines)
3885 "Check if the table has a marking column.
3886 If yes remove the column and the special lines."
3887 (setq org-table-colgroup-info nil)
3888 (if (memq nil
3889 (mapcar
3890 (lambda (x) (or (string-match "^[ \t]*|-" x)
3891 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3892 lines))
3893 (progn
3894 (setq org-table-clean-did-remove-column nil)
3895 (delq nil
3896 (mapcar
3897 (lambda (x)
3898 (cond
3899 ((string-match "^[ \t]*| */ *|" x)
3900 (setq org-table-colgroup-info
3901 (mapcar (lambda (x)
3902 (cond ((member x '("<" "&lt;")) :start)
3903 ((member x '(">" "&gt;")) :end)
3904 ((member x '("<>" "&lt;&gt;")) :startend)
3905 (t nil)))
3906 (org-split-string x "[ \t]*|[ \t]*")))
3907 nil)
3908 (t x)))
3909 lines)))
3910 (setq org-table-clean-did-remove-column t)
3911 (delq nil
3912 (mapcar
3913 (lambda (x)
3914 (cond
3915 ((string-match "^[ \t]*| */ *|" x)
3916 (setq org-table-colgroup-info
3917 (mapcar (lambda (x)
3918 (cond ((member x '("<" "&lt;")) :start)
3919 ((member x '(">" "&gt;")) :end)
3920 ((member x '("<>" "&lt;&gt;")) :startend)
3921 (t nil)))
3922 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3923 nil)
3924 ((string-match "^[ \t]*| *[!_^/] *|" x)
3925 nil) ; ignore this line
3926 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3927 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3928 ;; remove the first column
3929 (replace-match "\\1|" t nil x))))
3930 lines))))
3932 (defun org-format-table-table-html (lines)
3933 "Format a table generated by table.el into HTML.
3934 This conversion does *not* use `table-generate-source' from table.el.
3935 This has the advantage that Org-mode's HTML conversions can be used.
3936 But it has the disadvantage, that no cell- or row-spanning is allowed."
3937 (let (line field-buffer
3938 (head org-export-highlight-first-table-line)
3939 fields html empty)
3940 (setq html (concat html-table-tag "\n"))
3941 (while (setq line (pop lines))
3942 (setq empty "&nbsp;")
3943 (catch 'next-line
3944 (if (string-match "^[ \t]*\\+-" line)
3945 (progn
3946 (if field-buffer
3947 (progn
3948 (setq
3949 html
3950 (concat
3951 html
3952 "<tr>"
3953 (mapconcat
3954 (lambda (x)
3955 (if (equal x "") (setq x empty))
3956 (if head
3957 (concat (car org-export-table-header-tags) x
3958 (cdr org-export-table-header-tags))
3959 (concat (car org-export-table-data-tags) x
3960 (cdr org-export-table-data-tags))))
3961 field-buffer "\n")
3962 "</tr>\n"))
3963 (setq head nil)
3964 (setq field-buffer nil)))
3965 ;; Ignore this line
3966 (throw 'next-line t)))
3967 ;; Break the line into fields and store the fields
3968 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3969 (if field-buffer
3970 (setq field-buffer (mapcar
3971 (lambda (x)
3972 (concat x "<br/>" (pop fields)))
3973 field-buffer))
3974 (setq field-buffer fields))))
3975 (setq html (concat html "</table>\n"))
3976 html))
3978 (defun org-format-table-table-html-using-table-generate-source (lines)
3979 "Format a table into html, using `table-generate-source' from table.el.
3980 This has the advantage that cell- or row-spanning is allowed.
3981 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3982 (require 'table)
3983 (with-current-buffer (get-buffer-create " org-tmp1 ")
3984 (erase-buffer)
3985 (insert (mapconcat 'identity lines "\n"))
3986 (goto-char (point-min))
3987 (if (not (re-search-forward "|[^+]" nil t))
3988 (error "Error processing table"))
3989 (table-recognize-table)
3990 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3991 (table-generate-source 'html " org-tmp2 ")
3992 (set-buffer " org-tmp2 ")
3993 (buffer-substring (point-min) (point-max))))
3995 (defun org-export-splice-style (style extra)
3996 "Splice EXTRA into STYLE, just before \"</style>\"."
3997 (if (and (stringp extra)
3998 (string-match "\\S-" extra)
3999 (string-match "</style>" style))
4000 (concat (substring style 0 (match-beginning 0))
4001 "\n" extra "\n"
4002 (substring style (match-beginning 0)))
4003 style))
4005 (defun org-html-handle-time-stamps (s)
4006 "Format time stamps in string S, or remove them."
4007 (catch 'exit
4008 (let (r b)
4009 (while (string-match org-maybe-keyword-time-regexp s)
4010 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
4011 ;; never export CLOCK
4012 (throw 'exit ""))
4013 (or b (setq b (substring s 0 (match-beginning 0))))
4014 (if (not org-export-with-timestamps)
4015 (setq r (concat r (substring s 0 (match-beginning 0)))
4016 s (substring s (match-end 0)))
4017 (setq r (concat
4018 r (substring s 0 (match-beginning 0))
4019 (if (match-end 1)
4020 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4021 (match-string 1 s)))
4022 (format " @<span class=\"timestamp\">%s@</span>"
4023 (substring
4024 (org-translate-time (match-string 3 s)) 1 -1)))
4025 s (substring s (match-end 0)))))
4026 ;; Line break if line started and ended with time stamp stuff
4027 (if (not r)
4029 (setq r (concat r s))
4030 (unless (string-match "\\S-" (concat b s))
4031 (setq r (concat r "@<br/>")))
4032 r))))
4034 (defun org-export-htmlize-region-for-paste (beg end)
4035 "Convert the region to HTML, using htmlize.el.
4036 This is much like `htmlize-region-for-paste', only that it uses
4037 the settings define in the org-... variables."
4038 (let* ((htmlize-output-type org-export-htmlize-output-type)
4039 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
4040 (htmlbuf (htmlize-region beg end)))
4041 (unwind-protect
4042 (with-current-buffer htmlbuf
4043 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
4044 (plist-get htmlize-buffer-places 'content-end)))
4045 (kill-buffer htmlbuf))))
4047 ;;;###autoload
4048 (defun org-export-htmlize-generate-css ()
4049 "Create the CSS for all font definitions in the current Emacs session.
4050 Use this to create face definitions in your CSS style file that can then
4051 be used by code snippets transformed by htmlize.
4052 This command just produces a buffer that contains class definitions for all
4053 faces used in the current Emacs session. You can copy and paste the ones you
4054 need into your CSS file.
4056 If you then set `org-export-htmlize-output-type' to `css', calls to
4057 the function `org-export-htmlize-region-for-paste' will produce code
4058 that uses these same face definitions."
4059 (interactive)
4060 (require 'htmlize)
4061 (and (get-buffer "*html*") (kill-buffer "*html*"))
4062 (with-temp-buffer
4063 (let ((fl (face-list))
4064 (htmlize-css-name-prefix "org-")
4065 (htmlize-output-type 'css)
4066 f i)
4067 (while (setq f (pop fl)
4068 i (and f (face-attribute f :inherit)))
4069 (when (and (symbolp f) (or (not i) (not (listp i))))
4070 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4071 (htmlize-region (point-min) (point-max))))
4072 (switch-to-buffer "*html*")
4073 (goto-char (point-min))
4074 (if (re-search-forward "<style" nil t)
4075 (delete-region (point-min) (match-beginning 0)))
4076 (if (re-search-forward "</style>" nil t)
4077 (delete-region (1+ (match-end 0)) (point-max)))
4078 (beginning-of-line 1)
4079 (if (looking-at " +") (replace-match ""))
4080 (goto-char (point-min)))
4082 (defun org-html-protect (s)
4083 ;; convert & to &amp;, < to &lt; and > to &gt;
4084 (let ((start 0))
4085 (while (string-match "&" s start)
4086 (setq s (replace-match "&amp;" t t s)
4087 start (1+ (match-beginning 0))))
4088 (while (string-match "<" s)
4089 (setq s (replace-match "&lt;" t t s)))
4090 (while (string-match ">" s)
4091 (setq s (replace-match "&gt;" t t s)))
4092 ; (while (string-match "\"" s)
4093 ; (setq s (replace-match "&quot;" t t s)))
4097 (defun org-export-cleanup-toc-line (s)
4098 "Remove tags and timestamps from lines going into the toc."
4099 (when (memq org-export-with-tags '(not-in-toc nil))
4100 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4101 (setq s (replace-match "" t t s))))
4102 (when org-export-remove-timestamps-from-toc
4103 (while (string-match org-maybe-keyword-time-regexp s)
4104 (setq s (replace-match "" t t s))))
4105 (while (string-match org-bracket-link-regexp s)
4106 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4107 t t s)))
4110 (defun org-html-expand (string)
4111 "Prepare STRING for HTML export. Applies all active conversions.
4112 If there are links in the string, don't modify these."
4113 (let* ((re (concat org-bracket-link-regexp "\\|"
4114 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4115 m s l res)
4116 (while (setq m (string-match re string))
4117 (setq s (substring string 0 m)
4118 l (match-string 0 string)
4119 string (substring string (match-end 0)))
4120 (push (org-html-do-expand s) res)
4121 (push l res))
4122 (push (org-html-do-expand string) res)
4123 (apply 'concat (nreverse res))))
4125 (defun org-html-do-expand (s)
4126 "Apply all active conversions to translate special ASCII to HTML."
4127 (setq s (org-html-protect s))
4128 (if org-export-html-expand
4129 (let ((start 0))
4130 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
4131 (setq s (replace-match "<\\1>" t nil s)))))
4132 (if org-export-with-emphasize
4133 (setq s (org-export-html-convert-emphasize s)))
4134 (if org-export-with-special-strings
4135 (setq s (org-export-html-convert-special-strings s)))
4136 (if org-export-with-sub-superscripts
4137 (setq s (org-export-html-convert-sub-super s)))
4138 (if org-export-with-TeX-macros
4139 (let ((start 0) wd ass)
4140 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4141 s start))
4142 (if (get-text-property (match-beginning 0) 'org-protected s)
4143 (setq start (match-end 0))
4144 (setq wd (match-string 1 s))
4145 (if (setq ass (assoc wd org-html-entities))
4146 (setq s (replace-match (or (cdr ass)
4147 (concat "&" (car ass) ";"))
4148 t t s))
4149 (setq start (+ start (length wd))))))))
4152 (defun org-create-multibrace-regexp (left right n)
4153 "Create a regular expression which will match a balanced sexp.
4154 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4155 as single character strings.
4156 The regexp returned will match the entire expression including the
4157 delimiters. It will also define a single group which contains the
4158 match except for the outermost delimiters. The maximum depth of
4159 stacked delimiters is N. Escaping delimiters is not possible."
4160 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
4161 (or "\\|")
4162 (re nothing)
4163 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4164 (while (> n 1)
4165 (setq n (1- n)
4166 re (concat re or next)
4167 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4168 (concat left "\\(" re "\\)" right)))
4170 (defvar org-match-substring-regexp
4171 (concat
4172 "\\([^\\]\\)\\([_^]\\)\\("
4173 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4174 "\\|"
4175 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4176 "\\|"
4177 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4178 "The regular expression matching a sub- or superscript.")
4180 (defvar org-match-substring-with-braces-regexp
4181 (concat
4182 "\\([^\\]\\)\\([_^]\\)\\("
4183 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4184 "\\)")
4185 "The regular expression matching a sub- or superscript, forcing braces.")
4187 (defconst org-export-html-special-string-regexps
4188 '(("\\\\-" . "&shy;")
4189 ("---\\([^-]\\)" . "&mdash;\\1")
4190 ("--\\([^-]\\)" . "&ndash;\\1")
4191 ("\\.\\.\\." . "&hellip;"))
4192 "Regular expressions for special string conversion.")
4194 (defun org-export-html-convert-special-strings (string)
4195 "Convert special characters in STRING to HTML."
4196 (let ((all org-export-html-special-string-regexps)
4197 e a re rpl start)
4198 (while (setq a (pop all))
4199 (setq re (car a) rpl (cdr a) start 0)
4200 (while (string-match re string start)
4201 (if (get-text-property (match-beginning 0) 'org-protected string)
4202 (setq start (match-end 0))
4203 (setq string (replace-match rpl t nil string)))))
4204 string))
4206 (defun org-export-html-convert-sub-super (string)
4207 "Convert sub- and superscripts in STRING to HTML."
4208 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4209 (while (string-match org-match-substring-regexp string s)
4210 (cond
4211 ((and requireb (match-end 8)) (setq s (match-end 2)))
4212 ((get-text-property (match-beginning 2) 'org-protected string)
4213 (setq s (match-end 2)))
4215 (setq s (match-end 1)
4216 key (if (string= (match-string 2 string) "_") "sub" "sup")
4217 c (or (match-string 8 string)
4218 (match-string 6 string)
4219 (match-string 5 string))
4220 string (replace-match
4221 (concat (match-string 1 string)
4222 "<" key ">" c "</" key ">")
4223 t t string)))))
4224 (while (string-match "\\\\\\([_^]\\)" string)
4225 (setq string (replace-match (match-string 1 string) t t string)))
4226 string))
4228 (defun org-export-html-convert-emphasize (string)
4229 "Apply emphasis."
4230 (let ((s 0) rpl)
4231 (while (string-match org-emph-re string s)
4232 (if (not (equal
4233 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4234 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4235 (setq s (match-beginning 0)
4237 (concat
4238 (match-string 1 string)
4239 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4240 (match-string 4 string)
4241 (nth 3 (assoc (match-string 3 string)
4242 org-emphasis-alist))
4243 (match-string 5 string))
4244 string (replace-match rpl t t string)
4245 s (+ s (- (length rpl) 2)))
4246 (setq s (1+ s))))
4247 string))
4249 (defun org-open-par ()
4250 "Insert <p>, but first close previous paragraph if any."
4251 (org-close-par-maybe)
4252 (insert "\n<p>")
4253 (setq org-par-open t))
4254 (defun org-close-par-maybe ()
4255 "Close paragraph if there is one open."
4256 (when org-par-open
4257 (insert "</p>")
4258 (setq org-par-open nil)))
4259 (defun org-close-li (&optional type)
4260 "Close <li> if necessary."
4261 (org-close-par-maybe)
4262 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4264 (defvar body-only) ; dynamically scoped into this.
4265 (defun org-html-level-start (level title umax with-toc head-count)
4266 "Insert a new level in HTML export.
4267 When TITLE is nil, just close all open levels."
4268 (org-close-par-maybe)
4269 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4270 (extra-targets
4271 (mapconcat (lambda (x)
4272 (format "<a name=\"%s\" id=\"%s\"></a>"
4273 x x))
4274 (cdr (assoc target org-export-target-aliases))
4275 ""))
4276 (l org-level-max)
4277 snumber)
4278 (while (>= l level)
4279 (if (aref org-levels-open (1- l))
4280 (progn
4281 (org-html-level-close l umax)
4282 (aset org-levels-open (1- l) nil)))
4283 (setq l (1- l)))
4284 (when title
4285 ;; If title is nil, this means this function is called to close
4286 ;; all levels, so the rest is done only if title is given
4287 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4288 (setq title (replace-match
4289 (if org-export-with-tags
4290 (save-match-data
4291 (concat
4292 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4293 (mapconcat 'identity (org-split-string
4294 (match-string 1 title) ":")
4295 "&nbsp;")
4296 "</span>"))
4298 t t title)))
4299 (if (> level umax)
4300 (progn
4301 (if (aref org-levels-open (1- level))
4302 (progn
4303 (org-close-li)
4304 (if target
4305 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4306 (insert "<li>" title "<br/>\n")))
4307 (aset org-levels-open (1- level) t)
4308 (org-close-par-maybe)
4309 (if target
4310 (insert (format "<ul>\n<li id=\"%s\">" target)
4311 extra-targets title "<br/>\n")
4312 (insert "<ul>\n<li>" title "<br/>\n"))))
4313 (aset org-levels-open (1- level) t)
4314 (setq snumber (org-section-number level))
4315 (if (and org-export-with-section-numbers (not body-only))
4316 (setq title (concat snumber " " title)))
4317 (setq level (+ level org-export-html-toplevel-hlevel -1))
4318 (unless (= head-count 1) (insert "\n</div>\n"))
4319 (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"
4320 snumber level level snumber extra-targets title level snumber))
4321 (org-open-par)))))
4323 (defun org-get-text-property-any (pos prop &optional object)
4324 (or (get-text-property pos prop object)
4325 (and (setq pos (next-single-property-change pos prop object))
4326 (get-text-property pos prop object))))
4328 (defun org-html-level-close (level max-outline-level)
4329 "Terminate one level in HTML export."
4330 (if (<= level max-outline-level)
4331 (insert "</div>\n")
4332 (org-close-li)
4333 (insert "</ul>\n")))
4335 ;;; iCalendar export
4337 ;;;###autoload
4338 (defun org-export-icalendar-this-file ()
4339 "Export current file as an iCalendar file.
4340 The iCalendar file will be located in the same directory as the Org-mode
4341 file, but with extension `.ics'."
4342 (interactive)
4343 (org-export-icalendar nil buffer-file-name))
4345 ;;;###autoload
4346 (defun org-export-icalendar-all-agenda-files ()
4347 "Export all files in `org-agenda-files' to iCalendar .ics files.
4348 Each iCalendar file will be located in the same directory as the Org-mode
4349 file, but with extension `.ics'."
4350 (interactive)
4351 (apply 'org-export-icalendar nil (org-agenda-files t)))
4353 ;;;###autoload
4354 (defun org-export-icalendar-combine-agenda-files ()
4355 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4356 The file is stored under the name `org-combined-agenda-icalendar-file'."
4357 (interactive)
4358 (apply 'org-export-icalendar t (org-agenda-files t)))
4360 (defun org-export-icalendar (combine &rest files)
4361 "Create iCalendar files for all elements of FILES.
4362 If COMBINE is non-nil, combine all calendar entries into a single large
4363 file and store it under the name `org-combined-agenda-icalendar-file'."
4364 (save-excursion
4365 (org-prepare-agenda-buffers files)
4366 (let* ((dir (org-export-directory
4367 :ical (list :publishing-directory
4368 org-export-publishing-directory)))
4369 file ical-file ical-buffer category started org-agenda-new-buffers)
4370 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4371 (when combine
4372 (setq ical-file
4373 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4374 org-combined-agenda-icalendar-file
4375 (expand-file-name org-combined-agenda-icalendar-file dir))
4376 ical-buffer (org-get-agenda-file-buffer ical-file))
4377 (set-buffer ical-buffer) (erase-buffer))
4378 (while (setq file (pop files))
4379 (catch 'nextfile
4380 (org-check-agenda-file file)
4381 (set-buffer (org-get-agenda-file-buffer file))
4382 (unless combine
4383 (setq ical-file (concat (file-name-as-directory dir)
4384 (file-name-sans-extension
4385 (file-name-nondirectory buffer-file-name))
4386 ".ics"))
4387 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4388 (with-current-buffer ical-buffer (erase-buffer)))
4389 (setq category (or org-category
4390 (file-name-sans-extension
4391 (file-name-nondirectory buffer-file-name))))
4392 (if (symbolp category) (setq category (symbol-name category)))
4393 (let ((standard-output ical-buffer))
4394 (if combine
4395 (and (not started) (setq started t)
4396 (org-start-icalendar-file org-icalendar-combined-name))
4397 (org-start-icalendar-file category))
4398 (org-print-icalendar-entries combine)
4399 (when (or (and combine (not files)) (not combine))
4400 (org-finish-icalendar-file)
4401 (set-buffer ical-buffer)
4402 (run-hooks 'org-before-save-iCalendar-file-hook)
4403 (save-buffer)
4404 (run-hooks 'org-after-save-iCalendar-file-hook)
4405 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4406 ))))
4407 (org-release-buffers org-agenda-new-buffers))))
4409 (defvar org-before-save-iCalendar-file-hook nil
4410 "Hook run before an iCalendar file has been saved.
4411 This can be used to modify the result of the export.")
4413 (defvar org-after-save-iCalendar-file-hook nil
4414 "Hook run after an iCalendar file has been saved.
4415 The iCalendar buffer is still current when this hook is run.
4416 A good way to use this is to tell a desktop calendar application to re-read
4417 the iCalendar file.")
4419 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4420 (defun org-print-icalendar-entries (&optional combine)
4421 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4422 When COMBINE is non nil, add the category to each line."
4423 (require 'org-agenda)
4424 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4425 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4426 (dts (org-ical-ts-to-string
4427 (format-time-string (cdr org-time-stamp-formats) (current-time))
4428 "DTSTART"))
4429 hd ts ts2 state status (inc t) pos b sexp rrule
4430 scheduledp deadlinep todo prefix due start
4431 tmp pri categories entry location summary desc uid
4432 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4433 (org-refresh-category-properties)
4434 (save-excursion
4435 (goto-char (point-min))
4436 (while (re-search-forward re1 nil t)
4437 (catch :skip
4438 (org-agenda-skip)
4439 (when (boundp 'org-icalendar-verify-function)
4440 (unless (funcall org-icalendar-verify-function)
4441 (outline-next-heading)
4442 (backward-char 1)
4443 (throw :skip nil)))
4444 (setq pos (match-beginning 0)
4445 ts (match-string 0)
4446 inc t
4447 hd (condition-case nil
4448 (org-icalendar-cleanup-string
4449 (org-get-heading))
4450 (error (throw :skip nil)))
4451 summary (org-icalendar-cleanup-string
4452 (org-entry-get nil "SUMMARY"))
4453 desc (org-icalendar-cleanup-string
4454 (or (org-entry-get nil "DESCRIPTION")
4455 (and org-icalendar-include-body (org-get-entry)))
4456 t org-icalendar-include-body)
4457 location (org-icalendar-cleanup-string
4458 (org-entry-get nil "LOCATION" 'selective))
4459 uid (if org-icalendar-store-UID
4460 (org-id-get-create)
4461 (or (org-id-get) (org-id-new)))
4462 categories (org-export-get-categories)
4463 deadlinep nil scheduledp nil)
4464 (if (looking-at re2)
4465 (progn
4466 (goto-char (match-end 0))
4467 (setq ts2 (match-string 1)
4468 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4469 (setq tmp (buffer-substring (max (point-min)
4470 (- pos org-ds-keyword-length))
4471 pos)
4472 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4473 (progn
4474 (setq inc nil)
4475 (replace-match "\\1" t nil ts))
4477 deadlinep (string-match org-deadline-regexp tmp)
4478 scheduledp (string-match org-scheduled-regexp tmp)
4479 todo (org-get-todo-state)
4480 ;; donep (org-entry-is-done-p)
4482 (when (and
4483 deadlinep
4484 (if todo
4485 (not (memq 'event-if-todo org-icalendar-use-deadline))
4486 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4487 (throw :skip t))
4488 (when (and
4489 scheduledp
4490 (if todo
4491 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4492 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4493 (throw :skip t))
4494 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4495 (if (or (string-match org-tr-regexp hd)
4496 (string-match org-ts-regexp hd))
4497 (setq hd (replace-match "" t t hd)))
4498 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4499 (setq rrule
4500 (concat "\nRRULE:FREQ="
4501 (cdr (assoc
4502 (match-string 2 ts)
4503 '(("d" . "DAILY")("w" . "WEEKLY")
4504 ("m" . "MONTHLY")("y" . "YEARLY"))))
4505 ";INTERVAL=" (match-string 1 ts)))
4506 (setq rrule ""))
4507 (setq summary (or summary hd))
4508 (if (string-match org-bracket-link-regexp summary)
4509 (setq summary
4510 (replace-match (if (match-end 3)
4511 (match-string 3 summary)
4512 (match-string 1 summary))
4513 t t summary)))
4514 (if deadlinep (setq summary (concat "DL: " summary)))
4515 (if scheduledp (setq summary (concat "S: " summary)))
4516 (if (string-match "\\`<%%" ts)
4517 (with-current-buffer sexp-buffer
4518 (insert (substring ts 1 -1) " " summary "\n"))
4519 (princ (format "BEGIN:VEVENT
4520 UID: %s
4522 %s%s
4523 SUMMARY:%s%s%s
4524 CATEGORIES:%s
4525 END:VEVENT\n"
4526 (concat prefix uid)
4527 (org-ical-ts-to-string ts "DTSTART")
4528 (org-ical-ts-to-string ts2 "DTEND" inc)
4529 rrule summary
4530 (if (and desc (string-match "\\S-" desc))
4531 (concat "\nDESCRIPTION: " desc) "")
4532 (if (and location (string-match "\\S-" location))
4533 (concat "\nLOCATION: " location) "")
4534 categories)))))
4535 (when (and org-icalendar-include-sexps
4536 (condition-case nil (require 'icalendar) (error nil))
4537 (fboundp 'icalendar-export-region))
4538 ;; Get all the literal sexps
4539 (goto-char (point-min))
4540 (while (re-search-forward "^&?%%(" nil t)
4541 (catch :skip
4542 (org-agenda-skip)
4543 (setq b (match-beginning 0))
4544 (goto-char (1- (match-end 0)))
4545 (forward-sexp 1)
4546 (end-of-line 1)
4547 (setq sexp (buffer-substring b (point)))
4548 (with-current-buffer sexp-buffer
4549 (insert sexp "\n"))))
4550 (princ (org-diary-to-ical-string sexp-buffer))
4551 (kill-buffer sexp-buffer))
4553 (when org-icalendar-include-todo
4554 (setq prefix "TODO-")
4555 (goto-char (point-min))
4556 (while (re-search-forward org-todo-line-regexp nil t)
4557 (catch :skip
4558 (org-agenda-skip)
4559 (when (boundp 'org-icalendar-verify-function)
4560 (unless (funcall org-icalendar-verify-function)
4561 (outline-next-heading)
4562 (backward-char 1)
4563 (throw :skip nil)))
4564 (setq state (match-string 2))
4565 (setq status (if (member state org-done-keywords)
4566 "COMPLETED" "NEEDS-ACTION"))
4567 (when (and state
4568 (or (not (member state org-done-keywords))
4569 (eq org-icalendar-include-todo 'all))
4570 (not (member org-archive-tag (org-get-tags-at)))
4572 (setq hd (match-string 3)
4573 summary (org-icalendar-cleanup-string
4574 (org-entry-get nil "SUMMARY"))
4575 desc (org-icalendar-cleanup-string
4576 (or (org-entry-get nil "DESCRIPTION")
4577 (and org-icalendar-include-body (org-get-entry)))
4578 t org-icalendar-include-body)
4579 location (org-icalendar-cleanup-string
4580 (org-entry-get nil "LOCATION" 'selective))
4581 due (and (member 'todo-due org-icalendar-use-deadline)
4582 (org-entry-get nil "DEADLINE"))
4583 start (and (member 'todo-start org-icalendar-use-scheduled)
4584 (org-entry-get nil "SCHEDULED"))
4585 categories (org-export-get-categories)
4586 uid (if org-icalendar-store-UID
4587 (org-id-get-create)
4588 (or (org-id-get) (org-id-new))))
4589 (and due (setq due (org-ical-ts-to-string due "DUE")))
4590 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4592 (if (string-match org-bracket-link-regexp hd)
4593 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4594 (match-string 1 hd))
4595 t t hd)))
4596 (if (string-match org-priority-regexp hd)
4597 (setq pri (string-to-char (match-string 2 hd))
4598 hd (concat (substring hd 0 (match-beginning 1))
4599 (substring hd (match-end 1))))
4600 (setq pri org-default-priority))
4601 (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
4602 (- org-lowest-priority org-highest-priority))))))
4604 (princ (format "BEGIN:VTODO
4605 UID: %s
4607 SUMMARY:%s%s%s%s
4608 CATEGORIES:%s
4609 SEQUENCE:1
4610 PRIORITY:%d
4611 STATUS:%s
4612 END:VTODO\n"
4613 (concat prefix uid)
4614 (or start dts)
4615 (or summary hd)
4616 (if (and location (string-match "\\S-" location))
4617 (concat "\nLOCATION: " location) "")
4618 (if (and desc (string-match "\\S-" desc))
4619 (concat "\nDESCRIPTION: " desc) "")
4620 (if due (concat "\n" due) "")
4621 categories
4622 pri status)))))))))
4624 (defun org-export-get-categories ()
4625 "Get categories according to `org-icalendar-categories'."
4626 (let ((cs org-icalendar-categories) c rtn tmp)
4627 (while (setq c (pop cs))
4628 (cond
4629 ((eq c 'category) (push (org-get-category) rtn))
4630 ((eq c 'todo-state)
4631 (setq tmp (org-get-todo-state))
4632 (and tmp (push tmp rtn)))
4633 ((eq c 'local-tags)
4634 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4635 ((eq c 'all-tags)
4636 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4637 (mapconcat 'identity (nreverse rtn) ",")))
4639 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4640 "Take out stuff and quote what needs to be quoted.
4641 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4642 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4643 characters."
4644 (if (not s)
4646 (when is-body
4647 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4648 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4649 (while (string-match re s) (setq s (replace-match "" t t s)))
4650 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4651 (let ((start 0))
4652 (while (string-match "\\([,;]\\)" s start)
4653 (setq start (+ (match-beginning 0) 2)
4654 s (replace-match "\\\\\\1" nil nil s))))
4655 (setq s (org-trim s))
4656 (when is-body
4657 (while (string-match "[ \t]*\n[ \t]*" s)
4658 (setq s (replace-match "\\n" t t s))))
4659 (if is-body
4660 (if maxlength
4661 (if (and (numberp maxlength)
4662 (> (length s) maxlength))
4663 (setq s (substring s 0 maxlength)))))
4666 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
4667 "Take out stuff and quote what needs to be quoted.
4668 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4669 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4670 characters.
4671 This seems to be more like RFC 2455, but it causes problems, so it is
4672 not used right now."
4673 (if (not s)
4675 (if is-body
4676 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4677 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4678 (while (string-match re s) (setq s (replace-match "" t t s)))
4679 (while (string-match re2 s) (setq s (replace-match "" t t s)))
4680 (setq s (org-trim s))
4681 (while (string-match "[ \t]*\n[ \t]*" s)
4682 (setq s (replace-match "\\n" t t s)))
4683 (if maxlength
4684 (if (and (numberp maxlength)
4685 (> (length s) maxlength))
4686 (setq s (substring s 0 maxlength)))))
4687 (setq s (org-trim s)))
4688 (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
4689 (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
4692 (defun org-get-entry ()
4693 "Clean-up description string."
4694 (save-excursion
4695 (org-back-to-heading t)
4696 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4698 (defun org-start-icalendar-file (name)
4699 "Start an iCalendar file by inserting the header."
4700 (let ((user user-full-name)
4701 (name (or name "unknown"))
4702 (timezone (cadr (current-time-zone))))
4703 (princ
4704 (format "BEGIN:VCALENDAR
4705 VERSION:2.0
4706 X-WR-CALNAME:%s
4707 PRODID:-//%s//Emacs with Org-mode//EN
4708 X-WR-TIMEZONE:%s
4709 CALSCALE:GREGORIAN\n" name user timezone))))
4711 (defun org-finish-icalendar-file ()
4712 "Finish an iCalendar file by inserting the END statement."
4713 (princ "END:VCALENDAR\n"))
4715 (defun org-ical-ts-to-string (s keyword &optional inc)
4716 "Take a time string S and convert it to iCalendar format.
4717 KEYWORD is added in front, to make a complete line like DTSTART....
4718 When INC is non-nil, increase the hour by two (if time string contains
4719 a time), or the day by one (if it does not contain a time)."
4720 (let ((t1 (org-parse-time-string s 'nodefault))
4721 t2 fmt have-time time)
4722 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4723 (setq t2 t1 have-time t)
4724 (setq t2 (org-parse-time-string s)))
4725 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4726 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4727 (when inc
4728 (if have-time
4729 (if org-agenda-default-appointment-duration
4730 (setq mi (+ org-agenda-default-appointment-duration mi))
4731 (setq h (+ 2 h)))
4732 (setq d (1+ d))))
4733 (setq time (encode-time s mi h d m y)))
4734 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4735 (concat keyword (format-time-string fmt time))))
4737 ;;; XOXO export
4739 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4740 (with-current-buffer buffer
4741 (apply 'insert output)))
4742 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4744 ;;;###autoload
4745 (defun org-export-as-xoxo (&optional buffer)
4746 "Export the org buffer as XOXO.
4747 The XOXO buffer is named *xoxo-<source buffer name>*"
4748 (interactive (list (current-buffer)))
4749 ;; A quickie abstraction
4751 ;; Output everything as XOXO
4752 (with-current-buffer (get-buffer buffer)
4753 (let* ((pos (point))
4754 (opt-plist (org-combine-plists (org-default-export-plist)
4755 (org-infile-export-plist)))
4756 (filename (concat (file-name-as-directory
4757 (org-export-directory :xoxo opt-plist))
4758 (file-name-sans-extension
4759 (file-name-nondirectory buffer-file-name))
4760 ".html"))
4761 (out (find-file-noselect filename))
4762 (last-level 1)
4763 (hanging-li nil))
4764 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4765 ;; Check the output buffer is empty.
4766 (with-current-buffer out (erase-buffer))
4767 ;; Kick off the output
4768 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4769 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4770 (let* ((hd (match-string-no-properties 1))
4771 (level (length hd))
4772 (text (concat
4773 (match-string-no-properties 2)
4774 (save-excursion
4775 (goto-char (match-end 0))
4776 (let ((str ""))
4777 (catch 'loop
4778 (while 't
4779 (forward-line)
4780 (if (looking-at "^[ \t]\\(.*\\)")
4781 (setq str (concat str (match-string-no-properties 1)))
4782 (throw 'loop str)))))))))
4784 ;; Handle level rendering
4785 (cond
4786 ((> level last-level)
4787 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4789 ((< level last-level)
4790 (dotimes (- (- last-level level) 1)
4791 (if hanging-li
4792 (org-export-as-xoxo-insert-into out "</li>\n"))
4793 (org-export-as-xoxo-insert-into out "</ol>\n"))
4794 (when hanging-li
4795 (org-export-as-xoxo-insert-into out "</li>\n")
4796 (setq hanging-li nil)))
4798 ((equal level last-level)
4799 (if hanging-li
4800 (org-export-as-xoxo-insert-into out "</li>\n")))
4803 (setq last-level level)
4805 ;; And output the new li
4806 (setq hanging-li 't)
4807 (if (equal ?+ (elt text 0))
4808 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4809 (org-export-as-xoxo-insert-into out "<li>" text))))
4811 ;; Finally finish off the ol
4812 (dotimes (- last-level 1)
4813 (if hanging-li
4814 (org-export-as-xoxo-insert-into out "</li>\n"))
4815 (org-export-as-xoxo-insert-into out "</ol>\n"))
4817 (goto-char pos)
4818 ;; Finish the buffer off and clean it up.
4819 (switch-to-buffer-other-window out)
4820 (indent-region (point-min) (point-max) nil)
4821 (save-buffer)
4822 (goto-char (point-min))
4825 (provide 'org-exp)
4827 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4829 ;;; org-exp.el ends here