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