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