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