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