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