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