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