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