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