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