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