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