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