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