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