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