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