New link types that force special ways of opening the file
[rgr-org-mode.git] / lisp / org-exp.el
blob20c6ce8fe975d0787b01ba97fbef30decf71392d
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.33trans
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-macs)
31 (require 'org-agenda)
32 (require 'org-exp-blocks)
33 (require 'org-src)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function org-export-latex-preprocess "org-latex" (parameters))
38 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
39 (declare-function org-export-html-preprocess "org-html" (parameters))
40 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
41 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
42 (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
43 (declare-function htmlize-buffer "ext:htmlize" (&optional buffer))
44 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
45 (autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
46 (defgroup org-export nil
47 "Options for exporting org-listings."
48 :tag "Org Export"
49 :group 'org)
51 (defgroup org-export-general nil
52 "General options for exporting Org-mode files."
53 :tag "Org Export General"
54 :group 'org-export)
56 (defcustom org-export-allow-BIND 'confirm
57 "Non-nil means, allow #+BIND to define local variable values for export.
58 This is a potential security risk, which is why the user must confirm the
59 use of these lines."
60 :group 'org-export-general
61 :type '(choice
62 (const :tag "Never" nil)
63 (const :tag "Always" t)
64 (const :tag "Make the user confirm for each file" confirm)))
66 ;; FIXME
67 (defvar org-export-publishing-directory nil)
69 (defcustom org-export-show-temporary-export-buffer t
70 "Non-nil means, show buffer after exporting to temp buffer.
71 When Org exports to a file, the buffer visiting that file is ever
72 shown, but remains buried. However, when exporting to a temporary
73 buffer, that buffer is popped up in a second window. When this variable
74 is nil, the buffer remains buried also in these cases."
75 :group 'org-export-general
76 :type 'boolean)
78 (defcustom org-export-copy-to-kill-ring t
79 "Non-nil means, exported stuff will also be pushed onto the kill ring."
80 :group 'org-export-general
81 :type 'boolean)
83 (defcustom org-export-run-in-background nil
84 "Non-nil means export and publishing commands will run in background.
85 This works by starting up a separate Emacs process visiting the same file
86 and doing the export from there.
87 Not all export commands are affected by this - only the ones which
88 actually write to a file, and that do not depend on the buffer state.
90 If this option is nil, you can still get background export by calling
91 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
93 If this option is t, the double prefix can be used to exceptionally
94 force an export command into the current process."
95 :group 'org-export-general
96 :type 'boolean)
98 (defcustom org-export-select-tags '("export")
99 "Tags that select a tree for export.
100 If any such tag is found in a buffer, all trees that do not carry one
101 of these tags will be deleted before export.
102 Inside trees that are selected like this, you can still deselect a
103 subtree by tagging it with one of the `org-export-exclude-tags'."
104 :group 'org-export-general
105 :type '(repeat (string :tag "Tag")))
107 (defcustom org-export-exclude-tags '("noexport")
108 "Tags that exclude a tree from export.
109 All trees carrying any of these tags will be excluded from export.
110 This is without condition, so even subtrees inside that carry one of the
111 `org-export-select-tags' will be removed."
112 :group 'org-export-general
113 :type '(repeat (string :tag "Tag")))
115 ;; FIXME: rename, this is a general variable
116 (defcustom org-export-html-expand t
117 "Non-nil means, for HTML export, treat @<...> as HTML tag.
118 When nil, these tags will be exported as plain text and therefore
119 not be interpreted by a browser.
121 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
122 :group 'org-export-html
123 :group 'org-export-general
124 :type 'boolean)
126 (defcustom org-export-with-special-strings t
127 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
128 When this option is turned on, these strings will be exported as:
130 Org HTML LaTeX
131 -----+----------+--------
132 \\- &shy; \\-
133 -- &ndash; --
134 --- &mdash; ---
135 ... &hellip; \ldots
137 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
138 :group 'org-export-translation
139 :type 'boolean)
141 (defcustom org-export-html-link-up ""
142 "Where should the \"UP\" link of exported HTML pages lead?"
143 :group 'org-export-html
144 :group 'org-export-general
145 :type '(string :tag "File or URL"))
147 (defcustom org-export-html-link-home ""
148 "Where should the \"HOME\" link of exported HTML pages lead?"
149 :group 'org-export-html
150 :group 'org-export-general
151 :type '(string :tag "File or URL"))
153 (defcustom org-export-language-setup
154 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
155 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
156 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
157 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
158 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
159 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
160 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
161 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
162 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
163 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
164 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
165 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
166 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
167 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
168 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
169 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
170 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
171 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
172 "Terms used in export text, translated to different languages.
173 Use the variable `org-export-default-language' to set the language,
174 or use the +OPTION lines for a per-file setting."
175 :group 'org-export-general
176 :type '(repeat
177 (list
178 (string :tag "HTML language tag")
179 (string :tag "Author")
180 (string :tag "Date")
181 (string :tag "Table of Contents")
182 (string :tag "Footnotes"))))
184 (defcustom org-export-default-language "en"
185 "The default language of HTML export, as a string.
186 This should have an association in `org-export-language-setup'."
187 :group 'org-export-general
188 :type 'string)
190 (defvar org-export-page-description ""
191 "The page description, for the XHTML meta tag.
192 This is best set with the #+DESCRIPTION line in a file, it does not make
193 sense to set this globally.")
195 (defvar org-export-page-keywords ""
196 "The page description, for the XHTML meta tag.
197 This is best set with the #+KEYWORDS line in a file, it does not make
198 sense to set this globally.")
200 (defcustom org-export-skip-text-before-1st-heading nil
201 "Non-nil means, skip all text before the first headline when exporting.
202 When nil, that text is exported as well."
203 :group 'org-export-general
204 :type 'boolean)
206 (defcustom org-export-headline-levels 3
207 "The last level which is still exported as a headline.
208 Inferior levels will produce itemize lists when exported.
209 Note that a numeric prefix argument to an exporter function overrides
210 this setting.
212 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
213 :group 'org-export-general
214 :type 'integer)
216 (defcustom org-export-with-section-numbers t
217 "Non-nil means, add section numbers to headlines when exporting.
219 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
220 :group 'org-export-general
221 :type 'boolean)
223 (defcustom org-export-section-number-format '((("1" ".")) . "")
224 "Format of section numbers for export.
225 The variable has two components.
226 1. A list of lists, each indicating a counter type and a separator.
227 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
228 It causes causes numeric, alphabetic, or roman counters, respectively.
229 The separator is only used if another counter for a subsection is being
230 added.
231 If there are more numbered section levels than entries in this lists,
232 then the last entry will be reused.
233 2. A terminator string that will be added after the entire
234 section number."
235 :group 'org-export-general
236 :type '(cons
237 (repeat
238 (list
239 (string :tag "Counter Type")
240 (string :tag "Separator ")))
241 (string :tag "Terminator")))
243 (defcustom org-export-with-toc t
244 "Non-nil means, create a table of contents in exported files.
245 The TOC contains headlines with levels up to`org-export-headline-levels'.
246 When an integer, include levels up to N in the toc, this may then be
247 different from `org-export-headline-levels', but it will not be allowed
248 to be larger than the number of headline levels.
249 When nil, no table of contents is made.
251 Headlines which contain any TODO items will be marked with \"(*)\" in
252 ASCII export, and with red color in HTML output, if the option
253 `org-export-mark-todo-in-toc' is set.
255 In HTML output, the TOC will be clickable.
257 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
258 or \"toc:3\"."
259 :group 'org-export-general
260 :type '(choice
261 (const :tag "No Table of Contents" nil)
262 (const :tag "Full Table of Contents" t)
263 (integer :tag "TOC to level")))
265 (defcustom org-export-mark-todo-in-toc nil
266 "Non-nil means, mark TOC lines that contain any open TODO items."
267 :group 'org-export-general
268 :type 'boolean)
270 (defcustom org-export-with-todo-keywords t
271 "Non-nil means, include TODO keywords in export.
272 When nil, remove all these keywords from the export."
273 :group 'org-export-general
274 :type 'boolean)
276 (defcustom org-export-with-priority nil
277 "Non-nil means, include priority cookies in export.
278 When nil, remove priority cookies for export."
279 :group 'org-export-general
280 :type 'boolean)
282 (defcustom org-export-preserve-breaks nil
283 "Non-nil means, preserve all line breaks when exporting.
284 Normally, in HTML output paragraphs will be reformatted. In ASCII
285 export, line breaks will always be preserved, regardless of this variable.
287 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
288 :group 'org-export-general
289 :type 'boolean)
291 (defcustom org-export-with-archived-trees 'headline
292 "Whether subtrees with the ARCHIVE tag should be exported.
293 This can have three different values
294 nil Do not export, pretend this tree is not present
295 t Do export the entire tree
296 headline Only export the headline, but skip the tree below it."
297 :group 'org-export-general
298 :group 'org-archive
299 :type '(choice
300 (const :tag "not at all" nil)
301 (const :tag "headline only" 'headline)
302 (const :tag "entirely" t)))
304 (defcustom org-export-author-info t
305 "Non-nil means, insert author name and email into the exported file.
307 This option can also be set with the +OPTIONS line,
308 e.g. \"author-info:nil\"."
309 :group 'org-export-general
310 :type 'boolean)
312 (defcustom org-export-creator-info t
313 "Non-nil means, the postamble should contain a creator sentence.
314 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
315 :group 'org-export-general
316 :type 'boolean)
318 (defcustom org-export-time-stamp-file t
319 "Non-nil means, insert a time stamp into the exported file.
320 The time stamp shows when the file was created.
322 This option can also be set with the +OPTIONS line,
323 e.g. \"timestamp:nil\"."
324 :group 'org-export-general
325 :type 'boolean)
327 (defcustom org-export-with-timestamps t
328 "If nil, do not export time stamps and associated keywords."
329 :group 'org-export-general
330 :type 'boolean)
332 (defcustom org-export-remove-timestamps-from-toc t
333 "If t, remove timestamps from the table of contents entries."
334 :group 'org-export-general
335 :type 'boolean)
337 (defcustom org-export-with-tags 'not-in-toc
338 "If nil, do not export tags, just remove them from headlines.
339 If this is the symbol `not-in-toc', tags will be removed from table of
340 contents entries, but still be shown in the headlines of the document.
342 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
343 :group 'org-export-general
344 :type '(choice
345 (const :tag "Off" nil)
346 (const :tag "Not in TOC" not-in-toc)
347 (const :tag "On" t)))
349 (defcustom org-export-with-drawers nil
350 "Non-nil means, export with drawers like the property drawer.
351 When t, all drawers are exported. This may also be a list of
352 drawer names to export."
353 :group 'org-export-general
354 :type '(choice
355 (const :tag "All drawers" t)
356 (const :tag "None" nil)
357 (repeat :tag "Selected drawers"
358 (string :tag "Drawer name"))))
360 (defvar org-export-first-hook nil
361 "Hook called as the first thing in each exporter.
362 Good for general initialization")
364 (defvar org-export-preprocess-hook nil
365 "Hook for preprocessing an export buffer.
366 Pretty much the first thing when exporting is running this hook.")
368 (defvar org-export-preprocess-after-include-files-hook nil
369 "Hook for preprocessing an export buffer.
370 This is run after the contents of included files have been inserted.")
372 (defvar org-export-preprocess-after-tree-selection-hook nil
373 "Hook for preprocessing an export buffer.
374 This is run after selection of trees to be exported has happened.
375 This selection includes tags-based selection, as well as removal
376 of commented and archived trees.")
378 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
379 "Hook for preprocessing an export buffer.
380 This is run just before backend-specific blocks get selected.")
382 (defvar org-export-preprocess-after-blockquote-hook nil
383 "Hook for preprocessing an export buffer.
384 This is run after blockquote/quote/verse/center have been marked
385 with cookies.")
387 (defvar org-export-preprocess-before-normalizing-links-hook nil
388 "Hook for preprocessing an export buffer.
389 This hook is run before links are normalized.")
391 (defvar org-export-preprocess-before-backend-specifics-hook nil
392 "Hook run before backend-specific functions are called during preprocessing.")
394 (defvar org-export-preprocess-final-hook nil
395 "Hook for preprocessing an export buffer.
396 This is run as the last thing in the preprocessing buffer, just before
397 returning the buffer string to the backend.")
399 (defgroup org-export-translation nil
400 "Options for translating special ascii sequences for the export backends."
401 :tag "Org Export Translation"
402 :group 'org-export)
404 (defcustom org-export-with-emphasize t
405 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
406 If the export target supports emphasizing text, the word will be
407 typeset in bold, italic, or underlined, respectively. Works only for
408 single words, but you can say: I *really* *mean* *this*.
409 Not all export backends support this.
411 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
412 :group 'org-export-translation
413 :type 'boolean)
415 (defcustom org-export-with-footnotes t
416 "If nil, export [1] as a footnote marker.
417 Lines starting with [1] will be formatted as footnotes.
419 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
420 :group 'org-export-translation
421 :type 'boolean)
423 (defcustom org-export-with-sub-superscripts t
424 "Non-nil means, interpret \"_\" and \"^\" for export.
425 When this option is turned on, you can use TeX-like syntax for sub- and
426 superscripts. Several characters after \"_\" or \"^\" will be
427 considered as a single item - so grouping with {} is normally not
428 needed. For example, the following things will be parsed as single
429 sub- or superscripts.
431 10^24 or 10^tau several digits will be considered 1 item.
432 10^-12 or 10^-tau a leading sign with digits or a word
433 x^2-y^3 will be read as x^2 - y^3, because items are
434 terminated by almost any nonword/nondigit char.
435 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
437 Still, ambiguity is possible - so when in doubt use {} to enclose the
438 sub/superscript. If you set this variable to the symbol `{}',
439 the braces are *required* in order to trigger interpretations as
440 sub/superscript. This can be helpful in documents that need \"_\"
441 frequently in plain text.
443 Not all export backends support this, but HTML does.
445 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
446 :group 'org-export-translation
447 :type '(choice
448 (const :tag "Always interpret" t)
449 (const :tag "Only with braces" {})
450 (const :tag "Never interpret" nil)))
452 (defcustom org-export-with-TeX-macros t
453 "Non-nil means, interpret simple TeX-like macros when exporting.
454 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
455 Not only real TeX macros will work here, but the standard HTML entities
456 for math can be used as macro names as well. For a list of supported
457 names in HTML export, see the constant `org-html-entities'.
458 Not all export backends support this.
460 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
461 :group 'org-export-translation
462 :group 'org-export-latex
463 :type 'boolean)
465 (defcustom org-export-with-LaTeX-fragments nil
466 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
467 When set, the exporter will find LaTeX environments if the \\begin line is
468 the first non-white thing on a line. It will also find the math delimiters
469 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
470 display math.
472 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
474 The default is nil, because this option needs the `dvipng' program which
475 is not available on all systems."
476 :group 'org-export-translation
477 :group 'org-export-latex
478 :type 'boolean)
480 (defcustom org-export-with-fixed-width t
481 "Non-nil means, lines starting with \":\" will be in fixed width font.
482 This can be used to have pre-formatted text, fragments of code etc. For
483 example:
484 : ;; Some Lisp examples
485 : (while (defc cnt)
486 : (ding))
487 will be looking just like this in also HTML. See also the QUOTE keyword.
488 Not all export backends support this.
490 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
491 :group 'org-export-translation
492 :type 'boolean)
494 (defcustom org-match-sexp-depth 3
495 "Number of stacked braces for sub/superscript matching.
496 This has to be set before loading org.el to be effective."
497 :group 'org-export-translation
498 :type 'integer)
500 (defgroup org-export-tables nil
501 "Options for exporting tables in Org-mode."
502 :tag "Org Export Tables"
503 :group 'org-export)
505 (defcustom org-export-with-tables t
506 "If non-nil, lines starting with \"|\" define a table.
507 For example:
509 | Name | Address | Birthday |
510 |-------------+----------+-----------|
511 | Arthur Dent | England | 29.2.2100 |
513 Not all export backends support this.
515 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
516 :group 'org-export-tables
517 :type 'boolean)
519 (defcustom org-export-highlight-first-table-line t
520 "Non-nil means, highlight the first table line.
521 In HTML export, this means use <th> instead of <td>.
522 In tables created with table.el, this applies to the first table line.
523 In Org-mode tables, all lines before the first horizontal separator
524 line will be formatted with <th> tags."
525 :group 'org-export-tables
526 :type 'boolean)
528 (defcustom org-export-table-remove-special-lines t
529 "Remove special lines and marking characters in calculating tables.
530 This removes the special marking character column from tables that are set
531 up for spreadsheet calculations. It also removes the entire lines
532 marked with `!', `_', or `^'. The lines with `$' are kept, because
533 the values of constants may be useful to have."
534 :group 'org-export-tables
535 :type 'boolean)
537 (defcustom org-export-prefer-native-exporter-for-tables nil
538 "Non-nil means, always export tables created with table.el natively.
539 Natively means, use the HTML code generator in table.el.
540 When nil, Org-mode's own HTML generator is used when possible (i.e. if
541 the table does not use row- or column-spanning). This has the
542 advantage, that the automatic HTML conversions for math symbols and
543 sub/superscripts can be applied. Org-mode's HTML generator is also
544 much faster."
545 :group 'org-export-tables
546 :type 'boolean)
549 (defgroup org-export-xml nil
550 "Options specific for XML export of Org-mode files."
551 :tag "Org Export XML"
552 :group 'org-export)
554 ;;;; Exporting
556 ;;; Variables, constants, and parameter plists
558 (defconst org-level-max 20)
560 (defvar org-current-export-file nil) ; dynamically scoped parameter
561 (defvar org-current-export-dir nil) ; dynamically scoped parameter
562 (defvar org-export-opt-plist nil
563 "Contains the current option plist.")
564 (defvar org-last-level nil) ; dynamically scoped variable
565 (defvar org-min-level nil) ; dynamically scoped variable
566 (defvar org-levels-open nil) ; dynamically scoped parameter
568 (defconst org-export-plist-vars
569 '((:link-up nil org-export-html-link-up)
570 (:link-home nil org-export-html-link-home)
571 (:language nil org-export-default-language)
572 (:keywords nil org-export-page-keywords)
573 (:description nil org-export-page-description)
574 (:customtime nil org-display-custom-times)
575 (:headline-levels "H" org-export-headline-levels)
576 (:section-numbers "num" org-export-with-section-numbers)
577 (:section-number-format nil org-export-section-number-format)
578 (:table-of-contents "toc" org-export-with-toc)
579 (:preserve-breaks "\\n" org-export-preserve-breaks)
580 (:archived-trees nil org-export-with-archived-trees)
581 (:emphasize "*" org-export-with-emphasize)
582 (:sub-superscript "^" org-export-with-sub-superscripts)
583 (:special-strings "-" org-export-with-special-strings)
584 (:footnotes "f" org-export-with-footnotes)
585 (:drawers "d" org-export-with-drawers)
586 (:tags "tags" org-export-with-tags)
587 (:todo-keywords "todo" org-export-with-todo-keywords)
588 (:priority "pri" org-export-with-priority)
589 (:TeX-macros "TeX" org-export-with-TeX-macros)
590 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
591 (:latex-listings nil org-export-latex-listings)
592 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
593 (:fixed-width ":" org-export-with-fixed-width)
594 (:timestamps "<" org-export-with-timestamps)
595 (:author-info "author" org-export-author-info)
596 (:creator-info "creator" org-export-creator-info)
597 (:time-stamp-file "timestamp" org-export-time-stamp-file)
598 (:tables "|" org-export-with-tables)
599 (:table-auto-headline nil org-export-highlight-first-table-line)
600 (:style-include-default nil org-export-html-style-include-default)
601 (:style-include-scripts nil org-export-html-style-include-scripts)
602 (:style nil org-export-html-style)
603 (:style-extra nil org-export-html-style-extra)
604 (:agenda-style nil org-agenda-export-html-style)
605 (:convert-org-links nil org-export-html-link-org-files-as-html)
606 (:inline-images nil org-export-html-inline-images)
607 (:html-extension nil org-export-html-extension)
608 (:xml-declaration nil org-export-html-xml-declaration)
609 (:html-table-tag nil org-export-html-table-tag)
610 (:expand-quoted-html "@" org-export-html-expand)
611 (:timestamp nil org-export-html-with-timestamp)
612 (:publishing-directory nil org-export-publishing-directory)
613 (:preamble nil org-export-html-preamble)
614 (:postamble nil org-export-html-postamble)
615 (:auto-preamble nil org-export-html-auto-preamble)
616 (:auto-postamble nil org-export-html-auto-postamble)
617 (:author nil user-full-name)
618 (:email nil user-mail-address)
619 (:select-tags nil org-export-select-tags)
620 (:exclude-tags nil org-export-exclude-tags)
622 (:latex-image-options nil org-export-latex-image-default-option))
623 "List of properties that represent export/publishing variables.
624 Each element is a list of 3 items:
625 1. The property that is used internally, and also for org-publish-project-alist
626 2. The string that can be used in the OPTION lines to set this option,
627 or nil if this option cannot be changed in this way
628 3. The customization variable that sets the default for this option."
631 (defun org-default-export-plist ()
632 "Return the property list with default settings for the export variables."
633 (let* ((infile (org-infile-export-plist))
634 (letbind (plist-get infile :let-bind))
635 (l org-export-plist-vars) rtn e s v)
636 (while (setq e (pop l))
637 (setq s (nth 2 e)
638 v (cond
639 ((assq s letbind) (nth 1 (assq s letbind)))
640 ((boundp s) (symbol-value s))
641 (t nil))
642 rtn (cons (car e) (cons v rtn))))
643 rtn))
645 (defvar org-export-inbuffer-options-extra nil
646 "List of additional in-buffer options that should be detected.
647 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
648 etc. Extensions can add to this list to get their options detected, and they
649 can then add a function to `org-export-options-filters' to process these
650 options.
651 Each element in this list must be a list, with the in-buffer keyword as car,
652 and a property (a symbol) as the next element. All occurrences of the
653 keyword will be found, the values concatenated with a space character
654 in between, and the result stored in the export options property list.")
656 (defvar org-export-options-filters nil
657 "Functions to be called to finalize the export/publishing options.
658 All these options are stored in a property list, and each of the functions
659 in this hook gets a chance to modify this property list. Each function
660 must accept the property list as an argument, and must return the (possibly
661 modified) list.")
663 ;; FIXME: should we fold case here?
664 (defun org-infile-export-plist ()
665 "Return the property list with file-local settings for export."
666 (save-excursion
667 (save-restriction
668 (widen)
669 (goto-char (point-min))
670 (let ((re (org-make-options-regexp
671 (append
672 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
673 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
674 "LATEX_HEADER" "LATEX_CLASS"
675 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
676 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND")
677 (mapcar 'car org-export-inbuffer-options-extra))))
678 p key val text options a pr style
679 latex-header latex-class macros letbind
680 ext-setup-or-nil setup-contents (start 0))
681 (while (or (and ext-setup-or-nil
682 (string-match re ext-setup-or-nil start)
683 (setq start (match-end 0)))
684 (and (setq ext-setup-or-nil nil start 0)
685 (re-search-forward re nil t)))
686 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
687 val (org-match-string-no-properties 2 ext-setup-or-nil))
688 (cond
689 ((setq a (assoc key org-export-inbuffer-options-extra))
690 (setq pr (nth 1 a))
691 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
692 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
693 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
694 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
695 ((string-equal key "DATE") (setq p (plist-put p :date val)))
696 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
697 ((string-equal key "DESCRIPTION")
698 (setq p (plist-put p :description val)))
699 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
700 ((string-equal key "STYLE")
701 (setq style (concat style "\n" val)))
702 ((string-equal key "LATEX_HEADER")
703 (setq latex-header (concat latex-header "\n" val)))
704 ((string-equal key "LATEX_CLASS")
705 (setq latex-class val))
706 ((string-equal key "TEXT")
707 (setq text (if text (concat text "\n" val) val)))
708 ((string-equal key "OPTIONS")
709 (setq options (concat val " " options)))
710 ((string-equal key "BIND")
711 (push (read (concat "(" val ")")) letbind))
712 ((string-equal key "LINK_UP")
713 (setq p (plist-put p :link-up val)))
714 ((string-equal key "LINK_HOME")
715 (setq p (plist-put p :link-home val)))
716 ((string-equal key "EXPORT_SELECT_TAGS")
717 (setq p (plist-put p :select-tags (org-split-string val))))
718 ((string-equal key "EXPORT_EXCLUDE_TAGS")
719 (setq p (plist-put p :exclude-tags (org-split-string val))))
720 ((string-equal key "MACRO")
721 (push val macros))
722 ((equal key "SETUPFILE")
723 (setq setup-contents (org-file-contents
724 (expand-file-name
725 (org-remove-double-quotes
726 (org-trim val)))
727 'noerror))
728 (if (not ext-setup-or-nil)
729 (setq ext-setup-or-nil setup-contents start 0)
730 (setq ext-setup-or-nil
731 (concat (substring ext-setup-or-nil 0 start)
732 "\n" setup-contents "\n"
733 (substring ext-setup-or-nil start)))))))
734 (setq p (plist-put p :text text))
735 (when (and letbind (org-export-confirm-letbind))
736 (setq p (plist-put p :let-bind letbind)))
737 (when style (setq p (plist-put p :style-extra style)))
738 (when latex-header
739 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
740 (when latex-class
741 (setq p (plist-put p :latex-class latex-class)))
742 (when options
743 (setq p (org-export-add-options-to-plist p options)))
744 ;; Add macro definitions
745 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
746 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
747 (setq p (plist-put
748 p :macro-modification-time
749 (and (buffer-file-name)
750 (file-exists-p (buffer-file-name))
751 (concat
752 "(eval (format-time-string \"$1\" '"
753 (prin1-to-string (nth 5 (file-attributes
754 (buffer-file-name))))
755 "))"))))
756 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
757 (file-name-nondirectory
758 (buffer-file-name)))))
759 (while (setq val (pop macros))
760 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
761 (setq p (plist-put
762 p (intern
763 (concat ":macro-" (downcase (match-string 1 val))))
764 (org-export-interpolate-newlines (match-string 2 val))))))
765 p))))
767 (defun org-export-interpolate-newlines (s)
768 (while (string-match "\\\\n" s)
769 (setq s (replace-match "\n" t t s)))
772 (defvar org-export-allow-BIND-local nil)
773 (defun org-export-confirm-letbind ()
774 "Can we use #+BIND values during export?
775 By default this will ask fro confirmation by the user, to divert possible
776 security risks."
777 (cond
778 ((not org-export-allow-BIND) nil)
779 ((eq org-export-allow-BIND t) t)
780 ((local-variable-p 'org-export-allow-BIND-local (current-buffer))
781 org-export-allow-BIND-local)
782 (t (org-set-local 'org-export-allow-BIND-local
783 (yes-or-no-p "Allow BIND values in this buffer? ")))))
785 (defun org-install-letbind ()
786 "Install the values from #+BIND lines as local variables."
787 (let ((letbind (plist-get org-export-opt-plist :let-bind)))
788 (while letbind
789 (org-set-local (caar letbind) (nth 1 (pop letbind))))))
791 (defun org-export-add-options-to-plist (p options)
792 "Parse an OPTIONS line and set values in the property list P."
793 (let (o)
794 (when options
795 (let ((op org-export-plist-vars))
796 (while (setq o (pop op))
797 (if (and (nth 1 o)
798 (string-match (concat (regexp-quote (nth 1 o))
799 ":\\([^ \t\n\r;,.]*\\)")
800 options))
801 (setq p (plist-put p (car o)
802 (car (read-from-string
803 (match-string 1 options))))))))))
806 (defun org-export-add-subtree-options (p pos)
807 "Add options in subtree at position POS to property list P."
808 (save-excursion
809 (goto-char pos)
810 (when (org-at-heading-p)
811 (let (a)
812 ;; This is actually read in `org-export-get-title-from-subtree'
813 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
814 ;; (setq p (plist-put p :title a)))
815 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
816 (setq p (plist-put p :text a)))
817 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
818 (setq p (plist-put p :author a)))
819 (when (setq a (org-entry-get pos "EXPORT_DATE"))
820 (setq p (plist-put p :date a)))
821 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
822 (setq p (org-export-add-options-to-plist p a)))))
825 (defun org-export-directory (type plist)
826 (let* ((val (plist-get plist :publishing-directory))
827 (dir (if (listp val)
828 (or (cdr (assoc type val)) ".")
829 val)))
830 dir))
832 (defun org-export-process-option-filters (plist)
833 (let ((functions org-export-options-filters) f)
834 (while (setq f (pop functions))
835 (setq plist (funcall f plist))))
836 plist)
838 ;;;###autoload
839 (defun org-export (&optional arg)
840 "Export dispatcher for Org-mode.
841 When `org-export-run-in-background' is non-nil, try to run the command
842 in the background. This will be done only for commands that write
843 to a file. For details see the docstring of `org-export-run-in-background'.
845 The prefix argument ARG will be passed to the exporter. However, if
846 ARG is a double universal prefix `C-u C-u', that means to inverse the
847 value of `org-export-run-in-background'."
848 (interactive "P")
849 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
850 subtree-p
851 (help "[t] insert the export option template
852 \[v] limit export to visible part of outline tree
853 \[1] only export the current subtree
855 \[a] export as ASCII [A] to temporary buffer
857 \[h] export as HTML [H] to temporary buffer [R] export region
858 \[b] export as HTML and open in browser
860 \[l] export as LaTeX [L] to temporary buffer
861 \[p] export as LaTeX and process to PDF
862 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
864 \[D] export as DocBook
865 \[V] export as DocBook, process to PDF, and open the resulting PDF document
867 \[m] export as Freemind mind map
869 \[x] export as XOXO
870 \[g] export using Wes Hardaker's generic exporter
872 \[i] export current file as iCalendar file
873 \[I] export all agenda files as iCalendar files
874 \[c] export agenda files into combined iCalendar file
876 \[F] publish current file [P] publish current project
877 \[X] publish a project... [E] publish every projects")
878 (cmds
879 '((?t org-insert-export-options-template nil)
880 (?v org-export-visible nil)
881 (?a org-export-as-ascii t)
882 (?A org-export-as-ascii-to-buffer t)
883 (?h org-export-as-html t)
884 (?b org-export-as-html-and-open t)
885 (?H org-export-as-html-to-buffer nil)
886 (?R org-export-region-as-html nil)
887 (?x org-export-as-xoxo t)
888 (?g org-export-generic t)
889 (?D org-export-as-docbook t)
890 (?V org-export-as-docbook-pdf-and-open t)
891 (?m org-export-as-freemind t)
892 (?l org-export-as-latex t)
893 (?p org-export-as-pdf t)
894 (?d org-export-as-pdf-and-open t)
895 (?L org-export-as-latex-to-buffer nil)
896 (?i org-export-icalendar-this-file t)
897 (?I org-export-icalendar-all-agenda-files t)
898 (?c org-export-icalendar-combine-agenda-files t)
899 (?F org-publish-current-file t)
900 (?P org-publish-current-project t)
901 (?X org-publish t)
902 (?E org-publish-all t)))
903 r1 r2 ass)
904 (save-excursion
905 (save-window-excursion
906 (delete-other-windows)
907 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
908 (princ help))
909 (org-fit-window-to-buffer (get-buffer-window
910 "*Org Export/Publishing Help*"))
911 (message "Select command: ")
912 (setq r1 (read-char-exclusive))
913 (when (eq r1 ?1)
914 (setq subtree-p t)
915 (message "Select command (for subtree): ")
916 (setq r1 (read-char-exclusive)))))
917 (setq r2 (if (< r1 27) (+ r1 96) r1))
918 (unless (setq ass (assq r2 cmds))
919 (error "No command associated with key %c" r1))
920 (if (and bg (nth 2 ass)
921 (not (buffer-base-buffer))
922 (not (org-region-active-p)))
923 ;; execute in background
924 (let ((p (start-process
925 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
926 "*Org Processes*"
927 (expand-file-name invocation-name invocation-directory)
928 "-batch"
929 "-l" user-init-file
930 "--eval" "(require 'org-exp)"
931 "--eval" "(setq org-wait .2)"
932 (buffer-file-name)
933 "-f" (symbol-name (nth 1 ass)))))
934 (set-process-sentinel p 'org-export-process-sentinel)
935 (message "Background process \"%s\": started" p))
936 ;; background processing not requested, or not possible
937 (if subtree-p (outline-mark-subtree))
938 (call-interactively (nth 1 ass)))))
940 (defun org-export-process-sentinel (process status)
941 (if (string-match "\n+\\'" status)
942 (setq status (substring status 0 -1)))
943 (message "Background process \"%s\": %s" process status))
945 (defconst org-html-entities
946 '(("nbsp")
947 ("iexcl")
948 ("cent")
949 ("pound")
950 ("curren")
951 ("yen")
952 ("brvbar")
953 ("vert" . "&#124;")
954 ("sect")
955 ("uml")
956 ("copy")
957 ("ordf")
958 ("laquo")
959 ("not")
960 ("shy")
961 ("reg")
962 ("macr")
963 ("deg")
964 ("pm" . "&plusmn;")
965 ("plusmn")
966 ("sup2")
967 ("sup3")
968 ("acute")
969 ("micro")
970 ("para")
971 ("middot")
972 ("odot"."o")
973 ("star"."*")
974 ("cedil")
975 ("sup1")
976 ("ordm")
977 ("raquo")
978 ("frac14")
979 ("frac12")
980 ("frac34")
981 ("iquest")
982 ("Agrave")
983 ("Aacute")
984 ("Acirc")
985 ("Atilde")
986 ("Auml")
987 ("Aring") ("AA"."&Aring;")
988 ("AElig")
989 ("Ccedil")
990 ("Egrave")
991 ("Eacute")
992 ("Ecirc")
993 ("Euml")
994 ("Igrave")
995 ("Iacute")
996 ("Icirc")
997 ("Iuml")
998 ("ETH")
999 ("Ntilde")
1000 ("Ograve")
1001 ("Oacute")
1002 ("Ocirc")
1003 ("Otilde")
1004 ("Ouml")
1005 ("times")
1006 ("Oslash")
1007 ("Ugrave")
1008 ("Uacute")
1009 ("Ucirc")
1010 ("Uuml")
1011 ("Yacute")
1012 ("THORN")
1013 ("szlig")
1014 ("agrave")
1015 ("aacute")
1016 ("acirc")
1017 ("atilde")
1018 ("auml")
1019 ("aring")
1020 ("aelig")
1021 ("ccedil")
1022 ("egrave")
1023 ("eacute")
1024 ("ecirc")
1025 ("euml")
1026 ("igrave")
1027 ("iacute")
1028 ("icirc")
1029 ("iuml")
1030 ("eth")
1031 ("ntilde")
1032 ("ograve")
1033 ("oacute")
1034 ("ocirc")
1035 ("otilde")
1036 ("ouml")
1037 ("divide")
1038 ("oslash")
1039 ("ugrave")
1040 ("uacute")
1041 ("ucirc")
1042 ("uuml")
1043 ("yacute")
1044 ("thorn")
1045 ("yuml")
1046 ("fnof")
1047 ("Alpha")
1048 ("Beta")
1049 ("Gamma")
1050 ("Delta")
1051 ("Epsilon")
1052 ("Zeta")
1053 ("Eta")
1054 ("Theta")
1055 ("Iota")
1056 ("Kappa")
1057 ("Lambda")
1058 ("Mu")
1059 ("Nu")
1060 ("Xi")
1061 ("Omicron")
1062 ("Pi")
1063 ("Rho")
1064 ("Sigma")
1065 ("Tau")
1066 ("Upsilon")
1067 ("Phi")
1068 ("Chi")
1069 ("Psi")
1070 ("Omega")
1071 ("alpha")
1072 ("beta")
1073 ("gamma")
1074 ("delta")
1075 ("epsilon")
1076 ("varepsilon"."&epsilon;")
1077 ("zeta")
1078 ("eta")
1079 ("theta")
1080 ("iota")
1081 ("kappa")
1082 ("lambda")
1083 ("mu")
1084 ("nu")
1085 ("xi")
1086 ("omicron")
1087 ("pi")
1088 ("rho")
1089 ("sigmaf") ("varsigma"."&sigmaf;")
1090 ("sigma")
1091 ("tau")
1092 ("upsilon")
1093 ("phi")
1094 ("chi")
1095 ("psi")
1096 ("omega")
1097 ("thetasym") ("vartheta"."&thetasym;")
1098 ("upsih")
1099 ("piv")
1100 ("bull") ("bullet"."&bull;")
1101 ("hellip") ("dots"."&hellip;")
1102 ("prime")
1103 ("Prime")
1104 ("oline")
1105 ("frasl")
1106 ("weierp")
1107 ("image")
1108 ("real")
1109 ("trade")
1110 ("alefsym")
1111 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1112 ("uarr") ("uparrow"."&uarr;")
1113 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1114 ("darr")("downarrow"."&darr;")
1115 ("harr") ("leftrightarrow"."&harr;")
1116 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1117 ("lArr") ("Leftarrow"."&lArr;")
1118 ("uArr") ("Uparrow"."&uArr;")
1119 ("rArr") ("Rightarrow"."&rArr;")
1120 ("dArr") ("Downarrow"."&dArr;")
1121 ("hArr") ("Leftrightarrow"."&hArr;")
1122 ("forall")
1123 ("part") ("partial"."&part;")
1124 ("exist") ("exists"."&exist;")
1125 ("empty") ("emptyset"."&empty;")
1126 ("nabla")
1127 ("isin") ("in"."&isin;")
1128 ("notin")
1129 ("ni")
1130 ("prod")
1131 ("sum")
1132 ("minus")
1133 ("lowast") ("ast"."&lowast;")
1134 ("radic")
1135 ("prop") ("proptp"."&prop;")
1136 ("infin") ("infty"."&infin;")
1137 ("ang") ("angle"."&ang;")
1138 ("and") ("wedge"."&and;")
1139 ("or") ("vee"."&or;")
1140 ("cap")
1141 ("cup")
1142 ("int")
1143 ("there4")
1144 ("sim")
1145 ("cong") ("simeq"."&cong;")
1146 ("asymp")("approx"."&asymp;")
1147 ("ne") ("neq"."&ne;")
1148 ("equiv")
1149 ("le")
1150 ("ge")
1151 ("sub") ("subset"."&sub;")
1152 ("sup") ("supset"."&sup;")
1153 ("nsub")
1154 ("sube")
1155 ("supe")
1156 ("oplus")
1157 ("otimes")
1158 ("perp")
1159 ("sdot") ("cdot"."&sdot;")
1160 ("lceil")
1161 ("rceil")
1162 ("lfloor")
1163 ("rfloor")
1164 ("lang")
1165 ("rang")
1166 ("loz") ("Diamond"."&loz;")
1167 ("spades") ("spadesuit"."&spades;")
1168 ("clubs") ("clubsuit"."&clubs;")
1169 ("hearts") ("diamondsuit"."&hearts;")
1170 ("diams") ("diamondsuit"."&diams;")
1171 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1172 ("quot")
1173 ("amp")
1174 ("lt")
1175 ("gt")
1176 ("OElig")
1177 ("oelig")
1178 ("Scaron")
1179 ("scaron")
1180 ("Yuml")
1181 ("circ")
1182 ("tilde")
1183 ("ensp")
1184 ("emsp")
1185 ("thinsp")
1186 ("zwnj")
1187 ("zwj")
1188 ("lrm")
1189 ("rlm")
1190 ("ndash")
1191 ("mdash")
1192 ("lsquo")
1193 ("rsquo")
1194 ("sbquo")
1195 ("ldquo")
1196 ("rdquo")
1197 ("bdquo")
1198 ("dagger")
1199 ("Dagger")
1200 ("permil")
1201 ("lsaquo")
1202 ("rsaquo")
1203 ("euro")
1204 ("EUR"."&euro;")
1205 ("EURdig"."&euro;")
1206 ("EURhv"."&euro;")
1207 ("EURcr"."&euro;")
1208 ("EURtm"."&euro;")
1209 ("arccos"."arccos")
1210 ("arcsin"."arcsin")
1211 ("arctan"."arctan")
1212 ("arg"."arg")
1213 ("cos"."cos")
1214 ("cosh"."cosh")
1215 ("cot"."cot")
1216 ("coth"."coth")
1217 ("csc"."csc")
1218 ("deg"."deg")
1219 ("det"."det")
1220 ("dim"."dim")
1221 ("exp"."exp")
1222 ("gcd"."gcd")
1223 ("hom"."hom")
1224 ("inf"."inf")
1225 ("ker"."ker")
1226 ("lg"."lg")
1227 ("lim"."lim")
1228 ("liminf"."liminf")
1229 ("limsup"."limsup")
1230 ("ln"."ln")
1231 ("log"."log")
1232 ("max"."max")
1233 ("min"."min")
1234 ("Pr"."Pr")
1235 ("sec"."sec")
1236 ("sin"."sin")
1237 ("sinh"."sinh")
1238 ("sup"."sup")
1239 ("tan"."tan")
1240 ("tanh"."tanh")
1242 "Entities for TeX->HTML translation.
1243 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1244 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1245 In that case, \"\\ent\" will be translated to \"&other;\".
1246 The list contains HTML entities for Latin-1, Greek and other symbols.
1247 It is supplemented by a number of commonly used TeX macros with appropriate
1248 translations. There is currently no way for users to extend this.")
1250 ;;; General functions for all backends
1252 (defvar org-export-target-aliases nil
1253 "Alist of targets with invisible aliases.")
1254 (defvar org-export-preferred-target-alist nil
1255 "Alist of section id's with preferred aliases.")
1256 (defvar org-export-code-refs nil
1257 "Alist of code references and line numbers")
1259 (defun org-export-preprocess-string (string &rest parameters)
1260 "Cleanup STRING so that that the true exported has a more consistent source.
1261 This function takes STRING, which should be a buffer-string of an org-file
1262 to export. It then creates a temporary buffer where it does its job.
1263 The result is then again returned as a string, and the exporter works
1264 on this string to produce the exported version."
1265 (interactive)
1266 (let* ((htmlp (plist-get parameters :for-html))
1267 (asciip (plist-get parameters :for-ascii))
1268 (latexp (plist-get parameters :for-LaTeX))
1269 (docbookp (plist-get parameters :for-docbook))
1270 (backend (cond (htmlp 'html)
1271 (latexp 'latex)
1272 (asciip 'ascii)
1273 (docbookp 'docbook)))
1274 (archived-trees (plist-get parameters :archived-trees))
1275 (inhibit-read-only t)
1276 (drawers org-drawers)
1277 (outline-regexp "\\*+ ")
1278 target-alist rtn)
1280 (setq org-export-target-aliases nil)
1281 (setq org-export-preferred-target-alist nil)
1282 (setq org-export-code-refs nil)
1284 (with-current-buffer (get-buffer-create " org-mode-tmp")
1285 (erase-buffer)
1286 (insert string)
1287 (setq case-fold-search t)
1289 (let ((inhibit-read-only t))
1290 (remove-text-properties (point-min) (point-max)
1291 '(read-only t)))
1293 ;; Remove license-to-kill stuff
1294 ;; The caller marks some stuff for killing, stuff that has been
1295 ;; used to create the page title, for example.
1296 (org-export-kill-licensed-text)
1298 (let ((org-inhibit-startup t)) (org-mode))
1299 (setq case-fold-search t)
1300 (org-install-letbind)
1302 ;; Call the hook
1303 (run-hooks 'org-export-preprocess-hook)
1305 ;; Process the macros
1306 (org-export-preprocess-apply-macros)
1307 (run-hooks 'org-export-preprocess-after-macros-hook)
1309 (untabify (point-min) (point-max))
1311 ;; Handle include files, and call a hook
1312 (org-export-handle-include-files)
1313 (run-hooks 'org-export-preprocess-after-include-files-hook)
1315 ;; Get rid of archived trees
1316 (org-export-remove-archived-trees archived-trees)
1318 ;; Remove comment environment and comment subtrees
1319 (org-export-remove-comment-blocks-and-subtrees)
1321 ;; Get rid of excluded trees, and call a hook
1322 (org-export-handle-export-tags (plist-get parameters :select-tags)
1323 (plist-get parameters :exclude-tags))
1324 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1326 ;; Handle source code snippets
1327 (org-export-replace-src-segments-and-examples backend)
1329 ;; Protect short examples marked by a leading colon
1330 (org-export-protect-colon-examples)
1332 ;; Normalize footnotes
1333 (when (plist-get parameters :footnotes)
1334 (org-footnote-normalize nil t))
1336 ;; Find all headings and compute the targets for them
1337 (setq target-alist (org-export-define-heading-targets target-alist))
1339 ;; Get rid of drawers
1340 (org-export-remove-or-extract-drawers
1341 drawers (plist-get parameters :drawers) backend)
1343 ;; Get the correct stuff before the first headline
1344 (when (plist-get parameters :skip-before-1st-heading)
1345 (goto-char (point-min))
1346 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1347 (delete-region (point-min) (match-beginning 0))
1348 (goto-char (point-min))
1349 (insert "\n")))
1350 (when (plist-get parameters :add-text)
1351 (goto-char (point-min))
1352 (insert (plist-get parameters :add-text) "\n"))
1354 ;; Remove todo-keywords before exporting, if the user has requested so
1355 (org-export-remove-headline-metadata parameters)
1357 ;; Find targets in comments and move them out of comments,
1358 ;; but mark them as targets that should be invisible
1359 (setq target-alist (org-export-handle-invisible-targets target-alist))
1361 ;; Select and protect backend specific stuff, throw away stuff
1362 ;; that is specific for other backends
1363 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
1364 (org-export-select-backend-specific-text backend)
1366 ;; Protect quoted subtrees
1367 (org-export-protect-quoted-subtrees)
1369 ;; Remove clock lines
1370 (org-export-remove-clock-lines)
1372 ;; Protect verbatim elements
1373 (org-export-protect-verbatim)
1375 ;; Blockquotes, verse, and center
1376 (org-export-mark-blockquote-verse-center)
1377 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1379 ;; Remove timestamps, if the user has requested so
1380 (unless (plist-get parameters :timestamps)
1381 (org-export-remove-timestamps))
1383 ;; Attach captions to the correct object
1384 (setq target-alist (org-export-attach-captions-and-attributes
1385 backend target-alist))
1387 ;; Find matches for radio targets and turn them into internal links
1388 (org-export-mark-radio-links)
1390 ;; Find all links that contain a newline and put them into a single line
1391 (org-export-concatenate-multiline-links)
1393 ;; Normalize links: Convert angle and plain links into bracket links
1394 ;; and expand link abbreviations
1395 (run-hooks 'org-export-preprocess-before-normalizing-links-hook)
1396 (org-export-normalize-links)
1398 ;; Find all internal links. If they have a fuzzy match (i.e. not
1399 ;; a *dedicated* target match, let the link point to the
1400 ;; corresponding section.
1401 (org-export-target-internal-links target-alist)
1403 ;; Find multiline emphasis and put them into single line
1404 (when (plist-get parameters :emph-multiline)
1405 (org-export-concatenate-multiline-emphasis))
1407 ;; Remove special table lines
1408 (when org-export-table-remove-special-lines
1409 (org-export-remove-special-table-lines))
1411 ;; Another hook
1412 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1414 ;; LaTeX-specific preprocessing
1415 (when latexp
1416 (require 'org-latex nil)
1417 (org-export-latex-preprocess parameters))
1419 ;; ASCII-specific preprocessing
1420 (when asciip
1421 (org-export-ascii-preprocess parameters))
1423 ;; HTML-specific preprocessing
1424 (when htmlp
1425 (org-export-html-preprocess parameters))
1427 ;; DocBook-specific preprocessing
1428 (when docbookp
1429 (require 'org-docbook nil)
1430 (org-export-docbook-preprocess parameters))
1432 ;; Remove or replace comments
1433 (org-export-handle-comments (plist-get parameters :comments))
1435 ;; Run the final hook
1436 (run-hooks 'org-export-preprocess-final-hook)
1438 (setq rtn (buffer-string)))
1439 (kill-buffer " org-mode-tmp")
1440 rtn))
1442 (defun org-export-kill-licensed-text ()
1443 "Remove all text that is marked with a :org-license-to-kill property."
1444 (let (p)
1445 (while (setq p (text-property-any (point-min) (point-max)
1446 :org-license-to-kill t))
1447 (delete-region
1448 p (or (next-single-property-change p :org-license-to-kill)
1449 (point-max))))))
1451 (defun org-export-define-heading-targets (target-alist)
1452 "Find all headings and define the targets for them.
1453 The new targets are added to TARGET-ALIST, which is also returned."
1454 (goto-char (point-min))
1455 (org-init-section-numbers)
1456 (let ((re (concat "^" org-outline-regexp
1457 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1458 level target last-section-target a id)
1459 (while (re-search-forward re nil t)
1460 (if (match-end 2)
1461 (progn
1462 (setq id (org-match-string-no-properties 2))
1463 (push (cons id target) target-alist)
1464 (setq a (or (assoc last-section-target org-export-target-aliases)
1465 (progn
1466 (push (list last-section-target)
1467 org-export-target-aliases)
1468 (car org-export-target-aliases))))
1469 (push (caar target-alist) (cdr a))
1470 (when (equal (match-string 1) "CUSTOM_ID")
1471 (if (not (assoc last-section-target
1472 org-export-preferred-target-alist))
1473 (push (cons last-section-target id)
1474 org-export-preferred-target-alist))))
1475 (setq level (org-reduced-level
1476 (save-excursion (goto-char (point-at-bol))
1477 (org-outline-level))))
1478 (setq target (org-solidify-link-text
1479 (format "sec-%s" (org-section-number level))))
1480 (setq last-section-target target)
1481 (push (cons target target) target-alist)
1482 (add-text-properties
1483 (point-at-bol) (point-at-eol)
1484 (list 'target target)))))
1485 target-alist)
1487 (defun org-export-handle-invisible-targets (target-alist)
1488 "Find targets in comments and move them out of comments.
1489 Mark them as invisible targets."
1490 (let (target tmp a)
1491 (goto-char (point-min))
1492 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1493 ;; Check if the line before or after is a headline with a target
1494 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1495 (get-text-property (point-at-bol 2) 'target)))
1496 (progn
1497 ;; use the existing target in a neighboring line
1498 (setq tmp (match-string 2))
1499 (replace-match "")
1500 (and (looking-at "\n") (delete-char 1))
1501 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1502 target-alist)
1503 (setq a (or (assoc target org-export-target-aliases)
1504 (progn
1505 (push (list target) org-export-target-aliases)
1506 (car org-export-target-aliases))))
1507 (push tmp (cdr a)))
1508 ;; Make an invisible target
1509 (replace-match "\\1(INVISIBLE)"))))
1510 target-alist)
1512 (defun org-export-target-internal-links (target-alist)
1513 "Find all internal links and assign targets to them.
1514 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1515 let the link point to the corresponding section.
1516 This function also handles the id links, if they have a match in
1517 the current file."
1518 (goto-char (point-min))
1519 (while (re-search-forward org-bracket-link-regexp nil t)
1520 (org-if-unprotected-at (match-beginning 1)
1521 (let* ((md (match-data))
1522 (desc (match-end 2))
1523 (link (org-link-unescape (match-string 1)))
1524 (slink (org-solidify-link-text link))
1525 found props pos cref
1526 (target
1527 (cond
1528 ((= (string-to-char link) ?#)
1529 ;; user wants exactly this link
1530 link)
1531 ((cdr (assoc slink target-alist))
1532 (or (cdr (assoc (assoc slink target-alist)
1533 org-export-preferred-target-alist))
1534 (cdr (assoc slink target-alist))))
1535 ((and (string-match "^id:" link)
1536 (cdr (assoc (substring link 3) target-alist))))
1537 ((string-match "^(\\(.*\\))$" link)
1538 (setq cref (match-string 1 link))
1539 (concat "coderef:" cref))
1540 ((string-match org-link-types-re link) nil)
1541 ((or (file-name-absolute-p link)
1542 (string-match "^\\." link))
1543 nil)
1545 (save-excursion
1546 (setq found (condition-case nil (org-link-search link)
1547 (error nil)))
1548 (when (and found
1549 (or (org-on-heading-p)
1550 (not (eq found 'dedicated))))
1551 (or (get-text-property (point) 'target)
1552 (get-text-property
1553 (max (point-min)
1554 (1- (or (previous-single-property-change
1555 (point) 'target) 0)))
1556 'target))))))))
1557 (when target
1558 (set-match-data md)
1559 (goto-char (match-beginning 1))
1560 (setq props (text-properties-at (point)))
1561 (delete-region (match-beginning 1) (match-end 1))
1562 (setq pos (point))
1563 (insert target)
1564 (unless desc (insert "][" link))
1565 (add-text-properties pos (point) props))))))
1567 (defvar org-export-format-drawer-function nil
1568 "Function to be called to format the contents of a drawer.
1569 The function must accept three parameters:
1570 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1571 NAME the drawer name, like \"PROPERTIES\"
1572 CONTENT the content of the drawer.
1573 The function should return the text to be inserted into the buffer.
1574 If this is nil, `org-export-format-drawer' is used as a default.")
1576 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend)
1577 "Remove drawers, or extract and format the content.
1578 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1579 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1580 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1581 EXP-DRAWERS will be removed.
1582 BACKEND is the current export backend."
1583 (goto-char (point-min))
1584 (let ((re (concat "^[ \t]*:\\("
1585 (mapconcat 'identity all-drawers "\\|")
1586 "\\):[ \t]*$"))
1587 name beg beg-content eol content)
1588 (while (re-search-forward re nil t)
1589 (org-if-unprotected
1590 (setq name (match-string 1))
1591 (setq beg (match-beginning 0)
1592 beg-content (1+ (point-at-eol))
1593 eol (point-at-eol))
1594 (if (not (and (re-search-forward
1595 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t)
1596 (match-end 1)))
1597 (goto-char eol)
1598 (goto-char (match-beginning 0))
1599 (and (looking-at ".*\n?") (replace-match ""))
1600 (setq content (buffer-substring beg-content (point)))
1601 (delete-region beg (point))
1602 (when (or (eq exp-drawers t)
1603 (member name exp-drawers))
1604 (setq content (funcall (or org-export-format-drawer-function
1605 'org-export-format-drawer)
1606 name content backend))
1607 (insert content)))))))
1609 (defun org-export-format-drawer (name content backend)
1610 "Format the content of a drawer as a colon example."
1611 (if (string-match "[ \t]+\\'" content)
1612 (setq content (substring content (match-beginning 0))))
1613 (while (string-match "\\`[ \t]*\n" content)
1614 (setq content (substring content (match-end 0))))
1615 (setq content (org-remove-indentation content))
1616 (setq content (concat ": " (mapconcat 'identity
1617 (org-split-string content "\n")
1618 "\n: ")
1619 "\n"))
1620 (setq content (concat " : " (upcase name) "\n" content))
1621 (org-add-props content nil 'org-protected t))
1623 (defun org-export-handle-export-tags (select-tags exclude-tags)
1624 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1625 Both arguments are lists of tags.
1626 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1627 will be removed.
1628 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1629 removed as well."
1630 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1631 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1632 select-tags "\\|")
1633 "\\):"))
1634 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1635 exclude-tags "\\|")
1636 "\\):"))
1637 beg end cont)
1638 (goto-char (point-min))
1639 (when (and select-tags
1640 (re-search-forward
1641 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1642 ;; At least one tree is marked for export, this means
1643 ;; all the unmarked stuff needs to go.
1644 ;; Dig out the trees that should be exported
1645 (goto-char (point-min))
1646 (outline-next-heading)
1647 (setq beg (point))
1648 (put-text-property beg (point-max) :org-delete t)
1649 (while (re-search-forward re-sel nil t)
1650 (when (org-on-heading-p)
1651 (org-back-to-heading)
1652 (remove-text-properties
1653 (max (1- (point)) (point-min))
1654 (setq cont (save-excursion (org-end-of-subtree t t)))
1655 '(:org-delete t))
1656 (while (and (org-up-heading-safe)
1657 (get-text-property (point) :org-delete))
1658 (remove-text-properties (max (1- (point)) (point-min))
1659 (point-at-eol) '(:org-delete t)))
1660 (goto-char cont))))
1661 ;; Remove the trees explicitly marked for noexport
1662 (when exclude-tags
1663 (goto-char (point-min))
1664 (while (re-search-forward re-excl nil t)
1665 (when (org-at-heading-p)
1666 (org-back-to-heading t)
1667 (setq beg (point))
1668 (org-end-of-subtree t t)
1669 (delete-region beg (point))
1670 (when (featurep 'org-inlinetask)
1671 (org-inlinetask-remove-END-maybe)))))
1672 ;; Remove everything that is now still marked for deletion
1673 (goto-char (point-min))
1674 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1675 (setq end (or (next-single-property-change beg :org-delete)
1676 (point-max)))
1677 (delete-region beg end))))
1679 (defun org-export-remove-archived-trees (export-archived-trees)
1680 "Remove archived trees.
1681 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1682 When it is t, the entire archived tree will be exported.
1683 When it is nil the entire tree including the headline will be removed
1684 from the buffer."
1685 (let ((re-archive (concat ":" org-archive-tag ":"))
1686 a b)
1687 (when (not (eq export-archived-trees t))
1688 (goto-char (point-min))
1689 (while (re-search-forward re-archive nil t)
1690 (if (not (org-on-heading-p t))
1691 (org-end-of-subtree t)
1692 (beginning-of-line 1)
1693 (setq a (if export-archived-trees
1694 (1+ (point-at-eol)) (point))
1695 b (org-end-of-subtree t))
1696 (if (> b a) (delete-region a b)))))))
1698 (defun org-export-remove-headline-metadata (opts)
1699 "Remove meta data from the headline, according to user options."
1700 (let ((re org-complex-heading-regexp)
1701 (todo (plist-get opts :todo-keywords))
1702 (tags (plist-get opts :tags))
1703 (pri (plist-get opts :priority))
1704 (elts '(1 2 3 4 5))
1705 rpl)
1706 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1707 (when (or (not todo) (not tags) (not pri))
1708 (goto-char (point-min))
1709 (while (re-search-forward re nil t)
1710 (org-if-unprotected
1711 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1712 elts " "))
1713 (replace-match rpl t t))))))
1715 (defun org-export-remove-timestamps ()
1716 "Remove timestamps and keywords for export."
1717 (goto-char (point-min))
1718 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1719 (backward-char 1)
1720 (org-if-unprotected
1721 (unless (save-match-data (org-at-table-p))
1722 (replace-match "")
1723 (beginning-of-line 1)
1724 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1725 (replace-match ""))))))
1727 (defun org-export-remove-clock-lines ()
1728 "Remove clock lines for export."
1729 (goto-char (point-min))
1730 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1731 (while (re-search-forward re nil t)
1732 (org-if-unprotected
1733 (replace-match "")))))
1735 (defun org-export-protect-quoted-subtrees ()
1736 "Mark quoted subtrees with the protection property."
1737 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1738 (goto-char (point-min))
1739 (while (re-search-forward re-quote nil t)
1740 (goto-char (match-beginning 0))
1741 (end-of-line 1)
1742 (add-text-properties (point) (org-end-of-subtree t)
1743 '(org-protected t)))))
1745 (defun org-export-protect-verbatim ()
1746 "Mark verbatim snippets with the protection property."
1747 (goto-char (point-min))
1748 (while (re-search-forward org-verbatim-re nil t)
1749 (org-if-unprotected
1750 (add-text-properties (match-beginning 4) (match-end 4)
1751 '(org-protected t org-verbatim-emph t))
1752 (goto-char (1+ (match-end 4))))))
1754 (defun org-export-protect-colon-examples ()
1755 "Protect lines starting with a colon."
1756 (goto-char (point-min))
1757 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1758 (while (re-search-forward re nil t)
1759 (beginning-of-line 1)
1760 (setq beg (point))
1761 (while (looking-at re)
1762 (end-of-line 1)
1763 (or (eobp) (forward-char 1)))
1764 (add-text-properties beg (if (bolp) (1- (point)) (point))
1765 '(org-protected t)))))
1767 (defun org-export-select-backend-specific-text (backend)
1768 (let ((formatters
1769 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1770 (html "HTML" "BEGIN_HTML" "END_HTML")
1771 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1772 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1773 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1774 (case-fold-search t)
1775 fmt beg beg-content end end-content)
1777 (while formatters
1778 (setq fmt (pop formatters))
1779 (when (eq (car fmt) backend)
1780 ;; This is selected code, put it into the file for real
1781 (goto-char (point-min))
1782 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1783 ":[ \t]*\\(.*\\)") nil t)
1784 (replace-match "\\1\\2" t)
1785 (add-text-properties
1786 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1787 '(org-protected t))))
1788 (goto-char (point-min))
1789 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?")
1790 nil t)
1791 (setq beg (match-beginning 0) beg-content (match-end 0))
1792 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
1793 nil t)
1794 (setq end (match-end 0) end-content (match-beginning 0))
1795 (if (eq (car fmt) backend)
1796 ;; yes, keep this
1797 (progn
1798 (add-text-properties beg-content end-content '(org-protected t))
1799 (delete-region (match-beginning 0) (match-end 0))
1800 (save-excursion
1801 (goto-char beg)
1802 (delete-region (point) (1+ (point-at-eol)))))
1803 ;; No, this is for a different backend, kill it
1804 (delete-region beg end)))))))
1806 (defun org-export-mark-blockquote-verse-center ()
1807 "Mark block quote and verse environments with special cookies.
1808 These special cookies will later be interpreted by the backend."
1809 ;; Blockquotes
1810 (let (type t1 ind beg end beg1 end1 content)
1811 (goto-char (point-min))
1812 (while (re-search-forward
1813 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1814 nil t)
1815 (setq ind (length (match-string 1))
1816 type (downcase (match-string 3))
1817 t1 (if (equal type "quote") "blockquote" type))
1818 (setq beg (match-beginning 0)
1819 beg1 (1+ (match-end 0)))
1820 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1821 (setq end (1+ (point-at-eol))
1822 end1 (1- (match-beginning 0)))
1823 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1824 (setq content (concat "ORG-" (upcase t1) "-START\n"
1825 content "\n"
1826 "ORG-" (upcase t1) "-END\n"))
1827 (delete-region beg end)
1828 (insert (org-add-props content nil 'original-indentation ind))))))
1830 (defun org-export-attach-captions-and-attributes (backend target-alist)
1831 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1832 If the next thing following is a table, add the text properties to the first
1833 table line. If it is a link, add it to the line containing the link."
1834 (goto-char (point-min))
1835 (remove-text-properties (point-min) (point-max)
1836 '(org-caption nil org-attributes nil))
1837 (let ((case-fold-search t)
1838 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1839 "\\|"
1840 "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1841 "\\|"
1842 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1843 "\\|"
1844 "^[ \t]*|[^-]"
1845 "\\|"
1846 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1847 cap attr label)
1848 (while (re-search-forward re nil t)
1849 (cond
1850 ((match-end 1)
1851 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1852 ((match-end 2)
1853 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1854 ((match-end 3)
1855 (setq label (org-trim (match-string 3))))
1857 (add-text-properties (point-at-bol) (point-at-eol)
1858 (list 'org-caption cap
1859 'org-attributes attr
1860 'org-label label))
1861 (if label (push (cons label label) target-alist))
1862 (setq cap nil attr nil label nil)))))
1863 target-alist)
1865 (defun org-export-remove-comment-blocks-and-subtrees ()
1866 "Remove the comment environment, and also commented subtrees."
1867 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1868 (case-fold-search nil))
1869 ;; Remove comment environment
1870 (goto-char (point-min))
1871 (while (re-search-forward
1872 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1873 (replace-match "" t t))
1874 ;; Remove subtrees that are commented
1875 (goto-char (point-min))
1876 (while (re-search-forward re-commented nil t)
1877 (goto-char (match-beginning 0))
1878 (delete-region (point) (org-end-of-subtree t)))))
1880 (defun org-export-handle-comments (commentsp)
1881 "Remove comments, or convert to backend-specific format.
1882 COMMENTSP can be a format string for publishing comments.
1883 When it is nil, all comments will be removed."
1884 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1885 pos)
1886 (goto-char (point-min))
1887 (while (or (looking-at re)
1888 (re-search-forward re nil t))
1889 (setq pos (match-beginning 0))
1890 (if (and commentsp
1891 (not (equal (char-before (match-end 1)) ?+)))
1892 (progn (add-text-properties
1893 (match-beginning 0) (match-end 0) '(org-protected t))
1894 (replace-match (format commentsp (match-string 2)) t t))
1895 (goto-char (1+ pos))
1896 (org-if-unprotected
1897 (replace-match "")
1898 (goto-char (max (point-min) (1- pos))))))))
1900 (defun org-export-mark-radio-links ()
1901 "Find all matches for radio targets and turn them into internal links."
1902 (let ((re-radio (and org-target-link-regexp
1903 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1904 (goto-char (point-min))
1905 (when re-radio
1906 (while (re-search-forward re-radio nil t)
1907 (unless
1908 (save-match-data
1909 (or (org-in-regexp org-bracket-link-regexp)
1910 (org-in-regexp org-plain-link-re)
1911 (org-in-regexp "<<[^<>]+>>")))
1912 (org-if-unprotected
1913 (replace-match "\\1[[\\2]]")))))))
1915 (defun org-export-remove-special-table-lines ()
1916 "Remove tables lines that are used for internal purposes."
1917 (goto-char (point-min))
1918 (while (re-search-forward "^[ \t]*|" nil t)
1919 (beginning-of-line 1)
1920 (if (or (looking-at "[ \t]*| *[!_^] *|")
1921 (not
1922 (memq
1924 (mapcar
1925 (lambda (f)
1926 (or (= (length f) 0)
1927 (string-match
1928 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f)))
1929 (org-split-string ;; FIXME, can't we do this without splitting???
1930 (buffer-substring (point-at-bol) (point-at-eol))
1931 "[ \t]*|[ \t]*")))))
1932 (delete-region (max (point-min) (1- (point-at-bol)))
1933 (point-at-eol))
1934 (end-of-line 1))))
1936 (defun org-export-protect-sub-super (s)
1937 (save-match-data
1938 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s)
1939 (setq s (replace-match "\\1\\\\\\2" nil nil s)))
1942 (defun org-export-normalize-links ()
1943 "Convert all links to bracket links, and expand link abbreviations."
1944 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1945 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1946 nodesc)
1947 (goto-char (point-min))
1948 (while (re-search-forward re-plain-link nil t)
1949 (goto-char (1- (match-end 0)))
1950 (org-if-unprotected-at (1+ (match-beginning 0))
1951 (let* ((s (concat (match-string 1)
1952 "[[" (match-string 2) ":" (match-string 3)
1953 "][" (match-string 2) ":" (org-export-protect-sub-super
1954 (match-string 3))
1955 "]]")))
1956 ;; added 'org-link face to links
1957 (put-text-property 0 (length s) 'face 'org-link s)
1958 (replace-match s t t))))
1959 (goto-char (point-min))
1960 (while (re-search-forward re-angle-link nil t)
1961 (goto-char (1- (match-end 0)))
1962 (org-if-unprotected
1963 (let* ((s (concat (match-string 1)
1964 "[[" (match-string 2) ":" (match-string 3)
1965 "][" (match-string 2) ":" (org-export-protect-sub-super
1966 (match-string 3))
1967 "]]")))
1968 (put-text-property 0 (length s) 'face 'org-link s)
1969 (replace-match s t t))))
1970 (goto-char (point-min))
1971 (while (re-search-forward org-bracket-link-regexp nil t)
1972 (goto-char (1- (match-end 0)))
1973 (setq nodesc (not (match-end 3)))
1974 (org-if-unprotected
1975 (let* ((xx (save-match-data
1976 (org-translate-link
1977 (org-link-expand-abbrev (match-string 1)))))
1978 (s (concat
1979 "[[" (org-add-props (copy-sequence xx)
1980 nil 'org-protected t 'org-no-description nodesc)
1982 (if (match-end 3)
1983 (match-string 2)
1984 (concat "[" (copy-sequence xx)
1985 "]"))
1986 "]")))
1987 (put-text-property 0 (length s) 'face 'org-link s)
1988 (replace-match s t t))))))
1990 (defun org-export-concatenate-multiline-links ()
1991 "Find multi-line links and put it all into a single line.
1992 This is to make sure that the line-processing export backends
1993 can work correctly."
1994 (goto-char (point-min))
1995 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1996 (org-if-unprotected
1997 (replace-match "\\1 \\3")
1998 (goto-char (match-beginning 0)))))
2000 (defun org-export-concatenate-multiline-emphasis ()
2001 "Find multi-line emphasis and put it all into a single line.
2002 This is to make sure that the line-processing export backends
2003 can work correctly."
2004 (goto-char (point-min))
2005 (while (re-search-forward org-emph-re nil t)
2006 (if (and (not (= (char-after (match-beginning 3))
2007 (char-after (match-beginning 4))))
2008 (save-excursion (goto-char (match-beginning 0))
2009 (save-match-data (not (org-at-table-p)))))
2010 (org-if-unprotected
2011 (subst-char-in-region (match-beginning 0) (match-end 0)
2012 ?\n ?\ t)
2013 (goto-char (1- (match-end 0))))
2014 (goto-char (1+ (match-beginning 0))))))
2016 (defun org-export-grab-title-from-buffer ()
2017 "Get a title for the current document, from looking at the buffer."
2018 (let ((inhibit-read-only t))
2019 (save-excursion
2020 (goto-char (point-min))
2021 (let ((end (if (looking-at org-outline-regexp)
2022 (point)
2023 (save-excursion (outline-next-heading) (point)))))
2024 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2025 ;; Mark the line so that it will not be exported as normal text.
2026 (org-unmodified
2027 (add-text-properties (match-beginning 0) (match-end 0)
2028 (list :org-license-to-kill t)))
2029 ;; Return the title string
2030 (org-trim (match-string 0)))))))
2032 (defun org-export-get-title-from-subtree ()
2033 "Return subtree title and exclude it from export."
2034 (let (title (rbeg (region-beginning)) (rend (region-end)))
2035 (save-excursion
2036 (goto-char rbeg)
2037 (when (and (org-at-heading-p)
2038 (>= (org-end-of-subtree t t) rend))
2039 ;; This is a subtree, we take the title from the first heading
2040 (goto-char rbeg)
2041 (looking-at org-todo-line-regexp)
2042 (setq title (match-string 3))
2043 (org-unmodified
2044 (add-text-properties (point) (1+ (point-at-eol))
2045 (list :org-license-to-kill t)))
2046 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2047 title))
2049 (defun org-solidify-link-text (s &optional alist)
2050 "Take link text and make a safe target out of it."
2051 (save-match-data
2052 (let* ((rtn
2053 (mapconcat
2054 'identity
2055 (org-split-string s "[ \t\r\n]+") "=="))
2056 (a (assoc rtn alist)))
2057 (or (cdr a) rtn))))
2059 (defun org-get-min-level (lines &optional offset)
2060 "Get the minimum level in LINES."
2061 (let ((re "^\\(\\*+\\) ") l)
2062 (catch 'exit
2063 (while (setq l (pop lines))
2064 (if (string-match re l)
2065 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2066 (or offset 0))))))
2067 1)))
2069 ;; Variable holding the vector with section numbers
2070 (defvar org-section-numbers (make-vector org-level-max 0))
2072 (defun org-init-section-numbers ()
2073 "Initialize the vector for the section numbers."
2074 (let* ((level -1)
2075 (numbers (nreverse (org-split-string "" "\\.")))
2076 (depth (1- (length org-section-numbers)))
2077 (i depth) number-string)
2078 (while (>= i 0)
2079 (if (> i level)
2080 (aset org-section-numbers i 0)
2081 (setq number-string (or (car numbers) "0"))
2082 (if (string-match "\\`[A-Z]\\'" number-string)
2083 (aset org-section-numbers i
2084 (- (string-to-char number-string) ?A -1))
2085 (aset org-section-numbers i (string-to-number number-string)))
2086 (pop numbers))
2087 (setq i (1- i)))))
2089 (defun org-section-number (&optional level)
2090 "Return a string with the current section number.
2091 When LEVEL is non-nil, increase section numbers on that level."
2092 (let* ((depth (1- (length org-section-numbers)))
2093 (string "")
2094 (fmts (car org-export-section-number-format))
2095 (term (cdr org-export-section-number-format))
2096 (sep "")
2097 ctype fmt idx n)
2098 (when level
2099 (when (> level -1)
2100 (aset org-section-numbers
2101 level (1+ (aref org-section-numbers level))))
2102 (setq idx (1+ level))
2103 (while (<= idx depth)
2104 (if (not (= idx 1))
2105 (aset org-section-numbers idx 0))
2106 (setq idx (1+ idx))))
2107 (setq idx 0)
2108 (while (<= idx depth)
2109 (when (> (aref org-section-numbers idx) 0)
2110 (setq fmt (or (pop fmts) fmt)
2111 ctype (car fmt)
2112 n (aref org-section-numbers idx)
2113 string (if (> n 0)
2114 (concat string sep (org-number-to-counter n ctype))
2115 (concat string ".0"))
2116 sep (nth 1 fmt)))
2117 (setq idx (1+ idx)))
2118 (save-match-data
2119 (if (string-match "\\`\\([@0]\\.\\)+" string)
2120 (setq string (replace-match "" t nil string)))
2121 (if (string-match "\\(\\.0\\)+\\'" string)
2122 (setq string (replace-match "" t nil string))))
2123 (concat string term)))
2125 (defun org-number-to-counter (n type)
2126 "Concert number N to a string counter, according to TYPE.
2127 TYPE must be a string, any of:
2128 1 number
2129 A A,B,....
2130 a a,b,....
2131 I upper case roman numeral
2132 i lower case roman numeral"
2133 (cond
2134 ((equal type "1") (number-to-string n))
2135 ((equal type "A") (char-to-string (+ ?A n -1)))
2136 ((equal type "a") (char-to-string (+ ?a n -1)))
2137 ((equal type "I") (org-number-to-roman n))
2138 ((equal type "i") (downcase (org-number-to-roman n)))
2139 (t (error "Invalid counter type `%s'" type))))
2141 (defun org-number-to-roman (n)
2142 "Convert integer N into a roman numeral."
2143 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2144 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2145 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2146 ( 1 . "I")))
2147 (res ""))
2148 (if (<= n 0)
2149 (number-to-string n)
2150 (while roman
2151 (if (>= n (caar roman))
2152 (setq n (- n (caar roman))
2153 res (concat res (cdar roman)))
2154 (pop roman)))
2155 res)))
2157 ;;; Macros
2159 (defun org-export-preprocess-apply-macros ()
2160 "Replace macro references."
2161 (goto-char (point-min))
2162 (let (sy val key args args2 s n)
2163 (while (re-search-forward
2164 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2165 nil t)
2166 (unless (save-match-data
2167 (save-excursion
2168 (goto-char (point-at-bol))
2169 (looking-at "[ \t]*#\\+macro")))
2170 (setq key (downcase (match-string 1))
2171 args (match-string 3))
2172 (when (setq val (or (plist-get org-export-opt-plist
2173 (intern (concat ":macro-" key)))
2174 (plist-get org-export-opt-plist
2175 (intern (concat ":" key)))))
2176 (save-match-data
2177 (when args
2178 (setq args (org-split-string args ",[ \t\n]*") args2 nil)
2179 (setq args (mapcar 'org-trim args))
2180 (while args
2181 (while (string-match "\\\\\\'" (car args))
2182 ;; repair bad splits
2183 (setcar (cdr args) (concat (substring (car args) 0 -1)
2184 ";" (nth 1 args)))
2185 (pop args))
2186 (push (pop args) args2))
2187 (setq args (nreverse args2))
2188 (setq s 0)
2189 (while (string-match "\\$\\([0-9]+\\)" val s)
2190 (setq s (1+ (match-beginning 0))
2191 n (string-to-number (match-string 1 val)))
2192 (and (>= (length args) n)
2193 (setq val (replace-match (nth (1- n) args) t t val)))))
2194 (when (string-match "\\`(eval\\>" val)
2195 (setq val (eval (read val))))
2196 (if (and val (not (stringp val)))
2197 (setq val (format "%s" val))))
2198 (and (stringp val)
2199 (prog1 (replace-match val t t)
2200 (goto-char (match-beginning 0)))))))))
2202 (defun org-export-apply-macros-in-string (s)
2203 "Apply the macros in string S."
2204 (when s
2205 (with-temp-buffer
2206 (insert s)
2207 (org-export-preprocess-apply-macros)
2208 (buffer-string))))
2210 ;;; Include files
2212 (defun org-export-handle-include-files ()
2213 "Include the contents of include files, with proper formatting."
2214 (let ((case-fold-search t)
2215 params file markup lang start end prefix prefix1 switches)
2216 (goto-char (point-min))
2217 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2218 (setq params (read (concat "(" (match-string 1) ")"))
2219 prefix (org-get-and-remove-property 'params :prefix)
2220 prefix1 (org-get-and-remove-property 'params :prefix1)
2221 file (org-symname-or-string (pop params))
2222 markup (org-symname-or-string (pop params))
2223 lang (and (member markup '("src" "SRC"))
2224 (org-symname-or-string (pop params)))
2225 switches (mapconcat '(lambda (x) (format "%s" x)) params " ")
2226 start nil end nil)
2227 (delete-region (match-beginning 0) (match-end 0))
2228 (if (or (not file)
2229 (not (file-exists-p file))
2230 (not (file-readable-p file)))
2231 (insert (format "CANNOT INCLUDE FILE %s" file))
2232 (when markup
2233 (if (equal (downcase markup) "src")
2234 (setq start (format "#+begin_src %s %s\n"
2235 (or lang "fundamental")
2236 (or switches ""))
2237 end "#+end_src")
2238 (setq start (format "#+begin_%s %s\n" markup switches)
2239 end (format "#+end_%s" markup))))
2240 (insert (or start ""))
2241 (insert (org-get-file-contents (expand-file-name file)
2242 prefix prefix1 markup))
2243 (or (bolp) (newline))
2244 (insert (or end ""))))))
2246 (defun org-get-file-contents (file &optional prefix prefix1 markup)
2247 "Get the contents of FILE and return them as a string.
2248 If PREFIX is a string, prepend it to each line. If PREFIX1
2249 is a string, prepend it to the first line instead of PREFIX.
2250 If MARKUP, don't protect org-like lines, the exporter will
2251 take care of the block they are in."
2252 (if (stringp markup) (setq markup (downcase markup)))
2253 (with-temp-buffer
2254 (insert-file-contents file)
2255 (when (or prefix prefix1)
2256 (goto-char (point-min))
2257 (while (not (eobp))
2258 (insert (or prefix1 prefix))
2259 (setq prefix1 nil)
2260 (beginning-of-line 2)))
2261 (buffer-string)
2262 (when (member markup '("src" "example"))
2263 (goto-char (point-min))
2264 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t)
2265 (goto-char (match-beginning 0))
2266 (insert ",")
2267 (end-of-line 1)))
2268 (buffer-string)))
2270 (defun org-get-and-remove-property (listvar prop)
2271 "Check if the value of LISTVAR contains PROP as a property.
2272 If yes, return the value of that property (i.e. the element following
2273 in the list) and remove property and value from the list in LISTVAR."
2274 (let ((list (symbol-value listvar)) m v)
2275 (when (setq m (member prop list))
2276 (setq v (nth 1 m))
2277 (if (equal (car list) prop)
2278 (set listvar (cddr list))
2279 (setcdr (nthcdr (- (length list) (length m) 1) list)
2280 (cddr m))
2281 (set listvar list)))
2284 (defun org-symname-or-string (s)
2285 (if (symbolp s)
2286 (if s (symbol-name s) s)
2289 ;;; Fontification and line numbers for code examples
2291 (defvar org-export-last-code-line-counter-value 0)
2293 (defun org-export-replace-src-segments-and-examples (backend)
2294 "Replace source code segments with special code for export."
2295 (setq org-export-last-code-line-counter-value 0)
2296 (let ((case-fold-search t)
2297 lang code trans opts indent)
2298 (goto-char (point-min))
2299 (while (re-search-forward
2300 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2301 nil t)
2302 (if (match-end 1)
2303 ;; src segments
2304 (setq lang (match-string 3)
2305 opts (match-string 4)
2306 code (match-string 5)
2307 indent (length (match-string 2)))
2308 (setq lang nil
2309 opts (match-string 8)
2310 code (match-string 9)
2311 indent (length (match-string 7))))
2313 (setq trans (org-export-format-source-code-or-example
2314 backend lang code opts indent))
2315 (replace-match trans t t))))
2317 (defvar htmlp) ;; dynamically scoped
2318 (defvar latexp) ;; dynamically scoped
2319 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2320 (defvar org-export-latex-listings) ;; defined in org-latex.el
2321 (defvar org-export-latex-listings-langs) ;; defined in org-latex.el
2323 (defun org-export-format-source-code-or-example
2324 (backend lang code &optional opts indent)
2325 "Format CODE from language LANG and return it formatted for export.
2326 If LANG is nil, do not add any fontification.
2327 OPTS contains formatting options, like `-n' for triggering numbering lines,
2328 and `+n' for continuing previous numbering.
2329 Code formatting according to language currently only works for HTML.
2330 Numbering lines works for all three major backends (html, latex, and ascii).
2331 INDENT was the original indentation of the block."
2332 (save-match-data
2333 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2334 (setq opts (or opts "")
2335 num (string-match "[-+]n\\>" opts)
2336 cont (string-match "\\+n\\>" opts)
2337 rpllbl (string-match "-r\\>" opts)
2338 keepp (string-match "-k\\>" opts)
2339 textareap (string-match "-t\\>" opts)
2340 preserve-indentp (or org-src-preserve-indentation
2341 (string-match "-i\\>" opts))
2342 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2343 (string-to-number (match-string 1 opts))
2345 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2346 (string-to-number (match-string 1 opts))
2347 (org-count-lines code))
2348 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2349 (match-string 1 opts)))
2350 (when (and textareap (eq backend 'html))
2351 ;; we cannot use numbering or highlighting.
2352 (setq num nil cont nil lang nil))
2353 (if keepp (setq rpllbl 'keep))
2354 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2355 (when (string-match "^," rtn)
2356 (setq rtn (with-temp-buffer
2357 (insert rtn)
2358 ;; Free up the protected lines
2359 (goto-char (point-min))
2360 (while (re-search-forward "^," nil t)
2361 (if (or (equal lang "org")
2362 (save-match-data
2363 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2364 (replace-match ""))
2365 (end-of-line 1))
2366 (buffer-string))))
2367 ;; Now backend-specific coding
2368 (setq rtn
2369 (cond
2370 ((eq backend 'docbook)
2371 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2372 (concat "\n#+BEGIN_DOCBOOK\n"
2373 (org-add-props (concat "<programlisting><![CDATA["
2375 "]]>\n</programlisting>\n")
2376 '(org-protected t))
2377 "#+END_DOCBOOK\n"))
2378 ((eq backend 'html)
2379 ;; We are exporting to HTML
2380 (when lang
2381 (require 'htmlize nil t)
2382 (when (not (fboundp 'htmlize-region-for-paste))
2383 ;; we do not have htmlize.el, or an old version of it
2384 (setq lang nil)
2385 (message
2386 "htmlize.el 1.34 or later is needed for source code formatting")))
2388 (if lang
2389 (let* ((lang-m (when lang
2390 (or (cdr (assoc lang org-src-lang-modes))
2391 lang)))
2392 (mode (and lang-m (intern
2393 (concat
2394 (if (symbolp lang-m)
2395 (symbol-name lang-m)
2396 lang-m)
2397 "-mode"))))
2398 (org-inhibit-startup t)
2399 (org-startup-folded nil))
2400 (setq rtn
2401 (with-temp-buffer
2402 (insert rtn)
2403 (if (functionp mode)
2404 (funcall mode)
2405 (fundamental-mode))
2406 (font-lock-fontify-buffer)
2407 (org-src-mode)
2408 (set-buffer-modified-p nil)
2409 (org-export-htmlize-region-for-paste
2410 (point-min) (point-max))))
2411 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2412 (setq rtn (replace-match
2413 (format "<pre class=\"src src-%s\">\n" lang)
2414 t t rtn))))
2415 (if textareap
2416 (setq rtn (concat
2417 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2418 cols rows)
2419 rtn "</textarea>\n</p>\n"))
2420 (with-temp-buffer
2421 (insert rtn)
2422 (goto-char (point-min))
2423 (while (re-search-forward "[<>&]" nil t)
2424 (replace-match (cdr (assq (char-before)
2425 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2426 t t))
2427 (setq rtn (buffer-string)))
2428 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2429 (unless textareap
2430 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2431 cont rpllbl fmt)))
2432 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
2433 (setq rtn (replace-match "\\1" t nil rtn)))
2434 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2435 ((eq backend 'latex)
2436 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2437 (concat "#+BEGIN_LaTeX\n"
2438 (org-add-props
2439 (if org-export-latex-listings
2440 (concat
2441 (if lang
2442 (let*
2443 ((lang-sym (intern lang))
2444 (lstlang
2445 (or (cadr
2446 (assq
2447 lang-sym
2448 org-export-latex-listings-langs))
2449 lang)))
2450 (format "\\lstset{language=%s}\n" lstlang))
2452 "\\begin{lstlisting}\n"
2453 rtn "\\end{lstlisting}\n")
2454 (concat (car org-export-latex-verbatim-wrap)
2455 rtn (cdr org-export-latex-verbatim-wrap)))
2456 '(org-protected t))
2457 "#+END_LaTeX\n"))
2458 ((eq backend 'ascii)
2459 ;; This is not HTML or LaTeX, so just make it an example.
2460 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2461 (concat "#+BEGIN_ASCII\n"
2462 (org-add-props
2463 (concat
2464 (mapconcat
2465 (lambda (l) (concat " " l))
2466 (org-split-string rtn "\n")
2467 "\n")
2468 "\n")
2469 '(org-protected t))
2470 "#+END_ASCII\n"))))
2471 (org-add-props rtn nil 'original-indentation indent))))
2473 (defun org-export-number-lines (text backend
2474 &optional skip1 skip2 number cont
2475 replace-labels label-format)
2476 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2477 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2478 (with-temp-buffer
2479 (insert text)
2480 (goto-char (point-max))
2481 (skip-chars-backward " \t\n\r")
2482 (delete-region (point) (point-max))
2483 (beginning-of-line (- 1 skip2))
2484 (let* ((last (org-current-line))
2485 (n org-export-last-code-line-counter-value)
2486 (nmax (+ n (- last skip1)))
2487 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2489 (cond
2490 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2491 fmt))
2492 ((eq backend 'ascii) fmt)
2493 ((eq backend 'latex) fmt)
2494 ((eq backend 'docbook) fmt)
2495 (t "")))
2496 (label-format (or label-format org-coderef-label-format))
2497 (label-pre (if (string-match "%s" label-format)
2498 (substring label-format 0 (match-beginning 0))
2499 label-format))
2500 (label-post (if (string-match "%s" label-format)
2501 (substring label-format (match-end 0))
2502 ""))
2503 (lbl-re
2504 (concat
2505 ".*?\\S-.*?\\([ \t]*\\("
2506 (regexp-quote label-pre)
2507 "\\([-a-zA-Z0-9_ ]+\\)"
2508 (regexp-quote label-post)
2509 "\\)\\)"))
2510 ref)
2512 (org-goto-line (1+ skip1))
2513 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2514 (if number
2515 (insert (format fm (incf n)))
2516 (forward-char 1))
2517 (when (looking-at lbl-re)
2518 (setq ref (match-string 3))
2519 (cond ((numberp replace-labels)
2520 ;; remove labels; use numbers for references when lines
2521 ;; are numbered, use labels otherwise
2522 (delete-region (match-beginning 1) (match-end 1))
2523 (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
2524 ((eq replace-labels 'keep)
2525 ;; don't remove labels; use numbers for references when
2526 ;; lines are numbered, use labels otherwise
2527 (goto-char (match-beginning 2))
2528 (delete-region (match-beginning 2) (match-end 2))
2529 (insert "(" ref ")")
2530 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
2531 org-export-code-refs))
2533 ;; don't remove labels and don't use numbers for
2534 ;; references
2535 (goto-char (match-beginning 2))
2536 (delete-region (match-beginning 2) (match-end 2))
2537 (insert "(" ref ")")
2538 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
2539 (when (eq backend 'html)
2540 (save-excursion
2541 (beginning-of-line 1)
2542 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2543 ref))
2544 (end-of-line 1)
2545 (insert "</span>")))))
2546 (setq org-export-last-code-line-counter-value n)
2547 (goto-char (point-max))
2548 (newline)
2549 (buffer-string))))
2551 (defun org-search-todo-below (line lines level)
2552 "Search the subtree below LINE for any TODO entries."
2553 (let ((rest (cdr (memq line lines)))
2554 (re org-todo-line-regexp)
2555 line lv todo)
2556 (catch 'exit
2557 (while (setq line (pop rest))
2558 (if (string-match re line)
2559 (progn
2560 (setq lv (- (match-end 1) (match-beginning 1))
2561 todo (and (match-beginning 2)
2562 (not (member (match-string 2 line)
2563 org-done-keywords))))
2564 ; TODO, not DONE
2565 (if (<= lv level) (throw 'exit nil))
2566 (if todo (throw 'exit t))))))))
2568 ;;;###autoload
2569 (defun org-export-visible (type arg)
2570 "Create a copy of the visible part of the current buffer, and export it.
2571 The copy is created in a temporary buffer and removed after use.
2572 TYPE is the final key (as a string) that also select the export command in
2573 the `C-c C-e' export dispatcher.
2574 As a special case, if the you type SPC at the prompt, the temporary
2575 org-mode file will not be removed but presented to you so that you can
2576 continue to use it. The prefix arg ARG is passed through to the exporting
2577 command."
2578 (interactive
2579 (list (progn
2580 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]buffer with HTML [D]ocBook [l]atex [p]df [d]view pdf [L]atex buffer [x]OXO [ ]keep buffer")
2581 (read-char-exclusive))
2582 current-prefix-arg))
2583 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L)))
2584 (error "Invalid export key"))
2585 (let* ((binding (cdr (assoc type
2586 '((?a . org-export-as-ascii)
2587 (?A . org-export-as-ascii-to-buffer)
2588 (?\C-a . org-export-as-ascii)
2589 (?b . org-export-as-html-and-open)
2590 (?\C-b . org-export-as-html-and-open)
2591 (?h . org-export-as-html)
2592 (?H . org-export-as-html-to-buffer)
2593 (?R . org-export-region-as-html)
2594 (?D . org-export-as-docbook)
2596 (?l . org-export-as-latex)
2597 (?p . org-export-as-pdf)
2598 (?d . org-export-as-pdf-and-open)
2599 (?L . org-export-as-latex-to-buffer)
2601 (?x . org-export-as-xoxo)))))
2602 (keepp (equal type ?\ ))
2603 (file buffer-file-name)
2604 (buffer (get-buffer-create "*Org Export Visible*"))
2605 s e)
2606 ;; Need to hack the drawers here.
2607 (save-excursion
2608 (goto-char (point-min))
2609 (while (re-search-forward org-drawer-regexp nil t)
2610 (goto-char (match-beginning 1))
2611 (or (org-invisible-p) (org-flag-drawer nil))))
2612 (with-current-buffer buffer (erase-buffer))
2613 (save-excursion
2614 (setq s (goto-char (point-min)))
2615 (while (not (= (point) (point-max)))
2616 (goto-char (org-find-invisible))
2617 (append-to-buffer buffer s (point))
2618 (setq s (goto-char (org-find-visible))))
2619 (org-cycle-hide-drawers 'all)
2620 (goto-char (point-min))
2621 (unless keepp
2622 ;; Copy all comment lines to the end, to make sure #+ settings are
2623 ;; still available for the second export step. Kind of a hack, but
2624 ;; does do the trick.
2625 (if (looking-at "#[^\r\n]*")
2626 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2627 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2628 (append-to-buffer buffer (1+ (match-beginning 0))
2629 (min (point-max) (1+ (match-end 0))))))
2630 (set-buffer buffer)
2631 (let ((buffer-file-name file)
2632 (org-inhibit-startup t))
2633 (org-mode)
2634 (show-all)
2635 (unless keepp (funcall binding arg))))
2636 (if (not keepp)
2637 (kill-buffer buffer)
2638 (switch-to-buffer-other-window buffer)
2639 (goto-char (point-min)))))
2641 (defun org-find-visible ()
2642 (let ((s (point)))
2643 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2644 (get-char-property s 'invisible)))
2646 (defun org-find-invisible ()
2647 (let ((s (point)))
2648 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2649 (not (get-char-property s 'invisible))))
2652 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2654 ;;;###autoload
2655 (defun org-export-as-org (arg &optional hidden ext-plist
2656 to-buffer body-only pub-dir)
2657 "Make a copy with not-exporting stuff removed.
2658 The purpose of this function is to provide a way to export the source
2659 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2660 stuff removed. This command will remove the following:
2662 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2663 - comment blocks and trees starting with the COMMENT keyword
2664 - only trees that are consistent with `org-export-select-tags'
2665 and `org-export-exclude-tags'.
2667 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2668 all the others will be ignored (but are present so that the general
2669 mechanism to call publishing functions will work).
2671 EXT-PLIST is a property list with external parameters overriding
2672 org-mode's default settings, but still inferior to file-local
2673 settings. When PUB-DIR is set, use this as the publishing
2674 directory."
2675 (interactive "P")
2676 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2677 ext-plist
2678 (org-infile-export-plist)))
2679 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2680 (filename (concat (file-name-as-directory
2681 (or pub-dir
2682 (org-export-directory :org opt-plist)))
2683 (file-name-sans-extension
2684 (file-name-nondirectory bfname))
2685 ".org"))
2686 (filename (and filename
2687 (if (equal (file-truename filename)
2688 (file-truename bfname))
2689 (concat (file-name-sans-extension filename)
2690 "-source."
2691 (file-name-extension filename))
2692 filename)))
2693 (backup-inhibited t)
2694 (buffer (find-file-noselect filename))
2695 (region (buffer-string)))
2696 (save-excursion
2697 (switch-to-buffer buffer)
2698 (erase-buffer)
2699 (insert region)
2700 (let ((org-inhibit-startup t)) (org-mode))
2701 (org-install-letbind)
2703 ;; Get rid of archived trees
2704 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2706 ;; Remove comment environment and comment subtrees
2707 (org-export-remove-comment-blocks-and-subtrees)
2709 ;; Get rid of excluded trees
2710 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2711 (plist-get opt-plist :exclude-tags))
2713 (when (or (plist-get opt-plist :plain-source)
2714 (not (or (plist-get opt-plist :plain-source)
2715 (plist-get opt-plist :htmlized-source))))
2716 ;; Either nothing special is requested (default call)
2717 ;; or the plain source is explicitly requested
2718 ;; so: save it
2719 (save-buffer))
2720 (when (plist-get opt-plist :htmlized-source)
2721 ;; Make the htmlized version
2722 (require 'htmlize)
2723 (require 'org-html)
2724 (font-lock-fontify-buffer)
2725 (let* ((htmlize-output-type 'css)
2726 (newbuf (htmlize-buffer)))
2727 (with-current-buffer newbuf
2728 (when org-export-htmlized-org-css-url
2729 (goto-char (point-min))
2730 (and (re-search-forward
2731 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2732 nil t)
2733 (replace-match
2734 (format
2735 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2736 org-export-htmlized-org-css-url)
2737 t t)))
2738 (write-file (concat filename ".html")))
2739 (kill-buffer newbuf)))
2740 (set-buffer-modified-p nil)
2741 (kill-buffer (current-buffer)))))
2743 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2744 (defun org-get-current-options ()
2745 "Return a string with current options as keyword options.
2746 Does include HTML export options as well as TODO and CATEGORY stuff."
2747 (require 'org-archive)
2748 (format
2749 "#+TITLE: %s
2750 #+AUTHOR: %s
2751 #+EMAIL: %s
2752 #+DATE: %s
2753 #+DESCRIPTION:
2754 #+KEYWORDS:
2755 #+LANGUAGE: %s
2756 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2757 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2759 #+EXPORT_SELECT_TAGS: %s
2760 #+EXPORT_EXCLUDE_TAGS: %s
2761 #+LINK_UP: %s
2762 #+LINK_HOME: %s
2763 #+CATEGORY: %s
2764 #+SEQ_TODO: %s
2765 #+TYP_TODO: %s
2766 #+PRIORITIES: %c %c %c
2767 #+DRAWERS: %s
2768 #+STARTUP: %s %s %s %s %s
2769 #+TAGS: %s
2770 #+FILETAGS: %s
2771 #+ARCHIVE: %s
2772 #+LINK: %s
2774 (buffer-name) (user-full-name) user-mail-address
2775 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2776 org-export-default-language
2777 org-export-headline-levels
2778 org-export-with-section-numbers
2779 org-export-with-toc
2780 org-export-preserve-breaks
2781 org-export-html-expand
2782 org-export-with-fixed-width
2783 org-export-with-tables
2784 org-export-with-sub-superscripts
2785 org-export-with-special-strings
2786 org-export-with-footnotes
2787 org-export-with-emphasize
2788 org-export-with-timestamps
2789 org-export-with-TeX-macros
2790 org-export-with-LaTeX-fragments
2791 org-export-skip-text-before-1st-heading
2792 org-export-with-drawers
2793 org-export-with-todo-keywords
2794 org-export-with-priority
2795 org-export-with-tags
2796 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2797 (mapconcat 'identity org-export-select-tags " ")
2798 (mapconcat 'identity org-export-exclude-tags " ")
2799 org-export-html-link-up
2800 org-export-html-link-home
2801 (or (ignore-errors
2802 (file-name-sans-extension
2803 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2804 "NOFILENAME")
2805 "TODO FEEDBACK VERIFY DONE"
2806 "Me Jason Marie DONE"
2807 org-highest-priority org-lowest-priority org-default-priority
2808 (mapconcat 'identity org-drawers " ")
2809 (cdr (assoc org-startup-folded
2810 '((nil . "showall") (t . "overview") (content . "content"))))
2811 (if org-odd-levels-only "odd" "oddeven")
2812 (if org-hide-leading-stars "hidestars" "showstars")
2813 (if org-startup-align-all-tables "align" "noalign")
2814 (cond ((eq org-log-done t) "logdone")
2815 ((equal org-log-done 'note) "lognotedone")
2816 ((not org-log-done) "nologdone"))
2817 (or (mapconcat (lambda (x)
2818 (cond
2819 ((equal :startgroup (car x)) "{")
2820 ((equal :endgroup (car x)) "}")
2821 ((equal :newline (car x)) "")
2822 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2823 (t (car x))))
2824 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2825 (mapconcat 'identity org-file-tags " ")
2826 org-archive-location
2827 "org file:~/org/%s.org"
2830 ;;;###autoload
2831 (defun org-insert-export-options-template ()
2832 "Insert into the buffer a template with information for exporting."
2833 (interactive)
2834 (if (not (bolp)) (newline))
2835 (let ((s (org-get-current-options)))
2836 (and (string-match "#\\+CATEGORY" s)
2837 (setq s (substring s 0 (match-beginning 0))))
2838 (insert s)))
2840 (defvar org-table-colgroup-info nil)
2842 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2843 "Check if the table has a marking column.
2844 If yes remove the column and the special lines."
2845 (setq org-table-colgroup-info nil)
2846 (if (memq nil
2847 (mapcar
2848 (lambda (x) (or (string-match "^[ \t]*|-" x)
2849 (string-match
2850 (if maybe-quoted
2851 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2852 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2853 x)))
2854 lines))
2855 (progn
2856 (setq org-table-clean-did-remove-column nil)
2857 (delq nil
2858 (mapcar
2859 (lambda (x)
2860 (cond
2861 ((string-match "^[ \t]*| */ *|" x)
2862 (setq org-table-colgroup-info
2863 (mapcar (lambda (x)
2864 (cond ((member x '("<" "&lt;")) :start)
2865 ((member x '(">" "&gt;")) :end)
2866 ((member x '("<>" "&lt;&gt;")) :startend)
2867 (t nil)))
2868 (org-split-string x "[ \t]*|[ \t]*")))
2869 nil)
2870 (t x)))
2871 lines)))
2872 (setq org-table-clean-did-remove-column t)
2873 (delq nil
2874 (mapcar
2875 (lambda (x)
2876 (cond
2877 ((string-match "^[ \t]*| */ *|" x)
2878 (setq org-table-colgroup-info
2879 (mapcar (lambda (x)
2880 (cond ((member x '("<" "&lt;")) :start)
2881 ((member x '(">" "&gt;")) :end)
2882 ((member x '("<>" "&lt;&gt;")) :startend)
2883 (t nil)))
2884 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2885 nil)
2886 ((string-match "^[ \t]*| *[!_^/] *|" x)
2887 nil) ; ignore this line
2888 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2889 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2890 ;; remove the first column
2891 (replace-match "\\1|" t nil x))))
2892 lines))))
2894 (defun org-export-cleanup-toc-line (s)
2895 "Remove tags and timestamps from lines going into the toc."
2896 (when (memq org-export-with-tags '(not-in-toc nil))
2897 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2898 (setq s (replace-match "" t t s))))
2899 (when org-export-remove-timestamps-from-toc
2900 (while (string-match org-maybe-keyword-time-regexp s)
2901 (setq s (replace-match "" t t s))))
2902 (while (string-match org-bracket-link-regexp s)
2903 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2904 t t s)))
2905 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s)
2906 (setq s (replace-match "" t t s)))
2909 (defun org-create-multibrace-regexp (left right n)
2910 "Create a regular expression which will match a balanced sexp.
2911 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2912 as single character strings.
2913 The regexp returned will match the entire expression including the
2914 delimiters. It will also define a single group which contains the
2915 match except for the outermost delimiters. The maximum depth of
2916 stacked delimiters is N. Escaping delimiters is not possible."
2917 (let* ((nothing (concat "[^" left right "]*?"))
2918 (or "\\|")
2919 (re nothing)
2920 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
2921 (while (> n 1)
2922 (setq n (1- n)
2923 re (concat re or next)
2924 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
2925 (concat left "\\(" re "\\)" right)))
2927 (defvar org-match-substring-regexp
2928 (concat
2929 "\\([^\\]\\)\\([_^]\\)\\("
2930 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2931 "\\|"
2932 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
2933 "\\|"
2934 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2935 "The regular expression matching a sub- or superscript.")
2937 (defvar org-match-substring-with-braces-regexp
2938 (concat
2939 "\\([^\\]\\)\\([_^]\\)\\("
2940 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2941 "\\)")
2942 "The regular expression matching a sub- or superscript, forcing braces.")
2945 (defun org-get-text-property-any (pos prop &optional object)
2946 (or (get-text-property pos prop object)
2947 (and (setq pos (next-single-property-change pos prop object))
2948 (get-text-property pos prop object))))
2950 (defun org-export-get-coderef-format (path desc)
2951 (save-match-data
2952 (if (and desc (string-match
2953 (regexp-quote (concat "(" path ")"))
2954 desc))
2955 (replace-match "%s" t t desc)
2956 (or desc "%s"))))
2958 (defun org-export-push-to-kill-ring (format)
2959 "Push buffer content to kill ring.
2960 The depends on the variable `org-export-copy-to-kill'."
2961 (when org-export-copy-to-kill-ring
2962 (org-kill-new (buffer-string))
2963 (when (fboundp 'x-set-selection)
2964 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
2965 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
2966 (message "%s export done, pushed to kill ring and clipboard" format)))
2968 (provide 'org-exp)
2970 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2972 ;;; org-exp.el ends here