Release 6.26b
[org-mode/org-tableheadings.git] / lisp / org-exp.el
blob67d29a6a34623caddd3df1e7b8f8efb0fa09835d
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.26b
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-preferred-target-alist nil)
1160 (setq org-export-code-refs nil)
1162 (with-current-buffer (get-buffer-create " org-mode-tmp")
1163 (erase-buffer)
1164 (insert string)
1165 (setq case-fold-search t)
1167 ;; Remove license-to-kill stuff
1168 ;; The caller marks some stuff for killing, stuff that has been
1169 ;; used to create the page title, for example.
1170 (org-export-kill-licensed-text)
1172 (let ((org-inhibit-startup t)) (org-mode))
1173 (setq case-fold-search t)
1175 ;; Call the hook
1176 (run-hooks 'org-export-preprocess-hook)
1178 ;; Process the macros
1179 (org-export-preprocess-apply-macros)
1180 (run-hooks 'org-export-preprocess-after-macros-hook)
1182 (untabify (point-min) (point-max))
1184 ;; Handle include files, and call a hook
1185 (org-export-handle-include-files)
1186 (run-hooks 'org-export-preprocess-after-include-files-hook)
1188 ;; Get rid of archived trees
1189 (org-export-remove-archived-trees archived-trees)
1191 ;; Remove comment environment and comment subtrees
1192 (org-export-remove-comment-blocks-and-subtrees)
1194 ;; Get rid of excluded trees, and call a hook
1195 (org-export-handle-export-tags (plist-get parameters :select-tags)
1196 (plist-get parameters :exclude-tags))
1197 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1199 ;; Handle source code snippets
1200 (org-export-replace-src-segments-and-examples backend)
1202 ;; Protect short examples marked by a leading colon
1203 (org-export-protect-colon-examples)
1205 ;; Normalize footnotes
1206 (when (plist-get parameters :footnotes)
1207 (org-footnote-normalize nil t))
1209 ;; Find all headings and compute the targets for them
1210 (setq target-alist (org-export-define-heading-targets target-alist))
1212 ;; Get rid of drawers
1213 (org-export-remove-or-extract-drawers drawers
1214 (plist-get parameters :drawers))
1216 ;; Get the correct stuff before the first headline
1217 (when (plist-get parameters :skip-before-1st-heading)
1218 (goto-char (point-min))
1219 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1220 (delete-region (point-min) (match-beginning 0))
1221 (goto-char (point-min))
1222 (insert "\n")))
1223 (when (plist-get parameters :add-text)
1224 (goto-char (point-min))
1225 (insert (plist-get parameters :add-text) "\n"))
1227 ;; Remove todo-keywords before exporting, if the user has requested so
1228 (org-export-remove-headline-metadata parameters)
1230 ;; Find targets in comments and move them out of comments,
1231 ;; but mark them as targets that should be invisible
1232 (setq target-alist (org-export-handle-invisible-targets target-alist))
1234 ;; Select and protect backend specific stuff, throw away stuff
1235 ;; that is specific for other backends
1236 (org-export-select-backend-specific-text backend)
1238 ;; Protect quoted subtrees
1239 (org-export-protect-quoted-subtrees)
1241 ;; Remove clock lines
1242 (org-export-remove-clock-lines)
1244 ;; Protect verbatim elements
1245 (org-export-protect-verbatim)
1247 ;; Blockquotes, verse, and center
1248 (org-export-mark-blockquote-verse-center)
1250 ;; Remove timestamps, if the user has requested so
1251 (unless (plist-get parameters :timestamps)
1252 (org-export-remove-timestamps))
1254 ;; Attach captions to the correct object
1255 (setq target-alist (org-export-attach-captions-and-attributes
1256 backend target-alist))
1258 ;; Find matches for radio targets and turn them into internal links
1259 (org-export-mark-radio-links)
1261 ;; Find all links that contain a newline and put them into a single line
1262 (org-export-concatenate-multiline-links)
1264 ;; Normalize links: Convert angle and plain links into bracket links
1265 ;; and expand link abbreviations
1266 (org-export-normalize-links)
1268 ;; Find all internal links. If they have a fuzzy match (i.e. not
1269 ;; a *dedicated* target match, let the link point to the
1270 ;; corresponding section.
1271 (org-export-target-internal-links target-alist)
1273 ;; Find multiline emphasis and put them into single line
1274 (when (plist-get parameters :emph-multiline)
1275 (org-export-concatenate-multiline-emphasis))
1277 ;; Remove special table lines
1278 (when org-export-table-remove-special-lines
1279 (org-export-remove-special-table-lines))
1281 ;; Another hook
1282 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1284 ;; LaTeX-specific preprocessing
1285 (when latexp
1286 (require 'org-latex nil)
1287 (org-export-latex-preprocess parameters))
1289 ;; ASCII-specific preprocessing
1290 (when asciip
1291 (org-export-ascii-preprocess parameters))
1293 ;; HTML-specific preprocessing
1294 (when htmlp
1295 (org-export-html-preprocess parameters))
1297 ;; DocBook-specific preprocessing
1298 (when docbookp
1299 (require 'org-docbook nil)
1300 (org-export-docbook-preprocess parameters))
1302 ;; Remove or replace comments
1303 (org-export-handle-comments (plist-get parameters :comments))
1305 ;; Run the final hook
1306 (run-hooks 'org-export-preprocess-final-hook)
1308 (setq rtn (buffer-string)))
1309 (kill-buffer " org-mode-tmp")
1310 rtn))
1312 (defun org-export-kill-licensed-text ()
1313 "Remove all text that is marked with a :org-license-to-kill property."
1314 (let (p)
1315 (while (setq p (text-property-any (point-min) (point-max)
1316 :org-license-to-kill t))
1317 (delete-region
1318 p (or (next-single-property-change p :org-license-to-kill)
1319 (point-max))))))
1321 (defun org-export-define-heading-targets (target-alist)
1322 "Find all headings and define the targets for them.
1323 The new targets are added to TARGET-ALIST, which is also returned."
1324 (goto-char (point-min))
1325 (org-init-section-numbers)
1326 (let ((re (concat "^" org-outline-regexp
1327 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1328 level target last-section-target a id)
1329 (while (re-search-forward re nil t)
1330 (if (match-end 2)
1331 (progn
1332 (setq id (org-match-string-no-properties 2))
1333 (push (cons id target) target-alist)
1334 (setq a (or (assoc last-section-target org-export-target-aliases)
1335 (progn
1336 (push (list last-section-target)
1337 org-export-target-aliases)
1338 (car org-export-target-aliases))))
1339 (push (caar target-alist) (cdr a))
1340 (when (equal (match-string 1) "CUSTOM_ID")
1341 (if (not (assoc last-section-target
1342 org-export-preferred-target-alist))
1343 (push (cons last-section-target id)
1344 org-export-preferred-target-alist))))
1345 (setq level (org-reduced-level
1346 (save-excursion (goto-char (point-at-bol))
1347 (org-outline-level))))
1348 (setq target (org-solidify-link-text
1349 (format "sec-%s" (org-section-number level))))
1350 (setq last-section-target target)
1351 (push (cons target target) target-alist)
1352 (add-text-properties
1353 (point-at-bol) (point-at-eol)
1354 (list 'target target)))))
1355 target-alist)
1357 (defun org-export-handle-invisible-targets (target-alist)
1358 "Find targets in comments and move them out of comments.
1359 Mark them as invisible targets."
1360 (let (target tmp a)
1361 (goto-char (point-min))
1362 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1363 ;; Check if the line before or after is a headline with a target
1364 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1365 (get-text-property (point-at-bol 2) 'target)))
1366 (progn
1367 ;; use the existing target in a neighboring line
1368 (setq tmp (match-string 2))
1369 (replace-match "")
1370 (and (looking-at "\n") (delete-char 1))
1371 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1372 target-alist)
1373 (setq a (or (assoc target org-export-target-aliases)
1374 (progn
1375 (push (list target) org-export-target-aliases)
1376 (car org-export-target-aliases))))
1377 (push tmp (cdr a)))
1378 ;; Make an invisible target
1379 (replace-match "\\1(INVISIBLE)"))))
1380 target-alist)
1382 (defun org-export-target-internal-links (target-alist)
1383 "Find all internal links and assign targets to them.
1384 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1385 let the link point to the corresponding section.
1386 This function also handles the id links, if they have a match in
1387 the current file."
1388 (goto-char (point-min))
1389 (while (re-search-forward org-bracket-link-regexp nil t)
1390 (org-if-unprotected
1391 (let* ((md (match-data))
1392 (desc (match-end 2))
1393 (link (org-link-unescape (match-string 1)))
1394 (slink (org-solidify-link-text link))
1395 found props pos cref
1396 (target
1397 (cond
1398 ((= (string-to-char link) ?#)
1399 ;; user wants exactly this link
1400 link)
1401 ((cdr (assoc slink target-alist))
1402 (or (cdr (assoc (assoc slink target-alist)
1403 org-export-preferred-target-alist))
1404 (cdr (assoc slink target-alist))))
1405 ((and (string-match "^id:" link)
1406 (cdr (assoc (substring link 3) target-alist))))
1407 ((string-match "^(\\(.*\\))$" link)
1408 (setq cref (match-string 1 link))
1409 (concat "coderef:" cref))
1410 ((string-match org-link-types-re link) nil)
1411 ((or (file-name-absolute-p link)
1412 (string-match "^\\." link))
1413 nil)
1415 (save-excursion
1416 (setq found (condition-case nil (org-link-search link)
1417 (error nil)))
1418 (when (and found
1419 (or (org-on-heading-p)
1420 (not (eq found 'dedicated))))
1421 (or (get-text-property (point) 'target)
1422 (get-text-property
1423 (max (point-min)
1424 (1- (or (previous-single-property-change
1425 (point) 'target) 0)))
1426 'target))))))))
1427 (when target
1428 (set-match-data md)
1429 (goto-char (match-beginning 1))
1430 (setq props (text-properties-at (point)))
1431 (delete-region (match-beginning 1) (match-end 1))
1432 (setq pos (point))
1433 (insert target)
1434 (unless desc (insert "][" link))
1435 (add-text-properties pos (point) props))))))
1437 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1438 "Remove drawers, or extract the content.
1439 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1440 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1441 whose content to keep."
1442 (unless (eq t exp-drawers)
1443 (goto-char (point-min))
1444 (let ((re (concat "^[ \t]*:\\("
1445 (mapconcat
1446 'identity
1447 (org-delete-all exp-drawers
1448 (copy-sequence all-drawers))
1449 "\\|")
1450 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1451 (while (re-search-forward re nil t)
1452 (org-if-unprotected
1453 (replace-match ""))))))
1455 (defun org-export-handle-export-tags (select-tags exclude-tags)
1456 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1457 Both arguments are lists of tags.
1458 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1459 will be removed.
1460 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1461 removed as well."
1462 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1463 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1464 select-tags "\\|")
1465 "\\):"))
1466 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1467 exclude-tags "\\|")
1468 "\\):"))
1469 beg end cont)
1470 (goto-char (point-min))
1471 (when (and select-tags
1472 (re-search-forward
1473 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1474 ;; At least one tree is marked for export, this means
1475 ;; all the unmarked stuff needs to go.
1476 ;; Dig out the trees that should be exported
1477 (goto-char (point-min))
1478 (outline-next-heading)
1479 (setq beg (point))
1480 (put-text-property beg (point-max) :org-delete t)
1481 (while (re-search-forward re-sel nil t)
1482 (when (org-on-heading-p)
1483 (org-back-to-heading)
1484 (remove-text-properties
1485 (max (1- (point)) (point-min))
1486 (setq cont (save-excursion (org-end-of-subtree t t)))
1487 '(:org-delete t))
1488 (while (and (org-up-heading-safe)
1489 (get-text-property (point) :org-delete))
1490 (remove-text-properties (max (1- (point)) (point-min))
1491 (point-at-eol) '(:org-delete t)))
1492 (goto-char cont))))
1493 ;; Remove the trees explicitly marked for noexport
1494 (when exclude-tags
1495 (goto-char (point-min))
1496 (while (re-search-forward re-excl nil t)
1497 (when (org-at-heading-p)
1498 (org-back-to-heading t)
1499 (setq beg (point))
1500 (org-end-of-subtree t)
1501 (delete-region beg (point)))))
1502 ;; Remove everything that is now still marked for deletion
1503 (goto-char (point-min))
1504 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1505 (setq end (or (next-single-property-change beg :org-delete)
1506 (point-max)))
1507 (delete-region beg end))))
1509 (defun org-export-remove-archived-trees (export-archived-trees)
1510 "Remove archived trees.
1511 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1512 When it is t, the entire archived tree will be exported.
1513 When it is nil the entire tree including the headline will be removed
1514 from the buffer."
1515 (let ((re-archive (concat ":" org-archive-tag ":"))
1516 a b)
1517 (when (not (eq export-archived-trees t))
1518 (goto-char (point-min))
1519 (while (re-search-forward re-archive nil t)
1520 (if (not (org-on-heading-p t))
1521 (org-end-of-subtree t)
1522 (beginning-of-line 1)
1523 (setq a (if export-archived-trees
1524 (1+ (point-at-eol)) (point))
1525 b (org-end-of-subtree t))
1526 (if (> b a) (delete-region a b)))))))
1528 (defun org-export-remove-headline-metadata (opts)
1529 "Remove meta data from the headline, according to user options."
1530 (let ((re org-complex-heading-regexp)
1531 (todo (plist-get opts :todo-keywords))
1532 (tags (plist-get opts :tags))
1533 (pri (plist-get opts :priority))
1534 (elts '(1 2 3 4 5))
1535 rpl)
1536 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1537 (when (or (not todo) (not tags) (not pri))
1538 (goto-char (point-min))
1539 (while (re-search-forward re nil t)
1540 (org-if-unprotected
1541 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1542 elts " "))
1543 (replace-match rpl t t))))))
1545 (defun org-export-remove-timestamps ()
1546 "Remove timestamps and keywords for export."
1547 (goto-char (point-min))
1548 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1549 (backward-char 1)
1550 (org-if-unprotected
1551 (unless (save-match-data (org-at-table-p))
1552 (replace-match "")
1553 (beginning-of-line 1)
1554 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1555 (replace-match ""))))))
1557 (defun org-export-remove-clock-lines ()
1558 "Remove clock lines for export."
1559 (goto-char (point-min))
1560 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1561 (while (re-search-forward re nil t)
1562 (org-if-unprotected
1563 (replace-match "")))))
1565 (defun org-export-protect-quoted-subtrees ()
1566 "Mark quoted subtrees with the protection property."
1567 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1568 (goto-char (point-min))
1569 (while (re-search-forward re-quote nil t)
1570 (goto-char (match-beginning 0))
1571 (end-of-line 1)
1572 (add-text-properties (point) (org-end-of-subtree t)
1573 '(org-protected t)))))
1575 (defun org-export-protect-verbatim ()
1576 "Mark verbatim snippets with the protection property."
1577 (goto-char (point-min))
1578 (while (re-search-forward org-verbatim-re nil t)
1579 (add-text-properties (match-beginning 4) (match-end 4)
1580 '(org-protected t))
1581 (goto-char (1+ (match-end 4)))))
1583 (defun org-export-protect-colon-examples ()
1584 "Protect lines starting with a colon."
1585 (goto-char (point-min))
1586 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1587 (while (re-search-forward re nil t)
1588 (beginning-of-line 1)
1589 (setq beg (point))
1590 (while (looking-at re)
1591 (end-of-line 1)
1592 (or (eobp) (forward-char 1)))
1593 (add-text-properties beg (if (bolp) (1- (point)) (point))
1594 '(org-protected t)))))
1596 (defun org-export-select-backend-specific-text (backend)
1597 (let ((formatters
1598 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1599 (html "HTML" "BEGIN_HTML" "END_HTML")
1600 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1601 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1602 (case-fold-search t)
1603 fmt)
1605 (while formatters
1606 (setq fmt (pop formatters))
1607 (when (eq (car fmt) backend)
1608 ;; This is selected code, put it into the file for real
1609 (goto-char (point-min))
1610 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1611 ":[ \t]*\\(.*\\)") nil t)
1612 (replace-match "\\1" t)
1613 (add-text-properties
1614 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1615 '(org-protected t))))
1616 (goto-char (point-min))
1617 (while (re-search-forward
1618 (concat "^#\\+"
1619 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1620 (cadddr fmt) "\\>.*\n?") nil t)
1621 (if (eq (car fmt) backend)
1622 ;; yes, keep this
1623 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1624 '(org-protected t))
1625 ;; No, this is for a different backend, kill it
1626 (delete-region (match-beginning 0) (match-end 0)))))))
1628 (defun org-export-mark-blockquote-verse-center ()
1629 "Mark block quote and verse environments with special cookies.
1630 These special cookies will later be interpreted by the backend."
1631 ;; Blockquotes
1632 (goto-char (point-min))
1633 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1634 nil t)
1635 (replace-match (if (equal (downcase (match-string 1)) "end")
1636 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1637 t t))
1638 ;; Verse
1639 (goto-char (point-min))
1640 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1641 (replace-match (if (equal (downcase (match-string 1)) "end")
1642 "ORG-VERSE-END" "ORG-VERSE-START")
1643 t t))
1644 ;; Center
1645 (goto-char (point-min))
1646 (while (re-search-forward "^#\\+\\(begin\\|end\\)_center\\>.*" nil t)
1647 (replace-match (if (equal (downcase (match-string 1)) "end")
1648 "ORG-CENTER-END" "ORG-CENTER-START")
1649 t t)))
1651 (defun org-export-attach-captions-and-attributes (backend target-alist)
1652 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1653 If the next thing following is a table, add the text properties to the first
1654 table line. If it is a link, add it to the line containing the link."
1655 (goto-char (point-min))
1656 (remove-text-properties (point-min) (point-max)
1657 '(org-caption nil org-attributes nil))
1658 (let ((case-fold-search t)
1659 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1660 "\\|"
1661 "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1662 "\\|"
1663 "^#\\+label:[ \t]+\\(.*\\)"
1664 "\\|"
1665 "^[ \t]*|[^-]"
1666 "\\|"
1667 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1668 cap attr label)
1669 (while (re-search-forward re nil t)
1670 (cond
1671 ((match-end 1)
1672 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1673 ((match-end 2)
1674 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1675 ((match-end 3)
1676 (setq label (org-trim (match-string 3))))
1678 (add-text-properties (point-at-bol) (point-at-eol)
1679 (list 'org-caption cap
1680 'org-attributes attr
1681 'org-label label))
1682 (if label (push (cons label label) target-alist))
1683 (setq cap nil attr nil label nil)))))
1684 target-alist)
1686 (defun org-export-remove-comment-blocks-and-subtrees ()
1687 "Remove the comment environment, and also commented subtrees."
1688 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1689 (case-fold-search nil))
1690 ;; Remove comment environment
1691 (goto-char (point-min))
1692 (while (re-search-forward
1693 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1694 (replace-match "" t t))
1695 ;; Remove subtrees that are commented
1696 (goto-char (point-min))
1697 (while (re-search-forward re-commented nil t)
1698 (goto-char (match-beginning 0))
1699 (delete-region (point) (org-end-of-subtree t)))))
1701 (defun org-export-handle-comments (commentsp)
1702 "Remove comments, or convert to backend-specific format.
1703 COMMENTSP can be a format string for publishing comments.
1704 When it is nil, all comments will be removed."
1705 (let ((re "^#\\(.*\n?\\)")
1706 pos)
1707 (goto-char (point-min))
1708 (while (or (looking-at re)
1709 (re-search-forward re nil t))
1710 (setq pos (match-beginning 0))
1711 (if commentsp
1712 (progn (add-text-properties
1713 (match-beginning 0) (match-end 0) '(org-protected t))
1714 (replace-match (format commentsp (match-string 1)) t t))
1715 (goto-char (1+ pos))
1716 (org-if-unprotected
1717 (replace-match "")
1718 (goto-char (max (point-min) (1- pos))))))))
1720 (defun org-export-mark-radio-links ()
1721 "Find all matches for radio targets and turn them into internal links."
1722 (let ((re-radio (and org-target-link-regexp
1723 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1724 (goto-char (point-min))
1725 (when re-radio
1726 (while (re-search-forward re-radio nil t)
1727 (org-if-unprotected
1728 (replace-match "\\1[[\\2]]"))))))
1730 (defun org-export-remove-special-table-lines ()
1731 "Remove tables lines that are used for internal purposes."
1732 (goto-char (point-min))
1733 (while (re-search-forward "^[ \t]*|" nil t)
1734 (beginning-of-line 1)
1735 (if (or (looking-at "[ \t]*| *[!_^] *|")
1736 (and (looking-at ".*?| *<[0-9]+> *|")
1737 (not (looking-at ".*?| *[^ <|]"))))
1738 (delete-region (max (point-min) (1- (point-at-bol)))
1739 (point-at-eol))
1740 (end-of-line 1))))
1742 (defun org-export-normalize-links ()
1743 "Convert all links to bracket links, and expand link abbreviations."
1744 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1745 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1746 (goto-char (point-min))
1747 (while (re-search-forward re-plain-link nil t)
1748 (goto-char (1- (match-end 0)))
1749 (org-if-unprotected-at (1+ (match-beginning 0))
1750 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1751 ":" (match-string 3) "]]")))
1752 ;; added 'org-link face to links
1753 (put-text-property 0 (length s) 'face 'org-link s)
1754 (replace-match s t t))))
1755 (goto-char (point-min))
1756 (while (re-search-forward re-angle-link nil t)
1757 (goto-char (1- (match-end 0)))
1758 (org-if-unprotected
1759 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1760 ":" (match-string 3) "]]")))
1761 (put-text-property 0 (length s) 'face 'org-link s)
1762 (replace-match s t t))))
1763 (goto-char (point-min))
1764 (while (re-search-forward org-bracket-link-regexp nil t)
1765 (goto-char (1- (match-end 0)))
1766 (org-if-unprotected
1767 (let* ((xx (save-match-data
1768 (org-translate-link
1769 (org-link-expand-abbrev (match-string 1)))))
1770 (s (concat
1771 "[[" (org-add-props (copy-sequence xx)
1772 nil 'org-protected t)
1774 (if (match-end 3)
1775 (match-string 2)
1776 (concat "[" (org-add-props
1777 (copy-sequence xx)
1778 '(org-protected t))
1779 "]"))
1780 "]")))
1781 (put-text-property 0 (length s) 'face 'org-link s)
1782 (replace-match s t t))))))
1784 (defun org-export-concatenate-multiline-links ()
1785 "Find multi-line links and put it all into a single line.
1786 This is to make sure that the line-processing export backends
1787 can work correctly."
1788 (goto-char (point-min))
1789 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1790 (org-if-unprotected
1791 (replace-match "\\1 \\3")
1792 (goto-char (match-beginning 0)))))
1794 (defun org-export-concatenate-multiline-emphasis ()
1795 "Find multi-line emphasis and put it all into a single line.
1796 This is to make sure that the line-processing export backends
1797 can work correctly."
1798 (goto-char (point-min))
1799 (while (re-search-forward org-emph-re nil t)
1800 (if (and (not (= (char-after (match-beginning 3))
1801 (char-after (match-beginning 4))))
1802 (save-excursion (goto-char (match-beginning 0))
1803 (save-match-data (not (org-at-table-p)))))
1804 (org-if-unprotected
1805 (subst-char-in-region (match-beginning 0) (match-end 0)
1806 ?\n ?\ t)
1807 (goto-char (1- (match-end 0))))
1808 (goto-char (1+ (match-beginning 0))))))
1810 (defun org-export-grab-title-from-buffer ()
1811 "Get a title for the current document, from looking at the buffer."
1812 (let ((inhibit-read-only t))
1813 (save-excursion
1814 (goto-char (point-min))
1815 (let ((end (if (looking-at org-outline-regexp)
1816 (point)
1817 (save-excursion (outline-next-heading) (point)))))
1818 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1819 ;; Mark the line so that it will not be exported as normal text.
1820 (org-unmodified
1821 (add-text-properties (match-beginning 0) (match-end 0)
1822 (list :org-license-to-kill t)))
1823 ;; Return the title string
1824 (org-trim (match-string 0)))))))
1826 (defun org-export-get-title-from-subtree ()
1827 "Return subtree title and exclude it from export."
1828 (let (title (rbeg (region-beginning)) (rend (region-end)))
1829 (save-excursion
1830 (goto-char rbeg)
1831 (when (and (org-at-heading-p)
1832 (>= (org-end-of-subtree t t) rend))
1833 ;; This is a subtree, we take the title from the first heading
1834 (goto-char rbeg)
1835 (looking-at org-todo-line-regexp)
1836 (setq title (match-string 3))
1837 (org-unmodified
1838 (add-text-properties (point) (1+ (point-at-eol))
1839 (list :org-license-to-kill t)))
1840 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1841 title))
1843 (defun org-solidify-link-text (s &optional alist)
1844 "Take link text and make a safe target out of it."
1845 (save-match-data
1846 (let* ((rtn
1847 (mapconcat
1848 'identity
1849 (org-split-string s "[ \t\r\n]+") "=="))
1850 (a (assoc rtn alist)))
1851 (or (cdr a) rtn))))
1853 (defun org-get-min-level (lines &optional offset)
1854 "Get the minimum level in LINES."
1855 (let ((re "^\\(\\*+\\) ") l)
1856 (catch 'exit
1857 (while (setq l (pop lines))
1858 (if (string-match re l)
1859 (throw 'exit (org-tr-level (- (length (match-string 1 l))
1860 (or offset 0))))))
1861 1)))
1863 ;; Variable holding the vector with section numbers
1864 (defvar org-section-numbers (make-vector org-level-max 0))
1866 (defun org-init-section-numbers ()
1867 "Initialize the vector for the section numbers."
1868 (let* ((level -1)
1869 (numbers (nreverse (org-split-string "" "\\.")))
1870 (depth (1- (length org-section-numbers)))
1871 (i depth) number-string)
1872 (while (>= i 0)
1873 (if (> i level)
1874 (aset org-section-numbers i 0)
1875 (setq number-string (or (car numbers) "0"))
1876 (if (string-match "\\`[A-Z]\\'" number-string)
1877 (aset org-section-numbers i
1878 (- (string-to-char number-string) ?A -1))
1879 (aset org-section-numbers i (string-to-number number-string)))
1880 (pop numbers))
1881 (setq i (1- i)))))
1883 (defun org-section-number (&optional level)
1884 "Return a string with the current section number.
1885 When LEVEL is non-nil, increase section numbers on that level."
1886 (let* ((depth (1- (length org-section-numbers)))
1887 (string "")
1888 (fmts (car org-export-section-number-format))
1889 (term (cdr org-export-section-number-format))
1890 (sep "")
1891 ctype fmt idx n)
1892 (when level
1893 (when (> level -1)
1894 (aset org-section-numbers
1895 level (1+ (aref org-section-numbers level))))
1896 (setq idx (1+ level))
1897 (while (<= idx depth)
1898 (if (not (= idx 1))
1899 (aset org-section-numbers idx 0))
1900 (setq idx (1+ idx))))
1901 (setq idx 0)
1902 (while (<= idx depth)
1903 (when (> (aref org-section-numbers idx) 0)
1904 (setq fmt (or (pop fmts) fmt)
1905 ctype (car fmt)
1906 n (aref org-section-numbers idx)
1907 string (if (> n 0)
1908 (concat string sep (org-number-to-counter n ctype))
1909 (concat string ".0"))
1910 sep (nth 1 fmt)))
1911 (setq idx (1+ idx)))
1912 (save-match-data
1913 (if (string-match "\\`\\([@0]\\.\\)+" string)
1914 (setq string (replace-match "" t nil string)))
1915 (if (string-match "\\(\\.0\\)+\\'" string)
1916 (setq string (replace-match "" t nil string))))
1917 (concat string term)))
1919 (defun org-number-to-counter (n type)
1920 "Concert number N to a string counter, according to TYPE.
1921 TYPE must be a string, any of:
1922 1 number
1923 A A,B,....
1924 a a,b,....
1925 I upper case roman numeral
1926 i lower case roman numeral"
1927 (cond
1928 ((equal type "1") (number-to-string n))
1929 ((equal type "A") (char-to-string (+ ?A n -1)))
1930 ((equal type "a") (char-to-string (+ ?a n -1)))
1931 ((equal type "I") (org-number-to-roman n))
1932 ((equal type "i") (downcase (org-number-to-roman n)))
1933 (t (error "Invalid counter type `%s'" type))))
1935 (defun org-number-to-roman (n)
1936 "Convert integer N into a roman numeral."
1937 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1938 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1939 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1940 ( 1 . "I")))
1941 (res ""))
1942 (if (<= n 0)
1943 (number-to-string n)
1944 (while roman
1945 (if (>= n (caar roman))
1946 (setq n (- n (caar roman))
1947 res (concat res (cdar roman)))
1948 (pop roman)))
1949 res)))
1951 ;;; Macros
1953 (defun org-export-preprocess-apply-macros ()
1954 "Replace macro references."
1955 (goto-char (point-min))
1956 (let (sy val key)
1957 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t)
1958 (setq key (downcase (match-string 1)))
1959 (when (setq val (or (plist-get org-export-opt-plist
1960 (intern (concat ":macro-" key)))
1961 (plist-get org-export-opt-plist
1962 (intern (concat ":" key)))))
1963 (and (stringp val)
1964 (replace-match val t t))))))
1966 (defun org-export-apply-macros-in-string (s)
1967 "Apply the macros in string S."
1968 (when s
1969 (with-temp-buffer
1970 (insert s)
1971 (org-export-preprocess-apply-macros)
1972 (buffer-string))))
1974 ;;; Include files
1976 (defun org-export-handle-include-files ()
1977 "Include the contents of include files, with proper formatting."
1978 (let ((case-fold-search t)
1979 params file markup lang start end prefix prefix1 switches)
1980 (goto-char (point-min))
1981 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
1982 (setq params (read (concat "(" (match-string 1) ")"))
1983 prefix (org-get-and-remove-property 'params :prefix)
1984 prefix1 (org-get-and-remove-property 'params :prefix1)
1985 file (org-symname-or-string (pop params))
1986 markup (org-symname-or-string (pop params))
1987 lang (and (member markup '("src" "SRC"))
1988 (org-symname-or-string (pop params)))
1989 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
1990 (delete-region (match-beginning 0) (match-end 0))
1991 (if (or (not file)
1992 (not (file-exists-p file))
1993 (not (file-readable-p file)))
1994 (insert (format "CANNOT INCLUDE FILE %s" file))
1995 (when markup
1996 (if (equal (downcase markup) "src")
1997 (setq start (format "#+begin_src %s %s\n"
1998 (or lang "fundamental")
1999 (or switches ""))
2000 end "#+end_src")
2001 (setq start (format "#+begin_%s %s\n" markup switches)
2002 end (format "#+end_%s" markup))))
2003 (insert (or start ""))
2004 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2005 (or (bolp) (newline))
2006 (insert (or end ""))))))
2008 (defun org-get-file-contents (file &optional prefix prefix1)
2009 "Get the contents of FILE and return them as a string.
2010 If PREFIX is a string, prepend it to each line. If PREFIX1
2011 is a string, prepend it to the first line instead of PREFIX."
2012 (with-temp-buffer
2013 (insert-file-contents file)
2014 (when (or prefix prefix1)
2015 (goto-char (point-min))
2016 (while (not (eobp))
2017 (insert (or prefix1 prefix))
2018 (setq prefix1 nil)
2019 (beginning-of-line 2)))
2020 (buffer-string)))
2022 (defun org-get-and-remove-property (listvar prop)
2023 "Check if the value of LISTVAR contains PROP as a property.
2024 If yes, return the value of that property (i.e. the element following
2025 in the list) and remove property and value from the list in LISTVAR."
2026 (let ((list (symbol-value listvar)) m v)
2027 (when (setq m (member prop list))
2028 (setq v (nth 1 m))
2029 (if (equal (car list) prop)
2030 (set listvar (cddr list))
2031 (setcdr (nthcdr (- (length list) (length m) 1) list)
2032 (cddr m))
2033 (set listvar list)))
2036 (defun org-symname-or-string (s)
2037 (if (symbolp s)
2038 (if s (symbol-name s) s)
2041 ;;; Fontification and line numbers for code examples
2043 (defvar org-export-last-code-line-counter-value 0)
2045 (defun org-export-replace-src-segments-and-examples (backend)
2046 "Replace source code segments with special code for export."
2047 (setq org-export-last-code-line-counter-value 0)
2048 (let ((case-fold-search t)
2049 lang code trans opts)
2050 (goto-char (point-min))
2051 (while (re-search-forward
2052 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2053 nil t)
2054 (if (match-end 1)
2055 ;; src segments
2056 (setq lang (match-string 2)
2057 opts (match-string 3)
2058 code (match-string 4))
2059 (setq lang nil
2060 opts (match-string 6)
2061 code (match-string 7)))
2063 (setq trans (org-export-format-source-code-or-example
2064 backend lang code opts))
2065 (replace-match trans t t))))
2067 (defvar htmlp) ;; dynamically scoped
2068 (defvar latexp) ;; dynamically scoped
2070 (defun org-export-format-source-code-or-example (backend
2071 lang code &optional opts)
2072 "Format CODE from language LANG and return it formatted for export.
2073 If LANG is nil, do not add any fontification.
2074 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2075 and `+n' for continuing previous numering.
2076 Code formatting according to language currently only works for HTML.
2077 Numbering lines works for all three major backends (html, latex, and ascii)."
2078 (save-match-data
2079 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2080 (setq opts (or opts "")
2081 num (string-match "[-+]n\\>" opts)
2082 cont (string-match "\\+n\\>" opts)
2083 rpllbl (string-match "-r\\>" opts)
2084 keepp (string-match "-k\\>" opts)
2085 textareap (string-match "-t\\>" opts)
2086 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2087 (string-to-number (match-string 1 opts))
2089 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2090 (string-to-number (match-string 1 opts))
2091 (org-count-lines code))
2092 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2093 (match-string 1 opts)))
2094 (when (and textareap (eq backend 'html))
2095 ;; we cannot use numbering or highlighting.
2096 (setq num nil cont nil lang nil))
2097 (if keepp (setq rpllbl 'keep))
2098 (setq rtn code)
2099 (when (equal lang "org")
2100 (setq rtn (with-temp-buffer
2101 (insert rtn)
2102 ;; Free up the protected lines
2103 (goto-char (point-min))
2104 (while (re-search-forward "^," nil t)
2105 (replace-match "")
2106 (end-of-line 1))
2107 (buffer-string))))
2108 ;; Now backend-specific coding
2109 (cond
2110 ((eq backend 'docbook)
2111 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2112 (concat "\n#+BEGIN_DOCBOOK\n"
2113 (org-add-props (concat "<programlisting><![CDATA["
2115 "]]>\n</programlisting>\n")
2116 '(org-protected t))
2117 "#+END_DOCBOOK\n"))
2118 ((eq backend 'html)
2119 ;; We are exporting to HTML
2120 (when lang
2121 (require 'htmlize nil t)
2122 (when (not (fboundp 'htmlize-region-for-paste))
2123 ;; we do not have htmlize.el, or an old version of it
2124 (setq lang nil)
2125 (message
2126 "htmlize.el 1.34 or later is needed for source code formatting")))
2128 (if lang
2129 (let* ((mode (and lang (intern (concat lang "-mode"))))
2130 (org-inhibit-startup t)
2131 (org-startup-folded nil))
2132 (setq rtn
2133 (with-temp-buffer
2134 (insert rtn)
2135 (if (functionp mode)
2136 (funcall mode)
2137 (fundamental-mode))
2138 (font-lock-fontify-buffer)
2139 (set-buffer-modified-p nil)
2140 (org-export-htmlize-region-for-paste
2141 (point-min) (point-max))))
2142 (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
2143 (setq rtn (replace-match
2144 (format "<pre class=\"src src-%s\">\n" lang)
2145 t t rtn))))
2146 (if textareap
2147 (setq rtn (concat
2148 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2149 cols rows)
2150 rtn "</textarea>\n</p>\n"))
2151 (with-temp-buffer
2152 (insert rtn)
2153 (goto-char (point-min))
2154 (while (re-search-forward "[<>&]" nil t)
2155 (replace-match (cdr (assq (char-before)
2156 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2157 t t))
2158 (setq rtn (buffer-string)))
2159 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2160 (unless textareap
2161 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2162 cont rpllbl fmt)))
2163 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2164 ((eq backend 'latex)
2165 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2166 (concat "\n#+BEGIN_LaTeX\n"
2167 (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
2168 '(org-protected t))
2169 "#+END_LaTeX\n\n"))
2170 ((eq backend 'ascii)
2171 ;; This is not HTML or LaTeX, so just make it an example.
2172 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2173 (concat "#+BEGIN_ASCII\n"
2174 (org-add-props
2175 (concat
2176 (mapconcat
2177 (lambda (l) (concat " " l))
2178 (org-split-string rtn "\n")
2179 "\n")
2180 "\n")
2181 '(org-protected t))
2182 "#+END_ASCII\n"))))))
2184 (defun org-export-number-lines (text backend
2185 &optional skip1 skip2 number cont
2186 replace-labels label-format)
2187 (if (and (not number) (not (eq replace-labels 'keep)))
2188 (setq replace-labels nil)) ;; must use names if no numbers
2189 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2190 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2191 (with-temp-buffer
2192 (insert text)
2193 (goto-char (point-max))
2194 (skip-chars-backward " \t\n\r")
2195 (delete-region (point) (point-max))
2196 (beginning-of-line (- 1 skip2))
2197 (let* ((last (org-current-line))
2198 (n org-export-last-code-line-counter-value)
2199 (nmax (+ n (- last skip1)))
2200 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2202 (cond
2203 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2204 fmt))
2205 ((eq backend 'ascii) fmt)
2206 ((eq backend 'latex) fmt)
2207 ((eq backend 'docbook) fmt)
2208 (t "")))
2209 (label-format (or label-format org-coderef-label-format))
2210 (label-pre (if (string-match "%s" label-format)
2211 (substring label-format 0 (match-beginning 0))
2212 label-format))
2213 (label-post (if (string-match "%s" label-format)
2214 (substring label-format (match-end 0))
2215 ""))
2216 (lbl-re
2217 (concat
2218 ".*?\\S-.*?\\([ \t]*\\("
2219 (regexp-quote label-pre)
2220 "\\([-a-zA-Z0-9_]+\\)"
2221 (regexp-quote label-post)
2222 "\\)\\)"))
2223 ref)
2225 (goto-line (1+ skip1))
2226 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2227 (if number
2228 (insert (format fm (incf n)))
2229 (forward-char 1))
2230 (when (and (not (eq replace-labels 'keep))
2231 (looking-at lbl-re))
2232 (setq ref (match-string 3))
2233 (if replace-labels
2234 (progn
2235 (delete-region (match-beginning 1) (match-end 1))
2236 (push (cons ref n) org-export-code-refs))
2237 (goto-char (match-beginning 2))
2238 (delete-region (match-beginning 2) (match-end 2))
2239 (insert "(" ref ")")
2240 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2241 (when (eq backend 'html)
2242 (save-excursion
2243 (beginning-of-line 1)
2244 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2245 ref))
2246 (end-of-line 1)
2247 (insert "</span>")))))
2248 (setq org-export-last-code-line-counter-value n)
2249 (goto-char (point-max))
2250 (newline)
2251 (buffer-string))))
2253 (defun org-search-todo-below (line lines level)
2254 "Search the subtree below LINE for any TODO entries."
2255 (let ((rest (cdr (memq line lines)))
2256 (re org-todo-line-regexp)
2257 line lv todo)
2258 (catch 'exit
2259 (while (setq line (pop rest))
2260 (if (string-match re line)
2261 (progn
2262 (setq lv (- (match-end 1) (match-beginning 1))
2263 todo (and (match-beginning 2)
2264 (not (member (match-string 2 line)
2265 org-done-keywords))))
2266 ; TODO, not DONE
2267 (if (<= lv level) (throw 'exit nil))
2268 (if todo (throw 'exit t))))))))
2270 ;;;###autoload
2271 (defun org-export-visible (type arg)
2272 "Create a copy of the visible part of the current buffer, and export it.
2273 The copy is created in a temporary buffer and removed after use.
2274 TYPE is the final key (as a string) that also select the export command in
2275 the `C-c C-e' export dispatcher.
2276 As a special case, if the you type SPC at the prompt, the temporary
2277 org-mode file will not be removed but presented to you so that you can
2278 continue to use it. The prefix arg ARG is passed through to the exporting
2279 command."
2280 (interactive
2281 (list (progn
2282 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2283 (read-char-exclusive))
2284 current-prefix-arg))
2285 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
2286 (error "Invalid export key"))
2287 (let* ((binding (cdr (assoc type
2288 '((?a . org-export-as-ascii)
2289 (?\C-a . org-export-as-ascii)
2290 (?b . org-export-as-html-and-open)
2291 (?\C-b . org-export-as-html-and-open)
2292 (?h . org-export-as-html)
2293 (?H . org-export-as-html-to-buffer)
2294 (?R . org-export-region-as-html)
2295 (?D . org-export-as-docbook)
2296 (?x . org-export-as-xoxo)))))
2297 (keepp (equal type ?\ ))
2298 (file buffer-file-name)
2299 (buffer (get-buffer-create "*Org Export Visible*"))
2300 s e)
2301 ;; Need to hack the drawers here.
2302 (save-excursion
2303 (goto-char (point-min))
2304 (while (re-search-forward org-drawer-regexp nil t)
2305 (goto-char (match-beginning 1))
2306 (or (org-invisible-p) (org-flag-drawer nil))))
2307 (with-current-buffer buffer (erase-buffer))
2308 (save-excursion
2309 (setq s (goto-char (point-min)))
2310 (while (not (= (point) (point-max)))
2311 (goto-char (org-find-invisible))
2312 (append-to-buffer buffer s (point))
2313 (setq s (goto-char (org-find-visible))))
2314 (org-cycle-hide-drawers 'all)
2315 (goto-char (point-min))
2316 (unless keepp
2317 ;; Copy all comment lines to the end, to make sure #+ settings are
2318 ;; still available for the second export step. Kind of a hack, but
2319 ;; does do the trick.
2320 (if (looking-at "#[^\r\n]*")
2321 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2322 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2323 (append-to-buffer buffer (1+ (match-beginning 0))
2324 (min (point-max) (1+ (match-end 0))))))
2325 (set-buffer buffer)
2326 (let ((buffer-file-name file)
2327 (org-inhibit-startup t))
2328 (org-mode)
2329 (show-all)
2330 (unless keepp (funcall binding arg))))
2331 (if (not keepp)
2332 (kill-buffer buffer)
2333 (switch-to-buffer-other-window buffer)
2334 (goto-char (point-min)))))
2336 (defun org-find-visible ()
2337 (let ((s (point)))
2338 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2339 (get-char-property s 'invisible)))
2341 (defun org-find-invisible ()
2342 (let ((s (point)))
2343 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2344 (not (get-char-property s 'invisible))))
2347 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2348 (defun org-get-current-options ()
2349 "Return a string with current options as keyword options.
2350 Does include HTML export options as well as TODO and CATEGORY stuff."
2351 (require 'org-archive)
2352 (format
2353 "#+TITLE: %s
2354 #+AUTHOR: %s
2355 #+EMAIL: %s
2356 #+DATE: %s
2357 #+DESCRIPTION:
2358 #+KEYWORDS:
2359 #+LANGUAGE: %s
2360 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2361 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2363 #+EXPORT_SELECT_TAGS: %s
2364 #+EXPORT_EXCLUDE_TAGS: %s
2365 #+LINK_UP: %s
2366 #+LINK_HOME: %s
2367 #+CATEGORY: %s
2368 #+SEQ_TODO: %s
2369 #+TYP_TODO: %s
2370 #+PRIORITIES: %c %c %c
2371 #+DRAWERS: %s
2372 #+STARTUP: %s %s %s %s %s
2373 #+TAGS: %s
2374 #+FILETAGS: %s
2375 #+ARCHIVE: %s
2376 #+LINK: %s
2378 (buffer-name) (user-full-name) user-mail-address
2379 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2380 org-export-default-language
2381 org-export-headline-levels
2382 org-export-with-section-numbers
2383 org-export-with-toc
2384 org-export-preserve-breaks
2385 org-export-html-expand
2386 org-export-with-fixed-width
2387 org-export-with-tables
2388 org-export-with-sub-superscripts
2389 org-export-with-special-strings
2390 org-export-with-footnotes
2391 org-export-with-emphasize
2392 org-export-with-timestamps
2393 org-export-with-TeX-macros
2394 org-export-with-LaTeX-fragments
2395 org-export-skip-text-before-1st-heading
2396 org-export-with-drawers
2397 org-export-with-todo-keywords
2398 org-export-with-priority
2399 org-export-with-tags
2400 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2401 (mapconcat 'identity org-export-select-tags " ")
2402 (mapconcat 'identity org-export-exclude-tags " ")
2403 org-export-html-link-up
2404 org-export-html-link-home
2405 (or (ignore-errors
2406 (file-name-sans-extension
2407 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2408 "NOFILENAME")
2409 "TODO FEEDBACK VERIFY DONE"
2410 "Me Jason Marie DONE"
2411 org-highest-priority org-lowest-priority org-default-priority
2412 (mapconcat 'identity org-drawers " ")
2413 (cdr (assoc org-startup-folded
2414 '((nil . "showall") (t . "overview") (content . "content"))))
2415 (if org-odd-levels-only "odd" "oddeven")
2416 (if org-hide-leading-stars "hidestars" "showstars")
2417 (if org-startup-align-all-tables "align" "noalign")
2418 (cond ((eq org-log-done t) "logdone")
2419 ((equal org-log-done 'note) "lognotedone")
2420 ((not org-log-done) "nologdone"))
2421 (or (mapconcat (lambda (x)
2422 (cond
2423 ((equal '(:startgroup) x) "{")
2424 ((equal '(:endgroup) x) "}")
2425 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2426 (t (car x))))
2427 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2428 (mapconcat 'identity org-file-tags " ")
2429 org-archive-location
2430 "org file:~/org/%s.org"
2433 ;;;###autoload
2434 (defun org-insert-export-options-template ()
2435 "Insert into the buffer a template with information for exporting."
2436 (interactive)
2437 (if (not (bolp)) (newline))
2438 (let ((s (org-get-current-options)))
2439 (and (string-match "#\\+CATEGORY" s)
2440 (setq s (substring s 0 (match-beginning 0))))
2441 (insert s)))
2443 (defvar org-table-colgroup-info nil)
2445 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2446 "Check if the table has a marking column.
2447 If yes remove the column and the special lines."
2448 (setq org-table-colgroup-info nil)
2449 (if (memq nil
2450 (mapcar
2451 (lambda (x) (or (string-match "^[ \t]*|-" x)
2452 (string-match
2453 (if maybe-quoted
2454 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2455 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2456 x)))
2457 lines))
2458 (progn
2459 (setq org-table-clean-did-remove-column nil)
2460 (delq nil
2461 (mapcar
2462 (lambda (x)
2463 (cond
2464 ((string-match "^[ \t]*| */ *|" x)
2465 (setq org-table-colgroup-info
2466 (mapcar (lambda (x)
2467 (cond ((member x '("<" "&lt;")) :start)
2468 ((member x '(">" "&gt;")) :end)
2469 ((member x '("<>" "&lt;&gt;")) :startend)
2470 (t nil)))
2471 (org-split-string x "[ \t]*|[ \t]*")))
2472 nil)
2473 (t x)))
2474 lines)))
2475 (setq org-table-clean-did-remove-column t)
2476 (delq nil
2477 (mapcar
2478 (lambda (x)
2479 (cond
2480 ((string-match "^[ \t]*| */ *|" x)
2481 (setq org-table-colgroup-info
2482 (mapcar (lambda (x)
2483 (cond ((member x '("<" "&lt;")) :start)
2484 ((member x '(">" "&gt;")) :end)
2485 ((member x '("<>" "&lt;&gt;")) :startend)
2486 (t nil)))
2487 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2488 nil)
2489 ((string-match "^[ \t]*| *[!_^/] *|" x)
2490 nil) ; ignore this line
2491 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2492 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2493 ;; remove the first column
2494 (replace-match "\\1|" t nil x))))
2495 lines))))
2497 (defun org-export-cleanup-toc-line (s)
2498 "Remove tags and timestamps from lines going into the toc."
2499 (when (memq org-export-with-tags '(not-in-toc nil))
2500 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2501 (setq s (replace-match "" t t s))))
2502 (when org-export-remove-timestamps-from-toc
2503 (while (string-match org-maybe-keyword-time-regexp s)
2504 (setq s (replace-match "" t t s))))
2505 (while (string-match org-bracket-link-regexp s)
2506 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2507 t t s)))
2510 (defun org-create-multibrace-regexp (left right n)
2511 "Create a regular expression which will match a balanced sexp.
2512 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2513 as single character strings.
2514 The regexp returned will match the entire expression including the
2515 delimiters. It will also define a single group which contains the
2516 match except for the outermost delimiters. The maximum depth of
2517 stacked delimiters is N. Escaping delimiters is not possible."
2518 (let* ((nothing (concat "[^" left right "]*?"))
2519 (or "\\|")
2520 (re nothing)
2521 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
2522 (while (> n 1)
2523 (setq n (1- n)
2524 re (concat re or next)
2525 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
2526 (concat left "\\(" re "\\)" right)))
2528 (defvar org-match-substring-regexp
2529 (concat
2530 "\\([^\\]\\)\\([_^]\\)\\("
2531 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2532 "\\|"
2533 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
2534 "\\|"
2535 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2536 "The regular expression matching a sub- or superscript.")
2538 (defvar org-match-substring-with-braces-regexp
2539 (concat
2540 "\\([^\\]\\)\\([_^]\\)\\("
2541 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2542 "\\)")
2543 "The regular expression matching a sub- or superscript, forcing braces.")
2546 (defun org-get-text-property-any (pos prop &optional object)
2547 (or (get-text-property pos prop object)
2548 (and (setq pos (next-single-property-change pos prop object))
2549 (get-text-property pos prop object))))
2551 (defun org-export-get-coderef-format (path desc)
2552 (save-match-data
2553 (if (and desc (string-match
2554 (regexp-quote (concat "(" path ")"))
2555 desc))
2556 (replace-match "%s" t t desc)
2557 "%s")))
2559 (provide 'org-exp)
2561 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2563 ;;; org-exp.el ends here