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