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