org-agenda-append-agenda: check that we are in an agenda buffer.
[org-mode/org-mode-NeilSmithlineMods.git] / lisp / org-exp.el
blob4adc81ab295b4a174dc5a86a8c135badd32744be
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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: 7.4
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 ;;; Code:
31 (require 'org)
32 (require 'org-macs)
33 (require 'org-agenda)
34 (require 'org-exp-blocks)
35 (require 'ob-exp)
36 (require 'org-src)
38 (eval-when-compile
39 (require 'cl))
41 (declare-function org-export-latex-preprocess "org-latex" (parameters))
42 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
43 (declare-function org-export-html-preprocess "org-html" (parameters))
44 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
45 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
46 (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
47 (declare-function htmlize-buffer "ext:htmlize" (&optional buffer))
48 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
49 (declare-function org-table-cookie-line-p "org-table" (line))
50 (declare-function org-table-colgroup-line-p "org-table" (line))
51 (autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
52 (defgroup org-export nil
53 "Options for exporting org-listings."
54 :tag "Org Export"
55 :group 'org)
57 (defgroup org-export-general nil
58 "General options for exporting Org-mode files."
59 :tag "Org Export General"
60 :group 'org-export)
62 (defcustom org-export-allow-BIND 'confirm
63 "Non-nil means allow #+BIND to define local variable values for export.
64 This is a potential security risk, which is why the user must confirm the
65 use of these lines."
66 :group 'org-export-general
67 :type '(choice
68 (const :tag "Never" nil)
69 (const :tag "Always" t)
70 (const :tag "Make the user confirm for each file" confirm)))
72 ;; FIXME
73 (defvar org-export-publishing-directory nil)
75 (defcustom org-export-show-temporary-export-buffer t
76 "Non-nil means show buffer after exporting to temp buffer.
77 When Org exports to a file, the buffer visiting that file is ever
78 shown, but remains buried. However, when exporting to a temporary
79 buffer, that buffer is popped up in a second window. When this variable
80 is nil, the buffer remains buried also in these cases."
81 :group 'org-export-general
82 :type 'boolean)
84 (defcustom org-export-copy-to-kill-ring t
85 "Non-nil means exported stuff will also be pushed onto the kill ring."
86 :group 'org-export-general
87 :type 'boolean)
89 (defcustom org-export-kill-product-buffer-when-displayed nil
90 "Non-nil means kill the product buffer if it is displayed immediately.
91 This applied to the commands `org-export-html-and-open' and
92 `org-export-as-pdf-and-open'."
93 :group 'org-export-general
94 :type 'boolean)
96 (defcustom org-export-run-in-background nil
97 "Non-nil means export and publishing commands will run in background.
98 This works by starting up a separate Emacs process visiting the same file
99 and doing the export from there.
100 Not all export commands are affected by this - only the ones which
101 actually write to a file, and that do not depend on the buffer state.
102 \\<org-mode-map>
103 If this option is nil, you can still get background export by calling
104 `org-export' with a double prefix arg: \
105 \\[universal-argument] \\[universal-argument] \\[org-export].
107 If this option is t, the double prefix can be used to exceptionally
108 force an export command into the current process."
109 :group 'org-export-general
110 :type 'boolean)
112 (defcustom org-export-initial-scope 'buffer
113 "The initial scope when exporting with `org-export'.
114 This variable can be either set to 'buffer or 'subtree."
115 :group 'org-export-general
116 :type '(choice
117 (const :tag "Export current buffer" 'buffer)
118 (const :tag "Export current subtree" 'subtree)))
120 (defcustom org-export-select-tags '("export")
121 "Tags that select a tree for export.
122 If any such tag is found in a buffer, all trees that do not carry one
123 of these tags will be deleted before export.
124 Inside trees that are selected like this, you can still deselect a
125 subtree by tagging it with one of the `org-export-exclude-tags'."
126 :group 'org-export-general
127 :type '(repeat (string :tag "Tag")))
129 (defcustom org-export-exclude-tags '("noexport")
130 "Tags that exclude a tree from export.
131 All trees carrying any of these tags will be excluded from export.
132 This is without condition, so even subtrees inside that carry one of the
133 `org-export-select-tags' will be removed."
134 :group 'org-export-general
135 :type '(repeat (string :tag "Tag")))
137 ;; FIXME: rename, this is a general variable
138 (defcustom org-export-html-expand t
139 "Non-nil means for HTML export, treat @<...> as HTML tag.
140 When nil, these tags will be exported as plain text and therefore
141 not be interpreted by a browser.
143 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
144 :group 'org-export-html
145 :group 'org-export-general
146 :type 'boolean)
148 (defcustom org-export-with-special-strings t
149 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
150 When this option is turned on, these strings will be exported as:
152 Org HTML LaTeX
153 -----+----------+--------
154 \\- &shy; \\-
155 -- &ndash; --
156 --- &mdash; ---
157 ... &hellip; \ldots
159 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
160 :group 'org-export-translation
161 :type 'boolean)
163 (defcustom org-export-html-link-up ""
164 "Where should the \"UP\" link of exported HTML pages lead?"
165 :group 'org-export-html
166 :group 'org-export-general
167 :type '(string :tag "File or URL"))
169 (defcustom org-export-html-link-home ""
170 "Where should the \"HOME\" link of exported HTML pages lead?"
171 :group 'org-export-html
172 :group 'org-export-general
173 :type '(string :tag "File or URL"))
175 (defcustom org-export-language-setup
176 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
177 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
178 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
179 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
180 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
181 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
182 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
183 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
184 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
185 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
186 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
187 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
188 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
189 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
190 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
191 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
192 ("pl" "Autor" "Data" "Spis tre&#x015b;ci" "Przypis")
193 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
194 "Terms used in export text, translated to different languages.
195 Use the variable `org-export-default-language' to set the language,
196 or use the +OPTION lines for a per-file setting."
197 :group 'org-export-general
198 :type '(repeat
199 (list
200 (string :tag "HTML language tag")
201 (string :tag "Author")
202 (string :tag "Date")
203 (string :tag "Table of Contents")
204 (string :tag "Footnotes"))))
206 (defcustom org-export-default-language "en"
207 "The default language for export and clocktable translations, as a string.
208 This should have an association in `org-export-language-setup'
209 and in `org-clock-clocktable-language-setup'."
210 :group 'org-export-general
211 :type 'string)
213 (defvar org-export-page-description ""
214 "The page description, for the XHTML meta tag.
215 This is best set with the #+DESCRIPTION line in a file, it does not make
216 sense to set this globally.")
218 (defvar org-export-page-keywords ""
219 "The page description, for the XHTML meta tag.
220 This is best set with the #+KEYWORDS line in a file, it does not make
221 sense to set this globally.")
223 (defcustom org-export-skip-text-before-1st-heading nil
224 "Non-nil means skip all text before the first headline when exporting.
225 When nil, that text is exported as well."
226 :group 'org-export-general
227 :type 'boolean)
229 (defcustom org-export-headline-levels 3
230 "The last level which is still exported as a headline.
231 Inferior levels will produce itemize lists when exported.
232 Note that a numeric prefix argument to an exporter function overrides
233 this setting.
235 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
236 :group 'org-export-general
237 :type 'integer)
239 (defcustom org-export-with-section-numbers t
240 "Non-nil means add section numbers to headlines when exporting.
242 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
243 :group 'org-export-general
244 :type 'boolean)
246 (defcustom org-export-section-number-format '((("1" ".")) . "")
247 "Format of section numbers for export.
248 The variable has two components.
249 1. A list of lists, each indicating a counter type and a separator.
250 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
251 It causes causes numeric, alphabetic, or roman counters, respectively.
252 The separator is only used if another counter for a subsection is being
253 added.
254 If there are more numbered section levels than entries in this lists,
255 then the last entry will be reused.
256 2. A terminator string that will be added after the entire
257 section number."
258 :group 'org-export-general
259 :type '(cons
260 (repeat
261 (list
262 (string :tag "Counter Type")
263 (string :tag "Separator ")))
264 (string :tag "Terminator")))
266 (defcustom org-export-with-toc t
267 "Non-nil means create a table of contents in exported files.
268 The TOC contains headlines with levels up to`org-export-headline-levels'.
269 When an integer, include levels up to N in the toc, this may then be
270 different from `org-export-headline-levels', but it will not be allowed
271 to be larger than the number of headline levels.
272 When nil, no table of contents is made.
274 Headlines which contain any TODO items will be marked with \"(*)\" in
275 ASCII export, and with red color in HTML output, if the option
276 `org-export-mark-todo-in-toc' is set.
278 In HTML output, the TOC will be clickable.
280 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
281 or \"toc:3\"."
282 :group 'org-export-general
283 :type '(choice
284 (const :tag "No Table of Contents" nil)
285 (const :tag "Full Table of Contents" t)
286 (integer :tag "TOC to level")))
288 (defcustom org-export-mark-todo-in-toc nil
289 "Non-nil means mark TOC lines that contain any open TODO items."
290 :group 'org-export-general
291 :type 'boolean)
293 (defcustom org-export-with-todo-keywords t
294 "Non-nil means include TODO keywords in export.
295 When nil, remove all these keywords from the export."
296 :group 'org-export-general
297 :type 'boolean)
299 (defcustom org-export-with-priority nil
300 "Non-nil means include priority cookies in export.
301 When nil, remove priority cookies for export."
302 :group 'org-export-general
303 :type 'boolean)
305 (defcustom org-export-preserve-breaks nil
306 "Non-nil means preserve all line breaks when exporting.
307 Normally, in HTML output paragraphs will be reformatted. In ASCII
308 export, line breaks will always be preserved, regardless of this variable.
310 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
311 :group 'org-export-general
312 :type 'boolean)
314 (defcustom org-export-with-archived-trees 'headline
315 "Whether subtrees with the ARCHIVE tag should be exported.
316 This can have three different values
317 nil Do not export, pretend this tree is not present
318 t Do export the entire tree
319 headline Only export the headline, but skip the tree below it."
320 :group 'org-export-general
321 :group 'org-archive
322 :type '(choice
323 (const :tag "not at all" nil)
324 (const :tag "headline only" 'headline)
325 (const :tag "entirely" t)))
327 (defcustom org-export-author-info t
328 "Non-nil means insert author name and email into the exported file.
330 This option can also be set with the +OPTIONS line,
331 e.g. \"author:nil\"."
332 :group 'org-export-general
333 :type 'boolean)
335 (defcustom org-export-email-info nil
336 "Non-nil means insert author name and email into the exported file.
338 This option can also be set with the +OPTIONS line,
339 e.g. \"email:t\"."
340 :group 'org-export-general
341 :type 'boolean)
343 (defcustom org-export-creator-info t
344 "Non-nil means the postamble should contain a creator sentence.
345 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
346 :group 'org-export-general
347 :type 'boolean)
349 (defcustom org-export-time-stamp-file t
350 "Non-nil means insert a time stamp into the exported file.
351 The time stamp shows when the file was created.
353 This option can also be set with the +OPTIONS line,
354 e.g. \"timestamp:nil\"."
355 :group 'org-export-general
356 :type 'boolean)
358 (defcustom org-export-with-timestamps t
359 "If nil, do not export time stamps and associated keywords."
360 :group 'org-export-general
361 :type 'boolean)
363 (defcustom org-export-remove-timestamps-from-toc t
364 "If t, remove timestamps from the table of contents entries."
365 :group 'org-export-general
366 :type 'boolean)
368 (defcustom org-export-with-tags 'not-in-toc
369 "If nil, do not export tags, just remove them from headlines.
370 If this is the symbol `not-in-toc', tags will be removed from table of
371 contents entries, but still be shown in the headlines of the document.
373 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
374 :group 'org-export-general
375 :type '(choice
376 (const :tag "Off" nil)
377 (const :tag "Not in TOC" not-in-toc)
378 (const :tag "On" t)))
380 (defcustom org-export-with-drawers nil
381 "Non-nil means export with drawers like the property drawer.
382 When t, all drawers are exported. This may also be a list of
383 drawer names to export."
384 :group 'org-export-general
385 :type '(choice
386 (const :tag "All drawers" t)
387 (const :tag "None" nil)
388 (repeat :tag "Selected drawers"
389 (string :tag "Drawer name"))))
391 (defvar org-export-first-hook nil
392 "Hook called as the first thing in each exporter.
393 Point will be still in the original buffer.
394 Good for general initialization")
396 (defvar org-export-preprocess-hook nil
397 "Hook for preprocessing an export buffer.
398 Pretty much the first thing when exporting is running this hook.
399 Point will be in a temporary buffer that contains a copy of
400 the original buffer, or of the section that is being exported.
401 All the other hooks in the org-export-preprocess... category
402 also work in that temporary buffer, already modified by various
403 stages of the processing.")
405 (defvar org-export-preprocess-after-include-files-hook nil
406 "Hook for preprocessing an export buffer.
407 This is run after the contents of included files have been inserted.")
409 (defvar org-export-preprocess-after-tree-selection-hook nil
410 "Hook for preprocessing an export buffer.
411 This is run after selection of trees to be exported has happened.
412 This selection includes tags-based selection, as well as removal
413 of commented and archived trees.")
415 (defvar org-export-preprocess-after-headline-targets-hook nil
416 "Hook for preprocessing export buffer.
417 This is run just after the headline targets have been defined and
418 the target-alist has been set up.")
420 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
421 "Hook for preprocessing an export buffer.
422 This is run just before backend-specific blocks get selected.")
424 (defvar org-export-preprocess-after-blockquote-hook nil
425 "Hook for preprocessing an export buffer.
426 This is run after blockquote/quote/verse/center have been marked
427 with cookies.")
429 (defvar org-export-preprocess-after-radio-targets-hook nil
430 "Hook for preprocessing an export buffer.
431 This is run after radio target processing.")
433 (defvar org-export-preprocess-before-normalizing-links-hook nil
434 "Hook for preprocessing an export buffer.
435 This hook is run before links are normalized.")
437 (defvar org-export-preprocess-before-backend-specifics-hook nil
438 "Hook run before backend-specific functions are called during preprocessing.")
440 (defvar org-export-preprocess-final-hook nil
441 "Hook for preprocessing an export buffer.
442 This is run as the last thing in the preprocessing buffer, just before
443 returning the buffer string to the backend.")
445 (defgroup org-export-translation nil
446 "Options for translating special ascii sequences for the export backends."
447 :tag "Org Export Translation"
448 :group 'org-export)
450 (defcustom org-export-with-emphasize t
451 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
452 If the export target supports emphasizing text, the word will be
453 typeset in bold, italic, or underlined, respectively. Works only for
454 single words, but you can say: I *really* *mean* *this*.
455 Not all export backends support this.
457 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
458 :group 'org-export-translation
459 :type 'boolean)
461 (defcustom org-export-with-footnotes t
462 "If nil, export [1] as a footnote marker.
463 Lines starting with [1] will be formatted as footnotes.
465 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
466 :group 'org-export-translation
467 :type 'boolean)
469 (defcustom org-export-with-TeX-macros t
470 "Non-nil means interpret simple TeX-like macros when exporting.
471 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
472 Not only real TeX macros will work here, but the standard HTML entities
473 for math can be used as macro names as well. For a list of supported
474 names in HTML export, see the constant `org-entities' and the user option
475 `org-entities-user'.
476 Not all export backends support this.
478 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
479 :group 'org-export-translation
480 :group 'org-export-latex
481 :type 'boolean)
483 (defcustom org-export-with-LaTeX-fragments t
484 "Non-nil means process LaTeX math fragments for HTML display.
485 When set, the exporter will find and process LaTeX environments if the
486 \\begin line is the first non-white thing on a line. It will also find
487 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
488 $$a=b$$ and \\=\\[ a=b \\] for display math.
490 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
492 Allowed values are:
494 nil Don't do anything.
495 verbatim Keep everything in verbatim
496 dvipng Process the LaTeX fragments to images.
497 This will also include processing of non-math environments.
498 t Do MathJax preprocessing if there is at least on math snippet,
499 and arrange for MathJax.js to be loaded.
501 The default is nil, because this option needs the `dvipng' program which
502 is not available on all systems."
503 :group 'org-export-translation
504 :group 'org-export-latex
505 :type '(choice
506 (const :tag "Do not process math in any way" nil)
507 (const :tag "Obsolete, use dvipng setting" t)
508 (const :tag "Use dvipng to make images" dvipng)
509 (const :tag "Use MathJax to display math" mathjax)
510 (const :tag "Leave math verbatim" verbatim)))
512 (defcustom org-export-with-fixed-width t
513 "Non-nil means lines starting with \":\" will be in fixed width font.
514 This can be used to have pre-formatted text, fragments of code etc. For
515 example:
516 : ;; Some Lisp examples
517 : (while (defc cnt)
518 : (ding))
519 will be looking just like this in also HTML. See also the QUOTE keyword.
520 Not all export backends support this.
522 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
523 :group 'org-export-translation
524 :type 'boolean)
526 (defgroup org-export-tables nil
527 "Options for exporting tables in Org-mode."
528 :tag "Org Export Tables"
529 :group 'org-export)
531 (defcustom org-export-with-tables t
532 "If non-nil, lines starting with \"|\" define a table.
533 For example:
535 | Name | Address | Birthday |
536 |-------------+----------+-----------|
537 | Arthur Dent | England | 29.2.2100 |
539 Not all export backends support this.
541 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
542 :group 'org-export-tables
543 :type 'boolean)
545 (defcustom org-export-highlight-first-table-line t
546 "Non-nil means highlight the first table line.
547 In HTML export, this means use <th> instead of <td>.
548 In tables created with table.el, this applies to the first table line.
549 In Org-mode tables, all lines before the first horizontal separator
550 line will be formatted with <th> tags."
551 :group 'org-export-tables
552 :type 'boolean)
554 (defcustom org-export-table-remove-special-lines t
555 "Remove special lines and marking characters in calculating tables.
556 This removes the special marking character column from tables that are set
557 up for spreadsheet calculations. It also removes the entire lines
558 marked with `!', `_', or `^'. The lines with `$' are kept, because
559 the values of constants may be useful to have."
560 :group 'org-export-tables
561 :type 'boolean)
563 (defcustom org-export-prefer-native-exporter-for-tables nil
564 "Non-nil means always export tables created with table.el natively.
565 Natively means use the HTML code generator in table.el.
566 When nil, Org-mode's own HTML generator is used when possible (i.e. if
567 the table does not use row- or column-spanning). This has the
568 advantage, that the automatic HTML conversions for math symbols and
569 sub/superscripts can be applied. Org-mode's HTML generator is also
570 much faster. The LaTeX exporter always use the native exporter for
571 table.el tables."
572 :group 'org-export-tables
573 :type 'boolean)
576 (defgroup org-export-xml nil
577 "Options specific for XML export of Org-mode files."
578 :tag "Org Export XML"
579 :group 'org-export)
581 ;;;; Exporting
583 ;;; Variables, constants, and parameter plists
585 (defconst org-level-max 20)
587 (defvar org-export-current-backend nil
588 "During export, this will be bound to a symbol such as 'html,
589 'latex, 'docbook, 'ascii, etc, indicating which of the export
590 backends is in use. Otherwise it has the value nil. Users
591 should not attempt to change the value of this variable
592 directly, but it can be used in code to test whether export is
593 in progress, and if so, what the backend is.")
595 (defvar org-current-export-file nil) ; dynamically scoped parameter
596 (defvar org-current-export-dir nil) ; dynamically scoped parameter
597 (defvar org-export-opt-plist nil
598 "Contains the current option plist.")
599 (defvar org-last-level nil) ; dynamically scoped variable
600 (defvar org-min-level nil) ; dynamically scoped variable
601 (defvar org-levels-open nil) ; dynamically scoped parameter
603 (defconst org-export-plist-vars
604 '((:link-up nil org-export-html-link-up)
605 (:link-home nil org-export-html-link-home)
606 (:language nil org-export-default-language)
607 (:keywords nil org-export-page-keywords)
608 (:description nil org-export-page-description)
609 (:customtime nil org-display-custom-times)
610 (:headline-levels "H" org-export-headline-levels)
611 (:section-numbers "num" org-export-with-section-numbers)
612 (:section-number-format nil org-export-section-number-format)
613 (:table-of-contents "toc" org-export-with-toc)
614 (:preserve-breaks "\\n" org-export-preserve-breaks)
615 (:archived-trees nil org-export-with-archived-trees)
616 (:emphasize "*" org-export-with-emphasize)
617 (:sub-superscript "^" org-export-with-sub-superscripts)
618 (:special-strings "-" org-export-with-special-strings)
619 (:footnotes "f" org-export-with-footnotes)
620 (:drawers "d" org-export-with-drawers)
621 (:tags "tags" org-export-with-tags)
622 (:todo-keywords "todo" org-export-with-todo-keywords)
623 (:priority "pri" org-export-with-priority)
624 (:TeX-macros "TeX" org-export-with-TeX-macros)
625 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
626 (:latex-listings nil org-export-latex-listings)
627 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
628 (:fixed-width ":" org-export-with-fixed-width)
629 (:timestamps "<" org-export-with-timestamps)
630 (:author-info "author" org-export-author-info)
631 (:email-info "email" org-export-email-info)
632 (:creator-info "creator" org-export-creator-info)
633 (:time-stamp-file "timestamp" org-export-time-stamp-file)
634 (:tables "|" org-export-with-tables)
635 (:table-auto-headline nil org-export-highlight-first-table-line)
636 (:style-include-default nil org-export-html-style-include-default)
637 (:style-include-scripts nil org-export-html-style-include-scripts)
638 (:style nil org-export-html-style)
639 (:style-extra nil org-export-html-style-extra)
640 (:agenda-style nil org-agenda-export-html-style)
641 (:convert-org-links nil org-export-html-link-org-files-as-html)
642 (:inline-images nil org-export-html-inline-images)
643 (:html-extension nil org-export-html-extension)
644 (:xml-declaration nil org-export-html-xml-declaration)
645 (:html-table-tag nil org-export-html-table-tag)
646 (:expand-quoted-html "@" org-export-html-expand)
647 (:timestamp nil org-export-html-with-timestamp)
648 (:publishing-directory nil org-export-publishing-directory)
649 (:html-preamble nil org-export-html-preamble)
650 (:html-postamble nil org-export-html-postamble)
651 (:author nil user-full-name)
652 (:email nil user-mail-address)
653 (:select-tags nil org-export-select-tags)
654 (:exclude-tags nil org-export-exclude-tags)
656 (:latex-image-options nil org-export-latex-image-default-option))
657 "List of properties that represent export/publishing variables.
658 Each element is a list of 3 items:
659 1. The property that is used internally, and also for org-publish-project-alist
660 2. The string that can be used in the OPTION lines to set this option,
661 or nil if this option cannot be changed in this way
662 3. The customization variable that sets the default for this option."
665 (defun org-default-export-plist ()
666 "Return the property list with default settings for the export variables."
667 (let* ((infile (org-infile-export-plist))
668 (letbind (plist-get infile :let-bind))
669 (l org-export-plist-vars) rtn e s v)
670 (while (setq e (pop l))
671 (setq s (nth 2 e)
672 v (cond
673 ((assq s letbind) (nth 1 (assq s letbind)))
674 ((boundp s) (symbol-value s))
675 (t nil))
676 rtn (cons (car e) (cons v rtn))))
677 rtn))
679 (defvar org-export-inbuffer-options-extra nil
680 "List of additional in-buffer options that should be detected.
681 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
682 etc. Extensions can add to this list to get their options detected, and they
683 can then add a function to `org-export-options-filters' to process these
684 options.
685 Each element in this list must be a list, with the in-buffer keyword as car,
686 and a property (a symbol) as the next element. All occurrences of the
687 keyword will be found, the values concatenated with a space character
688 in between, and the result stored in the export options property list.")
690 (defvar org-export-options-filters nil
691 "Functions to be called to finalize the export/publishing options.
692 All these options are stored in a property list, and each of the functions
693 in this hook gets a chance to modify this property list. Each function
694 must accept the property list as an argument, and must return the (possibly
695 modified) list.")
697 ;; FIXME: should we fold case here?
698 (defun org-infile-export-plist ()
699 "Return the property list with file-local settings for export."
700 (save-excursion
701 (save-restriction
702 (widen)
703 (goto-char (point-min))
704 (let ((re (org-make-options-regexp
705 (append
706 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
707 "MATHJAX"
708 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
709 "LATEX_HEADER" "LATEX_CLASS"
710 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
711 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
712 (mapcar 'car org-export-inbuffer-options-extra))))
713 (case-fold-search t)
714 p key val text options mathjax a pr style
715 latex-header latex-class macros letbind
716 ext-setup-or-nil setup-contents (start 0))
717 (while (or (and ext-setup-or-nil
718 (string-match re ext-setup-or-nil start)
719 (setq start (match-end 0)))
720 (and (setq ext-setup-or-nil nil start 0)
721 (re-search-forward re nil t)))
722 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
723 val (org-match-string-no-properties 2 ext-setup-or-nil))
724 (cond
725 ((setq a (assoc key org-export-inbuffer-options-extra))
726 (setq pr (nth 1 a))
727 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
728 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
729 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
730 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
731 ((string-equal key "DATE") (setq p (plist-put p :date val)))
732 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
733 ((string-equal key "DESCRIPTION")
734 (setq p (plist-put p :description val)))
735 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
736 ((string-equal key "STYLE")
737 (setq style (concat style "\n" val)))
738 ((string-equal key "LATEX_HEADER")
739 (setq latex-header (concat latex-header "\n" val)))
740 ((string-equal key "LATEX_CLASS")
741 (setq latex-class val))
742 ((string-equal key "TEXT")
743 (setq text (if text (concat text "\n" val) val)))
744 ((string-equal key "OPTIONS")
745 (setq options (concat val " " options)))
746 ((string-equal key "MATHJAX")
747 (setq mathjax (concat val " " mathjax)))
748 ((string-equal key "BIND")
749 (push (read (concat "(" val ")")) letbind))
750 ((string-equal key "XSLT")
751 (setq p (plist-put p :xslt val)))
752 ((string-equal key "LINK_UP")
753 (setq p (plist-put p :link-up val)))
754 ((string-equal key "LINK_HOME")
755 (setq p (plist-put p :link-home val)))
756 ((string-equal key "EXPORT_SELECT_TAGS")
757 (setq p (plist-put p :select-tags (org-split-string val))))
758 ((string-equal key "EXPORT_EXCLUDE_TAGS")
759 (setq p (plist-put p :exclude-tags (org-split-string val))))
760 ((string-equal key "MACRO")
761 (push val macros))
762 ((equal key "SETUPFILE")
763 (setq setup-contents (org-file-contents
764 (expand-file-name
765 (org-remove-double-quotes
766 (org-trim val)))
767 'noerror))
768 (if (not ext-setup-or-nil)
769 (setq ext-setup-or-nil setup-contents start 0)
770 (setq ext-setup-or-nil
771 (concat (substring ext-setup-or-nil 0 start)
772 "\n" setup-contents "\n"
773 (substring ext-setup-or-nil start)))))))
774 (setq p (plist-put p :text text))
775 (when (and letbind (org-export-confirm-letbind))
776 (setq p (plist-put p :let-bind letbind)))
777 (when style (setq p (plist-put p :style-extra style)))
778 (when latex-header
779 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
780 (when latex-class
781 (setq p (plist-put p :latex-class latex-class)))
782 (when options
783 (setq p (org-export-add-options-to-plist p options)))
784 (when mathjax
785 (setq p (plist-put p :mathjax mathjax)))
786 ;; Add macro definitions
787 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
788 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
789 (setq p (plist-put p :macro-property "(eval (org-entry-get nil \"$1\" 'selective))"))
790 (setq p (plist-put
791 p :macro-modification-time
792 (and (buffer-file-name)
793 (file-exists-p (buffer-file-name))
794 (concat
795 "(eval (format-time-string \"$1\" '"
796 (prin1-to-string (nth 5 (file-attributes
797 (buffer-file-name))))
798 "))"))))
799 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
800 (file-name-nondirectory
801 (buffer-file-name)))))
802 (while (setq val (pop macros))
803 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
804 (setq p (plist-put
805 p (intern
806 (concat ":macro-" (downcase (match-string 1 val))))
807 (org-export-interpolate-newlines (match-string 2 val))))))
808 p))))
810 (defun org-export-interpolate-newlines (s)
811 (while (string-match "\\\\n" s)
812 (setq s (replace-match "\n" t t s)))
815 (defvar org-export-allow-BIND-local nil)
816 (defun org-export-confirm-letbind ()
817 "Can we use #+BIND values during export?
818 By default this will ask for confirmation by the user, to divert possible
819 security risks."
820 (cond
821 ((not org-export-allow-BIND) nil)
822 ((eq org-export-allow-BIND t) t)
823 ((local-variable-p 'org-export-allow-BIND-local (current-buffer))
824 org-export-allow-BIND-local)
825 (t (org-set-local 'org-export-allow-BIND-local
826 (yes-or-no-p "Allow BIND values in this buffer? ")))))
828 (defun org-install-letbind ()
829 "Install the values from #+BIND lines as local variables."
830 (let ((letbind (plist-get org-export-opt-plist :let-bind))
831 pair)
832 (while (setq pair (pop letbind))
833 (org-set-local (car pair) (nth 1 pair)))))
835 (defun org-export-add-options-to-plist (p options)
836 "Parse an OPTIONS line and set values in the property list P."
837 (let (o)
838 (when options
839 (let ((op org-export-plist-vars))
840 (while (setq o (pop op))
841 (if (and (nth 1 o)
842 (string-match (concat "\\<" (regexp-quote (nth 1 o))
843 ":\\([^ \t\n\r;,.]*\\)")
844 options))
845 (setq p (plist-put p (car o)
846 (car (read-from-string
847 (match-string 1 options))))))))))
850 (defun org-export-add-subtree-options (p pos)
851 "Add options in subtree at position POS to property list P."
852 (save-excursion
853 (goto-char pos)
854 (when (org-at-heading-p)
855 (let (a)
856 ;; This is actually read in `org-export-get-title-from-subtree'
857 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
858 ;; (setq p (plist-put p :title a)))
859 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
860 (setq p (plist-put p :text a)))
861 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
862 (setq p (plist-put p :author a)))
863 (when (setq a (org-entry-get pos "EXPORT_DATE"))
864 (setq p (plist-put p :date a)))
865 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
866 (setq p (org-export-add-options-to-plist p a)))))
869 (defun org-export-directory (type plist)
870 (let* ((val (plist-get plist :publishing-directory))
871 (dir (if (listp val)
872 (or (cdr (assoc type val)) ".")
873 val)))
874 dir))
876 (defun org-export-process-option-filters (plist)
877 (let ((functions org-export-options-filters) f)
878 (while (setq f (pop functions))
879 (setq plist (funcall f plist))))
880 plist)
882 ;;;###autoload
883 (defun org-export (&optional arg)
884 "Export dispatcher for Org-mode.
885 When `org-export-run-in-background' is non-nil, try to run the command
886 in the background. This will be done only for commands that write
887 to a file. For details see the docstring of `org-export-run-in-background'.
889 The prefix argument ARG will be passed to the exporter. However, if
890 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
891 that means to inverse the
892 value of `org-export-run-in-background'.
894 If `org-export-initial-scope' is set to 'subtree, try to export
895 the current subtree, otherwise try to export the whole buffer.
896 Pressing `1' will switch between these two options."
897 (interactive "P")
898 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
899 (subtree-p (or (org-region-active-p)
900 (eq org-export-initial-scope 'subtree)))
901 (help "[t] insert the export option template
902 \[v] limit export to visible part of outline tree
903 \[1] switch buffer/subtree export
904 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
906 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
908 \[h] export as HTML [H] to temporary buffer [R] export region
909 \[b] export as HTML and open in browser
911 \[l] export as LaTeX [L] to temporary buffer
912 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
914 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
916 \[j] export as TaskJuggler [J] ... and open
918 \[m] export as Freemind mind map
919 \[x] export as XOXO
920 \[g] export using Wes Hardaker's generic exporter
922 \[i] export current file as iCalendar file
923 \[I] export all agenda files as iCalendar files [c] ...as one combined file
925 \[F] publish current file [P] publish current project
926 \[X] publish a project... [E] publish every projects")
927 (cmds
928 '((?t org-insert-export-options-template nil)
929 (?v org-export-visible nil)
930 (?a org-export-as-ascii t)
931 (?A org-export-as-ascii-to-buffer t)
932 (?n org-export-as-latin1 t)
933 (?N org-export-as-latin1-to-buffer t)
934 (?u org-export-as-utf8 t)
935 (?U org-export-as-utf8-to-buffer t)
936 (?h org-export-as-html t)
937 (?b org-export-as-html-and-open t)
938 (?H org-export-as-html-to-buffer nil)
939 (?R org-export-region-as-html nil)
940 (?x org-export-as-xoxo t)
941 (?g org-export-generic t)
942 (?D org-export-as-docbook t)
943 (?V org-export-as-docbook-pdf-and-open t)
944 (?j org-export-as-taskjuggler t)
945 (?J org-export-as-taskjuggler-and-open t)
946 (?m org-export-as-freemind t)
947 (?l org-export-as-latex t)
948 (?p org-export-as-pdf t)
949 (?d org-export-as-pdf-and-open t)
950 (?L org-export-as-latex-to-buffer nil)
951 (?i org-export-icalendar-this-file t)
952 (?I org-export-icalendar-all-agenda-files t)
953 (?c org-export-icalendar-combine-agenda-files t)
954 (?F org-publish-current-file t)
955 (?P org-publish-current-project t)
956 (?X org-publish t)
957 (?E org-publish-all t)))
958 r1 r2 ass
959 (cpos (point)) (cbuf (current-buffer)) bpos)
960 (save-excursion
961 (save-window-excursion
962 (if subtree-p
963 (message "Export subtree: ")
964 (message "Export buffer: "))
965 (delete-other-windows)
966 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
967 (princ help))
968 (org-fit-window-to-buffer (get-buffer-window
969 "*Org Export/Publishing Help*"))
970 (while (eq (setq r1 (read-char-exclusive)) ?1)
971 (cond (subtree-p
972 (setq subtree-p nil)
973 (message "Export buffer: "))
974 ((not subtree-p)
975 (setq subtree-p t)
976 (message "Export subtree: "))))
977 (when (eq r1 ?\ )
978 (let ((case-fold-search t))
979 (if (re-search-backward
980 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
981 nil t)
982 (progn
983 (org-back-to-heading t)
984 (setq subtree-p t)
985 (setq bpos (point))
986 (message "Select command (for subtree): ")
987 (setq r1 (read-char-exclusive)))
988 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
989 )))))
990 (redisplay)
991 (and bpos (goto-char bpos))
992 (setq r2 (if (< r1 27) (+ r1 96) r1))
993 (unless (setq ass (assq r2 cmds))
994 (error "No command associated with key %c" r1))
995 (if (and bg (nth 2 ass)
996 (not (buffer-base-buffer))
997 (not (org-region-active-p)))
998 ;; execute in background
999 (let ((p (start-process
1000 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1001 "*Org Processes*"
1002 (expand-file-name invocation-name invocation-directory)
1003 "-batch"
1004 "-l" user-init-file
1005 "--eval" "(require 'org-exp)"
1006 "--eval" "(setq org-wait .2)"
1007 (buffer-file-name)
1008 "-f" (symbol-name (nth 1 ass)))))
1009 (set-process-sentinel p 'org-export-process-sentinel)
1010 (message "Background process \"%s\": started" p))
1011 ;; background processing not requested, or not possible
1012 (if subtree-p (progn (org-mark-subtree) (activate-mark)))
1013 (call-interactively (nth 1 ass))
1014 (when (and bpos (get-buffer-window cbuf))
1015 (let ((cw (selected-window)))
1016 (select-window (get-buffer-window cbuf))
1017 (goto-char cpos)
1018 (deactivate-mark)
1019 (select-window cw))))))
1021 (defun org-export-process-sentinel (process status)
1022 (if (string-match "\n+\\'" status)
1023 (setq status (substring status 0 -1)))
1024 (message "Background process \"%s\": %s" process status))
1026 ;;; General functions for all backends
1028 (defvar org-export-target-aliases nil
1029 "Alist of targets with invisible aliases.")
1030 (defvar org-export-preferred-target-alist nil
1031 "Alist of section id's with preferred aliases.")
1032 (defvar org-export-id-target-alist nil
1033 "Alist of section id's with preferred aliases.")
1034 (defvar org-export-code-refs nil
1035 "Alist of code references and line numbers.")
1037 (defun org-export-preprocess-string (string &rest parameters)
1038 "Cleanup STRING so that that the true exported has a more consistent source.
1039 This function takes STRING, which should be a buffer-string of an org-file
1040 to export. It then creates a temporary buffer where it does its job.
1041 The result is then again returned as a string, and the exporter works
1042 on this string to produce the exported version."
1043 (interactive)
1044 (let* ((org-export-current-backend (plist-get parameters :for-backend))
1045 (archived-trees (plist-get parameters :archived-trees))
1046 (inhibit-read-only t)
1047 (drawers org-drawers)
1048 (outline-regexp "\\*+ ")
1049 (source-buffer (current-buffer))
1050 target-alist rtn)
1052 (setq org-export-target-aliases nil
1053 org-export-preferred-target-alist nil
1054 org-export-id-target-alist nil
1055 org-export-code-refs nil)
1057 (with-current-buffer (get-buffer-create " org-mode-tmp")
1058 (erase-buffer)
1059 (insert string)
1060 (setq case-fold-search t)
1062 (let ((inhibit-read-only t))
1063 (remove-text-properties (point-min) (point-max)
1064 '(read-only t)))
1066 ;; Remove license-to-kill stuff
1067 ;; The caller marks some stuff for killing, stuff that has been
1068 ;; used to create the page title, for example.
1069 (org-export-kill-licensed-text)
1071 (let ((org-inhibit-startup t)) (org-mode))
1072 (setq case-fold-search t)
1073 (org-clone-local-variables source-buffer "^\\(org-\\|orgtbl-\\)")
1074 (org-install-letbind)
1076 ;; Call the hook
1077 (run-hooks 'org-export-preprocess-hook)
1079 ;; Process the macros
1080 (org-export-preprocess-apply-macros)
1081 (run-hooks 'org-export-preprocess-after-macros-hook)
1083 (untabify (point-min) (point-max))
1085 ;; Handle include files, and call a hook
1086 (org-export-handle-include-files-recurse)
1087 (run-hooks 'org-export-preprocess-after-include-files-hook)
1089 ;; Get rid of archived trees
1090 (org-export-remove-archived-trees archived-trees)
1092 ;; Remove comment environment and comment subtrees
1093 (org-export-remove-comment-blocks-and-subtrees)
1095 ;; Get rid of excluded trees, and call a hook
1096 (org-export-handle-export-tags (plist-get parameters :select-tags)
1097 (plist-get parameters :exclude-tags))
1098 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1100 ;; Change lists ending. Other parts of export may insert blank
1101 ;; lines and lists' structure could be altered.
1102 (org-export-mark-list-end)
1104 ;; Export code blocks
1105 (org-export-blocks-preprocess)
1107 ;; Mark lists with properties
1108 (org-export-mark-list-properties)
1110 ;; Handle source code snippets
1111 (org-export-replace-src-segments-and-examples)
1113 ;; Protect short examples marked by a leading colon
1114 (org-export-protect-colon-examples)
1116 ;; Protected spaces
1117 (org-export-convert-protected-spaces)
1119 ;; Normalize footnotes
1120 (when (plist-get parameters :footnotes)
1121 (org-footnote-normalize nil t))
1123 ;; Find all headings and compute the targets for them
1124 (setq target-alist (org-export-define-heading-targets target-alist))
1126 (run-hooks 'org-export-preprocess-after-headline-targets-hook)
1128 ;; Find HTML special classes for headlines
1129 (org-export-remember-html-container-classes)
1131 ;; Get rid of drawers
1132 (org-export-remove-or-extract-drawers
1133 drawers (plist-get parameters :drawers))
1135 ;; Get the correct stuff before the first headline
1136 (when (plist-get parameters :skip-before-1st-heading)
1137 (goto-char (point-min))
1138 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1139 (delete-region (point-min) (match-beginning 0))
1140 (goto-char (point-min))
1141 (insert "\n")))
1142 (when (plist-get parameters :add-text)
1143 (goto-char (point-min))
1144 (insert (plist-get parameters :add-text) "\n"))
1146 ;; Remove todo-keywords before exporting, if the user has requested so
1147 (org-export-remove-headline-metadata parameters)
1149 ;; Find targets in comments and move them out of comments,
1150 ;; but mark them as targets that should be invisible
1151 (setq target-alist (org-export-handle-invisible-targets target-alist))
1153 ;; Select and protect backend specific stuff, throw away stuff
1154 ;; that is specific for other backends
1155 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
1156 (org-export-select-backend-specific-text)
1158 ;; Protect quoted subtrees
1159 (org-export-protect-quoted-subtrees)
1161 ;; Remove clock lines
1162 (org-export-remove-clock-lines)
1164 ;; Protect verbatim elements
1165 (org-export-protect-verbatim)
1167 ;; Blockquotes, verse, and center
1168 (org-export-mark-blockquote-verse-center)
1169 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1171 ;; Remove timestamps, if the user has requested so
1172 (unless (plist-get parameters :timestamps)
1173 (org-export-remove-timestamps))
1175 ;; Attach captions to the correct object
1176 (setq target-alist (org-export-attach-captions-and-attributes target-alist))
1178 ;; Find matches for radio targets and turn them into internal links
1179 (org-export-mark-radio-links)
1180 (run-hooks 'org-export-preprocess-after-radio-targets-hook)
1182 ;; Find all links that contain a newline and put them into a single line
1183 (org-export-concatenate-multiline-links)
1185 ;; Normalize links: Convert angle and plain links into bracket links
1186 ;; and expand link abbreviations
1187 (run-hooks 'org-export-preprocess-before-normalizing-links-hook)
1188 (org-export-normalize-links)
1190 ;; Find all internal links. If they have a fuzzy match (i.e. not
1191 ;; a *dedicated* target match, let the link point to the
1192 ;; corresponding section.
1193 (org-export-target-internal-links target-alist)
1195 ;; Find multiline emphasis and put them into single line
1196 (when (plist-get parameters :emph-multiline)
1197 (org-export-concatenate-multiline-emphasis))
1199 ;; Remove special table lines, and store alignment information
1200 (org-store-forced-table-alignment)
1201 (when org-export-table-remove-special-lines
1202 (org-export-remove-special-table-lines))
1204 ;; Another hook
1205 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1207 ;; Backend-specific preprocessing
1208 (let* ((backend-name (symbol-name org-export-current-backend))
1209 (f (intern (format "org-export-%s-preprocess" backend-name))))
1210 (require (intern (concat "org-" backend-name)) nil)
1211 (funcall f parameters))
1213 ;; Remove or replace comments
1214 (org-export-handle-comments (plist-get parameters :comments))
1216 ;; Remove #+TBLFM and #+TBLNAME lines
1217 (org-export-handle-table-metalines)
1219 ;; Run the final hook
1220 (run-hooks 'org-export-preprocess-final-hook)
1222 (setq rtn (buffer-string)))
1223 (kill-buffer " org-mode-tmp")
1224 rtn))
1226 (defun org-export-kill-licensed-text ()
1227 "Remove all text that is marked with a :org-license-to-kill property."
1228 (let (p)
1229 (while (setq p (text-property-any (point-min) (point-max)
1230 :org-license-to-kill t))
1231 (delete-region
1232 p (or (next-single-property-change p :org-license-to-kill)
1233 (point-max))))))
1235 (defvar org-export-define-heading-targets-headline-hook nil
1236 "Hook that is run when a headline was matched during target search.
1237 This is part of the preprocessing for export.")
1239 (defun org-export-define-heading-targets (target-alist)
1240 "Find all headings and define the targets for them.
1241 The new targets are added to TARGET-ALIST, which is also returned.
1242 Also find all ID and CUSTOM_ID properties and store them."
1243 (goto-char (point-min))
1244 (org-init-section-numbers)
1245 (let ((re (concat "^" org-outline-regexp
1246 "\\|"
1247 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1248 level target last-section-target a id)
1249 (while (re-search-forward re nil t)
1250 (org-if-unprotected-at (match-beginning 0)
1251 (if (match-end 2)
1252 (progn
1253 (setq id (org-match-string-no-properties 2))
1254 (push (cons id target) target-alist)
1255 (setq a (or (assoc last-section-target org-export-target-aliases)
1256 (progn
1257 (push (list last-section-target)
1258 org-export-target-aliases)
1259 (car org-export-target-aliases))))
1260 (push (caar target-alist) (cdr a))
1261 (when (equal (match-string 1) "CUSTOM_ID")
1262 (if (not (assoc last-section-target
1263 org-export-preferred-target-alist))
1264 (push (cons last-section-target id)
1265 org-export-preferred-target-alist)))
1266 (when (equal (match-string 1) "ID")
1267 (if (not (assoc last-section-target
1268 org-export-id-target-alist))
1269 (push (cons last-section-target (concat "ID-" id))
1270 org-export-id-target-alist))))
1271 (setq level (org-reduced-level
1272 (save-excursion (goto-char (point-at-bol))
1273 (org-outline-level))))
1274 (setq target (org-solidify-link-text
1275 (format "sec-%s" (replace-regexp-in-string
1276 "\\." "_"
1277 (org-section-number level)))))
1278 (setq last-section-target target)
1279 (push (cons target target) target-alist)
1280 (add-text-properties
1281 (point-at-bol) (point-at-eol)
1282 (list 'target target))
1283 (run-hooks 'org-export-define-heading-targets-headline-hook)))))
1284 target-alist)
1286 (defun org-export-handle-invisible-targets (target-alist)
1287 "Find targets in comments and move them out of comments.
1288 Mark them as invisible targets."
1289 (let (target tmp a)
1290 (goto-char (point-min))
1291 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1292 ;; Check if the line before or after is a headline with a target
1293 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1294 (get-text-property (point-at-bol 2) 'target)))
1295 (progn
1296 ;; use the existing target in a neighboring line
1297 (setq tmp (match-string 2))
1298 (replace-match "")
1299 (and (looking-at "\n") (delete-char 1))
1300 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1301 target-alist)
1302 (setq a (or (assoc target org-export-target-aliases)
1303 (progn
1304 (push (list target) org-export-target-aliases)
1305 (car org-export-target-aliases))))
1306 (push tmp (cdr a)))
1307 ;; Make an invisible target
1308 (replace-match "\\1(INVISIBLE)"))))
1309 target-alist)
1311 (defun org-export-target-internal-links (target-alist)
1312 "Find all internal links and assign targets to them.
1313 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1314 let the link point to the corresponding section.
1315 This function also handles the id links, if they have a match in
1316 the current file."
1317 (goto-char (point-min))
1318 (while (re-search-forward org-bracket-link-regexp nil t)
1319 (org-if-unprotected-at (1+ (match-beginning 0))
1320 (let* ((org-link-search-must-match-exact-headline t)
1321 (md (match-data))
1322 (desc (match-end 2))
1323 (link (org-link-unescape (match-string 1)))
1324 (slink (org-solidify-link-text link))
1325 found props pos cref
1326 (target
1327 (cond
1328 ((= (string-to-char link) ?#)
1329 ;; user wants exactly this link
1330 link)
1331 ((cdr (assoc slink target-alist))
1332 (or (cdr (assoc (assoc slink target-alist)
1333 org-export-preferred-target-alist))
1334 (cdr (assoc slink target-alist))))
1335 ((and (string-match "^id:" link)
1336 (cdr (assoc (substring link 3) target-alist))))
1337 ((string-match "^(\\(.*\\))$" link)
1338 (setq cref (match-string 1 link))
1339 (concat "coderef:" cref))
1340 ((string-match org-link-types-re link) nil)
1341 ((or (file-name-absolute-p link)
1342 (string-match "^\\." link))
1343 nil)
1345 (let ((org-link-search-inhibit-query t))
1346 (save-excursion
1347 (setq found (condition-case nil (org-link-search link)
1348 (error nil)))
1349 (when (and found
1350 (or (org-on-heading-p)
1351 (not (eq found 'dedicated))))
1352 (or (get-text-property (point) 'target)
1353 (get-text-property
1354 (max (point-min)
1355 (1- (or (previous-single-property-change
1356 (point) 'target) 0)))
1357 'target)))))))))
1358 (when target
1359 (set-match-data md)
1360 (goto-char (match-beginning 1))
1361 (setq props (text-properties-at (point)))
1362 (delete-region (match-beginning 1) (match-end 1))
1363 (setq pos (point))
1364 (insert target)
1365 (unless desc (insert "][" link))
1366 (add-text-properties pos (point) props))))))
1368 (defun org-export-remember-html-container-classes ()
1369 "Store the HTML_CONTAINER_CLASS properties in a text property."
1370 (goto-char (point-min))
1371 (let (class)
1372 (while (re-search-forward
1373 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t)
1374 (setq class (match-string 1))
1375 (save-excursion
1376 (org-back-to-heading t)
1377 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class)))))
1379 (defvar org-export-format-drawer-function nil
1380 "Function to be called to format the contents of a drawer.
1381 The function must accept three parameters:
1382 NAME the drawer name, like \"PROPERTIES\"
1383 CONTENT the content of the drawer.
1384 You can check the export backend through `org-export-current-backend'.
1385 The function should return the text to be inserted into the buffer.
1386 If this is nil, `org-export-format-drawer' is used as a default.")
1388 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1389 "Remove drawers, or extract and format the content.
1390 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1391 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1392 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1393 EXP-DRAWERS will be removed."
1394 (goto-char (point-min))
1395 (let ((re (concat "^[ \t]*:\\("
1396 (mapconcat 'identity all-drawers "\\|")
1397 "\\):[ \t]*$"))
1398 name beg beg-content eol content)
1399 (while (re-search-forward re nil t)
1400 (org-if-unprotected
1401 (setq name (match-string 1))
1402 (setq beg (match-beginning 0)
1403 beg-content (1+ (point-at-eol))
1404 eol (point-at-eol))
1405 (if (not (and (re-search-forward
1406 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t)
1407 (match-end 1)))
1408 (goto-char eol)
1409 (goto-char (match-beginning 0))
1410 (and (looking-at ".*\n?") (replace-match ""))
1411 (setq content (buffer-substring beg-content (point)))
1412 (delete-region beg (point))
1413 (when (or (eq exp-drawers t)
1414 (member name exp-drawers))
1415 (setq content (funcall (or org-export-format-drawer-function
1416 'org-export-format-drawer)
1417 name content))
1418 (insert content)))))))
1420 (defun org-export-format-drawer (name content)
1421 "Format the content of a drawer as a colon example."
1422 (if (string-match "[ \t]+\\'" content)
1423 (setq content (substring content (match-beginning 0))))
1424 (while (string-match "\\`[ \t]*\n" content)
1425 (setq content (substring content (match-end 0))))
1426 (setq content (org-remove-indentation content))
1427 (setq content (concat ": " (mapconcat 'identity
1428 (org-split-string content "\n")
1429 "\n: ")
1430 "\n"))
1431 (setq content (concat " : " (upcase name) "\n" content))
1432 (org-add-props content nil 'org-protected t))
1434 (defun org-export-handle-export-tags (select-tags exclude-tags)
1435 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1436 Both arguments are lists of tags.
1437 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1438 will be removed.
1439 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1440 removed as well."
1441 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1442 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1443 select-tags "\\|")
1444 "\\):"))
1445 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1446 exclude-tags "\\|")
1447 "\\):"))
1448 beg end cont)
1449 (goto-char (point-min))
1450 (when (and select-tags
1451 (re-search-forward
1452 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1453 ;; At least one tree is marked for export, this means
1454 ;; all the unmarked stuff needs to go.
1455 ;; Dig out the trees that should be exported
1456 (goto-char (point-min))
1457 (outline-next-heading)
1458 (setq beg (point))
1459 (put-text-property beg (point-max) :org-delete t)
1460 (while (re-search-forward re-sel nil t)
1461 (when (org-on-heading-p)
1462 (org-back-to-heading)
1463 (remove-text-properties
1464 (max (1- (point)) (point-min))
1465 (setq cont (save-excursion (org-end-of-subtree t t)))
1466 '(:org-delete t))
1467 (while (and (org-up-heading-safe)
1468 (get-text-property (point) :org-delete))
1469 (remove-text-properties (max (1- (point)) (point-min))
1470 (point-at-eol) '(:org-delete t)))
1471 (goto-char cont))))
1472 ;; Remove the trees explicitly marked for noexport
1473 (when exclude-tags
1474 (goto-char (point-min))
1475 (while (re-search-forward re-excl nil t)
1476 (when (org-at-heading-p)
1477 (org-back-to-heading t)
1478 (setq beg (point))
1479 (org-end-of-subtree t t)
1480 (delete-region beg (point))
1481 (when (featurep 'org-inlinetask)
1482 (org-inlinetask-remove-END-maybe)))))
1483 ;; Remove everything that is now still marked for deletion
1484 (goto-char (point-min))
1485 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1486 (setq end (or (next-single-property-change beg :org-delete)
1487 (point-max)))
1488 (delete-region beg end))))
1490 (defun org-export-remove-archived-trees (export-archived-trees)
1491 "Remove archived trees.
1492 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1493 When it is t, the entire archived tree will be exported.
1494 When it is nil the entire tree including the headline will be removed
1495 from the buffer."
1496 (let ((re-archive (concat ":" org-archive-tag ":"))
1497 a b)
1498 (when (not (eq export-archived-trees t))
1499 (goto-char (point-min))
1500 (while (re-search-forward re-archive nil t)
1501 (if (not (org-on-heading-p t))
1502 (goto-char (point-at-eol))
1503 (beginning-of-line 1)
1504 (setq a (if export-archived-trees
1505 (1+ (point-at-eol)) (point))
1506 b (org-end-of-subtree t))
1507 (if (> b a) (delete-region a b)))))))
1509 (defun org-export-remove-headline-metadata (opts)
1510 "Remove meta data from the headline, according to user options."
1511 (let ((re org-complex-heading-regexp)
1512 (todo (plist-get opts :todo-keywords))
1513 (tags (plist-get opts :tags))
1514 (pri (plist-get opts :priority))
1515 (elts '(1 2 3 4 5))
1516 (case-fold-search nil)
1517 rpl)
1518 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1519 (when (or (not todo) (not tags) (not pri))
1520 (goto-char (point-min))
1521 (while (re-search-forward re nil t)
1522 (org-if-unprotected
1523 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1524 elts " "))
1525 (replace-match rpl t t))))))
1527 (defun org-export-remove-timestamps ()
1528 "Remove timestamps and keywords for export."
1529 (goto-char (point-min))
1530 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1531 (backward-char 1)
1532 (org-if-unprotected
1533 (unless (save-match-data (org-at-table-p))
1534 (replace-match "")
1535 (beginning-of-line 1)
1536 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1537 (replace-match ""))))))
1539 (defun org-export-remove-clock-lines ()
1540 "Remove clock lines for export."
1541 (goto-char (point-min))
1542 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1543 (while (re-search-forward re nil t)
1544 (org-if-unprotected
1545 (replace-match "")))))
1547 (defun org-export-protect-quoted-subtrees ()
1548 "Mark quoted subtrees with the protection property."
1549 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1550 (goto-char (point-min))
1551 (while (re-search-forward re-quote nil t)
1552 (goto-char (match-beginning 0))
1553 (end-of-line 1)
1554 (add-text-properties (point) (org-end-of-subtree t)
1555 '(org-protected t)))))
1557 (defun org-export-convert-protected-spaces ()
1558 "Convert strings like \\____ to protected spaces in all backends."
1559 (goto-char (point-min))
1560 (while (re-search-forward "\\\\__+" nil t)
1561 (org-if-unprotected-1
1562 (replace-match
1563 (org-add-props
1564 (cond
1565 ((eq org-export-current-backend 'latex)
1566 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1567 ((eq org-export-current-backend 'html)
1568 (org-add-props (match-string 0) nil
1569 'org-whitespace (- (match-end 0) (match-beginning 0))))
1570 ;; ((eq org-export-current-backend 'docbook))
1571 ((eq org-export-current-backend 'ascii)
1572 (org-add-props (match-string 0) '(org-whitespace t)))
1573 (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
1574 '(org-protected t))
1575 t t))))
1577 (defun org-export-protect-verbatim ()
1578 "Mark verbatim snippets with the protection property."
1579 (goto-char (point-min))
1580 (while (re-search-forward org-verbatim-re nil t)
1581 (org-if-unprotected
1582 (add-text-properties (match-beginning 4) (match-end 4)
1583 '(org-protected t org-verbatim-emph t))
1584 (goto-char (1+ (match-end 4))))))
1586 (defun org-export-protect-colon-examples ()
1587 "Protect lines starting with a colon."
1588 (goto-char (point-min))
1589 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1590 (while (re-search-forward re nil t)
1591 (beginning-of-line 1)
1592 (setq beg (point))
1593 (while (looking-at re)
1594 (end-of-line 1)
1595 (or (eobp) (forward-char 1)))
1596 (add-text-properties beg (if (bolp) (1- (point)) (point))
1597 '(org-protected t)))))
1599 (defun org-export-select-backend-specific-text ()
1600 (let ((formatters
1601 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1602 (html "HTML" "BEGIN_HTML" "END_HTML")
1603 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1604 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1605 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1606 (case-fold-search t)
1607 fmt beg beg-content end end-content ind)
1609 (while formatters
1610 (setq fmt (pop formatters))
1611 ;; Handle #+backend: stuff
1612 (goto-char (point-min))
1613 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1614 ":[ \t]*\\(.*\\)") nil t)
1615 (if (not (eq (car fmt) org-export-current-backend))
1616 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1617 (replace-match "\\1\\2" t)
1618 (add-text-properties
1619 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1620 `(org-protected t original-indentation ,ind))))
1621 ;; Delete #+attr_Backend: stuff of another backend. Those
1622 ;; matching the current backend will be taken care of by
1623 ;; `org-export-attach-captions-and-attributes'
1624 (goto-char (point-min))
1625 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt)
1626 ":[ \t]*\\(.*\\)") nil t)
1627 (setq ind (org-get-indentation))
1628 (when (not (eq (car fmt) org-export-current-backend))
1629 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1630 ;; Handle #+begin_backend and #+end_backend stuff
1631 (goto-char (point-min))
1632 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?")
1633 nil t)
1634 (setq beg (match-beginning 0) beg-content (match-end 0))
1635 (setq ind (save-excursion (goto-char beg) (org-get-indentation)))
1636 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
1637 nil t)
1638 (setq end (match-end 0) end-content (match-beginning 0))
1639 (if (eq (car fmt) org-export-current-backend)
1640 ;; yes, keep this
1641 (progn
1642 (add-text-properties
1643 beg-content end-content
1644 `(org-protected t original-indentation ,ind))
1645 (delete-region (match-beginning 0) (match-end 0))
1646 (save-excursion
1647 (goto-char beg)
1648 (delete-region (point) (1+ (point-at-eol)))))
1649 ;; No, this is for a different backend, kill it
1650 (delete-region beg end)))))))
1652 (defun org-export-mark-blockquote-verse-center ()
1653 "Mark block quote and verse environments with special cookies.
1654 These special cookies will later be interpreted by the backend."
1655 ;; Blockquotes
1656 (let (type t1 ind beg end beg1 end1 content)
1657 (goto-char (point-min))
1658 (while (re-search-forward
1659 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1660 nil t)
1661 (setq ind (length (match-string 1))
1662 type (downcase (match-string 3))
1663 t1 (if (equal type "quote") "blockquote" type))
1664 (setq beg (match-beginning 0)
1665 beg1 (1+ (match-end 0)))
1666 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1667 (setq end1 (1- (match-beginning 0))
1668 end (+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1669 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1670 (setq content (concat "ORG-" (upcase t1) "-START\n"
1671 content "\n"
1672 "ORG-" (upcase t1) "-END\n"))
1673 (delete-region beg end)
1674 (insert (org-add-props content nil 'original-indentation ind))))))
1676 (defun org-export-mark-list-end ()
1677 "Mark all list endings with a special string."
1678 (unless (eq org-export-current-backend 'ascii)
1679 (mapc
1680 (lambda (e)
1681 ;; For each type allowing list export, find every list, remove
1682 ;; ending regexp if needed, and insert org-list-end.
1683 (goto-char (point-min))
1684 (while (re-search-forward (org-item-beginning-re) nil t)
1685 (when (eq (nth 2 (org-list-context)) e)
1686 (let* ((struct (org-list-struct))
1687 (bottom (org-list-get-bottom-point struct))
1688 (top (point-at-bol))
1689 (top-ind (org-list-get-ind top struct)))
1690 (goto-char bottom)
1691 (when (and (not (eq org-list-ending-method 'indent))
1692 (looking-at org-list-end-re))
1693 (replace-match ""))
1694 (unless (bolp) (insert "\n"))
1695 ;; As org-list-end is inserted at column 0, it would end
1696 ;; by indentation any list. It can be problematic when
1697 ;; there are lists within lists: the inner list end would
1698 ;; also become the outer list end. To avoid this, text
1699 ;; property `original-indentation' is added, as
1700 ;; `org-list-struct' pays attention to it when reading a
1701 ;; list.
1702 (insert (org-add-props
1703 "ORG-LIST-END-MARKER\n"
1704 (list 'original-indentation top-ind)))))))
1705 (cons nil org-list-export-context))))
1707 (defun org-export-mark-list-properties ()
1708 "Mark list with special properties.
1709 These special properties will later be interpreted by the backend."
1710 (let ((mark-list
1711 (function
1712 ;; Mark a list with 3 properties: `list-item' which is
1713 ;; position at beginning of line, `list-struct' which is
1714 ;; list structure, and `list-prevs' which is the alist of
1715 ;; item and its predecessor. Leave point at list ending.
1716 (lambda (ctxt)
1717 (let* ((struct (org-list-struct))
1718 (top (org-list-get-top-point struct))
1719 (bottom (org-list-get-bottom-point struct))
1720 (prevs (org-list-prevs-alist struct))
1721 poi)
1722 ;; Get every item and ending position, without dups and
1723 ;; without bottom point of list.
1724 (mapc (lambda (e)
1725 (let ((pos (car e))
1726 (end (nth 6 e)))
1727 (unless (memq pos poi)
1728 (push pos poi))
1729 (unless (or (= end bottom) (memq end poi))
1730 (push end poi))))
1731 struct)
1732 (setq poi (sort poi '<))
1733 ;; For every point of interest, mark the whole line with
1734 ;; its position in list.
1735 (mapc
1736 (lambda (e)
1737 (goto-char e)
1738 (add-text-properties (point-at-bol) (point-at-eol)
1739 (list 'list-item (point-at-bol)
1740 'list-struct struct
1741 'list-prevs prevs)))
1742 poi)
1743 ;; Take care of bottom point. As babel may have inserted
1744 ;; a new list in buffer, list ending isn't always
1745 ;; marked. Now mark every list ending and add properties
1746 ;; useful to line processing exporters.
1747 (goto-char bottom)
1748 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1749 (and (not (eq org-list-ending-method 'indent))
1750 (looking-at org-list-end-re)))
1751 (replace-match ""))
1752 (unless (bolp) (insert "\n"))
1753 (insert
1754 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1755 'list-struct struct
1756 'list-prevs prevs)))
1757 ;; Following property is used by LaTeX exporter.
1758 (add-text-properties top (point) (list 'list-context ctxt)))))))
1759 ;; Mark lists except for backends not interpreting them.
1760 (unless (eq org-export-current-backend 'ascii)
1761 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1762 (mapc
1763 (lambda (e)
1764 (goto-char (point-min))
1765 (while (re-search-forward (org-item-beginning-re) nil t)
1766 (when (eq (nth 2 (org-list-context)) e) (funcall mark-list e))))
1767 (cons nil org-list-export-context))))))
1769 (defun org-export-attach-captions-and-attributes (target-alist)
1770 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1771 If the next thing following is a table, add the text properties to the first
1772 table line. If it is a link, add it to the line containing the link."
1773 (goto-char (point-min))
1774 (remove-text-properties (point-min) (point-max)
1775 '(org-caption nil org-attributes nil))
1776 (let ((case-fold-search t)
1777 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1778 "\\|"
1779 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \t]+\\(.*\\)"
1780 "\\|"
1781 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1782 "\\|"
1783 "^[ \t]*\\(|[^-]\\)"
1784 "\\|"
1785 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1786 cap shortn attr label end)
1787 (while (re-search-forward re nil t)
1788 (cond
1789 ;; there is a caption
1790 ((match-end 1)
1791 (progn
1792 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))
1793 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap)
1794 (setq shortn (match-string 1 cap)
1795 cap (match-string 2 cap)))
1796 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1797 ;; there is an attribute
1798 ((match-end 2)
1799 (progn
1800 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))
1801 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1802 ;; there is a label
1803 ((match-end 3)
1804 (progn
1805 (setq label (org-trim (match-string 3)))
1806 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1808 (setq end (if (match-end 4)
1809 (let ((ee (org-table-end)))
1810 (prog1 (1- (marker-position ee)) (move-marker ee nil)))
1811 (point-at-eol)))
1812 (add-text-properties (point-at-bol) end
1813 (list 'org-caption cap
1814 'org-caption-shortn shortn
1815 'org-attributes attr
1816 'org-label label))
1817 (if label (push (cons label label) target-alist))
1818 (goto-char end)
1819 (setq cap nil attr nil label nil)))))
1820 target-alist)
1822 (defun org-export-remove-comment-blocks-and-subtrees ()
1823 "Remove the comment environment, and also commented subtrees."
1824 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1825 case-fold-search)
1826 ;; Remove comment environment
1827 (goto-char (point-min))
1828 (setq case-fold-search t)
1829 (while (re-search-forward
1830 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t)
1831 (replace-match "" t t))
1832 ;; Remove subtrees that are commented
1833 (goto-char (point-min))
1834 (setq case-fold-search nil)
1835 (while (re-search-forward re-commented nil t)
1836 (goto-char (match-beginning 0))
1837 (delete-region (point) (org-end-of-subtree t)))))
1839 (defun org-export-handle-comments (commentsp)
1840 "Remove comments, or convert to backend-specific format.
1841 COMMENTSP can be a format string for publishing comments.
1842 When it is nil, all comments will be removed."
1843 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1844 pos)
1845 (goto-char (point-min))
1846 (while (or (looking-at re)
1847 (re-search-forward re nil t))
1848 (setq pos (match-beginning 0))
1849 (if (get-text-property pos 'org-protected)
1850 (goto-char (1+ pos))
1851 (if (and commentsp
1852 (not (equal (char-before (match-end 1)) ?+)))
1853 (progn (add-text-properties
1854 (match-beginning 0) (match-end 0) '(org-protected t))
1855 (replace-match (format commentsp (match-string 2)) t t))
1856 (goto-char (1+ pos))
1857 (replace-match "")
1858 (goto-char (max (point-min) (1- pos))))))))
1860 (defun org-export-handle-table-metalines ()
1861 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1862 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1863 pos)
1864 (goto-char (point-min))
1865 (while (or (looking-at re)
1866 (re-search-forward re nil t))
1867 (setq pos (match-beginning 0))
1868 (if (get-text-property (match-beginning 1) 'org-protected)
1869 (goto-char (1+ pos))
1870 (goto-char (1+ pos))
1871 (replace-match "")
1872 (goto-char (max (point-min) (1- pos)))))))
1874 (defun org-export-mark-radio-links ()
1875 "Find all matches for radio targets and turn them into internal links."
1876 (let ((re-radio (and org-target-link-regexp
1877 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1878 (goto-char (point-min))
1879 (when re-radio
1880 (while (re-search-forward re-radio nil t)
1881 (unless
1882 (save-match-data
1883 (or (org-in-regexp org-bracket-link-regexp)
1884 (org-in-regexp org-plain-link-re)
1885 (org-in-regexp "<<[^<>]+>>")))
1886 (org-if-unprotected
1887 (replace-match "\\1[[\\2]]")))))))
1889 (defun org-store-forced-table-alignment ()
1890 "Find table lines which force alignment, store the results in properties."
1891 (let (line cnt aligns)
1892 (goto-char (point-min))
1893 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t)
1894 ;; OK, this looks like a table line with an alignment cookie
1895 (org-if-unprotected
1896 (setq line (buffer-substring (point-at-bol) (point-at-eol)))
1897 (when (and (org-at-table-p)
1898 (org-table-cookie-line-p line))
1899 (setq cnt 0 aligns nil)
1900 (mapc
1901 (lambda (x)
1902 (setq cnt (1+ cnt))
1903 (if (string-match "\\`<\\([lrc]\\)" x)
1904 (push (cons cnt (downcase (match-string 1 x))) aligns)))
1905 (org-split-string line "[ \t]*|[ \t]*"))
1906 (add-text-properties (org-table-begin) (org-table-end)
1907 (list 'org-forced-aligns aligns))))
1908 (goto-char (point-at-eol)))))
1910 (defun org-export-remove-special-table-lines ()
1911 "Remove tables lines that are used for internal purposes.
1912 Also, store forcedalignment information found in such lines."
1913 (goto-char (point-min))
1914 (while (re-search-forward "^[ \t]*|" nil t)
1915 (org-if-unprotected-at (1- (point))
1916 (beginning-of-line 1)
1917 (if (or (looking-at "[ \t]*| *[!_^] *|")
1918 (not
1919 (memq
1921 (mapcar
1922 (lambda (f)
1923 (or (= (length f) 0)
1924 (string-match
1925 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f)))
1926 (org-split-string ;; FIXME, can't we do without splitting???
1927 (buffer-substring (point-at-bol) (point-at-eol))
1928 "[ \t]*|[ \t]*")))))
1929 (delete-region (max (point-min) (1- (point-at-bol)))
1930 (point-at-eol))
1931 (end-of-line 1)))))
1933 (defun org-export-protect-sub-super (s)
1934 (save-match-data
1935 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s)
1936 (setq s (replace-match "\\1\\\\\\2" nil nil s)))
1939 (defun org-export-normalize-links ()
1940 "Convert all links to bracket links, and expand link abbreviations."
1941 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1942 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1943 nodesc)
1944 (goto-char (point-min))
1945 (while (re-search-forward re-plain-link nil t)
1946 (unless (org-string-match-p
1947 "\\[\\[\\S-+:\\S-*?\\<"
1948 (buffer-substring (point-at-bol) (match-beginning 0)))
1949 (goto-char (1- (match-end 0)))
1950 (org-if-unprotected-at (1+ (match-beginning 0))
1951 (let* ((s (concat (match-string 1)
1952 "[[" (match-string 2) ":" (match-string 3)
1953 "][" (match-string 2) ":" (org-export-protect-sub-super
1954 (match-string 3))
1955 "]]")))
1956 ;; added 'org-link face to links
1957 (put-text-property 0 (length s) 'face 'org-link s)
1958 (replace-match s t t)))))
1959 (goto-char (point-min))
1960 (while (re-search-forward re-angle-link nil t)
1961 (goto-char (1- (match-end 0)))
1962 (org-if-unprotected
1963 (let* ((s (concat (match-string 1)
1964 "[[" (match-string 2) ":" (match-string 3)
1965 "][" (match-string 2) ":" (org-export-protect-sub-super
1966 (match-string 3))
1967 "]]")))
1968 (put-text-property 0 (length s) 'face 'org-link s)
1969 (replace-match s t t))))
1970 (goto-char (point-min))
1971 (while (re-search-forward org-bracket-link-regexp nil t)
1972 (goto-char (1- (match-end 0)))
1973 (setq nodesc (not (match-end 3)))
1974 (org-if-unprotected
1975 (let* ((xx (save-match-data
1976 (org-translate-link
1977 (org-link-expand-abbrev (match-string 1)))))
1978 (s (concat
1979 "[[" (org-add-props (copy-sequence xx)
1980 nil 'org-protected t 'org-no-description nodesc)
1982 (if (match-end 3)
1983 (match-string 2)
1984 (concat "[" (copy-sequence xx)
1985 "]"))
1986 "]")))
1987 (put-text-property 0 (length s) 'face 'org-link s)
1988 (replace-match s t t))))))
1990 (defun org-export-concatenate-multiline-links ()
1991 "Find multi-line links and put it all into a single line.
1992 This is to make sure that the line-processing export backends
1993 can work correctly."
1994 (goto-char (point-min))
1995 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1996 (org-if-unprotected-at (match-beginning 1)
1997 (replace-match "\\1 \\3")
1998 (goto-char (match-beginning 0)))))
2000 (defun org-export-concatenate-multiline-emphasis ()
2001 "Find multi-line emphasis and put it all into a single line.
2002 This is to make sure that the line-processing export backends
2003 can work correctly."
2004 (goto-char (point-min))
2005 (while (re-search-forward org-emph-re nil t)
2006 (if (and (not (= (char-after (match-beginning 3))
2007 (char-after (match-beginning 4))))
2008 (save-excursion (goto-char (match-beginning 0))
2009 (save-match-data
2010 (and (not (org-at-table-p))
2011 (not (org-at-heading-p))))))
2012 (org-if-unprotected
2013 (subst-char-in-region (match-beginning 0) (match-end 0)
2014 ?\n ?\ t)
2015 (goto-char (1- (match-end 0))))
2016 (goto-char (1+ (match-beginning 0))))))
2018 (defun org-export-grab-title-from-buffer ()
2019 "Get a title for the current document, from looking at the buffer."
2020 (let ((inhibit-read-only t))
2021 (save-excursion
2022 (goto-char (point-min))
2023 (let ((end (if (looking-at org-outline-regexp)
2024 (point)
2025 (save-excursion (outline-next-heading) (point)))))
2026 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2027 ;; Mark the line so that it will not be exported as normal text.
2028 (org-unmodified
2029 (add-text-properties (match-beginning 0) (match-end 0)
2030 (list :org-license-to-kill t)))
2031 ;; Return the title string
2032 (org-trim (match-string 0)))))))
2034 (defun org-export-get-title-from-subtree ()
2035 "Return subtree title and exclude it from export."
2036 (let ((rbeg (region-beginning)) (rend (region-end))
2037 (inhibit-read-only t) title)
2038 (save-excursion
2039 (goto-char rbeg)
2040 (when (and (org-at-heading-p)
2041 (>= (org-end-of-subtree t t) rend))
2042 ;; This is a subtree, we take the title from the first heading
2043 (goto-char rbeg)
2044 (looking-at org-todo-line-regexp)
2045 (setq title (match-string 3))
2046 (org-unmodified
2047 (add-text-properties (point) (1+ (point-at-eol))
2048 (list :org-license-to-kill t)))
2049 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2050 title))
2052 (defun org-solidify-link-text (s &optional alist)
2053 "Take link text and make a safe target out of it."
2054 (save-match-data
2055 (let* ((rtn
2056 (mapconcat
2057 'identity
2058 (org-split-string s "[^a-zA-Z0-9_\\.-]+") "--"))
2059 (a (assoc rtn alist)))
2060 (or (cdr a) rtn))))
2062 (defun org-get-min-level (lines &optional offset)
2063 "Get the minimum level in LINES."
2064 (let ((re "^\\(\\*+\\) ") l)
2065 (catch 'exit
2066 (while (setq l (pop lines))
2067 (if (string-match re l)
2068 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2069 (or offset 0))))))
2070 1)))
2072 ;; Variable holding the vector with section numbers
2073 (defvar org-section-numbers (make-vector org-level-max 0))
2075 (defun org-init-section-numbers ()
2076 "Initialize the vector for the section numbers."
2077 (let* ((level -1)
2078 (numbers (nreverse (org-split-string "" "\\.")))
2079 (depth (1- (length org-section-numbers)))
2080 (i depth) number-string)
2081 (while (>= i 0)
2082 (if (> i level)
2083 (aset org-section-numbers i 0)
2084 (setq number-string (or (car numbers) "0"))
2085 (if (string-match "\\`[A-Z]\\'" number-string)
2086 (aset org-section-numbers i
2087 (- (string-to-char number-string) ?A -1))
2088 (aset org-section-numbers i (string-to-number number-string)))
2089 (pop numbers))
2090 (setq i (1- i)))))
2092 (defun org-section-number (&optional level)
2093 "Return a string with the current section number.
2094 When LEVEL is non-nil, increase section numbers on that level."
2095 (let* ((depth (1- (length org-section-numbers)))
2096 (string "")
2097 (fmts (car org-export-section-number-format))
2098 (term (cdr org-export-section-number-format))
2099 (sep "")
2100 ctype fmt idx n)
2101 (when level
2102 (when (> level -1)
2103 (aset org-section-numbers
2104 level (1+ (aref org-section-numbers level))))
2105 (setq idx (1+ level))
2106 (while (<= idx depth)
2107 (if (not (= idx 1))
2108 (aset org-section-numbers idx 0))
2109 (setq idx (1+ idx))))
2110 (setq idx 0)
2111 (while (<= idx depth)
2112 (when (> (aref org-section-numbers idx) 0)
2113 (setq fmt (or (pop fmts) fmt)
2114 ctype (car fmt)
2115 n (aref org-section-numbers idx)
2116 string (if (> n 0)
2117 (concat string sep (org-number-to-counter n ctype))
2118 (concat string ".0"))
2119 sep (nth 1 fmt)))
2120 (setq idx (1+ idx)))
2121 (save-match-data
2122 (if (string-match "\\`\\([@0]\\.\\)+" string)
2123 (setq string (replace-match "" t nil string)))
2124 (if (string-match "\\(\\.0\\)+\\'" string)
2125 (setq string (replace-match "" t nil string))))
2126 (concat string term)))
2128 (defun org-number-to-counter (n type)
2129 "Concert number N to a string counter, according to TYPE.
2130 TYPE must be a string, any of:
2131 1 number
2132 A A,B,....
2133 a a,b,....
2134 I upper case roman numeral
2135 i lower case roman numeral"
2136 (cond
2137 ((equal type "1") (number-to-string n))
2138 ((equal type "A") (char-to-string (+ ?A n -1)))
2139 ((equal type "a") (char-to-string (+ ?a n -1)))
2140 ((equal type "I") (org-number-to-roman n))
2141 ((equal type "i") (downcase (org-number-to-roman n)))
2142 (t (error "Invalid counter type `%s'" type))))
2144 (defun org-number-to-roman (n)
2145 "Convert integer N into a roman numeral."
2146 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2147 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2148 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2149 ( 1 . "I")))
2150 (res ""))
2151 (if (<= n 0)
2152 (number-to-string n)
2153 (while roman
2154 (if (>= n (caar roman))
2155 (setq n (- n (caar roman))
2156 res (concat res (cdar roman)))
2157 (pop roman)))
2158 res)))
2160 ;;; Macros
2162 (defun org-export-preprocess-apply-macros ()
2163 "Replace macro references."
2164 (goto-char (point-min))
2165 (let (sy val key args args2 s n)
2166 (while (re-search-forward
2167 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2168 nil t)
2169 (unless (save-match-data
2170 (save-excursion
2171 (goto-char (point-at-bol))
2172 (looking-at "[ \t]*#\\+macro")))
2173 (setq key (downcase (match-string 1))
2174 args (match-string 3))
2175 (when (setq val (or (plist-get org-export-opt-plist
2176 (intern (concat ":macro-" key)))
2177 (plist-get org-export-opt-plist
2178 (intern (concat ":" key)))))
2179 (save-match-data
2180 (when args
2181 (setq args (org-split-string args ",") args2 nil)
2182 (while args
2183 (while (string-match "\\\\\\'" (car args))
2184 ;; repair bad splits
2185 (setcar (cdr args) (concat (substring (car args) 0 -1)
2186 "," (nth 1 args)))
2187 (pop args))
2188 (push (pop args) args2))
2189 (setq args (mapcar 'org-trim (nreverse args2)))
2190 (setq s 0)
2191 (while (string-match "\\$\\([0-9]+\\)" val s)
2192 (setq s (1+ (match-beginning 0))
2193 n (string-to-number (match-string 1 val)))
2194 (and (>= (length args) n)
2195 (setq val (replace-match (nth (1- n) args) t t val)))))
2196 (when (string-match "\\`(eval\\>" val)
2197 (setq val (eval (read val))))
2198 (if (and val (not (stringp val)))
2199 (setq val (format "%s" val))))
2200 (and (stringp val)
2201 (prog1 (replace-match val t t)
2202 (goto-char (match-beginning 0)))))))))
2204 (defun org-export-apply-macros-in-string (s)
2205 "Apply the macros in string S."
2206 (when s
2207 (with-temp-buffer
2208 (insert s)
2209 (org-export-preprocess-apply-macros)
2210 (buffer-string))))
2212 ;;; Include files
2214 (defun org-export-handle-include-files ()
2215 "Include the contents of include files, with proper formatting."
2216 (let ((case-fold-search t)
2217 params file markup lang start end prefix prefix1 switches all minlevel lines)
2218 (goto-char (point-min))
2219 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2220 (setq params (read (concat "(" (match-string 1) ")"))
2221 prefix (org-get-and-remove-property 'params :prefix)
2222 prefix1 (org-get-and-remove-property 'params :prefix1)
2223 minlevel (org-get-and-remove-property 'params :minlevel)
2224 lines (org-get-and-remove-property 'params :lines)
2225 file (org-symname-or-string (pop params))
2226 markup (org-symname-or-string (pop params))
2227 lang (and (member markup '("src" "SRC"))
2228 (org-symname-or-string (pop params)))
2229 switches (mapconcat '(lambda (x) (format "%s" x)) params " ")
2230 start nil end nil)
2231 (delete-region (match-beginning 0) (match-end 0))
2232 (if (or (not file)
2233 (not (file-exists-p file))
2234 (not (file-readable-p file)))
2235 (insert (format "CANNOT INCLUDE FILE %s" file))
2236 (setq all (cons file all))
2237 (when markup
2238 (if (equal (downcase markup) "src")
2239 (setq start (format "#+begin_src %s %s\n"
2240 (or lang "fundamental")
2241 (or switches ""))
2242 end "#+end_src")
2243 (setq start (format "#+begin_%s %s\n" markup switches)
2244 end (format "#+end_%s" markup))))
2245 (insert (or start ""))
2246 (insert (org-get-file-contents (expand-file-name file)
2247 prefix prefix1 markup minlevel lines))
2248 (or (bolp) (newline))
2249 (insert (or end ""))))
2250 all))
2252 (defun org-export-handle-include-files-recurse ()
2253 "Recursively include files aborting on circular inclusion."
2254 (let ((now (list org-current-export-file)) all)
2255 (while now
2256 (setq all (append now all))
2257 (setq now (org-export-handle-include-files))
2258 (let ((intersection
2259 (delq nil
2260 (mapcar (lambda (el) (when (member el all) el)) now))))
2261 (when intersection
2262 (error "Recursive #+INCLUDE: %S" intersection))))))
2264 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines)
2265 "Get the contents of FILE and return them as a string.
2266 If PREFIX is a string, prepend it to each line. If PREFIX1
2267 is a string, prepend it to the first line instead of PREFIX.
2268 If MARKUP, don't protect org-like lines, the exporter will
2269 take care of the block they are in. If LINES is a string
2270 specifying a range of lines, include only those lines ."
2271 (if (stringp markup) (setq markup (downcase markup)))
2272 (with-temp-buffer
2273 (insert-file-contents file)
2274 (when lines
2275 (let* ((lines (split-string lines "-"))
2276 (lbeg (string-to-number (car lines)))
2277 (lend (string-to-number (cadr lines)))
2278 (beg (if (zerop lbeg) (point-min)
2279 (goto-char (point-min))
2280 (forward-line (1- lbeg))
2281 (point)))
2282 (end (if (zerop lend) (point-max)
2283 (goto-char (point-min))
2284 (forward-line (1- lend))
2285 (point))))
2286 (narrow-to-region beg end)))
2287 (when (or prefix prefix1)
2288 (goto-char (point-min))
2289 (while (not (eobp))
2290 (insert (or prefix1 prefix))
2291 (setq prefix1 "")
2292 (beginning-of-line 2)))
2293 (buffer-string)
2294 (when (member markup '("src" "example"))
2295 (goto-char (point-min))
2296 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t)
2297 (goto-char (match-beginning 0))
2298 (insert ",")
2299 (end-of-line 1)))
2300 (when minlevel
2301 (dotimes (lvl minlevel)
2302 (org-map-region 'org-demote (point-min) (point-max))))
2303 (buffer-string)))
2305 (defun org-get-and-remove-property (listvar prop)
2306 "Check if the value of LISTVAR contains PROP as a property.
2307 If yes, return the value of that property (i.e. the element following
2308 in the list) and remove property and value from the list in LISTVAR."
2309 (let ((list (symbol-value listvar)) m v)
2310 (when (setq m (member prop list))
2311 (setq v (nth 1 m))
2312 (if (equal (car list) prop)
2313 (set listvar (cddr list))
2314 (setcdr (nthcdr (- (length list) (length m) 1) list)
2315 (cddr m))
2316 (set listvar list)))
2319 (defun org-symname-or-string (s)
2320 (if (symbolp s)
2321 (if s (symbol-name s) s)
2324 ;;; Fontification and line numbers for code examples
2326 (defvar org-export-last-code-line-counter-value 0)
2328 (defun org-export-replace-src-segments-and-examples ()
2329 "Replace source code segments with special code for export."
2330 (setq org-export-last-code-line-counter-value 0)
2331 (let ((case-fold-search t)
2332 lang code trans opts indent caption)
2333 (goto-char (point-min))
2334 (while (re-search-forward
2335 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2336 nil t)
2337 (if (match-end 1)
2338 (if (not (match-string 4))
2339 (error "Source block missing language specification: %s"
2340 (let* ((body (match-string 6))
2341 (nothing (message "body:%s" body))
2342 (preview (or (and (string-match
2343 "^[ \t]*\\([^\n\r]*\\)" body)
2344 (match-string 1 body)) body)))
2345 (if (> (length preview) 35)
2346 (concat (substring preview 0 32) "...")
2347 preview)))
2348 ;; src segments
2349 (setq lang (match-string 4)
2350 opts (match-string 5)
2351 code (match-string 6)
2352 indent (length (match-string 2))
2353 caption (get-text-property 0 'org-caption (match-string 0))))
2354 (setq lang nil
2355 opts (match-string 9)
2356 code (match-string 10)
2357 indent (length (match-string 8))
2358 caption (get-text-property 0 'org-caption (match-string 0))))
2360 (setq trans (org-export-format-source-code-or-example
2361 lang code opts indent caption))
2362 (replace-match trans t t))))
2364 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2365 (defvar org-export-latex-listings) ;; defined in org-latex.el
2366 (defvar org-export-latex-listings-langs) ;; defined in org-latex.el
2367 (defvar org-export-latex-listings-w-names) ;; defined in org-latex.el
2368 (defvar org-export-latex-minted-langs) ;; defined in org-latex.el
2369 (defvar org-export-latex-custom-lang-environments) ;; defined in org-latex.el
2370 (defvar org-export-latex-listings-options) ;; defined in org-latex.el
2371 (defvar org-export-latex-minted-options) ;; defined in org-latex.el
2373 (defun org-export-format-source-code-or-example
2374 (lang code &optional opts indent caption)
2375 "Format CODE from language LANG and return it formatted for export.
2376 If LANG is nil, do not add any fontification.
2377 OPTS contains formatting options, like `-n' for triggering numbering lines,
2378 and `+n' for continuing previous numbering.
2379 Code formatting according to language currently only works for HTML.
2380 Numbering lines works for all three major backends (html, latex, and ascii).
2381 INDENT was the original indentation of the block."
2382 (save-match-data
2383 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2384 (setq opts (or opts "")
2385 num (string-match "[-+]n\\>" opts)
2386 cont (string-match "\\+n\\>" opts)
2387 rpllbl (string-match "-r\\>" opts)
2388 keepp (string-match "-k\\>" opts)
2389 textareap (string-match "-t\\>" opts)
2390 preserve-indentp (or org-src-preserve-indentation
2391 (string-match "-i\\>" opts))
2392 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2393 (string-to-number (match-string 1 opts))
2395 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2396 (string-to-number (match-string 1 opts))
2397 (org-count-lines code))
2398 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2399 (match-string 1 opts)))
2400 (when (and textareap (eq org-export-current-backend 'html))
2401 ;; we cannot use numbering or highlighting.
2402 (setq num nil cont nil lang nil))
2403 (if keepp (setq rpllbl 'keep))
2404 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2405 (when (string-match "^," rtn)
2406 (setq rtn (with-temp-buffer
2407 (insert rtn)
2408 ;; Free up the protected lines
2409 (goto-char (point-min))
2410 (while (re-search-forward "^," nil t)
2411 (if (or (equal lang "org")
2412 (save-match-data
2413 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2414 (replace-match ""))
2415 (end-of-line 1))
2416 (buffer-string))))
2417 ;; Now backend-specific coding
2418 (setq rtn
2419 (cond
2420 ((eq org-export-current-backend 'docbook)
2421 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2422 (concat "\n#+BEGIN_DOCBOOK\n"
2423 (org-add-props (concat "<programlisting><![CDATA["
2425 "]]></programlisting>\n")
2426 '(org-protected t org-example t))
2427 "#+END_DOCBOOK\n"))
2428 ((eq org-export-current-backend 'html)
2429 ;; We are exporting to HTML
2430 (when lang
2431 (if (featurep 'xemacs)
2432 (require 'htmlize)
2433 (require 'htmlize nil t))
2434 (when (not (fboundp 'htmlize-region-for-paste))
2435 ;; we do not have htmlize.el, or an old version of it
2436 (setq lang nil)
2437 (message
2438 "htmlize.el 1.34 or later is needed for source code formatting")))
2440 (if lang
2441 (let* ((lang-m (when lang
2442 (or (cdr (assoc lang org-src-lang-modes))
2443 lang)))
2444 (mode (and lang-m (intern
2445 (concat
2446 (if (symbolp lang-m)
2447 (symbol-name lang-m)
2448 lang-m)
2449 "-mode"))))
2450 (org-inhibit-startup t)
2451 (org-startup-folded nil))
2452 (setq rtn
2453 (with-temp-buffer
2454 (insert rtn)
2455 (if (functionp mode)
2456 (funcall mode)
2457 (fundamental-mode))
2458 (font-lock-fontify-buffer)
2459 (org-src-mode)
2460 (set-buffer-modified-p nil)
2461 (org-export-htmlize-region-for-paste
2462 (point-min) (point-max))))
2463 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2464 (setq rtn
2465 (concat
2466 (if caption
2467 (concat
2468 "<div class=\"org-src-container\">"
2469 (format
2470 "<label class=\"org-src-name\">%s</label>"
2471 caption))
2473 (replace-match
2474 (format "<pre class=\"src src-%s\">\n" lang)
2475 t t rtn)
2476 (if caption "</div>" "")))))
2477 (if textareap
2478 (setq rtn (concat
2479 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2480 cols rows)
2481 rtn "</textarea>\n</p>\n"))
2482 (with-temp-buffer
2483 (insert rtn)
2484 (goto-char (point-min))
2485 (while (re-search-forward "[<>&]" nil t)
2486 (replace-match (cdr (assq (char-before)
2487 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2488 t t))
2489 (setq rtn (buffer-string)))
2490 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2491 (unless textareap
2492 (setq rtn (org-export-number-lines rtn 1 1 num cont rpllbl fmt)))
2493 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
2494 (setq rtn (replace-match "\\1" t nil rtn)))
2495 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t org-example t)) "\n#+END_HTML\n\n"))
2496 ((eq org-export-current-backend 'latex)
2497 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2498 (concat
2499 "#+BEGIN_LaTeX\n"
2500 (org-add-props
2501 (cond
2502 ((and lang org-export-latex-listings)
2503 (flet ((make-option-string
2504 (pair)
2505 (concat (first pair)
2506 (if (> (length (second pair)) 0)
2507 (concat "=" (second pair))))))
2508 (let* ((lang-sym (intern lang))
2509 (minted-p (eq org-export-latex-listings 'minted))
2510 (listings-p (not minted-p))
2511 (backend-lang
2512 (or (cadr
2513 (assq
2514 lang-sym
2515 (cond
2516 (minted-p org-export-latex-minted-langs)
2517 (listings-p org-export-latex-listings-langs))))
2518 lang))
2519 (custom-environment
2520 (cadr
2521 (assq
2522 lang-sym
2523 org-export-latex-custom-lang-environments))))
2524 (concat
2525 (when (and listings-p (not custom-environment))
2526 (format
2527 "\\lstset{%s}\n"
2528 (mapconcat
2529 #'make-option-string
2530 (append org-export-latex-listings-options
2531 `(("language" ,backend-lang))) ",")))
2532 (when (and caption org-export-latex-listings-w-names)
2533 (format
2534 "\n%s $\\equiv$ \n"
2535 (replace-regexp-in-string "_" "\\\\_" caption)))
2536 (cond
2537 (custom-environment
2538 (format "\\begin{%s}\n%s\\end{%s}\n"
2539 custom-environment rtn custom-environment))
2540 (listings-p
2541 (format "\\begin{%s}\n%s\\end{%s}\n"
2542 "lstlisting" rtn "lstlisting"))
2543 (minted-p
2544 (format
2545 "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
2546 (mapconcat #'make-option-string
2547 org-export-latex-minted-options ",")
2548 backend-lang rtn)))))))
2549 (t (concat (car org-export-latex-verbatim-wrap)
2550 rtn (cdr org-export-latex-verbatim-wrap))))
2551 '(org-protected t org-example t))
2552 "#+END_LaTeX\n"))
2553 ((eq org-export-current-backend 'ascii)
2554 ;; This is not HTML or LaTeX, so just make it an example.
2555 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2556 (concat caption "\n"
2557 "#+BEGIN_ASCII\n"
2558 (org-add-props
2559 (concat
2560 (mapconcat
2561 (lambda (l) (concat " " l))
2562 (org-split-string rtn "\n")
2563 "\n")
2564 "\n")
2565 '(org-protected t org-example t))
2566 "#+END_ASCII\n"))))
2567 (org-add-props rtn nil 'original-indentation indent))))
2569 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2570 replace-labels label-format)
2571 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2572 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2573 (with-temp-buffer
2574 (insert text)
2575 (goto-char (point-max))
2576 (skip-chars-backward " \t\n\r")
2577 (delete-region (point) (point-max))
2578 (beginning-of-line (- 1 skip2))
2579 (let* ((last (org-current-line))
2580 (n org-export-last-code-line-counter-value)
2581 (nmax (+ n (- last skip1)))
2582 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2584 (cond
2585 ((eq org-export-current-backend 'html) (format "<span class=\"linenr\">%s</span>"
2586 fmt))
2587 ((eq org-export-current-backend 'ascii) fmt)
2588 ((eq org-export-current-backend 'latex) fmt)
2589 ((eq org-export-current-backend 'docbook) fmt)
2590 (t "")))
2591 (label-format (or label-format org-coderef-label-format))
2592 (label-pre (if (string-match "%s" label-format)
2593 (substring label-format 0 (match-beginning 0))
2594 label-format))
2595 (label-post (if (string-match "%s" label-format)
2596 (substring label-format (match-end 0))
2597 ""))
2598 (lbl-re
2599 (concat
2600 ".*?\\S-.*?\\([ \t]*\\("
2601 (regexp-quote label-pre)
2602 "\\([-a-zA-Z0-9_ ]+\\)"
2603 (regexp-quote label-post)
2604 "\\)\\)"))
2605 ref)
2607 (org-goto-line (1+ skip1))
2608 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2609 (if number
2610 (insert (format fm (incf n)))
2611 (forward-char 1))
2612 (when (looking-at lbl-re)
2613 (setq ref (match-string 3))
2614 (cond ((numberp replace-labels)
2615 ;; remove labels; use numbers for references when lines
2616 ;; are numbered, use labels otherwise
2617 (delete-region (match-beginning 1) (match-end 1))
2618 (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
2619 ((eq replace-labels 'keep)
2620 ;; don't remove labels; use numbers for references when
2621 ;; lines are numbered, use labels otherwise
2622 (goto-char (match-beginning 2))
2623 (delete-region (match-beginning 2) (match-end 2))
2624 (insert "(" ref ")")
2625 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
2626 org-export-code-refs))
2628 ;; don't remove labels and don't use numbers for
2629 ;; references
2630 (goto-char (match-beginning 2))
2631 (delete-region (match-beginning 2) (match-end 2))
2632 (insert "(" ref ")")
2633 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
2634 (when (eq org-export-current-backend 'html)
2635 (save-excursion
2636 (beginning-of-line 1)
2637 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2638 ref))
2639 (end-of-line 1)
2640 (insert "</span>")))))
2641 (setq org-export-last-code-line-counter-value n)
2642 (goto-char (point-max))
2643 (newline)
2644 (buffer-string))))
2646 (defun org-search-todo-below (line lines level)
2647 "Search the subtree below LINE for any TODO entries."
2648 (let ((rest (cdr (memq line lines)))
2649 (re org-todo-line-regexp)
2650 line lv todo)
2651 (catch 'exit
2652 (while (setq line (pop rest))
2653 (if (string-match re line)
2654 (progn
2655 (setq lv (- (match-end 1) (match-beginning 1))
2656 todo (and (match-beginning 2)
2657 (not (member (match-string 2 line)
2658 org-done-keywords))))
2659 ; TODO, not DONE
2660 (if (<= lv level) (throw 'exit nil))
2661 (if todo (throw 'exit t))))))))
2663 ;;;###autoload
2664 (defun org-export-visible (type arg)
2665 "Create a copy of the visible part of the current buffer, and export it.
2666 The copy is created in a temporary buffer and removed after use.
2667 TYPE is the final key (as a string) that also selects the export command in
2668 the \\<org-mode-map>\\[org-export] export dispatcher.
2669 As a special case, if the you type SPC at the prompt, the temporary
2670 org-mode file will not be removed but presented to you so that you can
2671 continue to use it. The prefix arg ARG is passed through to the exporting
2672 command."
2673 (interactive
2674 (list (progn
2675 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]buffer with HTML [D]ocBook [l]atex [p]df [d]view pdf [L]atex buffer [x]OXO [ ]keep buffer")
2676 (read-char-exclusive))
2677 current-prefix-arg))
2678 (if (not (member type '(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L)))
2679 (error "Invalid export key"))
2680 (let* ((binding (cdr (assoc type
2682 (?a . org-export-as-ascii)
2683 (?A . org-export-as-ascii-to-buffer)
2684 (?n . org-export-as-latin1)
2685 (?N . org-export-as-latin1-to-buffer)
2686 (?u . org-export-as-utf8)
2687 (?U . org-export-as-utf8-to-buffer)
2688 (?\C-a . org-export-as-ascii)
2689 (?b . org-export-as-html-and-open)
2690 (?\C-b . org-export-as-html-and-open)
2691 (?h . org-export-as-html)
2692 (?H . org-export-as-html-to-buffer)
2693 (?R . org-export-region-as-html)
2694 (?D . org-export-as-docbook)
2696 (?l . org-export-as-latex)
2697 (?p . org-export-as-pdf)
2698 (?d . org-export-as-pdf-and-open)
2699 (?L . org-export-as-latex-to-buffer)
2701 (?x . org-export-as-xoxo)))))
2702 (keepp (equal type ?\ ))
2703 (file buffer-file-name)
2704 (buffer (get-buffer-create "*Org Export Visible*"))
2705 s e)
2706 ;; Need to hack the drawers here.
2707 (save-excursion
2708 (goto-char (point-min))
2709 (while (re-search-forward org-drawer-regexp nil t)
2710 (goto-char (match-beginning 1))
2711 (or (outline-invisible-p) (org-flag-drawer nil))))
2712 (with-current-buffer buffer (erase-buffer))
2713 (save-excursion
2714 (setq s (goto-char (point-min)))
2715 (while (not (= (point) (point-max)))
2716 (goto-char (org-find-invisible))
2717 (append-to-buffer buffer s (point))
2718 (setq s (goto-char (org-find-visible))))
2719 (org-cycle-hide-drawers 'all)
2720 (goto-char (point-min))
2721 (unless keepp
2722 ;; Copy all comment lines to the end, to make sure #+ settings are
2723 ;; still available for the second export step. Kind of a hack, but
2724 ;; does do the trick.
2725 (if (looking-at "#[^\r\n]*")
2726 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2727 (when (re-search-forward "^\\*+[ \t]+" nil t)
2728 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t)
2729 (append-to-buffer buffer (1+ (match-beginning 0))
2730 (min (point-max) (1+ (match-end 0)))))))
2731 (set-buffer buffer)
2732 (let ((buffer-file-name file)
2733 (org-inhibit-startup t))
2734 (org-mode)
2735 (show-all)
2736 (unless keepp (funcall binding arg))))
2737 (if (not keepp)
2738 (kill-buffer buffer)
2739 (switch-to-buffer-other-window buffer)
2740 (goto-char (point-min)))))
2742 (defun org-find-visible ()
2743 (let ((s (point)))
2744 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2745 (get-char-property s 'invisible)))
2747 (defun org-find-invisible ()
2748 (let ((s (point)))
2749 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2750 (not (get-char-property s 'invisible))))
2753 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2755 (defun org-export-string (string fmt &optional dir)
2756 "Export STRING to FMT using existing export facilities.
2757 During export STRING is saved to a temporary file whose location
2758 could vary. Optional argument DIR can be used to force the
2759 directory in which the temporary file is created during export
2760 which can be useful for resolving relative paths. Dir defaults
2761 to the value of `temporary-file-directory'."
2762 (let ((temporary-file-directory (or dir temporary-file-directory))
2763 (tmp-file (make-temp-file "org-")))
2764 (unwind-protect
2765 (with-temp-buffer
2766 (insert string)
2767 (write-file tmp-file)
2768 (org-load-modules-maybe)
2769 (unless org-local-vars
2770 (setq org-local-vars (org-get-local-variables)))
2771 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2772 (list 'let org-local-vars
2773 (list (intern (format "org-export-as-%s" fmt))
2774 nil nil nil ''string t))))
2775 (delete-file tmp-file))))
2777 ;;;###autoload
2778 (defun org-export-as-org (arg &optional hidden ext-plist
2779 to-buffer body-only pub-dir)
2780 "Make a copy with not-exporting stuff removed.
2781 The purpose of this function is to provide a way to export the source
2782 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2783 stuff removed. This command will remove the following:
2785 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2786 - comment blocks and trees starting with the COMMENT keyword
2787 - only trees that are consistent with `org-export-select-tags'
2788 and `org-export-exclude-tags'.
2790 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2791 all the others will be ignored (but are present so that the general
2792 mechanism to call publishing functions will work).
2794 EXT-PLIST is a property list with external parameters overriding
2795 org-mode's default settings, but still inferior to file-local
2796 settings. When PUB-DIR is set, use this as the publishing
2797 directory."
2798 (interactive "P")
2799 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2800 ext-plist
2801 (org-infile-export-plist)))
2802 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2803 (filename (concat (file-name-as-directory
2804 (or pub-dir
2805 (org-export-directory :org opt-plist)))
2806 (file-name-sans-extension
2807 (file-name-nondirectory bfname))
2808 ".org"))
2809 (filename (and filename
2810 (if (equal (file-truename filename)
2811 (file-truename bfname))
2812 (concat (file-name-sans-extension filename)
2813 "-source."
2814 (file-name-extension filename))
2815 filename)))
2816 (backup-inhibited t)
2817 (buffer (find-file-noselect filename))
2818 (region (buffer-string))
2819 str-ret)
2820 (save-excursion
2821 (switch-to-buffer buffer)
2822 (erase-buffer)
2823 (insert region)
2824 (let ((org-inhibit-startup t)) (org-mode))
2825 (org-install-letbind)
2827 ;; Get rid of archived trees
2828 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2830 ;; Remove comment environment and comment subtrees
2831 (org-export-remove-comment-blocks-and-subtrees)
2833 ;; Get rid of excluded trees
2834 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2835 (plist-get opt-plist :exclude-tags))
2837 (when (or (plist-get opt-plist :plain-source)
2838 (not (or (plist-get opt-plist :plain-source)
2839 (plist-get opt-plist :htmlized-source))))
2840 ;; Either nothing special is requested (default call)
2841 ;; or the plain source is explicitly requested
2842 ;; so: save it
2843 (save-buffer))
2844 (when (plist-get opt-plist :htmlized-source)
2845 ;; Make the htmlized version
2846 (require 'htmlize)
2847 (require 'org-html)
2848 (font-lock-fontify-buffer)
2849 (let* ((htmlize-output-type 'css)
2850 (newbuf (htmlize-buffer)))
2851 (with-current-buffer newbuf
2852 (when org-export-htmlized-org-css-url
2853 (goto-char (point-min))
2854 (and (re-search-forward
2855 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2856 nil t)
2857 (replace-match
2858 (format
2859 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2860 org-export-htmlized-org-css-url)
2861 t t)))
2862 (write-file (concat filename ".html")))
2863 (kill-buffer newbuf)))
2864 (set-buffer-modified-p nil)
2865 (if (equal to-buffer 'string)
2866 (progn (setq str-ret (buffer-string))
2867 (kill-buffer (current-buffer))
2868 str-ret)
2869 (kill-buffer (current-buffer))))))
2871 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2872 (defun org-get-current-options ()
2873 "Return a string with current options as keyword options.
2874 Does include HTML export options as well as TODO and CATEGORY stuff."
2875 (require 'org-archive)
2876 (format
2877 "#+TITLE: %s
2878 #+AUTHOR: %s
2879 #+EMAIL: %s
2880 #+DATE: %s
2881 #+DESCRIPTION:
2882 #+KEYWORDS:
2883 #+LANGUAGE: %s
2884 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2885 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2887 #+EXPORT_SELECT_TAGS: %s
2888 #+EXPORT_EXCLUDE_TAGS: %s
2889 #+LINK_UP: %s
2890 #+LINK_HOME: %s
2891 #+XSLT:
2892 #+CATEGORY: %s
2893 #+SEQ_TODO: %s
2894 #+TYP_TODO: %s
2895 #+PRIORITIES: %c %c %c
2896 #+DRAWERS: %s
2897 #+STARTUP: %s %s %s %s %s
2898 #+TAGS: %s
2899 #+FILETAGS: %s
2900 #+ARCHIVE: %s
2901 #+LINK: %s
2903 (buffer-name) (user-full-name) user-mail-address
2904 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2905 org-export-default-language
2906 org-export-headline-levels
2907 org-export-with-section-numbers
2908 org-export-with-toc
2909 org-export-preserve-breaks
2910 org-export-html-expand
2911 org-export-with-fixed-width
2912 org-export-with-tables
2913 org-export-with-sub-superscripts
2914 org-export-with-special-strings
2915 org-export-with-footnotes
2916 org-export-with-emphasize
2917 org-export-with-timestamps
2918 org-export-with-TeX-macros
2919 org-export-with-LaTeX-fragments
2920 org-export-skip-text-before-1st-heading
2921 org-export-with-drawers
2922 org-export-with-todo-keywords
2923 org-export-with-priority
2924 org-export-with-tags
2925 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2926 (mapconcat 'identity org-export-select-tags " ")
2927 (mapconcat 'identity org-export-exclude-tags " ")
2928 org-export-html-link-up
2929 org-export-html-link-home
2930 (or (ignore-errors
2931 (file-name-sans-extension
2932 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2933 "NOFILENAME")
2934 "TODO FEEDBACK VERIFY DONE"
2935 "Me Jason Marie DONE"
2936 org-highest-priority org-lowest-priority org-default-priority
2937 (mapconcat 'identity org-drawers " ")
2938 (cdr (assoc org-startup-folded
2939 '((nil . "showall") (t . "overview") (content . "content"))))
2940 (if org-odd-levels-only "odd" "oddeven")
2941 (if org-hide-leading-stars "hidestars" "showstars")
2942 (if org-startup-align-all-tables "align" "noalign")
2943 (cond ((eq org-log-done t) "logdone")
2944 ((equal org-log-done 'note) "lognotedone")
2945 ((not org-log-done) "nologdone"))
2946 (or (mapconcat (lambda (x)
2947 (cond
2948 ((equal :startgroup (car x)) "{")
2949 ((equal :endgroup (car x)) "}")
2950 ((equal :newline (car x)) "")
2951 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2952 (t (car x))))
2953 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2954 (mapconcat 'identity org-file-tags " ")
2955 org-archive-location
2956 "org file:~/org/%s.org"
2959 ;;;###autoload
2960 (defun org-insert-export-options-template ()
2961 "Insert into the buffer a template with information for exporting."
2962 (interactive)
2963 (if (not (bolp)) (newline))
2964 (let ((s (org-get-current-options)))
2965 (and (string-match "#\\+CATEGORY" s)
2966 (setq s (substring s 0 (match-beginning 0))))
2967 (insert s)))
2969 (defvar org-table-colgroup-info nil)
2971 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2972 "Check if the table has a marking column.
2973 If yes remove the column and the special lines."
2974 (setq org-table-colgroup-info nil)
2975 (if (memq nil
2976 (mapcar
2977 (lambda (x) (or (string-match "^[ \t]*|-" x)
2978 (string-match
2979 (if maybe-quoted
2980 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2981 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2982 x)))
2983 lines))
2984 ;; No special marking column
2985 (progn
2986 (setq org-table-clean-did-remove-column nil)
2987 (delq nil
2988 (mapcar
2989 (lambda (x)
2990 (cond
2991 ((org-table-colgroup-line-p x)
2992 ;; This line contains colgroup info, extract it
2993 ;; and then discard the line
2994 (setq org-table-colgroup-info
2995 (mapcar (lambda (x)
2996 (cond ((member x '("<" "&lt;")) :start)
2997 ((member x '(">" "&gt;")) :end)
2998 ((member x '("<>" "&lt;&gt;")) :startend)
2999 (t nil)))
3000 (org-split-string x "[ \t]*|[ \t]*")))
3001 nil)
3002 ((org-table-cookie-line-p x)
3003 ;; This line contains formatting cookies, discard it
3004 nil)
3005 (t x)))
3006 lines)))
3007 ;; there is a special marking column
3008 (setq org-table-clean-did-remove-column t)
3009 (delq nil
3010 (mapcar
3011 (lambda (x)
3012 (cond
3013 ((org-table-colgroup-line-p x)
3014 ;; This line contains colgroup info, extract it
3015 ;; and then discard the line
3016 (setq org-table-colgroup-info
3017 (mapcar (lambda (x)
3018 (cond ((member x '("<" "&lt;")) :start)
3019 ((member x '(">" "&gt;")) :end)
3020 ((member x '("<>" "&lt;&gt;")) :startend)
3021 (t nil)))
3022 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3023 nil)
3024 ((org-table-cookie-line-p x)
3025 ;; This line contains formatting cookies, discard it
3026 nil)
3027 ((string-match "^[ \t]*| *[!_^/] *|" x)
3028 ;; ignore this line
3029 nil)
3030 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3031 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3032 ;; remove the first column
3033 (replace-match "\\1|" t nil x))))
3034 lines))))
3036 (defun org-export-cleanup-toc-line (s)
3037 "Remove tags and timestamps from lines going into the toc."
3038 (when (memq org-export-with-tags '(not-in-toc nil))
3039 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s)
3040 (setq s (replace-match "" t t s))))
3041 (when org-export-remove-timestamps-from-toc
3042 (while (string-match org-maybe-keyword-time-regexp s)
3043 (setq s (replace-match "" t t s))))
3044 (while (string-match org-bracket-link-regexp s)
3045 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3046 t t s)))
3047 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s)
3048 (setq s (replace-match "" t t s)))
3052 (defun org-get-text-property-any (pos prop &optional object)
3053 (or (get-text-property pos prop object)
3054 (and (setq pos (next-single-property-change pos prop object))
3055 (get-text-property pos prop object))))
3057 (defun org-export-get-coderef-format (path desc)
3058 (save-match-data
3059 (if (and desc (string-match
3060 (regexp-quote (concat "(" path ")"))
3061 desc))
3062 (replace-match "%s" t t desc)
3063 (or desc "%s"))))
3065 (defun org-export-push-to-kill-ring (format)
3066 "Push buffer content to kill ring.
3067 The depends on the variable `org-export-copy-to-kill'."
3068 (when org-export-copy-to-kill-ring
3069 (org-kill-new (buffer-string))
3070 (when (fboundp 'x-set-selection)
3071 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
3072 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
3073 (message "%s export done, pushed to kill ring and clipboard" format)))
3075 (provide 'org-exp)
3077 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3079 ;;; org-exp.el ends here