]> code.delx.au - gnu-emacs/blob - lisp/org/org-exp.el
bf1dd2a276b9372aa3edcda52fbbf729b765e6b8
[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 ;; Get rid of drawers
1470 (org-export-remove-or-extract-drawers drawers
1471 (plist-get parameters :drawers))
1472
1473 ;; Get the correct stuff before the first headline
1474 (when (plist-get parameters :skip-before-1st-heading)
1475 (goto-char (point-min))
1476 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t)
1477 (delete-region (point-min) (match-beginning 0))
1478 (goto-char (point-min))
1479 (insert "\n")))
1480 (when (plist-get parameters :add-text)
1481 (goto-char (point-min))
1482 (insert (plist-get parameters :add-text) "\n"))
1483
1484 ;; Get rid of archived trees
1485 (org-export-remove-archived-trees archived-trees)
1486
1487 ;; Remove todo-keywords before exporting, if the user has requested so
1488 (org-export-remove-headline-metadata parameters)
1489
1490 ;; Find all headings and compute the targets for them
1491 (setq target-alist (org-export-define-heading-targets target-alist))
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
1517 ;; Find matches for radio targets and turn them into internal links
1518 (org-export-mark-radio-links)
1519
1520 ;; Find all links that contain a newline and put them into a single line
1521 (org-export-concatenate-multiline-links)
1522
1523 ;; Normalize links: Convert angle and plain links into bracket links
1524 ;; and expand link abbreviations
1525 (org-export-normalize-links)
1526
1527 ;; Find all internal links. If they have a fuzzy match (i.e. not
1528 ;; a *dedicated* target match, let the link point to the
1529 ;; corresponding section.
1530 (org-export-target-internal-links target-alist)
1531
1532 ;; Find multiline emphasis and put them into single line
1533 (when (plist-get parameters :emph-multiline)
1534 (org-export-concatenate-multiline-emphasis))
1535
1536 ;; Remove special table lines
1537 (when org-export-table-remove-special-lines
1538 (org-export-remove-special-table-lines))
1539
1540 ;; Specific LaTeX stuff
1541 (when latexp
1542 (require 'org-export-latex nil)
1543 (org-export-latex-preprocess))
1544
1545 ;; Specific ASCII stuff
1546 (when asciip
1547 (org-export-ascii-preprocess))
1548
1549 ;; Specific HTML stuff
1550 (when htmlp
1551 (org-export-html-preprocess parameters))
1552
1553 ;; Remove or replace comments
1554 (org-export-handle-comments (plist-get parameters :comments))
1555
1556 (setq rtn (buffer-string)))
1557 (kill-buffer " org-mode-tmp")
1558 rtn))
1559
1560 (defun org-export-kill-licensed-text ()
1561 "Remove all text that is marked with a :org-license-to-kill property."
1562 (let (p q)
1563 (while (setq p (text-property-any (point-min) (point-max)
1564 :org-license-to-kill t))
1565 (delete-region
1566 p (or (next-single-property-change p :org-license-to-kill)
1567 (point-max))))))
1568
1569 (defun org-export-define-heading-targets (target-alist)
1570 "Find all headings and define the targets for them.
1571 The new targets are added to TARGET-ALIST, which is also returned."
1572 (goto-char (point-min))
1573 (org-init-section-numbers)
1574 (let ((re (concat "^" org-outline-regexp))
1575 level target)
1576 (while (re-search-forward re nil t)
1577 (setq level (org-reduced-level
1578 (save-excursion (goto-char (point-at-bol))
1579 (org-outline-level))))
1580 (setq target (org-solidify-link-text
1581 (format "sec-%s" (org-section-number level))))
1582 (push (cons target target) target-alist)
1583 (add-text-properties
1584 (point-at-bol) (point-at-eol)
1585 (list 'target target))))
1586 target-alist)
1587
1588 (defun org-export-handle-invisible-targets (target-alist)
1589 "Find targets in comments and move them out of comments.
1590 Mark them as invisible targets."
1591 (let (target tmp a)
1592 (goto-char (point-min))
1593 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1594 ;; Check if the line before or after is a headline with a target
1595 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1596 (get-text-property (point-at-bol 2) 'target)))
1597 (progn
1598 ;; use the existing target in a neighboring line
1599 (setq tmp (match-string 2))
1600 (replace-match "")
1601 (and (looking-at "\n") (delete-char 1))
1602 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1603 target-alist)
1604 (setq a (or (assoc target org-export-target-aliases)
1605 (progn
1606 (push (list target) org-export-target-aliases)
1607 (car org-export-target-aliases))))
1608 (push tmp (cdr a)))
1609 ;; Make an invisible target
1610 (replace-match "\\1(INVISIBLE)"))))
1611 target-alist)
1612
1613 (defun org-export-target-internal-links (target-alist)
1614 "Find all internal links and assign target to them.
1615 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1616 let the link point to the corresponding section."
1617 (goto-char (point-min))
1618 (while (re-search-forward org-bracket-link-regexp nil t)
1619 (org-if-unprotected
1620 (let* ((md (match-data))
1621 (desc (match-end 2))
1622 (link (org-link-unescape (match-string 1)))
1623 (slink (org-solidify-link-text link))
1624 found props pos
1625 (target
1626 (cond
1627 ((cdr (assoc slink target-alist)))
1628 ((string-match org-link-types-re link) nil)
1629 ((or (file-name-absolute-p link)
1630 (string-match "^\\." link))
1631 nil)
1632 (t
1633 (save-excursion
1634 (setq found (condition-case nil (org-link-search link)
1635 (error nil)))
1636 (when (and found
1637 (or (org-on-heading-p)
1638 (not (eq found 'dedicated))))
1639 (or (get-text-property (point) 'target)
1640 (get-text-property
1641 (max (point-min)
1642 (1- (or (previous-single-property-change
1643 (point) 'target) 0)))
1644 'target))))))))
1645 (when target
1646 (set-match-data md)
1647 (goto-char (match-beginning 1))
1648 (setq props (text-properties-at (point)))
1649 (delete-region (match-beginning 1) (match-end 1))
1650 (setq pos (point))
1651 (insert target)
1652 (unless desc (insert "][" link))
1653 (add-text-properties pos (point) props))))))
1654
1655 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1656 "Remove drawers, or extract the content.
1657 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1658 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1659 whose content to keep."
1660 (unless (eq t exp-drawers)
1661 (goto-char (point-min))
1662 (let ((re (concat "^[ \t]*:\\("
1663 (mapconcat
1664 'identity
1665 (org-delete-all exp-drawers
1666 (copy-sequence all-drawers))
1667 "\\|")
1668 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1669 (while (re-search-forward re nil t)
1670 (replace-match "")))))
1671
1672 (defun org-export-handle-export-tags (select-tags exclude-tags)
1673 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1674 Both arguments are lists of tags.
1675 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1676 will be removed.
1677 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1678 removed as well."
1679 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1680 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1681 select-tags "\\|")
1682 "\\):"))
1683 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1684 exclude-tags "\\|")
1685 "\\):"))
1686 beg end cont)
1687 (goto-char (point-min))
1688 (when (and select-tags
1689 (re-search-forward
1690 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1691 ;; At least one tree is marked for export, this means
1692 ;; all the unmarked stuff needs to go.
1693 ;; Dig out the trees that should be exported
1694 (goto-char (point-min))
1695 (outline-next-heading)
1696 (setq beg (point))
1697 (put-text-property beg (point-max) :org-delete t)
1698 (while (re-search-forward re-sel nil t)
1699 (when (org-on-heading-p)
1700 (org-back-to-heading)
1701 (remove-text-properties
1702 (max (1- (point)) (point-min))
1703 (setq cont (save-excursion (org-end-of-subtree t t)))
1704 '(:org-delete t))
1705 (while (and (org-up-heading-safe)
1706 (get-text-property (point) :org-delete))
1707 (remove-text-properties (max (1- (point)) (point-min))
1708 (point-at-eol) '(:org-delete t)))
1709 (goto-char cont))))
1710 ;; Remove the trees explicitly marked for noexport
1711 (when exclude-tags
1712 (goto-char (point-min))
1713 (while (re-search-forward re-excl nil t)
1714 (when (org-at-heading-p)
1715 (org-back-to-heading t)
1716 (setq beg (point))
1717 (org-end-of-subtree t)
1718 (delete-region beg (point)))))
1719 ;; Remove everything that is now still marked for deletion
1720 (goto-char (point-min))
1721 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1722 (setq end (or (next-single-property-change beg :org-delete)
1723 (point-max)))
1724 (delete-region beg end))))
1725
1726 (defun org-export-remove-archived-trees (export-archived-trees)
1727 "Remove archived trees.
1728 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1729 When it is t, the entire archived tree will be exported.
1730 When it is nil the entire tree including the headline will be removed
1731 from the buffer."
1732 (let ((re-archive (concat ":" org-archive-tag ":"))
1733 a b)
1734 (when (not (eq export-archived-trees t))
1735 (goto-char (point-min))
1736 (while (re-search-forward re-archive nil t)
1737 (if (not (org-on-heading-p t))
1738 (org-end-of-subtree t)
1739 (beginning-of-line 1)
1740 (setq a (if export-archived-trees
1741 (1+ (point-at-eol)) (point))
1742 b (org-end-of-subtree t))
1743 (if (> b a) (delete-region a b)))))))
1744
1745 (defun org-export-remove-headline-metadata (opts)
1746 "Remove meta data from the headline, according to user options."
1747 (let ((re org-complex-heading-regexp)
1748 (todo (plist-get opts :todo-keywords))
1749 (tags (plist-get opts :tags))
1750 (pri (plist-get opts :priority))
1751 rpl)
1752 (when (or (not todo) (not tags) (not pri))
1753 ;; OK, something needs to be removed
1754 (setq rpl (concat "\\1"
1755 (if todo " \\2" "")
1756 (if pri " \\3" "")
1757 " \\4"
1758 (if tags " \\5" "")))
1759 (goto-char (point-min))
1760 (while (re-search-forward re nil t)
1761 (replace-match rpl t nil)))))
1762
1763 (defun org-export-protect-quoted-subtrees ()
1764 "Mark quoted subtrees with the protection property."
1765 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1766 (goto-char (point-min))
1767 (while (re-search-forward re-quote nil t)
1768 (goto-char (match-beginning 0))
1769 (end-of-line 1)
1770 (add-text-properties (point) (org-end-of-subtree t)
1771 '(org-protected t)))))
1772
1773 (defun org-export-protect-verbatim ()
1774 "Mark verbatim snippets with the protection property."
1775 (goto-char (point-min))
1776 (while (re-search-forward org-verbatim-re nil t)
1777 (add-text-properties (match-beginning 4) (match-end 4)
1778 '(org-protected t))
1779 (goto-char (1+ (match-end 4)))))
1780
1781 (defun org-export-protect-examples (&optional indent)
1782 "Protect code that should be exported as monospaced examples."
1783 (goto-char (point-min))
1784 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
1785 (goto-char (match-end 0))
1786 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1787 (insert (if indent ": " ":"))
1788 (beginning-of-line 2)))
1789 (goto-char (point-min))
1790 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
1791 (add-text-properties (match-beginning 0) (match-end 0)
1792 '(org-protected t))))
1793
1794 (defun org-export-select-backend-specific-text (backend)
1795 (let ((formatters
1796 '((html "HTML" "BEGIN_HTML" "END_HTML")
1797 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1798 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1799 fmt)
1800
1801 (while formatters
1802 (setq fmt (pop formatters))
1803 (when (eq (car fmt) backend)
1804 ;; This is selected code, put it into the file for real
1805 (goto-char (point-min))
1806 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1807 ":[ \t]*\\(.*\\)") nil t)
1808 (replace-match "\\1" t)
1809 (add-text-properties
1810 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1811 '(org-protected t))))
1812 (goto-char (point-min))
1813 (while (re-search-forward
1814 (concat "^#\\+"
1815 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1816 (cadddr fmt) "\\>.*\n?") nil t)
1817 (if (eq (car fmt) backend)
1818 ;; yes, keep this
1819 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1820 '(org-protected t))
1821 ;; No, this is for a different backend, kill it
1822 (delete-region (match-beginning 0) (match-end 0)))))))
1823
1824 (defun org-export-mark-blockquote-and-verse ()
1825 "Mark block quote and verse environments with special cookies.
1826 These special cookies will later be interpreted by the backend."
1827 ;; Blockquotes
1828 (goto-char (point-min))
1829 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1830 nil t)
1831 (replace-match (if (equal (downcase (match-string 1)) "end")
1832 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1833 t t))
1834 ;; Verse
1835 (goto-char (point-min))
1836 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1837 (replace-match (if (equal (downcase (match-string 1)) "end")
1838 "ORG-VERSE-END" "ORG-VERSE-START")
1839 t t)))
1840
1841 (defun org-export-remove-comment-blocks-and-subtrees ()
1842 "Remove the comment environment, and also commented subtrees."
1843 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1844 (case-fold-search nil))
1845 ;; Remove comment environment
1846 (goto-char (point-min))
1847 (while (re-search-forward
1848 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1849 (replace-match "" t t))
1850 ;; Remove subtrees that are commented
1851 (goto-char (point-min))
1852 (while (re-search-forward re-commented nil t)
1853 (goto-char (match-beginning 0))
1854 (delete-region (point) (org-end-of-subtree t)))))
1855
1856 (defun org-export-handle-comments (commentsp)
1857 "Remove comments, or convert to backend-specific format.
1858 COMMENTSP can be a format string for publishing comments.
1859 When it is nil, all comments will be removed."
1860 (let ((re "^#\\(.*\n?\\)")
1861 pos)
1862 (goto-char (point-min))
1863 (while (or (looking-at re)
1864 (re-search-forward re nil t))
1865 (setq pos (match-beginning 0))
1866 (if commentsp
1867 (progn (add-text-properties
1868 (match-beginning 0) (match-end 0) '(org-protected t))
1869 (replace-match (format commentsp (match-string 1)) t t))
1870 (goto-char (1+ pos))
1871 (org-if-unprotected
1872 (replace-match "")
1873 (goto-char (max (point-min) (1- pos))))))))
1874
1875 (defun org-export-mark-radio-links ()
1876 "Find all matches for radio targets and turn them into internal links."
1877 (let ((re-radio (and org-target-link-regexp
1878 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1879 (goto-char (point-min))
1880 (when re-radio
1881 (while (re-search-forward re-radio nil t)
1882 (org-if-unprotected
1883 (replace-match "\\1[[\\2]]"))))))
1884
1885 (defun org-export-remove-special-table-lines ()
1886 "Remove tables lines that are used for internal purposes."
1887 (goto-char (point-min))
1888 (while (re-search-forward "^[ \t]*|" nil t)
1889 (beginning-of-line 1)
1890 (if (or (looking-at "[ \t]*| *[!_^] *|")
1891 (and (looking-at ".*?| *<[0-9]+> *|")
1892 (not (looking-at ".*?| *[^ <|]"))))
1893 (delete-region (max (point-min) (1- (point-at-bol)))
1894 (point-at-eol))
1895 (end-of-line 1))))
1896
1897 (defun org-export-normalize-links ()
1898 "Convert all links to bracket links, and expand link abbreviations."
1899 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1900 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1901 (goto-char (point-min))
1902 (while (re-search-forward re-plain-link nil t)
1903 (goto-char (1- (match-end 0)))
1904 (org-if-unprotected
1905 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1906 ":" (match-string 3) "]]")))
1907 ;; added 'org-link face to links
1908 (put-text-property 0 (length s) 'face 'org-link s)
1909 (replace-match s t t))))
1910 (goto-char (point-min))
1911 (while (re-search-forward re-angle-link nil t)
1912 (goto-char (1- (match-end 0)))
1913 (org-if-unprotected
1914 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1915 ":" (match-string 3) "]]")))
1916 (put-text-property 0 (length s) 'face 'org-link s)
1917 (replace-match s t t))))
1918 (goto-char (point-min))
1919 (while (re-search-forward org-bracket-link-regexp nil t)
1920 (goto-char (1- (match-end 0)))
1921 (org-if-unprotected
1922 (let* ((xx (save-match-data
1923 (org-translate-link
1924 (org-link-expand-abbrev (match-string 1)))))
1925 (s (concat
1926 "[[" xx "]"
1927 (if (match-end 3)
1928 (match-string 2)
1929 (concat "[" xx "]"))
1930 "]")))
1931 (put-text-property 0 (length s) 'face 'org-link s)
1932 (replace-match s t t))))))
1933
1934 (defun org-export-concatenate-multiline-links ()
1935 "Find multi-line links and put it all into a single line.
1936 This is to make sure that the line-processing export backends
1937 can work correctly."
1938 (goto-char (point-min))
1939 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1940 (org-if-unprotected
1941 (replace-match "\\1 \\3")
1942 (goto-char (match-beginning 0)))))
1943
1944 (defun org-export-concatenate-multiline-emphasis ()
1945 "Find multi-line emphasis and put it all into a single line.
1946 This is to make sure that the line-processing export backends
1947 can work correctly."
1948 (goto-char (point-min))
1949 (while (re-search-forward org-emph-re nil t)
1950 (if (not (= (char-after (match-beginning 3))
1951 (char-after (match-beginning 4))))
1952 (org-if-unprotected
1953 (subst-char-in-region (match-beginning 0) (match-end 0)
1954 ?\n ?\ t)
1955 (goto-char (1- (match-end 0))))
1956 (goto-char (1+ (match-beginning 0))))))
1957
1958 (defun org-export-grab-title-from-buffer ()
1959 "Get a title for the current document, from looking at the buffer."
1960 (let ((inhibit-read-only t))
1961 (save-excursion
1962 (goto-char (point-min))
1963 (let ((end (if (looking-at org-outline-regexp)
1964 (point)
1965 (save-excursion (outline-next-heading) (point)))))
1966 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1967 ;; Mark the line so that it will not be exported as normal text.
1968 (org-unmodified
1969 (add-text-properties (match-beginning 0) (match-end 0)
1970 (list :org-license-to-kill t)))
1971 ;; Return the title string
1972 (org-trim (match-string 0)))))))
1973
1974 (defun org-export-get-title-from-subtree ()
1975 "Return subtree title and exclude it from export."
1976 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1977 (save-excursion
1978 (goto-char rbeg)
1979 (when (and (org-at-heading-p)
1980 (>= (org-end-of-subtree t t) rend))
1981 ;; This is a subtree, we take the title from the first heading
1982 (goto-char rbeg)
1983 (looking-at org-todo-line-regexp)
1984 (setq title (match-string 3))
1985 (org-unmodified
1986 (add-text-properties (point) (1+ (point-at-eol))
1987 (list :org-license-to-kill t)))
1988 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1989 title))
1990
1991 (defun org-solidify-link-text (s &optional alist)
1992 "Take link text and make a safe target out of it."
1993 (save-match-data
1994 (let* ((rtn
1995 (mapconcat
1996 'identity
1997 (org-split-string s "[ \t\r\n]+") "=="))
1998 (a (assoc rtn alist)))
1999 (or (cdr a) rtn))))
2000
2001 (defun org-get-min-level (lines)
2002 "Get the minimum level in LINES."
2003 (let ((re "^\\(\\*+\\) ") l min)
2004 (catch 'exit
2005 (while (setq l (pop lines))
2006 (if (string-match re l)
2007 (throw 'exit (org-tr-level (length (match-string 1 l))))))
2008 1)))
2009
2010 ;; Variable holding the vector with section numbers
2011 (defvar org-section-numbers (make-vector org-level-max 0))
2012
2013 (defun org-init-section-numbers ()
2014 "Initialize the vector for the section numbers."
2015 (let* ((level -1)
2016 (numbers (nreverse (org-split-string "" "\\.")))
2017 (depth (1- (length org-section-numbers)))
2018 (i depth) number-string)
2019 (while (>= i 0)
2020 (if (> i level)
2021 (aset org-section-numbers i 0)
2022 (setq number-string (or (car numbers) "0"))
2023 (if (string-match "\\`[A-Z]\\'" number-string)
2024 (aset org-section-numbers i
2025 (- (string-to-char number-string) ?A -1))
2026 (aset org-section-numbers i (string-to-number number-string)))
2027 (pop numbers))
2028 (setq i (1- i)))))
2029
2030 (defun org-section-number (&optional level)
2031 "Return a string with the current section number.
2032 When LEVEL is non-nil, increase section numbers on that level."
2033 (let* ((depth (1- (length org-section-numbers)))
2034 (string "")
2035 (fmts (car org-export-section-number-format))
2036 (term (cdr org-export-section-number-format))
2037 (sep "")
2038 ctype fmt idx n)
2039 (when level
2040 (when (> level -1)
2041 (aset org-section-numbers
2042 level (1+ (aref org-section-numbers level))))
2043 (setq idx (1+ level))
2044 (while (<= idx depth)
2045 (if (not (= idx 1))
2046 (aset org-section-numbers idx 0))
2047 (setq idx (1+ idx))))
2048 (setq idx 0)
2049 (while (<= idx depth)
2050 (when (> (aref org-section-numbers idx) 0)
2051 (setq fmt (or (pop fmts) fmt)
2052 ctype (car fmt)
2053 n (aref org-section-numbers idx)
2054 string (if (> n 0)
2055 (concat string sep (org-number-to-counter n ctype))
2056 (concat string ".0"))
2057 sep (nth 1 fmt)))
2058 (setq idx (1+ idx)))
2059 (save-match-data
2060 (if (string-match "\\`\\([@0]\\.\\)+" string)
2061 (setq string (replace-match "" t nil string)))
2062 (if (string-match "\\(\\.0\\)+\\'" string)
2063 (setq string (replace-match "" t nil string))))
2064 (concat string term)))
2065
2066 (defun org-number-to-counter (n type)
2067 "Concert number N to a string counter, according to TYPE.
2068 TYPE must be a string, any of:
2069 1 number
2070 A A,B,....
2071 a a,b,....
2072 I uppper case roman numeral
2073 i lower case roman numeral"
2074 (cond
2075 ((equal type "1") (number-to-string n))
2076 ((equal type "A") (char-to-string (+ ?A n -1)))
2077 ((equal type "a") (char-to-string (+ ?a n -1)))
2078 ((equal type "I") (org-number-to-roman n))
2079 ((equal type "i") (downcase (org-number-to-roman n)))
2080 (t (error "Invalid counter type `%s'" type))))
2081
2082 (defun org-number-to-roman (n)
2083 "Convert integer N into a roman numeral."
2084 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2085 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2086 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2087 ( 1 . "I")))
2088 (res ""))
2089 (if (<= n 0)
2090 (number-to-string n)
2091 (while roman
2092 (if (>= n (caar roman))
2093 (setq n (- n (caar roman))
2094 res (concat res (cdar roman)))
2095 (pop roman)))
2096 res)))
2097
2098 (org-number-to-roman 1961)
2099
2100
2101 ;;; Include files
2102
2103 (defun org-export-handle-include-files ()
2104 "Include the contents of include files, with proper formatting."
2105 (let ((case-fold-search t)
2106 params file markup lang start end prefix prefix1)
2107 (goto-char (point-min))
2108 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2109 (setq params (read (concat "(" (match-string 1) ")"))
2110 prefix (org-get-and-remove-property 'params :prefix)
2111 prefix1 (org-get-and-remove-property 'params :prefix1)
2112 file (org-symname-or-string (pop params))
2113 markup (org-symname-or-string (pop params))
2114 lang (org-symname-or-string (pop params)))
2115 (delete-region (match-beginning 0) (match-end 0))
2116 (if (or (not file)
2117 (not (file-exists-p file))
2118 (not (file-readable-p file)))
2119 (insert (format "CANNOT INCLUDE FILE %s" file))
2120 (when markup
2121 (if (equal (downcase markup) "src")
2122 (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
2123 end "#+end_src")
2124 (setq start (format "#+begin_%s\n" markup)
2125 end (format "#+end_%s" markup))))
2126 (insert (or start ""))
2127 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2128 (or (bolp) (newline))
2129 (insert (or end ""))))))
2130
2131 (defun org-get-file-contents (file &optional prefix prefix1)
2132 "Get the contents of FILE and return them as a string.
2133 If PREFIX is a string, prepend it to each line. If PREFIX1
2134 is a string, prepend it to the first line instead of PREFIX."
2135 (with-temp-buffer
2136 (insert-file-contents file)
2137 (when (or prefix prefix1)
2138 (goto-char (point-min))
2139 (while (not (eobp))
2140 (insert (or prefix1 prefix))
2141 (setq prefix1 nil)
2142 (beginning-of-line 2)))
2143 (buffer-string)))
2144
2145 (defun org-get-and-remove-property (listvar prop)
2146 "Check if the value of LISTVAR contains PROP as a property.
2147 If yes, return the value of that property (i.e. the element following
2148 in the list) and remove property and value from the list in LISTVAR."
2149 (let ((list (symbol-value listvar)) m v)
2150 (when (setq m (member prop list))
2151 (setq v (nth 1 m))
2152 (if (equal (car list) prop)
2153 (set listvar (cddr list))
2154 (setcdr (nthcdr (- (length list) (length m) 1) list)
2155 (cddr m))
2156 (set listvar list)))
2157 v))
2158
2159 (defun org-symname-or-string (s)
2160 (if (symbolp s)
2161 (if s (symbol-name s) s)
2162 s))
2163
2164 ;;; Fontification of code
2165 ;; Currently only for the HTML backend, but who knows....
2166 (defun org-export-replace-src-segments ()
2167 "Replace source code segments with special code for export."
2168 (let ((case-fold-search t)
2169 lang code trans)
2170 (goto-char (point-min))
2171 (while (re-search-forward
2172 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2173 nil t)
2174 (setq lang (match-string 1) code (match-string 2)
2175 trans (org-export-format-source-code lang code))
2176 (replace-match trans t t))))
2177
2178 (defvar htmlp) ;; dynamically scoped from org-exp.el
2179
2180 (defun org-export-format-source-code (lang code)
2181 "Format CODE from language LANG and return it formatted for export.
2182 Currently, this only does something for HTML export, for all other
2183 backends, it converts the segment into an EXAMPLE segment."
2184 (save-match-data
2185 (cond
2186 (htmlp
2187 ;; We are exporting to HTML
2188 (require 'htmlize nil t)
2189 (if (not (fboundp 'htmlize-region-for-paste))
2190 (progn
2191 ;; we do not have htmlize.el, or an old version of it
2192 (message
2193 "htmlize.el 1.34 or later is needed for source code formatting")
2194 (concat "#+BEGIN_EXAMPLE\n" code
2195 (if (string-match "\n\\'" code) "" "\n")
2196 "#+END_EXAMPLE\n"))
2197 ;; ok, we are good to go
2198 (let* ((mode (and lang (intern (concat lang "-mode"))))
2199 (org-inhibit-startup t)
2200 (org-startup-folded nil)
2201 (htmltext
2202 (with-temp-buffer
2203 (insert code)
2204 ;; Free up the protected stuff
2205 (goto-char (point-min))
2206 (while (re-search-forward "^," nil t)
2207 (replace-match "")
2208 (end-of-line 1))
2209 (if (functionp mode)
2210 (funcall mode)
2211 (fundamental-mode))
2212 (font-lock-fontify-buffer)
2213 (org-export-htmlize-region-for-paste
2214 (point-min) (point-max)))))
2215 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
2216 (setq htmltext (replace-match
2217 (format "<pre class=\"src src-%s\">" lang)
2218 t t htmltext)))
2219 (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
2220 (t
2221 ;; This is not HTML, so just make it an example.
2222 (when (equal lang "org")
2223 (while (string-match "^," code)
2224 (setq code (replace-match "" t t code))))
2225 (concat "#+BEGIN_EXAMPLE\n" code
2226 (if (string-match "\n\\'" code) "" "\n")
2227 "#+END_EXAMPLE\n")))))
2228
2229 ;;; ASCII export
2230
2231 (defvar org-last-level nil) ; dynamically scoped variable
2232 (defvar org-min-level nil) ; dynamically scoped variable
2233 (defvar org-levels-open nil) ; dynamically scoped parameter
2234 (defvar org-ascii-current-indentation nil) ; For communication
2235
2236 ;;;###autoload
2237 (defun org-export-as-ascii (arg)
2238 "Export the outline as a pretty ASCII file.
2239 If there is an active region, export only the region.
2240 The prefix ARG specifies how many levels of the outline should become
2241 underlined headlines. The default is 3."
2242 (interactive "P")
2243 (setq-default org-todo-line-regexp org-todo-line-regexp)
2244 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2245 (org-infile-export-plist)))
2246 (region-p (org-region-active-p))
2247 (rbeg (and region-p (region-beginning)))
2248 (rend (and region-p (region-end)))
2249 (subtree-p
2250 (when region-p
2251 (save-excursion
2252 (goto-char rbeg)
2253 (and (org-at-heading-p)
2254 (>= (org-end-of-subtree t t) rend)))))
2255 (opt-plist (if subtree-p
2256 (org-export-add-subtree-options opt-plist rbeg)
2257 opt-plist))
2258 (custom-times org-display-custom-times)
2259 (org-ascii-current-indentation '(0 . 0))
2260 (level 0) line txt
2261 (umax nil)
2262 (umax-toc nil)
2263 (case-fold-search nil)
2264 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2265 (filename (concat (file-name-as-directory
2266 (org-export-directory :ascii opt-plist))
2267 (file-name-sans-extension
2268 (or (and subtree-p
2269 (org-entry-get (region-beginning)
2270 "EXPORT_FILE_NAME" t))
2271 (file-name-nondirectory bfname)))
2272 ".txt"))
2273 (filename (if (equal (file-truename filename)
2274 (file-truename bfname))
2275 (concat filename ".txt")
2276 filename))
2277 (buffer (find-file-noselect filename))
2278 (org-levels-open (make-vector org-level-max nil))
2279 (odd org-odd-levels-only)
2280 (date (plist-get opt-plist :date))
2281 (author (plist-get opt-plist :author))
2282 (title (or (and subtree-p (org-export-get-title-from-subtree))
2283 (plist-get opt-plist :title)
2284 (and (not
2285 (plist-get opt-plist :skip-before-1st-heading))
2286 (org-export-grab-title-from-buffer))
2287 (file-name-sans-extension
2288 (file-name-nondirectory bfname))))
2289 (email (plist-get opt-plist :email))
2290 (language (plist-get opt-plist :language))
2291 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2292 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2293 (todo nil)
2294 (lang-words nil)
2295 (region
2296 (buffer-substring
2297 (if (org-region-active-p) (region-beginning) (point-min))
2298 (if (org-region-active-p) (region-end) (point-max))))
2299 (lines (org-split-string
2300 (org-export-preprocess-string
2301 region
2302 :for-ascii t
2303 :skip-before-1st-heading
2304 (plist-get opt-plist :skip-before-1st-heading)
2305 :drawers (plist-get opt-plist :drawers)
2306 :tags (plist-get opt-plist :tags)
2307 :priority (plist-get opt-plist :priority)
2308 :todo-keywords (plist-get opt-plist :todo-keywords)
2309 :verbatim-multiline t
2310 :select-tags (plist-get opt-plist :select-tags)
2311 :exclude-tags (plist-get opt-plist :exclude-tags)
2312 :archived-trees
2313 (plist-get opt-plist :archived-trees)
2314 :add-text (plist-get opt-plist :text))
2315 "\n"))
2316 thetoc have-headings first-heading-pos
2317 table-open table-buffer)
2318
2319 (let ((inhibit-read-only t))
2320 (org-unmodified
2321 (remove-text-properties (point-min) (point-max)
2322 '(:org-license-to-kill t))))
2323
2324 (setq org-min-level (org-get-min-level lines))
2325 (setq org-last-level org-min-level)
2326 (org-init-section-numbers)
2327
2328 (find-file-noselect filename)
2329
2330 (setq lang-words (or (assoc language org-export-language-setup)
2331 (assoc "en" org-export-language-setup)))
2332 (switch-to-buffer-other-window buffer)
2333 (erase-buffer)
2334 (fundamental-mode)
2335 ;; create local variables for all options, to make sure all called
2336 ;; functions get the correct information
2337 (mapc (lambda (x)
2338 (set (make-local-variable (nth 2 x))
2339 (plist-get opt-plist (car x))))
2340 org-export-plist-vars)
2341 (org-set-local 'org-odd-levels-only odd)
2342 (setq umax (if arg (prefix-numeric-value arg)
2343 org-export-headline-levels))
2344 (setq umax-toc (if (integerp org-export-with-toc)
2345 (min org-export-with-toc umax)
2346 umax))
2347
2348 ;; File header
2349 (if title (org-insert-centered title ?=))
2350 (insert "\n")
2351 (if (and (or author email)
2352 org-export-author-info)
2353 (insert (concat (nth 1 lang-words) ": " (or author "")
2354 (if email (concat " <" email ">") "")
2355 "\n")))
2356
2357 (cond
2358 ((and date (string-match "%" date))
2359 (setq date (format-time-string date)))
2360 (date)
2361 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2362
2363 (if (and date org-export-time-stamp-file)
2364 (insert (concat (nth 2 lang-words) ": " date"\n")))
2365
2366 (insert "\n\n")
2367
2368 (if org-export-with-toc
2369 (progn
2370 (push (concat (nth 3 lang-words) "\n") thetoc)
2371 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2372 "\n") thetoc)
2373 (mapc '(lambda (line)
2374 (if (string-match org-todo-line-regexp
2375 line)
2376 ;; This is a headline
2377 (progn
2378 (setq have-headings t)
2379 (setq level (- (match-end 1) (match-beginning 1))
2380 level (org-tr-level level)
2381 txt (match-string 3 line)
2382 todo
2383 (or (and org-export-mark-todo-in-toc
2384 (match-beginning 2)
2385 (not (member (match-string 2 line)
2386 org-done-keywords)))
2387 ; TODO, not DONE
2388 (and org-export-mark-todo-in-toc
2389 (= level umax-toc)
2390 (org-search-todo-below
2391 line lines level))))
2392 (setq txt (org-html-expand-for-ascii txt))
2393
2394 (while (string-match org-bracket-link-regexp txt)
2395 (setq txt
2396 (replace-match
2397 (match-string (if (match-end 2) 3 1) txt)
2398 t t txt)))
2399
2400 (if (and (memq org-export-with-tags '(not-in-toc nil))
2401 (string-match
2402 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2403 txt))
2404 (setq txt (replace-match "" t t txt)))
2405 (if (string-match quote-re0 txt)
2406 (setq txt (replace-match "" t t txt)))
2407
2408 (if org-export-with-section-numbers
2409 (setq txt (concat (org-section-number level)
2410 " " txt)))
2411 (if (<= level umax-toc)
2412 (progn
2413 (push
2414 (concat
2415 (make-string
2416 (* (max 0 (- level org-min-level)) 4) ?\ )
2417 (format (if todo "%s (*)\n" "%s\n") txt))
2418 thetoc)
2419 (setq org-last-level level))
2420 ))))
2421 lines)
2422 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2423
2424 (org-init-section-numbers)
2425 (while (setq line (pop lines))
2426 ;; Remove the quoted HTML tags.
2427 (setq line (org-html-expand-for-ascii line))
2428 ;; Replace links with the description when possible
2429 (while (string-match org-bracket-link-regexp line)
2430 (setq line (replace-match
2431 (if (match-end 3) "[\\3]" "[\\1]")
2432 t nil line)))
2433 (when custom-times
2434 (setq line (org-translate-time line)))
2435 (cond
2436 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2437 ;; a Headline
2438 (setq first-heading-pos (or first-heading-pos (point)))
2439 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
2440 txt (match-string 2 line))
2441 (org-ascii-level-start level txt umax lines))
2442
2443 ((and org-export-with-tables
2444 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2445 (if (not table-open)
2446 ;; New table starts
2447 (setq table-open t table-buffer nil))
2448 ;; Accumulate lines
2449 (setq table-buffer (cons line table-buffer))
2450 (when (or (not lines)
2451 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2452 (car lines))))
2453 (setq table-open nil
2454 table-buffer (nreverse table-buffer))
2455 (insert (mapconcat
2456 (lambda (x)
2457 (org-fix-indentation x org-ascii-current-indentation))
2458 (org-format-table-ascii table-buffer)
2459 "\n") "\n")))
2460 (t
2461 (setq line (org-fix-indentation line org-ascii-current-indentation))
2462 ;; Remove forced line breaks
2463 (if (string-match "\\\\\\\\[ \t]*$" line)
2464 (setq line (replace-match "" t t line)))
2465 (if (and org-export-with-fixed-width
2466 (string-match "^\\([ \t]*\\)\\(:\\)" line))
2467 (setq line (replace-match "\\1" nil nil line)))
2468 (insert line "\n"))))
2469
2470 (normal-mode)
2471
2472 ;; insert the table of contents
2473 (when thetoc
2474 (goto-char (point-min))
2475 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2476 (progn
2477 (goto-char (match-beginning 0))
2478 (replace-match ""))
2479 (goto-char first-heading-pos))
2480 (mapc 'insert thetoc)
2481 (or (looking-at "[ \t]*\n[ \t]*\n")
2482 (insert "\n\n")))
2483
2484 ;; Convert whitespace place holders
2485 (goto-char (point-min))
2486 (let (beg end)
2487 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2488 (setq end (next-single-property-change beg 'org-whitespace))
2489 (goto-char beg)
2490 (delete-region beg end)
2491 (insert (make-string (- end beg) ?\ ))))
2492
2493 (save-buffer)
2494 ;; remove display and invisible chars
2495 (let (beg end)
2496 (goto-char (point-min))
2497 (while (setq beg (next-single-property-change (point) 'display))
2498 (setq end (next-single-property-change beg 'display))
2499 (delete-region beg end)
2500 (goto-char beg)
2501 (insert "=>"))
2502 (goto-char (point-min))
2503 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2504 (setq end (next-single-property-change beg 'org-cwidth))
2505 (delete-region beg end)
2506 (goto-char beg)))
2507 (goto-char (point-min))))
2508
2509 (defun org-export-ascii-preprocess ()
2510 "Do extra work for ASCII export"
2511 ;; Put quotes around verbatim text
2512 (goto-char (point-min))
2513 (while (re-search-forward org-verbatim-re nil t)
2514 (goto-char (match-end 2))
2515 (backward-delete-char 1) (insert "'")
2516 (goto-char (match-beginning 2))
2517 (delete-char 1) (insert "`")
2518 (goto-char (match-end 2)))
2519 (goto-char (point-min))
2520 ;; Remove target markers
2521 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
2522 (replace-match "\\1\\2")))
2523
2524 (defun org-search-todo-below (line lines level)
2525 "Search the subtree below LINE for any TODO entries."
2526 (let ((rest (cdr (memq line lines)))
2527 (re org-todo-line-regexp)
2528 line lv todo)
2529 (catch 'exit
2530 (while (setq line (pop rest))
2531 (if (string-match re line)
2532 (progn
2533 (setq lv (- (match-end 1) (match-beginning 1))
2534 todo (and (match-beginning 2)
2535 (not (member (match-string 2 line)
2536 org-done-keywords))))
2537 ; TODO, not DONE
2538 (if (<= lv level) (throw 'exit nil))
2539 (if todo (throw 'exit t))))))))
2540
2541 (defun org-html-expand-for-ascii (line)
2542 "Handle quoted HTML for ASCII export."
2543 (if org-export-html-expand
2544 (while (string-match "@<[^<>\n]*>" line)
2545 ;; We just remove the tags for now.
2546 (setq line (replace-match "" nil nil line))))
2547 line)
2548
2549 (defun org-insert-centered (s &optional underline)
2550 "Insert the string S centered and underline it with character UNDERLINE."
2551 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2552 (insert (make-string ind ?\ ) s "\n")
2553 (if underline
2554 (insert (make-string ind ?\ )
2555 (make-string (string-width s) underline)
2556 "\n"))))
2557
2558 (defun org-ascii-level-start (level title umax &optional lines)
2559 "Insert a new level in ASCII export."
2560 (let (char (n (- level umax 1)) (ind 0))
2561 (if (> level umax)
2562 (progn
2563 (insert (make-string (* 2 n) ?\ )
2564 (char-to-string (nth (% n (length org-export-ascii-bullets))
2565 org-export-ascii-bullets))
2566 " " title "\n")
2567 ;; find the indentation of the next non-empty line
2568 (catch 'stop
2569 (while lines
2570 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2571 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2572 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2573 (pop lines)))
2574 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2575 (if (or (not (equal (char-before) ?\n))
2576 (not (equal (char-before (1- (point))) ?\n)))
2577 (insert "\n"))
2578 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2579 (unless org-export-with-tags
2580 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
2581 (setq title (replace-match "" t t title))))
2582 (if org-export-with-section-numbers
2583 (setq title (concat (org-section-number level) " " title)))
2584 (insert title "\n" (make-string (string-width title) char) "\n")
2585 (setq org-ascii-current-indentation '(0 . 0)))))
2586
2587 ;;;###autoload
2588 (defun org-export-visible (type arg)
2589 "Create a copy of the visible part of the current buffer, and export it.
2590 The copy is created in a temporary buffer and removed after use.
2591 TYPE is the final key (as a string) that also select the export command in
2592 the `C-c C-e' export dispatcher.
2593 As a special case, if the you type SPC at the prompt, the temporary
2594 org-mode file will not be removed but presented to you so that you can
2595 continue to use it. The prefix arg ARG is passed through to the exporting
2596 command."
2597 (interactive
2598 (list (progn
2599 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2600 (read-char-exclusive))
2601 current-prefix-arg))
2602 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
2603 (error "Invalid export key"))
2604 (let* ((binding (cdr (assoc type
2605 '((?a . org-export-as-ascii)
2606 (?\C-a . org-export-as-ascii)
2607 (?b . org-export-as-html-and-open)
2608 (?\C-b . org-export-as-html-and-open)
2609 (?h . org-export-as-html)
2610 (?H . org-export-as-html-to-buffer)
2611 (?R . org-export-region-as-html)
2612 (?x . org-export-as-xoxo)))))
2613 (keepp (equal type ?\ ))
2614 (file buffer-file-name)
2615 (buffer (get-buffer-create "*Org Export Visible*"))
2616 s e)
2617 ;; Need to hack the drawers here.
2618 (save-excursion
2619 (goto-char (point-min))
2620 (while (re-search-forward org-drawer-regexp nil t)
2621 (goto-char (match-beginning 1))
2622 (or (org-invisible-p) (org-flag-drawer nil))))
2623 (with-current-buffer buffer (erase-buffer))
2624 (save-excursion
2625 (setq s (goto-char (point-min)))
2626 (while (not (= (point) (point-max)))
2627 (goto-char (org-find-invisible))
2628 (append-to-buffer buffer s (point))
2629 (setq s (goto-char (org-find-visible))))
2630 (org-cycle-hide-drawers 'all)
2631 (goto-char (point-min))
2632 (unless keepp
2633 ;; Copy all comment lines to the end, to make sure #+ settings are
2634 ;; still available for the second export step. Kind of a hack, but
2635 ;; does do the trick.
2636 (if (looking-at "#[^\r\n]*")
2637 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2638 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2639 (append-to-buffer buffer (1+ (match-beginning 0))
2640 (min (point-max) (1+ (match-end 0))))))
2641 (set-buffer buffer)
2642 (let ((buffer-file-name file)
2643 (org-inhibit-startup t))
2644 (org-mode)
2645 (show-all)
2646 (unless keepp (funcall binding arg))))
2647 (if (not keepp)
2648 (kill-buffer buffer)
2649 (switch-to-buffer-other-window buffer)
2650 (goto-char (point-min)))))
2651
2652 (defun org-find-visible ()
2653 (let ((s (point)))
2654 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2655 (get-char-property s 'invisible)))
2656 s))
2657 (defun org-find-invisible ()
2658 (let ((s (point)))
2659 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2660 (not (get-char-property s 'invisible))))
2661 s))
2662
2663 ;;; HTML export
2664
2665 (defvar org-archive-location) ;; gets loades with the org-archive require.
2666 (defun org-get-current-options ()
2667 "Return a string with current options as keyword options.
2668 Does include HTML export options as well as TODO and CATEGORY stuff."
2669 (require 'org-archive)
2670 (format
2671 "#+TITLE: %s
2672 #+AUTHOR: %s
2673 #+EMAIL: %s
2674 #+DATE: %s
2675 #+LANGUAGE: %s
2676 #+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
2677 %s
2678 #+EXPORT_SELECT_TAGS: %s
2679 #+EXPORT_EXCLUDE_TAGS: %s
2680 #+LINK_UP: %s
2681 #+LINK_HOME: %s
2682 #+CATEGORY: %s
2683 #+SEQ_TODO: %s
2684 #+TYP_TODO: %s
2685 #+PRIORITIES: %c %c %c
2686 #+DRAWERS: %s
2687 #+STARTUP: %s %s %s %s %s
2688 #+TAGS: %s
2689 #+FILETAGS: %s
2690 #+ARCHIVE: %s
2691 #+LINK: %s
2692 "
2693 (buffer-name) (user-full-name) user-mail-address
2694 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2695 org-export-default-language
2696 org-export-headline-levels
2697 org-export-with-section-numbers
2698 org-export-with-toc
2699 org-export-preserve-breaks
2700 org-export-html-expand
2701 org-export-with-fixed-width
2702 org-export-with-tables
2703 org-export-with-sub-superscripts
2704 org-export-with-special-strings
2705 org-export-with-footnotes
2706 org-export-with-emphasize
2707 org-export-with-TeX-macros
2708 org-export-with-LaTeX-fragments
2709 org-export-skip-text-before-1st-heading
2710 org-export-with-drawers
2711 org-export-with-todo-keywords
2712 org-export-with-priority
2713 org-export-with-tags
2714 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2715 (mapconcat 'identity org-export-select-tags " ")
2716 (mapconcat 'identity org-export-exclude-tags " ")
2717 org-export-html-link-up
2718 org-export-html-link-home
2719 (file-name-nondirectory buffer-file-name)
2720 "TODO FEEDBACK VERIFY DONE"
2721 "Me Jason Marie DONE"
2722 org-highest-priority org-lowest-priority org-default-priority
2723 (mapconcat 'identity org-drawers " ")
2724 (cdr (assoc org-startup-folded
2725 '((nil . "showall") (t . "overview") (content . "content"))))
2726 (if org-odd-levels-only "odd" "oddeven")
2727 (if org-hide-leading-stars "hidestars" "showstars")
2728 (if org-startup-align-all-tables "align" "noalign")
2729 (cond ((eq org-log-done t) "logdone")
2730 ((equal org-log-done 'note) "lognotedone")
2731 ((not org-log-done) "nologdone"))
2732 (or (mapconcat (lambda (x)
2733 (cond
2734 ((equal '(:startgroup) x) "{")
2735 ((equal '(:endgroup) x) "}")
2736 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2737 (t (car x))))
2738 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2739 (mapconcat 'identity org-file-tags " ")
2740 org-archive-location
2741 "org file:~/org/%s.org"
2742 ))
2743
2744 (defun org-export-html-preprocess (parameters)
2745 ;; Convert LaTeX fragments to images
2746 (when (plist-get parameters :LaTeX-fragments)
2747 (org-format-latex
2748 (concat "ltxpng/" (file-name-sans-extension
2749 (file-name-nondirectory
2750 org-current-export-file)))
2751 org-current-export-dir nil "Creating LaTeX image %s"))
2752 (message "Exporting..."))
2753
2754 ;;;###autoload
2755 (defun org-insert-export-options-template ()
2756 "Insert into the buffer a template with information for exporting."
2757 (interactive)
2758 (if (not (bolp)) (newline))
2759 (let ((s (org-get-current-options)))
2760 (and (string-match "#\\+CATEGORY" s)
2761 (setq s (substring s 0 (match-beginning 0))))
2762 (insert s)))
2763
2764 ;;;###autoload
2765 (defun org-export-as-html-and-open (arg)
2766 "Export the outline as HTML and immediately open it with a browser.
2767 If there is an active region, export only the region.
2768 The prefix ARG specifies how many levels of the outline should become
2769 headlines. The default is 3. Lower levels will become bulleted lists."
2770 (interactive "P")
2771 (org-export-as-html arg 'hidden)
2772 (org-open-file buffer-file-name))
2773
2774 ;;;###autoload
2775 (defun org-export-as-html-batch ()
2776 "Call `org-export-as-html', may be used in batch processing as
2777 emacs --batch
2778 --load=$HOME/lib/emacs/org.el
2779 --eval \"(setq org-export-headline-levels 2)\"
2780 --visit=MyFile --funcall org-export-as-html-batch"
2781 (org-export-as-html org-export-headline-levels 'hidden))
2782
2783 ;;;###autoload
2784 (defun org-export-as-html-to-buffer (arg)
2785 "Call `org-exort-as-html` with output to a temporary buffer.
2786 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2787 (interactive "P")
2788 (org-export-as-html arg nil nil "*Org HTML Export*")
2789 (switch-to-buffer-other-window "*Org HTML Export*"))
2790
2791 ;;;###autoload
2792 (defun org-replace-region-by-html (beg end)
2793 "Assume the current region has org-mode syntax, and convert it to HTML.
2794 This can be used in any buffer. For example, you could write an
2795 itemized list in org-mode syntax in an HTML buffer and then use this
2796 command to convert it."
2797 (interactive "r")
2798 (let (reg html buf pop-up-frames)
2799 (save-window-excursion
2800 (if (org-mode-p)
2801 (setq html (org-export-region-as-html
2802 beg end t 'string))
2803 (setq reg (buffer-substring beg end)
2804 buf (get-buffer-create "*Org tmp*"))
2805 (with-current-buffer buf
2806 (erase-buffer)
2807 (insert reg)
2808 (org-mode)
2809 (setq html (org-export-region-as-html
2810 (point-min) (point-max) t 'string)))
2811 (kill-buffer buf)))
2812 (delete-region beg end)
2813 (insert html)))
2814
2815 ;;;###autoload
2816 (defun org-export-region-as-html (beg end &optional body-only buffer)
2817 "Convert region from BEG to END in org-mode buffer to HTML.
2818 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2819 contents, and only produce the region of converted text, useful for
2820 cut-and-paste operations.
2821 If BUFFER is a buffer or a string, use/create that buffer as a target
2822 of the converted HTML. If BUFFER is the symbol `string', return the
2823 produced HTML as a string and leave not buffer behind. For example,
2824 a Lisp program could call this function in the following way:
2825
2826 (setq html (org-export-region-as-html beg end t 'string))
2827
2828 When called interactively, the output buffer is selected, and shown
2829 in a window. A non-interactive call will only return the buffer."
2830 (interactive "r\nP")
2831 (when (interactive-p)
2832 (setq buffer "*Org HTML Export*"))
2833 (let ((transient-mark-mode t) (zmacs-regions t)
2834 ext-plist rtn)
2835 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2836 (goto-char end)
2837 (set-mark (point)) ;; to activate the region
2838 (goto-char beg)
2839 (setq rtn (org-export-as-html
2840 nil nil ext-plist
2841 buffer body-only))
2842 (if (fboundp 'deactivate-mark) (deactivate-mark))
2843 (if (and (interactive-p) (bufferp rtn))
2844 (switch-to-buffer-other-window rtn)
2845 rtn)))
2846
2847 (defvar html-table-tag nil) ; dynamically scoped into this.
2848 (defvar org-par-open nil)
2849 ;;;###autoload
2850 (defun org-export-as-html (arg &optional hidden ext-plist
2851 to-buffer body-only pub-dir)
2852 "Export the outline as a pretty HTML file.
2853 If there is an active region, export only the region. The prefix
2854 ARG specifies how many levels of the outline should become
2855 headlines. The default is 3. Lower levels will become bulleted
2856 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2857 EXT-PLIST is a property list with external parameters overriding
2858 org-mode's default settings, but still inferior to file-local
2859 settings. When TO-BUFFER is non-nil, create a buffer with that
2860 name and export to that buffer. If TO-BUFFER is the symbol
2861 `string', don't leave any buffer behind but just return the
2862 resulting HTML as a string. When BODY-ONLY is set, don't produce
2863 the file header and footer, simply return the content of
2864 <body>...</body>, without even the body tags themselves. When
2865 PUB-DIR is set, use this as the publishing directory."
2866 (interactive "P")
2867
2868 ;; Make sure we have a file name when we need it.
2869 (when (and (not (or to-buffer body-only))
2870 (not buffer-file-name))
2871 (if (buffer-base-buffer)
2872 (org-set-local 'buffer-file-name
2873 (with-current-buffer (buffer-base-buffer)
2874 buffer-file-name))
2875 (error "Need a file name to be able to export.")))
2876
2877 (message "Exporting...")
2878 (setq-default org-todo-line-regexp org-todo-line-regexp)
2879 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2880 (setq-default org-done-keywords org-done-keywords)
2881 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2882 (let* ((opt-plist
2883 (org-export-process-option-filters
2884 (org-combine-plists (org-default-export-plist)
2885 ext-plist
2886 (org-infile-export-plist))))
2887 (style (concat (if (plist-get opt-plist :style-include-default)
2888 org-export-html-style-default)
2889 (plist-get opt-plist :style)
2890 (plist-get opt-plist :style-extra)))
2891 (html-extension (plist-get opt-plist :html-extension))
2892 (link-validate (plist-get opt-plist :link-validation-function))
2893 valid thetoc have-headings first-heading-pos
2894 (odd org-odd-levels-only)
2895 (region-p (org-region-active-p))
2896 (rbeg (and region-p (region-beginning)))
2897 (rend (and region-p (region-end)))
2898 (subtree-p
2899 (if (plist-get opt-plist :ignore-subree-p)
2900 nil
2901 (when region-p
2902 (save-excursion
2903 (goto-char rbeg)
2904 (and (org-at-heading-p)
2905 (>= (org-end-of-subtree t t) rend))))))
2906 (opt-plist (if subtree-p
2907 (org-export-add-subtree-options opt-plist rbeg)
2908 opt-plist))
2909 ;; The following two are dynamically scoped into other
2910 ;; routines below.
2911 (org-current-export-dir
2912 (or pub-dir (org-export-directory :html opt-plist)))
2913 (org-current-export-file buffer-file-name)
2914 (level 0) (line "") (origline "") txt todo
2915 (umax nil)
2916 (umax-toc nil)
2917 (filename (if to-buffer nil
2918 (expand-file-name
2919 (concat
2920 (file-name-sans-extension
2921 (or (and subtree-p
2922 (org-entry-get (region-beginning)
2923 "EXPORT_FILE_NAME" t))
2924 (file-name-nondirectory buffer-file-name)))
2925 "." html-extension)
2926 (file-name-as-directory
2927 (or pub-dir (org-export-directory :html opt-plist))))))
2928 (current-dir (if buffer-file-name
2929 (file-name-directory buffer-file-name)
2930 default-directory))
2931 (buffer (if to-buffer
2932 (cond
2933 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2934 (t (get-buffer-create to-buffer)))
2935 (find-file-noselect filename)))
2936 (org-levels-open (make-vector org-level-max nil))
2937 (date (plist-get opt-plist :date))
2938 (author (plist-get opt-plist :author))
2939 (title (or (and subtree-p (org-export-get-title-from-subtree))
2940 (plist-get opt-plist :title)
2941 (and (not
2942 (plist-get opt-plist :skip-before-1st-heading))
2943 (org-export-grab-title-from-buffer))
2944 (and buffer-file-name
2945 (file-name-sans-extension
2946 (file-name-nondirectory buffer-file-name)))
2947 "UNTITLED"))
2948 (html-table-tag (plist-get opt-plist :html-table-tag))
2949 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2950 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2951 (inquote nil)
2952 (infixed nil)
2953 (inverse nil)
2954 (in-local-list nil)
2955 (local-list-type nil)
2956 (local-list-indent nil)
2957 (llt org-plain-list-ordered-item-terminator)
2958 (email (plist-get opt-plist :email))
2959 (language (plist-get opt-plist :language))
2960 (lang-words nil)
2961 (head-count 0) cnt
2962 (start 0)
2963 (coding-system (and (boundp 'buffer-file-coding-system)
2964 buffer-file-coding-system))
2965 (coding-system-for-write (or org-export-html-coding-system
2966 coding-system))
2967 (save-buffer-coding-system (or org-export-html-coding-system
2968 coding-system))
2969 (charset (and coding-system-for-write
2970 (fboundp 'coding-system-get)
2971 (coding-system-get coding-system-for-write
2972 'mime-charset)))
2973 (region
2974 (buffer-substring
2975 (if region-p (region-beginning) (point-min))
2976 (if region-p (region-end) (point-max))))
2977 (lines
2978 (org-split-string
2979 (org-export-preprocess-string
2980 region
2981 :emph-multiline t
2982 :for-html t
2983 :skip-before-1st-heading
2984 (plist-get opt-plist :skip-before-1st-heading)
2985 :drawers (plist-get opt-plist :drawers)
2986 :todo-keywords (plist-get opt-plist :todo-keywords)
2987 :tags (plist-get opt-plist :tags)
2988 :priority (plist-get opt-plist :priority)
2989 :archived-trees
2990 (plist-get opt-plist :archived-trees)
2991 :select-tags (plist-get opt-plist :select-tags)
2992 :exclude-tags (plist-get opt-plist :exclude-tags)
2993 :add-text
2994 (plist-get opt-plist :text)
2995 :LaTeX-fragments
2996 (plist-get opt-plist :LaTeX-fragments))
2997 "[\r\n]"))
2998 table-open type
2999 table-buffer table-orig-buffer
3000 ind item-type starter didclose
3001 rpl path attr desc descp desc1 desc2 link
3002 snumber fnc item-tag
3003 footnotes
3004 )
3005
3006 (let ((inhibit-read-only t))
3007 (org-unmodified
3008 (remove-text-properties (point-min) (point-max)
3009 '(:org-license-to-kill t))))
3010
3011 (message "Exporting...")
3012
3013 (setq org-min-level (org-get-min-level lines))
3014 (setq org-last-level org-min-level)
3015 (org-init-section-numbers)
3016
3017 (cond
3018 ((and date (string-match "%" date))
3019 (setq date (format-time-string date)))
3020 (date)
3021 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3022
3023 ;; Get the language-dependent settings
3024 (setq lang-words (or (assoc language org-export-language-setup)
3025 (assoc "en" org-export-language-setup)))
3026
3027 ;; Switch to the output buffer
3028 (set-buffer buffer)
3029 (let ((inhibit-read-only t)) (erase-buffer))
3030 (fundamental-mode)
3031
3032 (and (fboundp 'set-buffer-file-coding-system)
3033 (set-buffer-file-coding-system coding-system-for-write))
3034
3035 (let ((case-fold-search nil)
3036 (org-odd-levels-only odd))
3037 ;; create local variables for all options, to make sure all called
3038 ;; functions get the correct information
3039 (mapc (lambda (x)
3040 (set (make-local-variable (nth 2 x))
3041 (plist-get opt-plist (car x))))
3042 org-export-plist-vars)
3043 (setq umax (if arg (prefix-numeric-value arg)
3044 org-export-headline-levels))
3045 (setq umax-toc (if (integerp org-export-with-toc)
3046 (min org-export-with-toc umax)
3047 umax))
3048 (unless body-only
3049 ;; File header
3050 (insert (format
3051 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3052 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3053 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3054 lang=\"%s\" xml:lang=\"%s\">
3055 <head>
3056 <title>%s</title>
3057 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3058 <meta name=\"generator\" content=\"Org-mode\"/>
3059 <meta name=\"generated\" content=\"%s\"/>
3060 <meta name=\"author\" content=\"%s\"/>
3061 %s
3062 </head><body>
3063 "
3064 language language (org-html-expand title)
3065 (or charset "iso-8859-1") date author style))
3066
3067 (insert (or (plist-get opt-plist :preamble) ""))
3068
3069 (when (plist-get opt-plist :auto-preamble)
3070 (if title (insert (format org-export-html-title-format
3071 (org-html-expand title))))))
3072
3073 (if (and org-export-with-toc (not body-only))
3074 (progn
3075 (push (format "<h%d>%s</h%d>\n"
3076 org-export-html-toplevel-hlevel
3077 (nth 3 lang-words)
3078 org-export-html-toplevel-hlevel)
3079 thetoc)
3080 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3081 (push "<ul>\n<li>" thetoc)
3082 (setq lines
3083 (mapcar '(lambda (line)
3084 (if (string-match org-todo-line-regexp line)
3085 ;; This is a headline
3086 (progn
3087 (setq have-headings t)
3088 (setq level (- (match-end 1) (match-beginning 1))
3089 level (org-tr-level level)
3090 txt (save-match-data
3091 (org-html-expand
3092 (org-export-cleanup-toc-line
3093 (match-string 3 line))))
3094 todo
3095 (or (and org-export-mark-todo-in-toc
3096 (match-beginning 2)
3097 (not (member (match-string 2 line)
3098 org-done-keywords)))
3099 ; TODO, not DONE
3100 (and org-export-mark-todo-in-toc
3101 (= level umax-toc)
3102 (org-search-todo-below
3103 line lines level))))
3104 (if (string-match
3105 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3106 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3107 (if (string-match quote-re0 txt)
3108 (setq txt (replace-match "" t t txt)))
3109 (setq snumber (org-section-number level))
3110 (if org-export-with-section-numbers
3111 (setq txt (concat snumber " " txt)))
3112 (if (<= level (max umax umax-toc))
3113 (setq head-count (+ head-count 1)))
3114 (if (<= level umax-toc)
3115 (progn
3116 (if (> level org-last-level)
3117 (progn
3118 (setq cnt (- level org-last-level))
3119 (while (>= (setq cnt (1- cnt)) 0)
3120 (push "\n<ul>\n<li>" thetoc))
3121 (push "\n" thetoc)))
3122 (if (< level org-last-level)
3123 (progn
3124 (setq cnt (- org-last-level level))
3125 (while (>= (setq cnt (1- cnt)) 0)
3126 (push "</li>\n</ul>" thetoc))
3127 (push "\n" thetoc)))
3128 ;; Check for targets
3129 (while (string-match org-any-target-regexp line)
3130 (setq line (replace-match
3131 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3132 t t line)))
3133 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3134 (setq txt (replace-match "" t t txt)))
3135 (push
3136 (format
3137 (if todo
3138 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3139 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3140 snumber txt) thetoc)
3141
3142 (setq org-last-level level))
3143 )))
3144 line)
3145 lines))
3146 (while (> org-last-level (1- org-min-level))
3147 (setq org-last-level (1- org-last-level))
3148 (push "</li>\n</ul>\n" thetoc))
3149 (push "</div>\n" thetoc)
3150 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3151
3152 (setq head-count 0)
3153 (org-init-section-numbers)
3154
3155 (org-open-par)
3156
3157 (while (setq line (pop lines) origline line)
3158 (catch 'nextline
3159
3160 ;; end of quote section?
3161 (when (and inquote (string-match "^\\*+ " line))
3162 (insert "</pre>\n")
3163 (setq inquote nil))
3164 ;; inside a quote section?
3165 (when inquote
3166 (insert (org-html-protect line) "\n")
3167 (throw 'nextline nil))
3168
3169 ;; Fixed-width, verbatim lines (examples)
3170 (when (and org-export-with-fixed-width
3171 (string-match "^[ \t]*:\\(.*\\)" line))
3172 (when (not infixed)
3173 (setq infixed t)
3174 (org-close-par-maybe)
3175 (insert "<pre class=\"example\">\n"))
3176 (insert (org-html-protect (match-string 1 line)) "\n")
3177 (when (or (not lines)
3178 (not (string-match "^[ \t]*\\(:.*\\)"
3179 (car lines))))
3180 (setq infixed nil)
3181 (insert "</pre>\n"))
3182 (throw 'nextline nil))
3183
3184 ;; Protected HTML
3185 (when (get-text-property 0 'org-protected line)
3186 (let (par)
3187 (when (re-search-backward
3188 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3189 (setq par (match-string 1))
3190 (replace-match "\\2\n"))
3191 (insert line "\n")
3192 (while (and lines
3193 (not (string-match "^[ \t]*:" (car lines)))
3194 (or (= (length (car lines)) 0)
3195 (get-text-property 0 'org-protected (car lines))))
3196 (insert (pop lines) "\n"))
3197 (and par (insert "<p>\n")))
3198 (throw 'nextline nil))
3199
3200 ;; Horizontal line
3201 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3202 (if org-par-open
3203 (insert "\n</p>\n<hr/>\n<p>\n")
3204 (insert "\n<hr/>\n"))
3205 (throw 'nextline nil))
3206
3207 ;; Blockquotes and verse
3208 (when (equal "ORG-BLOCKQUOTE-START" line)
3209 (insert "<blockquote>\n<p>\n")
3210 (throw 'nextline nil))
3211 (when (equal "ORG-BLOCKQUOTE-END" line)
3212 (insert "</p>\n</blockquote>\n")
3213 (throw 'nextline nil))
3214 (when (equal "ORG-VERSE-START" line)
3215 (insert "\n<p class=\"verse\">\n")
3216 (setq inverse t)
3217 (throw 'nextline nil))
3218 (when (equal "ORG-VERSE-END" line)
3219 (insert "</p>\n")
3220 (setq inverse nil)
3221 (throw 'nextline nil))
3222 (when inverse
3223 (let ((i (org-get-string-indentation line)))
3224 (if (> i 0)
3225 (setq line (concat (mapconcat 'identity
3226 (make-list (* 2 i) "\\nbsp") "")
3227 " " (org-trim line))))
3228 (setq line (concat line " \\\\"))))
3229
3230 ;; make targets to anchors
3231 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3232 (cond
3233 ((match-end 2)
3234 (setq line (replace-match
3235 (format
3236 "@<a name=\"%s\" id=\"%s\">@</a>"
3237 (org-solidify-link-text (match-string 1 line))
3238 (org-solidify-link-text (match-string 1 line)))
3239 t t line)))
3240 ((and org-export-with-toc (equal (string-to-char line) ?*))
3241 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3242 (setq line (replace-match
3243 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3244 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3245 t t line)))
3246 (t
3247 (setq line (replace-match
3248 (concat "@<a name=\""
3249 (org-solidify-link-text (match-string 1 line))
3250 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3251 t t line)))))
3252
3253 (setq line (org-html-handle-time-stamps line))
3254
3255 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3256 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3257 ;; Also handle sub_superscripts and checkboxes
3258 (or (string-match org-table-hline-regexp line)
3259 (setq line (org-html-expand line)))
3260
3261 ;; Format the links
3262 (setq start 0)
3263 (while (string-match org-bracket-link-analytic-regexp line start)
3264 (setq start (match-beginning 0))
3265 (setq path (save-match-data (org-link-unescape
3266 (match-string 3 line))))
3267 (setq type (cond
3268 ((match-end 2) (match-string 2 line))
3269 ((save-match-data
3270 (or (file-name-absolute-p path)
3271 (string-match "^\\.\\.?/" path)))
3272 "file")
3273 (t "internal")))
3274 (setq path (org-extract-attributes path))
3275 (setq attr (org-attributes-to-string
3276 (get-text-property 0 'org-attributes path)))
3277 (setq desc1 (if (match-end 5) (match-string 5 line))
3278 desc2 (if (match-end 2) (concat type ":" path) path)
3279 descp (and desc1 (not (equal desc1 desc2)))
3280 desc (or desc1 desc2))
3281 ;; Make an image out of the description if that is so wanted
3282 (when (and descp (org-file-image-p desc))
3283 (save-match-data
3284 (if (string-match "^file:" desc)
3285 (setq desc (substring desc (match-end 0)))))
3286 (setq desc (org-add-props
3287 (concat "<img src=\"" desc "\"/>")
3288 '(org-protected t))))
3289 ;; FIXME: do we need to unescape here somewhere?
3290 (cond
3291 ((equal type "internal")
3292 (setq rpl
3293 (concat
3294 "<a href=\"#"
3295 (org-solidify-link-text
3296 (save-match-data (org-link-unescape path)) nil)
3297 "\"" attr ">"
3298 (org-export-html-format-desc desc)
3299 "</a>")))
3300 ((member type '("http" "https"))
3301 ;; standard URL, just check if we need to inline an image
3302 (if (and (or (eq t org-export-html-inline-images)
3303 (and org-export-html-inline-images (not descp)))
3304 (org-file-image-p path))
3305 (setq rpl (concat "<img src=\"" type ":" path "\""
3306 (if (string-match "\\<alt=" attr)
3307 attr (concat attr " alt=\"" path "\""))
3308 "/>"))
3309 (setq link (concat type ":" path))
3310 (setq rpl (concat "<a href=\""
3311 (org-export-html-format-href link)
3312 "\"" attr ">"
3313 (org-export-html-format-desc desc)
3314 "</a>"))))
3315 ((member type '("ftp" "mailto" "news"))
3316 ;; standard URL
3317 (setq link (concat type ":" path))
3318 (setq rpl (concat "<a href=\""
3319 (org-export-html-format-href link)
3320 "\"" attr ">"
3321 (org-export-html-format-desc desc)
3322 "</a>")))
3323
3324 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3325 ;; The link protocol has a function for format the link
3326 (setq rpl
3327 (save-match-data
3328 (funcall fnc (org-link-unescape path) desc1 'html))))
3329
3330 ((string= type "file")
3331 ;; FILE link
3332 (let* ((filename path)
3333 (abs-p (file-name-absolute-p filename))
3334 thefile file-is-image-p search)
3335 (save-match-data
3336 (if (string-match "::\\(.*\\)" filename)
3337 (setq search (match-string 1 filename)
3338 filename (replace-match "" t nil filename)))
3339 (setq valid
3340 (if (functionp link-validate)
3341 (funcall link-validate filename current-dir)
3342 t))
3343 (setq file-is-image-p (org-file-image-p filename))
3344 (setq thefile (if abs-p (expand-file-name filename) filename))
3345 (when (and org-export-html-link-org-files-as-html
3346 (string-match "\\.org$" thefile))
3347 (setq thefile (concat (substring thefile 0
3348 (match-beginning 0))
3349 "." html-extension))
3350 (if (and search
3351 ;; make sure this is can be used as target search
3352 (not (string-match "^[0-9]*$" search))
3353 (not (string-match "^\\*" search))
3354 (not (string-match "^/.*/$" search)))
3355 (setq thefile (concat thefile "#"
3356 (org-solidify-link-text
3357 (org-link-unescape search)))))
3358 (when (string-match "^file:" desc)
3359 (setq desc (replace-match "" t t desc))
3360 (if (string-match "\\.org$" desc)
3361 (setq desc (replace-match "" t t desc))))))
3362 (setq rpl (if (and file-is-image-p
3363 (or (eq t org-export-html-inline-images)
3364 (and org-export-html-inline-images
3365 (not descp))))
3366 (concat "<img src=\"" thefile "\""
3367 (if (string-match "alt=" attr)
3368 attr
3369 (concat attr " alt=\""
3370 thefile "\"")) "/>")
3371 (concat "<a href=\"" thefile "\"" attr ">"
3372 (org-export-html-format-desc desc)
3373 "</a>")))
3374 (if (not valid) (setq rpl desc))))
3375
3376 (t
3377 ;; just publish the path, as default
3378 (setq rpl (concat "<i>&lt;" type ":"
3379 (save-match-data (org-link-unescape path))
3380 "&gt;</i>"))))
3381 (setq line (replace-match rpl t t line)
3382 start (+ start (length rpl))))
3383
3384 ;; TODO items
3385 (if (and (string-match org-todo-line-regexp line)
3386 (match-beginning 2))
3387
3388 (setq line
3389 (concat (substring line 0 (match-beginning 2))
3390 "<span class=\""
3391 (if (member (match-string 2 line)
3392 org-done-keywords)
3393 "done" "todo")
3394 "\">" (match-string 2 line)
3395 "</span>" (substring line (match-end 2)))))
3396
3397 ;; Does this contain a reference to a footnote?
3398 (when org-export-with-footnotes
3399 (setq start 0)
3400 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3401 (if (get-text-property (match-beginning 2) 'org-protected line)
3402 (setq start (match-end 2))
3403 (let ((n (match-string 2 line)))
3404 (setq line
3405 (replace-match
3406 (format
3407 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3408 (match-string 1 line) n n n)
3409 t t line))))))
3410
3411 (cond
3412 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3413 ;; This is a headline
3414 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
3415 txt (match-string 2 line))
3416 (if (string-match quote-re0 txt)
3417 (setq txt (replace-match "" t t txt)))
3418 (if (<= level (max umax umax-toc))
3419 (setq head-count (+ head-count 1)))
3420 (when in-local-list
3421 ;; Close any local lists before inserting a new header line
3422 (while local-list-type
3423 (org-close-li (car local-list-type))
3424 (insert (format "</%sl>\n" (car local-list-type)))
3425 (pop local-list-type))
3426 (setq local-list-indent nil
3427 in-local-list nil))
3428 (setq first-heading-pos (or first-heading-pos (point)))
3429 (org-html-level-start level txt umax
3430 (and org-export-with-toc (<= level umax))
3431 head-count)
3432 ;; QUOTES
3433 (when (string-match quote-re line)
3434 (org-close-par-maybe)
3435 (insert "<pre>")
3436 (setq inquote t)))
3437
3438 ((and org-export-with-tables
3439 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3440 (if (not table-open)
3441 ;; New table starts
3442 (setq table-open t table-buffer nil table-orig-buffer nil))
3443 ;; Accumulate lines
3444 (setq table-buffer (cons line table-buffer)
3445 table-orig-buffer (cons origline table-orig-buffer))
3446 (when (or (not lines)
3447 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3448 (car lines))))
3449 (setq table-open nil
3450 table-buffer (nreverse table-buffer)
3451 table-orig-buffer (nreverse table-orig-buffer))
3452 (org-close-par-maybe)
3453 (insert (org-format-table-html table-buffer table-orig-buffer))))
3454 (t
3455 ;; Normal lines
3456 (when (string-match
3457 (cond
3458 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3459 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3460 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3461 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3462 line)
3463 (setq ind (org-get-string-indentation line)
3464 item-type (if (match-beginning 4) "o" "u")
3465 starter (if (match-beginning 2)
3466 (substring (match-string 2 line) 0 -1))
3467 line (substring line (match-beginning 5))
3468 item-tag nil)
3469 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3470 (setq item-type "d"
3471 item-tag (match-string 1 line)
3472 line (substring line (match-end 0))))
3473 (when (and (not (equal item-type "d"))
3474 (not (string-match "[^ \t]" line)))
3475 ;; empty line. Pretend indentation is large.
3476 (setq ind (if org-empty-line-terminates-plain-lists
3477 0
3478 (1+ (or (car local-list-indent) 1)))))
3479 (setq didclose nil)
3480 (while (and in-local-list
3481 (or (and (= ind (car local-list-indent))
3482 (not starter))
3483 (< ind (car local-list-indent))))
3484 (setq didclose t)
3485 (org-close-li (car local-list-type))
3486 (insert (format "</%sl>\n" (car local-list-type)))
3487 (pop local-list-type) (pop local-list-indent)
3488 (setq in-local-list local-list-indent))
3489 (cond
3490 ((and starter
3491 (or (not in-local-list)
3492 (> ind (car local-list-indent))))
3493 ;; Start new (level of) list
3494 (org-close-par-maybe)
3495 (insert (cond
3496 ((equal item-type "u") "<ul>\n<li>\n")
3497 ((equal item-type "o") "<ol>\n<li>\n")
3498 ((equal item-type "d")
3499 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3500 (push item-type local-list-type)
3501 (push ind local-list-indent)
3502 (setq in-local-list t))
3503 (starter
3504 ;; continue current list
3505 (org-close-li (car local-list-type))
3506 (insert (cond
3507 ((equal (car local-list-type) "d")
3508 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3509 (t "<li>\n"))))
3510 (didclose
3511 ;; we did close a list, normal text follows: need <p>
3512 (org-open-par)))
3513 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3514 (setq line
3515 (replace-match
3516 (if (equal (match-string 1 line) "X")
3517 "<b>[X]</b>"
3518 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3519 t t line))))
3520
3521 ;; Empty lines start a new paragraph. If hand-formatted lists
3522 ;; are not fully interpreted, lines starting with "-", "+", "*"
3523 ;; also start a new paragraph.
3524 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3525
3526 ;; Is this the start of a footnote?
3527 (when org-export-with-footnotes
3528 (when (and (boundp 'footnote-section-tag-regexp)
3529 (string-match (concat "^" footnote-section-tag-regexp)
3530 line))
3531 ;; ignore this line
3532 (throw 'nextline nil))
3533 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3534 (org-close-par-maybe)
3535 (let ((n (match-string 1 line)))
3536 (setq org-par-open t
3537 line (replace-match
3538 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
3539
3540 ;; Check if the line break needs to be conserved
3541 (cond
3542 ((string-match "\\\\\\\\[ \t]*$" line)
3543 (setq line (replace-match "<br/>" t t line)))
3544 (org-export-preserve-breaks
3545 (setq line (concat line "<br/>"))))
3546
3547 (insert line "\n")))))
3548
3549 ;; Properly close all local lists and other lists
3550 (when inquote
3551 (insert "</pre>\n")
3552 (org-open-par))
3553 (when in-local-list
3554 ;; Close any local lists before inserting a new header line
3555 (while local-list-type
3556 (org-close-li (car local-list-type))
3557 (insert (format "</%sl>\n" (car local-list-type)))
3558 (pop local-list-type))
3559 (setq local-list-indent nil
3560 in-local-list nil))
3561 (org-html-level-start 1 nil umax
3562 (and org-export-with-toc (<= level umax))
3563 head-count)
3564 ;; the </div> to close the last text-... div.
3565 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
3566
3567 (save-excursion
3568 (goto-char (point-min))
3569 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
3570 (push (match-string 0) footnotes)
3571 (replace-match "" t t)))
3572 (when footnotes
3573 (insert (format org-export-html-footnotes-section
3574 (or (nth 4 lang-words) "Footnotes")
3575 (mapconcat 'identity (nreverse footnotes) "\n"))
3576 "\n"))
3577 (unless body-only
3578 (when (plist-get opt-plist :auto-postamble)
3579 (insert "<div id=\"postamble\">")
3580 (when (and org-export-author-info author)
3581 (insert "<p class=\"author\"> "
3582 (nth 1 lang-words) ": " author "\n")
3583 (when email
3584 (if (listp (split-string email ",+ *"))
3585 (mapc (lambda(e)
3586 (insert "<a href=\"mailto:" e "\">&lt;"
3587 e "&gt;</a>\n"))
3588 (split-string email ",+ *"))
3589 (insert "<a href=\"mailto:" email "\">&lt;"
3590 email "&gt;</a>\n")))
3591 (insert "</p>\n"))
3592 (when (and date org-export-time-stamp-file)
3593 (insert "<p class=\"date\"> "
3594 (nth 2 lang-words) ": "
3595 date "</p>\n"))
3596 (when org-export-creator-info
3597 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3598 org-version emacs-major-version)))
3599 (insert "</div>"))
3600
3601 (if org-export-html-with-timestamp
3602 (insert org-export-html-html-helper-timestamp))
3603 (insert (or (plist-get opt-plist :postamble) ""))
3604 (insert "</body>\n</html>\n"))
3605
3606 (unless (plist-get opt-plist :buffer-will-be-killed)
3607 (normal-mode)
3608 (if (eq major-mode default-major-mode) (html-mode)))
3609
3610 ;; insert the table of contents
3611 (goto-char (point-min))
3612 (when thetoc
3613 (if (or (re-search-forward
3614 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3615 (re-search-forward
3616 "\\[TABLE-OF-CONTENTS\\]" nil t))
3617 (progn
3618 (goto-char (match-beginning 0))
3619 (replace-match ""))
3620 (goto-char first-heading-pos)
3621 (when (looking-at "\\s-*</p>")
3622 (goto-char (match-end 0))
3623 (insert "\n")))
3624 (insert "<div id=\"table-of-contents\">\n")
3625 (mapc 'insert thetoc)
3626 (insert "</div>\n"))
3627 ;; remove empty paragraphs and lists
3628 (goto-char (point-min))
3629 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3630 (replace-match ""))
3631 (goto-char (point-min))
3632 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3633 (replace-match ""))
3634 (goto-char (point-min))
3635 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3636 (replace-match ""))
3637 ;; Convert whitespace place holders
3638 (goto-char (point-min))
3639 (let (beg end n)
3640 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3641 (setq n (get-text-property beg 'org-whitespace)
3642 end (next-single-property-change beg 'org-whitespace))
3643 (goto-char beg)
3644 (delete-region beg end)
3645 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3646 (make-string n ?x)))))
3647 (or to-buffer (save-buffer))
3648 (goto-char (point-min))
3649 (message "Exporting... done")
3650 (if (eq to-buffer 'string)
3651 (prog1 (buffer-substring (point-min) (point-max))
3652 (kill-buffer (current-buffer)))
3653 (current-buffer)))))
3654
3655 (defun org-export-html-format-href (s)
3656 "Make sure the S is valid as a href reference in an XHTML document."
3657 (save-match-data
3658 (let ((start 0))
3659 (while (string-match "&" s start)
3660 (setq start (+ (match-beginning 0) 3)
3661 s (replace-match "&amp;" t t s)))))
3662 s)
3663
3664 (defun org-export-html-format-desc (s)
3665 "Make sure the S is valid as a description in a link."
3666 (if (and s (not (get-text-property 1 'org-protected s)))
3667 (save-match-data
3668 (org-html-do-expand s))
3669 s))
3670
3671 (defvar org-table-colgroup-info nil)
3672 (defun org-format-table-ascii (lines)
3673 "Format a table for ascii export."
3674 (if (stringp lines)
3675 (setq lines (org-split-string lines "\n")))
3676 (if (not (string-match "^[ \t]*|" (car lines)))
3677 ;; Table made by table.el - test for spanning
3678 lines
3679
3680 ;; A normal org table
3681 ;; Get rid of hlines at beginning and end
3682 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3683 (setq lines (nreverse lines))
3684 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3685 (setq lines (nreverse lines))
3686 (when org-export-table-remove-special-lines
3687 ;; Check if the table has a marking column. If yes remove the
3688 ;; column and the special lines
3689 (setq lines (org-table-clean-before-export lines)))
3690 ;; Get rid of the vertical lines except for grouping
3691 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
3692 rtn line vl1 start)
3693 (while (setq line (pop lines))
3694 (if (string-match org-table-hline-regexp line)
3695 (and (string-match "|\\(.*\\)|" line)
3696 (setq line (replace-match " \\1" t nil line)))
3697 (setq start 0 vl1 vl)
3698 (while (string-match "|" line start)
3699 (setq start (match-end 0))
3700 (or (pop vl1) (setq line (replace-match " " t t line)))))
3701 (push line rtn))
3702 (nreverse rtn))))
3703
3704 (defun org-colgroup-info-to-vline-list (info)
3705 (let (vl new last)
3706 (while info
3707 (setq last new new (pop info))
3708 (if (or (memq last '(:end :startend))
3709 (memq new '(:start :startend)))
3710 (push t vl)
3711 (push nil vl)))
3712 (setq vl (nreverse vl))
3713 (and vl (setcar vl nil))
3714 vl))
3715
3716 (defvar org-table-number-regexp) ; defined in org-table.el
3717 (defun org-format-table-html (lines olines)
3718 "Find out which HTML converter to use and return the HTML code."
3719 (if (stringp lines)
3720 (setq lines (org-split-string lines "\n")))
3721 (if (string-match "^[ \t]*|" (car lines))
3722 ;; A normal org table
3723 (org-format-org-table-html lines)
3724 ;; Table made by table.el - test for spanning
3725 (let* ((hlines (delq nil (mapcar
3726 (lambda (x)
3727 (if (string-match "^[ \t]*\\+-" x) x
3728 nil))
3729 lines)))
3730 (first (car hlines))
3731 (ll (and (string-match "\\S-+" first)
3732 (match-string 0 first)))
3733 (re (concat "^[ \t]*" (regexp-quote ll)))
3734 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3735 hlines))))
3736 (if (and (not spanning)
3737 (not org-export-prefer-native-exporter-for-tables))
3738 ;; We can use my own converter with HTML conversions
3739 (org-format-table-table-html lines)
3740 ;; Need to use the code generator in table.el, with the original text.
3741 (org-format-table-table-html-using-table-generate-source olines)))))
3742
3743 (defvar org-table-number-fraction) ; defined in org-table.el
3744 (defun org-format-org-table-html (lines &optional splice)
3745 "Format a table into HTML."
3746 (require 'org-table)
3747 ;; Get rid of hlines at beginning and end
3748 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3749 (setq lines (nreverse lines))
3750 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3751 (setq lines (nreverse lines))
3752 (when org-export-table-remove-special-lines
3753 ;; Check if the table has a marking column. If yes remove the
3754 ;; column and the special lines
3755 (setq lines (org-table-clean-before-export lines)))
3756
3757 (let ((head (and org-export-highlight-first-table-line
3758 (delq nil (mapcar
3759 (lambda (x) (string-match "^[ \t]*|-" x))
3760 (cdr lines)))))
3761 (nlines 0) fnum i
3762 tbopen line fields html gr colgropen)
3763 (if splice (setq head nil))
3764 (unless splice (push (if head "<thead>" "<tbody>") html))
3765 (setq tbopen t)
3766 (while (setq line (pop lines))
3767 (catch 'next-line
3768 (if (string-match "^[ \t]*|-" line)
3769 (progn
3770 (unless splice
3771 (push (if head "</thead>" "</tbody>") html)
3772 (if lines (push "<tbody>" html) (setq tbopen nil)))
3773 (setq head nil) ;; head ends here, first time around
3774 ;; ignore this line
3775 (throw 'next-line t)))
3776 ;; Break the line into fields
3777 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3778 (unless fnum (setq fnum (make-vector (length fields) 0)))
3779 (setq nlines (1+ nlines) i -1)
3780 (push (concat "<tr>"
3781 (mapconcat
3782 (lambda (x)
3783 (setq i (1+ i))
3784 (if (and (< i nlines)
3785 (string-match org-table-number-regexp x))
3786 (incf (aref fnum i)))
3787 (if head
3788 (concat (car org-export-table-header-tags) x
3789 (cdr org-export-table-header-tags))
3790 (concat (car org-export-table-data-tags) x
3791 (cdr org-export-table-data-tags))))
3792 fields "")
3793 "</tr>")
3794 html)))
3795 (unless splice (if tbopen (push "</tbody>" html)))
3796 (unless splice (push "</table>\n" html))
3797 (setq html (nreverse html))
3798 (unless splice
3799 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3800 (push (mapconcat
3801 (lambda (x)
3802 (setq gr (pop org-table-colgroup-info))
3803 (format "%s<col align=\"%s\"></col>%s"
3804 (if (memq gr '(:start :startend))
3805 (prog1
3806 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3807 (setq colgropen t))
3808 "")
3809 (if (> (/ (float x) nlines) org-table-number-fraction)
3810 "right" "left")
3811 (if (memq gr '(:end :startend))
3812 (progn (setq colgropen nil) "</colgroup>")
3813 "")))
3814 fnum "")
3815 html)
3816 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3817 (push html-table-tag html))
3818 (concat (mapconcat 'identity html "\n") "\n")))
3819
3820 (defun org-table-clean-before-export (lines)
3821 "Check if the table has a marking column.
3822 If yes remove the column and the special lines."
3823 (setq org-table-colgroup-info nil)
3824 (if (memq nil
3825 (mapcar
3826 (lambda (x) (or (string-match "^[ \t]*|-" x)
3827 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
3828 lines))
3829 (progn
3830 (setq org-table-clean-did-remove-column nil)
3831 (delq nil
3832 (mapcar
3833 (lambda (x)
3834 (cond
3835 ((string-match "^[ \t]*| */ *|" x)
3836 (setq org-table-colgroup-info
3837 (mapcar (lambda (x)
3838 (cond ((member x '("<" "&lt;")) :start)
3839 ((member x '(">" "&gt;")) :end)
3840 ((member x '("<>" "&lt;&gt;")) :startend)
3841 (t nil)))
3842 (org-split-string x "[ \t]*|[ \t]*")))
3843 nil)
3844 (t x)))
3845 lines)))
3846 (setq org-table-clean-did-remove-column t)
3847 (delq nil
3848 (mapcar
3849 (lambda (x)
3850 (cond
3851 ((string-match "^[ \t]*| */ *|" x)
3852 (setq org-table-colgroup-info
3853 (mapcar (lambda (x)
3854 (cond ((member x '("<" "&lt;")) :start)
3855 ((member x '(">" "&gt;")) :end)
3856 ((member x '("<>" "&lt;&gt;")) :startend)
3857 (t nil)))
3858 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3859 nil)
3860 ((string-match "^[ \t]*| *[!_^/] *|" x)
3861 nil) ; ignore this line
3862 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3863 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3864 ;; remove the first column
3865 (replace-match "\\1|" t nil x))))
3866 lines))))
3867
3868 (defun org-format-table-table-html (lines)
3869 "Format a table generated by table.el into HTML.
3870 This conversion does *not* use `table-generate-source' from table.el.
3871 This has the advantage that Org-mode's HTML conversions can be used.
3872 But it has the disadvantage, that no cell- or row-spanning is allowed."
3873 (let (line field-buffer
3874 (head org-export-highlight-first-table-line)
3875 fields html empty)
3876 (setq html (concat html-table-tag "\n"))
3877 (while (setq line (pop lines))
3878 (setq empty "&nbsp;")
3879 (catch 'next-line
3880 (if (string-match "^[ \t]*\\+-" line)
3881 (progn
3882 (if field-buffer
3883 (progn
3884 (setq
3885 html
3886 (concat
3887 html
3888 "<tr>"
3889 (mapconcat
3890 (lambda (x)
3891 (if (equal x "") (setq x empty))
3892 (if head
3893 (concat (car org-export-table-header-tags) x
3894 (cdr org-export-table-header-tags))
3895 (concat (car org-export-table-data-tags) x
3896 (cdr org-export-table-data-tags))))
3897 field-buffer "\n")
3898 "</tr>\n"))
3899 (setq head nil)
3900 (setq field-buffer nil)))
3901 ;; Ignore this line
3902 (throw 'next-line t)))
3903 ;; Break the line into fields and store the fields
3904 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3905 (if field-buffer
3906 (setq field-buffer (mapcar
3907 (lambda (x)
3908 (concat x "<br/>" (pop fields)))
3909 field-buffer))
3910 (setq field-buffer fields))))
3911 (setq html (concat html "</table>\n"))
3912 html))
3913
3914 (defun org-format-table-table-html-using-table-generate-source (lines)
3915 "Format a table into html, using `table-generate-source' from table.el.
3916 This has the advantage that cell- or row-spanning is allowed.
3917 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3918 (require 'table)
3919 (with-current-buffer (get-buffer-create " org-tmp1 ")
3920 (erase-buffer)
3921 (insert (mapconcat 'identity lines "\n"))
3922 (goto-char (point-min))
3923 (if (not (re-search-forward "|[^+]" nil t))
3924 (error "Error processing table"))
3925 (table-recognize-table)
3926 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3927 (table-generate-source 'html " org-tmp2 ")
3928 (set-buffer " org-tmp2 ")
3929 (buffer-substring (point-min) (point-max))))
3930
3931 (defun org-export-splice-style (style extra)
3932 "Splice EXTRA into STYLE, just before \"</style>\"."
3933 (if (and (stringp extra)
3934 (string-match "\\S-" extra)
3935 (string-match "</style>" style))
3936 (concat (substring style 0 (match-beginning 0))
3937 "\n" extra "\n"
3938 (substring style (match-beginning 0)))
3939 style))
3940
3941 (defun org-html-handle-time-stamps (s)
3942 "Format time stamps in string S, or remove them."
3943 (catch 'exit
3944 (let (r b)
3945 (while (string-match org-maybe-keyword-time-regexp s)
3946 (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
3947 ;; never export CLOCK
3948 (throw 'exit ""))
3949 (or b (setq b (substring s 0 (match-beginning 0))))
3950 (if (not org-export-with-timestamps)
3951 (setq r (concat r (substring s 0 (match-beginning 0)))
3952 s (substring s (match-end 0)))
3953 (setq r (concat
3954 r (substring s 0 (match-beginning 0))
3955 (if (match-end 1)
3956 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3957 (match-string 1 s)))
3958 (format " @<span class=\"timestamp\">%s@</span>"
3959 (substring
3960 (org-translate-time (match-string 3 s)) 1 -1)))
3961 s (substring s (match-end 0)))))
3962 ;; Line break if line started and ended with time stamp stuff
3963 (if (not r)
3964 s
3965 (setq r (concat r s))
3966 (unless (string-match "\\S-" (concat b s))
3967 (setq r (concat r "@<br/>")))
3968 r))))
3969
3970 (defun org-export-htmlize-region-for-paste (beg end)
3971 "Convert the region to HTML, using htmlize.el.
3972 This is much like `htmlize-region-for-paste', only that it uses
3973 the settings define in the org-... variables."
3974 (let* ((htmlize-output-type org-export-htmlize-output-type)
3975 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
3976 (htmlbuf (htmlize-region beg end)))
3977 (unwind-protect
3978 (with-current-buffer htmlbuf
3979 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
3980 (plist-get htmlize-buffer-places 'content-end)))
3981 (kill-buffer htmlbuf))))
3982
3983 ;;;###autoload
3984 (defun org-export-htmlize-generate-css ()
3985 "Create the CSS for all font definitions in the current Emacs session.
3986 Use this to create face definitions in your CSS style file that can then
3987 be used by code snippets transformed by htmlize.
3988 This command just produces a buffer that contains class definitions for all
3989 faces used in the current Emacs session. You can copy and paste the ones you
3990 need into your CSS file.
3991
3992 If you then set `org-export-htmlize-output-type' to `css', calls to
3993 the function `org-export-htmlize-region-for-paste' will produce code
3994 that uses these same face definitions."
3995 (interactive)
3996 (require 'htmlize)
3997 (and (get-buffer "*html*") (kill-buffer "*html*"))
3998 (with-temp-buffer
3999 (let ((fl (face-list))
4000 (htmlize-css-name-prefix "org-")
4001 (htmlize-output-type 'css)
4002 f i)
4003 (while (setq f (pop fl)
4004 i (and f (face-attribute f :inherit)))
4005 (when (and (symbolp f) (or (not i) (not (listp i))))
4006 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4007 (htmlize-region (point-min) (point-max))))
4008 (switch-to-buffer "*html*")
4009 (goto-char (point-min))
4010 (if (re-search-forward "<style" nil t)
4011 (delete-region (point-min) (match-beginning 0)))
4012 (if (re-search-forward "</style>" nil t)
4013 (delete-region (1+ (match-end 0)) (point-max)))
4014 (beginning-of-line 1)
4015 (if (looking-at " +") (replace-match ""))
4016 (goto-char (point-min)))
4017
4018 (defun org-html-protect (s)
4019 ;; convert & to &amp;, < to &lt; and > to &gt;
4020 (let ((start 0))
4021 (while (string-match "&" s start)
4022 (setq s (replace-match "&amp;" t t s)
4023 start (1+ (match-beginning 0))))
4024 (while (string-match "<" s)
4025 (setq s (replace-match "&lt;" t t s)))
4026 (while (string-match ">" s)
4027 (setq s (replace-match "&gt;" t t s)))
4028 ; (while (string-match "\"" s)
4029 ; (setq s (replace-match "&quot;" t t s)))
4030 )
4031 s)
4032
4033 (defun org-export-cleanup-toc-line (s)
4034 "Remove tags and time staps from lines going into the toc."
4035 (when (memq org-export-with-tags '(not-in-toc nil))
4036 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4037 (setq s (replace-match "" t t s))))
4038 (when org-export-remove-timestamps-from-toc
4039 (while (string-match org-maybe-keyword-time-regexp s)
4040 (setq s (replace-match "" t t s))))
4041 (while (string-match org-bracket-link-regexp s)
4042 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4043 t t s)))
4044 s)
4045
4046 (defun org-html-expand (string)
4047 "Prepare STRING for HTML export. Applies all active conversions.
4048 If there are links in the string, don't modify these."
4049 (let* ((re (concat org-bracket-link-regexp "\\|"
4050 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4051 m s l res)
4052 (while (setq m (string-match re string))
4053 (setq s (substring string 0 m)
4054 l (match-string 0 string)
4055 string (substring string (match-end 0)))
4056 (push (org-html-do-expand s) res)
4057 (push l res))
4058 (push (org-html-do-expand string) res)
4059 (apply 'concat (nreverse res))))
4060
4061 (defun org-html-do-expand (s)
4062 "Apply all active conversions to translate special ASCII to HTML."
4063 (setq s (org-html-protect s))
4064 (if org-export-html-expand
4065 (let ((start 0))
4066 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
4067 (setq s (replace-match "<\\1>" t nil s)))))
4068 (if org-export-with-emphasize
4069 (setq s (org-export-html-convert-emphasize s)))
4070 (if org-export-with-special-strings
4071 (setq s (org-export-html-convert-special-strings s)))
4072 (if org-export-with-sub-superscripts
4073 (setq s (org-export-html-convert-sub-super s)))
4074 (if org-export-with-TeX-macros
4075 (let ((start 0) wd ass)
4076 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4077 s start))
4078 (if (get-text-property (match-beginning 0) 'org-protected s)
4079 (setq start (match-end 0))
4080 (setq wd (match-string 1 s))
4081 (if (setq ass (assoc wd org-html-entities))
4082 (setq s (replace-match (or (cdr ass)
4083 (concat "&" (car ass) ";"))
4084 t t s))
4085 (setq start (+ start (length wd))))))))
4086 s)
4087
4088 (defun org-create-multibrace-regexp (left right n)
4089 "Create a regular expression which will match a balanced sexp.
4090 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4091 as single character strings.
4092 The regexp returned will match the entire expression including the
4093 delimiters. It will also define a single group which contains the
4094 match except for the outermost delimiters. The maximum depth of
4095 stacked delimiters is N. Escaping delimiters is not possible."
4096 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
4097 (or "\\|")
4098 (re nothing)
4099 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4100 (while (> n 1)
4101 (setq n (1- n)
4102 re (concat re or next)
4103 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4104 (concat left "\\(" re "\\)" right)))
4105
4106 (defvar org-match-substring-regexp
4107 (concat
4108 "\\([^\\]\\)\\([_^]\\)\\("
4109 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4110 "\\|"
4111 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4112 "\\|"
4113 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4114 "The regular expression matching a sub- or superscript.")
4115
4116 (defvar org-match-substring-with-braces-regexp
4117 (concat
4118 "\\([^\\]\\)\\([_^]\\)\\("
4119 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4120 "\\)")
4121 "The regular expression matching a sub- or superscript, forcing braces.")
4122
4123 (defconst org-export-html-special-string-regexps
4124 '(("\\\\-" . "&shy;")
4125 ("---\\([^-]\\)" . "&mdash;\\1")
4126 ("--\\([^-]\\)" . "&ndash;\\1")
4127 ("\\.\\.\\." . "&hellip;"))
4128 "Regular expressions for special string conversion.")
4129
4130 (defun org-export-html-convert-special-strings (string)
4131 "Convert special characters in STRING to HTML."
4132 (let ((all org-export-html-special-string-regexps)
4133 e a re rpl start)
4134 (while (setq a (pop all))
4135 (setq re (car a) rpl (cdr a) start 0)
4136 (while (string-match re string start)
4137 (if (get-text-property (match-beginning 0) 'org-protected string)
4138 (setq start (match-end 0))
4139 (setq string (replace-match rpl t nil string)))))
4140 string))
4141
4142 (defun org-export-html-convert-sub-super (string)
4143 "Convert sub- and superscripts in STRING to HTML."
4144 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4145 (while (string-match org-match-substring-regexp string s)
4146 (cond
4147 ((and requireb (match-end 8)) (setq s (match-end 2)))
4148 ((get-text-property (match-beginning 2) 'org-protected string)
4149 (setq s (match-end 2)))
4150 (t
4151 (setq s (match-end 1)
4152 key (if (string= (match-string 2 string) "_") "sub" "sup")
4153 c (or (match-string 8 string)
4154 (match-string 6 string)
4155 (match-string 5 string))
4156 string (replace-match
4157 (concat (match-string 1 string)
4158 "<" key ">" c "</" key ">")
4159 t t string)))))
4160 (while (string-match "\\\\\\([_^]\\)" string)
4161 (setq string (replace-match (match-string 1 string) t t string)))
4162 string))
4163
4164 (defun org-export-html-convert-emphasize (string)
4165 "Apply emphasis."
4166 (let ((s 0) rpl)
4167 (while (string-match org-emph-re string s)
4168 (if (not (equal
4169 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4170 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4171 (setq s (match-beginning 0)
4172 rpl
4173 (concat
4174 (match-string 1 string)
4175 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4176 (match-string 4 string)
4177 (nth 3 (assoc (match-string 3 string)
4178 org-emphasis-alist))
4179 (match-string 5 string))
4180 string (replace-match rpl t t string)
4181 s (+ s (- (length rpl) 2)))
4182 (setq s (1+ s))))
4183 string))
4184
4185 (defun org-open-par ()
4186 "Insert <p>, but first close previous paragraph if any."
4187 (org-close-par-maybe)
4188 (insert "\n<p>")
4189 (setq org-par-open t))
4190 (defun org-close-par-maybe ()
4191 "Close paragraph if there is one open."
4192 (when org-par-open
4193 (insert "</p>")
4194 (setq org-par-open nil)))
4195 (defun org-close-li (&optional type)
4196 "Close <li> if necessary."
4197 (org-close-par-maybe)
4198 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4199
4200 (defvar body-only) ; dynamically scoped into this.
4201 (defun org-html-level-start (level title umax with-toc head-count)
4202 "Insert a new level in HTML export.
4203 When TITLE is nil, just close all open levels."
4204 (org-close-par-maybe)
4205 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4206 (extra-targets
4207 (mapconcat (lambda (x)
4208 (format "<a name=\"%s\" id=\"%s\"></a>"
4209 x x))
4210 (cdr (assoc target org-export-target-aliases))
4211 ""))
4212 (l org-level-max)
4213 snumber)
4214 (while (>= l level)
4215 (if (aref org-levels-open (1- l))
4216 (progn
4217 (org-html-level-close l umax)
4218 (aset org-levels-open (1- l) nil)))
4219 (setq l (1- l)))
4220 (when title
4221 ;; If title is nil, this means this function is called to close
4222 ;; all levels, so the rest is done only if title is given
4223 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4224 (setq title (replace-match
4225 (if org-export-with-tags
4226 (save-match-data
4227 (concat
4228 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4229 (mapconcat 'identity (org-split-string
4230 (match-string 1 title) ":")
4231 "&nbsp;")
4232 "</span>"))
4233 "")
4234 t t title)))
4235 (if (> level umax)
4236 (progn
4237 (if (aref org-levels-open (1- level))
4238 (progn
4239 (org-close-li)
4240 (if target
4241 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4242 (insert "<li>" title "<br/>\n")))
4243 (aset org-levels-open (1- level) t)
4244 (org-close-par-maybe)
4245 (if target
4246 (insert (format "<ul>\n<li id=\"%s\">" target)
4247 extra-targets title "<br/>\n")
4248 (insert "<ul>\n<li>" title "<br/>\n"))))
4249 (aset org-levels-open (1- level) t)
4250 (setq snumber (org-section-number level))
4251 (if (and org-export-with-section-numbers (not body-only))
4252 (setq title (concat snumber " " title)))
4253 (setq level (+ level org-export-html-toplevel-hlevel -1))
4254 (unless (= head-count 1) (insert "\n</div>\n"))
4255 (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"
4256 snumber level level snumber extra-targets title level snumber))
4257 (org-open-par)))))
4258
4259 (defun org-get-text-property-any (pos prop &optional object)
4260 (or (get-text-property pos prop object)
4261 (and (setq pos (next-single-property-change pos prop object))
4262 (get-text-property pos prop object))))
4263
4264 (defun org-html-level-close (level max-outline-level)
4265 "Terminate one level in HTML export."
4266 (if (<= level max-outline-level)
4267 (insert "</div>\n")
4268 (org-close-li)
4269 (insert "</ul>\n")))
4270
4271 ;;; iCalendar export
4272
4273 ;;;###autoload
4274 (defun org-export-icalendar-this-file ()
4275 "Export current file as an iCalendar file.
4276 The iCalendar file will be located in the same directory as the Org-mode
4277 file, but with extension `.ics'."
4278 (interactive)
4279 (org-export-icalendar nil buffer-file-name))
4280
4281 ;;;###autoload
4282 (defun org-export-icalendar-all-agenda-files ()
4283 "Export all files in `org-agenda-files' to iCalendar .ics files.
4284 Each iCalendar file will be located in the same directory as the Org-mode
4285 file, but with extension `.ics'."
4286 (interactive)
4287 (apply 'org-export-icalendar nil (org-agenda-files t)))
4288
4289 ;;;###autoload
4290 (defun org-export-icalendar-combine-agenda-files ()
4291 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4292 The file is stored under the name `org-combined-agenda-icalendar-file'."
4293 (interactive)
4294 (apply 'org-export-icalendar t (org-agenda-files t)))
4295
4296 (defun org-export-icalendar (combine &rest files)
4297 "Create iCalendar files for all elements of FILES.
4298 If COMBINE is non-nil, combine all calendar entries into a single large
4299 file and store it under the name `org-combined-agenda-icalendar-file'."
4300 (save-excursion
4301 (org-prepare-agenda-buffers files)
4302 (let* ((dir (org-export-directory
4303 :ical (list :publishing-directory
4304 org-export-publishing-directory)))
4305 file ical-file ical-buffer category started org-agenda-new-buffers)
4306 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4307 (when combine
4308 (setq ical-file
4309 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4310 org-combined-agenda-icalendar-file
4311 (expand-file-name org-combined-agenda-icalendar-file dir))
4312 ical-buffer (org-get-agenda-file-buffer ical-file))
4313 (set-buffer ical-buffer) (erase-buffer))
4314 (while (setq file (pop files))
4315 (catch 'nextfile
4316 (org-check-agenda-file file)
4317 (set-buffer (org-get-agenda-file-buffer file))
4318 (unless combine
4319 (setq ical-file (concat (file-name-as-directory dir)
4320 (file-name-sans-extension
4321 (file-name-nondirectory buffer-file-name))
4322 ".ics"))
4323 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4324 (with-current-buffer ical-buffer (erase-buffer)))
4325 (setq category (or org-category
4326 (file-name-sans-extension
4327 (file-name-nondirectory buffer-file-name))))
4328 (if (symbolp category) (setq category (symbol-name category)))
4329 (let ((standard-output ical-buffer))
4330 (if combine
4331 (and (not started) (setq started t)
4332 (org-start-icalendar-file org-icalendar-combined-name))
4333 (org-start-icalendar-file category))
4334 (org-print-icalendar-entries combine)
4335 (when (or (and combine (not files)) (not combine))
4336 (org-finish-icalendar-file)
4337 (set-buffer ical-buffer)
4338 (run-hooks 'org-before-save-iCalendar-file-hook)
4339 (save-buffer)
4340 (run-hooks 'org-after-save-iCalendar-file-hook)
4341 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4342 ))))
4343 (org-release-buffers org-agenda-new-buffers))))
4344
4345 (defvar org-before-save-iCalendar-file-hook nil
4346 "Hook run before an iCalendar file has been saved.
4347 This can be used to modify the result of the export.")
4348
4349 (defvar org-after-save-iCalendar-file-hook nil
4350 "Hook run after an iCalendar file has been saved.
4351 The iCalendar buffer is still current when this hook is run.
4352 A good way to use this is to tell a desktop calenndar application to re-read
4353 the iCalendar file.")
4354
4355 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4356 (defun org-print-icalendar-entries (&optional combine)
4357 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4358 When COMBINE is non nil, add the category to each line."
4359 (require 'org-agenda)
4360 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4361 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4362 (dts (org-ical-ts-to-string
4363 (format-time-string (cdr org-time-stamp-formats) (current-time))
4364 "DTSTART"))
4365 hd ts ts2 state status (inc t) pos b sexp rrule
4366 scheduledp deadlinep todo prefix due start
4367 tmp pri categories entry location summary desc uid
4368 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4369 (org-refresh-category-properties)
4370 (save-excursion
4371 (goto-char (point-min))
4372 (while (re-search-forward re1 nil t)
4373 (catch :skip
4374 (org-agenda-skip)
4375 (when (boundp 'org-icalendar-verify-function)
4376 (unless (funcall org-icalendar-verify-function)
4377 (outline-next-heading)
4378 (backward-char 1)
4379 (throw :skip nil)))
4380 (setq pos (match-beginning 0)
4381 ts (match-string 0)
4382 inc t
4383 hd (condition-case nil
4384 (org-icalendar-cleanup-string
4385 (org-get-heading))
4386 (error (throw :skip nil)))
4387 summary (org-icalendar-cleanup-string
4388 (org-entry-get nil "SUMMARY"))
4389 desc (org-icalendar-cleanup-string
4390 (or (org-entry-get nil "DESCRIPTION")
4391 (and org-icalendar-include-body (org-get-entry)))
4392 t org-icalendar-include-body)
4393 location (org-icalendar-cleanup-string
4394 (org-entry-get nil "LOCATION" 'selective))
4395 uid (if org-icalendar-store-UID
4396 (org-id-get-create)
4397 (or (org-id-get) (org-id-new)))
4398 categories (org-export-get-categories)
4399 deadlinep nil scheduledp nil)
4400 (if (looking-at re2)
4401 (progn
4402 (goto-char (match-end 0))
4403 (setq ts2 (match-string 1)
4404 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4405 (setq tmp (buffer-substring (max (point-min)
4406 (- pos org-ds-keyword-length))
4407 pos)
4408 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4409 (progn
4410 (setq inc nil)
4411 (replace-match "\\1" t nil ts))
4412 ts)
4413 deadlinep (string-match org-deadline-regexp tmp)
4414 scheduledp (string-match org-scheduled-regexp tmp)
4415 todo (org-get-todo-state)
4416 ;; donep (org-entry-is-done-p)
4417 ))
4418 (when (and
4419 deadlinep
4420 (if todo
4421 (not (memq 'event-if-todo org-icalendar-use-deadline))
4422 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4423 (throw :skip t))
4424 (when (and
4425 scheduledp
4426 (if todo
4427 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4428 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4429 (throw :skip t))
4430 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4431 (if (or (string-match org-tr-regexp hd)
4432 (string-match org-ts-regexp hd))
4433 (setq hd (replace-match "" t t hd)))
4434 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4435 (setq rrule
4436 (concat "\nRRULE:FREQ="
4437 (cdr (assoc
4438 (match-string 2 ts)
4439 '(("d" . "DAILY")("w" . "WEEKLY")
4440 ("m" . "MONTHLY")("y" . "YEARLY"))))
4441 ";INTERVAL=" (match-string 1 ts)))
4442 (setq rrule ""))
4443 (setq summary (or summary hd))
4444 (if (string-match org-bracket-link-regexp summary)
4445 (setq summary
4446 (replace-match (if (match-end 3)
4447 (match-string 3 summary)
4448 (match-string 1 summary))
4449 t t summary)))
4450 (if deadlinep (setq summary (concat "DL: " summary)))
4451 (if scheduledp (setq summary (concat "S: " summary)))
4452 (if (string-match "\\`<%%" ts)
4453 (with-current-buffer sexp-buffer
4454 (insert (substring ts 1 -1) " " summary "\n"))
4455 (princ (format "BEGIN:VEVENT
4456 UID: %s
4457 %s
4458 %s%s
4459 SUMMARY:%s%s%s
4460 CATEGORIES:%s
4461 END:VEVENT\n"
4462 (concat prefix uid)
4463 (org-ical-ts-to-string ts "DTSTART")
4464 (org-ical-ts-to-string ts2 "DTEND" inc)
4465 rrule summary
4466 (if (and desc (string-match "\\S-" desc))
4467 (concat "\nDESCRIPTION: " desc) "")
4468 (if (and location (string-match "\\S-" location))
4469 (concat "\nLOCATION: " location) "")
4470 categories)))))
4471 (when (and org-icalendar-include-sexps
4472 (condition-case nil (require 'icalendar) (error nil))
4473 (fboundp 'icalendar-export-region))
4474 ;; Get all the literal sexps
4475 (goto-char (point-min))
4476 (while (re-search-forward "^&?%%(" nil t)
4477 (catch :skip
4478 (org-agenda-skip)
4479 (setq b (match-beginning 0))
4480 (goto-char (1- (match-end 0)))
4481 (forward-sexp 1)
4482 (end-of-line 1)
4483 (setq sexp (buffer-substring b (point)))
4484 (with-current-buffer sexp-buffer
4485 (insert sexp "\n"))))
4486 (princ (org-diary-to-ical-string sexp-buffer))
4487 (kill-buffer sexp-buffer))
4488
4489 (when org-icalendar-include-todo
4490 (setq prefix "TODO-")
4491 (goto-char (point-min))
4492 (while (re-search-forward org-todo-line-regexp nil t)
4493 (catch :skip
4494 (org-agenda-skip)
4495 (when (boundp 'org-icalendar-verify-function)
4496 (unless (funcall org-icalendar-verify-function)
4497 (outline-next-heading)
4498 (backward-char 1)
4499 (throw :skip nil)))
4500 (setq state (match-string 2))
4501 (setq status (if (member state org-done-keywords)
4502 "COMPLETED" "NEEDS-ACTION"))
4503 (when (and state
4504 (or (not (member state org-done-keywords))
4505 (eq org-icalendar-include-todo 'all))
4506 (not (member org-archive-tag (org-get-tags-at)))
4507 )
4508 (setq hd (match-string 3)
4509 summary (org-icalendar-cleanup-string
4510 (org-entry-get nil "SUMMARY"))
4511 desc (org-icalendar-cleanup-string
4512 (or (org-entry-get nil "DESCRIPTION")
4513 (and org-icalendar-include-body (org-get-entry)))
4514 t org-icalendar-include-body)
4515 location (org-icalendar-cleanup-string
4516 (org-entry-get nil "LOCATION" 'selective))
4517 due (and (member 'todo-due org-icalendar-use-deadline)
4518 (org-entry-get nil "DEADLINE"))
4519 start (and (member 'todo-start org-icalendar-use-scheduled)
4520 (org-entry-get nil "SCHEDULED"))
4521 categories (org-export-get-categories)
4522 uid (if org-icalendar-store-UID
4523 (org-id-get-create)
4524 (or (org-id-get) (org-id-new))))
4525 (and due (setq due (org-ical-ts-to-string due "DUE")))
4526 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
4527
4528 (if (string-match org-bracket-link-regexp hd)
4529 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
4530 (match-string 1 hd))
4531 t t hd)))
4532 (if (string-match org-priority-regexp hd)
4533 (setq pri (string-to-char (match-string 2 hd))
4534 hd (concat (substring hd 0 (match-beginning 1))
4535 (substring hd (match-end 1))))
4536 (setq pri org-default-priority))
4537 (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
4538 (- org-lowest-priority org-highest-priority))))))
4539
4540 (princ (format "BEGIN:VTODO
4541 UID: %s
4542 %s
4543 SUMMARY:%s%s%s%s
4544 CATEGORIES:%s
4545 SEQUENCE:1
4546 PRIORITY:%d
4547 STATUS:%s
4548 END:VTODO\n"
4549 (concat prefix uid)
4550 (or start dts)
4551 (or summary hd)
4552 (if (and location (string-match "\\S-" location))
4553 (concat "\nLOCATION: " location) "")
4554 (if (and desc (string-match "\\S-" desc))
4555 (concat "\nDESCRIPTION: " desc) "")
4556 (if due (concat "\n" due) "")
4557 categories
4558 pri status)))))))))
4559
4560 (defun org-export-get-categories ()
4561 "Get categories according to `org-icalendar-categories'."
4562 (let ((cs org-icalendar-categories) c rtn tmp)
4563 (while (setq c (pop cs))
4564 (cond
4565 ((eq c 'category) (push (org-get-category) rtn))
4566 ((eq c 'todo-state)
4567 (setq tmp (org-get-todo-state))
4568 (and tmp (push tmp rtn)))
4569 ((eq c 'local-tags)
4570 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
4571 ((eq c 'all-tags)
4572 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
4573 (mapconcat 'identity (nreverse rtn) ",")))
4574
4575 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
4576 "Take out stuff and quote what needs to be quoted.
4577 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4578 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4579 characters."
4580 (if (not s)
4581 nil
4582 (when is-body
4583 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4584 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4585 (while (string-match re s) (setq s (replace-match "" t t s)))
4586 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
4587 (let ((start 0))
4588 (while (string-match "\\([,;]\\)" s start)
4589 (setq start (+ (match-beginning 0) 2)
4590 s (replace-match "\\\\\\1" nil nil s))))
4591 (setq s (org-trim s))
4592 (when is-body
4593 (while (string-match "[ \t]*\n[ \t]*" s)
4594 (setq s (replace-match "\\n" t t s))))
4595 (if is-body
4596 (if maxlength
4597 (if (and (numberp maxlength)
4598 (> (length s) maxlength))
4599 (setq s (substring s 0 maxlength)))))
4600 s))
4601
4602 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
4603 "Take out stuff and quote what needs to be quoted.
4604 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4605 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4606 characters.
4607 This seems to be more like RFC 2455, but it causes problems, so it is
4608 not used right now."
4609 (if (not s)
4610 nil
4611 (if is-body
4612 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
4613 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
4614 (while (string-match re s) (setq s (replace-match "" t t s)))
4615 (while (string-match re2 s) (setq s (replace-match "" t t s)))
4616 (setq s (org-trim s))
4617 (while (string-match "[ \t]*\n[ \t]*" s)
4618 (setq s (replace-match "\\n" t t s)))
4619 (if maxlength
4620 (if (and (numberp maxlength)
4621 (> (length s) maxlength))
4622 (setq s (substring s 0 maxlength)))))
4623 (setq s (org-trim s)))
4624 (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
4625 (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
4626 s))
4627
4628 (defun org-get-entry ()
4629 "Clean-up description string."
4630 (save-excursion
4631 (org-back-to-heading t)
4632 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
4633
4634 (defun org-start-icalendar-file (name)
4635 "Start an iCalendar file by inserting the header."
4636 (let ((user user-full-name)
4637 (name (or name "unknown"))
4638 (timezone (cadr (current-time-zone))))
4639 (princ
4640 (format "BEGIN:VCALENDAR
4641 VERSION:2.0
4642 X-WR-CALNAME:%s
4643 PRODID:-//%s//Emacs with Org-mode//EN
4644 X-WR-TIMEZONE:%s
4645 CALSCALE:GREGORIAN\n" name user timezone))))
4646
4647 (defun org-finish-icalendar-file ()
4648 "Finish an iCalendar file by inserting the END statement."
4649 (princ "END:VCALENDAR\n"))
4650
4651 (defun org-ical-ts-to-string (s keyword &optional inc)
4652 "Take a time string S and convert it to iCalendar format.
4653 KEYWORD is added in front, to make a complete line like DTSTART....
4654 When INC is non-nil, increase the hour by two (if time string contains
4655 a time), or the day by one (if it does not contain a time)."
4656 (let ((t1 (org-parse-time-string s 'nodefault))
4657 t2 fmt have-time time)
4658 (if (and (car t1) (nth 1 t1) (nth 2 t1))
4659 (setq t2 t1 have-time t)
4660 (setq t2 (org-parse-time-string s)))
4661 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
4662 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
4663 (when inc
4664 (if have-time
4665 (if org-agenda-default-appointment-duration
4666 (setq mi (+ org-agenda-default-appointment-duration mi))
4667 (setq h (+ 2 h)))
4668 (setq d (1+ d))))
4669 (setq time (encode-time s mi h d m y)))
4670 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4671 (concat keyword (format-time-string fmt time))))
4672
4673 ;;; XOXO export
4674
4675 (defun org-export-as-xoxo-insert-into (buffer &rest output)
4676 (with-current-buffer buffer
4677 (apply 'insert output)))
4678 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
4679
4680 ;;;###autoload
4681 (defun org-export-as-xoxo (&optional buffer)
4682 "Export the org buffer as XOXO.
4683 The XOXO buffer is named *xoxo-<source buffer name>*"
4684 (interactive (list (current-buffer)))
4685 ;; A quickie abstraction
4686
4687 ;; Output everything as XOXO
4688 (with-current-buffer (get-buffer buffer)
4689 (let* ((pos (point))
4690 (opt-plist (org-combine-plists (org-default-export-plist)
4691 (org-infile-export-plist)))
4692 (filename (concat (file-name-as-directory
4693 (org-export-directory :xoxo opt-plist))
4694 (file-name-sans-extension
4695 (file-name-nondirectory buffer-file-name))
4696 ".html"))
4697 (out (find-file-noselect filename))
4698 (last-level 1)
4699 (hanging-li nil))
4700 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4701 ;; Check the output buffer is empty.
4702 (with-current-buffer out (erase-buffer))
4703 ;; Kick off the output
4704 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
4705 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
4706 (let* ((hd (match-string-no-properties 1))
4707 (level (length hd))
4708 (text (concat
4709 (match-string-no-properties 2)
4710 (save-excursion
4711 (goto-char (match-end 0))
4712 (let ((str ""))
4713 (catch 'loop
4714 (while 't
4715 (forward-line)
4716 (if (looking-at "^[ \t]\\(.*\\)")
4717 (setq str (concat str (match-string-no-properties 1)))
4718 (throw 'loop str)))))))))
4719
4720 ;; Handle level rendering
4721 (cond
4722 ((> level last-level)
4723 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
4724
4725 ((< level last-level)
4726 (dotimes (- (- last-level level) 1)
4727 (if hanging-li
4728 (org-export-as-xoxo-insert-into out "</li>\n"))
4729 (org-export-as-xoxo-insert-into out "</ol>\n"))
4730 (when hanging-li
4731 (org-export-as-xoxo-insert-into out "</li>\n")
4732 (setq hanging-li nil)))
4733
4734 ((equal level last-level)
4735 (if hanging-li
4736 (org-export-as-xoxo-insert-into out "</li>\n")))
4737 )
4738
4739 (setq last-level level)
4740
4741 ;; And output the new li
4742 (setq hanging-li 't)
4743 (if (equal ?+ (elt text 0))
4744 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
4745 (org-export-as-xoxo-insert-into out "<li>" text))))
4746
4747 ;; Finally finish off the ol
4748 (dotimes (- last-level 1)
4749 (if hanging-li
4750 (org-export-as-xoxo-insert-into out "</li>\n"))
4751 (org-export-as-xoxo-insert-into out "</ol>\n"))
4752
4753 (goto-char pos)
4754 ;; Finish the buffer off and clean it up.
4755 (switch-to-buffer-other-window out)
4756 (indent-region (point-min) (point-max) nil)
4757 (save-buffer)
4758 (goto-char (point-min))
4759 )))
4760
4761 (provide 'org-exp)
4762
4763 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4764
4765 ;;; org-exp.el ends here